浏览代码

manual config:add button use template

rufengsuixing 5 年之前
父节点
当前提交
9a9d994586
共有 3 个文件被更改,包括 37 次插入0 次删除
  1. 28 0
      luasrc/controller/AdGuardHome.lua
  2. 6 0
      luasrc/view/AdGuardHome/yamleditor.htm
  3. 3 0
      po/zh-cn/AdGuardHome.po

+ 28 - 0
luasrc/controller/AdGuardHome.lua

@@ -13,7 +13,35 @@ entry({"admin", "services", "AdGuardHome", "doupdate"}, call("do_update"))
 entry({"admin", "services", "AdGuardHome", "getlog"}, call("get_log"))
 entry({"admin", "services", "AdGuardHome", "getlog"}, call("get_log"))
 entry({"admin", "services", "AdGuardHome", "dodellog"}, call("do_dellog"))
 entry({"admin", "services", "AdGuardHome", "dodellog"}, call("do_dellog"))
 entry({"admin", "services", "AdGuardHome", "reloadconfig"}, call("reload_config"))
 entry({"admin", "services", "AdGuardHome", "reloadconfig"}, call("reload_config"))
+entry({"admin", "services", "AdGuardHome", "gettemplateconfig"}, call("get_template_config"))
 end 
 end 
+function get_template_config()
+	local b
+	local d=""
+	for cnt in io.lines("/tmp/resolv.conf.auto") 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()
 function reload_config()
 	fs.remove("/tmp/AdGuardHometmpconfig.yaml")
 	fs.remove("/tmp/AdGuardHometmpconfig.yaml")
 	http.prepare_content("application/json")
 	http.prepare_content("application/json")

+ 6 - 0
luasrc/view/AdGuardHome/yamleditor.htm

@@ -24,10 +24,16 @@ function reload_config(){
 	function(x, data) {
 	function(x, data) {
 	location.reload();
 	location.reload();
 	});}
 	});}
+function use_template(){
+	XHR.get('<%=url([[admin]], [[services]], [[AdGuardHome]], [[gettemplateconfig]])%>', null,
+	function(x, data) {
+	editor.setValue(x.responseText)
+	});}
 //]]>
 //]]>
 </script> 
 </script> 
 <%fs=require"nixio.fs"%>
 <%fs=require"nixio.fs"%>
 <%if fs.access("/tmp/AdGuardHometmpconfig.yaml") then%>
 <%if fs.access("/tmp/AdGuardHometmpconfig.yaml") then%>
 <input type="button" id="apply_update_button" value="<%:Reload Config%>" onclick=" return reload_config() "/>
 <input type="button" id="apply_update_button" value="<%:Reload Config%>" onclick=" return reload_config() "/>
 <%end%>
 <%end%>
+<input type="button" id="template_button" value="<%:Use template%>" onclick=" return use_template() "/>
 <%+cbi/valuefooter%>
 <%+cbi/valuefooter%>

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

@@ -219,3 +219,6 @@ msgstr "强制更新"
 
 
 msgid "Backup workdir files when shutdown"
 msgid "Backup workdir files when shutdown"
 msgstr "在关机时备份工作目录文件"
 msgstr "在关机时备份工作目录文件"
+
+msgid "Use template"
+msgstr "使用模板"