Add luci for new feature, and fix some bugs

This commit is contained in:
Nick Peng
2018-12-25 01:55:37 +08:00
parent 11552f906f
commit 9398573e6f
10 changed files with 114 additions and 36 deletions

View File

@@ -9,10 +9,12 @@ function index()
end
local page
page = entry({"admin", "services", "smartdns"}, cbi("smartdns"), _("SmartDNS"), 60)
page = entry({"admin", "services", "smartdns"}, cbi("smartdns/smartdns"), _("SmartDNS"), 60)
page.dependent = true
page = entry({"admin", "services", "smartdns", "status"}, call("act_status"))
page.leaf = true
page = entry({"admin", "services", "smartdns", "upstream"}, cbi("smartdns/upstream"), nil)
page.leaf = true
end
local function is_running()

View File

@@ -55,6 +55,12 @@ msgstr "IPV6服务器"
msgid "Enable IPV6 DNS Server"
msgstr "启用IPV6服务器"
msgid "Dual-stack IP Selection"
msgstr "双栈IP优选"
msgid "Enable IP selection between IPV4 and IPV6"
msgstr "启用或禁用IPV4IPV6间的IP优选策略。"
msgid "Redirect"
msgstr "重定向"
@@ -127,6 +133,9 @@ msgstr "IP黑名单过滤"
msgid "Filtering IP with blacklist"
msgstr "使用IP黑名单过滤"
msgid "Upstream DNS Server Configuration"
msgstr "上游DNS服务器配置"
msgid "Set Specific domain ip address."
msgstr "指定特定域名的IP地址"

View File

@@ -52,6 +52,14 @@ o.cfgvalue = function(...)
return Flag.cfgvalue(...) or "1"
end
---- Support DualStack ip selection
o = s:taboption("settings", Flag, "dualstack_ip_selection", translate("Dual-stack IP Selection"), translate("Enable IP selection between IPV4 and IPV6"))
o.rmempty = false
o.default = o.disabled
o.cfgvalue = function(...)
return Flag.cfgvalue(...) or "0"
end
---- Redirect
o = s:taboption("settings", ListValue, "redirect", translate("Redirect"), translate("SmartDNS redirect mode"))
o.placeholder = "none"
@@ -102,6 +110,15 @@ s = m:section(TypedSection, "server", translate("Upstream Servers"), translate("
s.anonymous = true
s.addremove = true
s.template = "cbi/tblsection"
s.extedit = luci.dispatcher.build_url("admin/services/smartdns/upstream/%s")
---- enable flag
o = s:option(Flag, "enabled", translate("Enable"), translate("Enable"))
o.rmempty = false
o.default = o.enabled
o.cfgvalue = function(...)
return Flag.cfgvalue(...) or "1"
end
---- name
s:option(Value, "name", translate("Name"), translate("DNS Server name"))
@@ -124,14 +141,6 @@ 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."))

View File

@@ -0,0 +1,24 @@
local sid = arg[1]
m = Map("smartdns", "%s - %s" %{translate("SmartDNS Server"), translate("Upstream DNS Server Configuration")})
m.redirect = luci.dispatcher.build_url("admin/services/smartdns")
if m.uci:get("smartdns", sid) ~= "server" then
luci.http.redirect(m.redirect)
return
end
-- [[ Edit Server ]]--
s = m:section(NamedSection, sid, "server")
s.anonymous = true
s.addremove = 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
return m

View File

@@ -113,11 +113,16 @@ load_server()
{
local section="$1"
local ADDITIONAL_ARGS=""
config_get_bool "enabled" "$section" "enabled" "1"
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 [ "$enabled" = "0" ]; then
return
fi
if [ -z "$port" ] || [ -z "$ip" ] || [ -z "$type" ]; then
return
fi
@@ -167,6 +172,11 @@ start_service() {
conf_append "bind-tcp" ":$port"
fi
fi
config_get "dualstack_ip_selection" "$section" "dualstack_ip_selection" "0"
if [ "$dualstack_ip_selection" = "1" ]; then
conf_append "dualstack-ip-selection" "yes"
fi
SMARTDNS_PORT="$port"
mkdir -p $SMARTDNS_CONF_DIR
@@ -215,15 +225,26 @@ start_service() {
config_get "old_redirect" "$section" "old_redirect" "none"
config_get "old_port" "$section" "old_port" "0"
if [ "$old_redirect" != "none" ] && [ "$old_port" != "0" ]; then
if [ "$old_port" != "$SMARTDNS_PORT" ]; then
clear_iptable "$old_port" "$ipv6_server"
stop_forward_dnsmasq "$old_port"
if [ "$redirect" = "redirect" ]; then
set_iptable $ipv6_server $tcp_server
fi
fi
if [ "$redirect" = "redirect" ]; then
set_iptable $ipv6_server $tcp_server
elif [ "$redirect" = "dnsmasq-upstream" ]; then
set_forward_dnsmasq "$SMARTDNS_PORT"
if [ "$old_redirect" != "$redirect" ]; then
if [ "$old_redirect" != "none" ]; then
if [ "$old_port" != "0" ]; then
clear_iptable "$old_port" "$ipv6_server"
fi
stop_forward_dnsmasq "$old_port"
fi
if [ "$redirect" = "redirect" ]; then
set_iptable $ipv6_server $tcp_server
elif [ "$redirect" = "dnsmasq-upstream" ]; then
set_forward_dnsmasq "$SMARTDNS_PORT"
fi
fi
uci delete smartdns.@smartdns[0].old_redirect 2>/dev/null

View File

@@ -51,7 +51,7 @@ case "$1" in
fi
;;
status)
pid="`cat $SMARTDNS_PID 2>/dev/null`"
pid="`cat $SMARTDNS_PID |head -n 1 2>/dev/null`"
if [ -z "$pid" ]; then
echo "smartdns not running."
return 0
@@ -66,7 +66,16 @@ case "$1" in
;;
stop)
clear_iptable
pid="`cat $SMARTDNS_PID 2>/dev/null`"
pid="`cat $SMARTDNS_PID | head -n 1 2>/dev/null`"
if [ -z "$pid" ]; then
echo "smartdns not running."
return 0
fi
if [ ! -d "/proc/$pid" ]; then
return 0;
fi
kill -9 $pid 2>/dev/null
;;
force-reload|restart)