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.

134 lines
2.8 KiB

  1. #!/bin/sh /etc/rc.common
  2. #
  3. START=30
  4. USE_PROCD=1
  5. EXTRA_COMMANDS="suspend resume query report"
  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. adb_init="/etc/init.d/adblock"
  11. adb_script="/usr/bin/adblock.sh"
  12. adb_pidfile="/var/run/adblock.pid"
  13. if [ -s "${adb_pidfile}" ] && { [ "${action}" = "start" ] || [ "${action}" = "stop" ] || \
  14. [ "${action}" = "restart" ] || [ "${action}" = "reload" ] || [ "${action}" = "report" ] || \
  15. [ "${action}" = "suspend" ] || [ "${action}" = "resume" ] || [ "${action}" = "query" ]; }
  16. then
  17. exit 0
  18. fi
  19. boot()
  20. {
  21. [ -s "${adb_pidfile}" ] && > "${adb_pidfile}"
  22. rc_procd start_service
  23. }
  24. start_service()
  25. {
  26. if [ "$("${adb_init}" enabled; printf "%u" ${?})" -eq 0 ]
  27. then
  28. if [ "${action}" = "boot" ]
  29. then
  30. if [ "$(uci_get adblock global adb_trigger)" != "timed" ]
  31. then
  32. return 0
  33. fi
  34. fi
  35. procd_open_instance "adblock"
  36. procd_set_param command "${adb_script}" "${@}"
  37. procd_set_param pidfile "${adb_pidfile}"
  38. procd_set_param nice "$(uci_get adblock extra adb_nice "0")"
  39. procd_set_param stdout 1
  40. procd_set_param stderr 1
  41. procd_close_instance
  42. fi
  43. }
  44. reload_service()
  45. {
  46. rc_procd start_service reload
  47. }
  48. stop_service()
  49. {
  50. rc_procd "${adb_script}" stop
  51. }
  52. restart()
  53. {
  54. rc_procd start_service restart
  55. }
  56. suspend()
  57. {
  58. rc_procd start_service suspend
  59. }
  60. resume()
  61. {
  62. rc_procd start_service resume
  63. }
  64. query()
  65. {
  66. rc_procd "${adb_script}" query "${1}"
  67. }
  68. report()
  69. {
  70. rc_procd "${adb_script}" report "${1:-"+"}" "${2:-"50"}" "${3:-"false"}" "${4:-"true"}"
  71. }
  72. status_service()
  73. {
  74. local key keylist value
  75. local rtfile="$(uci_get adblock extra adb_rtfile "/tmp/adb_runtime.json")"
  76. if [ -s "${rtfile}" ]
  77. then
  78. printf "%s\\n" "::: adblock runtime information"
  79. json_load_file "${rtfile}"
  80. json_select data
  81. json_get_keys keylist
  82. for key in ${keylist}
  83. do
  84. json_get_var value "${key}"
  85. printf " + %-15s : %s\\n" "${key}" "${value}"
  86. done
  87. else
  88. printf "%s\\n" "::: no adblock runtime information available"
  89. fi
  90. }
  91. service_triggers()
  92. {
  93. local trigger trigger_list="$(uci_get adblock global adb_trigger)"
  94. local delay="$(uci_get adblock extra adb_triggerdelay "2")"
  95. local type="$(uci_get adblock extra adb_starttype "start")"
  96. PROCD_RELOAD_DELAY=$((delay*1000))
  97. if [ -z "${trigger_list}" ] && [ -r "/lib/functions/network.sh" ]
  98. then
  99. . "/lib/functions/network.sh"
  100. network_find_wan trigger_list
  101. fi
  102. if [ -n "${trigger_list}" ]
  103. then
  104. for trigger in ${trigger_list}
  105. do
  106. if [ "${trigger}" != "none" ] && [ "${trigger}" != "timed" ]
  107. then
  108. procd_add_interface_trigger "interface.*.up" "${trigger}" "${adb_init}" "${type}"
  109. fi
  110. done
  111. else
  112. procd_add_raw_trigger "interface.*.up" ${PROCD_RELOAD_DELAY} "${adb_init}" "${type}"
  113. fi
  114. procd_add_reload_trigger "adblock"
  115. }