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.

135 lines
2.7 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. if [ -s "${adb_pidfile}" ] && [ "${action}" != "help" ] && [ "${action}" != "status" ]
  15. then
  16. exit 1
  17. fi
  18. boot()
  19. {
  20. adb_boot=1
  21. rc_procd start_service
  22. }
  23. start_service()
  24. {
  25. if [ "$("${adb_init}" enabled; printf "%u" ${?})" -eq 0 ]
  26. then
  27. if [ -n "${adb_boot}" ]
  28. then
  29. local trigger="$(uci_get adblock global adb_trigger)"
  30. if [ "${trigger}" != "timed" ]
  31. then
  32. return 0
  33. fi
  34. fi
  35. local nice="$(uci_get adblock extra adb_nice "0")"
  36. procd_open_instance "adblock"
  37. procd_set_param command "${adb_script}" "${@}"
  38. procd_set_param pidfile "${adb_pidfile}"
  39. procd_set_param nice "${nice}"
  40. procd_set_param stdout 1
  41. procd_set_param stderr 1
  42. procd_close_instance
  43. fi
  44. }
  45. reload_service()
  46. {
  47. rc_procd start_service reload
  48. }
  49. stop_service()
  50. {
  51. rc_procd "${adb_script}" stop
  52. }
  53. restart()
  54. {
  55. rc_procd start_service restart
  56. }
  57. suspend()
  58. {
  59. rc_procd start_service suspend
  60. }
  61. resume()
  62. {
  63. rc_procd start_service resume
  64. }
  65. query()
  66. {
  67. rc_procd "${adb_script}" query "${1}"
  68. }
  69. report()
  70. {
  71. rc_procd "${adb_script}" report "${1:-"+"}" "${2:-"50"}" "${3:-"false"}" "${4:-"true"}"
  72. }
  73. status_service()
  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 trigger_list="$(uci_get adblock global adb_trigger)"
  95. local delay="$(uci_get adblock extra adb_triggerdelay "2")"
  96. local type="$(uci_get adblock extra adb_starttype "start")"
  97. PROCD_RELOAD_DELAY=$((delay*1000))
  98. if [ -z "${trigger_list}" ] && [ -r "/lib/functions/network.sh" ]
  99. then
  100. . "/lib/functions/network.sh"
  101. network_find_wan trigger_list
  102. fi
  103. if [ -n "${trigger_list}" ]
  104. then
  105. for trigger in ${trigger_list}
  106. do
  107. if [ "${trigger}" != "none" ] && [ "${trigger}" != "timed" ]
  108. then
  109. procd_add_interface_trigger "interface.*.up" "${trigger}" "${adb_init}" "${type}"
  110. fi
  111. done
  112. else
  113. procd_add_raw_trigger "interface.*.up" ${PROCD_RELOAD_DELAY} "${adb_init}" "${type}"
  114. fi
  115. procd_add_reload_trigger "adblock"
  116. }