]> git.entuzijast.net Git - freeradius-dialup-admin.git/commitdiff
Add a few comments in log_badlogins, support auth logs containing the password, work...
authorkkalev <kkalev>
Tue, 24 Sep 2002 09:02:42 +0000 (09:02 +0000)
committerkkalev <kkalev>
Tue, 24 Sep 2002 09:02:42 +0000 (09:02 +0000)
is localhost, add an option to scan the whole radius.log and add failed logins in the sql database (can be
used for initialization).

Changelog
bin/log_badlogins

index 8e7f78ff14fdb6a54090fd4736af4d8984105bdf..432cfc4c64743c7a143e6dc6e827b9a86643fcdb 100644 (file)
--- 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
index 8f50af14e1584d3568f9f693129a580df354472d..0b7fd117dd293a1f06449068de47d0c33bed13ce 100755 (executable)
@@ -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 <radius.log> [<admin.conf>] [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(<LOG>){
                $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";
                        }
                }
        }