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.

121 lines
2.5 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 "0")"
  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}"
  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. }
  49. restart()
  50. {
  51. rc_procd start_service restart
  52. }
  53. suspend()
  54. {
  55. [ -s "${adb_pidfile}" ] && return 1
  56. rc_procd start_service suspend
  57. }
  58. resume()
  59. {
  60. [ -s "${adb_pidfile}" ] && return 1
  61. rc_procd start_service resume
  62. }
  63. query()
  64. {
  65. [ -s "${adb_pidfile}" ] && return 1
  66. rc_procd "${adb_script}" query "${1}"
  67. }
  68. report()
  69. {
  70. [ -s "${adb_pidfile}" ] && return 1
  71. rc_procd "${adb_script}" report "${1:-"+"}" "${2:-"50"}" "${3:-"false"}" "${4:-"true"}"
  72. }
  73. status()
  74. {
  75. local key keylist value
  76. local rtfile="$(uci_get adblock extra adb_rtfile "/tmp/adb_runtime.json")"
  77. if [ -s "${rtfile}" ]
  78. then
  79. printf "%s\\n" "::: adblock runtime information"
  80. json_load_file "${rtfile}"
  81. json_select data
  82. json_get_keys keylist
  83. for key in ${keylist}
  84. do
  85. json_get_var value "${key}"
  86. printf " + %-15s : %s\\n" "${key}" "${value}"
  87. done
  88. else
  89. printf "%s\\n" "::: no adblock runtime information available"
  90. fi
  91. }
  92. service_triggers()
  93. {
  94. local trigger="$(uci_get adblock global adb_trigger)"
  95. local delay="$(uci_get adblock extra adb_triggerdelay "2")"
  96. PROCD_RELOAD_DELAY=$((delay*1000))
  97. if [ -n "${trigger}" ] && [ "${trigger}" != "none" ] && [ "${trigger}" != "timed" ]
  98. then
  99. procd_add_interface_trigger "interface.*.up" "${trigger}" "${adb_init}" start
  100. elif [ -z "${trigger}" ]
  101. then
  102. procd_add_raw_trigger "interface.*.up" ${PROCD_RELOAD_DELAY} "${adb_init}" start
  103. fi
  104. procd_add_reload_trigger "adblock"
  105. }