From: kkalev Date: Tue, 24 Sep 2002 09:02:42 +0000 (+0000) Subject: Add a few comments in log_badlogins, support auth logs containing the password, work... X-Git-Url: https://git.entuzijast.net/?a=commitdiff_plain;h=0483b9dae802f2142b202037a297eed8798bf716;p=freeradius-dialup-admin.git Add a few comments in log_badlogins, support auth logs containing the password, work nice when the client is localhost, add an option to scan the whole radius.log and add failed logins in the sql database (can be used for initialization). --- diff --git a/Changelog b/Changelog index 8e7f78f..432cfc4 100644 --- a/Changelog +++ b/Changelog @@ -8,6 +8,9 @@ Ver 1.60: * Update the FAQ with an entry about the Online Users page not showing anything. * Update the FAQ with an entry about sessions. * Allow the user to add extra attributes in the test user page +* Add a few comments in log_badlogins, support auth logs containing the password, work nice when the client + is localhost, add an option to scan the whole radius.log and add failed logins in the sql database (can be + used for initialization). Ver 1.59: * Small html fixes in user_edit.php3 and password.php3 * Show number of failed logins in the last 7 days in the user admin page diff --git a/bin/log_badlogins b/bin/log_badlogins index 8f50af1..0b7fd11 100755 --- a/bin/log_badlogins +++ b/bin/log_badlogins @@ -1,13 +1,32 @@ #!/usr/bin/perl +# +# Log failed logins in the sql database +# Works only with mysql +# It will read the sql parameters from the admin.conf file +# +# Usage: +# log_badlogins [] [all] +# +# Defaults: +# radius.log: none +# admin.conf: /usr/local/dialup_admin/conf/admin.conf +# all: no. Go to the end of the file. Don't read it all. use Date::Manip qw(ParseDate UnixDate); $|=1; $file=shift||'none'; -$conf=shift||'/src/cvs/radiusd/dialup_admin/conf/admin.conf'; +$conf=shift||'/usr/local/dialup_admin/conf/admin.conf'; +$all_file=shift||'no'; +# +# +# CHANGE THESE TO MATCH YOUR SETUP +# $domain='company.com'; $mysql='/usr/local/mysql/bin/mysql'; $tmpfile='/tmp/mysql.input'; +# +# open CONF, "<$conf" or die "Could not open configuration file\n"; @@ -30,7 +49,8 @@ $pass = ($sql_password ne '') ? "-p$sql_password" : ''; open LOG, "<$file" or die "Could not open file $file\n"; -seek LOG, 0, 2; + +seek LOG, 0, 2 if ($all_file eq 'no'); for(;;){ while(){ $do=0; @@ -68,14 +88,18 @@ for(;;){ ($year,$mon,$mday,$hour,$min,$sec)=UnixDate($date2,'%Y','%m','%d','%H','%M','%S'); } $time = "$year-$mon-$mday $hour:$min:$sec"; - if (/\[(\w+?)\]\s+\(from (.+?)\)/){ + if (/\[([\w\-]+?)\]\s+\(from (.+?)\)/){ + $user = $1; + ($nas,$port,$caller) = (split /\s+/,$2)[1,3,5]; + } + elsif (/\[([\w\-]+?)\/.+?\]\s+\(from (.+?)\)/){ $user = $1; ($nas,$port,$caller) = (split /\s+/,$2)[1,3,5]; } $caller='' if (!defined($caller)); $user =~s/[^\w]//g; $nas =~s/[^\w]//g; - if ($nas !~ /\.$domain$/){ + if ($nas ne 'localhost' && $nas !~ /\.$domain$/){ $nas .= '.$domain'; } $port =~s/[^\d]//g; @@ -94,6 +118,7 @@ for(;;){ print TMP "INSERT INTO $sql_accounting_table (UserName,NASIPAddress,NASPortId,AcctStartTime,AcctStopTime,AcctSessionTime,AcctInputOctets,AcctOutputOctets,CallingStationId,AcctTerminateCause) VALUES ('$user','$addr','$port','$time','$time','0','0','0','$caller','$cause');"; close TMP; `$mysql -h$sql_server -u$sql_username $pass $sql_database <$tmpfile`; + print "$mysql -h$sql_server -u$sql_username $pass $sql_database <$tmpfile\n"; } } }