Optimize configuration, and add blacklist ip features

This commit is contained in:
Nick Peng
2018-12-14 20:50:07 +08:00
parent d6911608fc
commit 62f331c153
25 changed files with 1138 additions and 946 deletions

View File

@@ -121,12 +121,27 @@ msgstr "协议类型"
msgid "Domain Address"
msgstr "域名地址"
msgid "IP Blacklist Filtering"
msgstr "IP黑名单过滤"
msgid "Filtering IP with blacklist"
msgstr "使用IP黑名单过滤"
msgid "Set Specific domain ip address."
msgstr "指定特定域名的IP地址"
msgid "Specify an IP address to return for any host in the given domains, Queries in the domains are never forwarded and always replied to with the specified IP address which may be IPv4 or IPv6."
msgstr "配置特定域名返回特定的IP地址域名查询将不到上游服务器请求直接返回配置的IP地址可用于广告屏蔽。"
msgid "IP Blacklist"
msgstr "IP黑名单"
msgid "Set Specific ip blacklist."
msgstr "设置IP黑名单列表"
msgid "Configure IP blacklists that will be filtered from the results of specific DNS server."
msgstr "配置需要从指定域名服务器结果过滤的IP黑名单。"
msgid "Technical Support"
msgstr "技术支持"

View File

@@ -124,6 +124,14 @@ o:value("tls", translate("tls"))
o.default = "udp"
o.rempty = false
---- blacklist_ip
o = s:option(Flag, "blacklist_ip", translate("IP Blacklist Filtering"), translate("Filtering IP with blacklist"))
o.rmempty = false
o.default = o.disabled
o.cfgvalue = function(...)
return Flag.cfgvalue(...) or "0"
end
-- Doman addresss
s = m:section(TypedSection, "smartdns", translate("Domain Address"),
translate("Set Specific domain ip address."))
@@ -138,12 +146,34 @@ addr.template = "cbi/tvalue"
addr.rows = 20
function addr.cfgvalue(self, section)
return nixio.fs.readfile("/etc/smartdns/address.conf")
return nixio.fs.readfile("/var/etc/smartdns/address.conf")
end
function addr.write(self, section, value)
value = value:gsub("\r\n?", "\n")
nixio.fs.writefile("/etc/smartdns/address.conf", value)
nixio.fs.writefile("/var/etc/smartdns/address.conf", value)
end
-- IP Blacklist
s = m:section(TypedSection, "smartdns", translate("IP Blacklist"),
translate("Set Specific ip blacklist."))
s.anonymous = true
---- blacklist
addr = s:option(Value, "blacklist_ip",
translate(""),
translate("Configure IP blacklists that will be filtered from the results of specific DNS server."))
addr.template = "cbi/tvalue"
addr.rows = 20
function addr.cfgvalue(self, section)
return nixio.fs.readfile("/var/etc/smartdns/blacklist-ip.conf")
end
function addr.write(self, section, value)
value = value:gsub("\r\n?", "\n")
nixio.fs.writefile("/var/etc/smartdns/blacklist-ip.conf", value)
end
-- Doman addresss

View File

@@ -1,3 +1,3 @@
# Add domains which you want to force to an IP address here.
# The example below send any host in example.com to a local webserver.
#address /example.com/127.0.0.1
# address /example.com/127.0.0.1

View File

@@ -0,0 +1,4 @@
# Add IP blacklist which you want to filtering from some DNS server here.
# The example below filtering ip from the result of DNS server which is configured with -blacklist-ip.
# blacklist-ip [ip/subnet]
# blacklist-ip 254.0.0.1/16

View File

@@ -1,3 +1,4 @@
/etc/config/smartdns
/etc/smartdns/address.conf
/etc/smartdns/blacklist-ip.conf
/etc/smartdns/custom.conf

View File

@@ -2,11 +2,25 @@
chmod +x /usr/sbin/smartdns
chmod +x /etc/init.d/smartdns
mkdir -p /var/etc/smartdns/
[ "${IPKG_NO_SCRIPT}" = "1" ] && exit 0
if [ ! -f "/var/etc/smartdns/address.conf" ]; then
cp /etc/smartdns/address.conf /var/etc/smartdns/address.conf
fi
if [ ! -f "/var/etc/smartdns/blacklist-ip.conf" ]; then
cp /etc/smartdns/blacklist-ip.conf /var/etc/smartdns/blacklist-ip.conf
fi
if [ ! -f "/var/etc/smartdns/custom.conf" ]; then
cp /etc/smartdns/custom.conf /var/etc/smartdns/custom.conf
fi
. ${IPKG_INSTROOT}/lib/functions.sh
default_postinst $0 $@
ret=$?
/etc/init.d/smartdns enable
exit $ret
exit 0

View File

@@ -1,3 +1,6 @@
#!/bin/sh
. ${IPKG_INSTROOT}/lib/functions.sh
default_prerm $0 $@
rm /var/etc/smartdns.conf -f
rm /var/etc/smartdns/smartdns.conf -f
exit 0

View File

@@ -11,4 +11,4 @@
# log-num 2
# List of hosts that supply bogus NX domain results
# bogus-nxdomain [ip]
# bogus-nxdomain [ip/subnet]

View File

@@ -8,10 +8,13 @@ SERVICE_WRITE_PID=1
SERVICE_DAEMONIZE=1
SERVICE_PID_FILE="/var/run/smartdns.pid"
BASECONFIGFILE="/etc/smartdns/smartdns.conf"
SMARTDNS_CONF="/var/etc/smartdns.conf"
ADDRESS_CONF="/etc/smartdns/address.conf"
CUSTOM_CONF="/etc/smartdns/custom.conf"
SMARTDNS_CONF_DIR="/var/etc/smartdns"
SMARTDNS_CONF="$SMARTDNS_CONF_DIR/smartdns.conf"
ADDRESS_CONF="$SMARTDNS_CONF_DIR/address.conf"
BLACKLIST_IP_CONF="$SMARTDNS_CONF_DIR/blacklist-ip.conf"
CUSTOM_CONF="$SMARTDNS_CONF_DIR/custom.conf"
SMARTDNS_CONF_TMP="${SMARTDNS_CONF}.tmp"
COREDUMP="0"
set_forward_dnsmasq()
{
@@ -109,9 +112,11 @@ conf_append()
load_server()
{
local section="$1"
local ADDITIONAL_ARGS=""
config_get "port" "$section" "port" "53"
config_get "type" "$section" "type" "udp"
config_get "ip" "$section" "ip" ""
config_get "blacklist_ip" "$section" "blacklist_ip" "0"
if [ -z "$port" ] || [ -z "$ip" ] || [ -z "$type" ]; then
return
@@ -130,8 +135,11 @@ load_server()
fi
fi
conf_append "$SERVER" "$ip:$port"
if [ "$blacklist_ip" != "0" ]; then
ADDITIONAL_ARGS="$ADDITIONAL_ARGS -blacklist-ip"
fi
conf_append "$SERVER" "$ip:$port $ADDITIONAL_ARGS"
}
start_service() {
@@ -161,7 +169,7 @@ start_service() {
fi
SMARTDNS_PORT="$port"
mkdir -p $(dirname $SMARTDNS_CONF)
mkdir -p $SMARTDNS_CONF_DIR
config_get "cache_size" "$section" "cache_size" ""
if [ ! -z "$cache_size" ]; then
@@ -227,11 +235,16 @@ start_service() {
config_foreach load_server "server"
echo "conf-file $ADDRESS_CONF" >> $SMARTDNS_CONF_TMP
echo "conf-file $BLACKLIST_IP_CONF" >> $SMARTDNS_CONF_TMP
echo "conf-file $CUSTOM_CONF" >> $SMARTDNS_CONF_TMP
config_get_bool "enabled" "$section" "enabled" '0'
mv $SMARTDNS_CONF_TMP $SMARTDNS_CONF
[ "$enabled" -gt 0 ] || return 1
if [ "$COREDUMP" = "1" ]; then
args="$args -S"
ulimit -c unlimited
fi
service_start /usr/sbin/smartdns $args -c $SMARTDNS_CONF
}

View File

@@ -7,6 +7,7 @@ SMARTDNS_DIR=$CURR_DIR/../../
SMARTDNS_BIN=$SMARTDNS_DIR/src/smartdns
SMARTDNS_CONF=$SMARTDNS_DIR/etc/smartdns/smartdns.conf
ADDRESS_CONF=$CURR_DIR/address.conf
BLACKLIST_IP_CONF=$CURR_DIR/blacklist-ip.conf
CUSTOM_CONF=$CURR_DIR/custom.conf
showhelp()
@@ -33,6 +34,7 @@ build()
cp $SMARTDNS_CONF $ROOT/root/etc/smartdns/
cp $ADDRESS_CONF $ROOT/root/etc/smartdns/
cp $BLACKLIST_IP_CONF $ROOT/root/etc/smartdns/
cp $CUSTOM_CONF $ROOT/root/etc/smartdns/
cp $CURR_DIR/files/etc $ROOT/root/ -af
cp $SMARTDNS_BIN $ROOT/root/usr/sbin