summaryrefslogtreecommitdiff
path: root/localshowuserfromip
blob: 48398e2112d673b3d961031b976c8e05a7f267b0 (plain)
  1. #!/bin/sh
  2. #
  3. # /usr/local/sbin/localshowuserfromip
  4. # Copyright 2007 Jonas Smedegaard <dr@jones.dk>
  5. #
  6. # $Id: localshowuserfromip,v 1.1 2007-11-14 13:23:55 jonas Exp $
  7. #
  8. # List recent identifiable users from some IP address
  9. #
  10. input="${input:-user}"
  11. output="${output:-shortline}"
  12. logfilecount="${logfilecount:-1}"
  13. pattern="${pattern:-user_dovecot}"
  14. sed_longline='s/^\(.\{15\}\) [^:]*: /\1 /'
  15. sed_time='s/^\(.\{15\}\) .*$/\1 /'
  16. case $pattern in
  17. user_dovecot)
  18. # Dovecot "deliver"
  19. egrep_before=', rip=('
  20. egrep_after='), lip='
  21. sed_shortline='s/^\(.\{15\}\) [^:]*: [^-]*-login: Login: user=</\1/;s/>, method=[^,]*, rip=/ /;s/, lip=.*$//'
  22. sed_username='s/^.* user=<//;s/>, .*$//'
  23. ;;
  24. *)
  25. echo >&2 "ERROR: unknwon pattern \"$pattern\""
  26. exit 1
  27. ;;
  28. esac
  29. case $output in
  30. shortline)
  31. sedstring="$sed_shortline"
  32. ;;
  33. longline)
  34. sedstring="$sed_longline"
  35. ;;
  36. username)
  37. sedstring="$sed_msgid"
  38. ;;
  39. *)
  40. echo >&2 "ERROR: unknwon output \"$output\""
  41. exit 1
  42. ;;
  43. esac
  44. ip="$1"
  45. find /var/log -name 'syslog*' | sort -nr -t. -k3 | tail -n "$logfilecount" | xargs zcat -f \
  46. | egrep -- "$egrep_before$ip$egrep_after" \
  47. | sed "$sedstring"