vpnwho.pl 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #!/usr/bin/perl
  2. # NOTE: superceded by --logwtmp feature, see ../README.logwtmp
  3. #
  4. # By Jason Collins-Webb (jason@rbaltd.co.uk)
  5. # usage: vpnwho
  6. #
  7. # This program is free software; you can redistribute it and/or
  8. # modify it under the terms of the GNU General Public License
  9. # as published by the Free Software Foundation; either version 2
  10. # of the License, or (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with this program; if not, write to the Free Software
  19. # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  20. # Your copy is available at: http://www.gnu.org/licenses/gpl.html
  21. #
  22. $TDateM = substr(`/bin/date +"%b"`, 0, -1);
  23. $TDateD = substr(`/bin/date +"%e"`, 0, -1);
  24. $whoson = `/bin/ps -eo pid,bsdstart,cmd|/bin/grep "pptpd \\["`;
  25. if ($whoson ne "") {
  26. @logons = split(/\n/, $whoson);
  27. foreach $l (@logons) {
  28. if ($l =~ /(\d+)\s+(\d+:\d+).*\[(\d+\.\d+\.\d+\.\d+)\]/) {
  29. $PID = $1+1;
  30. $IP = $3;
  31. $STIME = $2;
  32. open MESSAGES, "</var/log/messages";
  33. while(<MESSAGES>){
  34. if ($_ =~ /.*\spppd\[$PID\]:\s+MSCHAP-v2\s.*\s(.+\\)*(.+)$/i) {
  35. $User = lc($2);
  36. }
  37. }
  38. close MESSAGES;
  39. print "Current VPN connection from $User ($IP), started at $STIME\n";
  40. }
  41. }
  42. } else {
  43. print "There are no current VPN connections.\n";
  44. }