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.

35 lines
1.0 KiB

  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. # This is free software, licensed under the GNU General Public License v3.
  5. # You should have received a copy of the GNU General Public License
  6. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  7. LC_ALL=C
  8. PATH="/usr/sbin:/usr/bin:/sbin:/bin"
  9. ban_ver="${1}"
  10. ban_sshdaemon="${2}"
  11. ban_logger="$(command -v logger)"
  12. ban_logread="$(command -v logread)"
  13. f_log()
  14. {
  15. local class="${1}" log_msg="${2}"
  16. if [ -x "${ban_logger}" ]
  17. then
  18. "${ban_logger}" -p "${class}" -t "banIP-${ban_ver}[${$}]" "${log_msg}"
  19. else
  20. printf "%s %s %s\\n" "${class}" "banIP-${ban_ver}[${$}]" "${log_msg}"
  21. fi
  22. }
  23. if [ -x "${ban_logread}" ]
  24. then
  25. f_log "info" "log/banIP service started"
  26. "${ban_logread}" -f -e "${ban_sshdaemon}\|luci: failed login" | \
  27. { grep -qE "Exit before auth|luci: failed login|[0-9]+ \[preauth\]$"; [ $? -eq 0 ] && /etc/init.d/banip refresh; }
  28. else
  29. f_log "err" "can't start log/banIP service"
  30. fi