From: kkalev Date: Fri, 3 May 2002 22:10:54 +0000 (+0000) Subject: * Change log_badlogins to use the mysql binary instead of the DBI module. That way... X-Git-Url: https://git.entuzijast.net/?a=commitdiff_plain;h=654398e46844a9022bba5c9fadb5dd9259a9e5cd;p=freeradius-dialup-admin.git * Change log_badlogins to use the mysql binary instead of the DBI module. That way we don't have any dependencies and we don't need to bother with connection maintainance (dead mysql connections etc). * Add a few comments in rlm_ippool.c --- diff --git a/Changelog b/Changelog index ec3f690..7275a73 100644 --- a/Changelog +++ b/Changelog @@ -2,8 +2,10 @@ Ver 1.30: * Add limit of results returned in accounting.php3 * Fix a bug in time2strclock() in lib/functions.php3. Seconds ammount more than 9 would not show. Bug noted by Timophey -* Reaarange a few things in user_admin. Put Subscription Analysis and 'Account Status' second. Make a +* Reaarange a few things in user_admin. Put Subscription Analysis first and 'Account Status' second. Make a few things bold. +* Change log_badlogins to use the mysql binary instead of the DBI module. That way we don't have any dependencies + and we don't need to bother with connection maintainance (dead mysql connections etc). Ver 1.29: * Add general_ld_library_path directive and set LD_LIBRARY_PATH accordingly (used in snmpfinger and radaclient). diff --git a/README b/README index 5f104c4..a106ef8 100644 --- a/README +++ b/README @@ -13,6 +13,8 @@ There are also a few more things included: invalid-user, outside of allowed login time and multiple-login cases to the radacct table with acctstarttime=acctstoptime, acctsessiontime=0 and acctterminatecause containing the reason. If the failing module sent back a module message then it will also appear in the terminate cause. + You will need to setup the $mysql and $tmpfile variables to suite your mysql installation and needs. + Perl module Date::Manip is needed by the script. * bin/clean_radacct: It will delete all entries in the radacct table with a starttime > 1 day and stoptime = 0. It will not do an harm even if it deletes valid entries since radiusd will fall back to insert if update fails. diff --git a/bin/log_badlogins b/bin/log_badlogins index 9018eec..2184406 100755 --- a/bin/log_badlogins +++ b/bin/log_badlogins @@ -1,5 +1,4 @@ #!/usr/bin/perl -use DBI; use Date::Manip qw(ParseDate UnixDate); $|=1; @@ -7,6 +6,8 @@ $|=1; $file=shift||'none'; $conf=shift||'/src/cvs/radiusd/dialup_admin/conf/admin.conf'; $domain='company.com'; +$mysql='/usr/local/mysql/bin/mysql'; +$tmpfile='/tmp/mysql.input'; open CONF, "<$conf" or die "Could not open configuration file\n"; @@ -20,9 +21,8 @@ while(){ $sql_accounting_table = $val if ($key eq 'sql_accounting_table'); } close CONF; +$pass = ($sql_password ne '') ? "-p$sql_password" : ''; -$dbh = DBI->connect("DBI:mysql:$sql_database:$sql_server","$sql_username","$sql_password") - or die "Could not connect to SQL database: $DBI::errtstr\n"; open LOG, "<$file" or die "Could not open file $file\n"; seek LOG, 0, 2; @@ -78,11 +78,14 @@ for(;;){ $addr = gethostbyname $nas; ($a,$b,$c,$d)=unpack('C4',$addr); $addr = "$a.$b.$c.$d"; -$dbh->do("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');"); + open TMP, ">$tmpfile" + or die "Could not open temporary file\n"; + 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`; } } } sleep 2; seek LOG,0,1; } -$dbh->disconnect();