Browse Source

meanless change

rufengsuixing 5 years ago
parent
commit
a4d914053c

+ 7 - 29
luasrc/controller/AdGuardHome.lua

@@ -23,12 +23,7 @@ function act_status()
 	local e={}
 	local binpath=uci:get("AdGuardHome","AdGuardHome","binpath")
 	e.running=luci.sys.call("pgrep "..binpath.." >/dev/null")==0
-	local st=fs.readfile("/var/run/AdGredir")
-	if (st=="0") then
-		e.redirect=false
-	else
-		e.redirect=true
-	end
+	e.redirect=(fs.readfile("/var/run/AdGredir")=="1")
 	http.prepare_content("application/json")
 	http.write_json(e)
 end
@@ -41,8 +36,8 @@ end
 function get_log()
 	local logfile=uci:get("AdGuardHome","AdGuardHome","logfile")
 	if (logfile==nil) then
-	http.write("no log available\n")
-	return
+		http.write("no log available\n")
+		return
 	elseif (logfile=="syslog") then
 		if not fs.access("/var/run/AdGuardHomesyslog") then
 			luci.sys.exec("(/usr/share/AdGuardHome/getsyslog.sh &); sleep 1;")
@@ -54,19 +49,10 @@ function get_log()
 		return
 	end
 	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
+	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)
-	if (a==nil) then
-		a=""
-	end
+	local a=f:read(2048000) or ""
 	fdp=f:seek()
 	fs.writefile("/var/run/lucilogpos",tostring(fdp))
 	f:close()
@@ -80,18 +66,10 @@ function do_dellog()
 end
 function check_update()
 	http.prepare_content("text/plain; charset=utf-8")
-	local logpos=fs.readfile("/var/run/lucilogpos")
-	if (logpos ~= nil) then
-	local fdp=tonumber(logpos)
-	else
-	fdp=0
-	end
+	local fdp=tonumber(fs.readfile("/var/run/lucilogpos")) or 0
 	local f=io.open("/tmp/AdGuardHome_update.log", "r+")
 	f:seek("set",fdp)
-	local a=f:read(2048000)
-	if (a==nil) then
-	a=""
-	end
+	local a=f:read(2048000) or ""
 	fdp=f:seek()
 	fs.writefile("/var/run/lucilogpos",tostring(fdp))
 	f:close()

+ 6 - 25
luasrc/model/cbi/AdGuardHome/base.lua

@@ -4,18 +4,9 @@ require("io")
 local m,s,o
 local fs=require"nixio.fs"
 local uci=require"luci.model.uci".cursor()
-local configpath=uci:get("AdGuardHome","AdGuardHome","configpath")
-if (configpath==nil) then
-configpath="/etc/AdGuardHome.yaml"
-end
-local binpath=uci:get("AdGuardHome","AdGuardHome","binpath")
-if (binpath==nil) then
-binpath="/usr/bin/AdGuardHome/AdGuardHome"
-end
-local httpport=luci.sys.exec("awk '/bind_port:/{printf($2);exit;}' "..configpath.." 2>/dev/null")
-if (httpport=="") then
+local configpath=uci:get("AdGuardHome","AdGuardHome","configpath") or "/etc/AdGuardHome.yaml"
+local binpath=uci:get("AdGuardHome","AdGuardHome","binpath") or "/usr/bin/AdGuardHome/AdGuardHome"
 httpport=uci:get("AdGuardHome","AdGuardHome","httpport") or "3000"
-end
 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"
@@ -35,7 +26,7 @@ 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
-local version=uci:get("AdGuardHome","AdGuardHome","version")
+local version=uci:get("AdGuardHome","AdGuardHome","version") or "unknown"
 local e=""
 if not fs.access(configpath) then
 	e=e.." no config"
@@ -43,26 +34,16 @@ end
 if not fs.access(binpath) then
 	e=e.." no bin"
 else
-	if (version ~= nil) then
-		e=version..e
-	else
-		e="unknown"..e
-	end
+	e=version..e
 end
 o=s:option(Button,"restart",translate("Update"))
 o.inputtitle=translate("Update core version")
 o.template = "AdGuardHome/AdGuardHome_check"
-if fs.access(configpath) then
-o.showfastconfig=false
-else
-o.showfastconfig=true
-end
+o.showfastconfig=(not fs.access(configpath))
 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
-port="?"
-end
+if (port=="") then port="?" end
 ---- Redirect
 o = s:option(ListValue, "redirect", port..translate("Redirect"), translate("AdGuardHome redirect mode"))
 o.placeholder = "none"

+ 2 - 6
luasrc/model/cbi/AdGuardHome/log.lua

@@ -9,11 +9,7 @@ t.rmempty=true
 t.rows=20
 t.template="AdGuardHome/log"
 t.readonly="readonly"
-local logfile=uci:get("AdGuardHome","AdGuardHome","logfile")
-if (logfile=="syslog" or logfile==nil ) then
-t.timereplace=false
-else
-t.timereplace=true
-end
+local logfile=uci:get("AdGuardHome","AdGuardHome","logfile") or ""
+t.timereplace=(logfile~="syslog" and logfile~="" )
 fs.writefile("/var/run/lucilogpos","0")
 return f