adblock.init 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #!/bin/sh /etc/rc.common
  2. #
  3. START=50
  4. USE_PROCD=1
  5. EXTRA_COMMANDS="suspend resume query status"
  6. EXTRA_HELP=" suspend Suspend adblock processing
  7. resume Resume adblock processing
  8. query <DOMAIN> Query active blocklists for specific domains
  9. status Print runtime information"
  10. adb_init="/etc/init.d/adblock"
  11. adb_script="/usr/bin/adblock.sh"
  12. boot()
  13. {
  14. adb_boot=1
  15. ubus -t 30 wait_for network.interface 2>/dev/null
  16. rc_procd start_service
  17. }
  18. start_service()
  19. {
  20. if [ $("${adb_init}" enabled; printf ${?}) -eq 0 ]
  21. then
  22. if [ -n "${adb_boot}" ]
  23. then
  24. return 0
  25. fi
  26. procd_open_instance "adblock"
  27. procd_set_param command "${adb_script}" "${@}"
  28. procd_set_param stdout 1
  29. procd_set_param stderr 1
  30. procd_close_instance
  31. fi
  32. }
  33. stop_service()
  34. {
  35. rc_procd "${adb_script}" stop
  36. rc_procd start_service
  37. }
  38. restart()
  39. {
  40. rc_procd start_service restart
  41. }
  42. suspend()
  43. {
  44. rc_procd "${adb_script}" suspend
  45. }
  46. resume()
  47. {
  48. rc_procd "${adb_script}" resume
  49. }
  50. query()
  51. {
  52. rc_procd "${adb_script}" query "${1}"
  53. }
  54. status()
  55. {
  56. rc_procd "${adb_script}" status
  57. }
  58. service_triggers()
  59. {
  60. local iface="$(uci -q get adblock.global.adb_iface)"
  61. local delay="$(uci -q get adblock.global.adb_triggerdelay)"
  62. PROCD_RELOAD_DELAY=$((${delay:=2} * 1000))
  63. for name in ${iface}
  64. do
  65. procd_add_interface_trigger "interface.*.up" "${name}" "${adb_init}" start
  66. done
  67. PROCD_RELOAD_DELAY=1000
  68. procd_add_config_trigger "config.change" "adblock" "${adb_init}" start
  69. }