Browse Source

fix 版本检测导致卡住luci

rufengsuixing 5 years ago
parent
commit
06e09f1271
3 changed files with 24 additions and 9 deletions
  1. 2 1
      README.md
  2. 22 7
      luasrc/model/cbi/AdGuardHome.lua
  3. 0 1
      root/etc/config/AdGuardHome

+ 2 - 1
README.md

@@ -4,9 +4,10 @@
  - 可以管理网页端口
  - luci更新核心版本
  - dns重定向
- - 自定义bin path
+ - 自定义bin path(支持tmp)
  - 自定义config path
  - 自定义work path
  - 自定义log path
 #### 已知问题:
  - 潘多拉固件老旧,不支持shell 的 function,如要使用请安装后手动修改update_core.sh合并函数
+ - db数据库不支持放在比较特别的文件系统上比如 overlay data-stk-oo,请修改workdir,如果检测到overlay会自动重定向到tmp,将会导致重启丢失dns数据库

+ 22 - 7
luasrc/model/cbi/AdGuardHome.lua

@@ -8,10 +8,13 @@ if (configpath==nil) then
 configpath="/etc/AdGuardHome.yaml"
 end
 local binpath=uci:get("AdGuardHome","AdGuardHome","binpath")
-if (configpath==nil) then
-configpath="/usr/bin/AdGuardHome/AdGuardHome"
+if (binpath==nil) then
+binpath="/usr/bin/AdGuardHome/AdGuardHome"
 end
 local httpport=luci.sys.exec("awk '/bind_port:/{printf($2)}' "..configpath.." 2>nul")
+if (httpport=="") then
+httpport=uci:get("AdGuardHome","AdGuardHome","httpport")
+end
 mp = Map("AdGuardHome", translate("AdGuard Home"))
 mp.description = translate("免费和开源,功能强大的全网络广告和跟踪程序拦截DNS服务器")
 mp:section(SimpleSection).template  = "AdGuardHome/AdGuardHome_status"
@@ -31,18 +34,30 @@ o.datatype="port"
 o.rmempty=false
 o.description = translate("<input type=\"button\" style=\"width:180px;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 e=luci.sys.exec(binpath.." --check-config 2>&1")
-e=string.match(e,'(v%d+\.%d+\.%d+)')
+if fs.access(configpath) then
+	local e=luci.sys.exec(binpath.." -c "..configpath.." --check-config 2>&1")
+	e=string.match(e,'(v%d+\.%d+\.%d+)')
+	if (e==nil) then
+	e="not found bin"
+	end
+else
+	if fs.access(binpath) then
+	e="not find config"
+	else
+	e="not found bin and config"
+	end
+end
+
 o=s:option(Button,"restart",translate("手动更新"))
 o.inputtitle=translate("更新核心版本")
-if (e==nil) then
-e="not found"
-end
 o.template = "AdGuardHome/AdGuardHome_check"
 o.description=string.format(translate("目前运行主程序版本").."<strong><font color=\"green\">: %s </font></strong>",e)
 
 ---- port warning not safe
 local port=luci.sys.exec("awk '/  port:/{printf($2)}' "..configpath.." 2>nul")
+if (port=="") then
+port="?"
+end
 ---- Redirect
 o = s:option(ListValue, "redirect", port..translate("Redirect"), translate("AdGuardHome redirect mode"))
 o.placeholder = "none"

+ 0 - 1
root/etc/config/AdGuardHome

@@ -1,5 +1,4 @@
 config AdGuardHome 'AdGuardHome'
-	option port '3000'
 	option enabled '0'
 	option httport '3000'
 	option httpport '3000'