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.

27 lines
936 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. # 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. if [ -r "/lib/functions.sh" ]
  10. then
  11. . "/lib/functions.sh"
  12. ban_sshdaemon="$(uci_get banip extra ban_sshdaemon "dropbear")"
  13. fi
  14. ban_ver="${1}"
  15. ban_log="$(command -v logread)"
  16. if [ -x "${ban_log}" ]
  17. then
  18. logger -p "info" -t "banIP-${ban_ver}[${$}]" "log/banIP service started"
  19. "${ban_log}" -f -e "${ban_sshdaemon}\|luci: failed login" | \
  20. { grep -qE "Exit before auth|luci: failed login|[0-9]+ \[preauth\]$"; [ $? -eq 0 ] && /etc/init.d/banip refresh; }
  21. else
  22. logger -p "err" -t "banIP-${ban_ver}[${$}]" "can't start log/banIP service"
  23. fi