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.

110 lines
2.2 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. if [ -s "${ban_pidfile}" ] && \
  12. [ "${action}" != "help" ] && [ "${action}" != "status" ] && [ "${action}" != "boot" ]
  13. then
  14. exit 1
  15. fi
  16. boot()
  17. {
  18. [ -s "${ban_pidfile}" ] && > "${ban_pidfile}"
  19. rc_procd start_service
  20. }
  21. start_service()
  22. {
  23. if [ "$("${ban_init}" enabled; printf "%u" ${?})" -eq 0 ]
  24. then
  25. if [ "${action}" = "boot" ]
  26. then
  27. return 0
  28. fi
  29. procd_open_instance "banip"
  30. procd_set_param command "${ban_script}" "${@}"
  31. procd_set_param pidfile "${ban_pidfile}"
  32. procd_set_param nice "$(uci_get banip extra ban_nice "0")"
  33. procd_set_param stdout 1
  34. procd_set_param stderr 1
  35. procd_close_instance
  36. fi
  37. }
  38. refresh()
  39. {
  40. rc_procd start_service refresh
  41. }
  42. reload_service()
  43. {
  44. rc_procd start_service reload
  45. }
  46. stop_service()
  47. {
  48. rc_procd "${ban_script}" stop
  49. }
  50. restart()
  51. {
  52. rc_procd start_service restart
  53. }
  54. status_service()
  55. {
  56. local key keylist value
  57. local rtfile="$(uci_get banip global ban_rtfile "/tmp/ban_runtime.json")"
  58. json_load_file "${rtfile}" >/dev/null 2>&1
  59. json_select data >/dev/null 2>&1
  60. if [ "${?}" -eq 0 ]
  61. then
  62. printf "%s\\n" "::: banIP runtime information"
  63. json_get_keys keylist
  64. for key in ${keylist}
  65. do
  66. json_get_var value "${key}"
  67. printf " + %-10s : %s\\n" "${key}" "${value}"
  68. done
  69. else
  70. printf "%s\\n" "::: no banIP runtime information available"
  71. fi
  72. }
  73. service_triggers()
  74. {
  75. local trigger trigger_list="$(uci_get banip global ban_trigger)"
  76. local delay="$(uci_get banip extra ban_triggerdelay "2")"
  77. local type="$(uci_get banip extra ban_starttype "start")"
  78. PROCD_RELOAD_DELAY=$((${delay}*1000))
  79. if [ -z "${trigger_list}" ] && [ -r "/lib/functions/network.sh" ]
  80. then
  81. . "/lib/functions/network.sh"
  82. network_find_wan trigger_list
  83. fi
  84. if [ -n "${trigger_list}" ]
  85. then
  86. for trigger in ${trigger_list}
  87. do
  88. procd_add_interface_trigger "interface.*.up" "${trigger}" "${ban_init}" "${type}"
  89. done
  90. else
  91. procd_add_raw_trigger "interface.*.up" ${PROCD_RELOAD_DELAY} "${ban_init}" "${type}"
  92. fi
  93. procd_add_reload_trigger "banip"
  94. }