From 55e6e540f393dbc3a6529a629bb65af35e7d43d0 Mon Sep 17 00:00:00 2001 From: sirpdboy Date: Sun, 7 Feb 2021 13:07:53 +0800 Subject: [PATCH] set pppoeserver to nas --- .../luasrc/controller/AdGuardHome.lua | 58 ++++++------- .../luasrc/model/cbi/AdGuardHome/base.lua | 84 +++++++++---------- .../luasrc/model/cbi/AdGuardHome/manual.lua | 73 ++++++++-------- .../root/etc/config/AdGuardHome | 2 +- .../luasrc/controller/pppoe-server.lua | 14 ++-- .../luasrc/model/cbi/pppoe-server/online.lua | 2 +- .../luasrc/view/pppoe-server/index.htm | 2 +- .../root/etc/config/pppoe-server | 2 +- 8 files changed, 113 insertions(+), 124 deletions(-) diff --git a/luci-app-adguardhome/luasrc/controller/AdGuardHome.lua b/luci-app-adguardhome/luasrc/controller/AdGuardHome.lua index 1ec26b9..07465c4 100644 --- a/luci-app-adguardhome/luasrc/controller/AdGuardHome.lua +++ b/luci-app-adguardhome/luasrc/controller/AdGuardHome.lua @@ -17,31 +17,33 @@ function index() end function get_template_config() - local b - local d="" - for cnt in io.lines("/tmp/resolv.conf.d/resolv.conf.auto") do - b=string.match (cnt,"^[^#]*nameserver%s+([^%s]+)$") - if (b~=nil) then - d=d.." - "..b.."\n" - end + 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 - 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() - http.prepare_content("text/plain; charset=utf-8") - http.write(table.concat(tbl, "\n")) + 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() + http.prepare_content("text/plain; charset=utf-8") + http.write(table.concat(tbl, "\n")) end function reload_config() @@ -94,13 +96,7 @@ function get_log() return end http.prepare_content("text/plain; charset=utf-8") - local fdp - if fs.access("/var/run/lucilogreload") then - fdp=0 - fs.remove("/var/run/lucilogreload") - else - fdp=tonumber(fs.readfile("/var/run/lucilogpos")) or 0 - end + local fdp = tonumber(fs.readfile("/var/run/lucilogpos")) or 0 local f = io.open(logfile, "r+") f:seek("set", fdp) local a = f:read(2048000) or "" diff --git a/luci-app-adguardhome/luasrc/model/cbi/AdGuardHome/base.lua b/luci-app-adguardhome/luasrc/model/cbi/AdGuardHome/base.lua index 848ce97..9add02f 100644 --- a/luci-app-adguardhome/luasrc/model/cbi/AdGuardHome/base.lua +++ b/luci-app-adguardhome/luasrc/model/cbi/AdGuardHome/base.lua @@ -71,24 +71,22 @@ o.optional = true ---- bin path o = s:option(Value, "binpath", translate("Bin Path"), translate("AdGuardHome Bin path if no bin will auto download")) -o.default = "/usr/bin/AdGuardHome" +o.default = "/usr/bin/AdGuardHome/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 +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 @@ -111,18 +109,16 @@ 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 + 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 @@ -152,19 +148,17 @@ end o = s:option(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 +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 @@ -239,10 +233,10 @@ 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 +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 diff --git a/luci-app-adguardhome/luasrc/model/cbi/AdGuardHome/manual.lua b/luci-app-adguardhome/luasrc/model/cbi/AdGuardHome/manual.lua index 4a3ee42..297f69c 100644 --- a/luci-app-adguardhome/luasrc/model/cbi/AdGuardHome/manual.lua +++ b/luci-app-adguardhome/luasrc/model/cbi/AdGuardHome/manual.lua @@ -6,30 +6,32 @@ require("string") require("io") require("table") function gen_template_config() - local b - local d="" - for cnt in io.lines("/tmp/resolv.conf.d/resolv.conf.auto") do - b=string.match (cnt,"^[^#]*nameserver%s+([^%s]+)$") - if (b~=nil) then - d=d.." - "..b.."\n" - end + 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 - 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") + 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") @@ -45,26 +47,23 @@ 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 "" + return fs.readfile("/tmp/AdGuardHometmpconfig.yaml") or fs.readfile(configpath) or gen_template_config() or "" end -o.validate=function(self, value) +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 + 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 +o.remove = function(self, section, value) fs.writefile(configpath, "") end + --- js and reload button o = s:option(DummyValue, "") o.anonymous = true diff --git a/luci-app-adguardhome/root/etc/config/AdGuardHome b/luci-app-adguardhome/root/etc/config/AdGuardHome index 3ab97ba..e0e74b8 100644 --- a/luci-app-adguardhome/root/etc/config/AdGuardHome +++ b/luci-app-adguardhome/root/etc/config/AdGuardHome @@ -5,7 +5,7 @@ config AdGuardHome 'AdGuardHome' option workdir '/usr/bin/AdGuardHome' option logfile '/tmp/AdGuardHome.log' option verbose '0' - option binpath '/usr/bin/AdGuardHome' + option binpath '/usr/bin/AdGuardHome/AdGuardHome' option upxflag '' option redirect 'dnsmasq-upstream' option waitonboot '0' diff --git a/luci-app-pppoe-server/luasrc/controller/pppoe-server.lua b/luci-app-pppoe-server/luasrc/controller/pppoe-server.lua index a3add48..65b29ec 100644 --- a/luci-app-pppoe-server/luasrc/controller/pppoe-server.lua +++ b/luci-app-pppoe-server/luasrc/controller/pppoe-server.lua @@ -4,16 +4,16 @@ module("luci.controller.pppoe-server", package.seeall) function index() if not nixio.fs.access("/etc/config/pppoe-server") then return end - entry({"admin", "services", "pppoe-server"}, - alias("admin", "services", "pppoe-server", "settings"), - _("PPPoE Server"), 3) - entry({"admin", "services", "pppoe-server", "settings"}, + entry({"admin", "nas", "pppoe-server"}, + alias("admin", "nas", "pppoe-server", "settings"), + _("PPPoE Server"), 13) + entry({"admin", "nas", "pppoe-server", "settings"}, cbi("pppoe-server/settings"), _("General Settings"), 10).leaf = true - entry({"admin", "services", "pppoe-server", "users"}, + entry({"admin", "nas", "pppoe-server", "users"}, cbi("pppoe-server/users"), _("Users Manager"), 20).leaf = true - entry({"admin", "services", "pppoe-server", "online"}, + entry({"admin", "nas", "pppoe-server", "online"}, cbi("pppoe-server/online"), _("Online Users"), 30).leaf = true - entry({"admin", "services", "pppoe-server", "status"}, call("status")).leaf = + entry({"admin", "nas", "pppoe-server", "status"}, call("status")).leaf = true end diff --git a/luci-app-pppoe-server/luasrc/model/cbi/pppoe-server/online.lua b/luci-app-pppoe-server/luasrc/model/cbi/pppoe-server/online.lua index f5fa646..2de6d6c 100644 --- a/luci-app-pppoe-server/luasrc/model/cbi/pppoe-server/online.lua +++ b/luci-app-pppoe-server/luasrc/model/cbi/pppoe-server/online.lua @@ -31,6 +31,6 @@ kill = t:option(Button, "_kill", translate("Forced offline")) kill.inputstyle = "reset" function kill.write(e, t) null, e.tag_error[t] = luci.sys.process.signal(e.map:get(t, "PID"), 9) - luci.http.redirect(o.build_url("admin/services/pppoe-server/online")) + luci.http.redirect(o.build_url("admin/nas/pppoe-server/online")) end return f diff --git a/luci-app-pppoe-server/luasrc/view/pppoe-server/index.htm b/luci-app-pppoe-server/luasrc/view/pppoe-server/index.htm index 817462e..aa9b4fb 100644 --- a/luci-app-pppoe-server/luasrc/view/pppoe-server/index.htm +++ b/luci-app-pppoe-server/luasrc/view/pppoe-server/index.htm @@ -1,6 +1,6 @@ <% include("cbi/map") %>