Add redirect check
This commit is contained in:
@@ -216,6 +216,9 @@ Non-authoritative answer:
|
|||||||
* 如已经安装chinaDNS,建议将chinaDNS的上游配置为SmartDNS。
|
* 如已经安装chinaDNS,建议将chinaDNS的上游配置为SmartDNS。
|
||||||
* SmartDNS默认情况,将53端口的请求转发到SmartDNS的本地端口,由`Redirect`配置选项控制。
|
* SmartDNS默认情况,将53端口的请求转发到SmartDNS的本地端口,由`Redirect`配置选项控制。
|
||||||
|
|
||||||
|
6. 界面提示重定向失败:
|
||||||
|
* openwrt 15.01系统不支持IPV6重定向,如网络需要支持IPV6,请将DNSMASQ上游改为smartdns,或者将smartdns的端口改为53,并停用dnsmasq。
|
||||||
|
* LEDE之后系统,请安装IPV6的nat转发驱动。点击`system`->`Software`,点击`update lists`更新软件列表后,安装`ip6tables-mod-nat`
|
||||||
|
|
||||||
华硕路由器原生固件
|
华硕路由器原生固件
|
||||||
--------------
|
--------------
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
-- Copyright 2018 Nick Peng (pymumu@gmail.com)
|
-- Copyright 2018 Nick Peng (pymumu@gmail.com)
|
||||||
|
|
||||||
module("luci.controller.smartdns", package.seeall)
|
module("luci.controller.smartdns", package.seeall)
|
||||||
|
local smartdns = require "luci.model.smartdns"
|
||||||
|
|
||||||
function index()
|
function index()
|
||||||
if not nixio.fs.access("/etc/config/smartdns") then
|
if not nixio.fs.access("/etc/config/smartdns") then
|
||||||
@@ -17,9 +18,23 @@ end
|
|||||||
local function is_running()
|
local function is_running()
|
||||||
return luci.sys.call("pidof smartdns >/dev/null") == 0
|
return luci.sys.call("pidof smartdns >/dev/null") == 0
|
||||||
end
|
end
|
||||||
|
|
||||||
function act_status()
|
function act_status()
|
||||||
local e={}
|
local e={}
|
||||||
|
e.ipv6_works = 2;
|
||||||
|
e.ipv4_works = 2;
|
||||||
|
e.redirect = smartdns.get_config_option("smartdns", "smartdns", "redirect", nil);
|
||||||
|
e.local_port = smartdns.get_config_option("smartdns", "smartdns", "port", nil);
|
||||||
|
if e.redirect == "1" 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.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
|
||||||
|
else
|
||||||
|
e.redirect = 0
|
||||||
|
end
|
||||||
|
end
|
||||||
e.running = is_running()
|
e.running = is_running()
|
||||||
|
|
||||||
luci.http.prepare_content("application/json")
|
luci.http.prepare_content("application/json")
|
||||||
luci.http.write_json(e)
|
luci.http.write_json(e)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -31,6 +31,12 @@ msgstr "本地端口"
|
|||||||
msgid "Smartdns local server port"
|
msgid "Smartdns local server port"
|
||||||
msgstr "SmartDNS本地服务端口"
|
msgstr "SmartDNS本地服务端口"
|
||||||
|
|
||||||
|
msgid "IPV4 53 Port Redirect Failure"
|
||||||
|
msgstr "IPV4 53端口重定向失败"
|
||||||
|
|
||||||
|
msgid "IPV6 53 Port Redirect Failure"
|
||||||
|
msgstr "IPV6 53端口重定向失败"
|
||||||
|
|
||||||
msgid "Redirect"
|
msgid "Redirect"
|
||||||
msgstr "重定向"
|
msgstr "重定向"
|
||||||
|
|
||||||
|
|||||||
17
package/luci/files/luci/model/smartdns.lua
Normal file
17
package/luci/files/luci/model/smartdns.lua
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
-- Copyright 2018 Nick Peng (pymumu@gmail.com)
|
||||||
|
|
||||||
|
require ("nixio.fs")
|
||||||
|
require ("luci.http")
|
||||||
|
require ("luci.dispatcher")
|
||||||
|
require ("nixio.fs")
|
||||||
|
|
||||||
|
local uci = require "luci.model.uci".cursor()
|
||||||
|
|
||||||
|
module("luci.model.smartdns", package.seeall)
|
||||||
|
|
||||||
|
function get_config_option(module, section, option, default)
|
||||||
|
return uci:get_first(module, section, option) or default
|
||||||
|
end
|
||||||
|
|
||||||
|
return m
|
||||||
|
|
||||||
@@ -3,12 +3,23 @@ XHR.poll(3, '<%=luci.dispatcher.build_url("admin", "services", "smartdns", "stat
|
|||||||
function(x, data) {
|
function(x, data) {
|
||||||
var tb = document.getElementById('smartdns_status');
|
var tb = document.getElementById('smartdns_status');
|
||||||
if (data && tb) {
|
if (data && tb) {
|
||||||
|
var links = "";
|
||||||
if (data.running) {
|
if (data.running) {
|
||||||
var links = '<b><font color=green>SmartDNS - <%:RUNNING%></font></b></em>';
|
links = '<b><font color=green>SmartDNS - <%:RUNNING%></font></b></em>';
|
||||||
tb.innerHTML = links;
|
if (data.redirect && data.redirect == 1) {
|
||||||
|
if (data.ipv4_works == 0) {
|
||||||
|
links += "<br></br><b><font color=red><%:IPV4 53 Port Redirect Failure%></font></b>"
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data.ipv6_works == 0) {
|
||||||
|
links += "<br></br><b><font color=red><%:IPV6 53 Port Redirect Failure%></font></b>"
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
tb.innerHTML = '<b><font color=red>SmartDNS - <%:NOT RUNNING%></font></b>';
|
links = '<b><font color=red>SmartDNS - <%:NOT RUNNING%></font></b>';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tb.innerHTML = links;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -18,6 +18,12 @@ set_iptable()
|
|||||||
iptables -t nat -A PREROUTING -p udp -d $IP --dport 53 -j REDIRECT --to-ports $SMARTDNS_PORT >/dev/null 2>&1
|
iptables -t nat -A PREROUTING -p udp -d $IP --dport 53 -j REDIRECT --to-ports $SMARTDNS_PORT >/dev/null 2>&1
|
||||||
done
|
done
|
||||||
|
|
||||||
|
IPS="`ifconfig | grep "inet6 addr" | grep -v " fe80::" | grep -v " ::1" | grep "Global" | awk '{print $3}'`"
|
||||||
|
for IP in $IPS
|
||||||
|
do
|
||||||
|
ip6tables -t nat -A PREROUTING -p udp -d $IP --dport 53 -j REDIRECT --to-ports $SMARTDNS_PORT >/dev/null 2>&1
|
||||||
|
done
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
clear_iptable()
|
clear_iptable()
|
||||||
@@ -27,6 +33,12 @@ clear_iptable()
|
|||||||
do
|
do
|
||||||
iptables -t nat -D PREROUTING -p udp -d $IP --dport 53 -j REDIRECT --to-ports $SMARTDNS_PORT >/dev/null 2>&1
|
iptables -t nat -D PREROUTING -p udp -d $IP --dport 53 -j REDIRECT --to-ports $SMARTDNS_PORT >/dev/null 2>&1
|
||||||
done
|
done
|
||||||
|
|
||||||
|
IPS="`ifconfig | grep "inet6 addr" | grep -v " fe80::" | grep -v " ::1" | grep "Global" | awk '{print $3}'`"
|
||||||
|
for IP in $IPS
|
||||||
|
do
|
||||||
|
ip6tables -t nat -D PREROUTING -p udp -d $IP --dport 53 -j REDIRECT --to-ports $SMARTDNS_PORT >/dev/null 2>&1
|
||||||
|
done
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user