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.

94 lines
1.9 KiB

  1. #!/bin/sh /etc/rc.common
  2. #
  3. START=30
  4. USE_PROCD=1
  5. EXTRA_COMMANDS="refresh status"
  6. EXTRA_HELP=" refresh Refresh ipsets without new list downloads
  7. status Print runtime information"
  8. ban_init="/etc/init.d/banip"
  9. ban_script="/usr/bin/banip.sh"
  10. ban_pidfile="/var/run/banip.pid"
  11. boot()
  12. {
  13. ban_boot="1"
  14. rc_procd start_service
  15. }
  16. start_service()
  17. {
  18. if [ "$("${ban_init}" enabled; printf "%u" ${?})" -eq 0 ]
  19. then
  20. if [ "${ban_boot}" = "1" ]
  21. then
  22. return 0
  23. fi
  24. local nice="$(uci_get banip extra ban_nice "0")"
  25. procd_open_instance "banip"
  26. procd_set_param command "${ban_script}" "${@}"
  27. procd_set_param pidfile "${ban_pidfile}"
  28. procd_set_param nice "${nice}"
  29. procd_set_param stdout 1
  30. procd_set_param stderr 1
  31. procd_close_instance
  32. fi
  33. }
  34. refresh()
  35. {
  36. [ -s "${ban_pidfile}" ] && return 1
  37. rc_procd start_service refresh
  38. }
  39. reload_service()
  40. {
  41. rc_procd start_service reload
  42. }
  43. stop_service()
  44. {
  45. rc_procd "${ban_script}" stop
  46. }
  47. status_service()
  48. {
  49. local key keylist value
  50. local rtfile="$(uci_get banip global ban_rtfile "/tmp/ban_runtime.json")"
  51. json_load_file "${rtfile}" >/dev/null 2>&1
  52. json_select data >/dev/null 2>&1
  53. if [ "${?}" -eq 0 ]
  54. then
  55. printf "%s\\n" "::: banIP runtime information"
  56. json_get_keys keylist
  57. for key in ${keylist}
  58. do
  59. json_get_var value "${key}"
  60. printf " + %-10s : %s\\n" "${key}" "${value}"
  61. done
  62. else
  63. printf "%s\\n" "::: no banIP runtime information available"
  64. fi
  65. }
  66. service_triggers()
  67. {
  68. local iface iface_list="$(uci_get banip global ban_iface)"
  69. local delay="$(uci_get banip extra ban_triggerdelay "2")"
  70. local type="$(uci_get banip extra ban_starttype "start")"
  71. PROCD_RELOAD_DELAY=$((${delay}*1000))
  72. if [ -n "${iface_list}" ]
  73. then
  74. for iface in ${iface_list}
  75. do
  76. procd_add_interface_trigger "interface.*.up" "${iface}" "${ban_init}" "${type}"
  77. done
  78. else
  79. procd_add_raw_trigger "interface.*.up" ${PROCD_RELOAD_DELAY} "${ban_init}" "${type}"
  80. fi
  81. procd_add_reload_trigger "banip"
  82. }