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.

80 lines
1.6 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. stop_service()
  35. {
  36. rc_procd "${ban_script}" stop
  37. rc_procd start_service
  38. }
  39. refresh()
  40. {
  41. rc_procd start_service "refresh"
  42. }
  43. status()
  44. {
  45. local key keylist value rtfile="$(uci_get banip global ban_rtfile)"
  46. rtfile="${rtfile:-"/tmp/ban_runtime.json"}"
  47. json_load_file "${rtfile}" >/dev/null 2>&1
  48. json_select data >/dev/null 2>&1
  49. if [ ${?} -eq 0 ]
  50. then
  51. printf "%s\n" "::: banIP runtime information"
  52. json_get_keys keylist
  53. for key in ${keylist}
  54. do
  55. json_get_var value "${key}"
  56. printf " + %-10s : %s\n" "${key}" "${value}"
  57. done
  58. else
  59. printf "%s\n" "::: no banIP runtime information available"
  60. fi
  61. }
  62. service_triggers()
  63. {
  64. local iface="$(uci_get banip global ban_iface)"
  65. local delay="$(uci_get banip extra ban_triggerdelay)"
  66. PROCD_RELOAD_DELAY=$((${delay:-2} * 1000))
  67. procd_add_interface_trigger "interface.*.up" "${iface:-"wan"}" "${ban_init}" start
  68. procd_add_reload_trigger "banip" "firewall"
  69. }