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.

91 lines
1.7 KiB

  1. #!/bin/sh /etc/rc.common
  2. #
  3. START=90
  4. USE_PROCD=1
  5. EXTRA_COMMANDS="suspend resume query"
  6. EXTRA_HELP=" suspend Suspend adblock processing
  7. resume Resume adblock processing
  8. query <DOMAIN> Query active blocklists for specific domain"
  9. adb_script="/usr/bin/adblock.sh"
  10. boot()
  11. {
  12. local wanif4 wanif6 cnt=0 max_cnt=30
  13. . "/lib/functions/network.sh"
  14. while [ ${cnt} -le ${max_cnt} ]
  15. do
  16. network_find_wan wanif4
  17. network_find_wan6 wanif6
  18. if [ -n "${wanif4}" ] || [ -n "${wanif6}" ] || [ ${cnt} -eq ${max_cnt} ]
  19. then
  20. rc_procd start_service
  21. return 0
  22. else
  23. sleep 1
  24. cnt=$((cnt+1))
  25. network_flush_cache
  26. fi
  27. done
  28. }
  29. start_service()
  30. {
  31. if [ $(/etc/init.d/adblock enabled; printf ${?}) -eq 0 ]
  32. then
  33. procd_open_instance "adblock"
  34. procd_set_param command "${adb_script}" "${@}"
  35. procd_set_param stdout 1
  36. procd_set_param stderr 1
  37. procd_close_instance
  38. fi
  39. }
  40. reload_service()
  41. {
  42. rc_procd start_service reload
  43. }
  44. stop_service()
  45. {
  46. rc_procd "${adb_script}" stop
  47. }
  48. restart()
  49. {
  50. rc_procd start_service restart
  51. }
  52. suspend()
  53. {
  54. rc_procd start_service suspend
  55. }
  56. resume()
  57. {
  58. rc_procd start_service resume
  59. }
  60. query()
  61. {
  62. rc_procd "${adb_script}" query "${1}"
  63. }
  64. service_triggers()
  65. {
  66. local iface="$(uci -q get adblock.global.adb_iface)"
  67. if [ -z "${iface}" ]
  68. then
  69. procd_add_raw_trigger "interface.*.up" 1000 /etc/init.d/adblock start
  70. else
  71. for name in ${iface}
  72. do
  73. procd_add_interface_trigger "interface.*.up" "${name}" /etc/init.d/adblock start
  74. done
  75. fi
  76. procd_add_config_trigger "config.change" "adblock" /etc/init.d/adblock start
  77. }