Browse Source

add manual config tab

rufengsuixing 5 years ago
parent
commit
d903fbd2c6

+ 4 - 2
luasrc/controller/AdGuardHome.lua

@@ -3,8 +3,9 @@ nixio=require"nixio"
 local uci=require"luci.model.uci".cursor()
 function index()
 	entry({"admin","services","AdGuardHome"},firstchild(),_("AdGuard Home"),30).dependent=true
-	entry({"admin","services","AdGuardHome","general"},cbi("AdGuardHome"),_("Base Setting"),1)
-    entry({"admin","services","AdGuardHome","log"},form("AdGuardHomelog"),_("Log"),2)
+	entry({"admin","services","AdGuardHome","general"},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"))
@@ -23,6 +24,7 @@ luci.sys.exec("(touch /var/run/update_core ; sh /usr/share/AdGuardHome/update_co
 luci.http.prepare_content("application/json")
 luci.http.write('')
 end
+
 function check_update()
 	luci.http.prepare_content("text/plain; charset=utf-8")
 	logpos=nixio.fs.readfile("/var/run/lucilogpos")

+ 1 - 0
luasrc/model/cbi/AdGuardHome.lua → luasrc/model/cbi/AdGuardHome/base.lua

@@ -106,6 +106,7 @@ 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"

+ 0 - 0
luasrc/model/cbi/AdGuardHomelog.lua → luasrc/model/cbi/AdGuardHome/log.lua


+ 59 - 0
luasrc/model/cbi/AdGuardHome/manual.lua

@@ -0,0 +1,59 @@
+local m, s, o
+local NXFS = require "nixio.fs"
+local uci=require"luci.model.uci".cursor()
+local sys=require"luci.sys"
+m = Map("AdGuardHome")
+
+local escconf = uci:get("AdGuardHome","AdGuardHome","configpath")
+local binpath = uci:get("AdGuardHome","AdGuardHome","binpath")
+s = m:section(TypedSection, "AdGuardHome")
+s.anonymous=true
+s.addremove=false
+o = s:option(TextValue, "escconf")
+o.rows = 33
+o.wrap = "off"
+o.rmempty = true
+o.cfgvalue = function(self, section)
+	return NXFS.readfile("/tmp/AdGuardHometmpconfig.yaml") or NXFS.readfile(escconf)
+end
+o.validate=function(self, value)
+    NXFS.writefile("/tmp/AdGuardHometmpconfig.yaml", value:gsub("\r\n", "\n"))
+	if (sys.call(binpath.." -c /tmp/AdGuardHometmpconfig.yaml --check-config 2> /tmp/AdGuardHometest.log")==0) then
+		NXFS.writefile("/tmp/debug", "o.validate is done")
+	return value
+	end
+	NXFS.writefile("/tmp/debug", "o.validate is false")
+	luci.http.redirect(luci.dispatcher.build_url("admin","services","AdGuardHome","manual"))
+	return nil
+end
+o.write = function(self, section, value)
+	NXFS.move("/tmp/AdGuardHometmpconfig.yaml",escconf)
+	NXFS.writefile("/tmp/debug", "o.write is done")
+end
+o.remove = function(self, section, value)
+	NXFS.writefile(escconf, "")
+end
+if (NXFS.access("/tmp/AdGuardHometmpconfig.yaml")) then
+local c=NXFS.readfile("/tmp/AdGuardHometest.log")
+if (c~="") then
+o = s:option(TextValue, "")
+o.readonly=true
+o.rows = 5
+o.rmempty = true
+o.cfgvalue = function(self, section)
+	return NXFS.readfile("/tmp/AdGuardHometest.log")
+end
+o=s:option(Button,"","")
+o.inputtitle=translate("Reload config")
+o.write=function()
+NXFS.remove("/tmp/AdGuardHometmpconfig.yaml")
+luci.http.redirect(luci.dispatcher.build_url("admin","services","AdGuardHome","manual"))
+end
+end
+end
+local apply = luci.http.formvalue("cbi.apply")
+ if apply then
+     io.popen("/etc/init.d/AdGuardHome reload &")
+end
+
+return m

+ 15 - 0
po/zh-cn/AdGuardHome.po

@@ -88,6 +88,21 @@ msgstr "gfw列表上游服务器"
 msgid "Gfwlist domain upstream dns service"
 msgstr "gfw列表域名上游服务器"
 
+msgid "Username"
+msgstr "用户名"
+
+msgid "Change browser management username"
+msgstr "改变网页登录用户名"
+
+msgid "Check Config"
+msgstr "检查配置"
+
+msgid "unknown"
+msgstr "未知"
+
+msgid "Reload Config"
+msgstr "重新载入配置"
+
 msgid "Change browser management password"
 msgstr "改变网页登录密码"
 

+ 1 - 0
root/etc/init.d/AdGuardHome

@@ -252,6 +252,7 @@ start_service() {
 		config_editor "users.password" "$hashpass" "$configpath"
 		uci set $CONFIGURATION.$CONFIGURATION.hashpass=""
 	fi
+	
 	config_get_bool enabled $CONFIGURATION enabled 0
 	config_get httpport $CONFIGURATION httpport 3000
 	ADDITIONAL_ARGS="$ADDITIONAL_ARGS -p $httpport"