Index: trunk/cgi-bin/main.cgi
===================================================================
--- trunk/cgi-bin/main.cgi	(revision 108)
+++ trunk/cgi-bin/main.cgi	(revision 111)
@@ -127,5 +127,4 @@
   }
 
-  printFooter;
 } # end add new master
 
@@ -149,5 +148,4 @@
     viewBy($webvar{searchfor}, $webvar{input});
   }
-  printFooter();
 }
 
@@ -188,12 +186,16 @@
   printAndExit("Error $boing:  ".$excuses[$rnd/30.0]);
 }
+## Finally! Done with that NASTY "case" emulation!
 
 
 
 # Clean up IPDB globals, DB handle, etc.
-finish;
+finish($ip_dbh);
+# We print the footer here, so we don't have to do it elsewhere.
+printFooter;
 # Just in case something waaaayyy down isn't in place
 # properly... we exit explicitly.
 exit;
+
 
 
@@ -294,9 +296,9 @@
     } else {
       # This shouldn't happen, but if it does, whoever gets it deserves what they get...
-      printAndExit("Invalid query.");
+      printError("Invalid query.");
     }
   } else {
     # This shouldn't happen, but if it does, whoever gets it deserves what they get...
-    printAndExit("Invalid searchfor.");
+    printError("Invalid searchfor.");
   }
 } # viewBy
@@ -477,8 +479,4 @@
   print "Note:  Free blocks noted here include both routed and unrouted blocks.\n";
 
-  # Because of the way this sub gets called, we don't need to print the footer here.
-  # (index.shtml makes an SSI #include call to cgi-bin/main.cgi?action=index)
-  # If we do, the footer comes in twice...
-  #printFooter;
 } # showSummary
 
@@ -608,5 +606,4 @@
 
   print "</table>\n";
-  printFooter;
 } # showMaster
 
@@ -696,5 +693,4 @@
 
   print "</table>\n";
-  printFooter;
 } # showRBlock
 
@@ -752,5 +748,4 @@
   print "</table>\n";
 
-  printFooter;
 } # end listPool
 
@@ -815,5 +810,4 @@
   print $html;
 
-  printFooter();
 } # assignBlock
 
@@ -828,10 +822,5 @@
   # Going to manually validate some items.
   # custid and city are automagic.
-  validateInput();
-
-# This isn't always useful.
-#  if (!$webvar{maskbits}) {
-#    printAndExit("Please enter a CIDR block length.");
-#  }
+  return if !validateInput();
 
 # Several different cases here.
@@ -882,5 +871,6 @@
 
       if (!$webvar{maskbits}) {
-        printAndExit("Please specify a CIDR mask length.");
+        printError("Please specify a CIDR mask length.");
+	return;
       }
       my $sql;
@@ -901,5 +891,7 @@
 	if ($webvar{alloctype} =~ /^[cdsmw]p$/) {
 	  if (($webvar{city} !~ /^(Sudbury|North Bay)$/) && ($webvar{alloctype} eq 'dp')) {
-	    printAndExit("You must chose Sudbury or North Bay for DSL pools."); }
+	    printError("You must chose Sudbury or North Bay for DSL pools.");
+	    return;
+	  }
 	  $city = $webvar{city};
 	  $failmsg = "No suitable free block found.<br>\nYou will have to route another".
@@ -924,5 +916,6 @@
       my @data = $sth->fetchrow_array();
       if ($data[0] eq "") {
-	printAndExit($failmsg);
+	printError($failmsg);
+	return;
       }
       $cidr = new NetAddr::IP $data[0];
@@ -973,5 +966,4 @@
   print $html;
 
-  printFooter;
 } # end confirmAssign
 
@@ -981,5 +973,5 @@
   # Some things are done more than once.
   printHeader('');
-  validateInput();
+  return if !validateInput();
 
   # $code is "success" vs "failure", $msg contains OK for a
@@ -990,15 +982,11 @@
 	$webvar{circid});
 
-  if ($code) {
-    syslog "err", "Allocation of '$webvar{fullcidr}' to '$webvar{custid}' as ".
-	"'$webvar{alloctype}' by $authuser failed: '$msg'";
-    printAndExit("Allocation of $webvar{fullcidr} as $disp_alloctypes{$webvar{alloctype}}".
-	" failed: $msg\n");
-  } else {
+  if ($code eq 'OK') {
     if ($webvar{alloctype} =~ /^.i$/) {
       print qq(<div class="center"><div class="heading">The IP $msg has been allocated to customer $webvar{custid}</div></div>);
       # Notify tech@example.com
       mailNotify('tech@example.com',"$disp_alloctypes{$webvar{alloctype}} allocation",
-	"$disp_alloctypes{$webvar{alloctype}} $msg allocated to customer $webvar{custid}");
+	"$disp_alloctypes{$webvar{alloctype}} $msg allocated to customer $webvar{custid}\n".
+	"Description: $webvar{desc}\n\nAllocated by: $authuser\n");
     } else {
       print qq(<div class="center"><div class="heading">The block $webvar{fullcidr} was ).
@@ -1008,7 +996,11 @@
     syslog "notice", "$authuser allocated '$webvar{fullcidr}' to '$webvar{custid}' as ".
 	"'$webvar{alloctype}'";
-  }
-
-  printFooter();
+  } else {
+    syslog "err", "Allocation of '$webvar{fullcidr}' to '$webvar{custid}' as ".
+	"'$webvar{alloctype}' by $authuser failed: '$msg'";
+    printError("Allocation of $webvar{fullcidr} as $disp_alloctypes{$webvar{alloctype}}".
+	" failed: $msg\n");
+  }
+
 } # end insertAssign()
 
@@ -1019,5 +1011,6 @@
 sub validateInput {
   if ($webvar{city} eq '-') {
-    printAndExit("Please choose a city.");
+    printError("Please choose a city.");
+    return;
   }
   chomp $webvar{alloctype};
@@ -1025,33 +1018,46 @@
   if ($webvar{alloctype} =~ /^(ci|di|cn|mi|wi)$/) {
     if (!$webvar{custid}) {
-      printAndExit("Please enter a customer ID.");
+      printError("Please enter a customer ID.");
+      return;
     }
     if ($webvar{custid} !~ /^(?:\d{10}|\d{7}|STAFF|TEMP)(?:-\d\d?)?$/) {
-      printAndExit("Please enter a valid customer ID- this must be a 7- or 10-digit number, or STAFF for static IPs for staff.");
+      printError("Please enter a valid customer ID- this must be a 7- or 10-digit number, or STAFF for static IPs for staff.");
+      return;
     }
     print "<!-- [ In validateInput().  Insert customer ID cross-check here. ] -->\n";
-  } elsif ($webvar{alloctype} =~ /^([cdsmw]p|si|dn|dy|dc|ee|rr|ii)$/){
+  } elsif ($webvar{alloctype} =~ /^([cdsmw]p|si|dn|dy|dc|ee|rr|in)$/){
     # All non-customer allocations MUST be entered with "our" customer ID.
     # I have Defined this as 6750400 for consistency.
     $webvar{custid} = "6750400";
-    if ($webvar{alloctype} eq 'rr') {
-      my $flag;
-      foreach (@poplist) {
-        if (/^$webvar{city}$/) {
-	  $flag = 'y'; last;
-	}
-      }
-      if (!$flag) {
-	printAndExit("Please choose a valid POP location for a routed netblock.  Valid ".
-		"POP locations are currently:<br>\n".join (" - ", @poplist));
-      }
-    }
   } else {
-print "$webvar{alloctype}";
     # Danger! Danger!  alloctype should ALWAYS be set by a dropdown.  Anyone
     # managing to call things in such a way as to cause this deserves a cryptic error.
-    printAndExit("Invalid alloctype");
-  }
-  return 0;
+    printError("Invalid alloctype");
+    return;
+  }
+
+  # Check POP location
+  my $flag;
+  if ($webvar{alloctype} eq 'rr') {
+    $flag = 'for a routed netblock';
+    foreach (@poplist) {
+      if (/^$webvar{city}$/) {
+	$flag = 'n';
+	last;
+      }
+    }
+  } else {
+    $flag = 'n';
+    if ($webvar{pop} =~ /^-$/) {
+      $flag = 'to route the block from/through';
+    }
+  }
+  if ($flag ne 'n') {
+    printError("Please choose a valid POP location $flag.  Valid ".
+	"POP locations are currently:<br>\n".join (" - ", @poplist));
+    return;
+  }
+
+  return 'OK';
 } # end validateInput
 
@@ -1128,5 +1134,4 @@
   print $html;
 
-  printFooter();
 } # edit()
 
@@ -1164,5 +1169,6 @@
     eval { $ip_dbh->rollback; };
     syslog "err", "$authuser could not update block/IP '$webvar{block}': '$@'";
-    printAndExit("Could not update block/IP $webvar{block}: $@");
+    printError("Could not update block/IP $webvar{block}: $@");
+    return;
   }
 
@@ -1170,5 +1176,5 @@
   syslog "notice", "$authuser updated $webvar{block}";
   open (HTML, "../updated.html")
-        or croak "Could not open updated.html :$!";
+	or croak "Could not open updated.html :$!";
   my $html = join('', <HTML>);
 
@@ -1188,5 +1194,4 @@
   print $html;
 
-  printFooter;
 } # update()
 
@@ -1203,5 +1208,6 @@
   # Serves'em right for getting here...
   if (!defined($webvar{block})) {
-    printAndExit("Error 332");
+    printError("Error 332");
+    return;
   }
 
@@ -1277,5 +1283,4 @@
 
   print $html;
-  printFooter;
 } # end edit()
 
@@ -1296,12 +1301,11 @@
     if ($webvar{alloctype} =~ /^.i$/) {
       syslog "err", "$authuser could not deallocate static IP '$webvar{block}': '$msg'";
-      printAndExit("Could not deallocate static IP $webvar{block}: $msg");
+      printError("Could not deallocate static IP $webvar{block}: $msg");
     } else {
       syslog "err", "$authuser could not deallocate netblock '$webvar{block}': '$msg'";
-      printAndExit("Could not deallocate netblock $webvar{block}: $msg");
-    }
-  }
-
-  printFooter;
+      printError("Could not deallocate netblock $webvar{block}: $msg");
+    }
+  }
+
 } # finalDelete
 
