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.

108 lines
2.2 KiB

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