🐶 Sync 2025-11-02 14:26:26
This commit is contained in:
345
luci-app-adguardhome/luasrc/model/cbi/AdGuardHome/base.lua
Normal file
345
luci-app-adguardhome/luasrc/model/cbi/AdGuardHome/base.lua
Normal file
@@ -0,0 +1,345 @@
|
||||
require("luci.sys")
|
||||
require("luci.util")
|
||||
require("io")
|
||||
local m,s,o,o1
|
||||
local fs=require"nixio.fs"
|
||||
local uci=require"luci.model.uci".cursor()
|
||||
local configpath=uci:get("AdGuardHome","AdGuardHome","configpath") or "/etc/AdGuardHome.yaml"
|
||||
local binpath=uci:get("AdGuardHome","AdGuardHome","binpath") or "/usr/bin/AdGuardHome"
|
||||
httpport=uci:get("AdGuardHome","AdGuardHome","httpport") or "3000"
|
||||
m = Map("AdGuardHome", "AdGuard Home")
|
||||
m.description = translate("Free and open source, powerful network-wide ads & trackers blocking DNS server.")
|
||||
m:section(SimpleSection).template = "AdGuardHome/AdGuardHome_status"
|
||||
|
||||
s = m:section(TypedSection, "AdGuardHome")
|
||||
s.anonymous=true
|
||||
s.addremove=false
|
||||
|
||||
---- Basic Settings ----
|
||||
s:tab("basic", translate("Main Config"))
|
||||
|
||||
o = s:taboption("basic", Flag, "enabled", translate("Enable"))
|
||||
o.default = 0
|
||||
o.optional = false
|
||||
|
||||
o = s:taboption("basic", Value,"httpport",translate("Browser management port"))
|
||||
o.placeholder=3000
|
||||
o.default=3000
|
||||
o.datatype="port"
|
||||
o.optional = false
|
||||
|
||||
local binmtime=uci:get("AdGuardHome","AdGuardHome","binmtime") or "0"
|
||||
|
||||
local e=""
|
||||
if not fs.access(configpath) then e = e .. " " .. translate("no config") end
|
||||
if not fs.access(binpath) then
|
||||
e=e.." "..translate("no core")
|
||||
else
|
||||
local version=uci:get("AdGuardHome","AdGuardHome","version")
|
||||
local testtime=fs.stat(binpath,"mtime")
|
||||
if testtime~=tonumber(binmtime) or version==nil then
|
||||
|
||||
version = luci.sys.exec(string.format("echo -n $(%s --version 2>&1 | awk -F 'version ' '{print $2}' | awk -F ',' '{print $1}')", binpath))
|
||||
if version == "" then version = "core error" end
|
||||
uci:set("AdGuardHome", "AdGuardHome", "version", version)
|
||||
uci:set("AdGuardHome", "AdGuardHome", "binmtime", testtime)
|
||||
uci:commit("AdGuardHome")
|
||||
end
|
||||
e=version..e
|
||||
end
|
||||
|
||||
o = s:taboption("basic", ListValue, "core_version", translate("Core Version"))
|
||||
o:value("latest", translate("Latest Version"))
|
||||
o:value("beta", translate("Beta Version"))
|
||||
o.default = "latest"
|
||||
o = s:taboption("basic", Button, "restart", translate("Upgrade Core"))
|
||||
o.inputtitle=translate("Update core version")
|
||||
o.template = "AdGuardHome/AdGuardHome_check"
|
||||
o.showfastconfig=(not fs.access(configpath))
|
||||
o.description = string.format(translate("Current core version:") .. "<strong><font id='updateversion' color='green'>%s </font></strong>", e)
|
||||
|
||||
local port=luci.sys.exec("grep -A 5 '^dns:' "..configpath.." | grep 'port:' | awk '{print $2}' 2>nul")
|
||||
if (port=="") then port="?" end
|
||||
|
||||
o = s:taboption("basic", ListValue, "redirect", port..translate("Redirect"), translate("AdGuardHome redirect mode"))
|
||||
o:value("none", translate("none"))
|
||||
o:value("dnsmasq-upstream", translate("Run as dnsmasq upstream server"))
|
||||
o:value("redirect", translate("Redirect 53 port to AdGuardHome"))
|
||||
o:value("exchange", translate("Use port 53 replace dnsmasq"))
|
||||
o.default = "none"
|
||||
o.optional = true
|
||||
---- chpass
|
||||
o = s:taboption("basic",Value, "hashpass", translate("Change management password"), translate("Press load culculate model and culculate finally save/apply"))
|
||||
o.default = ""
|
||||
o.datatype = "string"
|
||||
o.template = "AdGuardHome/AdGuardHome_chpass"
|
||||
o.optional = true
|
||||
|
||||
-- wait net on boot
|
||||
o = s:taboption("basic", Flag, "waitonboot", translate("Start up only when the network is normal"))
|
||||
o.default = 1
|
||||
o.optional = false
|
||||
|
||||
---- Core Settings ----
|
||||
s:tab("core", translate("Core Config"))
|
||||
|
||||
o = s:taboption("core",Value, "binpath", translate("Bin Path"), translate("AdGuardHome Bin path if no bin will auto download"))
|
||||
o.default = "/usr/bin/AdGuardHome"
|
||||
o.datatype = "string"
|
||||
o.optional = false
|
||||
o.rmempty=false
|
||||
o.validate=function(self, value)
|
||||
if value=="" then return nil end
|
||||
if fs.stat(value,"type")=="dir" then
|
||||
fs.rmdir(value)
|
||||
end
|
||||
if fs.stat(value,"type")=="dir" then
|
||||
if (m.message) then
|
||||
m.message =m.message.."\nerror!bin path is a dir"
|
||||
else
|
||||
m.message ="error!bin path is a dir"
|
||||
end
|
||||
return nil
|
||||
end
|
||||
return value
|
||||
end
|
||||
--- upx
|
||||
o = s:taboption("core",ListValue, "upxflag", translate("use upx to compress bin after download"))
|
||||
o:value("", translate("none"))
|
||||
o:value("-1", translate("compress faster"))
|
||||
o:value("-9", translate("compress better"))
|
||||
o:value("--best", translate("compress best(can be slow for big files)"))
|
||||
o:value("--brute", translate("try all available compression methods & filters [slow]"))
|
||||
o:value("--ultra-brute", translate("try even more compression variants [very slow]"))
|
||||
o.default = ""
|
||||
o.description=translate("bin use less space,but may have compatibility issues")
|
||||
o.rmempty = true
|
||||
---- config path
|
||||
o = s:taboption("core",Value, "configpath", translate("Config Path"), translate("AdGuardHome config path"))
|
||||
o.default = "/etc/AdGuardHome.yaml"
|
||||
o.datatype = "string"
|
||||
o.optional = false
|
||||
o.rmempty=false
|
||||
o.validate=function(self, value)
|
||||
if value==nil then return nil end
|
||||
if fs.stat(value,"type")=="dir" then
|
||||
fs.rmdir(value)
|
||||
end
|
||||
if fs.stat(value,"type")=="dir" then
|
||||
if m.message then
|
||||
m.message =m.message.."\nerror!config path is a dir"
|
||||
else
|
||||
m.message ="error!config path is a dir"
|
||||
end
|
||||
return nil
|
||||
end
|
||||
return value
|
||||
end
|
||||
---- work dir
|
||||
o = s:taboption("core",Value, "workdir", translate("Work dir"), translate("AdGuardHome work dir include rules,audit log and database"))
|
||||
o.default = "/etc/AdGuardHome"
|
||||
o.datatype = "string"
|
||||
o.optional = false
|
||||
o.rmempty=false
|
||||
o.validate=function(self, value)
|
||||
if value=="" then return nil end
|
||||
if fs.stat(value,"type")=="reg" then
|
||||
if m.message then
|
||||
m.message =m.message.."\nerror!work dir is a file"
|
||||
else
|
||||
m.message ="error!work dir is a file"
|
||||
end
|
||||
return nil
|
||||
end
|
||||
if string.sub(value, -1)=="/" then
|
||||
return string.sub(value, 1, -2)
|
||||
else
|
||||
return value
|
||||
end
|
||||
end
|
||||
---- log file
|
||||
o = s:taboption("core",Value, "logfile", translate("Runtime log file"), translate("AdGuardHome runtime Log file if 'syslog': write to system log;if empty no log"))
|
||||
o.datatype = "string"
|
||||
o.rmempty = true
|
||||
o.validate=function(self, value)
|
||||
if fs.stat(value,"type")=="dir" then
|
||||
fs.rmdir(value)
|
||||
end
|
||||
if fs.stat(value,"type")=="dir" then
|
||||
if m.message then
|
||||
m.message =m.message.."\nerror!log file is a dir"
|
||||
else
|
||||
m.message ="error!log file is a dir"
|
||||
end
|
||||
return nil
|
||||
end
|
||||
return value
|
||||
end
|
||||
---- debug
|
||||
o = s:taboption("core",Flag, "verbose", translate("Verbose log"))
|
||||
o.default = 0
|
||||
o.optional = true
|
||||
---- gfwlist
|
||||
local a=luci.sys.call("grep -m 1 -q programadd "..configpath)
|
||||
if (a==0) then
|
||||
a="Added"
|
||||
else
|
||||
a="Not added"
|
||||
end
|
||||
|
||||
---- Backup Settings ----
|
||||
s:tab("other", translate("Other Config"))
|
||||
|
||||
---- upgrade protect
|
||||
o = s:taboption("other", DynamicList, "upprotect", translate("Keep files when system upgrade"))
|
||||
o:value("$binpath",translate("core bin"))
|
||||
o:value("$configpath",translate("config file"))
|
||||
o:value("$logfile",translate("log file"))
|
||||
o:value("$workdir/data/sessions.db",translate("sessions.db"))
|
||||
o:value("$workdir/data/stats.db",translate("stats.db"))
|
||||
o:value("$workdir/data/querylog.json",translate("querylog.json"))
|
||||
o:value("$workdir/data/filters",translate("filters"))
|
||||
o.widget = "checkbox"
|
||||
o.default = nil
|
||||
o.optional=true
|
||||
|
||||
---- backup workdir on shutdown
|
||||
local workdir=uci:get("AdGuardHome","AdGuardHome","workdir") or "/etc/AdGuardHome"
|
||||
o = s:taboption("other",MultiValue, "backupfile", translate("Backup workdir files when shutdown"))
|
||||
o1 = s:taboption("other",Value, "backupwdpath", translate("Backup workdir path"))
|
||||
local name
|
||||
o:value("filters","filters")
|
||||
o:value("stats.db","stats.db")
|
||||
o:value("querylog.json","querylog.json")
|
||||
o:value("sessions.db","sessions.db")
|
||||
o1:depends ("backupfile", "filters")
|
||||
o1:depends ("backupfile", "stats.db")
|
||||
o1:depends ("backupfile", "querylog.json")
|
||||
o1:depends ("backupfile", "sessions.db")
|
||||
for name in fs.glob(workdir.."/data/*")
|
||||
do
|
||||
name=fs.basename (name)
|
||||
if name~="filters" and name~="stats.db" and name~="querylog.json" and name~="sessions.db" then
|
||||
o:value(name,name)
|
||||
o1:depends ("backupfile", name)
|
||||
end
|
||||
end
|
||||
o.widget = "checkbox"
|
||||
o.default = nil
|
||||
o.optional=false
|
||||
o.description=translate("Will be restore when workdir/data is empty")
|
||||
----backup workdir path
|
||||
|
||||
o1.default = "/etc/AdGuardHome"
|
||||
o1.datatype = "string"
|
||||
o1.optional = false
|
||||
o1.validate=function(self, value)
|
||||
if fs.stat(value,"type")=="reg" then
|
||||
if m.message then
|
||||
m.message =m.message.."\nerror!backup dir is a file"
|
||||
else
|
||||
m.message ="error!backup dir is a file"
|
||||
end
|
||||
return nil
|
||||
end
|
||||
if string.sub(value,-1)=="/" then
|
||||
return string.sub(value, 1, -2)
|
||||
else
|
||||
return value
|
||||
end
|
||||
end
|
||||
|
||||
---- Crontab Settings ----
|
||||
|
||||
o = s:taboption("other",MultiValue, "crontab", translate("Crontab task"),translate("Please change time and args in crontab"))
|
||||
o:value("autohost",translate("Auto update ipv6 hosts and restart AdGuardHome"))
|
||||
o:value("autogfw",translate("Auto update gfwlist and restart AdGuardHome"))
|
||||
o:value("autogfwipset",translate("Auto update ipset list and restart AdGuardHome"))
|
||||
o.widget = "checkbox"
|
||||
o.default = nil
|
||||
o.optional = false
|
||||
|
||||
---- GFWList Settings ----
|
||||
local a
|
||||
if fs.access(configpath) then
|
||||
a=luci.sys.call("grep -m 1 -q programadd "..configpath)
|
||||
else
|
||||
a=1
|
||||
end
|
||||
if (a==0) then
|
||||
a="Added"
|
||||
else
|
||||
a="Not added"
|
||||
end
|
||||
|
||||
o=s:taboption("other", Button,"gfwdel",translate("Del gfwlist"),translate(a))
|
||||
o.optional = false
|
||||
o.inputtitle=translate("Del")
|
||||
o.write=function()
|
||||
luci.sys.exec("sh /usr/share/AdGuardHome/gfw2adg.sh del 2>&1")
|
||||
luci.http.redirect(luci.dispatcher.build_url("admin","services","AdGuardHome"))
|
||||
end
|
||||
o=s:taboption("other", Button,"gfwadd",translate("Add gfwlist"),translate(a))
|
||||
o.optional = false
|
||||
o.inputtitle=translate("Add")
|
||||
o.write=function()
|
||||
luci.sys.exec("sh /usr/share/AdGuardHome/gfw2adg.sh 2>&1")
|
||||
luci.http.redirect(luci.dispatcher.build_url("admin","services","AdGuardHome"))
|
||||
end
|
||||
if fs.access(configpath) then
|
||||
a=luci.sys.call("grep -m 1 -q ipset.txt "..configpath)
|
||||
else
|
||||
a=1
|
||||
end
|
||||
if (a==0) then
|
||||
a="Added"
|
||||
else
|
||||
a="Not added"
|
||||
end
|
||||
o=s:taboption("other", Button,"gfwipsetdel",translate("Del gfwlist").." "..translate("(ipset only)"),translate(a))
|
||||
o.optional = false
|
||||
o.inputtitle=translate("Del")
|
||||
o.write=function()
|
||||
luci.sys.exec("sh /usr/share/AdGuardHome/gfwipset2adg.sh del 2>&1")
|
||||
luci.http.redirect(luci.dispatcher.build_url("admin","services","AdGuardHome"))
|
||||
end
|
||||
o=s:taboption("other", Button," ",translate("Add gfwlist").." "..translate("(ipset only)"),translate(a).." "..translate("will set to name gfwlist"))
|
||||
o.optional = false
|
||||
o.inputtitle=translate("Add")
|
||||
o.write=function()
|
||||
luci.sys.exec("sh /usr/share/AdGuardHome/gfwipset2adg.sh 2>&1")
|
||||
luci.http.redirect(luci.dispatcher.build_url("admin","services","AdGuardHome"))
|
||||
end
|
||||
o = s:taboption("other", Value, "gfwupstream", translate("Gfwlist upstream dns server"), translate("Gfwlist domain upstream dns service")..translate(a))
|
||||
o.default = "tcp://208.67.220.220:5353"
|
||||
o.datatype = "string"
|
||||
o.optional = false
|
||||
|
||||
fs.writefile("/var/run/AdG_log_pos","0")
|
||||
|
||||
function m.on_commit(map)
|
||||
if (fs.access("/var/run/AdGserverdis")) then
|
||||
io.popen("/etc/init.d/AdGuardHome reload &")
|
||||
return
|
||||
end
|
||||
local ucitracktest=uci:get("AdGuardHome","AdGuardHome","ucitracktest")
|
||||
if ucitracktest=="1" then
|
||||
return
|
||||
elseif ucitracktest=="0" then
|
||||
io.popen("/etc/init.d/AdGuardHome reload &")
|
||||
else
|
||||
if (fs.access("/var/run/AdGlucitest")) then
|
||||
uci:set("AdGuardHome","AdGuardHome","ucitracktest","0")
|
||||
io.popen("/etc/init.d/AdGuardHome reload &")
|
||||
else
|
||||
fs.writefile("/var/run/AdGlucitest","")
|
||||
if (ucitracktest=="2") then
|
||||
uci:set("AdGuardHome","AdGuardHome","ucitracktest","1")
|
||||
else
|
||||
uci:set("AdGuardHome","AdGuardHome","ucitracktest","2")
|
||||
end
|
||||
end
|
||||
uci:commit("AdGuardHome")
|
||||
end
|
||||
end
|
||||
return m
|
||||
16
luci-app-adguardhome/luasrc/model/cbi/AdGuardHome/log.lua
Normal file
16
luci-app-adguardhome/luasrc/model/cbi/AdGuardHome/log.lua
Normal file
@@ -0,0 +1,16 @@
|
||||
local fs = require "nixio.fs"
|
||||
local uci = require"luci.model.uci".cursor()
|
||||
local f, t
|
||||
f = SimpleForm("logview")
|
||||
f.reset = false
|
||||
f.submit = false
|
||||
t=f:field(TextValue,"conf")
|
||||
t.rmempty=true
|
||||
t.rows=20
|
||||
t.template="AdGuardHome/log"
|
||||
t.readonly="readonly"
|
||||
local logfile=uci:get("AdGuardHome","AdGuardHome","logfile") or ""
|
||||
t.timereplace=(logfile~="syslog" and logfile~="" )
|
||||
t.pollcheck=logfile~=""
|
||||
fs.writefile("/var/run/lucilogpos", "0")
|
||||
return f
|
||||
96
luci-app-adguardhome/luasrc/model/cbi/AdGuardHome/manual.lua
Normal file
96
luci-app-adguardhome/luasrc/model/cbi/AdGuardHome/manual.lua
Normal file
@@ -0,0 +1,96 @@
|
||||
local m, s, o
|
||||
local fs = require "nixio.fs"
|
||||
local uci=require"luci.model.uci".cursor()
|
||||
local sys=require"luci.sys"
|
||||
require("string")
|
||||
require("io")
|
||||
require("table")
|
||||
function gen_template_config()
|
||||
local b
|
||||
local d=""
|
||||
local file = "/tmp/resolv.conf.d/resolv.conf.auto"
|
||||
if not fs.access(file) then
|
||||
file = "/tmp/resolv.conf.auto"
|
||||
end
|
||||
for cnt in io.lines(file) do
|
||||
b = string.match(cnt, "^[^#]*nameserver%s+([^%s]+)$")
|
||||
if (b ~= nil) then d = d .. " - " .. b .. "\n" end
|
||||
end
|
||||
local f=io.open("/usr/share/AdGuardHome/AdGuardHome_template.yaml", "r+")
|
||||
local tbl = {}
|
||||
local a=""
|
||||
while (1) do
|
||||
a=f:read("*l")
|
||||
if (a=="#bootstrap_dns") then
|
||||
a=d
|
||||
elseif (a=="#upstream_dns") then
|
||||
a=d
|
||||
elseif (a==nil) then
|
||||
break
|
||||
end
|
||||
table.insert(tbl, a)
|
||||
end
|
||||
f:close()
|
||||
return table.concat(tbl, "\n")
|
||||
end
|
||||
m = Map("AdGuardHome")
|
||||
local configpath = uci:get("AdGuardHome","AdGuardHome","configpath")
|
||||
local binpath = uci:get("AdGuardHome","AdGuardHome","binpath")
|
||||
s = m:section(TypedSection, "AdGuardHome")
|
||||
s.anonymous=true
|
||||
s.addremove=false
|
||||
--- config
|
||||
o = s:option(TextValue, "escconf")
|
||||
o.rows = 66
|
||||
o.wrap = "off"
|
||||
o.rmempty = true
|
||||
o.cfgvalue = function(self, section)
|
||||
return fs.readfile("/tmp/AdGuardHometmpconfig.yaml") or fs.readfile(configpath) or gen_template_config() or ""
|
||||
end
|
||||
o.validate=function(self, value)
|
||||
fs.writefile("/tmp/AdGuardHometmpconfig.yaml", value:gsub("\r\n", "\n"))
|
||||
if fs.access(binpath) then
|
||||
if (sys.call(binpath .. " -c /tmp/AdGuardHometmpconfig.yaml --check-config 2> /tmp/AdGuardHometest.log") == 0) then return value end
|
||||
else
|
||||
return value
|
||||
end
|
||||
luci.http.redirect(luci.dispatcher.build_url("admin","services","AdGuardHome","manual"))
|
||||
return nil
|
||||
end
|
||||
o.write = function(self, section, value)
|
||||
fs.move("/tmp/AdGuardHometmpconfig.yaml",configpath)
|
||||
end
|
||||
o.remove = function(self, section, value) fs.writefile(configpath, "") end
|
||||
|
||||
--- js and reload button
|
||||
o = s:option(DummyValue, "")
|
||||
o.anonymous=true
|
||||
o.template = "AdGuardHome/yamleditor"
|
||||
if not fs.access(binpath) then
|
||||
o.description=translate("WARNING!!! no bin found apply config will not be test")
|
||||
end
|
||||
--- log
|
||||
if (fs.access("/tmp/AdGuardHometmpconfig.yaml")) then
|
||||
local c=fs.readfile("/tmp/AdGuardHometest.log")
|
||||
if (c~="") then
|
||||
o = s:option(TextValue, "")
|
||||
o.readonly=true
|
||||
o.rows = 5
|
||||
o.rmempty = true
|
||||
o.name=""
|
||||
o.cfgvalue = function(self, section)
|
||||
return fs.readfile("/tmp/AdGuardHometest.log")
|
||||
end
|
||||
end
|
||||
end
|
||||
function m.on_commit(map)
|
||||
local ucitracktest=uci:get("AdGuardHome","AdGuardHome","ucitracktest")
|
||||
if ucitracktest=="1" then
|
||||
return
|
||||
elseif ucitracktest=="0" then
|
||||
io.popen("/etc/init.d/AdGuardHome reload &")
|
||||
else
|
||||
fs.writefile("/var/run/AdGlucitest","")
|
||||
end
|
||||
end
|
||||
return m
|
||||
Reference in New Issue
Block a user