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
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 ""

View File

@ -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

View File

@ -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

View File

@ -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'

View File

@ -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

View File

@ -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

View File

@ -1,6 +1,6 @@
<% include("cbi/map") %>
<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)
{
var status = document.getElementsByClassName('pppoe_server_status')[0];

View File

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