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.

119 lines
2.4 KiB

  1. #!/bin/sh /etc/rc.common
  2. #
  3. START=30
  4. USE_PROCD=1
  5. EXTRA_COMMANDS="suspend resume query report status"
  6. EXTRA_HELP=" suspend Suspend adblock processing
  7. resume Resume adblock processing
  8. query <DOMAIN> Query active blocklists for specific domains
  9. report <SEARCH> Print dns query statistics with an optional search parameter
  10. status Print runtime information"
  11. adb_init="/etc/init.d/adblock"
  12. adb_script="/usr/bin/adblock.sh"
  13. adb_pidfile="/var/run/adblock.pid"
  14. boot()
  15. {
  16. adb_boot=1
  17. rc_procd start_service
  18. }
  19. start_service()
  20. {
  21. if [ $("${adb_init}" enabled; printf "%u" ${?}) -eq 0 ]
  22. then
  23. if [ -n "${adb_boot}" ]
  24. then
  25. local trigger="$(uci_get adblock global adb_trigger)"
  26. if [ "${trigger}" != "timed" ]
  27. then
  28. return 0
  29. fi
  30. fi
  31. local nice="$(uci_get adblock extra adb_nice)"
  32. procd_open_instance "adblock"
  33. procd_set_param command "${adb_script}" "${@}"
  34. procd_set_param pidfile "${adb_pidfile}"
  35. procd_set_param nice ${nice:-0}
  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. rc_procd "${adb_script}" stop
  48. rc_procd start_service
  49. }
  50. restart()
  51. {
  52. rc_procd start_service restart
  53. }
  54. suspend()
  55. {
  56. [ -s "${adb_pidfile}" ] && return 1
  57. rc_procd "${adb_script}" suspend
  58. }
  59. resume()
  60. {
  61. [ -s "${adb_pidfile}" ] && return 1
  62. rc_procd "${adb_script}" resume
  63. }
  64. query()
  65. {
  66. [ -s "${adb_pidfile}" ] && return 1
  67. rc_procd "${adb_script}" query "${1}"
  68. }
  69. report()
  70. {
  71. [ -s "${adb_pidfile}" ] && return 1
  72. rc_procd "${adb_script}" report "${1:-"+"}" "${2:-"50"}" "${3:-"false"}" "${4:-"true"}"
  73. }
  74. status()
  75. {
  76. local key keylist value rtfile="$(uci_get adblock extra adb_rtfile)"
  77. rtfile="${rtfile:-"/tmp/adb_runtime.json"}"
  78. if [ -s "${rtfile}" ]
  79. then
  80. printf "%s\n" "::: adblock runtime information"
  81. json_load_file "${rtfile}"
  82. json_select data
  83. json_get_keys keylist
  84. for key in ${keylist}
  85. do
  86. json_get_var value "${key}"
  87. printf " + %-15s : %s\n" "${key}" "${value}"
  88. done
  89. else
  90. printf "%s\n" "::: no adblock runtime information available"
  91. fi
  92. }
  93. service_triggers()
  94. {
  95. local trigger="$(uci_get adblock global adb_trigger)"
  96. local delay="$(uci_get adblock extra adb_triggerdelay)"
  97. if [ "${trigger}" != "none" ] && [ "${trigger}" != "timed" ]
  98. then
  99. PROCD_RELOAD_DELAY=$((${delay:-2} * 1000))
  100. procd_add_interface_trigger "interface.*.up" "${trigger}" "${adb_init}" start
  101. fi
  102. procd_add_reload_trigger "adblock"
  103. }