Index: trunk/assign.html
===================================================================
--- trunk/assign.html	(revision 316)
+++ trunk/assign.html	(revision 320)
@@ -29,5 +29,7 @@
 </td>
 </tr><tr class="color2">
-<td>Route/allocate from this master:&nbsp;</td><td>$$MASTERLIST$$</td>
+<td>Route/allocate from this master:&nbsp;</td><td>$$MASTERLIST$$
+Allow automatic allocation from private IP ranges:<input type=checkbox name=allowpriv>
+</td>
 </tr><tr class="color1">
 <td>Circuit ID:&nbsp;</td><td><input name=circid size=40></td>
Index: trunk/cgi-bin/IPDB.pm
===================================================================
--- trunk/cgi-bin/IPDB.pm	(revision 316)
+++ trunk/cgi-bin/IPDB.pm	(revision 320)
@@ -7,5 +7,5 @@
 # Last update by $Author$
 ###
-# Copyright (C) 2004,2005 - Kris Deugau
+# Copyright (C) 2004-2006 - Kris Deugau
 
 package IPDB;
Index: trunk/cgi-bin/MyIPDB.pm
===================================================================
--- trunk/cgi-bin/MyIPDB.pm	(revision 316)
+++ trunk/cgi-bin/MyIPDB.pm	(revision 320)
@@ -8,5 +8,5 @@
 # Last update by $Author$
 ###
-# Copyright (C) 2004,2005 - Kris Deugau
+# Copyright (C) 2004-2006 - Kris Deugau
 
 use IPDB 2.0 qw(:ALL);
Index: trunk/cgi-bin/admin.cgi
===================================================================
--- trunk/cgi-bin/admin.cgi	(revision 316)
+++ trunk/cgi-bin/admin.cgi	(revision 320)
@@ -10,5 +10,5 @@
 # Last update by $Author$
 ###
-# Copyright (C) 2004,2005 - Kris Deugau
+# Copyright (C) 2004-2006 - Kris Deugau
 
 use strict;
@@ -92,4 +92,8 @@
 <hr><a href="admin.cgi?action=showusers">Manage users</a> (add/remove users;  change
 internal access controls - note that this does NOT include IP-based limits)
+<hr>Consistency check tools<br>
+<a href="consistency-check.pl">General</a>:  Check general netblock consistency.<br>
+<a href="freespace.pl">Free space</a>:  List total and aggregate free space.  Does not 
+include private networks (192.168.0.0/16, 172.16.0.0/12, 10.0.0.0/8)
 );
 } else {
@@ -295,4 +299,5 @@
   print "Notes:<br>\n".
 	"<li>Admin users automatically get all other priviledges.\n".
+	"<li>Everyone has basic read access.\n".
 	"<hr>Add new user:<form action=admin.cgi method=POST>\n".
 	"Username: <input name=username><br>\n".
Index: trunk/cgi-bin/freespace.pl
===================================================================
--- trunk/cgi-bin/freespace.pl	(revision 316)
+++ trunk/cgi-bin/freespace.pl	(revision 320)
@@ -8,5 +8,5 @@
 # Last update by $Author$
 ###
-# Copyright (C) 2004,2005 - Kris Deugau
+# Copyright (C) 2004-2006 - Kris Deugau
 
 use DBI;
@@ -20,10 +20,15 @@
 $tnumfree = $bigrfree = $bigufree = 0;
 
+$sql = 'select * from freeblocks where ';
 # General counts first
 if ($ARGV[0]) {
-  $sth = $dbh->prepare("select * from freeblocks where maskbits >= $ARGV[0] order by maskbits desc");
-} else {
-  $sth = $dbh->prepare("select * from freeblocks order by maskbits desc");
+  $sql .= 'maskbits >= $ARGV[0] and ';
 }
+$sql .= "not (cidr <<= '192.168.0.0/16') ".
+		"and not (cidr <<= '172.16.0.0/12') ".
+		"and not (cidr <<= '10.0.0.0/8') ";
+$sql .= "order by maskbits desc";
+
+$sth = $dbh->prepare($sql);
 $sth->execute;
 while (@data = $sth->fetchrow_array) {
@@ -33,4 +38,5 @@
 }
 
+print "Free block counts:\n";
 foreach $size (sort {$a cmp $b} keys %numfree) {
   print "/$size: $numfree{$size}\n";
@@ -44,4 +50,5 @@
 }
 
+print "Aggregate free space:\n";
 foreach $size (sort {$a cmp $b} keys %numfree) {
   print "/$size: $numfree{$size}\n";
Index: trunk/cgi-bin/main.cgi
===================================================================
--- trunk/cgi-bin/main.cgi	(revision 316)
+++ trunk/cgi-bin/main.cgi	(revision 320)
@@ -103,8 +103,9 @@
 
     if ($@) {
-      carp "Transaction aborted because $@";
+      my $msg = $@;
+      carp "Transaction aborted because $msg";
       eval { $ip_dbh->rollback; };
-      syslog "err", "Could not add master block '$webvar{cidr}' to database: '$@'";
-      printError("Could not add master block $webvar{cidr} to database: $@");
+      syslog "err", "Could not add master block '$webvar{cidr}' to database: '$msg'";
+      printError("Could not add master block $webvar{cidr} to database: $msg");
     } else {
       print "<div type=heading align=center>Success!</div>\n";
@@ -414,8 +415,8 @@
 	qq($master ($data[0]):</div></center><br>\n);
 
-  startTable('CIDR allocation','Customer Location','Type','CustID','Description/Name');
+  startTable('CIDR allocation','Customer Location','Type','CustID','SWIPed?','Description/Name');
 
   # Snag the allocations for this block
-  $sth = $ip_dbh->prepare("select cidr,city,type,custid,description".
+  $sth = $ip_dbh->prepare("select cidr,city,type,custid,swip,description".
 	" from allocations where cidr <<= '$master' order by cidr");
   $sth->execute();
@@ -423,5 +424,5 @@
   my $count=0;
   while (my @data = $sth->fetchrow_array()) {
-    # cidr,city,type,custid,description, as per the SELECT
+    # cidr,city,type,custid,swip,description, as per the SELECT
     my $cidr = new NetAddr::IP $data[0];
 
@@ -432,5 +433,6 @@
     my @row = ( (($data[2] =~ /^.r$/) ? 'Sub ' : '').
 	qq(<a href="/ip/cgi-bin/main.cgi?action=edit&block=$data[0]">$data[0]</a>),
-	$data[1], $disp_alloctypes{$data[2]}, $data[3], $data[4]);
+	$data[1], $disp_alloctypes{$data[2]}, $data[3], 
+	($data[4] eq 'y' ? 'Yes' : 'No'), $data[5]);
     # If the allocation is a pool, allow listing of the IPs in the pool.
     if ($data[2] =~ /^.[pd]$/) {
@@ -710,11 +712,20 @@
       my $city;
       my $failmsg;
+      my $extracond = '';
+      if ($webvar{allocfrom} eq '-') {
+	$extracond = ($webvar{allowpriv} eq 'on' ? '' : 
+		" and not (cidr <<= '192.168.0.0/16'".
+			" or cidr <<= '10.0.0.0/8'".
+			" or cidr <<= '172.16.0.0/12')");
+      }
+      my $sortorder;
       if ($webvar{alloctype} eq 'rm') {
         if ($webvar{allocfrom} ne '-') {
 	  $sql = "select * from freeblocks where maskbits<=$webvar{maskbits} and routed='n'".
-		" and cidr <<= '$webvar{allocfrom}' order by maskbits desc";
+		" and cidr <<= '$webvar{allocfrom}'";
+	  $sortorder = "maskbits desc";
 	} else {
-	  $sql = "select * from freeblocks where maskbits<=$webvar{maskbits} and routed='n'".
-		" order by maskbits desc";
+	  $sql = "select * from freeblocks where maskbits<=$webvar{maskbits} and routed='n'";
+	  $sortorder = "maskbits desc";
 	}
 	$failmsg = "No suitable free block found.<br>\nWe do not have a free".
@@ -745,11 +756,13 @@
 	  $sql = "select cidr from freeblocks where city='$city' and maskbits<=$webvar{maskbits}".
 		" and cidr <<= '$webvar{allocfrom}' and routed='".
-		(($webvar{alloctype} =~ /^(.)r$/) ? "$1" : 'y')."' order by maskbits desc,cidr";
+		(($webvar{alloctype} =~ /^(.)r$/) ? "$1" : 'y')."'";
+	  $sortorder = "maskbits desc,cidr";
 	} else {
 	  $sql = "select cidr from freeblocks where city='$city' and maskbits<=$webvar{maskbits}".
-		" and routed='".(($webvar{alloctype} =~ /^(.)r$/) ? "$1" : 'y').
-		"' order by maskbits desc,cidr";
+		" and routed='".(($webvar{alloctype} =~ /^(.)r$/) ? "$1" : 'y')."'";
+	  $sortorder = "maskbits desc,cidr";
 	}
       }
+      $sql = $sql.$extracond." order by ".$sortorder;
       $sth = $ip_dbh->prepare($sql);
       $sth->execute;
@@ -914,5 +927,7 @@
   } else {
     # New!  Improved!  And now Loaded From The Database!!
-    $webvar{custid} = $def_custids{$webvar{alloctype}};
+    if ((!$webvar{custid}) || ($webvar{custid} ne 'STAFF')) {
+      $webvar{custid} = $def_custids{$webvar{alloctype}};
+    }
   }
 
@@ -929,9 +944,9 @@
   } else {
     $flag = 'n';
-    if ($webvar{alloctype} =~ /[wp][cr]|[ds][pi]/) {
+    if ($webvar{alloctype} =~ /[wp][cr]|d[pi]/) {
       # Set this forcibly rather than messing around elsewhere.  Yes, this *is* a hack.  PTHBTT!!
-      $webvar{pop} = 'Sudbury';
-    }
-    if ($webvar{pop} =~ /^-$/) {
+      # Match CORE/WAN types (wc, wr, pc, pr), DSL pool and IP (dp, di).
+      $webvar{pop} = "Sudbury";
+    } elsif ($webvar{pop} =~ /^-$/) {
       $flag = 'to route the block from/through';
     }
@@ -957,7 +972,7 @@
   # because I'm lazy, we'll try to make the SELECT's bring out identical)ish) data
   if ($webvar{block} =~ /\/32$/) {
-    $sql = "select ip,custid,type,city,circuitid,description,notes,modifystamp,privdata from poolips where ip='$webvar{block}'";
+    $sql = "select ip,custid,type,city,circuitid,description,notes,modifystamp,privdata,oldcustid from poolips where ip='$webvar{block}'";
   } else {
-    $sql = "select cidr,custid,type,city,circuitid,description,notes,modifystamp,privdata from allocations where cidr='$webvar{block}'"
+    $sql = "select cidr,custid,type,city,circuitid,description,notes,modifystamp,privdata,oldcustid,swip from allocations where cidr='$webvar{block}'"
   }
 
@@ -1006,4 +1021,5 @@
       $html =~ s/\$\$TYPESELECT\$\$/$disp_alloctypes{$data[2]}<input type=hidden name=alloctype value="$data[2]">/g;
     }
+    $html =~ s/\$\$OLDCUSTID\$\$/$data[9]/g;
     $html =~ s/\$\$CITY\$\$/<input type=text name=city value="$data[3]">/g;
     $html =~ s/\$\$CIRCID\$\$/<input type="text" name="circid" value="$data[4]" maxlength=64 size=64 class="regular">/g;
@@ -1012,4 +1028,5 @@
   } else {
     $html =~ s/\$\$CUSTID\$\$/$data[1]/g;
+    $html =~ s/\$\$OLDCUSTID\$\$/$data[9]/g;
     $html =~ s/\$\$TYPESELECT\$\$/$disp_alloctypes{$data[2]}/g;
     $html =~ s/\$\$CITY\$\$/$data[3]/g;
@@ -1020,4 +1037,13 @@
   my ($lastmod,undef) = split /\s+/, $data[7];
   $html =~ s/\$\$LASTMOD\$\$/$lastmod/g;
+
+## Hack time!  SWIP isn't going to stay, so I'm not going to integrate it with ACLs.
+if ($data[2] =~ /.i/) {
+  $html =~ s/\$\$SWIP\$\$/N\/A/;
+} else {
+  my $tmp = (($data[10] eq 'n') ? '<input type=checkbox name=swip>' : 
+	'<input type=checkbox name=swip checked=yes>');
+  $html =~ s/\$\$SWIP\$\$/$tmp/;
+}
 
   # Allows us to "correctly" colour backgrounds in table
@@ -1091,5 +1117,6 @@
       $sql = "update allocations set custid='$webvar{custid}',".
 	"description='$webvar{desc}',notes='$webvar{notes}',city='$webvar{city}',".
-	"type='$webvar{alloctype}',circuitid='$webvar{circid}'$privdata ".
+	"type='$webvar{alloctype}',circuitid='$webvar{circid}'$privdata,".
+	"swip='".($webvar{swip} eq 'on' ? 'y' : 'n')."' ".
 	"where cidr='$webvar{block}'";
     }
@@ -1115,4 +1142,5 @@
   my $html = join('', <HTML>);
 
+my $swiptmp = ($webvar{swip} eq 'on' ? 'Yes' : 'No');
   $html =~ s/\$\$BLOCK\$\$/$webvar{block}/g;
   $webvar{city} = desanitize($webvar{city});
@@ -1121,4 +1149,5 @@
   $html =~ s/\$\$TYPEFULL\$\$/$disp_alloctypes{$webvar{alloctype}}/g;
   $html =~ s/\$\$CUSTID\$\$/$webvar{custid}/g;
+  $html =~ s/\$\$SWIP\$\$/$swiptmp/g;
   $webvar{circid} = desanitize($webvar{circid});
   $html =~ s/\$\$CIRCID\$\$/$webvar{circid}/g;
Index: trunk/cgi-bin/search.cgi
===================================================================
--- trunk/cgi-bin/search.cgi	(revision 316)
+++ trunk/cgi-bin/search.cgi	(revision 320)
@@ -9,5 +9,5 @@
 # Last update by $Author$
 ###
-# Copyright 2005 Kris Deugau <kdeugau@deepnet.cx>
+# Copyright 2005,2006 Kris Deugau
 
 use strict;		
@@ -106,4 +106,5 @@
   # First chunk of SQL.  Filter on custid, description, and notes as necessary.
   my $sql = "(select $cols from searchme where $webvar{custexclude} custid ilike '%$webvar{custid}%')".
+	" $sqlconcat $webvar{custexclude} oldcustid ilike '%$webvar{custid}%')".
 	" $sqlconcat (select $cols from searchme where $webvar{descexclude} description ilike '%$webvar{desc}%')".
 	" $sqlconcat (select $cols from searchme where $webvar{notesexclude} notes ilike '%$webvar{notes}%')";
@@ -283,5 +284,5 @@
     # Query for a customer ID.  Note that we can't restrict to "numeric-only"
     # as we have non-numeric custIDs in the legacy data.  :/
-    $sql = "select * from searchme where custid ilike '%$query%'";
+    $sql = "select * from searchme where custid ilike '%$query%' or oldcustid ilike '%$query%'";
     my $count = countRows($sql);
     $sql .= " order by cidr limit $RESULTS_PER_PAGE offset $offset";
Index: trunk/editDisplay.html
===================================================================
--- trunk/editDisplay.html	(revision 316)
+++ trunk/editDisplay.html	(revision 320)
@@ -13,4 +13,7 @@
 
 <tr class="color2"><td class=heading>CustID:</td><td class="regular">$$CUSTID$$</td></tr>
+<tr class="color2"><td class=heading>Old CustID:</td><td class="regular">$$OLDCUSTID$$</td></tr>
+
+<tr class="color2"><td class=heading>SWIPed?:</td><td class=regular>$$SWIP$$</td></tr>
 
 <tr class="color1"><td class=heading>Last modified:</td><td class=regular>$$LASTMOD$$</td></tr>
Index: trunk/updated.html
===================================================================
--- trunk/updated.html	(revision 316)
+++ trunk/updated.html	(revision 320)
@@ -6,4 +6,5 @@
 <tr class="color1"><td>Type:</td><td>$$TYPEFULL$$</td></tr> 
 <tr class="color2"><td>Customer ID:</td><td>$$CUSTID$$</td></tr>
+<tr class="color2"><td>SWIPed?:</td><td>$$SWIP$$</td></tr>
 <tr class="color1"><td>Circuit ID:</td><td>$$CIRCID$$</td></tr>
 <tr class="color2"><td valign="top">Description/Name:</td><td>$$DESC$$</td></tr>
