luci-app-adbyby-plus: add support AdGuardHome / Host / DNSMASQ rules

This commit is contained in:
LEAN-ESX 2020-03-10 11:08:59 -07:00
parent 252c766ae3
commit f9cb999ad1
8 changed files with 106 additions and 14 deletions

View File

@ -10,7 +10,7 @@ LUCI_DEPENDS:=+adbyby +wget +ipset +dnsmasq-full
LUCI_PKGARCH:=all
PKG_NAME:=luci-app-adbyby-plus
PKG_VERSION:=2.0
PKG_RELEASE:=58
PKG_RELEASE:=61
include $(TOPDIR)/feeds/luci/luci.mk

View File

@ -32,14 +32,29 @@ function refresh_data()
local set =luci.http.formvalue("set")
local icount =0
if set == "gfw_data" then
retstring ="0"
elseif set == "ip_data" then
if set == "rule_data" then
luci.sys.exec("/usr/share/adbyby/rule-update")
icount = luci.sys.exec("/usr/share/adbyby/rule-count '/tmp/rules/'")
if tonumber(icount)>0 then
if nixio.fs.access("/usr/share/adbyby/rules/") then
oldcount=luci.sys.exec("/usr/share/adbyby/rule-count '/usr/share/adbyby/rules/'")
else
oldcount=0
end
else
retstring ="-1"
end
if tonumber(icount) ~= tonumber(oldcount) then
luci.sys.exec("rm -rf /usr/share/adbyby/rules/* && cp -a /tmp/rules /usr/share/adbyby/")
luci.sys.exec("/etc/init.d/dnsmasq reload")
retstring=tostring(math.ceil(tonumber(icount)))
else
retstring ="0"
end
else
refresh_cmd="wget-ssl -q --no-check-certificate -O - 'https://easylist-downloads.adblockplus.org/easylistchina+easylist.txt' > /tmp/adnew.conf"
sret=luci.sys.call(refresh_cmd .. " 2>/dev/null")
if sret== 0 then
luci.sys.call("/usr/share/adbyby/ad-update")

View File

@ -7,11 +7,21 @@ if nixio.fs.access("/usr/share/adbyby/dnsmasq.adblock") then
ad_count=tonumber(SYS.exec("cat /usr/share/adbyby/dnsmasq.adblock | wc -l"))
end
local rule_count=0
if nixio.fs.access("/usr/share/adbyby/rules/") then
rule_count=tonumber(SYS.exec("/usr/share/adbyby/rule-count '/usr/share/adbyby/rules/'"))
end
m = Map("adbyby")
s = m:section(TypedSection, "adbyby")
s.anonymous = true
o = s:option(Flag, "block_ios")
o.title = translate("Block Apple iOS OTA update")
o.default = 0
o.rmempty = false
o = s:option(Flag, "cron_mode")
o.title = translate("Update the rule at 6 a.m. every morning and restart adbyby")
o.default = 0
@ -22,9 +32,22 @@ o.rawhtml = true
o.template = "adbyby/refresh"
o.value =ad_count .. " " .. translate("Records")
o = s:option(Flag, "block_ios")
o.title = translate("Block Apple iOS OTA update")
o.default = 0
o.rmempty = false
o=s:option(DummyValue,"rule_data",translate("Subscribe 3rd Rules Data"))
o.rawhtml = true
o.template = "adbyby/refresh"
o.value =rule_count .. " " .. translate("Records")
o.description = translate("AdGuardHome / Host / DNSMASQ rules auto-convert")
o = s:option(Button,"delete",translate("Delete All Subscribe Rules"))
o.inputstyle = "reset"
o.write = function()
SYS.exec("rm -rf /usr/share/adbyby/rules/data/* /usr/share/adbyby/rules/host/*")
SYS.exec("mkdir -p /usr/share/adbyby/rules/data/ /usr/share/adbyby/rules/host/")
SYS.exec("/etc/init.d/adbyby restart 2>&1 &")
luci.http.redirect(luci.dispatcher.build_url("admin", "services", "adbyby", "advanced"))
end
o = s:option(DynamicList, "subscribe_url", translate("Anti-AD Rules Subscribe"))
o.rmempty = true
return m

View File

@ -8,10 +8,9 @@ local DV = SYS.exec("head -1 /tmp/adbyby/data/video.txt | awk -F' ' '{print $3,$
local NR = SYS.exec("grep -v '^!' /usr/share/adbyby/data/rules.txt | wc -l")
local NU = SYS.exec("cat /usr/share/adbyby/data/user.txt | wc -l")
local UD = NXFS.readfile("/tmp/adbyby.updated") or "1970-01-01 00:00:00"
local ND = SYS.exec("cat /usr/share/adbyby/dnsmasq.adblock | wc -l")
m = Map("adbyby")
m.title = translate("Adbyby Plus +")
m.title = translate("Adbyby Plus + Settings")
m.description = translate("Adbyby Plus + can filter all kinds of banners, popups, video ads, and prevent tracking, privacy theft and a variety of malicious websites<br /><font color=\"red\">Plus + version combination mode can operation with Adblock Plus Host,filtering ads without losing bandwidth</font>")
m:section(SimpleSection).template = "adbyby/adbyby_status"

View File

@ -13,6 +13,9 @@ msgstr "广告屏蔽大师 Plus + 可以全面过滤各种横幅、弹窗、视
msgid "Adbyby Plus +"
msgstr "广告屏蔽大师 Plus+"
msgid "Adbyby Plus + Settings"
msgstr "广告屏蔽大师 Plus+(支持 AdGuardHome /Host / DNSMASQ 规则)"
msgid "Base Setting"
msgstr "基本设置"
@ -55,7 +58,6 @@ msgstr "域名黑名单"
msgid "Black IP List"
msgstr "IP黑名单"
msgid "Advance Setting"
msgstr "高级设置"
@ -68,6 +70,18 @@ msgstr "Adblock Plus Hosts 记录数"
msgid "Adblock Plus Data"
msgstr "Adblock Plus 规则数据库"
msgid "Subscribe 3rd Rules Data"
msgstr "订阅第三方去广告规则"
msgid "Delete All Subscribe Rules"
msgstr "清空所有订阅的规则库"
msgid "Anti-AD Rules Subscribe"
msgstr "广告过滤规则订阅URL"
msgid "AdGuardHome / Host / DNSMASQ rules auto-convert"
msgstr "AdGuardHome / Host / DNSMASQ 规则自动识别"
msgid "Manually force update<br />Adblock Plus Host List"
msgstr "手动强制更新<br />Adblock Plus Host List"

View File

@ -110,6 +110,8 @@ add_dns()
awk '!/^$/&&!/^#/{printf("address=/%s/'"0.0.0.0"'\n",$0)}' $PROG_PATH/adblack.conf > /var/etc/dnsmasq-adbyby.d/07-dnsmasq.black
cat > /tmp/dnsmasq.d/dnsmasq-adbyby.conf <<EOF
conf-dir=/var/etc/dnsmasq-adbyby.d
addn-hosts=/usr/share/adbyby/rules/host/
conf-dir=/usr/share/adbyby/rules/data
EOF
local var=1
@ -122,7 +124,7 @@ EOF
fi
fi
sed -i '/mesu.apple.com/d' /etc/dnsmasq.conf && [ $block_ios -eq 1 ] && echo 'address=/mesu.apple.com/0.0.0.0' >> /etc/dnsmasq.conf
[ $block_ios -eq 1 ] && echo 'address=/mesu.apple.com/0.0.0.0' >> /tmp/dnsmasq.d/dnsmasq-adbyby.conf
}
del_dns()

View File

@ -0,0 +1,3 @@
#!/bin/sh
find $1 -type f -exec cat {} \; | wc -l

View File

@ -0,0 +1,36 @@
#!/bin/sh -e
url_md5() {
echo -n $1|md5sum|cut -d ' ' -f1
}
convert_rules() {
mkdir -p /tmp/rules/data
mkdir -p /tmp/rules/host
wget-ssl -q --no-check-certificate $1 -O /tmp/adnew.conf
rulename=$(url_md5 $1)
if [ -f /tmp/adnew.conf ]; then
if (grep -wq "address=" /tmp/adnew.conf) ; then
cp /tmp/adnew.conf /tmp/rules/data/$rulename.conf
elif (grep -wq -e"0.0.0.0" -e"127.0.0.1" /tmp/adnew.conf) ; then
cp /tmp/adnew.conf /tmp/rules/host/$rulename.txt
else
cat /tmp/adnew.conf | grep ^\|\|[^\*]*\^$ | sed -e 's:||:address\=\/:' -e 's:\^:/0\.0\.0\.0:' > /tmp/rules/data/$rulename.conf
fi
fi
rm -rf /tmp/adnew.conf
}
ARRAY=$(uci get adbyby.@adbyby[0].subscribe_url 2> /dev/null)
rm -rf /tmp/rules
i=1
for j in $ARRAY
do
convert_rules $j
i=`expr $i + 1`
done