Index: branches/stable/cgi-bin/ipdb.psql
===================================================================
--- branches/stable/cgi-bin/ipdb.psql	(revision 71)
+++ branches/stable/cgi-bin/ipdb.psql	(revision 75)
@@ -23,32 +23,5 @@
 
 --
--- TOC Entry ID 2 (OID 25848)
---
--- Name: allocations Type: TABLE Owner: ipdb
---
-
-CREATE TABLE "allocations" (
-	"cidr" cidr DEFAULT '255.255.255.255/32' NOT NULL,
-	"custid" character varying(16) DEFAULT '',
-	"type" character(2) DEFAULT '',
-	"city" character varying(30) DEFAULT '',
-	"description" character varying(64) DEFAULT '',
-	"notes" text,
-	"maskbits" integer DEFAULT 128,
-	Constraint "allocations_pkey" Primary Key ("cidr")
-);
-
---
--- TOC Entry ID 3 (OID 25848)
---
--- Name: allocations Type: ACL Owner: 
---
-
-REVOKE ALL on "allocations" from PUBLIC;
-GRANT ALL on "allocations" to "kdeugau";
-GRANT ALL on "allocations" to "ipdb";
-
---
--- TOC Entry ID 4 (OID 25854)
+-- TOC Entry ID 2 (OID 25854)
 --
 -- Name: customers Type: TABLE Owner: ipdb
@@ -71,5 +44,5 @@
 
 --
--- TOC Entry ID 5 (OID 25854)
+-- TOC Entry ID 3 (OID 25854)
 --
 -- Name: customers Type: ACL Owner: 
@@ -81,5 +54,111 @@
 
 --
--- TOC Entry ID 6 (OID 25866)
+-- TOC Entry ID 4 (OID 25872)
+--
+-- Name: masterblocks Type: TABLE Owner: ipdb
+--
+
+CREATE TABLE "masterblocks" (
+	"cidr" cidr DEFAULT '255.255.255.255/32' NOT NULL,
+	Constraint "masterblocks_pkey" Primary Key ("cidr")
+);
+
+--
+-- TOC Entry ID 5 (OID 25872)
+--
+-- Name: masterblocks Type: ACL Owner: 
+--
+
+REVOKE ALL on "masterblocks" from PUBLIC;
+GRANT ALL on "masterblocks" to "kdeugau";
+GRANT ALL on "masterblocks" to "ipdb";
+
+--
+-- TOC Entry ID 6 (OID 25875)
+--
+-- Name: routed Type: TABLE Owner: ipdb
+--
+
+CREATE TABLE "routed" (
+	"cidr" cidr DEFAULT '255.255.255.255/32' NOT NULL,
+	"maskbits" integer DEFAULT 128,
+	"city" character varying(30) DEFAULT '',
+	Constraint "routed_pkey" Primary Key ("cidr")
+);
+
+--
+-- TOC Entry ID 7 (OID 25875)
+--
+-- Name: routed Type: ACL Owner: 
+--
+
+REVOKE ALL on "routed" from PUBLIC;
+GRANT ALL on "routed" to "kdeugau";
+GRANT ALL on "routed" to "ipdb";
+
+--
+-- TOC Entry ID 8 (OID 31131)
+--
+-- Name: temp Type: TABLE Owner: ipdb
+--
+
+CREATE TABLE "temp" (
+	"ofs" integer
+);
+
+--
+-- TOC Entry ID 9 (OID 31131)
+--
+-- Name: temp Type: ACL Owner: 
+--
+
+REVOKE ALL on "temp" from PUBLIC;
+GRANT ALL on "temp" to "kdeugau";
+GRANT ALL on "temp" to "ipdb";
+
+--
+-- TOC Entry ID 10 (OID 73917)
+--
+-- Name: searchme Type: VIEW Owner: ipdb
+--
+
+CREATE VIEW "searchme" as SELECT allocations.cidr, allocations.custid, allocations."type", allocations.city, allocations.description FROM allocations UNION SELECT poolips.ip, poolips.custid, poolips.ptype, poolips.city, poolips.description FROM poolips;
+
+--
+-- TOC Entry ID 11 (OID 73917)
+--
+-- Name: searchme Type: ACL Owner: 
+--
+
+REVOKE ALL on "searchme" from PUBLIC;
+GRANT ALL on "searchme" to "kdeugau";
+GRANT ALL on "searchme" to "ipdb";
+
+--
+-- TOC Entry ID 12 (OID 91065)
+--
+-- Name: freeblocks Type: TABLE Owner: ipdb
+--
+
+CREATE TABLE "freeblocks" (
+	"cidr" cidr DEFAULT '255.255.255.255/32' NOT NULL,
+	"maskbits" integer DEFAULT 128,
+	"city" character varying(30) DEFAULT '',
+	"routed" character(1) DEFAULT 'n',
+	Constraint "freeblocks_pkey" Primary Key ("cidr")
+);
+
+--
+-- TOC Entry ID 13 (OID 91065)
+--
+-- Name: freeblocks Type: ACL Owner: 
+--
+
+REVOKE ALL on "freeblocks" from PUBLIC;
+GRANT ALL on "freeblocks" to "kdeugau";
+GRANT ALL on "freeblocks" to "ipdb";
+
+--
+-- TOC Entry ID 14 (OID 92444)
 --
 -- Name: poolips Type: TABLE Owner: ipdb
@@ -93,6 +172,7 @@
 	"ptype" character(1) DEFAULT 'c' NOT NULL,
 	"available" character(1) DEFAULT 'y',
-	"notes" text,
+	"notes" text DEFAULT '',
 	"description" character varying(64) DEFAULT '',
+	"circuitid" character varying(128) DEFAULT '',
 	CHECK (((available = 'y'::bpchar) OR (available = 'n'::bpchar))),
 	Constraint "poolips_pkey" Primary Key ("ip")
@@ -100,5 +180,5 @@
 
 --
--- TOC Entry ID 7 (OID 25866)
+-- TOC Entry ID 15 (OID 92444)
 --
 -- Name: poolips Type: ACL Owner: 
@@ -110,107 +190,29 @@
 
 --
--- TOC Entry ID 8 (OID 25872)
---
--- Name: masterblocks Type: TABLE Owner: ipdb
---
-
-CREATE TABLE "masterblocks" (
-	"cidr" cidr DEFAULT '255.255.255.255/32' NOT NULL,
-	Constraint "masterblocks_pkey" Primary Key ("cidr")
-);
-
---
--- TOC Entry ID 9 (OID 25872)
---
--- Name: masterblocks Type: ACL Owner: 
---
-
-REVOKE ALL on "masterblocks" from PUBLIC;
-GRANT ALL on "masterblocks" to "kdeugau";
-GRANT ALL on "masterblocks" to "ipdb";
-
---
--- TOC Entry ID 10 (OID 25875)
---
--- Name: routed Type: TABLE Owner: ipdb
---
-
-CREATE TABLE "routed" (
-	"cidr" cidr DEFAULT '255.255.255.255/32' NOT NULL,
+-- TOC Entry ID 16 (OID 92725)
+--
+-- Name: allocations Type: TABLE Owner: ipdb
+--
+
+CREATE TABLE "allocations" (
+	"cidr" cidr DEFAULT '255.255.255.255/32' NOT NULL,
+	"custid" character varying(16) DEFAULT '',
+	"type" character(2) DEFAULT '',
+	"city" character varying(30) DEFAULT '',
+	"description" character varying(64) DEFAULT '',
+	"notes" text DEFAULT '',
 	"maskbits" integer DEFAULT 128,
-	"city" character varying(30) DEFAULT '',
-	Constraint "routed_pkey" Primary Key ("cidr")
-);
-
---
--- TOC Entry ID 11 (OID 25875)
---
--- Name: routed Type: ACL Owner: 
---
-
-REVOKE ALL on "routed" from PUBLIC;
-GRANT ALL on "routed" to "kdeugau";
-GRANT ALL on "routed" to "ipdb";
-
---
--- TOC Entry ID 12 (OID 31131)
---
--- Name: temp Type: TABLE Owner: ipdb
---
-
-CREATE TABLE "temp" (
-	"ofs" integer
-);
-
---
--- TOC Entry ID 13 (OID 31131)
---
--- Name: temp Type: ACL Owner: 
---
-
-REVOKE ALL on "temp" from PUBLIC;
-GRANT ALL on "temp" to "kdeugau";
-GRANT ALL on "temp" to "ipdb";
-
---
--- TOC Entry ID 14 (OID 73917)
---
--- Name: searchme Type: VIEW Owner: ipdb
---
-
-CREATE VIEW "searchme" as SELECT allocations.cidr, allocations.custid, allocations."type", allocations.city, allocations.description FROM allocations UNION SELECT poolips.ip, poolips.custid, poolips.ptype, poolips.city, poolips.description FROM poolips;
-
---
--- TOC Entry ID 15 (OID 73917)
---
--- Name: searchme Type: ACL Owner: 
---
-
-REVOKE ALL on "searchme" from PUBLIC;
-GRANT ALL on "searchme" to "kdeugau";
-GRANT ALL on "searchme" to "ipdb";
-
---
--- TOC Entry ID 16 (OID 91065)
---
--- Name: freeblocks Type: TABLE Owner: ipdb
---
-
-CREATE TABLE "freeblocks" (
-	"cidr" cidr DEFAULT '255.255.255.255/32' NOT NULL,
-	"maskbits" integer DEFAULT 128,
-	"city" character varying(30) DEFAULT '',
-	"routed" character(1) DEFAULT 'n',
-	Constraint "freeblocks_pkey" Primary Key ("cidr")
-);
-
---
--- TOC Entry ID 17 (OID 91065)
---
--- Name: freeblocks Type: ACL Owner: 
---
-
-REVOKE ALL on "freeblocks" from PUBLIC;
-GRANT ALL on "freeblocks" to "kdeugau";
-GRANT ALL on "freeblocks" to "ipdb";
-
+	"circuitid" character varying(128) DEFAULT '',
+	Constraint "allocations_pkey" Primary Key ("cidr")
+);
+
+--
+-- TOC Entry ID 17 (OID 92725)
+--
+-- Name: allocations Type: ACL Owner: 
+--
+
+REVOKE ALL on "allocations" from PUBLIC;
+GRANT ALL on "allocations" to "kdeugau";
+GRANT ALL on "allocations" to "ipdb";
+
Index: branches/stable/cgi-bin/main.cgi
===================================================================
--- branches/stable/cgi-bin/main.cgi	(revision 71)
+++ branches/stable/cgi-bin/main.cgi	(revision 75)
@@ -735,5 +735,5 @@
   my $count = 0;
   while (my @data = $sth->fetchrow_array) {
-    # pool,ip,custid,city,ptype,available,notes,description
+    # pool,ip,custid,city,ptype,available,notes,description,circuitid
     # If desc is null, make it not null.  <g>
     if ($data[7] eq '') {
@@ -934,4 +934,5 @@
   $html =~ s|\$\$CITY\$\$|$webvar{city}|g;
   $html =~ s|\$\$CUSTID\$\$|$webvar{custid}|g;
+  $html =~ s|\$\$CIRCID\$\$|$webvar{circid}|g;
   $webvar{desc} = desanitize($webvar{desc});
   $webvar{notes} = desanitize($webvar{notes});
@@ -977,5 +978,6 @@
 
     $sth = $ip_dbh->prepare("update poolips set custid='$webvar{custid}',".
-	"city='$webvar{city}',available='n',description='$webvar{desc}'".
+	"city='$webvar{city}',available='n',description='$webvar{desc}',".
+	"circuitid='$webvar{circid}'".
 	" where ip='$cidr'");
     $sth->execute;
@@ -1029,5 +1031,5 @@
 	  $sth = $ip_dbh->prepare("insert into allocations values ('$webvar{fullcidr}',".
 	    "'$webvar{custid}','$webvar{alloctype}','$webvar{city}','$webvar{desc}',".
-	    "'$webvar{notes}',".$cidr->masklen.")");
+	    "'$webvar{notes}',".$cidr->masklen.",'$webvar{circid}')");
 	  $sth->execute;
 	} # routing vs non-routing netblock
@@ -1095,5 +1097,5 @@
 	  $sth = $ip_dbh->prepare("insert into allocations values ('$webvar{fullcidr}',".
 	    "'$webvar{custid}','$webvar{alloctype}','$webvar{city}',".
-	    "'$webvar{desc}','$webvar{notes}',".$cidr->masklen.")");
+	    "'$webvar{desc}','$webvar{notes}',".$cidr->masklen.",'$webvar{circid}')");
 	  $sth->execute;
 	} # done with netblock alloctype != rr
@@ -1118,5 +1120,5 @@
 	# have to insert all pool IPs into poolips table as "unallocated".
 	$sth = $ip_dbh->prepare("insert into poolips values ('$webvar{fullcidr}',".
-	  " ?, '6750400', '$webvar{city}', '$pooltype', 'y', '')");
+	  " ?, '6750400', '$webvar{city}', '$pooltype', 'y', '', '', '')");
 	my @poolip_list = $cidr->hostenum;
 	for (my $i=1; $i<=$#poolip_list; $i++) {
@@ -1205,7 +1207,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,ptype,city,description,notes from poolips where ip='$webvar{block}'";
+    $sql = "select ip,custid,ptype,city,circuitid,description,notes from poolips where ip='$webvar{block}'";
   } else {
-    $sql = "select cidr,custid,type,city,description,notes from allocations where cidr='$webvar{block}'"
+    $sql = "select cidr,custid,type,city,circuitid,description,notes from allocations where cidr='$webvar{block}'"
   }
 
@@ -1258,6 +1260,8 @@
   # These can be modified, although CustID changes may get ignored.
   $html =~ s/\$\$CUSTID\$\$/$data[1]/g;
-  $html =~ s/\$\$DESC\$\$/$data[4]/g;
-  $html =~ s/\$\$NOTES\$\$/$data[5]/g;
+  $html =~ s/\$\$TYPE\$\$/$data[2]/g;
+  $html =~ s/\$\$CIRCID\$\$/$data[4]/g;
+  $html =~ s/\$\$DESC\$\$/$data[5]/g;
+  $html =~ s/\$\$NOTES\$\$/$data[6]/g;
 
   print $html;
@@ -1280,11 +1284,11 @@
     my $sql;
     if (my $pooltype = ($webvar{alloctype} =~ /^([cdms])i$/) ) {
-      $sql = "update poolips set custid='$webvar{custid}',".
-	"notes='$webvar{notes}',description='$webvar{desc}' ".
+      $sql = "update poolips set custid='$webvar{custid}',notes='$webvar{notes}',".
+	"circuitid='$webvar{circid}',description='$webvar{desc}' ".
 	"where ip='$webvar{block}'";
     } else {
       $sql = "update allocations set custid='$webvar{custid}',".
 	"description='$webvar{desc}',notes='$webvar{notes}',city='$webvar{city}',".
-	"type='$webvar{alloctype}' where cidr='$webvar{block}'";
+	"type='$webvar{alloctype}',circuitid='$webvar{circid}' where cidr='$webvar{block}'";
     }
 syslog "debug", $sql;
@@ -1311,4 +1315,5 @@
   $html =~ s/\$\$TYPEFULL\$\$/$full_alloc_types{$webvar{alloctype}}/g;
   $html =~ s/\$\$CUSTID\$\$/$webvar{custid}/g;
+  $html =~ s/\$\$CIRCID\$\$/$webvar{circid}/g;
   $html =~ s/\$\$DESC\$\$/$webvar{desc}/g;
   $html =~ s/\$\$NOTES\$\$/$webvar{notes}/g;
@@ -1335,5 +1340,5 @@
   }
 
-  my ($cidr, $custid, $type, $city, $desc, $notes, $alloctype);
+  my ($cidr, $custid, $type, $city, $circid, $desc, $notes, $alloctype);
 
   if ($webvar{alloctype} eq 'rr') {
@@ -1349,4 +1354,5 @@
     $custid = "N/A";
     $alloctype = $webvar{alloctype};
+    $circid = "N/A";
     $desc = "N/A";
     $notes = "N/A";
@@ -1357,4 +1363,5 @@
     $custid = "N/A";
     $alloctype = $webvar{alloctype};
+    $circid = "N/A";
     $desc = "N/A";
     $notes = "N/A";
@@ -1362,10 +1369,10 @@
 
     # Unassigning a static IP
-    my $sth = $ip_dbh->prepare("select ip,custid,city,ptype,notes from poolips".
+    my $sth = $ip_dbh->prepare("select ip,custid,city,ptype,notes,circuitid from poolips".
 	" where ip='$webvar{block}'");
     $sth->execute();
 #  croak $sth->errstr() if($sth->errstr());
 
-    $sth->bind_columns(\$cidr, \$custid, \$city, \$alloctype, \$notes);
+    $sth->bind_columns(\$cidr, \$custid, \$city, \$alloctype, \$notes, \$circid);
     $sth->fetch() || croak $sth->errstr;
 
@@ -1374,11 +1381,11 @@
   } else { # done with alloctype=[sdcmw]i
 
-    my $sth = $ip_dbh->prepare("select cidr,custid,type,city,description,notes from ".
+    my $sth = $ip_dbh->prepare("select cidr,custid,type,city,circuitid,description,notes from ".
 	"allocations where cidr='$webvar{block}'");
     $sth->execute();
 #	croak $sth->errstr() if($sth->errstr());
 
-    $sth->bind_columns(\$cidr, \$custid, \$alloctype, \$city, \$desc, \$notes);
-    $sth->fetch() || croak $sth->errstr;
+    $sth->bind_columns(\$cidr, \$custid, \$alloctype, \$city, \$circid, \$desc, \$notes);
+    $sth->fetch() || carp $sth->errstr;
   } # end cases for different alloctypes
 
@@ -1390,4 +1397,5 @@
   $html =~ s|\$\$CITY\$\$|$city|g;
   $html =~ s|\$\$CUSTID\$\$|$custid|g;
+  $html =~ s|\$\$CIRCID\$\$|$circid|g;
   $html =~ s|\$\$DESC\$\$|$desc|g;
   $html =~ s|\$\$NOTES\$\$|$notes|g;
