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.

109 lines
2.2 KiB

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