diff --git a/luci-app-mosdns/Makefile b/luci-app-mosdns/Makefile index 5b4bf9e..4763246 100644 --- a/luci-app-mosdns/Makefile +++ b/luci-app-mosdns/Makefile @@ -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 diff --git a/luci-app-mosdns/luasrc/model/cbi/mosdns/basic.lua b/luci-app-mosdns/luasrc/model/cbi/mosdns/basic.lua index d53cacb..240e6f1 100644 --- a/luci-app-mosdns/luasrc/model/cbi/mosdns/basic.lua +++ b/luci-app-mosdns/luasrc/model/cbi/mosdns/basic.lua @@ -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") diff --git a/luci-app-mosdns/po/zh-cn/mosdns.po b/luci-app-mosdns/po/zh-cn/mosdns.po index 4a1bea0..f091dca 100644 --- a/luci-app-mosdns/po/zh-cn/mosdns.po +++ b/luci-app-mosdns/po/zh-cn/mosdns.po @@ -31,6 +31,9 @@ msgstr "将 Dnsmasq 域名解析请求转发到 MosDNS 服务器" msgid "Enable DNS ADblock" msgstr "启用 DNS 广告过滤" +msgid "ADblock Source" +msgstr "广告过滤来源" + msgid "Reload Service" msgstr "重载服务" diff --git a/luci-app-mosdns/root/etc/init.d/mosdns b/luci-app-mosdns/root/etc/init.d/mosdns index 4c991e4..9d9f775 100755 --- a/luci-app-mosdns/root/etc/init.d/mosdns +++ b/luci-app-mosdns/root/etc/init.d/mosdns @@ -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() { diff --git a/luci-app-mosdns/root/etc/mosdns/rule/adlist.txt b/luci-app-mosdns/root/etc/mosdns/rule/adlist.txt new file mode 100644 index 0000000..e69de29 diff --git a/luci-app-mosdns/root/usr/share/mosdns/default.yaml b/luci-app-mosdns/root/usr/share/mosdns/default.yaml index b05254c..be2eae0 100644 --- a/luci-app-mosdns/root/usr/share/mosdns/default.yaml +++ b/luci-app-mosdns/root/usr/share/mosdns/default.yaml @@ -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 diff --git a/luci-app-mosdns/root/usr/share/mosdns/mosdns.sh b/luci-app-mosdns/root/usr/share/mosdns/mosdns.sh index 3d5c0de..172f772 100755 --- a/luci-app-mosdns/root/usr/share/mosdns/mosdns.sh +++ b/luci-app-mosdns/root/usr/share/mosdns/mosdns.sh @@ -26,12 +26,30 @@ interface_dns() ( ad_block() ( adblock=$(uci -q get mosdns.mosdns.adblock) if [ "$adblock" -eq 1 ]; then - echo "provider:geosite:category-ads-all" + 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