Ver código fonte

manual config:add button use template

rufengsuixing 5 anos atrás
pai
commit
9a9d994586

+ 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", "dodellog"}, call("do_dellog"))
 entry({"admin", "services", "AdGuardHome", "reloadconfig"}, call("reload_config"))
+entry({"admin", "services", "AdGuardHome", "gettemplateconfig"}, call("get_template_config"))
 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()
 	fs.remove("/tmp/AdGuardHometmpconfig.yaml")
 	http.prepare_content("application/json")

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

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

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

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