浏览代码

meanless changes

rufengsuixing 5 年之前
父节点
当前提交
9e4340cbb0

+ 47 - 47
luasrc/controller/AdGuardHome.lua

@@ -1,103 +1,103 @@
 module("luci.controller.AdGuardHome",package.seeall)
-nixio=require"nixio"
+local fs=require"fs"
+local http=require"http"
 local uci=require"luci.model.uci".cursor()
 function index()
-entry({"admin", "services", "AdGuardHome"},
-		alias("admin", "services", "AdGuardHome", "base"),
-		_("AdGuard Home"), 10).dependent = true
-	entry({"admin","services","AdGuardHome","base"},cbi("AdGuardHome/base"),_("Base Setting"),1).leaf = true
-    entry({"admin","services","AdGuardHome","log"},form("AdGuardHome/log"),_("Log"),2).leaf = true
-	entry({"admin","services","AdGuardHome","manual"},cbi("AdGuardHome/manual"),_("Manual Config"),3).leaf = true
-    entry({"admin","services","AdGuardHome","status"},call("act_status")).leaf=true
-	entry({"admin", "services", "AdGuardHome", "check"}, call("check_update"))
-	entry({"admin", "services", "AdGuardHome", "doupdate"}, call("do_update"))
-	entry({"admin", "services", "AdGuardHome", "getlog"}, call("get_log"))
-	entry({"admin", "services", "AdGuardHome", "dodellog"}, call("do_dellog"))
-	entry({"admin", "services", "AdGuardHome", "reloadconfig"}, call("reload_config"))
+entry({"admin", "services", "AdGuardHome"},alias("admin", "services", "AdGuardHome", "base"),_("AdGuard Home"), 10).dependent = true
+entry({"admin","services","AdGuardHome","base"},cbi("AdGuardHome/base"),_("Base Setting"),1).leaf = true
+entry({"admin","services","AdGuardHome","log"},form("AdGuardHome/log"),_("Log"),2).leaf = true
+entry({"admin","services","AdGuardHome","manual"},cbi("AdGuardHome/manual"),_("Manual Config"),3).leaf = true
+entry({"admin","services","AdGuardHome","status"},call("act_status")).leaf=true
+entry({"admin", "services", "AdGuardHome", "check"}, call("check_update"))
+entry({"admin", "services", "AdGuardHome", "doupdate"}, call("do_update"))
+entry({"admin", "services", "AdGuardHome", "getlog"}, call("get_log"))
+entry({"admin", "services", "AdGuardHome", "dodellog"}, call("do_dellog"))
+entry({"admin", "services", "AdGuardHome", "reloadconfig"}, call("reload_config"))
 end 
 function reload_config()
-	nixio.fs.remove("/tmp/AdGuardHometmpconfig.yaml")
-	luci.http.prepare_content("application/json")
-	luci.http.write('')
+	fs.remove("/tmp/AdGuardHometmpconfig.yaml")
+	http.prepare_content("application/json")
+	http.write('')
 end
 function act_status()
 	local e={}
-	binpath=uci:get("AdGuardHome","AdGuardHome","binpath")
+	local binpath=uci:get("AdGuardHome","AdGuardHome","binpath")
 	e.running=luci.sys.call("pgrep "..binpath.." >/dev/null")==0
-	st=nixio.fs.readfile("/var/run/AdGredir")
+	local st=fs.readfile("/var/run/AdGredir")
 	if (st=="0") then
 		e.redirect=false
 	else
 		e.redirect=true
 	end
-	luci.http.prepare_content("application/json")
-	luci.http.write_json(e)
+	http.prepare_content("application/json")
+	http.write_json(e)
 end
 function do_update()
-	nixio.fs.writefile("/var/run/lucilogpos","0")
+	fs.writefile("/var/run/lucilogpos","0")
 	luci.sys.exec("(rm /var/run/update_core_error ; touch /var/run/update_core ; sh /usr/share/AdGuardHome/update_core.sh >/tmp/AdGuardHome_update.log 2>&1 || touch /var/run/update_core_error ;rm /var/run/update_core) &")
-	luci.http.prepare_content("application/json")
-	luci.http.write('')
+	http.prepare_content("application/json")
+	http.write('')
 end
 function get_log()
 	local logfile=uci:get("AdGuardHome","AdGuardHome","logfile")
 	if (logfile==nil) then
-	luci.http.write("no log available\n")
+	http.write("no log available\n")
 	return
 	elseif (logfile=="syslog") then
-		if not nixio.fs.access("/var/run/AdGuardHomesyslog") then
+		if not fs.access("/var/run/AdGuardHomesyslog") then
 			luci.sys.exec("(/usr/share/AdGuardHome/getsyslog.sh &); sleep 1;")
 		end
 		logfile="/tmp/AdGuardHometmp.log"
-		nixio.fs.writefile("/var/run/AdGuardHomesyslog","1")
-	elseif not nixio.fs.access(logfile) then
-		luci.http.write("log file not created\n")
+		fs.writefile("/var/run/AdGuardHomesyslog","1")
+	elseif not fs.access(logfile) then
+		http.write("log file not created\n")
 		return
 	end
-	luci.http.prepare_content("text/plain; charset=utf-8")
-	logpos=nixio.fs.readfile("/var/run/lucilogpos")
+	http.prepare_content("text/plain; charset=utf-8")
+	local logpos=fs.readfile("/var/run/lucilogpos")
+	local fdp
 	if (logpos ~= nil) then
 		fdp=tonumber(logpos)
 	else
 		fdp=0
 	end
-	f=io.open(logfile, "r+")
+	local f=io.open(logfile, "r+")
 	f:seek("set",fdp)
-	a=f:read(2048000)
+	local a=f:read(2048000)
 	if (a==nil) then
 		a=""
 	end
 	fdp=f:seek()
-	nixio.fs.writefile("/var/run/lucilogpos",tostring(fdp))
+	fs.writefile("/var/run/lucilogpos",tostring(fdp))
 	f:close()
-	luci.http.write(a)
+	http.write(a)
 end
 function do_dellog()
-	logfile=uci:get("AdGuardHome","AdGuardHome","logfile")
-	nixio.fs.writefile(logfile,"")
-	luci.http.prepare_content("application/json")
-	luci.http.write('')
+	local logfile=uci:get("AdGuardHome","AdGuardHome","logfile")
+	fs.writefile(logfile,"")
+	http.prepare_content("application/json")
+	http.write('')
 end
 function check_update()
-	luci.http.prepare_content("text/plain; charset=utf-8")
-	logpos=nixio.fs.readfile("/var/run/lucilogpos")
+	http.prepare_content("text/plain; charset=utf-8")
+	local logpos=fs.readfile("/var/run/lucilogpos")
 	if (logpos ~= nil) then
-	fdp=tonumber(logpos)
+	local fdp=tonumber(logpos)
 	else
 	fdp=0
 	end
-	f=io.open("/tmp/AdGuardHome_update.log", "r+")
+	local f=io.open("/tmp/AdGuardHome_update.log", "r+")
 	f:seek("set",fdp)
-	a=f:read(2048000)
+	local a=f:read(2048000)
 	if (a==nil) then
 	a=""
 	end
 	fdp=f:seek()
-	nixio.fs.writefile("/var/run/lucilogpos",tostring(fdp))
+	fs.writefile("/var/run/lucilogpos",tostring(fdp))
 	f:close()
-if nixio.fs.access("/var/run/update_core") then
-	luci.http.write(a)
+if fs.access("/var/run/update_core") then
+	http.write(a)
 else
-	luci.http.write(a.."\0")
+	http.write(a.."\0")
 end
 end

+ 20 - 17
luasrc/model/cbi/AdGuardHome/base.lua

@@ -1,8 +1,9 @@
 require("luci.sys")
 require("luci.util")
+require("io")
+local m,s,o
 local fs=require"nixio.fs"
 local uci=require"luci.model.uci".cursor()
-require("io")
 local configpath=uci:get("AdGuardHome","AdGuardHome","configpath")
 if (configpath==nil) then
 configpath="/etc/AdGuardHome.yaml"
@@ -15,11 +16,11 @@ local httpport=luci.sys.exec("awk '/bind_port:/{printf($2);exit;}' "..configpath
 if (httpport=="") then
 httpport=uci:get("AdGuardHome","AdGuardHome","httpport") or "3000"
 end
-mp = Map("AdGuardHome", "AdGuard Home")
-mp.description = translate("Free and open source, powerful network-wide ads & trackers blocking DNS server.")
-mp:section(SimpleSection).template  = "AdGuardHome/AdGuardHome_status"
+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 = mp:section(TypedSection, "AdGuardHome")
+s = m:section(TypedSection, "AdGuardHome")
 s.anonymous=true
 s.addremove=false
 ---- enable
@@ -34,8 +35,8 @@ o.datatype="port"
 o.rmempty=false
 o.description = translate("<input type=\"button\" style=\"width:210px;border-color:Teal; text-align:center;font-weight:bold;color:Green;\" value=\"AdGuardHome Web:"..httpport.."\" onclick=\"window.open('http://'+window.location.hostname+':"..httpport.."/')\"/>")
 ---- update warning not safe
-version=uci:get("AdGuardHome","AdGuardHome","version")
-e=""
+local version=uci:get("AdGuardHome","AdGuardHome","version")
+local e=""
 if not fs.access(configpath) then
 	e=e.." no config"
 end
@@ -51,8 +52,12 @@ end
 o=s:option(Button,"restart",translate("Update"))
 o.inputtitle=translate("Update core version")
 o.template = "AdGuardHome/AdGuardHome_check"
+if fs.access(configpath)
+o.showfastconfig=false
+else
+o.showfastconfig=true
+end
 o.description=string.format(translate("core version got last time:").."<strong><font id=\"updateversion\" color=\"green\">%s </font></strong>",e)
-
 ---- port warning not safe
 local port=luci.sys.exec("awk '/  port:/{printf($2);exit;}' "..configpath.." 2>nul")
 if (port=="") then
@@ -66,14 +71,13 @@ 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"
-
 ---- 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/AdGuardHome"
 o.datatype    = "string"
 o.validate=function(self, value)
 if fs.stat(value,"type")=="dir" then
-	mp.message ="error!bin path is a dir"
+	m.message ="error!bin path is a dir"
 	return nil
 end 
 return value
@@ -94,7 +98,7 @@ o.default     = "/etc/AdGuardHome.yaml"
 o.datatype    = "string"
 o.validate=function(self, value)
 if fs.stat(value,"type")=="dir" then
-	mp.message ="error!config path is a dir"
+	m.message ="error!config path is a dir"
 	return nil
 end 
 return value
@@ -105,7 +109,7 @@ o.default     = "/usr/bin/AdGuardHome"
 o.datatype    = "string"
 o.validate=function(self, value)
 if fs.stat(value,"type")=="reg" then
-	mp.message ="error!work dir is a file"
+	m.message ="error!work dir is a file"
 	return nil
 end 
 return value
@@ -116,7 +120,7 @@ o.default     = ""
 o.datatype    = "string"
 o.validate=function(self, value)
 if fs.stat(value,"type")=="dir" then
-	mp.message ="error!log file is a dir"
+	m.message ="error!log file is a dir"
 	return nil
 end 
 return value
@@ -141,7 +145,6 @@ o = s:option(Value, "gfwupstream", translate("Gfwlist upstream dns server"), tra
 o.default     = "tcp://208.67.220.220:5353"
 o.datatype    = "string"
 ---- chpass
-
 o = s:option(Value, "hashpass", translate("Change browser management password"), translate("Press load culculate model and culculate finally save/apply"))
 o.default     = ""
 o.datatype    = "string"
@@ -162,12 +165,12 @@ o.default     = "/usr/bin/AdGuardHome"
 o.datatype    = "string"
 o.validate=function(self, value)
 if fs.stat(value,"type")=="reg" then
-	mp.message ="error!backup dir is a file"
+	m.message ="error!backup dir is a file"
 	return nil
 end 
 return value
 end
 o = s:option(Flag, "autoupdate", translate("Auto update core with crontab"))
 o.default = 0
-nixio.fs.writefile("/var/run/lucilogpos","0")
-return mp
+fs.writefile("/var/run/lucilogpos","0")
+return m

+ 9 - 4
luasrc/model/cbi/AdGuardHome/log.lua

@@ -1,7 +1,6 @@
-local e=require"nixio.fs"
+local fs=require"nixio.fs"
 local uci=require"luci.model.uci".cursor()
-logfile=uci:get("AdGuardHome","AdGuardHome","logfile")
-
+local f,t
 f=SimpleForm("logview")
 f.reset = false
 f.submit = false
@@ -10,5 +9,11 @@ t.rmempty=true
 t.rows=20
 t.template="AdGuardHome/log"
 t.readonly="readonly"
-nixio.fs.writefile("/var/run/lucilogpos","0")
+local logfile=uci:get("AdGuardHome","AdGuardHome","logfile")
+if (logfile=="syslog" or logfile==nil ) then
+t.timereplace=false
+else
+t.timereplace=true
+end
+fs.writefile("/var/run/lucilogpos","0")
 return f

+ 11 - 11
luasrc/model/cbi/AdGuardHome/manual.lua

@@ -1,5 +1,5 @@
 local m, s, o
-local NXFS = require "nixio.fs"
+local fs = require "nixio.fs"
 local uci=require"luci.model.uci".cursor()
 local sys=require"luci.sys"
 require("string")
@@ -32,7 +32,7 @@ function gen_template_config()
 	return table.concat(tbl, "\n")
 end
 m = Map("AdGuardHome")
-local escconf = uci:get("AdGuardHome","AdGuardHome","configpath")
+local configpath = uci:get("AdGuardHome","AdGuardHome","configpath")
 local binpath = uci:get("AdGuardHome","AdGuardHome","binpath")
 s = m:section(TypedSection, "AdGuardHome")
 s.anonymous=true
@@ -43,11 +43,11 @@ o.rows = 66
 o.wrap = "off"
 o.rmempty = true
 o.cfgvalue = function(self, section)
-	return  NXFS.readfile("/tmp/AdGuardHometmpconfig.yaml") or NXFS.readfile(escconf) 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)
-    NXFS.writefile("/tmp/AdGuardHometmpconfig.yaml", value:gsub("\r\n", "\n"))
-	if NXFS.access(binpath) then
+    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
@@ -58,21 +58,21 @@ o.validate=function(self, value)
 	return nil
 end
 o.write = function(self, section, value)
-	NXFS.move("/tmp/AdGuardHometmpconfig.yaml",escconf)
+	fs.move("/tmp/AdGuardHometmpconfig.yaml",configpath)
 end
 o.remove = function(self, section, value)
-	NXFS.writefile(escconf, "")
+	fs.writefile(configpath, "")
 end
 --- js and reload button
 o = s:option(DummyValue, "")
 o.anonymous=true
 o.template = "AdGuardHome/yamleditor"
-if not NXFS.access(binpath) then
+if not fs.access(binpath) then
 	o.description=translate("WARNING!!! no bin found apply config will not be test")
 end
 --- log 
-if (NXFS.access("/tmp/AdGuardHometmpconfig.yaml")) then
-local c=NXFS.readfile("/tmp/AdGuardHometest.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
@@ -80,7 +80,7 @@ o.rows = 5
 o.rmempty = true
 o.name=""
 o.cfgvalue = function(self, section)
-	return NXFS.readfile("/tmp/AdGuardHometest.log")
+	return fs.readfile("/tmp/AdGuardHometest.log")
 end
 end
 end

+ 5 - 11
luasrc/view/AdGuardHome/AdGuardHome_check.htm

@@ -1,14 +1,10 @@
 <%+cbi/valueheader%>
-<%uci=require"luci.model.uci".cursor()%>
-<%nixio=require"nixio"%>
-
+<%fs=require"nixio.fs"%>
 <input type="button" class="cbi-button cbi-button-apply" id="apply_update_button" value="<%:Update core version%>" onclick=" return apply_update() "/>
-<% if not nixio.fs.access(uci:get("AdGuardHome","AdGuardHome","configpath"))then %>
+<% if self.showfastconfig then %>
 <input type="button" class="cbi-button cbi-button-apply" id="to_configpage" value="<%:Fast config%>" onclick="location.href='<%=url([[admin]], [[services]], [[AdGuardHome]], [[manual]])%>'"/>
 <%end%>
-
-
-		<textarea id="cbid.logview.1.conf" class="cbi-input-textarea" style="width: 100%;display:none" data-update="change" rows="5" cols="60" readonly="readonly" > </textarea>
+<textarea id="cbid.logview.1.conf" class="cbi-input-textarea" style="width: 100%;display:none" data-update="change" rows="5" cols="60" readonly="readonly" > </textarea>
 <script type="text/javascript">//<![CDATA[
 function apply_update(){
 	XHR.get('<%=url([[admin]], [[services]], [[AdGuardHome]], [[doupdate]])%>',null,function(x, data){}
@@ -44,12 +40,12 @@ XHR.poll(3, '<%=url([[admin]], [[services]], [[AdGuardHome]], [[check]])%>', nul
 		}
 	}
 );}
-<% if nixio.fs.access("/var/run/update_core") then %>
+<% if fs.access("/var/run/update_core") then %>
 var	btn = document.getElementById('apply_update_button');
 	btn.disabled = true;
 	btn.value    = '<%:Check...%>';
 poll_check();
-<%elseif nixio.fs.access("/var/run/update_core_error") then %>
+<%elseif fs.access("/var/run/update_core_error") then %>
 poll_check();
 <%else%>
 var	btn = document.getElementById('apply_update_button');
@@ -57,6 +53,4 @@ var	btn = document.getElementById('apply_update_button');
 <%end%>
 //]]>
 </script>
-		
-
 <%+cbi/valuefooter%>

+ 0 - 3
luasrc/view/AdGuardHome/AdGuardHome_chpass.htm

@@ -45,8 +45,5 @@ function chpass(btn)
 		ifattr(#self.keylist > 0, "data-choices", { self.keylist, self.vallist })
 	%> />
 	<% if self.password then %><img src="<%=resource%>/cbi/reload.gif" style="vertical-align:middle" title="<%:Reveal/hide password%>" onclick="var e = document.getElementById('<%=cbid%>'); e.type = (e.type=='password') ? 'text' : 'password';" /><% end %>
-	
 	<input type="button" class="cbi-button cbi-button-apply" id="cbid.AdGuardHome.AdGuardHome.applychpass" value="<%:Load culculate model%>" onclick="return chpass(this)"/>
-
-	
 <%+cbi/valuefooter%>

+ 3 - 12
luasrc/view/AdGuardHome/log.htm

@@ -1,14 +1,6 @@
 <%+cbi/valueheader%>
-<%uci=require"luci.model.uci".cursor()
-nixio=require"nixio"
-logfile=uci:get("AdGuardHome","AdGuardHome","logfile")
-if (logfile=="syslog" or logfile==nil ) then
-timereplace=false
-else
-timereplace=true
-end%>
 <input type="checkbox" name="NAME" value="reverse" onclick=" return reverselog()" style="vertical-align:middle;height: auto;" checked><%:reverse%></input>
-<%if timereplace==true then%>
+<%if self.timereplace then%>
 <input type="checkbox" name="NAME" value="localtime" onclick=" return chlogtime()" style="vertical-align:middle;height: auto;" checked><%:localtime%></input><br>
 <%end%>
 <textarea id="cbid.logview.1.conf" class="cbi-input-textarea" style="width: 100%;display:inline" data-update="change" rows="32" cols="60" readonly="readonly" > </textarea>
@@ -16,7 +8,7 @@ end%>
 <input type="button" class="cbi-button cbi-button-apply" value="<%:download log%>" style=" display:inline;" onclick=" return download_log()" />
 <script type="text/javascript">//<![CDATA[
 var islogreverse = true;
-var isutc2local = <%=tostring(timereplace)%>;
+var isutc2local = <%=tostring(self.timereplace)%>;
 function createAndDownloadFile(fileName, content) {
     var aTag = document.createElement('a');
     var blob = new Blob([content]);
@@ -107,6 +99,5 @@ XHR.poll(3, '<%=url([[admin]], [[services]], [[AdGuardHome]], [[getlog]])%>', nu
 );}
 poll_check();
 //]]>
-</script>
-		
+</script>	
 <%+cbi/valuefooter%>

+ 14 - 15
luasrc/view/AdGuardHome/yamleditor.htm

@@ -1,23 +1,22 @@
-    <%+cbi/valueheader%>
-	<script src="/luci-static/resources/codemirror/lib/codemirror.js"></script>
-	<link rel="stylesheet" href="/luci-static/resources/codemirror/lib/codemirror.css"/>
-    <script src="/luci-static/resources/codemirror/mode/yaml/yaml.js"></script>
-	<link rel="stylesheet" href="/luci-static/resources/codemirror/theme/dracula.css"/>
-	<link rel="stylesheet" href="/luci-static/resources/codemirror/addon/fold/foldgutter.css"/>
-	<script src="/luci-static/resources/codemirror/addon/fold/foldcode.js"></script>
-	<script src="/luci-static/resources/codemirror/addon/fold/foldgutter.js"></script>
-	<script src="/luci-static/resources/codemirror/addon/fold/indent-fold.js"></script>
-	<script type="text/javascript">//<![CDATA[
-	var editor = CodeMirror.fromTextArea(document.getElementById("cbid.AdGuardHome.AdGuardHome.escconf"), {
-	mode: "text/yaml",    //实现groovy代码高亮
-	    styleActiveLine: true,
+<%+cbi/valueheader%>
+<script src="/luci-static/resources/codemirror/lib/codemirror.js"></script>
+<link rel="stylesheet" href="/luci-static/resources/codemirror/lib/codemirror.css"/>
+<script src="/luci-static/resources/codemirror/mode/yaml/yaml.js"></script>
+<link rel="stylesheet" href="/luci-static/resources/codemirror/theme/dracula.css"/>
+<link rel="stylesheet" href="/luci-static/resources/codemirror/addon/fold/foldgutter.css"/>
+<script src="/luci-static/resources/codemirror/addon/fold/foldcode.js"></script>
+<script src="/luci-static/resources/codemirror/addon/fold/foldgutter.js"></script>
+<script src="/luci-static/resources/codemirror/addon/fold/indent-fold.js"></script>
+<script type="text/javascript">//<![CDATA[
+var editor = CodeMirror.fromTextArea(document.getElementById("cbid.AdGuardHome.AdGuardHome.escconf"), {
+mode: "text/yaml",    //实现groovy代码高亮
+styleActiveLine: true,
 lineNumbers: true,	//显示行号
 theme: "dracula",	//设置主题
 lineWrapping: true,	//代码折叠
 foldGutter: true,
 gutters: ["CodeMirror-linenumbers", "CodeMirror-foldgutter"],
-matchBrackets: true,//括号匹配
-foldGutter: true
+matchBrackets: true //括号匹配
 }
 );
 function reload_config(){

+ 7 - 1
po/zh-cn/AdGuardHome.po

@@ -191,4 +191,10 @@ msgid "Auto update core with crontab"
 msgstr "计划任务自动更新核心"
 
 msgid "localtime"
-msgstr "本地时间"
+msgstr "本地时间"
+
+msgid "Redirected"
+msgstr "已重定向"
+
+msgid "Not redirect"
+msgstr "未重定向"