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.

88 lines
1.7 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 only (no new download!)
  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)"
  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:-0}
  29. procd_set_param stdout 1
  30. procd_set_param stderr 1
  31. procd_close_instance
  32. fi
  33. }
  34. refresh()
  35. {
  36. rc_procd start_service refresh
  37. }
  38. reload_service()
  39. {
  40. rc_procd start_service reload
  41. }
  42. stop_service()
  43. {
  44. rc_procd "${ban_script}" stop
  45. rc_procd start_service
  46. }
  47. status()
  48. {
  49. local key keylist value rtfile="$(uci_get banip global ban_rtfile)"
  50. rtfile="${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 ban_iface="$(uci_get banip global ban_iface)"
  69. local delay="$(uci_get banip extra ban_triggerdelay)"
  70. PROCD_RELOAD_DELAY=$((${delay:-2} * 1000))
  71. for iface in ${ban_iface:-"wan"}
  72. do
  73. procd_add_interface_trigger "interface.*.up" "${iface}" "${ban_init}" start
  74. done
  75. procd_add_reload_trigger "banip"
  76. }