From: kkalev Date: Sat, 3 Apr 2004 20:42:29 +0000 (+0000) Subject: * Sort the servers list in failed_logins,user_stats,stats X-Git-Url: https://git.entuzijast.net/?a=commitdiff_plain;h=12038bee2ab6ad7cf884c0a417d57eb194abe6aa;p=freeradius-dialup-admin.git * Sort the servers list in failed_logins,user_stats,stats * Add the /bin postgresql compatibility patch from Guy Fraser --- diff --git a/Changelog b/Changelog index 9f282a5..3f15eb7 100644 --- a/Changelog +++ b/Changelog @@ -12,6 +12,8 @@ Ver 1.68: * Add a force directive in log_badlogins. If uncommented it will force inserts even if there are sql errors. That can help in case there is one sql query which stops the whole failed logins logging system from working +* Sort the servers list in failed_logins,user_stats,stats +* Add the /bin postgresql compatibility patch from Guy Fraser Ver 1.65: * Add a captions.conf file with a few configurable captions for now * Move the nas list to a separate file called naslist.conf diff --git a/bin/Changelog.GuyFraser b/bin/Changelog.GuyFraser new file mode 100644 index 0000000..bb6e1f2 --- /dev/null +++ b/bin/Changelog.GuyFraser @@ -0,0 +1,51 @@ +Fri Dec 19 2003 +--------------- +Fixed a couple bugs. +Tested against current CVS, and all programs appear to work. + +Wed Dec 17 2003 +--------------- +Added configurable entries to admin.conf. +TODO: Write a proper config file parser to get recursive entries from config +file. + +Tue Dec 16 2003 +--------------- + +File Compatiblity Change +----------------------- --------------- --------------------------------------- +clean_radacct MySQL/PG Added PG compatability +log_badlogins MySQL/PG Added PG compatability + " Added routine to determine ip from the + " FreeRadius clients.conf file. +monthly_tot_stats MySQL/PG Added PG compatability +showmodem UCD/NET Made compatabile with Net/UCD SNMP + " Cleaned up output formatting. +snmpfinger UCD/NET Made compatabile with Net/UCD SNMP +tot_stats MySQL/PG Added PG compatability + " Added a delete request. +truncate_radacct MySQL/PG Added PG compatability + +These utilities have been updated to work with NET-SNMP, and have been modified +to work with PostgreSQL. + +The argument order and options for NET-SNMP have changed from UCD-SNMP's +requirements. Since most current Unix type systems are using the newer +NET-SNMP, I have included the changes for everyones benefit. + +I have also modified some scripts : + +log_badlogins - I changed it to use the data from the FreeRadius clients.conf + file to determine the IP address of each NAS. I did this because in my + case, and likely that of many others, the shortname from the radius log + file is not shortname.domain.com, where domain.com is defined in + admin.conf. + +showmodem - I cleaned up the output presentation. + +Path to admin.conf, set to /usr/local/dialup_admin/conf/ for all scripts. + +Guy Fraser +Network Administrator +The Internet Centre +Edmonton, Alberta, Canada. diff --git a/bin/clean_radacct b/bin/clean_radacct index 339ba51..2dbd117 100755 --- a/bin/clean_radacct +++ b/bin/clean_radacct @@ -2,6 +2,7 @@ # # Clean stale open sessions from the radacct table. # we only clean up sessions which are older than $back_days +# Works with mysql and postgresql # use POSIX; @@ -14,17 +15,18 @@ open CONF, "<$conf" while(){ chomp; ($key,$val)=(split /:\s*/,$_); + $sql_type = $val if ($key eq 'sql_type'); $sql_server = $val if ($key eq 'sql_server'); $sql_username = $val if ($key eq 'sql_username'); $sql_password = $val if ($key eq 'sql_password'); $sql_database = $val if ($key eq 'sql_database'); $sql_accounting_table = $val if ($key eq 'sql_accounting_table'); - $mysql = $val if ($key eq 'sql_command'); + $sqlcmd = $val if ($key eq 'sql_command'); } close CONF; -die "sql_command directive is not set in admin.conf\n" if ($mysql eq ''); -die "Could not find mysql binary. Please make sure that the \$mysql variable points to the right location\n" if (! -x $mysql); +die "sql_command directive is not set in admin.conf\n" if ($sqlcmd eq ''); +die "Could not find sql binary. Please make sure that the \$sqlcmd variable points to the right location\n" if (! -x $sqlcmd); $sql_password = ($sql_password eq '') ? '' : "-p$sql_password"; @@ -32,10 +34,12 @@ $sql_password = ($sql_password eq '') ? '' : "-p$sql_password"; $date = POSIX::strftime("%Y-%m-%d %T",$sec,$min,$hour,($mday - $back_days),$mon,$year,$wday,$yday,$isdst); print "$date\n"; -$query = "DELETE FROM $sql_accounting_table WHERE AcctStopTime = '0' AND AcctStartTime < '$date';"; +$query = "DELETE FROM $sql_accounting_table WHERE AcctStopTime IS NULL AND AcctStartTime < '$date';"; print "$query\n"; open TMP, ">/tmp/clean_radacct.query" or die "Could not open tmp file\n"; print TMP $query; close TMP; -`$mysql -h$sql_server -u$sql_username $sql_password $sql_database /dev/null 2>&1 +5 0 * * * /usr/local/dialup_admin/bin/monthly_tot_stats >/dev/null 2>&1 +10 0 1 * * /usr/local/dialup_admin/bin/truncate_radacct >/dev/null 2>&1 +15 0 1 * * /usr/local/dialup_admin/bin/clean_radacct >/dev/null 2>&1 diff --git a/bin/log_badlogins b/bin/log_badlogins index 5301e12..42660e2 100755 --- a/bin/log_badlogins +++ b/bin/log_badlogins @@ -1,7 +1,7 @@ #!/usr/bin/perl # # Log failed logins in the sql database -# Works only with mysql +# Works with mysql and postgresql # It will read the sql parameters from the admin.conf file # # Usage: @@ -29,7 +29,7 @@ $all_file=shift||'no'; # CHANGE THESE TO MATCH YOUR SETUP # #$regexp = 'from client localhost port 135|from client blabla '; -$tmpfile='/var/tmp/mysql.input'; +$tmpfile='/var/tmp/sql.input'; # # @@ -38,6 +38,9 @@ open CONF, "<$conf" while(){ chomp; ($key,$val)=(split /:\s*/,$_); + # Fixme : recursivly solve %{.*} replacement for $val + # Fixme: Conf should be put in an associative array + $sql_type = $val if ($key eq 'sql_type'); $sql_server = $val if ($key eq 'sql_server'); $sql_username = $val if ($key eq 'sql_username'); $sql_password = $val if ($key eq 'sql_password'); @@ -49,16 +52,52 @@ while(){ $domain = $val if ($key eq 'general_domain'); $sql_timeout = $val if ($key eq 'sql_connect_timeout'); $sql_extra = $val if ($key eq 'sql_extra_servers'); - $mysql = $val if ($key eq 'sql_command'); + $sqlcmd = $val if ($key eq 'sql_command'); + $clients= $val if ($key eq 'general_clients_conf'); } close CONF; + +open CLIENTS, "<$clients" + or die "Could not open $clients file\n"; +while(){ + chomp; + s/^\s*//g; + s/\s*#.*//g; + if (!/^\s*$/ && /=/) { + ($key,$val)=(split /\s*=\s*/,$_); + $client_short = $val if ($key eq 'shortname'); + } else { + if (/\{/) { + s/.*client\s+([^\s]*)\s+\{.*$/\1/; + if (/^\d+\.\d+\.\d+\.\d+/) { + $client = $_; + } else { + if (/\./ || /localhost/) { + $name = $_ ; + } else { + $name = $_.".".$domain; + } + $addr = gethostbyname $name; + ($a,$b,$c,$d)=unpack('C4',$addr); + $client = "$a.$b.$c.$d"; +#DEBUG# print $name." = ".$client."\n"; + } + } else { + if (/\}/) { + $client_array{$client_short} .= $client; + } + } + } +} +close CLIENTS; + $realm_del = '@' if ($realm_del eq ''); $realm_for = 'suffix' if ($realm_for eq ''); $pass = ($sql_password ne '') ? "-p$sql_password" : ''; die "SQL server not defined\n" if ($sql_server eq ''); -die "sql_command directive is not set in admin.conf\n" if ($mysql eq ''); -die "Could not find mysql binary. Please make sure that the \$mysql variable points to the right location\n" if (! -x $mysql); +die "sql_command directive is not set in admin.conf\n" if ($sqlcmd eq ''); +die "Could not find sql binary. Please make sure that the \$sqlcmd variable points to the right location\n" if (! -x $sqlcmd); $opt = ""; $opt = "-O connect_timeout=$sql_timeout" if ($sql_timeout); @@ -129,13 +168,8 @@ for(;;){ $caller='' if (!defined($caller)); $user =~s/[^\w\-\.\d\!\@\s]//g; $nas =~s/[^\w\.]//g; - if ($nas ne 'localhost' && $nas !~ /\.$domain$/){ - $nas .= ".$domain"; - } $port =~s/[^\d]//g; - $addr = gethostbyname $nas; - ($a,$b,$c,$d)=unpack('C4',$addr); - $addr = "$a.$b.$c.$d"; + $addr = $client_array{$nas}; if ($user ne '' && $realm_strip eq 'yes'){ ($one,$two) = (split /$realm_del/, $user)[0,1]; if ($two ne ''){ @@ -153,9 +187,13 @@ for(;;){ $ctx->add($time); $ctx->add('badlogin'); $uniqueid = $ctx->hexdigest; +#DEBUG# print "INSERT INTO $sql_accounting_table (UserName,AcctUniqueId,NASIPAddress,NASPortId,AcctStartTime,AcctStopTime,AcctSessionTime,AcctInputOctets,AcctOutputOctets,CallingStationId,AcctTerminateCause) VALUES ('$user','$uniqueid','$addr','$port','$time','$time','0','0','0','$caller','$cause');\n"; print TMP "INSERT INTO $sql_accounting_table (UserName,AcctUniqueId,NASIPAddress,NASPortId,AcctStartTime,AcctStopTime,AcctSessionTime,AcctInputOctets,AcctOutputOctets,CallingStationId,AcctTerminateCause) VALUES ('$user','$uniqueid','$addr','$port','$time','$time','0','0','0','$caller','$cause');\n"; close TMP; - `$mysql -h$server $opt -u$sql_username $pass $sql_database <$tmpfile.$server`; + $command = "$sqlcmd -h$server $opt -u$sql_username $pass $sql_database <$tmpfile.$server" if ($sql_type eq 'mysql'); + $command = "$sqlcmd -U $sql_username -f $tmpfile.$server $sql_database" if ($sql_type eq 'pg'); + `$command`; + $exit = $? >> 8; $delete{$server} = ($exit == 0) ? 1 : 0; print "ERROR: SQL query failed for host $server\n" if ($exit != 0); @@ -163,6 +201,10 @@ for(;;){ } } } - sleep 2; - seek LOG,0,1; + if ($all_file ne 'once') { + sleep 2; + seek LOG,0,1; + } else { + exit(0); + } } diff --git a/bin/monthly_tot_stats b/bin/monthly_tot_stats index 79a976e..533cc98 100755 --- a/bin/monthly_tot_stats +++ b/bin/monthly_tot_stats @@ -5,8 +5,10 @@ use POSIX; # each user spaning in one month period. # If the current month has not ended it will log information up to # the current month day +# Works only with mysql and postgresql +# -$conf=shift||'/usr/local/dialupadmin/conf/admin.conf'; +$conf=shift||'/usr/local/dialup_admin/conf/admin.conf'; open CONF, "<$conf" @@ -14,17 +16,18 @@ open CONF, "<$conf" while(){ chomp; ($key,$val)=(split /:\s*/,$_); + $sql_type = $val if ($key eq 'sql_type'); $sql_server = $val if ($key eq 'sql_server'); $sql_username = $val if ($key eq 'sql_username'); $sql_password = $val if ($key eq 'sql_password'); $sql_database = $val if ($key eq 'sql_database'); $sql_accounting_table = $val if ($key eq 'sql_accounting_table'); - $mysql = $val if ($key eq 'sql_command'); + $sqlcmd = $val if ($key eq 'sql_command'); } close CONF; -die "sql_command directive is not set in admin.conf\n" if ($mysql eq ''); -die "Could not find mysql binary. Please make sure that the \$mysql variable points to the right location\n" if (! -x $mysql); +die "sql_command directive is not set in admin.conf\n" if ($sqlcmd eq ''); +die "Could not find sql binary. Please make sure that the \$sqlcmd variable points to the right location\n" if (! -x $sqlcmd); $sql_password = ($sql_password == '') ? '' : "-p$sql_password"; @@ -42,7 +45,7 @@ $query2 = "INSERT INTO mtotacct (UserName,AcctDate,ConnNum,ConnTotDuration, MAX(ConnMaxDuration),MIN(ConnMinDuration),SUM(InputOctets), SUM(OutputOctets),NASIPAddress FROM totacct WHERE AcctDate >= '$date_start' AND - AcctDate <= '$date_end' GROUP BY UserName;"; + AcctDate <= '$date_end' GROUP BY UserName,NASIPAddress;"; print "$query1\n"; print "$query2\n"; open TMP, ">/tmp/tot_stats.query" @@ -50,4 +53,6 @@ open TMP, ">/tmp/tot_stats.query" print TMP $query1; print TMP $query2; close TMP; -`$mysql -h $sql_server -u $sql_username $sql_password $sql_database ){ + chomp; + ($key,$val)=(split /:\s*/,$_); + $snmp_type = $val if ($key eq 'general_snmp_type'); + $snmpget = $val if ($key eq 'general_snmpget_command'); + $snmpwalk = $val if ($key eq 'general_snmpwalk_command'); +} +close CONF; + +die "general_snmp_type directive is not set in admin.conf\n" if ($snmp_type eq ''); +die "Could not find snmpwalk binary. Please make sure that the \$snmpwalk variable points to the right location\n" if (! -x $snmpwalk); + +if ($snmp_type = 'ucd') { + $snmpgetcmd="$snmpget $host $comm"; + $snmpwalkcmd="$snmpwalk $host $comm"; +} +if ($snmp_type = 'net') { + $snmpgetcmd="$snmpget -v 1 -c $comm $host"; + $snmpwalkcmd="$snmpwalk -v 1 -c $comm $host"; +} +#DEBUG#print "$snmpwalkcmd\n"; print "$snmpgetcmd\n"; @ModulationScheme = ( "error", "unknown", @@ -42,48 +66,60 @@ $type=shift|| "xml"; "ara20", "unknown", ); - -$modem=`$snmpwalk $nas $com enterprises.9.2.9.2.1.18 | grep $user`; +#DEBUG#print "$snmpwalkcmd enterprises.9.2.9.2.1.18 | grep $user\n"; +$modem=`$snmpwalkcmd enterprises.9.2.9.2.1.18 | grep $user`; if($modem=~/enterprises\.9\.2\.9\.2\.1\.18\.(\d+) =/){ $modem=$1; $slot=(1+int($modem/120)); $port=$modem%120-1; $modem="$slot.$port"; - - $duration=`$snmpget $nas $com enterprises.9.9.47.1.3.1.1.9.$modem` or die "No MIB\n"; +#DEBUG#print "$snmpgetcmd enterprises.9.9.47.1.3.1.1.9.$modem\n"; + $duration=`$snmpgetcmd enterprises.9.9.47.1.3.1.1.9.$modem` or die "No MIB\n"; $duration=~/\) (.*)\./; $duration=$1; - $modulation=`$snmpget $nas $com enterprises.9.9.47.1.3.1.1.12.$modem` or die "No MIB\n"; +#DEBUG#print "$snmpgetcmd enterprises.9.9.47.1.3.1.1.12.$modem\n"; + $modulation=`$snmpgetcmd enterprises.9.9.47.1.3.1.1.12.$modem` or die "No MIB\n"; $modulation=~/ \= (\d+)/; $modulation=$ModulationScheme[$1]; - $protocol=`$snmpget $nas $com enterprises.9.9.47.1.3.1.1.13.$modem` or die "No MIB\n"; +#DEBUG#print "$snmpgetcmd enterprises.9.9.47.1.3.1.1.13.$modem\n"; + $protocol=`$snmpgetcmd enterprises.9.9.47.1.3.1.1.13.$modem` or die "No MIB\n"; $protocol=~/ \= (\d+)/; $protocol=$Protocol[$1]; - $txrate=`$snmpget $nas $com enterprises.9.9.47.1.3.1.1.14.$modem` or die "No MIB\n"; +#DEBUG#print "$snmpgetcmd enterprises.9.9.47.1.3.1.1.14.$modem\n"; + $txrate=`$snmpgetcmd enterprises.9.9.47.1.3.1.1.14.$modem` or die "No MIB\n"; $txrate=~/Gauge32\: (\d+)/; $txrate=$1; - $rxrate=`$snmpget $nas $com enterprises.9.9.47.1.3.1.1.15.$modem` or die "No MIB\n"; +#DEBUG#print "$snmpgetcmd enterprises.9.9.47.1.3.1.1.15.$modem\n"; + $rxrate=`$snmpgetcmd enterprises.9.9.47.1.3.1.1.15.$modem` or die "No MIB\n"; $rxrate=~/Gauge32\: (\d+)/; $rxrate=$1; - $rxsignal=`$snmpget $nas $com enterprises.9.9.47.1.3.1.1.17.$modem` or die "No MIB\n"; +#DEBUG#print "$snmpgetcmd enterprises.9.9.47.1.3.1.1.17.$modem\n"; + $rxsignal=`$snmpgetcmd enterprises.9.9.47.1.3.1.1.17.$modem` or die "No MIB\n"; +# $rxsignal=~ s/INTEGER\://; $rxsignal=~/ \= (.*)\n/; $rxsignal=$1; if($type eq "xml"){ - print"$modulation$protocol$txrate$rxrate$rxsignal\n"; - + print "$user\n"; + print "\t$duration\n"; + print "\t$modulation\n"; + print "\t$protocol\n"; + print "\t$txrate\n"; + print "\t$rxrate\n"; + print "\t$rxsignal dBm\n\n"; }else{ - print "Duration>\t$duration\n"; - print "Modulation>\t$modulation\n"; - print "Protocol>\t$protocol\n"; - print "TxRate>\t\t$txrate\n"; - print "RxRate>\t\t$rxrate\n"; - print "RxSignal>\t$rxsignal dbm\n"; + printf("%14s\t%s\n","User",$user); + printf("%14s\t%s\n","Duration",$duration); + printf("%14s\t%s\n","Modulation",$modulation); + printf("%14s\t%s\n","Protocol",$protocol); + printf("%14s\t%s\n","TxRate",$txrate); + printf("%14s\t%s\n","RxRate",$rxrate); + printf("%14s\t%s dBm\n\n","RxSignal",$rxsignal); } } diff --git a/bin/snmpfinger b/bin/snmpfinger index 77d8368..68a7cad 100755 --- a/bin/snmpfinger +++ b/bin/snmpfinger @@ -1,21 +1,37 @@ #!/usr/bin/perl +# +# This works with Net-SNMP and UCD-SNMP -$SNMPWALK="/usr/bin/snmpwalk"; $host=shift; $comm=shift || 'public'; $type=shift || 'cisco'; -die "Could not find snmpwalk binary. Please make sure that the \$SNMPWALK variable points to the right location\n" if (! -x $SNMPWALK); +$conf='/usr/local/dialup_admin/conf/admin.conf'; +open CONF, "<$conf" + or die "Could not open configuration file\n"; +while(){ + chomp; + ($key,$val)=(split /:\s*/,$_); + $snmp_type = $val if ($key eq 'general_snmp_type'); + $snmpwalk = $val if ($key eq 'general_snmpwalk_command'); +} +close CONF; + +die "general_snmp_type directive is not set in admin.conf\n" if ($snmp_type eq ''); +die "Could not find snmpwalk binary. Please make sure that the \$snmpwalk variable points to the right location\n" if (! -x $snmpwalk); + +$snmpwalkcmd="$snmpwalk $host $comm" if ($snmp_type = 'ucd'); +$snmpwalkcmd="$snmpwalk -v 1 -c $comm $host" if ($snmp_type = 'net'); if ($type eq 'cisco'){ - $walk =`$SNMPWALK -v2c -c $comm $host .iso.org.dod.internet.private.enterprises.9.9.150.1.1.3.1.2`; + $walk =`$snmpwalkcmd .iso.org.dod.internet.private.enterprises.9.9.150.1.1.3.1.2`; if ($walk =~ /^$/){ - $walk =`$SNMPWALK -v2c -c $comm $host .iso.org.dod.internet.private.enterprises.9.2.9.2.1.18`; - $walk.=`$SNMPWALK -v2c -c $comm $host .iso.org.dod.internet.private.enterprises.9.10.19.1.3.1.1.3`; + $walk =`$snmpwalkcmd .iso.org.dod.internet.private.enterprises.9.2.9.2.1.18`; + $walk.=`$snmpwalkcmd .iso.org.dod.internet.private.enterprises.9.10.19.1.3.1.1.3`; } } elsif ($type eq 'lucent'){ - $walk =`$SNMPWALK -v2c -c $comm $host .iso.org.dod.internet.private.enterprises.529.10.4.1.12`; + $walk =`$snmpwalkcmd .iso.org.dod.internet.private.enterprises.529.10.4.1.12`; } while($walk=~/\"([\w\-]+?)\"/g){ diff --git a/bin/tot_stats b/bin/tot_stats index ca4149b..f3a3e07 100755 --- a/bin/tot_stats +++ b/bin/tot_stats @@ -4,9 +4,10 @@ use POSIX; # Log in the totacct table aggregated daily accounting information for # each user. # We keep a row per user for each day. +# Works with mysql and postgresql +# - -$conf=shift||'/usr/local/dialupadmin/conf/admin.conf'; +$conf=shift||'/usr/local/dialup_admin/conf/admin.conf'; open CONF, "<$conf" @@ -14,17 +15,18 @@ open CONF, "<$conf" while(){ chomp; ($key,$val)=(split /:\s*/,$_); + $sql_type = $val if ($key eq 'sql_type'); $sql_server = $val if ($key eq 'sql_server'); $sql_username = $val if ($key eq 'sql_username'); $sql_password = $val if ($key eq 'sql_password'); $sql_database = $val if ($key eq 'sql_database'); $sql_accounting_table = $val if ($key eq 'sql_accounting_table'); - $mysql = $val if ($key eq 'sql_command'); + $sqlcmd = $val if ($key eq 'sql_command'); } close CONF; -die "sql_command directive is not set in admin.conf\n" if ($mysql eq ''); -die "Could not find mysql binary. Please make sure that the \$mysql variable points to the right location\n" if (! -x $mysql); +die "sql_command directive is not set in admin.conf\n" if ($sqlcmd eq ''); +die "Could not find sql binary. Please make sure that the \$sqlcmd variable points to the right location\n" if (! -x $sqlcmd); $sql_password = ($sql_password == '') ? '' : "-p$sql_password"; @@ -33,16 +35,21 @@ $date_start = POSIX::strftime("%Y-%m-%d %T",0,0,0,($mday - 1),$mon,$year,$wday,$ $date_small_start = POSIX::strftime("%Y-%m-%d",0,0,0,($mday - 1),$mon,$year,$wday,$yday,$isdst); $date_end = POSIX::strftime("%Y-%m-%d %T",0,0,0,$mday,$mon,$year,$wday,$yday,$isdst); -$query = "INSERT INTO totacct (UserName,AcctDate,ConnNum,ConnTotDuration, +$query1 = "DELETE FROM totacct WHERE AcctDate = '$date_start';"; +$query2 = "INSERT INTO totacct (UserName,AcctDate,ConnNum,ConnTotDuration, ConnMaxDuration,ConnMinDuration,InputOctets,OutputOctets,NASIPAddress) SELECT UserName,'$date_small_start',COUNT(*),SUM(AcctSessionTime), MAX(AcctSessionTime),MIN(AcctSessionTime),SUM(AcctInputOctets), SUM(AcctOutputOctets),NASIPAddress FROM radacct WHERE AcctStopTime >= '$date_start' AND - AcctStopTime < '$date_end' GROUP BY UserName;"; -print "$query\n"; + AcctStopTime < '$date_end' GROUP BY UserName,NASIPAddress;"; +print "$query1\n"; +print "$query2\n"; open TMP, ">/tmp/tot_stats.query" or die "Could not open tmp file\n"; -print TMP $query; +print TMP $query1; +print TMP $query2; close TMP; -`$mysql -h $sql_server -u $sql_username $sql_password $sql_database ){ chomp; ($key,$val)=(split /:\s*/,$_); + $sql_type = $val if ($key eq 'sql_type'); $sql_server = $val if ($key eq 'sql_server'); $sql_username = $val if ($key eq 'sql_username'); $sql_password = $val if ($key eq 'sql_password'); $sql_database = $val if ($key eq 'sql_database'); $sql_accounting_table = $val if ($key eq 'sql_accounting_table'); - $mysql = $val if ($key eq 'sql_command'); + $sqlcmd = $val if ($key eq 'sql_command'); } close CONF; -die "sql_command directive is not set in admin.conf\n" if ($mysql eq ''); -die "Could not find mysql binary. Please make sure that the \$mysql variable points to the right location\n" if (! -x $mysql); +die "sql_command directive is not set in admin.conf\n" if ($sqlcmd eq ''); +die "Could not find sql binary. Please make sure that the \$sqlcmd variable points to the right location\n" if (! -x $sqlcmd); $sql_password = ($sql_password eq '') ? '' : "-p$sql_password"; ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime; $date = POSIX::strftime("%Y-%m-%d %T",$sec,$min,$hour,($mday - $back_days),$mon,$year,$wday,$yday,$isdst); print "$date\n"; - -$query = "LOCK TABLES $sql_accounting_table WRITE;"; -$query .= "DELETE FROM $sql_accounting_table WHERE AcctStopTime < '$date' AND AcctStopTime != 0;"; -$query .= "UNLOCK TABLES;"; +$query = ""; +$query = "LOCK TABLES $sql_accounting_table WRITE;" if ($sql_type eq 'mysql'); +$query .= "DELETE FROM $sql_accounting_table WHERE AcctStopTime < '$date' AND AcctStopTime IS NOT NULL ;"; +$query .= "UNLOCK TABLES;" if ($sql_type eq 'mysql'); print "$query\n"; open TMP, ">/tmp/truncate_radacct.query" or die "Could not open tmp file\n"; print TMP $query; close TMP; -`$mysql -h$sql_server -u$sql_username $sql_password $sql_database $config[$name]\n"; + $ip = $config[$name_ip]; + $name = $config[$name]; + $servers[$name] = $ip; +} +ksort($servers); +foreach ($servers as $name => $ip){ + if ($server == $ip) + echo "