luci-app-mosdns: add custom adblock list source support
This commit is contained in:
parent
a2f818e433
commit
d9c1f1ca62
@ -2,7 +2,7 @@ include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_NAME:=luci-app-mosdns
|
||||
PKG_VERSION:=1.4.2
|
||||
PKG_RELEASE:=1
|
||||
PKG_RELEASE:=2
|
||||
|
||||
LUCI_TITLE:=LuCI Support for mosdns
|
||||
LUCI_PKGARCH:=all
|
||||
|
@ -88,6 +88,14 @@ adblock = s:option(Flag, "adblock", translate("Enable DNS ADblock"))
|
||||
adblock:depends( "configfile", "/etc/mosdns/config.yaml")
|
||||
adblock.default = false
|
||||
|
||||
adblock = s:option(Value, "ad_source", translate("ADblock Source"))
|
||||
adblock:depends("adblock", "1")
|
||||
adblock.default = "https://cdn.jsdelivr.net/gh/privacy-protection-tools/anti-AD@master/anti-ad-domains.txt"
|
||||
adblock:value("geosite.dat", "v2ray-geosite")
|
||||
adblock:value("https://cdn.jsdelivr.net/gh/privacy-protection-tools/anti-AD@master/anti-ad-domains.txt", "anti-AD")
|
||||
adblock:value("https://cdn.jsdelivr.net/gh/sjhgvr/oisd@main/dbl_basic.txt", "oisd (basic)")
|
||||
adblock:value("https://cdn.jsdelivr.net/gh/QiuSimons/openwrt-mos@master/dat/serverlist.txt", "QiuSimons/openwrt-mos")
|
||||
|
||||
reload_service = s:option( Button, "_reload", translate("Reload Service"), translate("Reload service to take effect of new configuration"))
|
||||
reload_service.write = function()
|
||||
luci.sys.exec("/etc/init.d/mosdns reload")
|
||||
|
@ -31,6 +31,9 @@ msgstr "将 Dnsmasq 域名解析请求转发到 MosDNS 服务器"
|
||||
msgid "Enable DNS ADblock"
|
||||
msgstr "启用 DNS 广告过滤"
|
||||
|
||||
msgid "ADblock Source"
|
||||
msgstr "广告过滤来源"
|
||||
|
||||
msgid "Reload Service"
|
||||
msgstr "重载服务"
|
||||
|
||||
|
@ -118,6 +118,7 @@ start_service() {
|
||||
setcron
|
||||
[ "${CONF}" = "/etc/mosdns/config.yaml" ] && init_yaml
|
||||
cat /dev/null > $(/usr/share/mosdns/mosdns.sh logfile)
|
||||
[ ! "$(uci -q get mosdns.mosdns.ad_source)" = "geosite.dat" ] && cat /dev/null > /etc/mosdns/rule/adlist.txt
|
||||
procd_open_instance mosdns
|
||||
procd_set_param command $PROG start -c "$CONF"
|
||||
procd_set_param user root
|
||||
@ -129,6 +130,8 @@ start_service() {
|
||||
restore_setting
|
||||
[ "$(uci -q get mosdns.mosdns.redirect)" -eq 1 ] && redirect_setting
|
||||
reload_others
|
||||
|
||||
[ ! "$(uci -q get mosdns.mosdns.ad_source)" = "geosite.dat" ] && /usr/share/mosdns/mosdns.sh adlist_update &> /dev/null &
|
||||
}
|
||||
|
||||
stop_service() {
|
||||
|
0
luci-app-mosdns/root/etc/mosdns/rule/adlist.txt
Normal file
0
luci-app-mosdns/root/etc/mosdns/rule/adlist.txt
Normal file
@ -37,6 +37,10 @@ data_providers:
|
||||
file: "/etc/mosdns/rule/local-ptr.txt"
|
||||
auto_reload: true
|
||||
|
||||
- tag: adlist
|
||||
file: "/etc/mosdns/rule/adlist.txt"
|
||||
auto_reload: true
|
||||
|
||||
plugins:
|
||||
- tag: lazy_cache
|
||||
type: cache
|
||||
|
@ -26,12 +26,30 @@ interface_dns() (
|
||||
ad_block() (
|
||||
adblock=$(uci -q get mosdns.mosdns.adblock)
|
||||
if [ "$adblock" -eq 1 ]; then
|
||||
ad_source=$(uci -q get mosdns.mosdns.ad_source)
|
||||
if [ "$ad_source" = "geosite.dat" ]; then
|
||||
echo "provider:geosite:category-ads-all"
|
||||
else
|
||||
echo "provider:adlist"
|
||||
fi
|
||||
else
|
||||
echo "full:disable-category-ads-all.null"
|
||||
fi
|
||||
)
|
||||
|
||||
adlist_update() (
|
||||
ad_source=$(uci -q get mosdns.mosdns.ad_source)
|
||||
[ $ad_source = "geosite.dat" ] && exit 0
|
||||
AD_TMPDIR=$(mktemp -d) || exit 1
|
||||
curl --connect-timeout 60 -m 900 --ipv4 -fSLo "$AD_TMPDIR/adlist.txt" "$ad_source"
|
||||
if [ $? -ne 0 ]; then
|
||||
exit 1
|
||||
else
|
||||
\cp $AD_TMPDIR/adlist.txt /etc/mosdns/rule/adlist.txt
|
||||
rm -rf $AD_TMPDIR
|
||||
fi
|
||||
)
|
||||
|
||||
geodat_update() (
|
||||
geodat_download() (
|
||||
google_status=$(curl -I -4 -m 3 -o /dev/null -s -w %{http_code} http://www.google.com/generate_204)
|
||||
@ -58,7 +76,9 @@ if [ "$1" == "dns" ]; then
|
||||
elif [ "$1" == "ad" ]; then
|
||||
ad_block
|
||||
elif [ "$1" == "geodata" ]; then
|
||||
geodat_update
|
||||
geodat_update && adlist_update
|
||||
elif [ "$1" == "logfile" ]; then
|
||||
logfile_path
|
||||
elif [ "$1" == "adlist_update" ]; then
|
||||
adlist_update
|
||||
fi
|
||||
|
Loading…
Reference in New Issue
Block a user