Skip to content

Commit

Permalink
luci-app-adbyby-plus: add support AdGuardHome / Host / DNSMASQ rules
Browse files Browse the repository at this point in the history
  • Loading branch information
coolsnowwolf committed Mar 10, 2020
1 parent 252c766 commit f9cb999
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 14 deletions.
2 changes: 1 addition & 1 deletion package/lean/luci-app-adbyby-plus/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
25 changes: 20 additions & 5 deletions package/lean/luci-app-adbyby-plus/luasrc/controller/adbyby.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
16 changes: 15 additions & 1 deletion package/lean/luci-app-adbyby-plus/po/zh-cn/adbyby.po
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ msgstr "广告屏蔽大师 Plus + 可以全面过滤各种横幅、弹窗、视
msgid "Adbyby Plus +"
msgstr "广告屏蔽大师 Plus+"

msgid "Adbyby Plus + Settings"
msgstr "广告屏蔽大师 Plus+(支持 AdGuardHome /Host / DNSMASQ 规则)"

msgid "Base Setting"
msgstr "基本设置"

Expand Down Expand Up @@ -55,7 +58,6 @@ msgstr "域名黑名单"
msgid "Black IP List"
msgstr "IP黑名单"


msgid "Advance Setting"
msgstr "高级设置"

Expand All @@ -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"

Expand Down
4 changes: 3 additions & 1 deletion package/lean/luci-app-adbyby-plus/root/etc/init.d/adbyby
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

find $1 -type f -exec cat {} \; | wc -l
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit f9cb999

Please sign in to comment.