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.

110 lines
2.4 KiB

  1. #!/bin/sh /etc/rc.common
  2. #
  3. START=30
  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. adb_pidfile="/var/run/adblock.pid"
  13. boot()
  14. {
  15. adb_boot=1
  16. rc_procd start_service
  17. }
  18. start_service()
  19. {
  20. if [ $("${adb_init}" enabled; printf "%u" ${?}) -eq 0 ]
  21. then
  22. if [ -n "${adb_boot}" ]
  23. then
  24. local trigger="$(uci_get adblock global adb_trigger)"
  25. if [ "${trigger}" != "timed" ]
  26. then
  27. return 0
  28. fi
  29. fi
  30. procd_open_instance "adblock"
  31. procd_set_param command "${adb_script}" "${@}"
  32. procd_set_param pidfile "${adb_pidfile}"
  33. procd_set_param stdout 1
  34. procd_set_param stderr 1
  35. procd_close_instance
  36. fi
  37. }
  38. reload_service()
  39. {
  40. rc_procd start_service reload
  41. }
  42. stop_service()
  43. {
  44. rc_procd "${adb_script}" stop
  45. rc_procd start_service
  46. }
  47. restart()
  48. {
  49. rc_procd start_service restart
  50. }
  51. suspend()
  52. {
  53. [ -s "${adb_pidfile}" ] && return 1
  54. rc_procd "${adb_script}" suspend
  55. }
  56. resume()
  57. {
  58. [ -s "${adb_pidfile}" ] && return 1
  59. rc_procd "${adb_script}" resume
  60. }
  61. query()
  62. {
  63. [ -s "${adb_pidfile}" ] && return 1
  64. rc_procd "${adb_script}" query "${1}"
  65. }
  66. status()
  67. {
  68. local key keylist value rtfile="$(uci_get adblock extra adb_rtfile)"
  69. rtfile="${rtfile:-"/tmp/adb_runtime.json"}"
  70. if [ -s "${rtfile}" ]
  71. then
  72. printf "%s\n" "::: adblock runtime information"
  73. json_load "$(cat "${rtfile}" 2>/dev/null)"
  74. json_select data
  75. json_get_keys keylist
  76. for key in ${keylist}
  77. do
  78. json_get_var value "${key}"
  79. printf " + %-15s : %s\n" "${key}" "${value}"
  80. done
  81. else
  82. printf "%s\n" "::: no adblock runtime information available"
  83. fi
  84. }
  85. service_triggers()
  86. {
  87. local trigger="$(uci_get adblock global adb_trigger)"
  88. local delay="$(uci_get adblock extra adb_triggerdelay)"
  89. if [ "${trigger}" != "none" ] && [ "${trigger}" != "timed" ]
  90. then
  91. PROCD_RELOAD_DELAY=$((${delay:-2} * 1000))
  92. procd_add_interface_trigger "interface.*.up" "${trigger}" "${adb_init}" start
  93. fi
  94. procd_add_reload_trigger "adblock"
  95. }