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.

89 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. exec 2>/dev/null
  10. adb_script="/usr/bin/adblock.sh"
  11. adb_iface="$(uci -q get adblock.global.adb_iface)"
  12. boot()
  13. {
  14. local wanif4 wanif6
  15. ubus -t 30 wait_for network.interface
  16. if [ ${?} -eq 0 ]
  17. then
  18. . "/lib/functions/network.sh"
  19. network_find_wan wanif4
  20. network_find_wan6 wanif6
  21. if [ -n "${wanif4}" ] || [ -n "${wanif6}" ]
  22. then
  23. rc_procd start_service
  24. else
  25. rc_procd service_triggers
  26. fi
  27. fi
  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. suspend()
  51. {
  52. rc_procd start_service suspend
  53. }
  54. resume()
  55. {
  56. rc_procd start_service resume
  57. }
  58. query()
  59. {
  60. export adb_procd="true"
  61. rc_procd "${adb_script}" query "${1}"
  62. }
  63. service_triggers()
  64. {
  65. local iface
  66. procd_add_config_trigger "config.change" "adblock" /etc/init.d/adblock start
  67. if [ -z "${adb_iface}" ]
  68. then
  69. procd_add_raw_trigger "interface.*.up" 1000 /etc/init.d/adblock start
  70. else
  71. for iface in ${adb_iface}
  72. do
  73. procd_add_interface_trigger "interface.*.up" "${iface}" /etc/init.d/adblock start
  74. done
  75. fi
  76. }