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.

88 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
  13. ubus -t 30 wait_for network.interface
  14. if [ ${?} -eq 0 ]
  15. then
  16. . "/lib/functions/network.sh"
  17. network_find_wan wanif4
  18. network_find_wan6 wanif6
  19. if [ -n "${wanif4}" ] || [ -n "${wanif6}" ]
  20. then
  21. rc_procd start_service
  22. else
  23. rc_procd service_triggers
  24. fi
  25. fi
  26. }
  27. start_service()
  28. {
  29. if [ $(/etc/init.d/adblock enabled; printf ${?}) -eq 0 ]
  30. then
  31. procd_open_instance "adblock"
  32. procd_set_param env adb_procd="true"
  33. procd_set_param command "${adb_script}" "${@}"
  34. procd_set_param stdout 1
  35. procd_set_param stderr 1
  36. procd_close_instance
  37. fi
  38. }
  39. reload_service()
  40. {
  41. rc_procd start_service reload
  42. }
  43. stop_service()
  44. {
  45. export adb_procd="true"
  46. rc_procd "${adb_script}" stop
  47. }
  48. suspend()
  49. {
  50. rc_procd start_service suspend
  51. }
  52. resume()
  53. {
  54. rc_procd start_service resume
  55. }
  56. query()
  57. {
  58. export adb_procd="true"
  59. rc_procd "${adb_script}" query "${1}"
  60. }
  61. service_triggers()
  62. {
  63. local iface="$(uci -q get adblock.global.adb_iface)"
  64. if [ -z "${iface}" ]
  65. then
  66. procd_add_raw_trigger "interface.*.up" 1000 /etc/init.d/adblock start
  67. else
  68. for name in ${iface}
  69. do
  70. procd_add_interface_trigger "interface.*.up" "${name}" /etc/init.d/adblock start
  71. done
  72. fi
  73. procd_add_config_trigger "config.change" "adblock" /etc/init.d/adblock start
  74. }