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.

95 lines
1.8 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
  13. . "/lib/functions/network.sh"
  14. while [ ${cnt} -le 30 ]
  15. do
  16. network_find_wan wanif4
  17. network_find_wan6 wanif6
  18. if [ -n "${wanif4}" ] || [ -n "${wanif6}" ] || [ ${cnt} -eq 30 ]
  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 env adb_procd="true"
  35. procd_set_param command "${adb_script}" "${@}"
  36. procd_set_param stdout 1
  37. procd_set_param stderr 1
  38. procd_close_instance
  39. fi
  40. }
  41. reload_service()
  42. {
  43. rc_procd start_service reload
  44. }
  45. stop_service()
  46. {
  47. export adb_procd="true"
  48. rc_procd "${adb_script}" stop
  49. }
  50. restart()
  51. {
  52. rc_procd start_service restart
  53. }
  54. suspend()
  55. {
  56. rc_procd start_service suspend
  57. }
  58. resume()
  59. {
  60. rc_procd start_service resume
  61. }
  62. query()
  63. {
  64. export adb_procd="true"
  65. rc_procd "${adb_script}" query "${1}"
  66. }
  67. service_triggers()
  68. {
  69. local iface="$(uci -q get adblock.global.adb_iface)"
  70. if [ -z "${iface}" ]
  71. then
  72. procd_add_raw_trigger "interface.*.up" 1000 /etc/init.d/adblock start
  73. else
  74. for name in ${iface}
  75. do
  76. procd_add_interface_trigger "interface.*.up" "${name}" /etc/init.d/adblock start
  77. done
  78. fi
  79. procd_add_config_trigger "config.change" "adblock" /etc/init.d/adblock start
  80. }