Index: /branches/sql-cleanup/cgi-bin/IPDB.pm
===================================================================
--- /branches/sql-cleanup/cgi-bin/IPDB.pm	(revision 148)
+++ /branches/sql-cleanup/cgi-bin/IPDB.pm	(revision 149)
@@ -251,7 +251,14 @@
 
 	  # And initialize the pool, if necessary
+	  # PPPoE pools (currently dialup, DSL, and WiFi) get all IPs made available
+	  # "DHCP" or "real-subnet" pools have the net, gw, and bcast IPs removed.
 	  if ($type =~ /^.p$/) {
-	    $msg = "Could not initialize IPs in new $disp_alloctypes{$type} pool $cidr";
-	    initPool($dbh,$cidr,$type,$city,($type eq 'dp' ? "all" : "normal"));
+	    $msg = "Could not initialize IPs in new $disp_alloctypes{$type} $cidr";
+	    my ($code,$rmsg) = initPool($dbh,$cidr,$type,$city,"all");
+	    die $rmsg if $code eq 'FAIL';
+	  } elsif ($type =~ /^.d$/) {
+	    $msg = "Could not initialize IPs in new $disp_alloctypes{$type} $cidr";
+	    my ($code,$rmsg) = initPool($dbh,$cidr,$type,$city,"normal");
+	    die $rmsg if $code eq 'FAIL';
 	  }
 
@@ -261,7 +268,7 @@
       }; # end of eval
       if ($@) {
-	$msg = $@;
+	$msg .= ": ".$@;
 	eval { $dbh->rollback; };
-	return ('FAIL',$@);
+	return ('FAIL',$msg);
       } else {
 	return ('OK',"OK");
@@ -367,22 +374,39 @@
   my $pool = new NetAddr::IP $_[1];
 
-  my ($pooltype) = ($type =~ /^(.)p$/);
+##fixme Need to just replace 2nd char of type with i rather than capturing 1st char of type
+  $type =~ s/[pd]$/i/;
   my $sth;
-
-  # have to insert all pool IPs into poolips table as "unallocated".
-  $sth = $dbh->prepare("insert into poolips (pool,ip,custid,city,ptype)".
-	" values ('$pool', ?, '6750400', '$city', '$pooltype')");
-  my @poolip_list = $pool->hostenum;
-  if ($class eq 'all') { # (DSL-ish block - *all* IPs available
-    $sth->execute($pool->addr);
-    for (my $i=0; $i<=$#poolip_list; $i++) {
-      $sth->execute($poolip_list[$i]->addr);
-    }
-    $pool--;
-    $sth->execute($pool->addr);
-  } else { # (real netblock)
-    for (my $i=1; $i<=$#poolip_list; $i++) {
-      $sth->execute($poolip_list[$i]->addr);
-    }
+  my $msg;
+
+  # Trap errors so we can pass them back to the caller.  Even if the
+  # caller is only ever supposed to be local, and therefore already
+  # trapping errors.  >:(
+  local $dbh->{AutoCommit} = 0; # These need to be local so we don't
+  local $dbh->{RaiseError} = 1; # step on our toes by accident.
+
+  eval {
+    # have to insert all pool IPs into poolips table as "unallocated".
+    $sth = $dbh->prepare("insert into poolips (pool,ip,custid,city,type)".
+	" values ('$pool', ?, '6750400', '$city', '$type')");
+    my @poolip_list = $pool->hostenum;
+    if ($class eq 'all') { # (DSL-ish block - *all* IPs available
+      $sth->execute($pool->addr);
+      for (my $i=0; $i<=$#poolip_list; $i++) {
+	$sth->execute($poolip_list[$i]->addr);
+      }
+      $pool--;
+      $sth->execute($pool->addr);
+    } else { # (real netblock)
+      for (my $i=1; $i<=$#poolip_list; $i++) {
+	$sth->execute($poolip_list[$i]->addr);
+      }
+    }
+  };
+  if ($@) {
+    $msg = "'".$sth->errstr."'";
+    eval { $dbh->rollback; };
+    return ('FAIL',$msg);
+  } else {
+    return ('OK',"OK");
   }
 } # end initPool()
@@ -412,5 +436,5 @@
 
     eval {
-      $msg = "Unable to deallocate $type $cidr";
+      $msg = "Unable to deallocate $disp_alloctypes{$type} $cidr";
       $sth = $dbh->prepare("update poolips set custid='6750400',available='y',".
 	"city=(select city from allocations where cidr >>= '$cidr'),".
@@ -469,5 +493,5 @@
 	$sth->execute;
 	# Special case - delete pool IPs
-	if ($type =~ /^.p$/) {
+	if ($type =~ /^.[pd]$/) {
 	  # We have to delete the IPs from the pool listing.
 	  $sth = $dbh->prepare("delete from poolips where pool='$cidr'");
Index: /branches/sql-cleanup/cgi-bin/main.cgi
===================================================================
--- /branches/sql-cleanup/cgi-bin/main.cgi	(revision 148)
+++ /branches/sql-cleanup/cgi-bin/main.cgi	(revision 149)
@@ -354,5 +354,5 @@
 	$data[1], $disp_alloctypes{$data[2]}, $data[3], $data[4]);
     # Allow listing of pool if desired/required.
-    if ($data[2] =~ /^[cdsmw]p$/) {
+    if ($data[2] =~ /^.[pd]$/) {
       $row[0] .= ' &nbsp; <a href="/ip/cgi-bin/main.cgi?action=listpool'.
 	"&pool=$data[0]\">List IPs</a>";
@@ -620,5 +620,5 @@
 	$data[3], $disp_alloctypes{$data[2]}, $data[1], $data[4]);
     # If the allocation is a pool, allow listing of the IPs in the pool.
-    if ($data[2] =~ /^[cdsmw]p$/) {
+    if ($data[2] =~ /^.[pd]$/) {
       $row[0] .= ' &nbsp; <a href="/ip/cgi-bin/main.cgi?action=listpool'.
 	"&pool=$data[0]\">List IPs</a>";
@@ -675,21 +675,26 @@
   my $cidr = new NetAddr::IP $webvar{pool};
 
+  my ($pooltype,$poolcity);
+
   # Snag pool info for heading
-  $sth = $ip_dbh->prepare("select * from allocations where cidr='$cidr'");
+  $sth = $ip_dbh->prepare("select type,city from allocations where cidr='$cidr'");
   $sth->execute;
-  my @data = $sth->fetchrow_array;
-  my $type = $data[2];	# We'll need this later.
+  $sth->bind_columns(\$pooltype, \$poolcity);
+  $sth->fetch() || carp $sth->errstr;
 
   print qq(<center><div class="heading">Listing pool IPs for $cidr<br>\n).
-	qq(($disp_alloctypes{$type} in $data[3])</div></center><br>\n);
-  print qq(<div class="indent"><b>Reserved IPs:</b><br>\n);
-  print qq(<div class="indent"><table><tr class=color1><td>Network IP:</td><td>).
+	qq(($disp_alloctypes{$pooltype} in $poolcity)</div></center><br>\n);
+  # Only display net/gw/bcast if it's a "real" netblock and not a PPP(oE) lunacy
+  if ($pooltype =~ /^.d$/) {
+    print qq(<div class="indent"><b>Reserved IPs:</b><br>\n);
+    print qq(<div class="indent"><table><tr class=color1><td>Network IP:</td><td>).
 	$cidr->addr."</td></tr>\n";
-  $cidr++;
-  print "<tr class=color2><td>Gateway:</td><td>".$cidr->addr."</td></tr>\n";
-  $cidr--;  $cidr--;
-  print "<tr class=color1><td>Broadcast:</td><td>".$cidr->addr."</td></tr>\n".
+    $cidr++;
+    print "<tr class=color2><td>Gateway:</td><td>".$cidr->addr."</td></tr>\n";
+    $cidr--;  $cidr--;
+    print "<tr class=color1><td>Broadcast:</td><td>".$cidr->addr."</td></tr>\n".
 	"<tr><td>Netmask:</td><td>".$cidr->mask."</td></tr>\n".
 	"</table></div></div>\n";
+  }
 
 # probably have to add an "edit IP allocation" link here somewhere.
@@ -973,5 +978,5 @@
 	"'$webvar{alloctype}' by $authuser failed: '$msg'";
     printError("Allocation of $webvar{fullcidr} as $disp_alloctypes{$webvar{alloctype}}".
-	" failed: $msg\n");
+	" failed:<br>\n$msg\n");
   }
 
