|
|
- #!/bin/sh /etc/rc.common
- #
-
- START=99
- EXTRA_COMMANDS="toggle stats cfgup"
- EXTRA_HELP=" toggle Toggle adblock 'on' or 'off'
- stats Update adblock statistics
- cfgup Update adblock configuration file"
-
- adb_debug=0
- adb_pid="${$}"
- adb_script="/usr/bin/adblock-update.sh"
- adb_helper="/usr/bin/adblock-helper.sh"
- adb_pidfile="/var/run/adblock.pid"
- bg_parm="&"
- if [ -t 1 ]
- then
- unset bg_parm
- fi
-
- if [ $((adb_debug)) -eq 0 ]
- then
- exec 2>/dev/null
- fi
-
- if [ -r "${adb_pidfile}" ]
- then
- logger -s -t "adblock[${adb_pid}] error" "adblock service already running ($(cat ${adb_pidfile}))" 2>&1
- exit 255
- fi
-
- . "${adb_helper}"
- f_envload
-
- boot()
- {
- return 0
- }
-
- start()
- {
- eval "${adb_script}" ${bg_parm}
- return 0
- }
-
- restart()
- {
- stop
- start
- }
-
- reload()
- {
- reload="true"
- stop
- start
- }
-
- stop()
- {
- f_rmdns
- f_rmuhttpd
- adb_uci="$(which uci)"
- config_foreach f_rmconfig source
- if [ -n "$(${adb_uci} -q changes adblock)" ]
- then
- "${adb_uci}" -q commit adblock
- fi
- if [ -z "${reload}" ]
- then
- f_rmfirewall
- fi
- if [ -n "${rm_dns}" ] || [ -n "${rm_uhttpd}" ] || [ -n "${rm_fw}" ] || [ -n "${rm_cfg}" ]
- then
- f_log "all adblock related services stopped"
- fi
- return 0
- }
-
- toggle()
- {
- if [ -d "${adb_dnshidedir}" ]
- then
- list_dns="$(find "${adb_dnsdir}" -maxdepth 1 -type f -name "${adb_dnsprefix}*" -print)"
- list_dnshide="$(find "${adb_dnshidedir}" -maxdepth 1 -type f -name "${adb_dnsprefix}*" -print)"
- if [ -n "${list_dns}" ]
- then
- source="${adb_dnsdir}/${adb_dnsprefix}"
- target="${adb_dnshidedir}"
- pos="off"
- elif [ -n "${list_dnshide}" ]
- then
- source="${adb_dnshidedir}/${adb_dnsprefix}"
- target="${adb_dnsdir}"
- pos="on"
- fi
- if [ -n "${list_dns}" ] || [ -n "${list_dnshide}" ]
- then
- mv -f "${source}"* "${target}"
- "${adb_uci}" -q set "adblock.global.adb_dnstoggle=${pos}"
- "${adb_uci}" -q commit "adblock"
- /etc/init.d/dnsmasq restart
- f_log "adblock toggle switched '${pos}'"
- fi
- fi
- return 0
- }
-
- stats()
- {
- f_statistics
- "${adb_uci}" -q commit "adblock"
- return 0
- }
-
- cfgup()
- {
- stop
- cp -pf "/etc/adblock/adblock.conf.default" "/etc/config/adblock"
- rc=$?
- if [ $((rc)) -eq 0 ]
- then
- f_log "default adblock configuration applied, please check the settings in '/etc/config/adblock'"
- else
- f_log "default adblock configuration not found, please re-install the package via 'opkg install adblock --force-maintainer'"
- fi
- return 0
- }
|