diff --git a/luci-app-mosdns/root/etc/init.d/mosdns b/luci-app-mosdns/root/etc/init.d/mosdns index 61cbce5..3f22ee3 100755 --- a/luci-app-mosdns/root/etc/init.d/mosdns +++ b/luci-app-mosdns/root/etc/init.d/mosdns @@ -27,6 +27,7 @@ CRON_FILE=/etc/crontabs/root get_config() { config_get enabled $1 enabled 0 + config_get adblock $1 adblock 0 config_get ad_source $1 ad_source "" config_get cache_size $1 cache_size 200000 config_get cache_survival_time $1 cache_survival_time 259200 @@ -47,7 +48,7 @@ get_config() { init_yaml() { tmpdir=$(mktemp -d) || exit 1 - adblock=$(/usr/share/mosdns/mosdns.sh ad) + adlist=$(/usr/share/mosdns/mosdns.sh ad) [ $enable_pipeline = 1 ] && enable_pipeline=true || enable_pipeline=false local_dns=$(/usr/share/mosdns/mosdns.sh dns | xargs -n1 echo " - addr:") remote_dns=$(echo $remote_dns | awk '{for(i=1;i<=NF;i++)printf "%s- addr: %s\n%s enable_pipeline: '${enable_pipeline}'\n",s,$i,s}' s=' ') @@ -56,7 +57,7 @@ init_yaml() { s,cache_survival_time,$cache_survival_time,g; \ s,minimal_ttl_custom,$minimal_ttl_custom,g; \ s,maximum_ttl_custom,$maximum_ttl_custom,g; \ - s,adblock,$adblock,g;s,remote_dns_pipeline,$enable_pipeline,g" \ + s,adblock,$adlist,g;s,remote_dns_pipeline,$enable_pipeline,g" \ /usr/share/mosdns/default.yaml > $CONF [ "$custom_local_dns" -eq 0 ] && sed -i "/bootstrap/d" $CONF || \ sed -i "s,bootstrap_dns,$bootstrap_dns,g" $CONF @@ -127,8 +128,7 @@ start_service() { delcron setcron [ "${CONF}" = "/etc/mosdns/config.yaml" ] && init_yaml - cat /dev/null > $(/usr/share/mosdns/mosdns.sh logfile) - [ ! "$ad_source" = "geosite.dat" ] && cat /dev/null > /etc/mosdns/rule/adlist.txt + :> $(/usr/share/mosdns/mosdns.sh logfile) procd_open_instance mosdns procd_set_param command $PROG start -c "$CONF" procd_set_param user root @@ -136,13 +136,15 @@ start_service() { procd_set_param stderr 1 procd_set_param respawn "${respawn_threshold:-3600}" "${respawn_timeout:-5}" "${respawn_retry:-5}" procd_close_instance mosdns - [ "$redirect" -ne 1 ] && [ -f "/etc/mosdns/redirect.lock" ] && restore_setting [ "$redirect" -eq 1 ] && redirect_setting - reload_others - - [ ! "$ad_source" = "geosite.dat" ] && /usr/share/mosdns/mosdns.sh adlist_update &> /dev/null & + update_list=0 + [ "$adblock" -eq 1 ] && [ "$ad_source" != "geosite.dat" ] && { + [ -s "/etc/mosdns/rule/adlist.txt" ] && [ -f "/etc/mosdns/rule/.ad_source" ] && url_adlist=$(cat /etc/mosdns/rule/.ad_source) || update_list=1 + [ "$ad_source" != "$url_adlist" ] && update_list=1 + } + [ "$update_list" -eq 1 ] && /usr/share/mosdns/mosdns.sh adlist_update &> /dev/null & } stop_service() { diff --git a/luci-app-mosdns/root/usr/share/mosdns/mosdns.sh b/luci-app-mosdns/root/usr/share/mosdns/mosdns.sh index e05d90d..25a6707 100755 --- a/luci-app-mosdns/root/usr/share/mosdns/mosdns.sh +++ b/luci-app-mosdns/root/usr/share/mosdns/mosdns.sh @@ -56,6 +56,7 @@ adlist_update() ( exit 1 else \cp "$AD_TMPDIR/adlist.txt" /etc/mosdns/rule/adlist.txt + echo "$ad_source" > /etc/mosdns/rule/.ad_source rm -rf "$AD_TMPDIR" fi )