Prechádzať zdrojové kódy

add fast config the first time

rufengsuixing 5 rokov pred
rodič
commit
285ea0961c

+ 23 - 1
luasrc/model/cbi/AdGuardHome/manual.lua

@@ -2,7 +2,29 @@ local m, s, o
 local NXFS = require "nixio.fs"
 local uci=require"luci.model.uci".cursor()
 local sys=require"luci.sys"
+require("string")
 require("io")
+require("table")
+function gen_template_config()
+	local d=NXFS.readfile("/tmp/resolv.conf.auto")
+	d=string.gsub(d,"nameserver ","  - ")
+	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()
+	return table.concat(tbl, "\n")
+end
 m = Map("AdGuardHome")
 
 local escconf = uci:get("AdGuardHome","AdGuardHome","configpath")
@@ -16,7 +38,7 @@ o.rows = 66
 o.wrap = "off"
 o.rmempty = true
 o.cfgvalue = function(self, section)
-	return NXFS.readfile("/tmp/AdGuardHometmpconfig.yaml") or NXFS.readfile(escconf) or ""
+	return  NXFS.readfile("/tmp/AdGuardHometmpconfig.yaml") or NXFS.readfile(escconf) or gen_template_config() or ""
 end
 o.validate=function(self, value)
     NXFS.writefile("/tmp/AdGuardHometmpconfig.yaml", value:gsub("\r\n", "\n"))

+ 5 - 0
luasrc/view/AdGuardHome/AdGuardHome_check.htm

@@ -3,6 +3,11 @@
 <%nixio=require"nixio"%>
 
 <input class="cbi-button cbi-button-apply" name="apply_update_button" id="apply_update_button" value="<%:Update core version%>" onclick=" return apply_update() "/>
+<% if not nixio.fs.access(uci:get("AdGuardHome","AdGuardHome","configpath"))then %>
+<input class="cbi-button cbi-button-apply" name="to_configpage" id="to_configpage" value="<%:Fast config%>" onclick="location.href='<%=url([[admin]], [[services]], [[AdGuardHome]], [[manual]])%>'"/>
+<%end%>
+
+
 		<textarea id="cbid.logview.1.conf" class="cbi-input-textarea" style="width: 100%;display:none" data-update="change" name="vbid.logview.1.conf" rows="5" cols="60" readonly="readonly" > </textarea>
 <script type="text/javascript">//<![CDATA[
 function apply_update(){

+ 93 - 0
root/usr/share/AdGuardHome/AdGuardHome_template.yaml

@@ -0,0 +1,93 @@
+#提交就可以直接用的配置模板文件,使用重定向dnsmasq上游
+#a template config can be use with a apply,use redirect with dnsmasq upstream
+bind_host: 0.0.0.0
+bind_port: 3000
+users:
+- name: root
+  password: $2y$10$FfeQavihMUiXCuJhHuQwy.6EOXDvkXb/S50qI5fXizqarNT/ShhQm
+language: ""
+rlimit_nofile: 0
+dns:
+  bind_host: 127.0.0.1
+  port: 5553
+  statistics_interval: 1
+  protection_enabled: true
+  filtering_enabled: true
+  filters_update_interval: 24
+  blocking_mode: nxdomain
+  blocked_response_ttl: 10
+  querylog_enabled: false
+  querylog_interval: 1
+  ratelimit: 0
+  ratelimit_whitelist: []
+  refuse_any: false
+  bootstrap_dns:
+#bootstrap_dns
+  all_servers: false
+  allowed_clients: []
+  disallowed_clients: []
+  blocked_hosts: []
+  parental_block_host: ""
+  safebrowsing_block_host: ""
+  blocked_services: []
+  cache_size: 4194304
+  parental_sensitivity: 13
+  parental_enabled: false
+  safesearch_enabled: false
+  safebrowsing_enabled: false
+  safebrowsing_cache_size: 1048576
+  safesearch_cache_size: 1048576
+  parental_cache_size: 1048576
+  cache_time: 30
+  rewrites: []
+  upstream_dns:
+#upstream_dns
+tls:
+  enabled: false
+  server_name: ""
+  force_https: false
+  port_https: 443
+  port_dns_over_tls: 853
+  certificate_chain: ""
+  private_key: ""
+  certificate_path: ""
+  private_key_path: ""
+filters:
+- enabled: true
+  url: https://adguardteam.github.io/AdGuardSDNSFilter/Filters/filter.txt
+  name: AdGuard Simplified Domain Names filter
+  id: 1
+- enabled: true
+  url: https://adaway.org/hosts.txt
+  name: AdAway
+  id: 2
+- enabled: false
+  url: https://hosts-file.net/ad_servers.txt
+  name: hpHosts - Ad and Tracking servers only
+  id: 3
+- enabled: true
+  url: https://www.malwaredomainlist.com/hostslist/hosts.txt
+  name: MalwareDomainList.com Hosts List
+  id: 4
+- enabled: true
+  url: https://raw.githubusercontent.com/vokins/yhosts/master/hosts.txt
+  name: yhost
+  id: 1575018006
+- enabled: false
+  url: https://raw.githubusercontent.com/vokins/yhosts/master/data/tvbox.txt
+  name: tvbox
+  id: 1575018007
+user_rules: []
+dhcp:
+  enabled: false
+  interface_name: ""
+  gateway_ip: ""
+  subnet_mask: ""
+  range_start: ""
+  range_end: ""
+  lease_duration: 86400
+  icmp_timeout_msec: 1000
+clients: []
+log_file: ""
+verbose: false
+schema_version: 5