Dial-up Admin patches

Scott Lambert lambert at lambertfam.org
Thu Oct 11 00:51:00 CEST 2007


These patches:

1) Let dialup_admin/bin/log_badlogins read the NAS table from SQL.

2) Make dialup_admin/bin/log_badlogins record the bad password in the
   callerid field.

    It is very useful for my support technicians to be able to look at
    the failed logins table and determine how the user has mis-typed
    their password, and the caller id field seemed to have the available
    chars.

3) Change the sort order in dialup_admin/htdocs/accounting.php3 so that
   the most recent entries are at the top.  This usually prevents a lot of
   scrolling for my techs.

4) Remember the server for which we are showing stats on
   dialup_admin/htdocs/stats.php3 so that the techs doesn't have to reselect
   the NAS option every time the refresh the page.

5) Fix the html in dialup_admin/htdocs/user_finger.php3 so that NAS
   farther down the page do not get farther and farther apart.

6) MySQL 5 did not like the "DEFAULT '0'" for the auto-increment id
   fields in dialup_admin/sql/mysql/(badusers|userinfo).sql.  I simply
   removed that phrase.  Additionally, badusers.sql had a KEY defined on
   a Date column which apparanlty has been renamed to IncidentDate.

I think thats about it for this patch set.

Would it be an evil thing to repo-mv *.php3 to *.php and update the code
to follow?

Has anybody done any work toward making dialup_admin run under PHP5?  It
appears that PHP4 is on it's last legs.  I'm not sure I can do it in a
reasonable amount of time since to me "PHP is just this language, you
know?"  If I can't do it quickly, I probably won't get a chance to do
it.

-- 
Scott Lambert                    KC5MLE                       Unix SysAdmin
lambert at lambertfam.org


Yes, that was a HHGTTG reference.
-------------- next part --------------
diff -ru dialup_admin/bin/log_badlogins /usr/local/dialup_admin.working/bin/log_badlogins
--- dialup_admin/bin/log_badlogins	Mon May 14 17:27:26 2007
+++ /usr/local/dialup_admin.working/bin/log_badlogins	Sun Sep  2 13:12:44 2007
@@ -47,6 +47,7 @@
 	$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');
+	$sql_nas_table = $val if ($key eq 'sql_nas_table');
 	$realm_strip = $val if ($key eq 'general_strip_realms');
 	$realm_del = $val if ($key eq 'general_realm_delimiter');
 	$realm_for = $val if ($key eq 'general_realm_format');
@@ -112,6 +113,24 @@
 @servers = (split /\s+/,$sql_extra) if ($sql_extra ne '');
 unshift @servers, $sql_server;
 
+if ( $sql_use_nas_table = "true" ) {
+	my $query = "SELECT shortname, nasname from $sql_nas_table;";
+	$sqlclientscommand = "$sqlcmd -h$sql_server $opt -u $sql_username $pass -e \"$query\" $sql_database";
+
+	open (SQLCLIENTS, "$sqlclientscommand |") || die "sqlclients: $!";
+	while (<SQLCLIENTS>) {
+		chop;
+		s/shortname.*//o;
+		next unless length;
+		($client_short, $name) = split /\s+/;
+		$addr = gethostbyname $name;
+		($a,$b,$c,$d)=unpack('C4',$addr);
+		$client = "$a.$b.$c.$d";
+		$client_array{$client_short} = $client;
+	}
+}
+
+
 open LOG, "<$file"
 	or die "Could not open file $file\n";
 if ($verbose > 1) { print STDOUT "DEBUG: Opened $file\n" }
@@ -124,7 +143,7 @@
 		chomp;
 		next if ($regexp ne '' && !/$regexp/);
 		if ($_ ne ''){
-			$user = $nas = $port = $caller = '-';
+			$user = $badpass = $nas = $port = $caller = '-';
 			if (/Login incorrect/){
 				if (/Login incorrect \((.+?)\):/){
 					$cause = "Login-Incorrect ($1)";
@@ -169,12 +188,14 @@
 						$caller = $1;
 					}
 				}
-				elsif (/\[([\w\-\.\!\@\s]+?)\/.+?\]\s+\(from (.+?)\)/){
+				elsif (/\[([\w\-\.\!\@\s]+?)\/(.+)?\]\s+\(from (.+?)\)/){
 					$user = $1;
-					($nas,$port) = (split /\s+/,$2)[1,3];
+					$badpass = $2;
+					($nas,$port) = (split /\s+/,$3)[1,3];
 					if ($2 =~ /cli (.+?)$/){
 						$caller = $1;
 					}
+					$caller = $caller . " " . $badpass;
 				}
 				$caller='' if (!defined($caller));
 				$user =~s/[^\w\-\.\d\!\@\s]//g;
diff -ru dialup_admin/htdocs/accounting.php3 /usr/local/dialup_admin.working/htdocs/accounting.php3
--- dialup_admin/htdocs/accounting.php3	Mon May 14 17:27:26 2007
+++ /usr/local/dialup_admin.working/htdocs/accounting.php3	Sun Sep  2 12:43:52 2007
@@ -240,7 +240,7 @@
 	$sql_extra_query = da_sql_escape_string($sql_extra_query);
 $query="SELECT " . da_sql_limit($maxresults,0,$config) . " $query_view FROM $config[sql_accounting_table]
 	$where $sql_extra_query " . da_sql_limit($maxresults,1,$config) .
-	" ORDER BY $order " . da_sql_limit($maxresults,2,$config) . ";";
+	" ORDER BY $order DESC" . da_sql_limit($maxresults,2,$config) . ";";
 
 echo <<<EOM
 <html>
diff -ru dialup_admin/htdocs/stats.php3 /usr/local/dialup_admin.working/htdocs/stats.php3
--- dialup_admin/htdocs/stats.php3	Mon May 14 17:27:28 2007
+++ /usr/local/dialup_admin.working/htdocs/stats.php3	Tue Sep  4 09:59:51 2007
@@ -94,6 +94,9 @@
 	$server = da_sql_escape_string($server);
 	$s = "AND nasipaddress = '$server'";
 }
+if ($server == '') {
+	$server = 'all';
+}
 $sql_extra_query = '';
 if ($config[sql_accounting_extra_query] != '')
 	$sql_extra_query = xlat($config[sql_accounting_extra_query],$login,$config);
diff -ru dialup_admin/htdocs/user_finger.php3 /usr/local/dialup_admin.working/htdocs/user_finger.php3
--- dialup_admin/htdocs/user_finger.php3	Tue Apr  5 08:32:23 2005
+++ /usr/local/dialup_admin.working/htdocs/user_finger.php3	Mon Sep  3 01:15:53 2007
@@ -178,7 +178,7 @@
 	<th align=left>$server_name[$j]<br><font color="green">$server_model[$j]</font></th><th align=right><font color="red">$server_loggedin[$j] users connected</font></th><th><font color="green">$server_rem[$j] $config[general_caption_finger_free_lines]</font></th>
 	</tr>
 	</table>
-	<div height="$height[$j]" style="height:$height[$j]">
+	<!-- <div height="$height[$j]" style="height:$height[$j]"> -->
 	<table border=1 bordercolordark=#ffffe0 bordercolorlight=#000000 width=100% cellpadding=2 cellspacing=0 bgcolor="#ffffe0" valign=top>
 	<tr bgcolor="#d0ddb0">
 	<th>#</th><th>user</th>
@@ -212,7 +212,8 @@
 
 	echo <<<EOM
 	</table>
-	</div>
+</p>
+	<!-- </div> -->
 EOM;
 }
 ?>
@@ -220,5 +221,4 @@
 	</table>
 </td></tr>
 </table>
-<p>
 </html>
diff -ru dialup_admin/html/stats.html.php3 /usr/local/dialup_admin.working/html/stats.html.php3
--- dialup_admin/html/stats.html.php3	Mon May 14 17:27:29 2007
+++ /usr/local/dialup_admin.working/html/stats.html.php3	Tue Sep  4 10:00:11 2007
@@ -19,9 +19,11 @@
 		<td valign=middle><select name="server" size=1>
 EOM;
 foreach($servers as $key => $val)
-	echo <<<EOM
-	<option value="$val">$key
-EOM;
+	if ($val == $server) {
+		echo "<option selected value=\"$val\">$key";
+	} else {
+		echo "<option value=\"$val\">$key";
+	}
 ?>
 		</select></td>
 		<td valign=middle><input type="submit" class=button value="Go"></td>
diff -ru dialup_admin/sql/mysql/badusers.sql /usr/local/dialup_admin.working/sql/mysql/badusers.sql
--- dialup_admin/sql/mysql/badusers.sql	Mon Mar 21 11:05:17 2005
+++ /usr/local/dialup_admin.working/sql/mysql/badusers.sql	Tue Aug 14 15:27:34 2007
@@ -2,12 +2,12 @@
 # Table structure for table 'badusers'
 #
 CREATE TABLE badusers (
-  id int(10) DEFAULT '0' NOT NULL auto_increment,
+  id int(10) NOT NULL auto_increment,
   UserName varchar(30),
   IncidentDate	datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
   Reason varchar(200),
   Admin varchar(30) DEFAULT '-',
   PRIMARY KEY (id),
   KEY UserName (UserName),
-  KEY Date (Date)
+  KEY IncidentDate (IncidentDate)
 );
diff -ru dialup_admin/sql/mysql/userinfo.sql /usr/local/dialup_admin.working/sql/mysql/userinfo.sql
--- dialup_admin/sql/mysql/userinfo.sql	Mon Sep 13 04:37:17 2004
+++ /usr/local/dialup_admin.working/sql/mysql/userinfo.sql	Tue Aug 14 15:26:21 2007
@@ -2,7 +2,7 @@
 # Table structure for table 'userinfo'
 #
 CREATE TABLE userinfo (
-  id int(10) DEFAULT '0' NOT NULL auto_increment,
+  id int(10) NOT NULL auto_increment,
   UserName varchar(30),
   Name varchar(200),
   Mail varchar(200),


More information about the Freeradius-Devel mailing list