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.

129 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 [ $((adb_debug)) -eq 0 ]
  15. then
  16. exec 2>/dev/null
  17. fi
  18. if [ -r "${adb_pidfile}" ]
  19. then
  20. logger -s -t "adblock[${adb_pid}] error" "adblock service already running ($(cat ${adb_pidfile}))" 2>&1
  21. exit 255
  22. fi
  23. . "${adb_helper}"
  24. f_envload
  25. if [ "${adb_restricted}" = "1" ]
  26. then
  27. adb_uci="$(which true)"
  28. fi
  29. boot()
  30. {
  31. return 0
  32. }
  33. start()
  34. {
  35. if [ -t 1 ]
  36. then
  37. unset bg_parm
  38. fi
  39. eval "${adb_script}" ${bg_parm}
  40. return 0
  41. }
  42. restart()
  43. {
  44. stop
  45. start
  46. }
  47. reload()
  48. {
  49. reload="true"
  50. stop
  51. start
  52. }
  53. stop()
  54. {
  55. f_rmdns
  56. f_rmuhttpd
  57. config_foreach f_rmconfig source
  58. if [ -z "${reload}" ]
  59. then
  60. f_rmfirewall
  61. fi
  62. if [ -n "${rm_dns}" ] || [ -n "${rm_uhttpd}" ] || [ -n "${rm_fw}" ] || [ -n "$(${adb_uci} -q changes adblock)" ]
  63. then
  64. "${adb_uci}" -q commit adblock
  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. /etc/init.d/dnsmasq restart
  90. "${adb_uci}" -q set "adblock.global.adb_dnstoggle=${pos}"
  91. "${adb_uci}" -q commit "adblock"
  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. }