Add conf-file option.
Luci add custom.conf Bugfix for timer Update address matching.
This commit is contained in:
@@ -300,6 +300,7 @@ vi /opt/etc/smartdns/smartdns.conf
|
|||||||
|log-file|日志文件路径|/var/log/smartdns.log|路径|log-file /var/log/smartdns.log
|
|log-file|日志文件路径|/var/log/smartdns.log|路径|log-file /var/log/smartdns.log
|
||||||
|log-size|日志大小|128K|数字+K,M,G|log-size 128K
|
|log-size|日志大小|128K|数字+K,M,G|log-size 128K
|
||||||
|log-num|日志归档个数|2|数字|log-num 2
|
|log-num|日志归档个数|2|数字|log-num 2
|
||||||
|
|conf-file|附加日志文件|无|文件路径|conf-file /etc/smartdns/smartdns.more.conf
|
||||||
|server|上游UDP DNS|114.114.114.114|[ip][:port],可重复| server 8.8.8.8:53
|
|server|上游UDP DNS|114.114.114.114|[ip][:port],可重复| server 8.8.8.8:53
|
||||||
|server-tcp|上游TCP DNS|无|[IP][:port],可重复| server-tcp 8.8.8.8:53
|
|server-tcp|上游TCP DNS|无|[IP][:port],可重复| server-tcp 8.8.8.8:53
|
||||||
|address|指定域名IP地址|无|address /domain/ip| address /www.example.com/1.2.3.4
|
|address|指定域名IP地址|无|address /domain/ip| address /www.example.com/1.2.3.4
|
||||||
|
|||||||
@@ -27,8 +27,8 @@ function act_status()
|
|||||||
e.local_port = smartdns.get_config_option("smartdns", "smartdns", "port", nil);
|
e.local_port = smartdns.get_config_option("smartdns", "smartdns", "port", nil);
|
||||||
if e.redirect == "1" then
|
if e.redirect == "1" then
|
||||||
if e.local_port ~= nil and e.local_port ~= "53" then
|
if e.local_port ~= nil and e.local_port ~= "53" then
|
||||||
e.ipv4_works = luci.sys.call("iptables -t nat -nL PREROUTING | grep REDIRECT | grep dpt:53 | grep %q >/dev/null 2>&1" % e.local_port) == 0
|
e.ipv4_works = luci.sys.call("iptables -t nat -nL PREROUTING 2>/dev/null | grep REDIRECT | grep dpt:53 | grep %q >/dev/null 2>&1" % e.local_port) == 0
|
||||||
e.ipv6_works = luci.sys.call("ip6tables -t nat -nL PREROUTING | grep REDIRECT | grep dpt:53 | grep %q >/dev/null 2>&1" % e.local_port) == 0
|
e.ipv6_works = luci.sys.call("ip6tables -t nat -nL PREROUTING 2>/dev/null| grep REDIRECT | grep dpt:53 | grep %q >/dev/null 2>&1" % e.local_port) == 0
|
||||||
else
|
else
|
||||||
e.redirect = 0
|
e.redirect = 0
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -13,6 +13,9 @@ msgstr "SmartDNS 服务器"
|
|||||||
msgid "SmartDNS is a local high-performance DNS server, supports finding fastest IP, supports ad filtering, and supports avoiding DNS poisoning."
|
msgid "SmartDNS is a local high-performance DNS server, supports finding fastest IP, supports ad filtering, and supports avoiding DNS poisoning."
|
||||||
msgstr "SmartDNS是一个本地高性能DNS服务器,支持避免域名污染,支持返回最快IP,支持广告过滤。"
|
msgstr "SmartDNS是一个本地高性能DNS服务器,支持避免域名污染,支持返回最快IP,支持广告过滤。"
|
||||||
|
|
||||||
|
msgid "Custom Settings"
|
||||||
|
msgstr "自定义设置"
|
||||||
|
|
||||||
msgid "Server Name"
|
msgid "Server Name"
|
||||||
msgstr "服务器名称"
|
msgstr "服务器名称"
|
||||||
|
|
||||||
@@ -67,6 +70,9 @@ msgstr "域名TTL最大值"
|
|||||||
msgid "Maximum TTL for all domain result."
|
msgid "Maximum TTL for all domain result."
|
||||||
msgstr "设置所有域名的TTL最大值"
|
msgstr "设置所有域名的TTL最大值"
|
||||||
|
|
||||||
|
msgid "smartdns custom settings"
|
||||||
|
msgstr "smartdns 自定义设置,具体配置参数参考指导"
|
||||||
|
|
||||||
msgid "Upstream Servers"
|
msgid "Upstream Servers"
|
||||||
msgstr "上游服务器"
|
msgstr "上游服务器"
|
||||||
|
|
||||||
|
|||||||
@@ -15,25 +15,28 @@ m:section(SimpleSection).template = "smartdns/smartdns_status"
|
|||||||
s = m:section(TypedSection, "smartdns", translate("Settings"), translate("General Settings"))
|
s = m:section(TypedSection, "smartdns", translate("Settings"), translate("General Settings"))
|
||||||
s.anonymous = true
|
s.anonymous = true
|
||||||
|
|
||||||
|
s:tab("settings", translate("General Settings"))
|
||||||
|
s:tab("custom", translate("Custom Settings"))
|
||||||
|
|
||||||
---- Eanble
|
---- Eanble
|
||||||
o = s:option(Flag, "enabled", translate("Enable"), translate("Enable or disable smartdns server"))
|
o = s:taboption("settings", Flag, "enabled", translate("Enable"), translate("Enable or disable smartdns server"))
|
||||||
o.default = o.disabled
|
o.default = o.disabled
|
||||||
o.rempty = false
|
o.rempty = false
|
||||||
|
|
||||||
---- server name
|
---- server name
|
||||||
o = s:option(Value, "server_name", translate("Server Name"), translate("Smartdns server name"))
|
o = s:taboption("settings", Value, "server_name", translate("Server Name"), translate("Smartdns server name"))
|
||||||
o.default = "smartdns"
|
o.default = "smartdns"
|
||||||
o.datatype = "hostname"
|
o.datatype = "hostname"
|
||||||
o.rempty = false
|
o.rempty = false
|
||||||
|
|
||||||
---- Port
|
---- Port
|
||||||
o = s:option(Value, "port", translate("Local Port"), translate("Smartdns local server port"))
|
o = s:taboption("settings", Value, "port", translate("Local Port"), translate("Smartdns local server port"))
|
||||||
o.placeholder = 5353
|
o.placeholder = 5353
|
||||||
o.default = 5353
|
o.default = 5353
|
||||||
o.datatype = "port"
|
o.datatype = "port"
|
||||||
o.rempty = false
|
o.rempty = false
|
||||||
|
|
||||||
o = s:option(Flag, "redirect", translate("Redirect"), translate("Redirect standard dns query from 53 to smartdns, as default DNS server"))
|
o = s:taboption("settings", Flag, "redirect", translate("Redirect"), translate("Redirect standard dns query from 53 to smartdns, as default DNS server"))
|
||||||
o.rmempty = false
|
o.rmempty = false
|
||||||
o.default = o.enabled
|
o.default = o.enabled
|
||||||
o.cfgvalue = function(...)
|
o.cfgvalue = function(...)
|
||||||
@@ -41,21 +44,40 @@ o.cfgvalue = function(...)
|
|||||||
end
|
end
|
||||||
|
|
||||||
---- cache-size
|
---- cache-size
|
||||||
o = s:option(Value, "cache_size", translate("Cache Size"), translate("DNS domain result cache size"))
|
o = s:taboption("settings", Value, "cache_size", translate("Cache Size"), translate("DNS domain result cache size"))
|
||||||
o.rempty = true
|
o.rempty = true
|
||||||
|
|
||||||
---- rr-ttl
|
---- rr-ttl
|
||||||
o = s:option(Value, "rr_ttl", translate("Domain TTL"), translate("TTL for all domain result."))
|
o = s:taboption("settings", Value, "rr_ttl", translate("Domain TTL"), translate("TTL for all domain result."))
|
||||||
o.rempty = true
|
o.rempty = true
|
||||||
|
|
||||||
---- rr-ttl-min
|
---- rr-ttl-min
|
||||||
o = s:option(Value, "rr_ttl_min", translate("Domain TTL Min"), translate("Minimum TTL for all domain result."))
|
o = s:taboption("settings", Value, "rr_ttl_min", translate("Domain TTL Min"), translate("Minimum TTL for all domain result."))
|
||||||
o.rempty = true
|
o.rempty = true
|
||||||
|
|
||||||
---- rr-ttl-max
|
---- rr-ttl-max
|
||||||
o = s:option(Value, "rr_ttl_max", translate("Domain TTL Max"), translate("Maximum TTL for all domain result."))
|
o = s:taboption("settings", Value, "rr_ttl_max", translate("Domain TTL Max"), translate("Maximum TTL for all domain result."))
|
||||||
o.rempty = true
|
o.rempty = true
|
||||||
|
|
||||||
|
|
||||||
|
----- custom settings
|
||||||
|
custom = s:taboption("custom", Value, "Custom Settings",
|
||||||
|
translate(""),
|
||||||
|
translate("smartdns custom settings"))
|
||||||
|
|
||||||
|
custom.template = "cbi/tvalue"
|
||||||
|
custom.rows = 20
|
||||||
|
|
||||||
|
function custom.cfgvalue(self, section)
|
||||||
|
return nixio.fs.readfile("/etc/smartdns/custom.conf")
|
||||||
|
end
|
||||||
|
|
||||||
|
function custom.write(self, section, value)
|
||||||
|
value = value:gsub("\r\n?", "\n")
|
||||||
|
nixio.fs.writefile("/etc/smartdns/custom.conf", value)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
-- Upstream servers
|
-- Upstream servers
|
||||||
s = m:section(TypedSection, "server", translate("Upstream Servers"), translate("Upstream Servers, support UDP, TCP protocol. " ..
|
s = m:section(TypedSection, "server", translate("Upstream Servers"), translate("Upstream Servers, support UDP, TCP protocol. " ..
|
||||||
"Please configure multiple DNS servers, including multiple foreign DNS servers."))
|
"Please configure multiple DNS servers, including multiple foreign DNS servers."))
|
||||||
|
|||||||
@@ -1 +1,3 @@
|
|||||||
/etc/config/smartdns
|
/etc/config/smartdns
|
||||||
|
/etc/smartdns/address.conf
|
||||||
|
/etc/smartdns/custom.conf
|
||||||
|
|||||||
11
package/openwrt/custom.conf
Normal file
11
package/openwrt/custom.conf
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
# Add custom settings here.
|
||||||
|
|
||||||
|
# set log level
|
||||||
|
# log-level [level], level=error, warn, info, debug
|
||||||
|
# log-level error
|
||||||
|
|
||||||
|
# log-size k,m,g
|
||||||
|
# log-size 128k
|
||||||
|
|
||||||
|
# log-file /var/log/smartdns.log
|
||||||
|
# log-num 2
|
||||||
@@ -8,6 +8,7 @@ SERVICE_DAEMONIZE=1
|
|||||||
BASECONFIGFILE="/etc/smartdns/smartdns.conf"
|
BASECONFIGFILE="/etc/smartdns/smartdns.conf"
|
||||||
SMARTDNS_CONF="/var/etc/smartdns.conf"
|
SMARTDNS_CONF="/var/etc/smartdns.conf"
|
||||||
ADDRESS_CONF="/etc/smartdns/address.conf"
|
ADDRESS_CONF="/etc/smartdns/address.conf"
|
||||||
|
CUSTOM_CONF="/etc/smartdns/custom.conf"
|
||||||
SMARTDNS_CONF_TMP="${SMARTDNS_CONF}.tmp"
|
SMARTDNS_CONF_TMP="${SMARTDNS_CONF}.tmp"
|
||||||
|
|
||||||
set_iptable()
|
set_iptable()
|
||||||
@@ -141,8 +142,8 @@ start_service() {
|
|||||||
|
|
||||||
config_foreach load_server "server"
|
config_foreach load_server "server"
|
||||||
|
|
||||||
echo "# address" >> $SMARTDNS_CONF_TMP
|
echo "conf-file $ADDRESS_CONF" >> $SMARTDNS_CONF_TMP
|
||||||
grep "^ *address " $ADDRESS_CONF >> $SMARTDNS_CONF_TMP
|
echo "conf-file $CUSTOM_CONF" >> $SMARTDNS_CONF_TMP
|
||||||
|
|
||||||
config_get_bool "enabled" "$section" "enabled" '0'
|
config_get_bool "enabled" "$section" "enabled" '0'
|
||||||
mv $SMARTDNS_CONF_TMP $SMARTDNS_CONF
|
mv $SMARTDNS_CONF_TMP $SMARTDNS_CONF
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ SMARTDNS_DIR=$CURR_DIR/../../
|
|||||||
SMARTDNS_BIN=$SMARTDNS_DIR/src/smartdns
|
SMARTDNS_BIN=$SMARTDNS_DIR/src/smartdns
|
||||||
SMARTDNS_CONF=$SMARTDNS_DIR/etc/smartdns/smartdns.conf
|
SMARTDNS_CONF=$SMARTDNS_DIR/etc/smartdns/smartdns.conf
|
||||||
ADDRESS_CONF=$CURR_DIR/address.conf
|
ADDRESS_CONF=$CURR_DIR/address.conf
|
||||||
|
CUSTOM_CONF=$CURR_DIR/custom.conf
|
||||||
|
|
||||||
showhelp()
|
showhelp()
|
||||||
{
|
{
|
||||||
@@ -32,6 +33,7 @@ build()
|
|||||||
|
|
||||||
cp $SMARTDNS_CONF $ROOT/root/etc/smartdns/
|
cp $SMARTDNS_CONF $ROOT/root/etc/smartdns/
|
||||||
cp $ADDRESS_CONF $ROOT/root/etc/smartdns/
|
cp $ADDRESS_CONF $ROOT/root/etc/smartdns/
|
||||||
|
cp $CUSTOM_CONF $ROOT/root/etc/smartdns/
|
||||||
cp $CURR_DIR/files/etc $ROOT/root/ -af
|
cp $CURR_DIR/files/etc $ROOT/root/ -af
|
||||||
cp $SMARTDNS_BIN $ROOT/root/usr/sbin
|
cp $SMARTDNS_BIN $ROOT/root/usr/sbin
|
||||||
|
|
||||||
|
|||||||
38
src/conf.c
38
src/conf.c
@@ -28,6 +28,8 @@ int dns_conf_rr_ttl;
|
|||||||
int dns_conf_rr_ttl_min;
|
int dns_conf_rr_ttl_min;
|
||||||
int dns_conf_rr_ttl_max;
|
int dns_conf_rr_ttl_max;
|
||||||
|
|
||||||
|
int load_conf_file(const char *file);
|
||||||
|
|
||||||
int config_bind(char *value)
|
int config_bind(char *value)
|
||||||
{
|
{
|
||||||
/* server bind address */
|
/* server bind address */
|
||||||
@@ -116,7 +118,12 @@ int config_address(char *value)
|
|||||||
|
|
||||||
memset(address, 0, sizeof(*address));
|
memset(address, 0, sizeof(*address));
|
||||||
len = end - begin;
|
len = end - begin;
|
||||||
memcpy(domain, begin, len);
|
memcpy(domain + 1, begin, len);
|
||||||
|
|
||||||
|
/* add dot for subdomain */
|
||||||
|
domain[0] = '.';
|
||||||
|
len++;
|
||||||
|
|
||||||
domain[len] = 0;
|
domain[len] = 0;
|
||||||
reverse_string(domain_key + 1, domain, len);
|
reverse_string(domain_key + 1, domain, len);
|
||||||
|
|
||||||
@@ -209,6 +216,8 @@ int config_log_level(char *value)
|
|||||||
dns_conf_log_level = TLOG_WARN;
|
dns_conf_log_level = TLOG_WARN;
|
||||||
} else if (strncmp("error", value, MAX_LINE_LEN) == 0) {
|
} else if (strncmp("error", value, MAX_LINE_LEN) == 0) {
|
||||||
dns_conf_log_level = TLOG_ERROR;
|
dns_conf_log_level = TLOG_ERROR;
|
||||||
|
} else {
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@@ -297,6 +306,18 @@ int config_rr_ttl_max(char *value)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int config_addtional_file(char *value)
|
||||||
|
{
|
||||||
|
char *file_path = value;
|
||||||
|
|
||||||
|
if (access(file_path, R_OK) != 0) {
|
||||||
|
tlog(TLOG_WARN, "conf file %s is not readable.", file_path);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return load_conf_file(file_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
struct config_item {
|
struct config_item {
|
||||||
const char *item;
|
const char *item;
|
||||||
@@ -318,6 +339,7 @@ struct config_item config_item[] = {
|
|||||||
{"rr-ttl", config_rr_ttl},
|
{"rr-ttl", config_rr_ttl},
|
||||||
{"rr-ttl-min", config_rr_ttl_min},
|
{"rr-ttl-min", config_rr_ttl_min},
|
||||||
{"rr-ttl-max", config_rr_ttl_max},
|
{"rr-ttl-max", config_rr_ttl_max},
|
||||||
|
{"conf-file", config_addtional_file},
|
||||||
};
|
};
|
||||||
int config_item_num = sizeof(config_item) / sizeof(struct config_item);
|
int config_item_num = sizeof(config_item) / sizeof(struct config_item);
|
||||||
|
|
||||||
@@ -333,7 +355,7 @@ void load_exit(void)
|
|||||||
config_address_destroy();
|
config_address_destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
int load_conf(const char *file)
|
int load_conf_file(const char *file)
|
||||||
{
|
{
|
||||||
FILE *fp = NULL;
|
FILE *fp = NULL;
|
||||||
char line[MAX_LINE_LEN];
|
char line[MAX_LINE_LEN];
|
||||||
@@ -343,8 +365,6 @@ int load_conf(const char *file)
|
|||||||
int line_num = 0;
|
int line_num = 0;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
load_conf_init();
|
|
||||||
|
|
||||||
fp = fopen(file, "r");
|
fp = fopen(file, "r");
|
||||||
if (fp == NULL) {
|
if (fp == NULL) {
|
||||||
tlog(TLOG_ERROR, "config file %s not exist.", file);
|
tlog(TLOG_ERROR, "config file %s not exist.", file);
|
||||||
@@ -386,9 +406,17 @@ int load_conf(const char *file)
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
errout:
|
errout:
|
||||||
printf("invalid config at line %d: %s", line_num, line);
|
printf("invalid config at file %s:%d, %s", file, line_num, line);
|
||||||
|
tlog(TLOG_ERROR, "invalid config at file %s:%d, %s", file, line_num, line);
|
||||||
if (fp) {
|
if (fp) {
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int load_conf(const char *file)
|
||||||
|
{
|
||||||
|
load_conf_init();
|
||||||
|
|
||||||
|
return load_conf_file(file);
|
||||||
|
}
|
||||||
|
|||||||
@@ -870,7 +870,7 @@ static void *_dns_client_work(void *arg)
|
|||||||
unsigned long now = {0};
|
unsigned long now = {0};
|
||||||
unsigned int sleep = 100;
|
unsigned int sleep = 100;
|
||||||
int sleep_time;
|
int sleep_time;
|
||||||
unsigned int expect_time = 0;
|
unsigned long expect_time = 0;
|
||||||
|
|
||||||
sleep_time = sleep;
|
sleep_time = sleep;
|
||||||
now = get_tick_count() - sleep;
|
now = get_tick_count() - sleep;
|
||||||
|
|||||||
@@ -773,6 +773,9 @@ static struct dns_address *_dns_server_get_address_by_domain(char *domain, int q
|
|||||||
reverse_string(domain_key + 1, domain, domain_len);
|
reverse_string(domain_key + 1, domain, domain_len);
|
||||||
domain_key[0] = type;
|
domain_key[0] = type;
|
||||||
domain_len++;
|
domain_len++;
|
||||||
|
domain_key[domain_len] = '.';
|
||||||
|
domain_len++;
|
||||||
|
domain_key[domain_len] = 0;
|
||||||
|
|
||||||
if (likely(dns_conf_log_level > TLOG_INFO)) {
|
if (likely(dns_conf_log_level > TLOG_INFO)) {
|
||||||
return art_substring(&dns_conf_address, (unsigned char *)domain_key, domain_len, NULL, NULL);
|
return art_substring(&dns_conf_address, (unsigned char *)domain_key, domain_len, NULL, NULL);
|
||||||
|
|||||||
@@ -182,11 +182,11 @@ int smartdns_init(void)
|
|||||||
char logname[DNS_MAX_PATH];
|
char logname[DNS_MAX_PATH];
|
||||||
|
|
||||||
if (dns_conf_log_file[0] != 0) {
|
if (dns_conf_log_file[0] != 0) {
|
||||||
strncpy(logdir, dns_conf_log_file, DNS_MAX_PATH);
|
char dns_log_file[DNS_MAX_PATH];
|
||||||
strncpy(logname, dns_conf_log_file, DNS_MAX_PATH);
|
strncpy(dns_log_file, dns_conf_log_file, DNS_MAX_PATH);
|
||||||
|
strncpy(logdir, dirname(dns_log_file), DNS_MAX_PATH);
|
||||||
dirname(logdir);
|
strncpy(dns_log_file, dns_conf_log_file, DNS_MAX_PATH);
|
||||||
basename(logname);
|
strncpy(logname, basename(dns_log_file), DNS_MAX_PATH);
|
||||||
} else {
|
} else {
|
||||||
strncpy(logdir, SMARTDNS_LOG_PATH, DNS_MAX_PATH);
|
strncpy(logdir, SMARTDNS_LOG_PATH, DNS_MAX_PATH);
|
||||||
strncpy(logname, SMARTDNS_LOG_FILE, DNS_MAX_PATH);
|
strncpy(logname, SMARTDNS_LOG_FILE, DNS_MAX_PATH);
|
||||||
|
|||||||
Reference in New Issue
Block a user