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.

36 lines
986 B

  1. #!/bin/sh
  2. # log service to trace failed ssh/luci logins and conditionally refresh banIP
  3. # written by Dirk Brenken (dev@brenken.org)
  4. #
  5. # This is free software, licensed under the GNU General Public License v3.
  6. #
  7. # (s)hellcheck exceptions
  8. # shellcheck disable=1091,2030,2031,2034,2039,2086,2129,2140,2143,2154,2181,2183,2188
  9. export LC_ALL=C
  10. export PATH="/usr/sbin:/usr/bin:/sbin:/bin"
  11. set -o pipefail
  12. ban_ver="${1}"
  13. ban_search="${2}"
  14. ban_logger="$(command -v logger)"
  15. ban_logread="$(command -v logread)"
  16. f_log()
  17. {
  18. local class="${1}" log_msg="${2}"
  19. if [ -x "${ban_logger}" ]
  20. then
  21. "${ban_logger}" -p "${class}" -t "banIP-${ban_ver%-*}[${$}]" "${log_msg}"
  22. else
  23. printf "%s %s %s\n" "${class}" "banIP-${ban_ver%-*}[${$}]" "${log_msg}"
  24. fi
  25. }
  26. if [ -x "${ban_logread}" ]
  27. then
  28. f_log "info" "log/banIP service started"
  29. "${ban_logread}" -f | { grep -qE "${ban_search}"; [ "${?}" = "0" ] && { /etc/init.d/banip refresh; exit 0; }; }
  30. else
  31. f_log "err" "can't start log/banIP service"
  32. fi