]> git.entuzijast.net Git - freeradius-dialup-admin.git/commitdiff
* Sort the servers list in failed_logins,user_stats,stats
authorkkalev <kkalev>
Sat, 3 Apr 2004 20:42:29 +0000 (20:42 +0000)
committerkkalev <kkalev>
Sat, 3 Apr 2004 20:42:29 +0000 (20:42 +0000)
* Add the /bin postgresql compatibility patch from Guy Fraser

14 files changed:
Changelog
bin/Changelog.GuyFraser [new file with mode: 0644]
bin/clean_radacct
bin/dialup_admin.cron [new file with mode: 0644]
bin/log_badlogins
bin/monthly_tot_stats
bin/showmodem
bin/snmpfinger
bin/tot_stats
bin/truncate_radacct
conf/admin.conf
htdocs/failed_logins.php3
htdocs/stats.php3
htdocs/user_stats.php3

index 9f282a55f47aa475b161e871b0d7c0683310fa5f..3f15eb7657973ad50062a4bb385b6a93f638a06e 100644 (file)
--- 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 (file)
index 0000000..bb6e1f2
--- /dev/null
@@ -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.
index 339ba512c151d7fa2f6053d82bf7ed6762cc3ba3..2dbd11799cd9e67a151e2b0eee3b039dca9bc4c6 100755 (executable)
@@ -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(<CONF>){
        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 </tmp/clean_radacct.query`;
+$command = "$sqlcmd -h$sql_server -u$sql_username $sql_password $sql_database </tmp/clean_radacct.query" if ($sql_type eq 'mysql');
+$command = "$sqlcmd  -U $sql_username -f /tmp/clean_radacct.query $sql_database" if ($sql_type eq 'pg');
+`$command`;
diff --git a/bin/dialup_admin.cron b/bin/dialup_admin.cron
new file mode 100644 (file)
index 0000000..bc1cee2
--- /dev/null
@@ -0,0 +1,4 @@
+1 0 * * * /usr/local/dialup_admin/bin/tot_stats >/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
index 5301e12c3d013a37a7c7c60aac327aed14d0522e..42660e2084b16d8cbcc432b3b26a7e5224291259 100755 (executable)
@@ -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(<CONF>){
        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(<CONF>){
        $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(<CLIENTS>){
+       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);
+       }
 }
index 79a976eaee7021ae4e5fa2e2dd1e03befc332ad4..533cc98d813b808685b4d5495e54b8caff7cc28b 100755 (executable)
@@ -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(<CONF>){
        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 </tmp/tot_stats.query`;
+$command = "$sqlcmd -h $sql_server -u $sql_username $sql_password $sql_database </tmp/tot_stats.query" if ($sql_type eq 'mysql');
+$command = "$sqlcmd  -U $sql_username -f /tmp/tot_stats.query $sql_database" if ($sql_type eq 'pg');
+`$command`;
index e7a4f8f925efe12611797c5d3cfc5f01a1d122fc..08c73e5bd5f6b707ba09d7e58c0a2aaa0f5b8c49 100755 (executable)
@@ -1,12 +1,36 @@
 #!/usr/bin/perl
+#
+# This works with Net-SNMP and UCD-SNMP
 
-$snmpget="/usr/local/bin/snmpget";
-$snmpwalk="/usr/local/bin/snmpwalk";
-$nas=shift;
+$host=shift;
 $user=shift;
-$com=shift || "public";
+$comm=shift || "public";
 $type=shift|| "xml";
 
+$conf='/usr/local/dialup_admin/conf/admin.conf';
+open CONF, "<$conf"
+       or die "Could not open configuration file\n";
+while(<CONF>){
+       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>$modulation</Modulation><Protocol>$protocol</Protocol><TxRate>$txrate</TxRate><RxRate>$rxrate</RxRate><RxSignal>$rxsignal</RxSignal>\n";
-
+    print "<User>$user</User>\n";
+    print "\t<Duration>$duration</Duration>\n";
+    print "\t<Modulation>$modulation</Modulation>\n";
+    print "\t<Protocol>$protocol</Protocol>\n";
+    print "\t<TxRate>$txrate</TxRate>\n";
+    print "\t<RxRate>$rxrate</RxRate>\n";
+    print "\t<RxSignal>$rxsignal dBm</RxSignal>\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);
   }
 }
index 77d836893ddb3fc205384160a63ab988c7958269..68a7cade275116bf8e02ee9f9a5373f023ad415e 100755 (executable)
@@ -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(<CONF>){
+       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){
index ca4149bb6428278672fc268102e4f8e00ad71d1e..f3a3e07599e520b336f8d9b211fd2b4c063249ef 100755 (executable)
@@ -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(<CONF>){
        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 </tmp/tot_stats.query`;
+$command = "$sqlcmd -h $sql_server -u $sql_username $sql_password $sql_database </tmp/tot_stats.query" if ($sql_type eq 'mysql');
+$command = "$sqlcmd  -U $sql_username -f /tmp/tot_stats.query $sql_database" if ($sql_type eq 'pg');
+`$command`;
index 4176616c0c97b5ca4d7cbe4f4b4b869eb5dbbb5b..6df9e49d906794cf0ed97bdf2f15cd09c0849c2e 100755 (executable)
@@ -2,6 +2,7 @@
 #
 # Delete sessions from the radacct table which are older than
 # $back_days
+# Works with mysql and postgresql
 #
 use POSIX;
 
@@ -14,30 +15,33 @@ open CONF, "<$conf"
 while(<CONF>){
        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 </tmp/truncate_radacct.query`;
+$command = "$sqlcmd -h$sql_server -u$sql_username $sql_password $sql_database </tmp/truncate_radacct.query" if ($sql_type eq 'mysql');
+$command = "$sqlcmd  -U $sql_username -f /tmp/truncate_radacct.query $sql_database" if ($sql_type eq 'pg');
+`$command`;
index 561b6d6547fdc2b023f57e9d7b18b704df7ca1e0..6fefb56e682339a4ce499e7a9d628a9878e065d3 100644 (file)
@@ -63,8 +63,11 @@ general_realm_format: suffix
 # the user edit page
 general_show_user_password: yes
 
-
-general_ldap_attrmap: %{general_radiusd_base_dir}/etc/raddb/ldap.attrmap
+general_raddb_dir: %{general_radiusd_base_dir}/etc/raddb
+general_ldap_attrmap: %{general_raddb_dir}/ldap.attrmap
+# Need to fix admin.conf file parser
+#general_clients_conf: %{general_raddb_dir}/clients.conf
+general_clients_conf: /usr/local/etc/raddb/clients.conf
 general_sql_attrmap: %{general_base_dir}/conf/sql.attrmap
 general_accounting_attrs_file: %{general_base_dir}/conf/accounting.attrs
 general_extra_ldap_attrmap: %{general_base_dir}/conf/extra.ldap-attrmap
@@ -217,9 +220,17 @@ sql_total_accounting_table: totacct
 #
 # This variable is used by the scripts in the bin folder
 # It should contain the path to the sql binary used to run
-# sql commands (mysql is only supported for now)
+# sql commands (mysql and psql are only supported for now)
 sql_command: /usr/local/bin/mysql
 #
+# This variable is used by the scripts in the bin folder
+# It should contain the snmp type and  path to the binary 
+# used to run snmp commands. 
+# (ucd = UCD-Snmp and net = Net-Snmp are only supported for now)
+general_snmp_type: net
+general_snmpwalk_command: /usr/local/bin/snmpwalk
+general_snmpget_command: /usr/local/bin/snmpget
+#
 # Uncomment to enable sql debug
 #
 #sql_debug: true
index a4436c00c3f2a7d9fec1ce54cd002a9fd22897fb..2cf1ff6abe43a24c57f9b40cb04591ea5dfc8c26 100644 (file)
@@ -193,13 +193,21 @@ while(1){
                break;
        }
        $name_ip = 'nas' . $i . '_ip';
-       if ($server == $config[$name_ip])
-               echo "<option selected value=\"$config[$name_ip]\">$config[$name]\n";
+       $ip = $config[$name_ip];
+       $name = $config[$name];
+       $servers[$name] = $ip;
+}
+ksort($servers);
+foreach ($servers as $name => $ip){
+       if ($server == $ip)
+               echo "<option selected value=\"$ip\">$name\n";
        else
-               echo "<option value=\"$config[$name_ip]\">$config[$name]\n";
+               echo "<option value=\"$ip\">$name\n";
 }
 if ($server == '' || $server == 'all')
        echo "<option selected value=\"all\">all\n";
+else
+       echo "<option value=\"all\">all\n";
 ?>
 </select>
 </td></tr>
index 806846e28bbe8a58dc6a6d0a93c7bb6d1648c880..f4f89940e719c17d0393839a27ed256e5db67cf4 100644 (file)
@@ -89,6 +89,7 @@ while(1){
        $servers[$name] = $config[$ip];
        $i++;
 }
+ksort($servers);
 if ($server != 'all' && $server != '')
        $s = "AND nasipaddress = '$server'";
 
index 786ddb2408971e18ff498b4adc8f0e3278a95913..06112c373b7357e9297802a7c2d71f74471fcd27 100644 (file)
@@ -190,13 +190,21 @@ while(1){
                break;
        }
        $name_ip = 'nas' . $i . '_ip';
-       if ($server == $config[$name_ip])
-               echo "<option selected value=\"$config[$name_ip]\">$config[$name]\n";
+       $ip = $config[$name_ip];
+       $name = $config[$name];
+       $servers[$name] = $ip;
+}
+ksort($servers);
+foreach ($servers as $name => $ip){
+       if ($server == $ip])
+               echo "<option selected value=\"$ip\">$name\n";
        else
-               echo "<option value=\"$config[$name_ip]\">$config[$name]\n";
+               echo "<option value=\"$ip\">$name\n";
 }
 if ($server == '' || $server == 'all')
        echo "<option selected value=\"all\">all\n";
+else
+       echo "<option value=\"all\">all\n";
 ?>
 </select>
 </td>