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.

87 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. }
  46. status()
  47. {
  48. local key keylist value rtfile="$(uci_get banip global ban_rtfile)"
  49. rtfile="${rtfile:-"/tmp/ban_runtime.json"}"
  50. json_load_file "${rtfile}" >/dev/null 2>&1
  51. json_select data >/dev/null 2>&1
  52. if [ ${?} -eq 0 ]
  53. then
  54. printf "%s\n" "::: banIP runtime information"
  55. json_get_keys keylist
  56. for key in ${keylist}
  57. do
  58. json_get_var value "${key}"
  59. printf " + %-10s : %s\n" "${key}" "${value}"
  60. done
  61. else
  62. printf "%s\n" "::: no banIP runtime information available"
  63. fi
  64. }
  65. service_triggers()
  66. {
  67. local ban_iface="$(uci_get banip global ban_iface)"
  68. local delay="$(uci_get banip extra ban_triggerdelay)"
  69. PROCD_RELOAD_DELAY=$((${delay:-2} * 1000))
  70. for iface in ${ban_iface:-"wan"}
  71. do
  72. procd_add_interface_trigger "interface.*.up" "${iface}" "${ban_init}" start
  73. done
  74. procd_add_reload_trigger "banip"
  75. }