Index: branches/stable/cgi-bin/main.cgi
===================================================================
--- branches/stable/cgi-bin/main.cgi	(revision 408)
+++ branches/stable/cgi-bin/main.cgi	(revision 445)
@@ -1,5 +1,4 @@
 #!/usr/bin/perl
 # ipdb/cgi-bin/main.cgi
-# Started munging from noc.vianet's old IPDB 04/22/2004
 ###
 # SVN revision info
@@ -8,4 +7,5 @@
 # Last update by $Author$
 ###
+# Copyright (C) 2004-2010 - Kris Deugau
 
 use strict;		
@@ -14,5 +14,4 @@
 use DBI;
 use CommonWeb qw(:ALL);
-use MyIPDB;
 use CustIDCK;
 use POSIX qw(ceil);
@@ -21,5 +20,10 @@
 use Sys::Syslog;
 
-openlog "IPDB","pid","local2";
+# don't remove!  required for GNU/FHS-ish install from tarball
+##uselib##
+
+use MyIPDB;
+
+openlog "IPDB","pid","$IPDB::syslog_facility";
 
 # Collect the username from HTTP auth.  If undefined, we're in
@@ -681,20 +685,9 @@
   if ($webvar{alloctype} =~ /^.i$/) {
     my ($base,undef) = split //, $webvar{alloctype};	# split into individual chars
-    my ($sql,$city);
-    # Check for pools in Subury, North Bay, or Toronto if DSL or server pool.
-    # Anywhere else is invalid and shouldn't be in the db in the first place.
-    # ... aside from #^%#$%#@#^%^^!!!! legacy data.  GRRR.
-    # Note that we want to retain the requested city to relate to customer info.
-    if ($base =~ /^[ds]$/) {
-      $city = "(allocations.city='Sudbury' or allocations.city='North Bay' or ".
-	"allocations.city='Toronto')";
-    } else {
-      $city = "allocations.city='$webvar{pop}'";
-    }
 
 # Ewww.  But it works.
     $sth = $ip_dbh->prepare("SELECT (SELECT city FROM allocations WHERE cidr=poolips.pool), ".
 	"poolips.pool, COUNT(*) FROM poolips,allocations WHERE poolips.available='y' AND ".
-	"poolips.pool=allocations.cidr AND $city AND poolips.type LIKE '".$base."_' ".
+	"poolips.pool=allocations.cidr AND allocations.city='$webvar{pop}' AND poolips.type LIKE '".$base."_' ".
 	"GROUP BY pool");
     $sth->execute;
@@ -750,16 +743,12 @@
 	# This does NOT include cable pools.
 	if ($webvar{alloctype} =~ /^.[pc]$/) {
-	  if (($webvar{city} !~ /^(Sudbury|North Bay|Toronto)$/) && ($webvar{alloctype} eq 'dp')) {
-	    printError("You must chose Sudbury, North Bay, or Toronto for DSL pools.");
-	    return;
-	  }
 	  $city = $webvar{city};
 	  $failmsg = "No suitable free block found.<br>\nYou will have to route another".
-	    " superblock from one of the<br>\nmaster blocks in Sudbury or chose a smaller".
+	    " superblock from one of the<br>\nmaster blocks or chose a smaller".
 	    " block size for the pool.";
 	} else {
 	  $city = $webvar{pop};
 	  $failmsg = "No suitable free block found.<br>\nYou will have to route another".
-	    " superblock to $webvar{pop}<br>\nfrom one of the master blocks in Sudbury or".
+	    " superblock to $webvar{pop}<br>\nfrom one of the master blocks or".
 	    " chose a smaller blocksize.";
 	}
@@ -891,8 +880,7 @@
 		qq(&ipdb=1&ip=$msg">Add this IP to RADIUS user table</a></div>)
 	: "</div>");
-      # Notify tech@example.com
-#      mailNotify('tech@example.com',"ADDED: $disp_alloctypes{$webvar{alloctype}} allocation",
-#	"$disp_alloctypes{$webvar{alloctype}} $msg allocated to customer $webvar{custid}\n".
-#	"Description: $webvar{desc}\n\nAllocated by: $authuser\n");
+      mailNotify($ip_dbh, "a$webvar{alloctype}", "ADDED: $disp_alloctypes{$webvar{alloctype}} allocation",
+	"$disp_alloctypes{$webvar{alloctype}} $msg allocated to customer $webvar{custid}\n".
+	"Description: $webvar{desc}\n\nAllocated by: $authuser\n");
     } else {
       my $netblock = new NetAddr::IP $webvar{fullcidr};
@@ -906,7 +894,7 @@
 		qq(">Add this netblock to RADIUS user table</a></div>)
 	: "</div>");
-#      mailNotify('nocmgr@example.com',"ADDED: $disp_alloctypes{$webvar{alloctype}} allocation",
-#	"$disp_alloctypes{$webvar{alloctype}} $webvar{fullcidr} allocated to customer $webvar{custid}\n".
-#	"Description: $webvar{desc}\n\nAllocated by: $authuser\n");
+      mailNotify($ip_dbh, "a$webvar{alloctype}", "ADDED: $disp_alloctypes{$webvar{alloctype}} allocation",
+	"$disp_alloctypes{$webvar{alloctype}} $webvar{fullcidr} allocated to customer $webvar{custid}\n".
+	"Description: $webvar{desc}\n\nAllocated by: $authuser\n");
     }
     syslog "notice", "$authuser allocated '$webvar{fullcidr}' to '$webvar{custid}' as ".
@@ -958,10 +946,8 @@
       if (!$status) {
 	printError("Customer ID not valid.  Make sure the Customer ID ".
-	  "is correct.<br>\nUse STAFF for staff static IPs, and 6750400 for any other ".
+	  "is correct.<br>\nUse STAFF for staff static IPs, and $IPDB::defcustid for any other ".
 	  "non-customer assignments.");
 	return;
       }
-#"Please enter a valid customer ID- this must be a 7- or 10-digit number, or STAFF for
-#static IPs for staff.");
     }
 #    print "<!-- [ In validateInput().  Insert customer ID cross-check here. ] -->\n";
@@ -985,8 +971,6 @@
   } else {
     $flag = 'n';
-    if ($webvar{alloctype} =~ /[wp][cr]|[ds][pi]/) {
-      # Set this forcibly rather than messing around elsewhere.  Yes, this *is* a hack.  PTHBTT!!
-      $webvar{pop} = 'Sudbury';
-    }
+##fixme:  hook to force-set POP or city on certain alloctypes
+# if ($webvar{alloctype =~ /foo,bar,bz/ { $webvar{pop} = 'blah'; }
     if ($webvar{pop} =~ /^-$/) {
       $flag = 'to route the block from/through';
@@ -1225,6 +1209,8 @@
   # If we get here, the operation succeeded.
   syslog "notice", "$authuser updated $webvar{block}";
-#mailNotify('nocmgr@example.com',"SWIPed: $disp_alloctypes{$webvar{alloctype}} $webvar{block}",
-#	"$webvar{block} had SWIP status changed to \"Yes\" by $authuser");
+##fixme:  need to wedge something in to allow "update:field" notifications
+## hmm.  how to tell what changed?  O_o
+mailNotify($ip_dbh, 's:swi', "SWIPed: $disp_alloctypes{$webvar{alloctype}} $webvar{block}",
+	"$webvar{block} had SWIP status changed to \"Yes\" by $authuser") if $webvar{swip} eq 'on';
   open (HTML, "../updated.html")
 	or croak "Could not open updated.html :$!";
@@ -1402,11 +1388,7 @@
     syslog "notice", "$authuser deallocated '$webvar{alloctype}'-type netblock $webvar{block}".
 	" $custid, $city, desc='$description'";
-    # Notify tech@ when a block/IP is deallocated
-#    mailNotify('tech@example.com',"REMOVED: $disp_alloctypes{$webvar{alloctype}} $webvar{block}",
-#	"$disp_alloctypes{$webvar{alloctype}} $webvar{block} deallocated by $authuser\n".
-#	"CustID: $custid\nCity: $city\nDescription: $description\n");
-#    mailNotify('nocmgr@example.com',"REMOVED: $disp_alloctypes{$webvar{alloctype}} $webvar{block}",
-#	"$disp_alloctypes{$webvar{alloctype}} $webvar{block} deallocated by $authuser\n".
-#	"CustID: $custid\nCity: $city\nDescription: $description\n");
+    mailNotify($ip_dbh, 'da', "REMOVED: $disp_alloctypes{$webvar{alloctype}} $webvar{block}",
+	"$disp_alloctypes{$webvar{alloctype}} $webvar{block} deallocated by $authuser\n".
+	"CustID: $custid\nCity: $city\nDescription: $description\n");
   } else {
     if ($webvar{alloctype} =~ /^.i$/) {
