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.

112 lines
2.2 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. local nice="$(uci_get adblock extra adb_nice)"
  31. procd_open_instance "adblock"
  32. procd_set_param command "${adb_script}" "${@}"
  33. procd_set_param pidfile "${adb_pidfile}"
  34. procd_set_param nice ${nice:-0}
  35. procd_set_param stdout 1
  36. procd_set_param stderr 1
  37. procd_close_instance
  38. fi
  39. }
  40. reload_service()
  41. {
  42. rc_procd start_service reload
  43. }
  44. stop_service()
  45. {
  46. rc_procd "${adb_script}" stop
  47. rc_procd start_service
  48. }
  49. restart()
  50. {
  51. rc_procd start_service restart
  52. }
  53. suspend()
  54. {
  55. [ -s "${adb_pidfile}" ] && return 1
  56. rc_procd "${adb_script}" suspend
  57. }
  58. resume()
  59. {
  60. [ -s "${adb_pidfile}" ] && return 1
  61. rc_procd "${adb_script}" resume
  62. }
  63. query()
  64. {
  65. [ -s "${adb_pidfile}" ] && return 1
  66. rc_procd "${adb_script}" query "${1}"
  67. }
  68. status()
  69. {
  70. local key keylist value rtfile="$(uci_get adblock extra adb_rtfile)"
  71. rtfile="${rtfile:-"/tmp/adb_runtime.json"}"
  72. if [ -s "${rtfile}" ]
  73. then
  74. printf "%s\n" "::: adblock runtime information"
  75. json_load_file "${rtfile}"
  76. json_select data
  77. json_get_keys keylist
  78. for key in ${keylist}
  79. do
  80. json_get_var value "${key}"
  81. printf " + %-15s : %s\n" "${key}" "${value}"
  82. done
  83. else
  84. printf "%s\n" "::: no adblock runtime information available"
  85. fi
  86. }
  87. service_triggers()
  88. {
  89. local trigger="$(uci_get adblock global adb_trigger)"
  90. local delay="$(uci_get adblock extra adb_triggerdelay)"
  91. if [ "${trigger}" != "none" ] && [ "${trigger}" != "timed" ]
  92. then
  93. PROCD_RELOAD_DELAY=$((${delay:-2} * 1000))
  94. procd_add_interface_trigger "interface.*.up" "${trigger}" "${adb_init}" start
  95. fi
  96. procd_add_reload_trigger "adblock"
  97. }