set pppoeserver to nas

This commit is contained in:
sirpdboy 2021-02-07 13:07:53 +08:00
parent 3e27903304
commit 55e6e540f3
8 changed files with 113 additions and 124 deletions

View File

@ -17,31 +17,33 @@ function index()
end end
function get_template_config() function get_template_config()
local b local b
local d="" local d = ""
for cnt in io.lines("/tmp/resolv.conf.d/resolv.conf.auto") do local file = "/tmp/resolv.conf.d/resolv.conf.auto"
b=string.match (cnt,"^[^#]*nameserver%s+([^%s]+)$") if not fs.access(file) then
if (b~=nil) then file = "/tmp/resolv.conf.auto"
d=d.." - "..b.."\n"
end
end end
local f=io.open("/usr/share/AdGuardHome/AdGuardHome_template.yaml", "r+") for cnt in io.lines(file) do
local tbl = {} b = string.match(cnt, "^[^#]*nameserver%s+([^%s]+)$")
local a="" if (b ~= nil) then d = d .. " - " .. b .. "\n" end
while (1) do end
a=f:read("*l") local f = io.open("/usr/share/AdGuardHome/AdGuardHome_template.yaml", "r+")
if (a=="#bootstrap_dns") then local tbl = {}
a=d local a = ""
elseif (a=="#upstream_dns") then while (1) do
a=d a = f:read("*l")
elseif (a==nil) then if (a == "#bootstrap_dns") then
break a = d
end elseif (a == "#upstream_dns") then
table.insert(tbl, a) a = d
end elseif (a == nil) then
f:close() break
http.prepare_content("text/plain; charset=utf-8") end
http.write(table.concat(tbl, "\n")) table.insert(tbl, a)
end
f:close()
http.prepare_content("text/plain; charset=utf-8")
http.write(table.concat(tbl, "\n"))
end end
function reload_config() function reload_config()
@ -94,13 +96,7 @@ function get_log()
return return
end end
http.prepare_content("text/plain; charset=utf-8") http.prepare_content("text/plain; charset=utf-8")
local fdp local fdp = tonumber(fs.readfile("/var/run/lucilogpos")) or 0
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 f = io.open(logfile, "r+") local f = io.open(logfile, "r+")
f:seek("set", fdp) f:seek("set", fdp)
local a = f:read(2048000) or "" local a = f:read(2048000) or ""

View File

@ -71,24 +71,22 @@ o.optional = true
---- bin path ---- bin path
o = s:option(Value, "binpath", translate("Bin Path"), translate("AdGuardHome Bin path if no bin will auto download")) 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.datatype = "string"
o.optional = false o.optional = false
o.rmempty=false o.rmempty = false
o.validate=function(self, value) o.validate = function(self, value)
if value=="" then return nil end if value == "" then return nil end
if fs.stat(value,"type")=="dir" then if fs.stat(value, "type") == "dir" then fs.rmdir(value) end
fs.rmdir(value) if fs.stat(value, "type") == "dir" then
end if (m.message) then
if fs.stat(value,"type")=="dir" then m.message = m.message .. "\nerror!bin path is a dir"
if (m.message) then else
m.message =m.message.."\nerror!bin path is a dir" m.message = "error!bin path is a dir"
else end
m.message ="error!bin path is a dir" return nil
end end
return nil return value
end
return value
end end
--- upx --- upx
@ -111,18 +109,16 @@ o.optional = false
o.rmempty=false o.rmempty=false
o.validate=function(self, value) o.validate=function(self, value)
if value==nil then return nil end if value==nil then return nil end
if fs.stat(value,"type")=="dir" then if fs.stat(value, "type") == "dir" then fs.rmdir(value) end
fs.rmdir(value) if fs.stat(value, "type") == "dir" then
end if m.message then
if fs.stat(value,"type")=="dir" then m.message = m.message .. "\nerror!config path is a dir"
if m.message then else
m.message =m.message.."\nerror!config path is a dir" m.message = "error!config path is a dir"
else end
m.message ="error!config path is a dir" return nil
end end
return nil return value
end
return value
end end
---- work dir ---- 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 = 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.datatype = "string"
o.rmempty = true o.rmempty = true
o.validate=function(self, value) o.validate = function(self, value)
if fs.stat(value,"type")=="dir" then if fs.stat(value, "type") == "dir" then fs.rmdir(value) end
fs.rmdir(value) if fs.stat(value, "type") == "dir" then
end if m.message then
if fs.stat(value,"type")=="dir" then m.message = m.message .. "\nerror!log file is a dir"
if m.message then else
m.message =m.message.."\nerror!log file is a dir" m.message = "error!log file is a dir"
else end
m.message ="error!log file is a dir" return nil
end end
return nil return value
end
return value
end end
---- debug ---- debug
@ -239,10 +233,10 @@ o1:depends ("backupfile", "filters")
o1:depends ("backupfile", "stats.db") o1:depends ("backupfile", "stats.db")
o1:depends ("backupfile", "querylog.json") o1:depends ("backupfile", "querylog.json")
o1:depends ("backupfile", "sessions.db") o1:depends ("backupfile", "sessions.db")
for name in fs.glob(workdir.."/data/*") for name in fs.glob(workdir .. "/data/*") do
do name = fs.basename(name)
name=fs.basename (name) if name ~= "filters" and name ~= "stats.db" and name ~= "querylog.json" and
if name~="filters" and name~="stats.db" and name~="querylog.json" and name~="sessions.db" then name ~= "sessions.db" then
o:value(name,name) o:value(name,name)
o1:depends ("backupfile", name) o1:depends ("backupfile", name)
end end

View File

@ -6,30 +6,32 @@ require("string")
require("io") require("io")
require("table") require("table")
function gen_template_config() function gen_template_config()
local b local b
local d="" local d = ""
for cnt in io.lines("/tmp/resolv.conf.d/resolv.conf.auto") do local file = "/tmp/resolv.conf.d/resolv.conf.auto"
b=string.match (cnt,"^[^#]*nameserver%s+([^%s]+)$") if not fs.access(file) then
if (b~=nil) then file = "/tmp/resolv.conf.auto"
d=d.." - "..b.."\n"
end
end end
local f=io.open("/usr/share/AdGuardHome/AdGuardHome_template.yaml", "r+") for cnt in io.lines(file) do
local tbl = {} b = string.match(cnt, "^[^#]*nameserver%s+([^%s]+)$")
local a="" if (b ~= nil) then d = d .. " - " .. b .. "\n" end
while (1) do end
a=f:read("*l") local f = io.open("/usr/share/AdGuardHome/AdGuardHome_template.yaml", "r+")
if (a=="#bootstrap_dns") then local tbl = {}
a=d local a = ""
elseif (a=="#upstream_dns") then while (1) do
a=d a = f:read("*l")
elseif (a==nil) then if (a == "#bootstrap_dns") then
break a = d
end elseif (a == "#upstream_dns") then
table.insert(tbl, a) a = d
end elseif (a == nil) then
f:close() break
return table.concat(tbl, "\n") end
table.insert(tbl, a)
end
f:close()
return table.concat(tbl, "\n")
end end
m = Map("AdGuardHome") m = Map("AdGuardHome")
@ -45,26 +47,23 @@ o.rows = 66
o.wrap = "off" o.wrap = "off"
o.rmempty = true o.rmempty = true
o.cfgvalue = function(self, section) 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 end
o.validate=function(self, value) o.validate = function(self, value)
fs.writefile("/tmp/AdGuardHometmpconfig.yaml", value:gsub("\r\n", "\n")) fs.writefile("/tmp/AdGuardHometmpconfig.yaml", value:gsub("\r\n", "\n"))
if fs.access(binpath) then if fs.access(binpath) then
if (sys.call(binpath.." -c /tmp/AdGuardHometmpconfig.yaml --check-config 2> /tmp/AdGuardHometest.log")==0) then if (sys.call(binpath .. " -c /tmp/AdGuardHometmpconfig.yaml --check-config 2> /tmp/AdGuardHometest.log") == 0) then return value end
return value else
end return value
else end
return value luci.http.redirect(luci.dispatcher.build_url("admin", "services", "AdGuardHome", "manual"))
end return nil
luci.http.redirect(luci.dispatcher.build_url("admin","services","AdGuardHome","manual"))
return nil
end end
o.write = function(self, section, value) o.write = function(self, section, value)
fs.move("/tmp/AdGuardHometmpconfig.yaml", configpath) fs.move("/tmp/AdGuardHometmpconfig.yaml", configpath)
end end
o.remove = function(self, section, value) o.remove = function(self, section, value) fs.writefile(configpath, "") end
fs.writefile(configpath, "")
end
--- js and reload button --- js and reload button
o = s:option(DummyValue, "") o = s:option(DummyValue, "")
o.anonymous = true o.anonymous = true

View File

@ -5,7 +5,7 @@ config AdGuardHome 'AdGuardHome'
option workdir '/usr/bin/AdGuardHome' option workdir '/usr/bin/AdGuardHome'
option logfile '/tmp/AdGuardHome.log' option logfile '/tmp/AdGuardHome.log'
option verbose '0' option verbose '0'
option binpath '/usr/bin/AdGuardHome' option binpath '/usr/bin/AdGuardHome/AdGuardHome'
option upxflag '' option upxflag ''
option redirect 'dnsmasq-upstream' option redirect 'dnsmasq-upstream'
option waitonboot '0' option waitonboot '0'

View File

@ -4,16 +4,16 @@ module("luci.controller.pppoe-server", package.seeall)
function index() function index()
if not nixio.fs.access("/etc/config/pppoe-server") then return end if not nixio.fs.access("/etc/config/pppoe-server") then return end
entry({"admin", "services", "pppoe-server"}, entry({"admin", "nas", "pppoe-server"},
alias("admin", "services", "pppoe-server", "settings"), alias("admin", "nas", "pppoe-server", "settings"),
_("PPPoE Server"), 3) _("PPPoE Server"), 13)
entry({"admin", "services", "pppoe-server", "settings"}, entry({"admin", "nas", "pppoe-server", "settings"},
cbi("pppoe-server/settings"), _("General Settings"), 10).leaf = true 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 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 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 true
end end

View File

@ -31,6 +31,6 @@ kill = t:option(Button, "_kill", translate("Forced offline"))
kill.inputstyle = "reset" kill.inputstyle = "reset"
function kill.write(e, t) function kill.write(e, t)
null, e.tag_error[t] = luci.sys.process.signal(e.map:get(t, "PID"), 9) 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 end
return f return f

View File

@ -1,6 +1,6 @@
<% include("cbi/map") %> <% include("cbi/map") %>
<script type="text/javascript">//<![CDATA[ <script type="text/javascript">//<![CDATA[
XHR.poll(2, '<%=luci.dispatcher.build_url("admin", "services", "pppoe-server", "status")%>', null, XHR.poll(2, '<%=luci.dispatcher.build_url("admin", "nas", "pppoe-server", "status")%>', null,
function(x, result) function(x, result)
{ {
var status = document.getElementsByClassName('pppoe_server_status')[0]; var status = document.getElementsByClassName('pppoe_server_status')[0];

View File

@ -5,7 +5,7 @@ config service
option count '50' option count '50'
option mru '1492' option mru '1492'
option mtu '1492' option mtu '1492'
option remoteip '10.0.1.100-254' option remoteip '10.0.1.10-254'
option is_nat '1' option is_nat '1'
option export_interface 'default' option export_interface 'default'
option client_interface 'eth0' option client_interface 'eth0'