update 2026-10-29 11:59:06

This commit is contained in:
action committed 2026-10-29 11:59:06 +08:00
1 parent bc85557d34
commit e2f86e09f4
5033 files changed
-2043160

No files matched your search

@@ -1,51 +0,0 @@
module("luci.controller.dnsfilter", package.seeall)
function index()
if not nixio.fs.access("/etc/config/dnsfilter") then
return
end
local page = entry({"admin", "services", "dnsfilter"}, alias("admin", "services", "dnsfilter", "base"), _("DNS Filter"), 9)
page.dependent = true
page.acl_depends = { "luci-app-dnsfilter" }
entry({"admin", "services", "dnsfilter", "base"}, cbi("dnsfilter/base"), _("Base Setting"), 10).leaf = true
entry({"admin", "services", "dnsfilter", "white"}, form("dnsfilter/white"), _("White Domain List"), 20).leaf = true
entry({"admin", "services", "dnsfilter", "black"}, form("dnsfilter/black"), _("Block Domain List"), 30).leaf = true
entry({"admin", "services", "dnsfilter", "ip"}, form("dnsfilter/ip"), _("Block IP List"), 40).leaf = true
entry({"admin", "services", "dnsfilter", "log"}, form("dnsfilter/log"), _("Update Log"), 50).leaf = true
entry({"admin", "services", "dnsfilter", "run"}, call("act_status")).leaf = true
entry({"admin", "services", "dnsfilter", "refresh"}, call("refresh_data"))
end
function act_status()
local e = {}
e.running = luci.sys.call("[ -s /tmp/dnsmasq.dnsfilter/rules.conf ]") == 0
luci.http.prepare_content("application/json")
luci.http.write_json(e)
end
function refresh_data()
local set = luci.http.formvalue("set")
local icount = 0
luci.sys.exec("/usr/share/dnsfilter/dnsfilter down")
icount = luci.sys.exec("find /tmp/ad_tmp -type f -name rules.conf -exec cat {} \\; 2>/dev/null | wc -l")
if tonumber(icount)>0 then
oldcount = luci.sys.exec("find /tmp/dnsfilter -type f -name rules.conf -exec cat {} \\; 2>/dev/null | wc -l")
if tonumber(icount) ~= tonumber(oldcount) then
luci.sys.exec("[ -h /tmp/dnsfilter/url ] && (rm -f /etc/dnsfilter/rules/*;cp -a /tmp/ad_tmp/* /etc/dnsfilter/rules) || (rm -f /tmp/dnsfilter/*;cp -a /tmp/ad_tmp/* /tmp/dnsfilter)")
luci.sys.exec("/etc/init.d/dnsfilter restart &")
retstring = tostring(math.ceil(tonumber(icount)))
else
retstring = 0
end
luci.sys.call("echo `date +'%Y-%m-%d %H:%M:%S'` > /tmp/dnsfilter/dnsfilter.updated")
else
retstring = "-1"
end
luci.sys.exec("rm -rf /tmp/ad_tmp")
luci.http.prepare_content("application/json")
luci.http.write_json({ret=retstring,retcount=icount})
end
@@ -1,84 +0,0 @@
local SYS = require "luci.sys"
m = Map("dnsfilter")
m.title = translate("DNS Filter")
m.description = translate("Support AdGuardHome/Host/DNSMASQ/Domain Rules")
m:section(SimpleSection).template = "dnsfilter/dnsfilter_status"
s = m:section(TypedSection, "dnsfilter")
s.anonymous = true
o = s:option(Flag, "enable", translate("Enable"))
o.rmempty = false
o = s:option(Flag, "block_ios", translate("Block Apple iOS OTA update"))
o.rmempty = false
o.default = 0
o = s:option(Flag, "block_cnshort", translate("Block CNshort APP and Website"))
o.rmempty = false
o.default = 0
o = s:option(Flag, "safe_search", translate("Safe Search"))
o.description = translate("Enforcing SafeSearch for Google Bing Duckduckgo Yandex and Youtube.")
o.rmempty = false
o.default = 0
o = s:option(Flag, "cron_mode", translate("Enable automatic update rules"))
o.rmempty = false
o.default = 1
o = s:option(ListValue, "time_update", translate("Update time (every day)"))
for s = 0,23 do
o:value(s, s .. ':00')
end
o.default = 6
o:depends("cron_mode",1)
tmp_rule = 0
if nixio.fs.access("/tmp/dnsfilter/rules.conf") then
tmp_rule = 1
UD = SYS.exec("cat /tmp/dnsfilter/dnsfilter.updated 2>/dev/null")
rule_count = tonumber(SYS.exec("find /tmp/dnsfilter -exec cat {} \\; 2>/dev/null | wc -l"))
o = s:option(DummyValue, "1", translate("Subscribe Rules Data"))
o.rawhtml = true
o.template = "dnsfilter/dnsfilter_refresh"
o.value = rule_count.." "..translate("Records")
o.description = string.format(translate("AdGuardHome / Host / DNSMASQ / Domain rules auto-convert").."<br/><strong>"..translate("Last Update Checked")..":</strong> %s<br/>",UD)
end
o = s:option(Flag, "flash", translate("Save rules to flash"))
o.description = translate("Should be enabled when rules addresses are slow to download")
o.rmempty = false
o.default = 0
if tmp_rule == 1 then
o = s:option(Button, "delete", translate("Delete All Subscribe Rules"))
o.inputstyle = "reset"
o.description = translate("Delete rules files and delete the subscription link<br/>There is no need to click for modify the subscription link,The script will automatically replace the old rule file")
o.write = function()
SYS.exec("[ -d /etc/dnsfilter/rules ] && rm -rf /etc/dnsfilter/rules")
SYS.exec("grep -wq 'list url' /etc/config/dnsfilter && sed -i '/list url/d' /etc/config/dnsfilter && /etc/init.d/dnsfilter restart 2>&1 &")
luci.http.redirect(luci.dispatcher.build_url("admin", "services", "dnsfilter", "base"))
end
end
if luci.sys.call("[ -h /tmp/dnsfilter/url ] || exit 9") == 9 then
if nixio.fs.access("/etc/dnsfilter/rules") then
o = s:option(Button, "delete_1", translate("Delete Subscribe Rules On The Flash"))
o.inputstyle = "reset"
o.write = function()
SYS.exec("rm -rf /etc/dnsfilter/rules")
luci.http.redirect(luci.dispatcher.build_url("admin", "services", "dnsfilter", "base"))
end
end
end
o = s:option(DynamicList, "url", translate("Anti-AD Rules Subscribe"))
o:value("https://anti-ad.net/anti-ad-for-dnsmasq.conf", translate("anti-AD"))
o:value("https://adguardteam.github.io/AdGuardSDNSFilter/Filters/filter.txt", translate("AdGuard"))
o:value("https://easylist-downloads.adblockplus.org/easylistchina+easylist.txt", translate("Easylistchina+Easylist"))
o:value("https://block.energized.pro/extensions/porn-lite/formats/domains.txt", translate("Anti-Porn"))
o.default = "https://anti-ad.net/anti-ad-for-dnsmasq.conf"
return m
@@ -1,26 +0,0 @@
local fs = require "nixio.fs"
local conffile = "/etc/dnsfilter/black.list"
f = SimpleForm("custom")
t = f:field(TextValue, "conf")
t.rmempty = true
t.rows = 13
t.description = translate("Will Always block these Domain")
function t.cfgvalue()
return fs.readfile(conffile) or ""
end
function f.handle(self,state,data)
if state == FORM_VALID then
if data.conf then
fs.writefile(conffile,data.conf:gsub("\r\n","\n"))
else
luci.sys.call("> /etc/dnsfilter/black.list")
end
luci.sys.exec("[ \"$(uci -q get dnsfilter.@dnsfilter[0].enable)\" = 1 ] && /etc/init.d/dnsfilter restart")
end
return true
end
return f
@@ -1,26 +0,0 @@
local fs = require "nixio.fs"
local conffile = "/etc/dnsfilter/ip.list"
f = SimpleForm("custom")
t = f:field(TextValue, "conf")
t.rmempty = true
t.rows = 13
t.description = translate("Will Always block these IP")
function t.cfgvalue()
return fs.readfile(conffile) or ""
end
function f.handle(self,state,data)
if state == FORM_VALID then
if data.conf then
fs.writefile(conffile,data.conf:gsub("\r\n","\n"))
else
luci.sys.call("> /etc/dnsfilter/ip.list")
end
luci.sys.exec("ipset -F blockip 2>/dev/null && for i in $(cat /etc/dnsfilter/ip.list);do ipset add blockip $i 2>/dev/null;done")
end
return true
end
return f
@@ -1,16 +0,0 @@
local fs = require "nixio.fs"
local conffile = "/tmp/adupdate.log"
f = SimpleForm("logview")
f.reset = false
f.submit = false
t = f:field(TextValue, "conf")
t.rmempty = true
t.rows = 20
function t.cfgvalue()
return fs.readfile(conffile) or ""
end
t.readonly = "readonly"
return f
@@ -1,28 +0,0 @@
local fs = require "nixio.fs"
local conffile = "/etc/dnsfilter/white.list"
f = SimpleForm("custom")
t = f:field(TextValue, "conf")
t.rmempty = true
t.rows = 13
t.description = translate("Will Never filter these Domain")
function t.cfgvalue()
return fs.readfile(conffile) or ""
end
function f.handle(self,state,data)
if state == FORM_VALID then
if data.conf then
fs.writefile(conffile,data.conf:gsub("\r\n","\n"))
else
luci.sys.call("> /etc/dnsfilter/white.list")
end
luci.sys.exec("for i in $(cat /etc/dnsfilter/white.list);do sed -i -e \"/\\/$i\\//d\" -e \"/\\.$i\\//d\" /tmp/dnsfilter/rules.conf 2>/dev/null;\\\
[ -s /etc/dnsfilter/rules/rules.conf ] && sed -i -e \"/\\/$i\\//d\" -e \"/\\.$i\\//d\" /etc/dnsfilter/rules/rules.conf;done;\\\
[ -s /tmp/dnsfilter/rules.conf ] && rm -f /tmp/dnsmasq.dnsfilter/rules.conf && /etc/init.d/dnsfilter start")
end
return true
end
return f
@@ -1,34 +0,0 @@
<%+cbi/valueheader%>
<script type="text/javascript">//<![CDATA[
function refresh_data(btn,dataname)
{
btn.disabled=true;
btn.value='<%:Refresh...%>';
murl=dataname;
XHR.get('<%=luci.dispatcher.build_url("admin","services","dnsfilter","refresh")%>',
{set:murl},
function(x,rv)
{
var s=document.getElementById(dataname+'-status');
if (s)
{
if (rv.ret=="0")
s.innerHTML="<font color='green'>"+"<%:No new data!%> "+"</font>";
else if(rv.ret=="-1")
{
s.innerHTML="<font color='red'>"+"<%:Refresh Error!%> "+"</font>";
}
else{
s.innerHTML="<font color='green'>"+"<%:Refresh OK!%> "+"<%:Total Records:%>"+rv.ret+"</font>";
}
}
btn.disabled=false;
btn.value='<%:Refresh Data%>';
}
);
return false;
}
//]]></script>
<input type="button" class="cbi-button cbi-input-reload" value="<%:Refresh Data%>" onclick="return refresh_data(this,'<%=self.option%>')"/>
<span id="<%=self.option%>-status"><em><%=self.value%></em></span>
<%+cbi/valuefooter%>
@@ -1,21 +0,0 @@
<script type="text/javascript">//<![CDATA[
XHR.poll(3,'<%=url([[admin]],[[services]],[[dnsfilter]],[[run]])%>',null,
function(x,data){
var tb=document.getElementById('dnsfilter_status');
if (data&&tb){
if (data.running){
tb.innerHTML='<em><b><font color=green>DNS Filter <%:RUNNING%></font></b></em>';
}else{
tb.innerHTML='<em><b><font color=red>DNS Filter <%:NOT RUNNING%></font></b></em>';
}
}
}
);
//]]>
</script>
<style>.mar-10{margin-left:50px;margin-right:10px;}</style>
<fieldset class="cbi-section">
<p id="dnsfilter_status">
<em><%:Collecting data...%></em>
</p>
</fieldset>