├── README.md
└── luci-app-adguardhome
├── root
├── usr
│ └── share
│ │ ├── AdGuardHome
│ │ ├── tailto.sh
│ │ ├── firewall.start
│ │ ├── links.txt
│ │ ├── watchconfig.sh
│ │ ├── adguardhome.nft.tpl
│ │ ├── getsyslog.sh
│ │ ├── waitnet.sh
│ │ ├── addhost.sh
│ │ ├── gfw2adg.sh
│ │ ├── gfwipset2adg.sh
│ │ ├── AdGuardHome_template.yaml
│ │ └── update_core.sh
│ │ └── rpcd
│ │ └── acl.d
│ │ └── luci-app-adguardhome.json
├── etc
│ ├── uci-defaults
│ │ └── 40_luci-AdGuardHome
│ ├── config
│ │ └── AdGuardHome
│ ├── AdGuardHome.yaml
│ └── init.d
│ │ └── AdGuardHome
└── www
│ └── luci-static
│ └── resources
│ ├── codemirror
│ ├── addon
│ │ └── fold
│ │ │ ├── foldgutter.css
│ │ │ ├── indent-fold.js
│ │ │ ├── foldcode.js
│ │ │ └── foldgutter.js
│ ├── theme
│ │ └── dracula.css
│ ├── mode
│ │ └── yaml
│ │ │ └── yaml.js
│ └── lib
│ │ └── codemirror.css
│ └── twin-bcrypt.min.js
├── luasrc
├── model
│ └── cbi
│ │ └── AdGuardHome
│ │ ├── log.lua
│ │ ├── manual.lua
│ │ └── base.lua
├── view
│ └── AdGuardHome
│ │ ├── AdGuardHome_status.htm
│ │ ├── yamleditor.htm
│ │ ├── AdGuardHome_chpass.htm
│ │ ├── AdGuardHome_check.htm
│ │ └── log.htm
└── controller
│ └── AdGuardHome.lua
├── Makefile
└── po
├── zh-cn
└── AdGuardHome.po
└── zh_Hans
└── AdGuardHome.po
/README.md:
--------------------------------------------------------------------------------
1 | # luci-app-adguardhome
2 |
3 | luci-app-adguardhome for openwrt 24.10 lua
4 |
5 | 这个是sirpdboy自用修改版,完整版本,可以压缩,更新汉化,自适应FW3和FW4,更方便控制,目前BUG最少的版本。
6 |
--------------------------------------------------------------------------------
/luci-app-adguardhome/root/usr/share/AdGuardHome/tailto.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | tail -n $1 "$2" > /var/run/tailtmp
4 | cat /var/run/tailtmp > "$2"
5 | rm /var/run/tailtmp
6 |
--------------------------------------------------------------------------------
/luci-app-adguardhome/root/usr/share/AdGuardHome/firewall.start:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | AdGuardHome_enable=$(uci get AdGuardHome.AdGuardHome.enabled)
4 | redirect=$(uci get AdGuardHome.AdGuardHome.redirect)
5 |
6 | if [ $AdGuardHome_enable -eq 1 -a "$redirect" == "redirect" ]; then
7 | /etc/init.d/AdGuardHome do_redirect 1
8 | fi
9 |
--------------------------------------------------------------------------------
/luci-app-adguardhome/root/usr/share/AdGuardHome/links.txt:
--------------------------------------------------------------------------------
1 | https://github.com/AdguardTeam/AdGuardHome/releases/download/${latest_ver}/AdGuardHome_linux_${Arch}.tar.gz
2 | https://static.adguard.com/adguardhome/release/AdGuardHome_linux_${Arch}.tar.gz
3 | https://static.adguard.com/adguardhome/beta/AdGuardHome_linux_${Arch}.tar.gz
4 |
--------------------------------------------------------------------------------
/luci-app-adguardhome/root/usr/share/AdGuardHome/watchconfig.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | PATH="/usr/sbin:/usr/bin:/sbin:/bin"
4 | configpath=$(uci get AdGuardHome.AdGuardHome.configpath)
5 | while :
6 | do
7 | sleep 10
8 | if [ -f "$configpath" ]; then
9 | /etc/init.d/AdGuardHome do_redirect 1
10 | break
11 | fi
12 | done
13 | return 0
14 |
--------------------------------------------------------------------------------
/luci-app-adguardhome/root/etc/uci-defaults/40_luci-AdGuardHome:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | chmod +x /etc/init.d/AdGuardHome
3 | uci -q batch <<-EOF >/dev/null 2>&1
4 | delete ucitrack.@AdGuardHome[-1]
5 | add ucitrack AdGuardHome
6 | set ucitrack.@AdGuardHome[-1].init=AdGuardHome
7 | commit ucitrack
8 | delete AdGuardHome.AdGuardHome.ucitracktest
9 | EOF
10 |
11 | rm -f /tmp/luci-indexcache
12 | exit 0
13 |
--------------------------------------------------------------------------------
/luci-app-adguardhome/root/usr/share/AdGuardHome/adguardhome.nft.tpl:
--------------------------------------------------------------------------------
1 | table inet adguardhome {
2 | chain prerouting {
3 | type nat hook prerouting priority dstnat; policy accept;
4 |
5 | iifname { "eth0" } return
6 |
7 | fib daddr type local udp dport 53 redirect to :__AGH_PORT__
8 | fib daddr type local tcp dport 53 redirect to :__AGH_PORT__
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/luci-app-adguardhome/root/www/luci-static/resources/codemirror/addon/fold/foldgutter.css:
--------------------------------------------------------------------------------
1 | .CodeMirror-foldmarker{color:blue;text-shadow:#b9f 1px 1px 2px,#b9f -1px -1px 2px,#b9f 1px -1px 2px,#b9f -1px 1px 2px;font-family:arial;line-height:.3;cursor:pointer}.CodeMirror-foldgutter{width:.7em}.CodeMirror-foldgutter-open,.CodeMirror-foldgutter-folded{cursor:pointer}.CodeMirror-foldgutter-open:after{content:"\25BE"}.CodeMirror-foldgutter-folded:after{content:"\25B8"}
2 |
--------------------------------------------------------------------------------
/luci-app-adguardhome/luasrc/model/cbi/AdGuardHome/log.lua:
--------------------------------------------------------------------------------
1 | local fs = require "nixio.fs"
2 | local uci = require"luci.model.uci".cursor()
3 | local f, t
4 | f = SimpleForm("logview")
5 | f.reset = false
6 | f.submit = false
7 | t=f:field(TextValue,"conf")
8 | t.rmempty=true
9 | t.rows=20
10 | t.template="AdGuardHome/log"
11 | t.readonly="readonly"
12 | local logfile=uci:get("AdGuardHome","AdGuardHome","logfile") or ""
13 | t.timereplace=(logfile~="syslog" and logfile~="" )
14 | t.pollcheck=logfile~=""
15 | fs.writefile("/var/run/lucilogpos", "0")
16 | return f
17 |
--------------------------------------------------------------------------------
/luci-app-adguardhome/root/usr/share/AdGuardHome/getsyslog.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | PATH="/usr/sbin:/usr/bin:/sbin:/bin"
4 | logread -e AdGuardHome > /tmp/AdGuardHometmp.log
5 | logread -e AdGuardHome -f >> /tmp/AdGuardHometmp.log &
6 | pid=$!
7 | echo "1">/var/run/AdGuardHomesyslog
8 | while true
9 | do
10 | sleep 12
11 | watchdog=$(cat /var/run/AdGuardHomesyslog)
12 | if [ "$watchdog"x == "0"x ]; then
13 | kill $pid
14 | rm /tmp/AdGuardHometmp.log
15 | rm /var/run/AdGuardHomesyslog
16 | exit 0
17 | else
18 | echo "0">/var/run/AdGuardHomesyslog
19 | fi
20 | done
21 |
--------------------------------------------------------------------------------
/luci-app-adguardhome/root/etc/config/AdGuardHome:
--------------------------------------------------------------------------------
1 |
2 | config AdGuardHome 'AdGuardHome'
3 | option configpath '/etc/AdGuardHome.yaml'
4 | option workdir '/etc/AdGuardHome'
5 | option redirect 'dnsmasq-upstream'
6 | option logfile '/tmp/AdGuardHome.log'
7 | option verbose '0'
8 | option binpath '/usr/bin/AdGuardHome'
9 | option enabled '0'
10 | option core_version 'latest'
11 | option waitonboot '1'
12 | option upxflag '-9'
13 | option update_url 'https://github.com/AdguardTeam/AdGuardHome/releases/download/${Cloud_Version}/AdGuardHome_linux_${Arch}.tar.gz'
14 |
--------------------------------------------------------------------------------
/luci-app-adguardhome/root/www/luci-static/resources/codemirror/addon/fold/indent-fold.js:
--------------------------------------------------------------------------------
1 | !function(e){"object"==typeof exports&&"object"==typeof module?e(require("../../lib/codemirror")):"function"==typeof define&&define.amd?define(["../../lib/codemirror"],e):e(CodeMirror)}(function(e){"use strict";function n(n,t){var i=n.getLine(t),o=i.search(/\S/);return-1==o||/\bcomment\b/.test(n.getTokenTypeAt(e.Pos(t,o+1)))?-1:e.countColumn(i,null,n.getOption("tabSize"))}e.registerHelper("fold","indent",function(t,i){var o=n(t,i.line);if(!(o<0)){for(var r=null,l=i.line+1,f=t.lastLine();l<=f;++l){var u=n(t,l);if(-1==u);else{if(!(u>o))break;r=l}}return r?{from:e.Pos(i.line,t.getLine(i.line).length),to:e.Pos(r,t.getLine(r).length)}:void 0}})});
--------------------------------------------------------------------------------
/luci-app-adguardhome/root/usr/share/AdGuardHome/waitnet.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | PATH="/usr/sbin:/usr/bin:/sbin:/bin"
4 | count=0
5 | while :
6 | do
7 | ping -c 1 -W 1 -q www.baidu.com 1>/dev/null 2>&1
8 | if [ "$?" == "0" ]; then
9 | /etc/init.d/AdGuardHome force_reload
10 | break
11 | fi
12 | ping -c 1 -W 1 -q 202.108.22.5 1>/dev/null 2>&1
13 | if [ "$?" == "0" ]; then
14 | /etc/init.d/AdGuardHome force_reload
15 | break
16 | fi
17 | sleep 5
18 | ping -c 1 -W 1 -q www.google.com 1>/dev/null 2>&1
19 | if [ "$?" == "0" ]; then
20 | /etc/init.d/AdGuardHome force_reload
21 | break
22 | fi
23 | ping -c 1 -W 1 -q 8.8.8.8 1>/dev/null 2>&1
24 | if [ "$?" == "0" ]; then
25 | /etc/init.d/AdGuardHome force_reload
26 | break
27 | fi
28 | sleep 5
29 | count=$((count+1))
30 | if [ $count -gt 18 ]; then
31 | /etc/init.d/AdGuardHome force_reload
32 | break
33 | fi
34 | done
35 | return 0
36 |
--------------------------------------------------------------------------------
/luci-app-adguardhome/root/usr/share/rpcd/acl.d/luci-app-adguardhome.json:
--------------------------------------------------------------------------------
1 | {
2 | "luci-app-adguardhome": {
3 | "description": "Grant UCI access for luci-app-adguardhome",
4 | "read": {
5 | "file": {
6 | "/usr/share/AdGuardHome/addhost.sh": [ "exec" ],
7 | "/usr/share/AdGuardHome/AdGuardHome_template.yaml": [ "read" ],
8 | "/usr/share/AdGuardHome/getsyslog.sh": [ "exec" ],
9 | "/usr/share/AdGuardHome/gfw2adg.sh": [ "exec" ],
10 | "/usr/share/AdGuardHome/gfwipset2adg.sh": [ "exec" ],
11 | "/usr/share/AdGuardHome/update_core.sh": [ "exec" ],
12 | "/usr/share/AdGuardHome/waitnet.sh": [ "exec" ],
13 | "/usr/share/AdGuardHome/watchconfig.sh": [ "exec" ],
14 | "/etc/init.d/AdGuardHome": [ "exec" ],
15 | "/etc/init.d/dnsmasq": [ "exec" ],
16 | "/usr/bin/AdGuardHome/AdGuardHome": [ "exec" ]
17 | },
18 | "uci": [ "AdGuardHome" ]
19 | },
20 | "write": {
21 | "uci": [ "AdGuardHome" ]
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/luci-app-adguardhome/root/usr/share/AdGuardHome/addhost.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | checkmd5(){
4 | local nowmd5=$(md5sum /etc/hosts)
5 | nowmd5=${nowmd5%% *}
6 | local lastmd5=$(uci get AdGuardHome.AdGuardHome.hostsmd5 2>/dev/null)
7 | if [ "$nowmd5" != "$lastmd5" ]; then
8 | uci set AdGuardHome.AdGuardHome.hostsmd5="$nowmd5"
9 | uci commit AdGuardHome
10 | [ "$1" == "noreload" ] || /etc/init.d/AdGuardHome reload
11 | fi
12 | }
13 |
14 | [ "$1" == "del" ] && sed -i '/programaddstart/,/programaddend/d' /etc/hosts && checkmd5 "$2" && exit 0
15 | /usr/bin/awk 'BEGIN{
16 | while ((getline < "/tmp/dhcp.leases") > 0)
17 | {
18 | a[$2]=$4;
19 | }
20 | while (("ip -6 neighbor show | grep -v fe80" | getline) > 0)
21 | {
22 | if (a[$5]) {print $1" "a[$5] >"/tmp/tmphost"; }
23 | }
24 | print "#programaddend" >"/tmp/tmphost";
25 | }'
26 | grep programaddstart /etc/hosts >/dev/null 2>&1
27 | if [ "$?" == "0" ]; then
28 | sed -i '/programaddstart/,/programaddend/c\#programaddstart' /etc/hosts
29 | sed -i '/programaddstart/'r/tmp/tmphost /etc/hosts
30 | else
31 | echo "#programaddstart" >>/etc/hosts
32 | cat /tmp/tmphost >> /etc/hosts
33 | fi
34 | rm /tmp/tmphost
35 | checkmd5 "$2"
36 |
--------------------------------------------------------------------------------
/luci-app-adguardhome/luasrc/view/AdGuardHome/AdGuardHome_status.htm:
--------------------------------------------------------------------------------
1 |
2 |
22 |
23 |
--------------------------------------------------------------------------------
/luci-app-adguardhome/root/www/luci-static/resources/codemirror/theme/dracula.css:
--------------------------------------------------------------------------------
1 | .cm-s-dracula.CodeMirror,.cm-s-dracula .CodeMirror-gutters{background-color:#282a36 !important;color:#f8f8f2 !important;border:0}.cm-s-dracula .CodeMirror-gutters{color:#282a36}.cm-s-dracula .CodeMirror-cursor{border-left:solid thin #f8f8f0}.cm-s-dracula .CodeMirror-linenumber{color:#6d8a88}.cm-s-dracula .CodeMirror-selected{background:rgba(255,255,255,0.10)}.cm-s-dracula .CodeMirror-line::selection,.cm-s-dracula .CodeMirror-line>span::selection,.cm-s-dracula .CodeMirror-line>span>span::selection{background:rgba(255,255,255,0.10)}.cm-s-dracula .CodeMirror-line::-moz-selection,.cm-s-dracula .CodeMirror-line>span::-moz-selection,.cm-s-dracula .CodeMirror-line>span>span::-moz-selection{background:rgba(255,255,255,0.10)}.cm-s-dracula span.cm-comment{color:#6272a4}.cm-s-dracula span.cm-string,.cm-s-dracula span.cm-string-2{color:#f1fa8c}.cm-s-dracula span.cm-number{color:#bd93f9}.cm-s-dracula span.cm-variable{color:#50fa7b}.cm-s-dracula span.cm-variable-2{color:white}.cm-s-dracula span.cm-def{color:#50fa7b}.cm-s-dracula span.cm-operator{color:#ff79c6}.cm-s-dracula span.cm-keyword{color:#ff79c6}.cm-s-dracula span.cm-atom{color:#bd93f9}.cm-s-dracula span.cm-meta{color:#f8f8f2}.cm-s-dracula span.cm-tag{color:#ff79c6}.cm-s-dracula span.cm-attribute{color:#50fa7b}.cm-s-dracula span.cm-qualifier{color:#50fa7b}.cm-s-dracula span.cm-property{color:#66d9ef}.cm-s-dracula span.cm-builtin{color:#50fa7b}.cm-s-dracula span.cm-variable-3,.cm-s-dracula span.cm-type{color:#ffb86c}.cm-s-dracula .CodeMirror-activeline-background{background:rgba(255,255,255,0.1)}.cm-s-dracula .CodeMirror-matchingbracket{text-decoration:underline;color:white !important}
2 |
--------------------------------------------------------------------------------
/luci-app-adguardhome/root/www/luci-static/resources/codemirror/mode/yaml/yaml.js:
--------------------------------------------------------------------------------
1 | !function(e){"object"==typeof exports&&"object"==typeof module?e(require("../../lib/codemirror")):"function"==typeof define&&define.amd?define(["../../lib/codemirror"],e):e(CodeMirror)}(function(e){"use strict";e.defineMode("yaml",function(){var e=new RegExp("\\b(("+["true","false","on","off","yes","no"].join(")|(")+"))$","i");return{token:function(i,t){var r=i.peek(),n=t.escaped;if(t.escaped=!1,"#"==r&&(0==i.pos||/\s/.test(i.string.charAt(i.pos-1))))return i.skipToEnd(),"comment";if(i.match(/^('([^']|\\.)*'?|"([^"]|\\.)*"?)/))return"string";if(t.literal&&i.indentation()>t.keyCol)return i.skipToEnd(),"string";if(t.literal&&(t.literal=!1),i.sol()){if(t.keyCol=0,t.pair=!1,t.pairStart=!1,i.match(/---/))return"def";if(i.match(/\.\.\./))return"def";if(i.match(/\s*-\s+/))return"meta"}if(i.match(/^(\{|\}|\[|\])/))return"{"==r?t.inlinePairs++:"}"==r?t.inlinePairs--:"["==r?t.inlineList++:t.inlineList--,"meta";if(t.inlineList>0&&!n&&","==r)return i.next(),"meta";if(t.inlinePairs>0&&!n&&","==r)return t.keyCol=0,t.pair=!1,t.pairStart=!1,i.next(),"meta";if(t.pairStart){if(i.match(/^\s*(\||\>)\s*/))return t.literal=!0,"meta";if(i.match(/^\s*(\&|\*)[a-z0-9\._-]+\b/i))return"variable-2";if(0==t.inlinePairs&&i.match(/^\s*-?[0-9\.\,]+\s?$/))return"number";if(t.inlinePairs>0&&i.match(/^\s*-?[0-9\.\,]+\s?(?=(,|}))/))return"number";if(i.match(e))return"keyword"}return!t.pair&&i.match(/^\s*(?:[,\[\]{}&*!|>'"%@`][^\s'":]|[^,\[\]{}#&*!|>'"%@`])[^#]*?(?=\s*:($|\s))/)?(t.pair=!0,t.keyCol=i.indentation(),"atom"):t.pair&&i.match(/^:\s*/)?(t.pairStart=!0,"meta"):(t.pairStart=!1,t.escaped="\\"==r,i.next(),null)},startState:function(){return{pair:!1,pairStart:!1,keyCol:0,inlinePairs:0,inlineList:0,literal:!1,escaped:!1}},lineComment:"#",fold:"indent"}}),e.defineMIME("text/x-yaml","yaml"),e.defineMIME("text/yaml","yaml")});
--------------------------------------------------------------------------------
/luci-app-adguardhome/Makefile:
--------------------------------------------------------------------------------
1 | # This is free software, licensed under the Apache License, Version 2.0 .
2 | #
3 |
4 | include $(TOPDIR)/rules.mk
5 |
6 | PKG_NAME:=luci-app-adguardhome
7 | PKG_VERSION:=1.1.1
8 | PKG_MAINTAINER:=
9 |
10 | LUCI_TITLE:=LuCI app for AdGuardHome
11 | LUCI_PKGARCH:=all
12 | LUCI_DEPENDS:=+ca-certs +!wget&&!curl&&!wget-ssl:curl
13 | LUCI_DESCRIPTION:=LuCI support for AdGuardHome
14 |
15 |
16 | define Package/$(PKG_NAME)/conffiles
17 | /etc/config/AdGuardHome
18 | /etc/AdGuardHome.yaml
19 | endef
20 |
21 | define Package/$(PKG_NAME)/preinst
22 | #!/bin/sh
23 | uci -q batch <<-EOF >/dev/null 2>&1
24 | delete ucitrack.@AdGuardHome[-1]
25 | add ucitrack AdGuardHome
26 | set ucitrack.@AdGuardHome[-1].init=AdGuardHome
27 | commit ucitrack
28 | EOF
29 | rm -f /tmp/luci-indexcache
30 | exit 0
31 | endef
32 |
33 | define Package/$(PKG_NAME)/postinst
34 |
35 | #!/bin/sh
36 | chmod +x /usr/share/AdGuardHome/*
37 | chmod +x /etc/init.d/AdGuardHome
38 | /etc/init.d/AdGuardHome enable >/dev/null 2>&1
39 | enable=$(uci get AdGuardHome.AdGuardHome.enabled 2>/dev/null)
40 | if [ "$enable" == "1" ]; then
41 | /etc/init.d/AdGuardHome reload >/dev/null 2>&1
42 | fi
43 | rm -f /tmp/luci-indexcache
44 | rm -f /tmp/luci-modulecache/*
45 | exit 0
46 | endef
47 |
48 | define Package/$(PKG_NAME)/prerm
49 | #!/bin/sh
50 | if [ -z "$${IPKG_INSTROOT}" ]; then
51 | /etc/init.d/AdGuardHome disable
52 | /etc/init.d/AdGuardHome stop
53 | uci -q batch <<-EOF >/dev/null 2>&1
54 | delete ucitrack.@AdGuardHome[-1]
55 | commit ucitrack
56 | EOF
57 | fi
58 | exit 0
59 | endef
60 |
61 | define Package/$(PKG_NAME)/postrm
62 | #!/bin/sh
63 | rm -rf /etc/AdGuardHome/
64 | exit 0
65 | endef
66 | include $(TOPDIR)/feeds/luci/luci.mk
67 |
68 | # call BuildPackage - OpenWrt buildroot signature
69 |
--------------------------------------------------------------------------------
/luci-app-adguardhome/luasrc/view/AdGuardHome/yamleditor.htm:
--------------------------------------------------------------------------------
1 | <%+cbi/valueheader%>
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
40 | <%fs=require"nixio.fs"%>
41 | <%if fs.access("/tmp/AdGuardHometmpconfig.yaml") then%>
42 |
43 | <%end%>
44 |
45 | <%+cbi/valuefooter%>
--------------------------------------------------------------------------------
/luci-app-adguardhome/luasrc/view/AdGuardHome/AdGuardHome_chpass.htm:
--------------------------------------------------------------------------------
1 | <%+cbi/valueheader%>
2 |
32 | 0, "data-choices", { self.keylist, self.vallist })
46 | %> />
47 | <% if self.password then %>
<% end %>
48 |
49 | <%+cbi/valuefooter%>
--------------------------------------------------------------------------------
/luci-app-adguardhome/root/www/luci-static/resources/codemirror/addon/fold/foldcode.js:
--------------------------------------------------------------------------------
1 | !function(n){"object"==typeof exports&&"object"==typeof module?n(require("../../lib/codemirror")):"function"==typeof define&&define.amd?define(["../../lib/codemirror"],n):n(CodeMirror)}(function(n){"use strict";function e(e,o,i,t){if(i&&i.call){var l=i;i=null}else l=r(e,i,"rangeFinder");"number"==typeof o&&(o=n.Pos(o,0));var f=r(e,i,"minFoldSize");function d(n){var r=l(e,o);if(!r||r.to.line-r.from.linee.firstLine();)o=n.Pos(o.line-1,0),u=d(!1);if(u&&!u.cleared&&"unfold"!==t){var a=function(n,e){var o=r(n,e,"widget");if("string"==typeof o){var i=document.createTextNode(o);(o=document.createElement("span")).appendChild(i),o.className="CodeMirror-foldmarker"}else o&&(o=o.cloneNode(!0));return o}(e,i);n.on(a,"mousedown",function(e){c.clear(),n.e_preventDefault(e)});var c=e.markText(u.from,u.to,{replacedWith:a,clearOnEnter:r(e,i,"clearOnEnter"),__isFold:!0});c.on("clear",function(o,r){n.signal(e,"unfold",e,o,r)}),n.signal(e,"fold",e,u.from,u.to)}}n.newFoldFunction=function(n,o){return function(r,i){e(r,i,{rangeFinder:n,widget:o})}},n.defineExtension("foldCode",function(n,o,r){e(this,n,o,r)}),n.defineExtension("isFolded",function(n){for(var e=this.findMarksAt(n),o=0;o=u){if(s&&f&&s.test(f.className))return;i=r(a.indicatorOpen)}}(i||f)&&t.setGutterMarker(n,a.gutter,i)})}function i(t){return new RegExp("(^|\\s)"+t+"(?:$|\\s)\\s*")}function f(t){var o=t.getViewport(),e=t.state.foldGutter;e&&(t.operation(function(){n(t,o.from,o.to)}),e.from=o.from,e.to=o.to)}function a(t,r,n){var i=t.state.foldGutter;if(i){var f=i.options;if(n==f.gutter){var a=e(t,r);a?a.clear():t.foldCode(o(r,0),f)}}}function d(t){var o=t.state.foldGutter;if(o){var e=o.options;o.from=o.to=0,clearTimeout(o.changeUpdate),o.changeUpdate=setTimeout(function(){f(t)},e.foldOnChangeTimeSpan||600)}}function u(t){var o=t.state.foldGutter;if(o){var e=o.options;clearTimeout(o.changeUpdate),o.changeUpdate=setTimeout(function(){var e=t.getViewport();o.from==o.to||e.from-o.to>20||o.from-e.to>20?f(t):t.operation(function(){e.fromo.to&&(n(t,o.to,e.to),o.to=e.to)})},e.updateViewportTimeSpan||400)}}function l(t,o){var e=t.state.foldGutter;if(e){var r=o.line;r>=e.from&&r/dev/null)
7 | nowmd5=${nowmd5%% *}
8 | local lastmd5=$(uci get AdGuardHome.AdGuardHome.gfwlistmd5 2>/dev/null)
9 | if [ "$nowmd5" != "$lastmd5" ]; then
10 | uci set AdGuardHome.AdGuardHome.gfwlistmd5="$nowmd5"
11 | uci commit AdGuardHome
12 | [ "$1" == "noreload" ] || /etc/init.d/AdGuardHome reload
13 | fi
14 | }
15 |
16 | configpath=$(uci get AdGuardHome.AdGuardHome.configpath 2>/dev/null)
17 | [ "$1" == "del" ] && sed -i '/programaddstart/,/programaddend/d' $configpath && checkmd5 "$2" && exit 0
18 | gfwupstream=$(uci get AdGuardHome.AdGuardHome.gfwupstream 2>/dev/null)
19 | if [ -z $gfwupstream ]; then
20 | gfwupstream="tcp://208.67.220.220:5353"
21 | fi
22 | if [ ! -f "$configpath" ]; then
23 | echo "please make a config first"
24 | exit 1
25 | fi
26 | wget-ssl --no-check-certificate https://cdn.jsdelivr.net/gh/gfwlist/gfwlist/gfwlist.txt -O- | base64 -d > /tmp/gfwlist.txt
27 | cat /tmp/gfwlist.txt | awk -v upst="$gfwupstream" 'BEGIN{getline;}{
28 | s1=substr($0,1,1);
29 | if (s1=="!")
30 | {next;}
31 | if (s1=="@"){
32 | $0=substr($0,3);
33 | s1=substr($0,1,1);
34 | white=1;}
35 | else{
36 | white=0;
37 | }
38 |
39 | if (s1=="|")
40 | {s2=substr($0,2,1);
41 | if (s2=="|")
42 | {
43 | $0=substr($0,3);
44 | split($0,d,"/");
45 | $0=d[1];
46 | }else{
47 | split($0,d,"/");
48 | $0=d[3];
49 | }}
50 | else{
51 | split($0,d,"/");
52 | $0=d[1];
53 | }
54 | star=index($0,"*");
55 | if (star!=0)
56 | {
57 | $0=substr($0,star+1);
58 | dot=index($0,".");
59 | if (dot!=0)
60 | $0=substr($0,dot+1);
61 | else
62 | next;
63 | s1=substr($0,1,1);
64 | }
65 | if (s1==".")
66 | {fin=substr($0,2);}
67 | else{fin=$0;}
68 | if (index(fin,".")==0) next;
69 | if (index(fin,"%")!=0) next;
70 | if (index(fin,":")!=0) next;
71 | match(fin,"^[0-9\.]+")
72 | if (RSTART==1 && RLENGTH==length(fin)) {print "ipset add gfwlist "fin>"/tmp/doipset.sh";next;}
73 | if (fin=="" || finl==fin) next;
74 | finl=fin;
75 | if (white==0)
76 | {print(" - '\''[/"fin"/]"upst"'\''");}
77 | else{
78 | print(" - '\''[/"fin"/]#'\''");}
79 | }END{print(" - '\''[/programaddend/]#'\''")}' > /tmp/adguard.list
80 | grep programaddstart $configpath
81 | if [ "$?" == "0" ]; then
82 | sed -i '/programaddstart/,/programaddend/c\ - '\''\[\/programaddstart\/\]#'\''' $configpath
83 | sed -i '/programaddstart/'r/tmp/adguard.list $configpath
84 | else
85 | sed -i '1i\ - '\''[/programaddstart/]#'\''' /tmp/adguard.list
86 | sed -i '/upstream_dns:/'r/tmp/adguard.list $configpath
87 | fi
88 | checkmd5 "$2"
89 | rm -f /tmp/gfwlist.txt /tmp/adguard.list
90 |
--------------------------------------------------------------------------------
/luci-app-adguardhome/luasrc/model/cbi/AdGuardHome/manual.lua:
--------------------------------------------------------------------------------
1 | local m, s, o
2 | local fs = require "nixio.fs"
3 | local uci=require"luci.model.uci".cursor()
4 | local sys=require"luci.sys"
5 | require("string")
6 | require("io")
7 | require("table")
8 | function gen_template_config()
9 | local b
10 | local d=""
11 | local file = "/tmp/resolv.conf.d/resolv.conf.auto"
12 | if not fs.access(file) then
13 | file = "/tmp/resolv.conf.auto"
14 | end
15 | for cnt in io.lines(file) do
16 | b = string.match(cnt, "^[^#]*nameserver%s+([^%s]+)$")
17 | if (b ~= nil) then d = d .. " - " .. b .. "\n" end
18 | end
19 | local f=io.open("/usr/share/AdGuardHome/AdGuardHome_template.yaml", "r+")
20 | local tbl = {}
21 | local a=""
22 | while (1) do
23 | a=f:read("*l")
24 | if (a=="#bootstrap_dns") then
25 | a=d
26 | elseif (a=="#upstream_dns") then
27 | a=d
28 | elseif (a==nil) then
29 | break
30 | end
31 | table.insert(tbl, a)
32 | end
33 | f:close()
34 | return table.concat(tbl, "\n")
35 | end
36 | m = Map("AdGuardHome")
37 | local configpath = uci:get("AdGuardHome","AdGuardHome","configpath")
38 | local binpath = uci:get("AdGuardHome","AdGuardHome","binpath")
39 | s = m:section(TypedSection, "AdGuardHome")
40 | s.anonymous=true
41 | s.addremove=false
42 | --- config
43 | o = s:option(TextValue, "escconf")
44 | o.rows = 66
45 | o.wrap = "off"
46 | o.rmempty = true
47 | o.cfgvalue = function(self, section)
48 | return fs.readfile("/tmp/AdGuardHometmpconfig.yaml") or fs.readfile(configpath) or gen_template_config() or ""
49 | end
50 | o.validate=function(self, value)
51 | fs.writefile("/tmp/AdGuardHometmpconfig.yaml", value:gsub("\r\n", "\n"))
52 | if fs.access(binpath) then
53 | if (sys.call(binpath .. " -c /tmp/AdGuardHometmpconfig.yaml --check-config 2> /tmp/AdGuardHometest.log") == 0) then return value end
54 | else
55 | return value
56 | end
57 | luci.http.redirect(luci.dispatcher.build_url("admin","services","AdGuardHome","manual"))
58 | return nil
59 | end
60 | o.write = function(self, section, value)
61 | fs.move("/tmp/AdGuardHometmpconfig.yaml",configpath)
62 | end
63 | o.remove = function(self, section, value) fs.writefile(configpath, "") end
64 |
65 | --- js and reload button
66 | o = s:option(DummyValue, "")
67 | o.anonymous=true
68 | o.template = "AdGuardHome/yamleditor"
69 | if not fs.access(binpath) then
70 | o.description=translate("WARNING!!! no bin found apply config will not be test")
71 | end
72 | --- log
73 | if (fs.access("/tmp/AdGuardHometmpconfig.yaml")) then
74 | local c=fs.readfile("/tmp/AdGuardHometest.log")
75 | if (c~="") then
76 | o = s:option(TextValue, "")
77 | o.readonly=true
78 | o.rows = 5
79 | o.rmempty = true
80 | o.name=""
81 | o.cfgvalue = function(self, section)
82 | return fs.readfile("/tmp/AdGuardHometest.log")
83 | end
84 | end
85 | end
86 | function m.on_commit(map)
87 | local ucitracktest=uci:get("AdGuardHome","AdGuardHome","ucitracktest")
88 | if ucitracktest=="1" then
89 | return
90 | elseif ucitracktest=="0" then
91 | io.popen("/etc/init.d/AdGuardHome reload &")
92 | else
93 | fs.writefile("/var/run/AdGlucitest","")
94 | end
95 | end
96 | return m
--------------------------------------------------------------------------------
/luci-app-adguardhome/root/usr/share/AdGuardHome/gfwipset2adg.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | PATH="/usr/sbin:/usr/bin:/sbin:/bin"
3 | mkdir -p "/etc/AdGuardHome"
4 | checkmd5(){
5 | local nowmd5=$(md5sum /tmp/adguard.list 2>/dev/null)
6 | nowmd5=${nowmd5%% *}
7 | local lastmd5=$(uci get AdGuardHome.AdGuardHome.ipsetlistmd5 2>/dev/null)
8 | if [ "$nowmd5" != "$lastmd5" ]; then
9 | uci set AdGuardHome.AdGuardHome.ipsetlistmd5="$nowmd5"
10 | uci commit AdGuardHome
11 | [ "$1" == "noreload" ] || /etc/init.d/AdGuardHome reload
12 | fi
13 | }
14 | ipstok=1
15 | configpath=$(uci get AdGuardHome.AdGuardHome.configpath 2>/dev/null)
16 | if [ "$1" == "del" ]; then
17 | #sed -i -r 's/upstream_dns_file:\s*['\"]?.*['\"]?/upstream_dns_file: ""/' $configpath
18 | sed -i -r 's/ipset_file:\s*['\"]?.*['\"]?/ipset_file: ""/' $configpath
19 | checkmd5 "$2"
20 | exit 0
21 | fi
22 | gfwupstream=$(uci get AdGuardHome.AdGuardHome.gfwupstream 2>/dev/null)
23 | if [ -z $gfwupstream ]; then
24 | gfwupstream="tcp://208.67.220.220:5353"
25 | fi
26 | if [ ! -f "$configpath" ]; then
27 | echo "please make a config first"
28 | exit 1
29 | fi
30 | wget-ssl --no-check-certificate https://cdn.jsdelivr.net/gh/gfwlist/gfwlist/gfwlist.txt -O- | base64 -d > /tmp/gfwlist.txt
31 | cat /tmp/gfwlist.txt | awk -v upst="$gfwupstream" 'BEGIN{getline;}{
32 | s1=substr($0,1,1);
33 | if (s1=="!")
34 | {next;}
35 | if (s1=="@"){
36 | $0=substr($0,3);
37 | s1=substr($0,1,1);
38 | white=1;}
39 | else{
40 | white=0;
41 | }
42 |
43 | if (s1=="|")
44 | {s2=substr($0,2,1);
45 | if (s2=="|")
46 | {
47 | $0=substr($0,3);
48 | split($0,d,"/");
49 | $0=d[1];
50 | }else{
51 | split($0,d,"/");
52 | $0=d[3];
53 | }}
54 | else{
55 | split($0,d,"/");
56 | $0=d[1];
57 | }
58 | star=index($0,"*");
59 | if (star!=0)
60 | {
61 | $0=substr($0,star+1);
62 | dot=index($0,".");
63 | if (dot!=0)
64 | $0=substr($0,dot+1);
65 | else
66 | next;
67 | s1=substr($0,1,1);
68 | }
69 | if (s1==".")
70 | {fin=substr($0,2);}
71 | else{fin=$0;}
72 | if (index(fin,".")==0) next;
73 | if (index(fin,"%")!=0) next;
74 | if (index(fin,":")!=0) next;
75 | match(fin,"^[0-9\.]+")
76 | if (RSTART==1 && RLENGTH==length(fin)) {print "ipset add gfwlist "fin>"/tmp/doipset.sh";next;}
77 | if (fin=="" || finl==fin) next;
78 | finl=fin;
79 | if (white==0)
80 | {print(" - '\''[/"fin"/]"upst"'\''");}
81 | else{
82 | print(" - '\''[/"fin"/]#'\''");}
83 | }END{print(" - '\''[/programaddend/]#'\''")}' > /tmp/adguard.list
84 | cat /tmp/adguard.list 2>/dev/null |sed -r -e "s/\s+\-\s+'//" -e "s/'//" -e "/programaddend/d" > /etc/AdGuardHome/gfw.txt
85 | cat /etc/AdGuardHome/gfw.txt 2>/dev/null |sed -e 's:\[\/::' -e 's:\/\].*:\/gfwlist:' -e "/#/d" |sort -u > /etc/AdGuardHome/ipset.txt
86 | #sed -i -r 's/upstream_dns_file:\s*['\"].*['\"]/upstream_dns_file: \/etc\/AdGuardHome\/gfw.txt/' $configpath
87 | which ipset >/dev/null || ipstok=0
88 | if [ -s /etc/AdGuardHome/ipset.txt -a $ipstok -eq 1 ];then
89 | ipset list gfwlist >/dev/null 2>&1 || ipset create gfwlist hash:ip 2>/dev/null
90 | sed -i -r 's/ipset_file:\s*['\"].*['\"]/ipset_file: \/etc\/AdGuardHome\/ipset.txt/' $configpath
91 | fi
92 | checkmd5 "$2"
93 | rm -f /tmp/gfwlist.txt /tmp/adguard.list
--------------------------------------------------------------------------------
/luci-app-adguardhome/luasrc/view/AdGuardHome/AdGuardHome_check.htm:
--------------------------------------------------------------------------------
1 | <%+cbi/valueheader%>
2 | <%local fs=require"nixio.fs"%>
3 |
4 |
5 | <% if self.showfastconfig then %>
6 |
7 | <%end%>
8 |
9 | <%:reverse%>
10 |
11 |
12 |
78 | <%+cbi/valuefooter%>
--------------------------------------------------------------------------------
/luci-app-adguardhome/root/etc/AdGuardHome.yaml:
--------------------------------------------------------------------------------
1 | http:
2 | address: 0.0.0.0:3000
3 | session_ttl: 720h
4 | users:
5 | - name: admin
6 | password: $2y$10$vHRcARdPCieYG3RXWomV5evDYN.Nj/edtwEkQgQJZcK6z7qTLaIc6
7 | auth_attempts: 5
8 | block_auth_min: 15
9 | http_proxy: ""
10 | language: zh-cn
11 | theme: auto
12 | debug_pprof: false
13 | dns:
14 | bind_hosts:
15 | - 0.0.0.0
16 | port: 5553
17 | anonymize_client_ip: false
18 | protection_enabled: true
19 | blocking_mode: default
20 | blocking_ipv4: ""
21 | blocking_ipv6: ""
22 | blocked_response_ttl: 10
23 | protection_disabled_until: null
24 | parental_block_host: family-block.dns.adguard.com
25 | safebrowsing_block_host: standard-block.dns.adguard.com
26 | ratelimit: 0
27 | ratelimit_whitelist: []
28 | refuse_any: false
29 | upstream_dns:
30 | - 223.5.5.5
31 | upstream_dns_file: ""
32 | bootstrap_dns:
33 | - 119.29.29.29
34 | - 223.5.5.5
35 | all_servers: false
36 | fastest_addr: false
37 | fastest_timeout: 1s
38 | allowed_clients: []
39 | disallowed_clients: []
40 | blocked_hosts:
41 | - version.bind
42 | - id.server
43 | - hostname.bind
44 | trusted_proxies:
45 | - 127.0.0.0/8
46 | - ::1/128
47 | cache_size: 4194304
48 | cache_ttl_min: 0
49 | cache_ttl_max: 0
50 | cache_optimistic: true
51 | bogus_nxdomain: []
52 | aaaa_disabled: false
53 | enable_dnssec: false
54 | edns_client_subnet: false
55 | max_goroutines: 300
56 | ipset: []
57 | filtering_enabled: true
58 | filters_update_interval: 24
59 | parental_enabled: false
60 | safesearch_enabled: false
61 | safebrowsing_enabled: false
62 | safebrowsing_cache_size: 1048576
63 | safesearch_cache_size: 1048576
64 | parental_cache_size: 1048576
65 | cache_time: 30
66 | rewrites: []
67 | blocked_services: []
68 | upstream_timeout: 10s
69 | private_networks: []
70 | use_private_ptr_resolvers: true
71 | local_ptr_upstreams: []
72 | tls:
73 | enabled: false
74 | server_name: ""
75 | force_https: false
76 | port_https: 443
77 | port_dns_over_tls: 853
78 | port_dns_over_quic: 784
79 | port_dnscrypt: 0
80 | dnscrypt_config_file: ""
81 | allow_unencrypted_doh: false
82 | certificate_chain: ""
83 | private_key: ""
84 | certificate_path: ""
85 | private_key_path: ""
86 | filters:
87 | - enabled: true
88 | url: https://adguardteam.github.io/AdGuardSDNSFilter/Filters/filter.txt
89 | name: AdGuard DNS filter
90 | id: 1228750870
91 | - enabled: true
92 | url: https://easylist-downloads.adblockplus.org/easylist.txt
93 | name: EasyList-去除国际网页中大多数广告,包括不需要的框架、图像和对象
94 | id: 139789112
95 | - enabled: true
96 | url: https://easylist-downloads.adblockplus.org/easylistchina.txt
97 | name: EasyList China-EasyList针对国内的补充规则
98 | id: 139789121
99 | - enabled: true
100 | url: https://anti-ad.net/easylist.txt
101 | name: anti-AD命中率最高列表
102 | id: 139789221
103 | - enabled: true
104 | url: https://adguardteam.github.io/HostlistsRegistry/assets/filter_1.txt
105 | name: AdGuard DNS filter
106 | id: 139789332
107 | - enabled: false
108 | url: https://adguardteam.github.io/HostlistsRegistry/assets/filter_2.txt
109 | name: AdAway Default Blocklist
110 | id: 149789121
111 | whitelist_filters: []
112 | user_rules:
113 |
114 | dhcp:
115 | enabled: false
116 | interface_name: ""
117 | dhcpv4:
118 | gateway_ip: ""
119 | subnet_mask: ""
120 | range_start: ""
121 | range_end: ""
122 | lease_duration: 86400
123 | icmp_timeout_msec: 1000
124 | options: []
125 | dhcpv6:
126 | range_start: ""
127 | lease_duration: 86400
128 | ra_slaac_only: false
129 | ra_allow_slaac: false
130 | clients: []
131 | log_compress: false
132 | log_localtime: false
133 | log_max_backups: 0
134 | log_max_size: 100
135 | log_max_age: 3
136 | log_file: ""
137 | verbose: false
138 | schema_version: 10
--------------------------------------------------------------------------------
/luci-app-adguardhome/root/usr/share/AdGuardHome/AdGuardHome_template.yaml:
--------------------------------------------------------------------------------
1 | #模板用户名为 admin 密码为 admin
2 | #The username is admin and the password is admin.
3 | #提交就可以直接用的配置模板文件
4 | #a template config can be use with a apply
5 | bind_host: 0.0.0.0
6 | bind_port: 3000
7 | beta_bind_port: 0
8 | users:
9 | - name: admin
10 | password: $2y$10$vHRcARdPCieYG3RXWomV5evDYN.Nj/edtwEkQgQJZcK6z7qTLaIc6
11 | auth_attempts: 5
12 | block_auth_min: 15
13 | http_proxy: ""
14 | language: zh-cn
15 | theme: auto
16 | debug_pprof: false
17 | dns:
18 | bind_hosts:
19 | - 0.0.0.0
20 | port: 5333
21 | anonymize_client_ip: false
22 | protection_enabled: true
23 | blocking_mode: default
24 | blocking_ipv4: ""
25 | blocking_ipv6: ""
26 | blocked_response_ttl: 10
27 | protection_disabled_until: null
28 | parental_block_host: family-block.dns.adguard.com
29 | safebrowsing_block_host: standard-block.dns.adguard.com
30 | ratelimit: 0
31 | ratelimit_whitelist: []
32 | refuse_any: false
33 | upstream_dns:
34 | - 223.5.5.5
35 | upstream_dns_file: ""
36 | bootstrap_dns:
37 | - 119.29.29.29
38 | - 223.5.5.5
39 | all_servers: false
40 | fastest_addr: false
41 | fastest_timeout: 1s
42 | allowed_clients: []
43 | disallowed_clients: []
44 | blocked_hosts:
45 | - version.bind
46 | - id.server
47 | - hostname.bind
48 | trusted_proxies:
49 | - 127.0.0.0/8
50 | - ::1/128
51 | cache_size: 4194304
52 | cache_ttl_min: 0
53 | cache_ttl_max: 0
54 | cache_optimistic: true
55 | bogus_nxdomain: []
56 | aaaa_disabled: false
57 | enable_dnssec: false
58 | edns_client_subnet: false
59 | max_goroutines: 300
60 | ipset: []
61 | filtering_enabled: true
62 | filters_update_interval: 24
63 | parental_enabled: false
64 | safesearch_enabled: false
65 | safebrowsing_enabled: false
66 | safebrowsing_cache_size: 1048576
67 | safesearch_cache_size: 1048576
68 | parental_cache_size: 1048576
69 | cache_time: 30
70 | rewrites: []
71 | blocked_services: []
72 | upstream_timeout: 10s
73 | private_networks: []
74 | use_private_ptr_resolvers: true
75 | local_ptr_upstreams: []
76 | tls:
77 | enabled: false
78 | server_name: ""
79 | force_https: false
80 | port_https: 443
81 | port_dns_over_tls: 853
82 | port_dns_over_quic: 784
83 | port_dnscrypt: 0
84 | dnscrypt_config_file: ""
85 | allow_unencrypted_doh: false
86 | certificate_chain: ""
87 | private_key: ""
88 | certificate_path: ""
89 | private_key_path: ""
90 | filters:
91 | - enabled: true
92 | url: https://adguardteam.github.io/AdGuardSDNSFilter/Filters/filter.txt
93 | name: AdGuard DNS filter
94 | id: 1128750870
95 | - enabled: true
96 | url: https://anti-ad.net/easylist.txt
97 | name: 'CHN: anti-AD'
98 | id: 1128750871
99 | - enabled: true
100 | url: https://adguardteam.github.io/HostlistsRegistry/assets/filter_1.txt
101 | name: AdGuard DNS filter
102 | id: 1128751871
103 | - enabled: false
104 | url: https://adguardteam.github.io/HostlistsRegistry/assets/filter_2.txt
105 | name: AdAway Default Blocklist
106 | id: 1128752871
107 | whitelist_filters: []
108 | user_rules:
109 | - '@@||taobao.com^$important'
110 | - '@@||jd.com^important'
111 | - '@@||flyme.cn^$important'
112 | - '@@||meizu.com^$important'
113 | - '@@||wl.jd.com^$important'
114 | - '@@||flydigi.com^'
115 | - '@@||pv.sohu.com^$important'
116 | dhcp:
117 | enabled: false
118 | interface_name: ""
119 | dhcpv4:
120 | gateway_ip: ""
121 | subnet_mask: ""
122 | range_start: ""
123 | range_end: ""
124 | lease_duration: 86400
125 | icmp_timeout_msec: 1000
126 | options: []
127 | dhcpv6:
128 | range_start: ""
129 | lease_duration: 86400
130 | ra_slaac_only: false
131 | ra_allow_slaac: false
132 | clients: []
133 | log_compress: false
134 | log_localtime: false
135 | log_max_backups: 0
136 | log_max_size: 100
137 | log_max_age: 3
138 | log_file: ""
139 | verbose: false
140 | schema_version: 10
141 |
--------------------------------------------------------------------------------
/luci-app-adguardhome/luasrc/view/AdGuardHome/log.htm:
--------------------------------------------------------------------------------
1 | <%+cbi/valueheader%>
2 | <%:reverse%>
3 | <%if self.timereplace then%>
4 | <%:localtime%>
5 | <%end%>
6 |
7 |
8 |
9 |
111 | <%+cbi/valuefooter%>
--------------------------------------------------------------------------------
/luci-app-adguardhome/luasrc/controller/AdGuardHome.lua:
--------------------------------------------------------------------------------
1 | module("luci.controller.AdGuardHome", package.seeall)
2 | local fs = require "nixio.fs"
3 | local http = require "luci.http"
4 | local uci = require"luci.model.uci".cursor()
5 | function index()
6 | local page = entry({"admin", "services", "AdGuardHome"},alias("admin", "services", "AdGuardHome", "base"),_("AdGuard Home"))
7 | page.order = 11
8 | page.dependent = true
9 | page.acl_depends = { "luci-app-adguardhome" }
10 | entry({"admin", "services", "AdGuardHome", "base"}, cbi("AdGuardHome/base"), _("Base Setting"), 1).leaf = true
11 | entry({"admin", "services", "AdGuardHome", "log"}, form("AdGuardHome/log"), _("Log"), 2).leaf = true
12 | entry({"admin", "services", "AdGuardHome", "manual"}, cbi("AdGuardHome/manual"), _("Manual Config"), 3).leaf = true
13 | entry({"admin", "services", "AdGuardHome", "status"}, call("act_status")).leaf = true
14 | entry({"admin", "services", "AdGuardHome", "check"}, call("check_update"))
15 | entry({"admin", "services", "AdGuardHome", "doupdate"}, call("do_update"))
16 | entry({"admin", "services", "AdGuardHome", "getlog"}, call("get_log"))
17 | entry({"admin", "services", "AdGuardHome", "dodellog"}, call("do_dellog"))
18 | entry({"admin", "services", "AdGuardHome", "reloadconfig"}, call("reload_config"))
19 | entry({"admin", "services", "AdGuardHome", "gettemplateconfig"}, call("get_template_config"))
20 | end
21 | function get_template_config()
22 | local b
23 | local d=""
24 | local file = "/tmp/resolv.conf.d/resolv.conf.auto"
25 | if not fs.access(file) then
26 | file = "/tmp/resolv.conf.auto"
27 | end
28 | for cnt in io.lines(file) do
29 | b = string.match(cnt, "^[^#]*nameserver%s+([^%s]+)$")
30 | if (b ~= nil) then d = d .. " - " .. b .. "\n" end
31 | end
32 | local f=io.open("/usr/share/AdGuardHome/AdGuardHome_template.yaml", "r+")
33 | local tbl = {}
34 | local a=""
35 | while (1) do
36 | a=f:read("*l")
37 | if (a=="#bootstrap_dns") then
38 | a=d
39 | elseif (a=="#upstream_dns") then
40 | a=d
41 | elseif (a==nil) then
42 | break
43 | end
44 | table.insert(tbl, a)
45 | end
46 | f:close()
47 | http.prepare_content("text/plain; charset=utf-8")
48 | http.write(table.concat(tbl, "\n"))
49 | end
50 | function reload_config()
51 | fs.remove("/tmp/AdGuardHometmpconfig.yaml")
52 | http.prepare_content("application/json")
53 | http.write('')
54 | end
55 | function act_status()
56 | local e={}
57 | local binpath=uci:get("AdGuardHome","AdGuardHome","binpath")
58 | e.running=luci.sys.call("pgrep "..binpath.." >/dev/null")==0
59 | e.redirect=(fs.readfile("/var/run/AdGredir")=="1")
60 | http.prepare_content("application/json")
61 | http.write_json(e)
62 | end
63 | function do_update()
64 | fs.writefile("/var/run/lucilogpos","0")
65 | http.prepare_content("application/json")
66 | http.write('')
67 | local arg
68 | if luci.http.formvalue("force") == "1" then
69 | arg="force"
70 | else
71 | arg=""
72 | end
73 | if arg=="force" then
74 | luci.sys.exec("kill $(pgrep /usr/share/AdGuardHome/update_core.sh) ; sh /usr/share/AdGuardHome/update_core.sh "..arg.." >/tmp/AdGuardHome_update.log 2>&1 &")
75 |
76 |
77 | else
78 | luci.sys.exec("sh /usr/share/AdGuardHome/update_core.sh "..arg.." >/tmp/AdGuardHome_update.log 2>&1 &")
79 | end
80 | end
81 | function get_log()
82 | local logfile=uci:get("AdGuardHome","AdGuardHome","logfile")
83 | if (logfile==nil) then
84 | http.write("no log available\n")
85 | return
86 | elseif (logfile=="syslog") then
87 | if not fs.access("/var/run/AdGuardHomesyslog") then
88 | luci.sys.exec("(/usr/share/AdGuardHome/getsyslog.sh &); sleep 1;")
89 | end
90 | logfile="/tmp/AdGuardHometmp.log"
91 | fs.writefile("/var/run/AdGuardHomesyslog","1")
92 | elseif not fs.access(logfile) then
93 | http.write("")
94 | return
95 | end
96 | http.prepare_content("text/plain; charset=utf-8")
97 | local fdp = tonumber(fs.readfile("/var/run/lucilogpos")) or 0
98 | local f=io.open(logfile, "r+")
99 | f:seek("set",fdp)
100 | local a=f:read(2048000) or ""
101 | fdp=f:seek()
102 | fs.writefile("/var/run/lucilogpos",tostring(fdp))
103 | f:close()
104 | http.write(a)
105 | end
106 | function do_dellog()
107 | local logfile=uci:get("AdGuardHome","AdGuardHome","logfile")
108 | fs.writefile(logfile,"")
109 | http.prepare_content("application/json")
110 | http.write('')
111 | end
112 | function check_update()
113 | http.prepare_content("text/plain; charset=utf-8")
114 | local fdp=tonumber(fs.readfile("/var/run/lucilogpos")) or 0
115 | local f=io.open("/tmp/AdGuardHome_update.log", "r+")
116 | f:seek("set",fdp)
117 | local a=f:read(2048000) or ""
118 | fdp=f:seek()
119 | fs.writefile("/var/run/lucilogpos",tostring(fdp))
120 | f:close()
121 | if fs.access("/var/run/update_core") then
122 | http.write(a)
123 | else
124 | http.write(a.."\0")
125 | end
126 | end
127 |
--------------------------------------------------------------------------------
/luci-app-adguardhome/root/www/luci-static/resources/codemirror/lib/codemirror.css:
--------------------------------------------------------------------------------
1 | .CodeMirror{font-family:monospace;height:500px;color:black;direction:ltr}.CodeMirror-lines{padding:4px 0}.CodeMirror pre.CodeMirror-line,.CodeMirror pre.CodeMirror-line-like{padding:0 4px}.CodeMirror-scrollbar-filler,.CodeMirror-gutter-filler{background-color:white}.CodeMirror-gutters{border-right:1px solid #ddd;background-color:#f7f7f7;white-space:nowrap}.CodeMirror-linenumber{padding:0 3px 0 5px;min-width:20px;text-align:right;color:#999;white-space:nowrap}.CodeMirror-guttermarker{color:black}.CodeMirror-guttermarker-subtle{color:#999}.CodeMirror-cursor{border-left:1px solid black;border-right:0;width:0}.CodeMirror div.CodeMirror-secondarycursor{border-left:1px solid silver}.cm-fat-cursor .CodeMirror-cursor{width:auto;border:0 !important;background:#7e7}.cm-fat-cursor div.CodeMirror-cursors{z-index:1}.cm-fat-cursor-mark{background-color:rgba(20,255,20,0.5);-webkit-animation:blink 1.06s steps(1) infinite;-moz-animation:blink 1.06s steps(1) infinite;animation:blink 1.06s steps(1) infinite}.cm-animate-fat-cursor{width:auto;border:0;-webkit-animation:blink 1.06s steps(1) infinite;-moz-animation:blink 1.06s steps(1) infinite;animation:blink 1.06s steps(1) infinite;background-color:#7e7}@-moz-keyframes blink{50%{background-color:transparent}}@-webkit-keyframes blink{50%{background-color:transparent}}@keyframes blink{50%{background-color:transparent}}.cm-tab{display:inline-block;text-decoration:inherit}.CodeMirror-rulers{position:absolute;left:0;right:0;top:-50px;bottom:0;overflow:hidden}.CodeMirror-ruler{border-left:1px solid #ccc;top:0;bottom:0;position:absolute}.cm-s-default .cm-header{color:blue}.cm-s-default .cm-quote{color:#090}.cm-negative{color:#d44}.cm-positive{color:#292}.cm-header,.cm-strong{font-weight:bold}.cm-em{font-style:italic}.cm-link{text-decoration:underline}.cm-strikethrough{text-decoration:line-through}.cm-s-default .cm-keyword{color:#708}.cm-s-default .cm-atom{color:#219}.cm-s-default .cm-number{color:#164}.cm-s-default .cm-def{color:#00f}.cm-s-default .cm-variable-2{color:#05a}.cm-s-default .cm-variable-3,.cm-s-default .cm-type{color:#085}.cm-s-default .cm-comment{color:#a50}.cm-s-default .cm-string{color:#a11}.cm-s-default .cm-string-2{color:#f50}.cm-s-default .cm-meta{color:#555}.cm-s-default .cm-qualifier{color:#555}.cm-s-default .cm-builtin{color:#30a}.cm-s-default .cm-bracket{color:#997}.cm-s-default .cm-tag{color:#170}.cm-s-default .cm-attribute{color:#00c}.cm-s-default .cm-hr{color:#999}.cm-s-default .cm-link{color:#00c}.cm-s-default .cm-error{color:red}.cm-invalidchar{color:red}.CodeMirror-composing{border-bottom:2px solid}div.CodeMirror span.CodeMirror-matchingbracket{color:#0b0}div.CodeMirror span.CodeMirror-nonmatchingbracket{color:#a22}.CodeMirror-matchingtag{background:rgba(255,150,0,.3)}.CodeMirror-activeline-background{background:#e8f2ff}.CodeMirror{position:relative;overflow:hidden;background:white}.CodeMirror-scroll{overflow:scroll !important;margin-bottom:-30px;margin-right:-30px;padding-bottom:30px;height:100%;outline:0;position:relative}.CodeMirror-sizer{position:relative;border-right:30px solid transparent}.CodeMirror-vscrollbar,.CodeMirror-hscrollbar,.CodeMirror-scrollbar-filler,.CodeMirror-gutter-filler{position:absolute;z-index:6;display:none}.CodeMirror-vscrollbar{right:0;top:0;overflow-x:hidden;overflow-y:scroll}.CodeMirror-hscrollbar{bottom:0;left:0;overflow-y:hidden;overflow-x:scroll}.CodeMirror-scrollbar-filler{right:0;bottom:0}.CodeMirror-gutter-filler{left:0;bottom:0}.CodeMirror-gutters{position:absolute;left:0;top:0;min-height:100%;z-index:3}.CodeMirror-gutter{white-space:normal;height:100%;display:inline-block;vertical-align:top;margin-bottom:-30px}.CodeMirror-gutter-wrapper{position:absolute;z-index:4;background:none !important;border:none !important}.CodeMirror-gutter-background{position:absolute;top:0;bottom:0;z-index:4}.CodeMirror-gutter-elt{position:absolute;cursor:default;z-index:4}.CodeMirror-gutter-wrapper ::selection{background-color:transparent}.CodeMirror-gutter-wrapper ::-moz-selection{background-color:transparent}.CodeMirror-lines{cursor:text;min-height:1px}.CodeMirror pre.CodeMirror-line,.CodeMirror pre.CodeMirror-line-like{-moz-border-radius:0;-webkit-border-radius:0;border-radius:0;border-width:0;background:transparent;font-family:inherit;font-size:inherit;margin:0;white-space:pre;word-wrap:normal;line-height:inherit;color:inherit;z-index:2;position:relative;overflow:visible;-webkit-tap-highlight-color:transparent;-webkit-font-variant-ligatures:contextual;font-variant-ligatures:contextual}.CodeMirror-wrap pre.CodeMirror-line,.CodeMirror-wrap pre.CodeMirror-line-like{word-wrap:break-word;white-space:pre-wrap;word-break:normal}.CodeMirror-linebackground{position:absolute;left:0;right:0;top:0;bottom:0;z-index:0}.CodeMirror-linewidget{position:relative;z-index:2;padding:.1px}.CodeMirror-rtl pre{direction:rtl}.CodeMirror-code{outline:0}.CodeMirror-scroll,.CodeMirror-sizer,.CodeMirror-gutter,.CodeMirror-gutters,.CodeMirror-linenumber{-moz-box-sizing:content-box;box-sizing:content-box}.CodeMirror-measure{position:absolute;width:100%;height:0;overflow:hidden;visibility:hidden}.CodeMirror-cursor{position:absolute;pointer-events:none}.CodeMirror-measure pre{position:static}div.CodeMirror-cursors{visibility:hidden;position:relative;z-index:3}div.CodeMirror-dragcursors{visibility:visible}.CodeMirror-focused div.CodeMirror-cursors{visibility:visible}.CodeMirror-selected{background:#d9d9d9}.CodeMirror-focused .CodeMirror-selected{background:#d7d4f0}.CodeMirror-crosshair{cursor:crosshair}.CodeMirror-line::selection,.CodeMirror-line>span::selection,.CodeMirror-line>span>span::selection{background:#d7d4f0}.CodeMirror-line::-moz-selection,.CodeMirror-line>span::-moz-selection,.CodeMirror-line>span>span::-moz-selection{background:#d7d4f0}.cm-searching{background-color:#ffa;background-color:rgba(255,255,0,.4)}.cm-force-border{padding-right:.1px}@media print{.CodeMirror div.CodeMirror-cursors{visibility:hidden}}.cm-tab-wrap-hack:after{content:''}span.CodeMirror-selectedtext{background:0}
2 |
--------------------------------------------------------------------------------
/luci-app-adguardhome/po/zh-cn/AdGuardHome.po:
--------------------------------------------------------------------------------
1 |
2 | msgid "Base Setting"
3 | msgstr "基础设置"
4 |
5 | msgid "Log"
6 | msgstr "日志"
7 |
8 | msgid "AdGuardHome's version"
9 | msgstr "AdGuardHome 版本"
10 |
11 | msgid "Needed to click 'save&apply' to generate the configuration file"
12 | msgstr "需要点击“保存并应用”才能生成配置文件"
13 |
14 | msgid "In case of the latest realease is a source code that can not download the binary file"
15 | msgstr "防止最新release只有源码,导致下载不成功"
16 |
17 | msgid "Manual Config"
18 | msgstr "手动设置"
19 |
20 | msgid "Free and open source, powerful network-wide ads & trackers blocking DNS server."
21 | msgstr "全网络广告和跟踪程序拦截DNS服务器,默认账号和密码均为:admin"
22 |
23 | msgid "RUNNING"
24 | msgstr "运行中"
25 |
26 | msgid "NOT RUNNING"
27 | msgstr "未运行"
28 |
29 | msgid "Redirected"
30 | msgstr "已重定向"
31 |
32 | msgid "Not redirect"
33 | msgstr "未重定向"
34 |
35 | msgid "Collecting data..."
36 | msgstr "获取数据中..."
37 |
38 | msgid "Enable"
39 | msgstr "启用"
40 |
41 | msgid "Browser management port"
42 | msgstr "网页管理端口"
43 |
44 | msgid "Upgrade Core"
45 | msgstr "更新核心"
46 |
47 | msgid "Update core version"
48 | msgstr "更新核心版本"
49 |
50 | msgid "Check..."
51 | msgstr "检查中..."
52 |
53 | msgid "Updated"
54 | msgstr "已更新"
55 |
56 | msgid "Force update"
57 | msgstr "强制更新核心"
58 |
59 | msgid "Fast config"
60 | msgstr "快速配置"
61 |
62 | msgid "Core Version"
63 | msgstr "核心版本"
64 |
65 | msgid "Latest Version"
66 | msgstr "最新版"
67 |
68 | msgid "Beta Version"
69 | msgstr "测试版"
70 |
71 | msgid "Current core version:"
72 | msgstr "当前核心版本:"
73 |
74 | msgid "core version:"
75 | msgstr "核心版本:"
76 |
77 | msgid "no config"
78 | msgstr "没有配置文件"
79 |
80 | msgid "no core"
81 | msgstr "没有核心"
82 |
83 | msgid "Redirect"
84 | msgstr "重定向"
85 |
86 | msgid "none"
87 | msgstr "无"
88 |
89 | msgid "Run as dnsmasq upstream server"
90 | msgstr "作为dnsmasq的上游服务器"
91 |
92 | msgid "Redirect 53 port to AdGuardHome"
93 | msgstr "重定向53端口到AdGuardHome"
94 |
95 | msgid "Use port 53 replace dnsmasq"
96 | msgstr "使用53端口替换dnsmasq"
97 |
98 | msgid "AdGuardHome redirect mode"
99 | msgstr "AdGuardHome重定向模式"
100 |
101 | msgid "Bin Path"
102 | msgstr "执行文件路径"
103 |
104 | msgid "AdGuardHome Bin path if no bin will auto download"
105 | msgstr "AdGuardHome 执行文件路径 如果没有执行文件将自动下载"
106 |
107 | msgid "use upx to compress bin after download"
108 | msgstr "下载后使用upx压缩执行文件"
109 |
110 | msgid "compress faster"
111 | msgstr "快速压缩"
112 |
113 | msgid "compress better"
114 | msgstr "更好的压缩"
115 |
116 | msgid "compress best(can be slow for big files)"
117 | msgstr "最好的压缩(大文件可能慢)"
118 |
119 | msgid "try all available compression methods & filters [slow]"
120 | msgstr "尝试所有可能的压缩方法和过滤器[慢]"
121 |
122 | msgid "try even more compression variants [very slow]"
123 | msgstr "尝试更多变体压缩手段[很慢]"
124 |
125 | msgid "bin use less space,but may have compatibility issues"
126 | msgstr "减小执行文件空间占用,但是可能压缩后有兼容性问题"
127 |
128 | msgid "Config Path"
129 | msgstr "配置文件路径"
130 |
131 | msgid "AdGuardHome config path"
132 | msgstr "AdGuardHome 配置文件路径"
133 |
134 | msgid "Work dir"
135 | msgstr "工作目录"
136 |
137 | msgid "AdGuardHome work dir include rules,audit log and database"
138 | msgstr "AdGuardHome 工作目录包含规则,审计日志和数据库"
139 |
140 | msgid "Runtime log file"
141 | msgstr "运行日志路径"
142 |
143 | msgid "AdGuardHome runtime Log file if 'syslog': write to system log;if empty no log"
144 | msgstr "AdGuardHome 运行日志, 如果填 syslog 将写入系统日志; 如果该项为空则不记录运行日志"
145 |
146 | msgid "Verbose log"
147 | msgstr "输出详细日志"
148 |
149 | msgid "Add gfwlist"
150 | msgstr "添加 GFW 列表"
151 |
152 | msgid "Add"
153 | msgstr "添加"
154 |
155 | msgid "Added"
156 | msgstr "已添加"
157 |
158 | msgid "Not added"
159 | msgstr "未添加"
160 |
161 | msgid "Del gfwlist"
162 | msgstr "删除gfw列表"
163 |
164 | msgid "Del"
165 | msgstr "删除"
166 |
167 | msgid "Gfwlist upstream dns server"
168 | msgstr "gfw列表上游服务器"
169 |
170 | msgid "Gfwlist domain upstream dns service"
171 | msgstr "gfw列表域名上游服务器"
172 |
173 | msgid "Change management password"
174 | msgstr "更改登录密码"
175 |
176 | msgid "Culculate"
177 | msgstr "计算"
178 |
179 | msgid "Load culculate model"
180 | msgstr "载入计算模块"
181 |
182 | msgid "loading..."
183 | msgstr "载入中"
184 |
185 | msgid "Please save/apply"
186 | msgstr "请点击[保存/应用]"
187 |
188 | msgid "is empty"
189 | msgstr "为空"
190 |
191 | msgid "Press load culculate model and culculate finally save/apply"
192 | msgstr "先输入你想要的密码, 点击[载入计算模块], 然后点击[计算], 最后点击下方[保存&应用]"
193 |
194 | msgid "Keep files when system upgrade"
195 | msgstr "系统升级时保留文件"
196 |
197 | msgid "core bin"
198 | msgstr "核心执行文件"
199 |
200 | msgid "config file"
201 | msgstr "配置文件"
202 |
203 | msgid "log file"
204 | msgstr "日志文件"
205 |
206 | msgid "querylog.json"
207 | msgstr "审计日志.json"
208 |
209 | msgid "On boot when network ok restart"
210 | msgstr "开机后网络准备好时重启"
211 |
212 | msgid "Backup workdir files when shutdown"
213 | msgstr "在关机时备份工作目录文件"
214 |
215 | msgid "Will be restore when workdir/data is empty"
216 | msgstr "在工作目录/data为空的时候恢复"
217 |
218 | msgid "Backup workdir path"
219 | msgstr "工作目录备份路径"
220 |
221 | msgid "Crontab task"
222 | msgstr "计划任务"
223 |
224 | msgid "Auto update core"
225 | msgstr "自动升级核心"
226 |
227 | msgid "Auto tail querylog"
228 | msgstr "自动截短查询日志"
229 |
230 | msgid "Auto tail runtime log"
231 | msgstr "自动截短运行日志"
232 |
233 | msgid "Auto update ipv6 hosts and restart adh"
234 | msgstr "自动更新ipv6主机并重启adh"
235 |
236 | msgid "Auto update gfwlist and restart adh"
237 | msgstr "自动更新gfw列表并重启adh"
238 |
239 | msgid "Please change time and args in crontab"
240 | msgstr "请在计划任务中修改时间和参数"
241 |
242 | msgid "Core Update URL"
243 | msgstr "核心更新地址"
244 |
245 | msgid "reverse"
246 | msgstr "逆序"
247 |
248 | msgid "localtime"
249 | msgstr "本地时间"
250 |
251 | msgid "Please add log path in config to enable log"
252 | msgstr "请在设置里填写日志路径以启用日志"
253 |
254 | msgid "dellog"
255 | msgstr "删除日志"
256 |
257 | msgid "download log"
258 | msgstr "下载日志"
259 |
260 | msgid "Use template"
261 | msgstr "使用模板"
262 |
263 | msgid "Reload Config"
264 | msgstr "重新载入配置"
265 |
266 | msgid "WARNING!!! no bin found apply config will not be test"
267 | msgstr "警告!!!未找到执行文件,提交配置将不会进行校验"
268 |
269 | msgid "Change browser management username"
270 | msgstr "改变网页登录用户名"
271 |
272 | msgid "Username"
273 | msgstr "用户名"
274 |
275 | msgid "Check Config"
276 | msgstr "检查配置"
277 |
278 | msgid "unknown"
279 | msgstr "未知"
280 |
281 | msgid "Keep database when system upgrade"
282 | msgstr "系统升级时保留数据"
283 |
284 | msgid "Start up only when the network is normal"
285 | msgstr "开机网络正常才启动"
286 |
287 | msgid "Other Settings"
288 | msgstr "其它设置"
289 |
290 | msgid ""
291 | msgstr ""
292 |
293 | msgid ""
294 | msgstr ""
295 |
296 | msgid ""
297 | msgstr ""
298 |
--------------------------------------------------------------------------------
/luci-app-adguardhome/po/zh_Hans/AdGuardHome.po:
--------------------------------------------------------------------------------
1 |
2 |
3 | msgid "Log"
4 | msgstr "日志"
5 |
6 | msgid "AdGuardHome's version"
7 | msgstr "AdGuardHome 版本"
8 |
9 | msgid "Needed to click 'save&apply' to generate the configuration file"
10 | msgstr "需要点击“保存并应用”才能生成配置文件"
11 |
12 | msgid "In case of the latest realease is a source code that can not download the binary file"
13 | msgstr "防止最新release只有源码,导致下载不成功"
14 |
15 | msgid "Manual Config"
16 | msgstr "手动设置"
17 |
18 | msgid "Free and open source, powerful network-wide ads & trackers blocking DNS server."
19 | msgstr "全网络广告和跟踪程序拦截DNS服务器,默认账号和密码均为:admin"
20 |
21 | msgid "RUNNING"
22 | msgstr "运行中"
23 |
24 | msgid "NOT RUNNING"
25 | msgstr "未运行"
26 |
27 | msgid "Redirected"
28 | msgstr "已重定向"
29 |
30 | msgid "Not redirect"
31 | msgstr "未重定向"
32 |
33 | msgid "Collecting data..."
34 | msgstr "获取数据中..."
35 |
36 | msgid "Enable"
37 | msgstr "启用"
38 |
39 | msgid "Browser management port"
40 | msgstr "网页管理端口"
41 |
42 | msgid "Upgrade Core"
43 | msgstr "更新核心"
44 |
45 | msgid "Update core version"
46 | msgstr "更新核心版本"
47 |
48 | msgid "Check..."
49 | msgstr "检查中..."
50 |
51 | msgid "Updated"
52 | msgstr "已更新"
53 |
54 | msgid "Force update"
55 | msgstr "强制更新核心"
56 |
57 | msgid "Fast config"
58 | msgstr "快速配置"
59 |
60 | msgid "Core Version"
61 | msgstr "核心版本"
62 |
63 | msgid "Latest Version"
64 | msgstr "最新版"
65 |
66 | msgid "Beta Version"
67 | msgstr "测试版"
68 |
69 | msgid "Current core version:"
70 | msgstr "当前核心版本:"
71 |
72 | msgid "core version:"
73 | msgstr "核心版本:"
74 |
75 | msgid "no config"
76 | msgstr "没有配置文件"
77 |
78 | msgid "no core"
79 | msgstr "没有核心"
80 |
81 | msgid "Redirect"
82 | msgstr "重定向"
83 |
84 | msgid "none"
85 | msgstr "无"
86 |
87 | msgid "Run as dnsmasq upstream server"
88 | msgstr "作为dnsmasq的上游服务器"
89 |
90 | msgid "Redirect 53 port to AdGuardHome"
91 | msgstr "重定向53端口到AdGuardHome"
92 |
93 | msgid "Use port 53 replace dnsmasq"
94 | msgstr "使用53端口替换dnsmasq"
95 |
96 | msgid "AdGuardHome redirect mode"
97 | msgstr "AdGuardHome重定向模式"
98 |
99 | msgid "Bin Path"
100 | msgstr "执行文件路径"
101 |
102 | msgid "AdGuardHome Bin path if no bin will auto download"
103 | msgstr "AdGuardHome 执行文件路径 如果没有执行文件将自动下载"
104 |
105 | msgid "use upx to compress bin after download"
106 | msgstr "下载后使用upx压缩执行文件"
107 |
108 | msgid "compress faster"
109 | msgstr "快速压缩"
110 |
111 | msgid "compress better"
112 | msgstr "更好的压缩"
113 |
114 | msgid "compress best(can be slow for big files)"
115 | msgstr "最好的压缩(大文件可能慢)"
116 |
117 | msgid "try all available compression methods & filters [slow]"
118 | msgstr "尝试所有可能的压缩方法和过滤器[慢]"
119 |
120 | msgid "try even more compression variants [very slow]"
121 | msgstr "尝试更多变体压缩手段[很慢]"
122 |
123 | msgid "bin use less space,but may have compatibility issues"
124 | msgstr "减小执行文件空间占用,但是可能压缩后有兼容性问题"
125 |
126 | msgid "Config Path"
127 | msgstr "配置文件路径"
128 |
129 | msgid "AdGuardHome config path"
130 | msgstr "AdGuardHome 配置文件路径"
131 |
132 | msgid "Work dir"
133 | msgstr "工作目录"
134 |
135 | msgid "AdGuardHome work dir include rules,audit log and database"
136 | msgstr "AdGuardHome 工作目录包含规则,审计日志和数据库"
137 |
138 | msgid "Runtime log file"
139 | msgstr "运行日志路径"
140 |
141 | msgid "AdGuardHome runtime Log file if 'syslog': write to system log;if empty no log"
142 | msgstr "AdGuardHome 运行日志, 如果填 syslog 将写入系统日志; 如果该项为空则不记录运行日志"
143 |
144 | msgid "Verbose log"
145 | msgstr "输出详细日志"
146 |
147 | msgid "Add gfwlist"
148 | msgstr "添加 GFW 列表"
149 |
150 | msgid "Add"
151 | msgstr "添加"
152 |
153 | msgid "Added"
154 | msgstr "已添加"
155 |
156 | msgid "Not added"
157 | msgstr "未添加"
158 |
159 | msgid "Del gfwlist"
160 | msgstr "删除gfw列表"
161 |
162 | msgid "Del"
163 | msgstr "删除"
164 |
165 | msgid "Gfwlist upstream dns server"
166 | msgstr "gfw列表上游服务器"
167 |
168 | msgid "Gfwlist domain upstream dns service"
169 | msgstr "gfw列表域名上游服务器"
170 |
171 | msgid "Change management password"
172 | msgstr "更改登录密码"
173 |
174 | msgid "Culculate"
175 | msgstr "计算"
176 |
177 | msgid "Load culculate model"
178 | msgstr "载入计算模块"
179 |
180 | msgid "loading..."
181 | msgstr "载入中"
182 |
183 | msgid "Please save/apply"
184 | msgstr "请点击[保存/应用]"
185 |
186 | msgid "is empty"
187 | msgstr "为空"
188 |
189 | msgid "Press load culculate model and culculate finally save/apply"
190 | msgstr "先输入你想要的密码, 点击[载入计算模块], 然后点击[计算], 最后点击下方[保存&应用]"
191 |
192 | msgid "Keep files when system upgrade"
193 | msgstr "系统升级时保留文件"
194 |
195 | msgid "core bin"
196 | msgstr "核心执行文件"
197 |
198 | msgid "config file"
199 | msgstr "配置文件"
200 |
201 | msgid "log file"
202 | msgstr "日志文件"
203 |
204 | msgid "querylog.json"
205 | msgstr "审计日志.json"
206 |
207 | msgid "On boot when network ok restart"
208 | msgstr "开机后网络准备好时重启"
209 |
210 | msgid "Backup workdir files when shutdown"
211 | msgstr "在关机时备份工作目录文件"
212 |
213 | msgid "Will be restore when workdir/data is empty"
214 | msgstr "在工作目录/data为空的时候恢复"
215 |
216 | msgid "Backup workdir path"
217 | msgstr "工作目录备份路径"
218 |
219 | msgid "Crontab task"
220 | msgstr "计划任务"
221 |
222 | msgid "Auto update core"
223 | msgstr "自动升级核心"
224 |
225 | msgid "Auto tail querylog"
226 | msgstr "自动截短查询日志"
227 |
228 | msgid "Auto tail runtime log"
229 | msgstr "自动截短运行日志"
230 |
231 | msgid "Auto update ipv6 hosts and restart AdGuardHome"
232 | msgstr "自动更新ipv6主机并重启AdGuardHome"
233 |
234 | msgid "Auto update gfwlist and restart AdGuardHome"
235 | msgstr "自动更新gfw列表并重启AdGuardHome"
236 |
237 | msgid "Auto update ipset list and restart AdGuardHome"
238 | msgstr "自动更新ipset列表并重启AdGuardHome"
239 |
240 | msgid "Please change time and args in crontab"
241 | msgstr "请在计划任务中修改时间和参数"
242 |
243 | msgid "Core Update URL"
244 | msgstr "核心更新地址"
245 |
246 | msgid "reverse"
247 | msgstr "逆序"
248 |
249 | msgid "localtime"
250 | msgstr "本地时间"
251 |
252 | msgid "Please add log path in config to enable log"
253 | msgstr "请在设置里填写日志路径以启用日志"
254 |
255 | msgid "dellog"
256 | msgstr "删除日志"
257 |
258 | msgid "download log"
259 | msgstr "下载日志"
260 |
261 | msgid "Use template"
262 | msgstr "使用模板"
263 |
264 | msgid "Reload Config"
265 | msgstr "重新载入配置"
266 |
267 | msgid "WARNING!!! no bin found apply config will not be test"
268 | msgstr "警告!!!未找到执行文件,提交配置将不会进行校验"
269 |
270 | msgid "Change browser management username"
271 | msgstr "改变网页登录用户名"
272 |
273 | msgid "Username"
274 | msgstr "用户名"
275 |
276 | msgid "Check Config"
277 | msgstr "检查配置"
278 |
279 | msgid "unknown"
280 | msgstr "未知"
281 |
282 | msgid "Keep database when system upgrade"
283 | msgstr "系统升级时保留数据"
284 |
285 | msgid "Start up only when the network is normal"
286 | msgstr "开机网络正常才启动"
287 |
288 | msgid "Main Config"
289 | msgstr "主要设置"
290 |
291 | msgid "Other Config"
292 | msgstr "其它设置"
293 |
294 | msgid "Core Config"
295 | msgstr "内核设置"
296 |
297 | msgid "will set to name gfwlist"
298 | msgstr "将设置为gfwlist名称"
299 |
300 | msgid ""
301 | msgstr ""
--------------------------------------------------------------------------------
/luci-app-adguardhome/root/usr/share/AdGuardHome/update_core.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | PATH="/usr/sbin:/usr/bin:/sbin:/bin"
4 | update_mode=$1
5 | binpath=$(uci get AdGuardHome.AdGuardHome.binpath)
6 | if [ -z "$binpath" ]; then
7 | uci set AdGuardHome.AdGuardHome.binpath="/tmp/AdGuardHome/AdGuardHome"
8 | binpath="/tmp/AdGuardHome/AdGuardHome"
9 | fi
10 | [[ ! -d ${binpath%/*} ]] && mkdir -p ${binpath%/*}
11 | upxflag=$(uci get AdGuardHome.AdGuardHome.upxflag 2>/dev/null)
12 |
13 | [[ -z ${upxflag} ]] && upxflag=off
14 | enabled=$(uci get AdGuardHome.AdGuardHome.enabled 2>/dev/null)
15 | core_version=$(uci get AdGuardHome.AdGuardHome.core_version 2>/dev/null)
16 | case "${core_version}" in
17 | beta)
18 | core_api_url=https://api.github.com/repos/AdguardTeam/AdGuardHome/releases
19 | ;;
20 | *)
21 | core_api_url=https://api.github.com/repos/AdguardTeam/AdGuardHome/releases/latest
22 | ;;
23 | esac
24 |
25 | Check_Task(){
26 | running_tasks="$(ps -efww | grep -v grep | grep "AdGuardHome" | grep "update_core" | awk '{print $1}' | wc -l)"
27 | case $1 in
28 | force)
29 | echo -e "执行: 强制更新核心"
30 | echo -e "清除 ${running_tasks} 个进程 ..."
31 | ps -efww | grep -v grep | grep -v $$ | grep "AdGuardHome" | grep "update_core" | awk '{print $1}' | xargs kill -9 2> /dev/null
32 | ;;
33 | *)
34 | [[ ${running_tasks} -gt 2 ]] && echo -e "已经有 ${running_tasks} 个任务正在运行, 请等待其执行结束或将其强行停止!" && EXIT 2
35 | ;;
36 | esac
37 | }
38 |
39 | Check_Downloader(){
40 | which curl > /dev/null 2>&1 && PKG="curl" && return
41 | echo -e "\n未安装 curl"
42 | which wget-ssl > /dev/null 2>&1 && PKG="wget-ssl" && return
43 | echo "未安装 curl 和 wget, 无法检测更新!" && EXIT 1
44 | }
45 |
46 | Check_Updates(){
47 | Check_Downloader
48 | case "${PKG}" in
49 | curl)
50 | Downloader="curl -L -k -o"
51 | _Downloader="curl -s"
52 | ;;
53 | wget-ssl)
54 | Downloader="wget-ssl --no-check-certificate -T 5 -O"
55 | _Downloader="wget-ssl -q -O -"
56 | ;;
57 | esac
58 | echo "[${PKG}] 开始检查更新, 请耐心等待 ..."
59 | Cloud_Version="$(${_Downloader} ${core_api_url} 2>/dev/null | grep 'tag_name' | grep -Eo "v[0-9].+[0-9.]" | awk 'NR==1')"
60 | [[ -z ${Cloud_Version} ]] && echo -e "\n检查更新失败, 请检查网络或稍后重试!" && EXIT 1
61 | if [[ -f ${binpath} ]]; then
62 | Current_Version="$(${binpath} --version 2>/dev/null | grep -Eo "v[0-9].+[0-9]" | sed -r 's/(.*), c(.*)/\1/')"
63 | else
64 | Current_Version="未知"
65 | fi
66 | [[ -z ${Current_Version} ]] && Current_Version="未知"
67 | echo -e "\n执行文件: ${binpath}\n正在检查更新, 请耐心等待 ..."
68 | echo -e "\n当前 AdGuardHome 版本: ${Current_Version}\n云端 AdGuardHome 版本: ${Cloud_Version}"
69 | if [[ ! "${Cloud_Version}" == "${Current_Version}" || "$1" == force ]]; then
70 | Update_Core
71 | else
72 | echo -e "\n已是最新版本, 无需更新!"
73 | EXIT 0
74 | fi
75 | EXIT 0
76 | }
77 |
78 | UPX_Compress(){
79 | Arch_upx=$(GET_Arch )
80 | # https://github.com/upx/upx/releases/download/v5.0.0/upx-5.0.0-amd64_linux.tar.xz
81 | upx_latest_ver="$(${_Downloader} https://api.github.com/repos/upx/upx/releases/latest 2>/dev/null | grep -E 'tag_name' | grep -E '[0-9.]+' -o 2>/dev/null)"
82 | upx_name="upx-${upx_latest_ver}-${Arch_upx}_linux.tar.xz"
83 | echo -e "开始下载 ${upx_name} ...\n"
84 | $Downloader /tmp/upx-${upx_latest_ver}-${Arch_upx}_linux.tar.xz "https://github.com/upx/upx/releases/download/v${upx_latest_ver}/${upx_name}"
85 | if [[ ! -e /tmp/upx-${upx_latest_ver}-${Arch_upx}_linux.tar.xz ]]; then
86 | echo -e "\n${upx_name} 下载失败!\n"
87 | EXIT 1
88 | else
89 | echo -e "\n${upx_name} 下载成功!\n"
90 | fi
91 | which xz > /dev/null 2>&1 || (opkg list | grep ^xz || opkg update > /dev/null 2>&1 && opkg install xz --force-depends) || (echo "软件包 xz 安装失败!" && EXIT 1)
92 | mkdir -p /tmp/upx-${upx_latest_ver}-${Arch_upx}_linux
93 | echo -e "正在解压 ${upx_name} ...\n"
94 | xz -d -c /tmp/upx-${upx_latest_ver}-${Arch_upx}_linux.tar.xz | tar -x -C "/tmp"
95 | [[ ! -f /tmp/upx-${upx_latest_ver}-${Arch_upx}_linux/upx ]] && echo -e "\n${upx_name} 解压失败!" && EXIT 1
96 | }
97 |
98 | Update_Core(){
99 | rm -r /tmp/AdGuardHome_Update > /dev/null 2>&1
100 | mkdir -p "/tmp/AdGuardHome_Update"
101 |
102 | Arch=$(GET_Arch )
103 | eval link=$(uci get AdGuardHome.AdGuardHome.update_url 2>/dev/null)
104 | echo -e "下载链接:${link}"
105 | echo -e "文件名称:${link##*/}"
106 | echo -e "\n开始下载 AdGuardHome 核心文件 ...\n"
107 | $Downloader /tmp/AdGuardHome_Update/${link##*/} ${link}
108 | if [[ $? != 0 ]];then
109 | echo -e "\nAdGuardHome 核心下载失败 ..."
110 | rm -r /tmp/AdGuardHome_Update
111 | EXIT 1
112 | fi
113 | if [[ ${link##*.} == gz ]]; then
114 | echo -e "\n正在解压 AdGuardHome ..."
115 | tar -zxf "/tmp/AdGuardHome_Update/${link##*/}" -C "/tmp/AdGuardHome_Update/"
116 | if [[ ! -e /tmp/AdGuardHome_Update/AdGuardHome ]]
117 | then
118 | echo "AdGuardHome 核心解压失败!"
119 | rm -rf "/tmp/AdGuardHome_Update" > /dev/null 2>&1
120 | EXIT 1
121 | fi
122 | downloadbin="/tmp/AdGuardHome_Update/AdGuardHome/AdGuardHome"
123 | else
124 | downloadbin="/tmp/AdGuardHome_Update/${link##*/}"
125 | fi
126 | chmod +x ${downloadbin}
127 | echo -e "\nAdGuardHome 核心体积: $(awk 'BEGIN{printf "%.2fMB\n",'$((`ls -l $downloadbin | awk '{print $5}'`))'/1000000}')"
128 | if [[ ${upxflag} != off ]]; then
129 | UPX_Compress
130 | echo -e "使用 UPX 压缩可能会花很长时间, 期间请耐心等待!\n正在压缩 $downloadbin ..."
131 | /tmp/upx-${upx_latest_ver}-${Arch_upx}_linux/upx $upxflag $downloadbin > /dev/null 2>&1
132 | echo -e "\n压缩后的核心体积: $(awk 'BEGIN{printf "%.2fMB\n",'$((`ls -l $downloadbin | awk '{print $5}'`))'/1000000}')"
133 | else
134 | echo "未启用 UPX 压缩, 跳过操作..."
135 | fi
136 | /etc/init.d/AdGuardHome stop > /dev/null 2>&1
137 | echo -e "\n移动 AdGuardHome 核心文件到 ${binpath%/*} ..."
138 | rm -rf ${binpath}
139 | mv -f ${downloadbin} ${binpath} > /dev/null 2>&1
140 | if [[ ! -s ${binpath} && $? != 0 ]]; then
141 | echo -e "AdGuardHome 核心移动失败!\n可能是设备空间不足导致, 请尝试开启 UPX 压缩, 或更改 [执行文件路径] 为 /tmp/AdGuardHome"
142 | EXIT 1
143 | fi
144 | rm -f /tmp/upx*.tar.xz
145 | rm -rf /tmp/upx*
146 | rm -rf /tmp/AdGuardHome_Update
147 | chmod +x ${binpath}
148 | if [[ ${enabled} == 1 ]]; then
149 | echo -e "\n正在重启 AdGuardHome 服务..."
150 | /etc/init.d/AdGuardHome restart
151 | fi
152 | echo -e "\nAdGuardHome 核心更新成功!"
153 | }
154 |
155 | GET_Arch() {
156 | Archt="$(opkg info kernel | grep Architecture | awk -F "[ _]" '{print($2)}')"
157 | case "${Archt}" in
158 | "i386")
159 | Arch="386"
160 | ;;
161 | "i686")
162 | Arch="386"
163 | ;;
164 | "x86")
165 | Arch="amd64"
166 | ;;
167 | "mipsel")
168 | Arch="mipsle"
169 | ;;
170 | "mips64el")
171 | Arch="mips64le"
172 | Arch="mipsle"
173 | echo -e "mips64el use $Arch may have bug"
174 | ;;
175 | "mips")
176 | Arch="mips"
177 | ;;
178 | "mips64")
179 | Arch="mips64"
180 | Arch="mips"
181 | echo -e "mips64 use $Arch may have bug"
182 | ;;
183 | "arm")
184 | Arch="arm"
185 | ;;
186 | "aarch64")
187 | Arch="arm64"
188 | ;;
189 | "powerpc")
190 | Arch="ppc"
191 | echo -e "error not support $Archt"
192 | EXIT 1
193 | ;;
194 | "powerpc64")
195 | Arch="ppc64"
196 | echo -e "error not support $Archt"
197 | EXIT 1
198 | ;;
199 |
200 | *)
201 | echo -e "error not support $Archt if you can use offical release please issue a bug"
202 | EXIT 1
203 | ;;
204 | esac
205 | echo "$Arch"
206 | }
207 |
208 | EXIT(){
209 | rm -rf /var/run/update_core $LOCKU 2>/dev/null
210 | [[ $1 != 0 ]] && touch /var/run/update_core_error
211 | exit $1
212 | }
213 |
214 | main(){
215 | Check_Task ${update_mode}
216 | Check_Updates ${update_mode}
217 | }
218 |
219 | trap "EXIT 1" SIGTERM SIGINT
220 | touch /var/run/update_core
221 | rm - rf /var/run/update_core_error 2>/dev/null
222 |
223 | main
224 |
--------------------------------------------------------------------------------
/luci-app-adguardhome/luasrc/model/cbi/AdGuardHome/base.lua:
--------------------------------------------------------------------------------
1 | require("luci.sys")
2 | require("luci.util")
3 | require("io")
4 | local m,s,o,o1
5 | local fs=require"nixio.fs"
6 | local uci=require"luci.model.uci".cursor()
7 | local configpath=uci:get("AdGuardHome","AdGuardHome","configpath") or "/etc/AdGuardHome.yaml"
8 | local binpath=uci:get("AdGuardHome","AdGuardHome","binpath") or "/usr/bin/AdGuardHome"
9 | httpport=uci:get("AdGuardHome","AdGuardHome","httpport") or "3000"
10 | m = Map("AdGuardHome", "AdGuard Home")
11 | m.description = translate("Free and open source, powerful network-wide ads & trackers blocking DNS server.")
12 | m:section(SimpleSection).template = "AdGuardHome/AdGuardHome_status"
13 |
14 | s = m:section(TypedSection, "AdGuardHome")
15 | s.anonymous=true
16 | s.addremove=false
17 |
18 | ---- Basic Settings ----
19 | s:tab("basic", translate("Main Config"))
20 |
21 | o = s:taboption("basic", Flag, "enabled", translate("Enable"))
22 | o.default = 0
23 | o.optional = false
24 |
25 | o = s:taboption("basic", Value,"httpport",translate("Browser management port"))
26 | o.placeholder=3000
27 | o.default=3000
28 | o.datatype="port"
29 | o.optional = false
30 |
31 | local binmtime=uci:get("AdGuardHome","AdGuardHome","binmtime") or "0"
32 |
33 | local e=""
34 | if not fs.access(configpath) then e = e .. " " .. translate("no config") end
35 | if not fs.access(binpath) then
36 | e=e.." "..translate("no core")
37 | else
38 | local version=uci:get("AdGuardHome","AdGuardHome","version")
39 | local testtime=fs.stat(binpath,"mtime")
40 | if testtime~=tonumber(binmtime) or version==nil then
41 |
42 | version = luci.sys.exec(string.format("echo -n $(%s --version 2>&1 | awk -F 'version ' '{print $2}' | awk -F ',' '{print $1}')", binpath))
43 | if version == "" then version = "core error" end
44 | uci:set("AdGuardHome", "AdGuardHome", "version", version)
45 | uci:set("AdGuardHome", "AdGuardHome", "binmtime", testtime)
46 | uci:commit("AdGuardHome")
47 | end
48 | e=version..e
49 | end
50 |
51 | o = s:taboption("basic", ListValue, "core_version", translate("Core Version"))
52 | o:value("latest", translate("Latest Version"))
53 | o:value("beta", translate("Beta Version"))
54 | o.default = "latest"
55 | o = s:taboption("basic", Button, "restart", translate("Upgrade Core"))
56 | o.inputtitle=translate("Update core version")
57 | o.template = "AdGuardHome/AdGuardHome_check"
58 | o.showfastconfig=(not fs.access(configpath))
59 | o.description = string.format(translate("Current core version:") .. "%s ", e)
60 |
61 | local port=luci.sys.exec("grep -A 5 '^dns:' "..configpath.." | grep 'port:' | awk '{print $2}' 2>nul")
62 | if (port=="") then port="?" end
63 |
64 | o = s:taboption("basic", ListValue, "redirect", port..translate("Redirect"), translate("AdGuardHome redirect mode"))
65 | o:value("none", translate("none"))
66 | o:value("dnsmasq-upstream", translate("Run as dnsmasq upstream server"))
67 | o:value("redirect", translate("Redirect 53 port to AdGuardHome"))
68 | o:value("exchange", translate("Use port 53 replace dnsmasq"))
69 | o.default = "none"
70 | o.optional = true
71 | ---- chpass
72 | o = s:taboption("basic",Value, "hashpass", translate("Change management password"), translate("Press load culculate model and culculate finally save/apply"))
73 | o.default = ""
74 | o.datatype = "string"
75 | o.template = "AdGuardHome/AdGuardHome_chpass"
76 | o.optional = true
77 |
78 | -- wait net on boot
79 | o = s:taboption("basic", Flag, "waitonboot", translate("Start up only when the network is normal"))
80 | o.default = 1
81 | o.optional = false
82 |
83 | ---- Core Settings ----
84 | s:tab("core", translate("Core Config"))
85 |
86 | o = s:taboption("core",Value, "binpath", translate("Bin Path"), translate("AdGuardHome Bin path if no bin will auto download"))
87 | o.default = "/usr/bin/AdGuardHome"
88 | o.datatype = "string"
89 | o.optional = false
90 | o.rmempty=false
91 | o.validate=function(self, value)
92 | if value=="" then return nil end
93 | if fs.stat(value,"type")=="dir" then
94 | fs.rmdir(value)
95 | end
96 | if fs.stat(value,"type")=="dir" then
97 | if (m.message) then
98 | m.message =m.message.."\nerror!bin path is a dir"
99 | else
100 | m.message ="error!bin path is a dir"
101 | end
102 | return nil
103 | end
104 | return value
105 | end
106 | --- upx
107 | o = s:taboption("core",ListValue, "upxflag", translate("use upx to compress bin after download"))
108 | o:value("", translate("none"))
109 | o:value("-1", translate("compress faster"))
110 | o:value("-9", translate("compress better"))
111 | o:value("--best", translate("compress best(can be slow for big files)"))
112 | o:value("--brute", translate("try all available compression methods & filters [slow]"))
113 | o:value("--ultra-brute", translate("try even more compression variants [very slow]"))
114 | o.default = ""
115 | o.description=translate("bin use less space,but may have compatibility issues")
116 | o.rmempty = true
117 | ---- config path
118 | o = s:taboption("core",Value, "configpath", translate("Config Path"), translate("AdGuardHome config path"))
119 | o.default = "/etc/AdGuardHome.yaml"
120 | o.datatype = "string"
121 | o.optional = false
122 | o.rmempty=false
123 | o.validate=function(self, value)
124 | if value==nil then return nil end
125 | if fs.stat(value,"type")=="dir" then
126 | fs.rmdir(value)
127 | end
128 | if fs.stat(value,"type")=="dir" then
129 | if m.message then
130 | m.message =m.message.."\nerror!config path is a dir"
131 | else
132 | m.message ="error!config path is a dir"
133 | end
134 | return nil
135 | end
136 | return value
137 | end
138 | ---- work dir
139 | o = s:taboption("core",Value, "workdir", translate("Work dir"), translate("AdGuardHome work dir include rules,audit log and database"))
140 | o.default = "/etc/AdGuardHome"
141 | o.datatype = "string"
142 | o.optional = false
143 | o.rmempty=false
144 | o.validate=function(self, value)
145 | if value=="" then return nil end
146 | if fs.stat(value,"type")=="reg" then
147 | if m.message then
148 | m.message =m.message.."\nerror!work dir is a file"
149 | else
150 | m.message ="error!work dir is a file"
151 | end
152 | return nil
153 | end
154 | if string.sub(value, -1)=="/" then
155 | return string.sub(value, 1, -2)
156 | else
157 | return value
158 | end
159 | end
160 | ---- log file
161 | o = s:taboption("core",Value, "logfile", translate("Runtime log file"), translate("AdGuardHome runtime Log file if 'syslog': write to system log;if empty no log"))
162 | o.datatype = "string"
163 | o.rmempty = true
164 | o.validate=function(self, value)
165 | if fs.stat(value,"type")=="dir" then
166 | fs.rmdir(value)
167 | end
168 | if fs.stat(value,"type")=="dir" then
169 | if m.message then
170 | m.message =m.message.."\nerror!log file is a dir"
171 | else
172 | m.message ="error!log file is a dir"
173 | end
174 | return nil
175 | end
176 | return value
177 | end
178 | ---- debug
179 | o = s:taboption("core",Flag, "verbose", translate("Verbose log"))
180 | o.default = 0
181 | o.optional = true
182 | ---- gfwlist
183 | local a=luci.sys.call("grep -m 1 -q programadd "..configpath)
184 | if (a==0) then
185 | a="Added"
186 | else
187 | a="Not added"
188 | end
189 |
190 | ---- Backup Settings ----
191 | s:tab("other", translate("Other Config"))
192 |
193 | ---- upgrade protect
194 | o = s:taboption("other", DynamicList, "upprotect", translate("Keep files when system upgrade"))
195 | o:value("$binpath",translate("core bin"))
196 | o:value("$configpath",translate("config file"))
197 | o:value("$logfile",translate("log file"))
198 | o:value("$workdir/data/sessions.db",translate("sessions.db"))
199 | o:value("$workdir/data/stats.db",translate("stats.db"))
200 | o:value("$workdir/data/querylog.json",translate("querylog.json"))
201 | o:value("$workdir/data/filters",translate("filters"))
202 | o.widget = "checkbox"
203 | o.default = nil
204 | o.optional=true
205 |
206 | ---- backup workdir on shutdown
207 | local workdir=uci:get("AdGuardHome","AdGuardHome","workdir") or "/etc/AdGuardHome"
208 | o = s:taboption("other",MultiValue, "backupfile", translate("Backup workdir files when shutdown"))
209 | o1 = s:taboption("other",Value, "backupwdpath", translate("Backup workdir path"))
210 | local name
211 | o:value("filters","filters")
212 | o:value("stats.db","stats.db")
213 | o:value("querylog.json","querylog.json")
214 | o:value("sessions.db","sessions.db")
215 | o1:depends ("backupfile", "filters")
216 | o1:depends ("backupfile", "stats.db")
217 | o1:depends ("backupfile", "querylog.json")
218 | o1:depends ("backupfile", "sessions.db")
219 | for name in fs.glob(workdir.."/data/*")
220 | do
221 | name=fs.basename (name)
222 | if name~="filters" and name~="stats.db" and name~="querylog.json" and name~="sessions.db" then
223 | o:value(name,name)
224 | o1:depends ("backupfile", name)
225 | end
226 | end
227 | o.widget = "checkbox"
228 | o.default = nil
229 | o.optional=false
230 | o.description=translate("Will be restore when workdir/data is empty")
231 | ----backup workdir path
232 |
233 | o1.default = "/etc/AdGuardHome"
234 | o1.datatype = "string"
235 | o1.optional = false
236 | o1.validate=function(self, value)
237 | if fs.stat(value,"type")=="reg" then
238 | if m.message then
239 | m.message =m.message.."\nerror!backup dir is a file"
240 | else
241 | m.message ="error!backup dir is a file"
242 | end
243 | return nil
244 | end
245 | if string.sub(value,-1)=="/" then
246 | return string.sub(value, 1, -2)
247 | else
248 | return value
249 | end
250 | end
251 |
252 | ---- Crontab Settings ----
253 |
254 | o = s:taboption("other",MultiValue, "crontab", translate("Crontab task"),translate("Please change time and args in crontab"))
255 | o:value("autohost",translate("Auto update ipv6 hosts and restart AdGuardHome"))
256 | o:value("autogfw",translate("Auto update gfwlist and restart AdGuardHome"))
257 | o:value("autogfwipset",translate("Auto update ipset list and restart AdGuardHome"))
258 | o.widget = "checkbox"
259 | o.default = nil
260 | o.optional = false
261 |
262 | ---- GFWList Settings ----
263 | local a
264 | if fs.access(configpath) then
265 | a=luci.sys.call("grep -m 1 -q programadd "..configpath)
266 | else
267 | a=1
268 | end
269 | if (a==0) then
270 | a="Added"
271 | else
272 | a="Not added"
273 | end
274 |
275 | o=s:taboption("other", Button,"gfwdel",translate("Del gfwlist"),translate(a))
276 | o.optional = false
277 | o.inputtitle=translate("Del")
278 | o.write=function()
279 | luci.sys.exec("sh /usr/share/AdGuardHome/gfw2adg.sh del 2>&1")
280 | luci.http.redirect(luci.dispatcher.build_url("admin","services","AdGuardHome"))
281 | end
282 | o=s:taboption("other", Button,"gfwadd",translate("Add gfwlist"),translate(a))
283 | o.optional = false
284 | o.inputtitle=translate("Add")
285 | o.write=function()
286 | luci.sys.exec("sh /usr/share/AdGuardHome/gfw2adg.sh 2>&1")
287 | luci.http.redirect(luci.dispatcher.build_url("admin","services","AdGuardHome"))
288 | end
289 | if fs.access(configpath) then
290 | a=luci.sys.call("grep -m 1 -q ipset.txt "..configpath)
291 | else
292 | a=1
293 | end
294 | if (a==0) then
295 | a="Added"
296 | else
297 | a="Not added"
298 | end
299 | o=s:taboption("other", Button,"gfwipsetdel",translate("Del gfwlist").." "..translate("(ipset only)"),translate(a))
300 | o.optional = false
301 | o.inputtitle=translate("Del")
302 | o.write=function()
303 | luci.sys.exec("sh /usr/share/AdGuardHome/gfwipset2adg.sh del 2>&1")
304 | luci.http.redirect(luci.dispatcher.build_url("admin","services","AdGuardHome"))
305 | end
306 | o=s:taboption("other", Button," ",translate("Add gfwlist").." "..translate("(ipset only)"),translate(a).." "..translate("will set to name gfwlist"))
307 | o.optional = false
308 | o.inputtitle=translate("Add")
309 | o.write=function()
310 | luci.sys.exec("sh /usr/share/AdGuardHome/gfwipset2adg.sh 2>&1")
311 | luci.http.redirect(luci.dispatcher.build_url("admin","services","AdGuardHome"))
312 | end
313 | o = s:taboption("other", Value, "gfwupstream", translate("Gfwlist upstream dns server"), translate("Gfwlist domain upstream dns service")..translate(a))
314 | o.default = "tcp://208.67.220.220:5353"
315 | o.datatype = "string"
316 | o.optional = false
317 |
318 | fs.writefile("/var/run/AdG_log_pos","0")
319 |
320 | function m.on_commit(map)
321 | if (fs.access("/var/run/AdGserverdis")) then
322 | io.popen("/etc/init.d/AdGuardHome reload &")
323 | return
324 | end
325 | local ucitracktest=uci:get("AdGuardHome","AdGuardHome","ucitracktest")
326 | if ucitracktest=="1" then
327 | return
328 | elseif ucitracktest=="0" then
329 | io.popen("/etc/init.d/AdGuardHome reload &")
330 | else
331 | if (fs.access("/var/run/AdGlucitest")) then
332 | uci:set("AdGuardHome","AdGuardHome","ucitracktest","0")
333 | io.popen("/etc/init.d/AdGuardHome reload &")
334 | else
335 | fs.writefile("/var/run/AdGlucitest","")
336 | if (ucitracktest=="2") then
337 | uci:set("AdGuardHome","AdGuardHome","ucitracktest","1")
338 | else
339 | uci:set("AdGuardHome","AdGuardHome","ucitracktest","2")
340 | end
341 | end
342 | uci:commit("AdGuardHome")
343 | end
344 | end
345 | return m
346 |
--------------------------------------------------------------------------------
/luci-app-adguardhome/root/www/luci-static/resources/twin-bcrypt.min.js:
--------------------------------------------------------------------------------
1 | /* @license
2 | * Twin-Bcrypt 2.2.0
3 | * https://github.com/fpirsch/twin-bcrypt
4 | * Licence: BSD-3-Clause
5 | */
6 | !function(r,n){"use strict";function e(r){return y[g]=t.apply(n,r),g++}function t(r){var e=[].slice.call(arguments,1);return function(){"function"==typeof r?r.apply(n,e):new Function(""+r)()}}function o(r){if(m)setTimeout(t(o,r),0);else{var n=y[r];if(n){m=!0;try{n()}finally{a(r),m=!1}}}}function a(r){delete y[r]}function i(){p=function(){var r=e(arguments);return process.nextTick(t(o,r)),r}}function u(){if(r.postMessage&&!r.importScripts){var n=!0,e=r.onmessage;return r.onmessage=function(){n=!1},r.postMessage("","*"),r.onmessage=e,n}}function f(){var n="setImmediate$"+Math.random()+"$",t=function(e){e.source===r&&"string"==typeof e.data&&0===e.data.indexOf(n)&&o(+e.data.slice(n.length))};r.addEventListener?r.addEventListener("message",t,!1):r.attachEvent("onmessage",t),p=function(){var t=e(arguments);return r.postMessage(n+t,"*"),t}}function c(){var r=new MessageChannel;r.port1.onmessage=function(r){var n=r.data;o(n)},p=function(){var n=e(arguments);return r.port2.postMessage(n),n}}function s(){var r=v.documentElement;p=function(){var n=e(arguments),t=v.createElement("script");return t.onreadystatechange=function(){o(n),t.onreadystatechange=null,r.removeChild(t),t=null},r.appendChild(t),n}}function l(){p=function(){var r=e(arguments);return setTimeout(t(o,r),0),r}}if(!r.setImmediate){var p,g=1,y={},m=!1,v=r.document,d=Object.getPrototypeOf&&Object.getPrototypeOf(r);d=d&&d.setTimeout?d:r,"[object process]"==={}.toString.call(r.process)?i():u()?f():r.MessageChannel?c():v&&"onreadystatechange"in v.createElement("script")?s():l(),d.setImmediate=p,d.clearImmediate=a}}(new Function("return this")()),function(r){"object"==typeof exports?r(exports,require("crypto")):r(self.TwinBcrypt={},self.crypto||self.msCrypto)}(function(r,n){"use strict";function e(r){for(var n=unescape(encodeURIComponent(r)),e=n.length,t=new Array(e),o=0;e>o;o++)t[o]=n.charCodeAt(o);return t}function t(r){for(var n=r.length,e=new Array(n),t=0;n>t;t++)e[t]=r.charCodeAt(t);return e}function o(r,n){for(var e,t,o=0,a="";n>o;){if(e=255&r[o++],a+=B[e>>2],e=(3&e)<<4,o>=n){a+=B[e];break}if(t=255&r[o++],e|=t>>4,a+=B[e],e=(15&t)<<2,o>=n){a+=B[e];break}t=255&r[o++],e|=t>>6,a+=B[e],a+=B[63&t]}return a}function a(r){for(var n,e,t=new Array(16),o=0,a=0;;){if(n=D[r.charCodeAt(o++)-46],e=D[r.charCodeAt(o++)-46],t[a++]=255&(n<<2|e>>4),22===o)break;n=e<<4,e=D[r.charCodeAt(o++)-46],t[a++]=255&(n|e>>2),n=e<<6,e=D[r.charCodeAt(o++)-46],t[a++]=255&(n|e)}return t}function i(r){for(var n=r.length,e=new Array(72),t=0,o=0;72>o;)e[o++]=r[t++],t===n&&(t=0);return e}function u(r,n,e){for(var t=0,o=e>>2;tt;)r[n++]=e[t++]<<24|e[t++]<<16|e[t++]<<8|e[t++]}function c(r){function n(n){for(var e=r,t=G>>2,o=t|O,f=n>>2,c=e[f]^e[t],s=e[1|f];o>t;)s^=(e[c>>>24]+e[a|c>>>16&255]^e[i|c>>>8&255])+e[u|255&c]^e[++t],c^=(e[s>>>24]+e[a|s>>>16&255]^e[i|s>>>8&255])+e[u|255&s]^e[++t];e[f]=s^e[S>>2],e[1|f]=c}function e(n){var e;for(r[L>>2]=0,r[L+4>>2]=0,e=0;M>e;e++)r[G>>2|e]^=r[(n>>2)+e];var t,o,f,c,s,l=r;for(e=0;M>e;e+=2){for(t=G>>2,o=t|O,f=L>>2,c=l[f]^l[t],s=l[1|f];o>t;)s^=(l[c>>>24]+l[a|c>>>16&255]^l[i|c>>>8&255])+l[u|255&c]^l[++t],c^=(l[s>>>24]+l[a|s>>>16&255]^l[i|s>>>8&255])+l[u|255&s]^l[++t];l[f]=s^l[S>>2],l[1|f]=c,r[G>>2|e]=l[f],r[G>>2|e+1]=c}for(e=0;T>e;e+=2){for(t=G>>2,o=t|O,f=L>>2,c=l[f]^l[t],s=l[1|f];o>t;)s^=(l[c>>>24]+l[a|c>>>16&255]^l[i|c>>>8&255])+l[u|255&c]^l[++t],c^=(l[s>>>24]+l[a|s>>>16&255]^l[i|s>>>8&255])+l[u|255&s]^l[++t];l[f]=s^l[S>>2],l[1|f]=c,r[e]=l[f],r[1|e]=c}}function t(r,n,t){for(var o=0;t>=o&&!(r>n);o++)e(R),e(j),r++;return r}var o=k>>2,a=o+256|0,i=a+256|0,u=i+256|0;return{encrypt:n,expandLoop:t}}function s(stdlib, foreign, heap) {"use asm";var HEAP32=new stdlib.Uint32Array(heap);var BLOWFISH_NUM_ROUNDS=16;var S_offset=0x0000;var S1_offset=0x0400;var S2_offset=0x0800;var S3_offset=0x0C00;var P_offset=0x1000;var P_last_offset=0x1044;var crypt_ciphertext_offset=0x1048;var LR_offset=0x01060;var password_offset=0x1068;var salt_offset=0x10b0;var P_LEN=18;var S_LEN=1024;function encrypt(offset) {offset=offset|0;var i=0;var n=0;var L=0;var R=0;var imax=0;imax=P_offset|BLOWFISH_NUM_ROUNDS<<2;L=HEAP32[offset>>2]|0;R=HEAP32[offset+4>>2]|0;L=L^HEAP32[P_offset>>2];for (i=P_offset; (i|0)<(imax|0);) {i=(i+4)>>>0;R=R^(((HEAP32[(L>>>22)>>2]>>>0) +(HEAP32[(S1_offset|(L>>>14&0x3ff))>>2]>>>0) ^(HEAP32[(S2_offset|(L>>>6&0x3ff))>>2])) +(HEAP32[(S3_offset|(L<<2&0x3ff))>>2]>>>0))^HEAP32[i>>2];i=(i+4)>>>0;L=L^(((HEAP32[(R>>>22)>>2]>>>0) +(HEAP32[(S1_offset|(R>>>14&0x3ff))>>2]>>>0) ^(HEAP32[(S2_offset|(R>>>6&0x3ff))>>2])) +(HEAP32[(S3_offset|(R<<2&0x3ff))>>2]>>>0))^HEAP32[i>>2];}HEAP32[offset>>2]=R^HEAP32[P_last_offset>>2];HEAP32[(offset+4)>>2]=L;}function expandKey(offset) {offset=offset|0;var i=0;var off=0;off=P_offset|0;for (i=0; (i|0)<(P_LEN|0); i=(i+1)|0) {HEAP32[off>>2]=HEAP32[off>>2]^HEAP32[offset>>2];offset=(offset+4)|0;off=(off+4)|0;}HEAP32[LR_offset>>2]=0;HEAP32[LR_offset+4>>2]=0;off=P_offset;for (i=0; (i|0)<(P_LEN|0); i=(i+2)|0) {encrypt(LR_offset);HEAP32[off>>2]=HEAP32[LR_offset>>2];HEAP32[off+4>>2]=HEAP32[LR_offset+4>>2];off=(off+8)|0;}off=S_offset;for (i=0; (i|0)<(S_LEN|0); i=(i+2)|0) {encrypt(LR_offset);HEAP32[off>>2]=HEAP32[LR_offset>>2];HEAP32[off+4>>2]=HEAP32[LR_offset+4>>2];off=(off+8)|0;}}function expandLoop(i, counterEnd, maxIterations) {i=i|0;counterEnd=counterEnd|0;maxIterations=maxIterations|0;var j=0;for (j=0; (j|0) <= (maxIterations|0); j=(j+1)|0) {if ((i>>>0)>(counterEnd>>>0)) break;expandKey(password_offset);expandKey(salt_offset);i=(i+1)>>>0;}return i|0;}return {encrypt: encrypt,expandLoop: expandLoop};}
7 | function l(r,n,e,t){var o,a,i,u=L>>2,f=u+1;for(t[u]=0,t[f]=0,a=0,o=0;M>o;o++)i=n[a++]<<24|n[a++]<<16|n[a++]<<8|n[a++],t[G>>2|o]^=i;for(a=0,o=0;M>o;o+=2)i=r[a++]<<24|r[a++]<<16|r[a++]<<8|r[a++],a&=65295,t[u]^=i,i=r[a++]<<24|r[a++]<<16|r[a++]<<8|r[a++],a&=65295,t[f]^=i,e.encrypt(L),t[G>>2|o]=t[u],t[G>>2|o+1]=t[f];var c=k>>2;for(o=0;T>o;o+=2)i=r[a++]<<24|r[a++]<<16|r[a++]<<8|r[a++],a&=65295,t[u]^=i,i=r[a++]<<24|r[a++]<<16|r[a++]<<8|r[a++],a&=65295,t[f]^=i,e.encrypt(L),t[c|o]=t[u],t[c|o+1]=t[f]}function p(r,n,e,t,o,a,i){for(var u=e;t>=u;){if(u=r.expandLoop(u,t,o),a){var f=a(u/(t+1));if(f===!1)return}if(u>t){if(i)return void setImmediate(g.bind(null,r,n,i));return}if(i)return void setImmediate(p.bind(null,r,n,u,t,o,a,i))}}function g(r,n,e){u(n,x,F);var t;for(t=0;64>t;t++)r.encrypt(F+0),r.encrypt(F+8),r.encrypt(F+16);var o,a=0,i=x.length,f=new Array(4*i);for(t=0;i>t;t++)o=n[(F>>2)+t],f[a++]=o>>24,f[a++]=o>>16&255,f[a++]=o>>8&255,f[a++]=255&o;return e&&e(f),f}function y(r,n){return r+o(n,23)}function m(n,o,m,v){var d,h=o.substr(0,29),w=+o.substr(4,2),A=o.substr(7,22);if("string"==typeof n)d=r.encodingMode===r.ENCODING_UTF8?e(n):t(n);else if(Array.isArray(n))d=n.map(function(r){return 255&r});else{if(!(n instanceof Uint8Array))throw new Error("Incorrect arguments");d=Array.prototype.slice.call(n)}d.push(0);var b,E,N=a(A,C),O=31>w?1<>2,N),f(b,R>>2,d),l(N,d,E,b),v?void p(E,b,0,M,T,m,function(r){v(y(h,r))}):(p(E,b,0,M,T,m),y(h,g(E,b)))}function v(r){if(!b)throw new Error("No cryptographically secure pseudorandom number generator available.");if(null==r&&(r=N),r=0|+r,isNaN(r)||4>r||r>31)throw new Error("Invalid cost parameter.");var n="$2y$";return 10>r&&(n+="0"),n+=r+"$",n+=o(b(C),C)}function d(r,n,e){if(n&&"number"!=typeof n){if("string"!=typeof n||!z.test(n))throw new Error("Invalid salt")}else n=v(n);return m(r,n,e)}function h(r,n,e,t){if(arguments.length<2)throw new Error("Incorrect arguments");if(2===arguments.length?(t=n,n=e=null):3===arguments.length&&(t=e,e=null,"function"==typeof n&&(e=n,n=null)),n&&"number"!=typeof n){if("string"!=typeof n||!z.test(n))throw new Error("Invalid salt")}else n=v(n);if(!t||"function"!=typeof t)throw new Error("No callback function was given.");m(r,n,e,t)}function w(r,n){if("string"!=typeof n||!Z.test(n))throw new Error("Incorrect arguments");var e=n.substr(0,n.length-31),t=d(r,e);return t===n}function A(r,n,e,t){if("string"!=typeof n||!Z.test(n))throw new Error("Incorrect arguments");if(t||(t=e,e=null),!t||"function"!=typeof t)throw new Error("No callback function was given.");var o=n.substr(0,n.length-31);h(r,o,e,function(r){t(r===n)})}var b,E="undefined"!=typeof InstallTrigger,I=E;n&&(b=n.randomBytes,n.getRandomValues&&(b=function(r){var e=new Uint8Array(r);return n.getRandomValues(e)}));var C=16,N=10,O=16,$=[608135816,2242054355,320440878,57701188,2752067618,698298832,137296536,3964562569,1160258022,953160567,3193202383,887688300,3232508343,3380367581,1065670069,3041331479,2450970073,2306472731],U=[3509652390,2564797868,805139163,3491422135,3101798381,1780907670,3128725573,4046225305,614570311,3012652279,134345442,2240740374,1667834072,1901547113,2757295779,4103290238,227898511,1921955416,1904987480,2182433518,2069144605,3260701109,2620446009,720527379,3318853667,677414384,3393288472,3101374703,2390351024,1614419982,1822297739,2954791486,3608508353,3174124327,2024746970,1432378464,3864339955,2857741204,1464375394,1676153920,1439316330,715854006,3033291828,289532110,2706671279,2087905683,3018724369,1668267050,732546397,1947742710,3462151702,2609353502,2950085171,1814351708,2050118529,680887927,999245976,1800124847,3300911131,1713906067,1641548236,4213287313,1216130144,1575780402,4018429277,3917837745,3693486850,3949271944,596196993,3549867205,258830323,2213823033,772490370,2760122372,1774776394,2652871518,566650946,4142492826,1728879713,2882767088,1783734482,3629395816,2517608232,2874225571,1861159788,326777828,3124490320,2130389656,2716951837,967770486,1724537150,2185432712,2364442137,1164943284,2105845187,998989502,3765401048,2244026483,1075463327,1455516326,1322494562,910128902,469688178,1117454909,936433444,3490320968,3675253459,1240580251,122909385,2157517691,634681816,4142456567,3825094682,3061402683,2540495037,79693498,3249098678,1084186820,1583128258,426386531,1761308591,1047286709,322548459,995290223,1845252383,2603652396,3431023940,2942221577,3202600964,3727903485,1712269319,422464435,3234572375,1170764815,3523960633,3117677531,1434042557,442511882,3600875718,1076654713,1738483198,4213154764,2393238008,3677496056,1014306527,4251020053,793779912,2902807211,842905082,4246964064,1395751752,1040244610,2656851899,3396308128,445077038,3742853595,3577915638,679411651,2892444358,2354009459,1767581616,3150600392,3791627101,3102740896,284835224,4246832056,1258075500,768725851,2589189241,3069724005,3532540348,1274779536,3789419226,2764799539,1660621633,3471099624,4011903706,913787905,3497959166,737222580,2514213453,2928710040,3937242737,1804850592,3499020752,2949064160,2386320175,2390070455,2415321851,4061277028,2290661394,2416832540,1336762016,1754252060,3520065937,3014181293,791618072,3188594551,3933548030,2332172193,3852520463,3043980520,413987798,3465142937,3030929376,4245938359,2093235073,3534596313,375366246,2157278981,2479649556,555357303,3870105701,2008414854,3344188149,4221384143,3956125452,2067696032,3594591187,2921233993,2428461,544322398,577241275,1471733935,610547355,4027169054,1432588573,1507829418,2025931657,3646575487,545086370,48609733,2200306550,1653985193,298326376,1316178497,3007786442,2064951626,458293330,2589141269,3591329599,3164325604,727753846,2179363840,146436021,1461446943,4069977195,705550613,3059967265,3887724982,4281599278,3313849956,1404054877,2845806497,146425753,1854211946,1266315497,3048417604,3681880366,3289982499,290971e4,1235738493,2632868024,2414719590,3970600049,1771706367,1449415276,3266420449,422970021,1963543593,2690192192,3826793022,1062508698,1531092325,1804592342,2583117782,2714934279,4024971509,1294809318,4028980673,1289560198,2221992742,1669523910,35572830,157838143,1052438473,1016535060,1802137761,1753167236,1386275462,3080475397,2857371447,1040679964,2145300060,2390574316,1461121720,2956646967,4031777805,4028374788,33600511,2920084762,1018524850,629373528,3691585981,3515945977,2091462646,2486323059,586499841,988145025,935516892,3367335476,2599673255,2839830854,265290510,3972581182,2759138881,3795373465,1005194799,847297441,406762289,1314163512,1332590856,1866599683,4127851711,750260880,613907577,1450815602,3165620655,3734664991,3650291728,3012275730,3704569646,1427272223,778793252,1343938022,2676280711,2052605720,1946737175,3164576444,3914038668,3967478842,3682934266,1661551462,3294938066,4011595847,840292616,3712170807,616741398,312560963,711312465,1351876610,322626781,1910503582,271666773,2175563734,1594956187,70604529,3617834859,1007753275,1495573769,4069517037,2549218298,2663038764,504708206,2263041392,3941167025,2249088522,1514023603,1998579484,1312622330,694541497,2582060303,2151582166,1382467621,776784248,2618340202,3323268794,2497899128,2784771155,503983604,4076293799,907881277,423175695,432175456,1378068232,4145222326,3954048622,3938656102,3820766613,2793130115,2977904593,26017576,3274890735,3194772133,1700274565,1756076034,4006520079,3677328699,720338349,1533947780,354530856,688349552,3973924725,1637815568,332179504,3949051286,53804574,2852348879,3044236432,1282449977,3583942155,3416972820,4006381244,1617046695,2628476075,3002303598,1686838959,431878346,2686675385,1700445008,1080580658,1009431731,832498133,3223435511,2605976345,2271191193,2516031870,1648197032,4164389018,2548247927,300782431,375919233,238389289,3353747414,2531188641,2019080857,1475708069,455242339,2609103871,448939670,3451063019,1395535956,2413381860,1841049896,1491858159,885456874,4264095073,4001119347,1565136089,3898914787,1108368660,540939232,1173283510,2745871338,3681308437,4207628240,3343053890,4016749493,1699691293,1103962373,3625875870,2256883143,3830138730,1031889488,3479347698,1535977030,4236805024,3251091107,2132092099,1774941330,1199868427,1452454533,157007616,2904115357,342012276,595725824,1480756522,206960106,497939518,591360097,863170706,2375253569,3596610801,1814182875,2094937945,3421402208,1082520231,3463918190,2785509508,435703966,3908032597,1641649973,2842273706,3305899714,1510255612,2148256476,2655287854,3276092548,4258621189,236887753,3681803219,274041037,1734335097,3815195456,3317970021,1899903192,1026095262,4050517792,356393447,2410691914,3873677099,3682840055,3913112168,2491498743,4132185628,2489919796,1091903735,1979897079,3170134830,3567386728,3557303409,857797738,1136121015,1342202287,507115054,2535736646,337727348,3213592640,1301675037,2528481711,1895095763,1721773893,3216771564,62756741,2142006736,835421444,2531993523,1442658625,3659876326,2882144922,676362277,1392781812,170690266,3921047035,1759253602,3611846912,1745797284,664899054,1329594018,3901205900,3045908486,2062866102,2865634940,3543621612,3464012697,1080764994,553557557,3656615353,3996768171,991055499,499776247,1265440854,648242737,3940784050,980351604,3713745714,1749149687,3396870395,4211799374,3640570775,1161844396,3125318951,1431517754,545492359,4268468663,3499529547,1437099964,2702547544,3433638243,2581715763,2787789398,1060185593,1593081372,2418618748,4260947970,69676912,2159744348,86519011,2512459080,3838209314,1220612927,3339683548,133810670,1090789135,1078426020,1569222167,845107691,3583754449,4072456591,1091646820,628848692,1613405280,3757631651,526609435,236106946,48312990,2942717905,3402727701,1797494240,859738849,992217954,4005476642,2243076622,3870952857,3732016268,765654824,3490871365,2511836413,1685915746,3888969200,1414112111,2273134842,3281911079,4080962846,172450625,2569994100,980381355,4109958455,2819808352,2716589560,2568741196,3681446669,3329971472,1835478071,660984891,3704678404,4045999559,3422617507,3040415634,1762651403,1719377915,3470491036,2693910283,3642056355,3138596744,1364962596,2073328063,1983633131,926494387,3423689081,2150032023,4096667949,1749200295,3328846651,309677260,2016342300,1779581495,3079819751,111262694,1274766160,443224088,298511866,1025883608,3806446537,1145181785,168956806,3641502830,3584813610,1689216846,3666258015,3200248200,1692713982,2646376535,4042768518,1618508792,1610833997,3523052358,4130873264,2001055236,3610705100,2202168115,4028541809,2961195399,1006657119,2006996926,3186142756,1430667929,3210227297,1314452623,4074634658,4101304120,2273951170,1399257539,3367210612,3027628629,1190975929,2062231137,2333990788,2221543033,2438960610,1181637006,548689776,2362791313,3372408396,3104550113,3145860560,296247880,1970579870,3078560182,3769228297,1714227617,3291629107,3898220290,166772364,1251581989,493813264,448347421,195405023,2709975567,677966185,3703036547,1463355134,2715995803,1338867538,1343315457,2802222074,2684532164,233230375,2599980071,2000651841,3277868038,1638401717,4028070440,3237316320,6314154,819756386,300326615,590932579,1405279636,3267499572,3150704214,2428286686,3959192993,3461946742,1862657033,1266418056,963775037,2089974820,2263052895,1917689273,448879540,3550394620,3981727096,150775221,3627908307,1303187396,508620638,2975983352,2726630617,1817252668,1876281319,1457606340,908771278,3720792119,3617206836,2455994898,1729034894,1080033504,976866871,3556439503,2881648439,1522871579,1555064734,1336096578,3548522304,2579274686,3574697629,3205460757,3593280638,3338716283,3079412587,564236357,2993598910,1781952180,1464380207,3163844217,3332601554,1699332808,1393555694,1183702653,3581086237,1288719814,691649499,2847557200,2895455976,3193889540,2717570544,1781354906,1676643554,2592534050,3230253752,1126444790,2770207658,2633158820,2210423226,2615765581,2414155088,3127139286,673620729,2805611233,1269405062,4015350505,3341807571,4149409754,1057255273,2012875353,2162469141,2276492801,2601117357,993977747,3918593370,2654263191,753973209,36408145,2530585658,25011837,3520020182,2088578344,530523599,2918365339,1524020338,1518925132,3760827505,3759777254,1202760957,3985898139,3906192525,674977740,4174734889,2031300136,2019492241,3983892565,4153806404,3822280332,352677332,2297720250,60907813,90501309,3286998549,1016092578,2535922412,2839152426,457141659,509813237,4120667899,652014361,1966332200,2975202805,55981186,2327461051,676427537,3255491064,2882294119,3433927263,1307055953,942726286,933058658,2468411793,3933900994,4215176142,1361170020,2001714738,2830558078,3274259782,1222529897,1679025792,2729314320,3714953764,1770335741,151462246,3013232138,1682292957,1483529935,471910574,1539241949,458788160,3436315007,1807016891,3718408830,978976581,1043663428,3165965781,1927990952,4200891579,2372276910,3208408903,3533431907,1412390302,2931980059,4132332400,1947078029,3881505623,4168226417,2941484381,1077988104,1320477388,886195818,18198404,3786409e3,2509781533,112762804,3463356488,1866414978,891333506,18488651,661792760,1628790961,3885187036,3141171499,876946877,2693282273,1372485963,791857591,2686433993,3759982718,3167212022,3472953795,2716379847,445679433,3561995674,3504004811,3574258232,54117162,3331405415,2381918588,3769707343,4154350007,1140177722,4074052095,668550556,3214352940,367459370,261225585,2610173221,4209349473,3468074219,3265815641,314222801,3066103646,3808782860,282218597,3406013506,3773591054,379116347,1285071038,846784868,2669647154,3771962079,3550491691,2305946142,453669953,1268987020,3317592352,3279303384,3744833421,2610507566,3859509063,266596637,3847019092,517658769,3462560207,3443424879,370717030,4247526661,2224018117,4143653529,4112773975,2788324899,2477274417,1456262402,2901442914,1517677493,1846949527,2295493580,3734397586,2176403920,1280348187,1908823572,3871786941,846861322,1172426758,3287448474,3383383037,1655181056,3139813346,901632758,1897031941,2986607138,3066810236,3447102507,1393639104,373351379,950779232,625454576,3124240540,4148612726,2007998917,544563296,2244738638,2330496472,2058025392,1291430526,424198748,50039436,29584100,3605783033,2429876329,2791104160,1057563949,3255363231,3075367218,3463963227,1469046755,985887462],M=$.length,T=U.length,x=[1332899944,1700884034,1701343084,1684370003,1668446532,1869963892],k=0,G=4096,S=4164,F=4168,L=4192,R=4200,j=4272,B="./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",D=[0,1,54,55,56,57,58,59,60,61,62,63,-1,-1,-1,-1,-1,-1,-1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,-1,-1,-1,-1,-1,-1,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,-1,-1,-1,-1,-1],z=/^\$2[ay]\$(0[4-9]|[12][0-9]|3[01])\$[.\/A-Za-z0-9]{21}[.Oeu]/,Z=/^\$2[ay]\$(0[4-9]|[12][0-9]|3[01])\$[.\/A-Za-z0-9]{21}[.Oeu][.\/A-Za-z0-9]{30}[.CGKOSWaeimquy26]$/;r.genSalt=v,r.hashSync=d,r.hash=h,r.compareSync=w,r.compare=A,r.ENCODING_UTF8=0,r.ENCODING_RAW=1,r.encodingMode=r.ENCODING_UTF8,r.cryptoRNG=!!b,r.randomBytes=b,r.defaultCost=N,r.version="2.2.0"});
--------------------------------------------------------------------------------
/luci-app-adguardhome/root/etc/init.d/AdGuardHome:
--------------------------------------------------------------------------------
1 | #!/bin/sh /etc/rc.common
2 |
3 | USE_PROCD=1
4 |
5 | START=95
6 | STOP=01
7 |
8 | CONFIGURATION=AdGuardHome
9 | CRON_FILE=/etc/crontabs/root
10 | GFWSET="gfwlist"
11 | EXTRA_COMMANDS="do_redirect testbackup test_crontab force_reload isrunning"
12 | EXTRA_HELP=" do_redirect 0 or 1\
13 | testbackup backup or restore\
14 | test_crontab
15 | force_reload
16 | isrunning"
17 |
18 | set_forward_dnsmasq()
19 | {
20 | addr="127.0.0.1#$AdGuardHome_PORT"
21 | OLD_SERVER="$(uci get dhcp.@dnsmasq[0].server 2>/dev/null)"
22 | echo $OLD_SERVER | grep "^$addr" >/dev/null 2>&1
23 | if [ $? -eq 0 ]; then
24 | return
25 | fi
26 | uci delete dhcp.@dnsmasq[0].server 2>/dev/null
27 | uci add_list dhcp.@dnsmasq[0].server="$addr"
28 | for server in $OLD_SERVER; do
29 | if [ "$server" = "$addr" ]; then
30 | continue
31 | fi
32 | uci add_list dhcp.@dnsmasq[0].server=$server
33 | done
34 | uci delete dhcp.@dnsmasq[0].resolvfile 2>/dev/null
35 | uci set dhcp.@dnsmasq[0].noresolv=1
36 | uci commit dhcp
37 | /etc/init.d/dnsmasq restart >/dev/null 2>&1
38 | }
39 |
40 | stop_forward_dnsmasq()
41 | {
42 | local OLD_PORT="$1"
43 | addr="127.0.0.1#$OLD_PORT"
44 | OLD_SERVER="$(uci get dhcp.@dnsmasq[0].server 2>/dev/null)"
45 | echo $OLD_SERVER | grep "^$addr" >/dev/null 2>&1
46 | if [ $? -ne 0 ]; then
47 | return
48 | fi
49 |
50 | uci del_list dhcp.@dnsmasq[0].server="$addr" 2>/dev/null
51 |
52 | addrlist="$(uci get dhcp.@dnsmasq[0].server 2>/dev/null)"
53 | if [ -z "$addrlist" ]; then
54 | resolvfile="/tmp/resolv.conf.d/resolv.conf.auto"
55 | [ ! -f "$resolvfile" ] && resolvfile="/tmp/resolv.conf.auto"
56 | uci set dhcp.@dnsmasq[0].resolvfile="$resolvfile" 2>/dev/null
57 | uci delete dhcp.@dnsmasq[0].noresolv 2>/dev/null
58 | fi
59 | uci commit dhcp
60 | /etc/init.d/dnsmasq restart >/dev/null 2>&1
61 | }
62 |
63 | set_firewall()
64 | {
65 | uci set firewall.adguardhome_redirect="redirect"
66 | uci set firewall.adguardhome_redirect.target="DNAT"
67 | uci set firewall.adguardhome_redirect.name="AdGuard Home"
68 | uci set firewall.adguardhome_redirect.src="lan"
69 | uci set firewall.adguardhome_redirect.family="any"
70 | uci set firewall.adguardhome_redirect.src_dport="53"
71 | uci set firewall.adguardhome_redirect.dest_port="$AdGuardHome_PORT"
72 | uci commit firewall
73 | /etc/init.d/firewall reload
74 | echo "firewall rules updated."
75 | }
76 |
77 | clear_firewall()
78 | {
79 | redirects=$(uci show firewall | grep "firewall.adguardhome_redirect")
80 | if [ -z "$redirects" ]; then
81 | echo "no redirect rules found."
82 | else
83 | uci delete firewall.adguardhome_redirect
84 | uci commit firewall
85 | /etc/init.d/firewall reload
86 | echo "deleted redirect rule: firewall.adguardhome_redirect"
87 | fi
88 | }
89 |
90 | service_triggers() {
91 | procd_add_reload_trigger "$CONFIGURATION"
92 | [ "$(uci get AdGuardHome.AdGuardHome.redirect)" == "redirect" ] && procd_add_reload_trigger firewall
93 | }
94 |
95 | isrunning(){
96 | config_load "${CONFIGURATION}"
97 | _isrunning
98 | local r=$?
99 | ([ "$r" == "0" ] && echo "running") || ([ "$r" == "1" ] && echo "not run" ) || echo "no bin"
100 | return $r
101 | }
102 |
103 | _isrunning(){
104 | config_get binpath $CONFIGURATION binpath "/usr/bin/AdGuardHome"
105 | [ ! -f "$binpath" ] && return 2
106 | pgrep $binpath 2>&1 >/dev/null && return 0
107 | return 1
108 | }
109 |
110 | force_reload(){
111 | config_load "${CONFIGURATION}"
112 | _isrunning && procd_send_signal "$CONFIGURATION" || start
113 | }
114 |
115 | rm_port53()
116 | {
117 | local AdGuardHome_PORT=$(config_editor "dns.port" "" "$configpath" "1")
118 | dnsmasq_port=$(uci get dhcp.@dnsmasq[0].port 2>/dev/null)
119 | if [ -z "$dnsmasq_port" ]; then
120 | dnsmasq_port="53"
121 | fi
122 | if [ "$dnsmasq_port" == "$AdGuardHome_PORT" ]; then
123 | if [ "$dnsmasq_port" == "53" ]; then
124 | dnsmasq_port="1745"
125 | fi
126 | elif [ "$dnsmasq_port" == "53" ]; then
127 | return
128 | fi
129 | config_editor "dns.port" "$dnsmasq_port" "$configpath"
130 | uci set dhcp.@dnsmasq[0].port="53"
131 | uci commit dhcp
132 | config_get binpath $CONFIGURATION binpath "/usr/bin/AdGuardHome"
133 | killall -9 $binpath
134 | /etc/init.d/dnsmasq restart
135 | }
136 |
137 | use_port53()
138 | {
139 | local AdGuardHome_PORT=$(config_editor "dns.port" "" "$configpath" "1")
140 | dnsmasq_port=$(uci get dhcp.@dnsmasq[0].port 2>/dev/null)
141 | if [ -z "$dnsmasq_port" ]; then
142 | dnsmasq_port="53"
143 | fi
144 | if [ "$dnsmasq_port" == "$AdGuardHome_PORT" ]; then
145 | if [ "$dnsmasq_port" == "53" ]; then
146 | AdGuardHome_PORT="1745"
147 | fi
148 | elif [ "$AdGuardHome_PORT" == "53" ]; then
149 | return
150 | fi
151 | config_editor "dns.port" "53" "$configpath"
152 | uci set dhcp.@dnsmasq[0].port="$AdGuardHome_PORT"
153 | uci commit dhcp
154 | /etc/init.d/dnsmasq restart
155 | }
156 |
157 | do_redirect()
158 | {
159 | config_load "${CONFIGURATION}"
160 | _do_redirect $1
161 | }
162 |
163 | _do_redirect()
164 | {
165 | local section="$CONFIGURATION"
166 | enabled=$1
167 |
168 | config_get configpath $CONFIGURATION configpath "/etc/AdGuardHome.yaml"
169 | AdGuardHome_PORT=$(config_editor "dns.port" "" "$configpath" "1")
170 | if [ ! -s "$configpath" ]; then
171 | cp -f /usr/share/AdGuardHome/AdGuardHome_template.yaml $configpath
172 | fi
173 | if [ -z "$AdGuardHome_PORT" ]; then
174 | AdGuardHome_PORT="0"
175 | fi
176 | config_get "redirect" "$section" "redirect" "none"
177 | config_get "old_redirect" "$section" "old_redirect" "none"
178 | config_get "old_port" "$section" "old_port" "0"
179 | config_get "old_enabled" "$section" "old_enabled" "0"
180 | uci get dhcp.@dnsmasq[0].port >/dev/null 2>&1 || uci set dhcp.@dnsmasq[0].port="53" >/dev/null 2>&1
181 | uci commit dhcp
182 | if [ "$old_enabled" = "1" -a "$old_redirect" == "exchange" ]; then
183 | AdGuardHome_PORT=$(uci get dhcp.@dnsmasq[0].port 2>/dev/null)
184 | fi
185 |
186 | if [ "$old_redirect" != "$redirect" ] || [ "$old_port" != "$AdGuardHome_PORT" ] || [ "$old_enabled" = "1" -a "$enabled" = "0" ]; then
187 | if [ "$old_redirect" != "none" ]; then
188 | if [ "$old_redirect" == "redirect" -a "$old_port" != "0" ]; then
189 | clear_firewall
190 | elif [ "$old_redirect" == "dnsmasq-upstream" ]; then
191 | stop_forward_dnsmasq "$old_port"
192 | elif [ "$old_redirect" == "exchange" ]; then
193 | rm_port53
194 | fi
195 | fi
196 | elif [ "$old_enabled" = "1" -a "$enabled" = "1" ]; then
197 | if [ "$old_redirect" == "redirect" -a "$old_port" != "0" ]; then
198 | clear_firewall
199 | fi
200 | fi
201 | uci delete AdGuardHome.@AdGuardHome[0].old_redirect 2>/dev/null
202 | uci delete AdGuardHome.@AdGuardHome[0].old_port 2>/dev/null
203 | uci delete AdGuardHome.@AdGuardHome[0].old_enabled 2>/dev/null
204 | uci add_list AdGuardHome.@AdGuardHome[0].old_redirect="$redirect" 2>/dev/null
205 | uci add_list AdGuardHome.@AdGuardHome[0].old_port="$AdGuardHome_PORT" 2>/dev/null
206 | uci add_list AdGuardHome.@AdGuardHome[0].old_enabled="$enabled" 2>/dev/null
207 | uci commit AdGuardHome
208 |
209 | if [ "$enabled" == "0" ] || [ "$AdGuardHome_PORT" == "0" ]; then
210 | echo -n "0">/var/run/AdGredir
211 | return 1
212 | fi
213 | redirected=1
214 | if [ "$redirect" = "redirect" ]; then
215 | set_firewall
216 | elif [ "$redirect" = "dnsmasq-upstream" ]; then
217 | set_forward_dnsmasq
218 | elif [ "$redirect" == "exchange" -a "$(uci get dhcp.@dnsmasq[0].port 2>/dev/null)" == "53" ]; then
219 | use_port53
220 | else
221 | redirected=0
222 | fi
223 | echo -n "$redirected">/var/run/AdGredir
224 | }
225 |
226 | get_filesystem()
227 | {
228 | # print out path filesystem
229 | echo $1 | awk '
230 | BEGIN{
231 | while (("mount"| getline ret) > 0)
232 | {
233 | split(ret,d);
234 | fs[d[3]]=d[5];
235 | m=index(d[1],":")
236 | if (m==0)
237 | {
238 | pt[d[3]]=d[1]
239 | }else{
240 | pt[d[3]]=substr(d[1],m+1)
241 | }}}{
242 | split($0,d,"/");
243 | if ("/" in fs)
244 | {
245 | result1=fs["/"];
246 | }
247 | if ("/" in pt)
248 | {
249 | result2=pt["/"];
250 | }
251 | for (i=2;i<=length(d);i++)
252 | {
253 | p[i]=p[i-1]"/"d[i];
254 | if (p[i] in fs)
255 | {
256 | result1=fs[p[i]];
257 | result2=pt[p[i]];
258 | }
259 | }
260 | if (result2 in fs){
261 | result=fs[result2]}
262 | else{
263 | result=result1}
264 | print(result);}'
265 | }
266 |
267 | config_editor()
268 | {
269 | [ -n "$3" -a -f $3 ] || return
270 | awk -v yaml="$1" -v value="$2" -v file="$3" -v ro="$4" '
271 | BEGIN{split(yaml,part,"\.");s="";i=1;l=length(part);}
272 | {
273 | if (match($0,s""part[i]":"))
274 | {
275 | if (i==l)
276 | {
277 | split($0,t,": ");
278 | if (ro==""){
279 | system("sed -i '\''"FNR"c \\"t[1]": "value"'\'' "file);
280 | }else{
281 | print(t[2]);
282 | }
283 | exit;
284 | }
285 | s=s"[- ]{2}";
286 | i++;
287 | }
288 | }' $3
289 | }
290 |
291 | boot_service() {
292 | rm /var/run/AdGserverdis >/dev/null 2>&1
293 | config_load "${CONFIGURATION}"
294 | config_get waitonboot $CONFIGURATION waitonboot "0"
295 | config_get_bool enabled $CONFIGURATION enabled 0
296 | config_get binpath $CONFIGURATION binpath "/usr/bin/AdGuardHome"
297 | [ -f "$binpath" ] && start_service
298 | if [ "$enabled" == "1" ] && [ "$waitonboot" == "1" ]; then
299 | procd_open_instance "waitnet"
300 | procd_set_param command "/usr/share/AdGuardHome/waitnet.sh"
301 | procd_close_instance
302 | echo "no net start pinging"
303 | fi
304 | }
305 |
306 | testbackup(){
307 | config_load "${CONFIGURATION}"
308 | if [ "$1" == "backup" ]; then
309 | backup
310 | elif [ "$1" == "restore" ]; then
311 | restore
312 | fi
313 | }
314 |
315 | restore()
316 | {
317 | config_get workdir $CONFIGURATION workdir "/etc/AdGuardHome"
318 | config_get backupwdpath $CONFIGURATION backupwdpath "/etc/AdGuardHome"
319 | cp -u -r -f $backupwdpath/data $workdir
320 | }
321 |
322 | backup() {
323 | config_get backupwdpath $CONFIGURATION backupwdpath "/etc/AdGuardHome"
324 | mkdir -p $backupwdpath/data
325 | config_get workdir $CONFIGURATION workdir "/etc/AdGuardHome"
326 | config_get backupfile $CONFIGURATION backupfile ""
327 | for one in $backupfile;
328 | do
329 | while :
330 | do
331 | if [ -d "$backupwdpath/data/$one" ]; then
332 | cpret=$(cp -u -r -f $workdir/data/$one $backupwdpath/data 2>&1)
333 | else
334 | cpret=$(cp -u -r -f $workdir/data/$one $backupwdpath/data/$one 2>&1)
335 | fi
336 | echo "$cpret"
337 | echo "$cpret" | grep "no space left on device"
338 | if [ "$?" == "0" ]; then
339 | echo "磁盘已满,删除log重试中"
340 | del_querylog && continue
341 | rm -f -r $backupwdpath/data/filters
342 | rm -f -r $workdir/data/filters && continue
343 | echo "backup failed"
344 | fi
345 | break
346 | done
347 | done
348 | }
349 |
350 | _add_upprotect_file()
351 | {
352 | local file="$1"
353 | # Expand variables in the file path
354 | local expanded_file=$(eval echo "$file")
355 | echo "$expanded_file" >> /lib/upgrade/keep.d/luci-app-adguardhome
356 | }
357 | start_service() {
358 | # Reading config
359 | rm /var/run/AdGserverdis >/dev/null 2>&1
360 | config_load "${CONFIGURATION}"
361 | # update password
362 | config_get hashpass $CONFIGURATION hashpass ""
363 | config_get configpath $CONFIGURATION configpath "/etc/AdGuardHome.yaml"
364 | if [ -n "$hashpass" ]; then
365 | config_editor "users.password" "$hashpass" "$configpath"
366 | uci set $CONFIGURATION.$CONFIGURATION.hashpass=""
367 | fi
368 | local ipst=0
369 | config_get_bool enabled $CONFIGURATION enabled 0
370 | # update crontab
371 | do_crontab
372 | echo "luci enable switch=$enabled"
373 | if [ "$enabled" == "0" ]; then
374 | _do_redirect 0
375 | return
376 | fi
377 | #what need to do before reload
378 | config_get workdir $CONFIGURATION workdir "/etc/AdGuardHome"
379 | grep -q "ipset.txt" $configpath 2>/dev/null && ipst=1
380 | if [ $ipst -eq 1 ];then
381 | ipset list $GFWSET >/dev/null 2>&1 || ipset create $GFWSET hash:ip 2>/dev/null
382 | fi
383 | config_get backupfile $CONFIGURATION backupfile ""
384 | mkdir -p $workdir/data
385 | if [ -n "$backupfile" ] && [ ! -d "$workdir/data" ]; then
386 | restore
387 | fi
388 | # for overlay data-stk-oo not suppport
389 | local cwdfs=$(get_filesystem $workdir)
390 | echo "workdir is a $cwdfs filesystem"
391 | if [ "$cwdfs" == "jffs2" ]; then
392 | echo "fs error ln db to tmp $workdir $cwdfs"
393 | logger "AdGuardHome" "warning db redirect to tmp"
394 | touch $workdir/data/stats.db
395 | if [ ! -L $workdir/data/stats.db ]; then
396 | mv -f $workdir/data/stats.db /tmp/stats.db 2>/dev/null
397 | ln -s /tmp/stats.db $workdir/data/stats.db 2>/dev/null
398 | fi
399 | touch $workdir/data/sessions.db
400 | if [ ! -L $workdir/data/sessions.db ]; then
401 | mv -f $workdir/data/sessions.db /tmp/sessions.db 2>/dev/null
402 | ln -s /tmp/sessions.db $workdir/data/sessions.db 2>/dev/null
403 | fi
404 | fi
405 |
406 | # hack to save config file when upgrade system
407 | config_get upprotect $CONFIGURATION upprotect ""
408 | if [ -n "$upprotect" ]; then
409 | # Handle both old MultiValue format (space-separated) and new DynamicList format
410 | if echo "$upprotect" | grep -q " "; then
411 | # Old format: space-separated values
412 | eval upprotect=${upprotect// /\\\\n}
413 | echo -e "$upprotect">/lib/upgrade/keep.d/luci-app-adguardhome
414 | else
415 | echo -n > /lib/upgrade/keep.d/luci-app-adguardhome
416 | # New format: UCI list, get all values
417 | config_list_foreach $CONFIGURATION upprotect _add_upprotect_file
418 | fi
419 | fi
420 |
421 |
422 |
423 | config_get binpath $CONFIGURATION binpath "/usr/bin/AdGuardHome"
424 | mkdir -p ${binpath%/*}
425 | if [ ! -f "$binpath" ]; then
426 | _do_redirect 0
427 | /usr/share/AdGuardHome/update_core.sh 2>&1 >/tmp/AdGuardHome_update.log &
428 | exit 0
429 | fi
430 | config_get httpport $CONFIGURATION httpport 3000
431 | local ADDITIONAL_ARGS=" -c $configpath -w $workdir -p $httpport --no-check-update"
432 | config_get logfile $CONFIGURATION logfile ""
433 | if [ -n "$logfile" ]; then
434 | ADDITIONAL_ARGS="$ADDITIONAL_ARGS -l $logfile"
435 | fi
436 | config_get_bool verbose $CONFIGURATION verbose 0
437 | if [ "$verbose" -eq 1 ]; then
438 | ADDITIONAL_ARGS="$ADDITIONAL_ARGS -v"
439 | fi
440 |
441 | procd_open_instance
442 | SET_TZ="`uci get system.@system[0].timezone 2>/dev/null`"
443 | if [ -n "$SET_TZ" ]; then
444 | procd_set_param env TZ="$SET_TZ"
445 | fi
446 | procd_set_param respawn ${respawn_threshold:-3600} ${respawn_timeout:-5} ${respawn_retry:-5}
447 | procd_set_param limits core="unlimited" nofile="65535 65535"
448 | procd_set_param stderr 1
449 | procd_set_param command $binpath $ADDITIONAL_ARGS
450 | procd_set_param file "$configpath" "/etc/hosts" "/etc/config/AdGuardHome"
451 | procd_close_instance
452 | if [ -f "$configpath" ]; then
453 | (sleep 5 && _do_redirect 1) &
454 | else
455 | _do_redirect 0
456 | config_get "redirect" $CONFIGURATION "redirect" "none"
457 | if [ "$redirect" != "none" ]; then
458 | procd_open_instance "waitconfig"
459 | procd_set_param command "/usr/share/AdGuardHome/watchconfig.sh"
460 | procd_close_instance
461 | echo "no config start watching"
462 | fi
463 | fi
464 | echo "AdGuardHome service enabled"
465 |
466 | }
467 |
468 | reload_service()
469 | {
470 | rm /var/run/AdGlucitest >/dev/null 2>&1
471 | echo "AdGuardHome reloading"
472 | start
473 | }
474 |
475 | del_querylog(){
476 | local btarget=$(ls $backupwdpath/data | grep -F "querylog.json" | sort -r | head -n 1)
477 | local wtarget=$(ls $workdir/data | grep -F "querylog.json" | sort -r | head -n 1)
478 | if [ "$btarget"x == "$wtarget"x ]; then
479 | [ -z "$btarget" ] && return 1
480 | rm -f $workdir/data/$wtarget
481 | rm -f $backupwdpath/data/$btarget
482 | return 0
483 | fi
484 | if [ "$btarget" \> "$wtarget" ]; then
485 | rm -f $backupwdpath/data/$btarget
486 | return 0
487 | else
488 | rm -f $workdir/data/$wtarget
489 | return 0
490 | fi
491 | }
492 |
493 | stop_service()
494 | {
495 | config_load "${CONFIGURATION}"
496 | _do_redirect 0
497 | do_crontab
498 | if [ "$1" != "nobackup" ]; then
499 | config_get backupfile $CONFIGURATION backupfile "0"
500 | if [ -n "$backupfile" ]; then
501 | backup
502 | fi
503 | fi
504 | echo "AdGuardHome service disabled"
505 | touch /var/run/AdGserverdis
506 | }
507 |
508 | boot() {
509 | rc_procd boot_service "$@"
510 | if eval "type service_started" 2>/dev/null >/dev/null; then
511 | service_started
512 | fi
513 | }
514 |
515 | test_crontab(){
516 | config_load "${CONFIGURATION}"
517 | do_crontab
518 | }
519 |
520 | do_crontab(){
521 | config_get_bool enabled $CONFIGURATION enabled 0
522 | config_get crontab $CONFIGURATION crontab ""
523 | local findstr default cronenable replace commit
524 | local cronreload=0
525 | local commit=0
526 | findstr="/usr/share/AdGuardHome/update_core.sh"
527 | default="30 3 * * * /usr/share/AdGuardHome/update_core.sh 2>&1"
528 | [ "$enabled" == "0" ] || [ "${crontab//autoupdate/}" == "$crontab" ] && cronenable=0 || cronenable=1
529 | crontab_editor
530 |
531 | config_get workdir $CONFIGURATION workdir "/etc/AdGuardHome"
532 | config_get lastworkdir $CONFIGURATION lastworkdir "/etc/AdGuardHome"
533 | findstr="/usr/share/AdGuardHome/tailto.sh [0-9]* \$(uci get AdGuardHome.AdGuardHome.workdir)/data/querylog.json"
534 | #[ -n "$lastworkdir" ] && findstr="/usr/share/AdGuardHome/tailto.sh [0-9]* $lastworkdir/data/querylog.json" && [ "$lastworkdir" != "$workdir" ] && replace="${lastworkdir//\//\\/}/${workdir//\//\\/}"
535 | default="0 * * * * /usr/share/AdGuardHome/tailto.sh 2000 \$(uci get AdGuardHome.AdGuardHome.workdir)/data/querylog.json"
536 | [ "$enabled" == "0" ] || [ "${crontab//cutquerylog/}" == "$crontab" ] && cronenable=0 || cronenable=1
537 | crontab_editor
538 | #[ "$lastworkdir" != "$workdir" ] && uci set AdGuardHome.AdGuardHome.lastworkdir="$workdir" && commit=1
539 |
540 | config_get logfile $CONFIGURATION logfile ""
541 | config_get lastlogfile $CONFIGURATION lastlogfile ""
542 | findstr="/usr/share/AdGuardHome/tailto.sh [0-9]* \$(uci get AdGuardHome.AdGuardHome.logfile)"
543 | default="30 3 * * * /usr/share/AdGuardHome/tailto.sh 2000 \$(uci get AdGuardHome.AdGuardHome.logfile)"
544 | #[ -n "$lastlogfile" ] && findstr="/usr/share/AdGuardHome/tailto.sh [0-9]* $lastlogfile" && [ -n "$logfile" ] && [ "$lastlogfile" != "$logfile" ] && replace="${lastlogfile//\//\\/}/${logfile//\//\\/}"
545 | [ "$logfile" == "syslog" ] || [ "$logfile" == "" ] || [ "$enabled" == "0" ] || [ "${crontab//cutruntimelog/}" == "$crontab" ] && cronenable=0 || cronenable=1
546 | crontab_editor
547 | #[ -n "$logfile" ] && [ "$lastlogfile" != "$logfile" ] && uci set AdGuardHome.AdGuardHome.lastlogfile="$logfile" && commit=1
548 |
549 | findstr="/usr/share/AdGuardHome/addhost.sh"
550 | default="0 * * * * /usr/share/AdGuardHome/addhost.sh"
551 | [ "$enabled" == "0" ] || [ "${crontab//autohost/}" == "$crontab" ] && cronenable=0 || cronenable=1
552 | crontab_editor
553 | [ "$cronenable" == "0" ] && /usr/share/AdGuardHome/addhost.sh "del" "noreload" || /usr/share/AdGuardHome/addhost.sh "" "noreload"
554 |
555 | findstr="/usr/share/AdGuardHome/gfw2adg.sh"
556 | default="30 3 * * * /usr/share/AdGuardHome/gfw2adg.sh"
557 | [ "$enabled" == "0" ] || [ "${crontab//autogfw/}" == "$crontab" ] && cronenable=0 || cronenable=1
558 | crontab_editor
559 | findstr="/usr/share/AdGuardHome/gfwipset2adg.sh"
560 | default="31 3 * * * /usr/share/AdGuardHome/gfwipset2adg.sh"
561 | [ "$enabled" == "0" ] || [ "${crontab//autogfwipset/}" == "$crontab" ] && cronenable=0 || cronenable=1
562 | crontab_editor
563 | [ "$cronreload" -gt 0 ] && /etc/init.d/cron restart
564 | #[ "$commit" -gt 0 ] && uci commit AdGuardHome
565 | }
566 |
567 | crontab_editor(){
568 | [ ! -f "$CRON_FILE" ] && mkdir -p ${CRON_FILE%/*} && touch "$CRON_FILE" && chmod 600 "$CRON_FILE"
569 | #usage input:
570 | #findstr=
571 | #default=
572 | #cronenable=
573 | #replace="${last//\//\\/}/${now//\//\\/}"
574 | #output:cronreload:if >1 please /etc/init.d/cron restart manual
575 | local testline reload
576 | local line="$(grep "$findstr" $CRON_FILE)"
577 | [ -n "$replace" ] && [ -n "$line" ] && eval testline="\${line//$replace}" && [ "$testline" != "$line" ] && line="$testline" && reload="1" && replace=""
578 | if [ "${line:0:1}" != "#" ]; then
579 | if [ $cronenable -eq 1 ]; then
580 | [ -z "$line" ] && line="$default" && reload="1"
581 | if [ -n "$reload" ]; then
582 | sed -i "\,$findstr,d" $CRON_FILE
583 | echo "$line" >> $CRON_FILE
584 | cronreload=$((cronreload+1))
585 | fi
586 | elif [ -n "$line" ]; then
587 | sed -i "\,$findstr,d" $CRON_FILE
588 | echo "#$line" >> $CRON_FILE
589 | cronreload=$((cronreload+1))
590 | fi
591 | else
592 | if [ $cronenable -eq 1 ]; then
593 | sed -i "\,$findstr,d" $CRON_FILE
594 | echo "${line:1}" >> $CRON_FILE
595 | cronreload=$((cronreload+1))
596 | elif [ -z "$reload" ]; then
597 | sed -i "\,$findstr,d" $CRON_FILE
598 | echo "$line" >> $CRON_FILE
599 | fi
600 | fi
601 | }
602 |
--------------------------------------------------------------------------------