You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

128 lines
2.6 KiB

  1. #!/bin/sh /etc/rc.common
  2. #
  3. START=99
  4. EXTRA_COMMANDS="toggle stats cfgup"
  5. EXTRA_HELP=" toggle Toggle adblock 'on' or 'off'
  6. stats Update adblock statistics
  7. cfgup Update adblock configuration file"
  8. adb_debug=0
  9. adb_pid="${$}"
  10. adb_script="/usr/bin/adblock-update.sh"
  11. adb_helper="/usr/bin/adblock-helper.sh"
  12. adb_pidfile="/var/run/adblock.pid"
  13. bg_parm="&"
  14. if [ -t 1 ]
  15. then
  16. unset bg_parm
  17. fi
  18. if [ $((adb_debug)) -eq 0 ]
  19. then
  20. exec 2>/dev/null
  21. fi
  22. if [ -r "${adb_pidfile}" ]
  23. then
  24. logger -s -t "adblock[${adb_pid}] error" "adblock service already running ($(cat ${adb_pidfile}))" 2>&1
  25. exit 255
  26. fi
  27. . "${adb_helper}"
  28. f_envload
  29. boot()
  30. {
  31. return 0
  32. }
  33. start()
  34. {
  35. eval "${adb_script}" ${bg_parm}
  36. return 0
  37. }
  38. restart()
  39. {
  40. stop
  41. start
  42. }
  43. reload()
  44. {
  45. reload="true"
  46. stop
  47. start
  48. }
  49. stop()
  50. {
  51. f_rmdns
  52. f_rmuhttpd
  53. adb_uci="$(which uci)"
  54. config_foreach f_rmconfig source
  55. if [ -n "$(${adb_uci} -q changes adblock)" ]
  56. then
  57. "${adb_uci}" -q commit adblock
  58. fi
  59. if [ -z "${reload}" ]
  60. then
  61. f_rmfirewall
  62. fi
  63. if [ -n "${rm_dns}" ] || [ -n "${rm_uhttpd}" ] || [ -n "${rm_fw}" ] || [ -n "${rm_cfg}" ]
  64. then
  65. f_log "all adblock related services stopped"
  66. fi
  67. return 0
  68. }
  69. toggle()
  70. {
  71. if [ -d "${adb_dnshidedir}" ]
  72. then
  73. list_dns="$(find "${adb_dnsdir}" -maxdepth 1 -type f -name "${adb_dnsprefix}*" -print)"
  74. list_dnshide="$(find "${adb_dnshidedir}" -maxdepth 1 -type f -name "${adb_dnsprefix}*" -print)"
  75. if [ -n "${list_dns}" ]
  76. then
  77. source="${adb_dnsdir}/${adb_dnsprefix}"
  78. target="${adb_dnshidedir}"
  79. pos="off"
  80. elif [ -n "${list_dnshide}" ]
  81. then
  82. source="${adb_dnshidedir}/${adb_dnsprefix}"
  83. target="${adb_dnsdir}"
  84. pos="on"
  85. fi
  86. if [ -n "${list_dns}" ] || [ -n "${list_dnshide}" ]
  87. then
  88. mv -f "${source}"* "${target}"
  89. "${adb_uci}" -q set "adblock.global.adb_dnstoggle=${pos}"
  90. "${adb_uci}" -q commit "adblock"
  91. /etc/init.d/dnsmasq restart
  92. f_log "adblock toggle switched '${pos}'"
  93. fi
  94. fi
  95. return 0
  96. }
  97. stats()
  98. {
  99. f_statistics
  100. "${adb_uci}" -q commit "adblock"
  101. return 0
  102. }
  103. cfgup()
  104. {
  105. stop
  106. cp -pf "/etc/adblock/adblock.conf.default" "/etc/config/adblock"
  107. rc=$?
  108. if [ $((rc)) -eq 0 ]
  109. then
  110. f_log "default adblock configuration applied, please check the settings in '/etc/config/adblock'"
  111. else
  112. f_log "default adblock configuration not found, please re-install the package via 'opkg install adblock --force-maintainer'"
  113. fi
  114. return 0
  115. }