Index: trunk/cgi-bin/admin.cgi
===================================================================
--- trunk/cgi-bin/admin.cgi	(revision 418)
+++ trunk/cgi-bin/admin.cgi	(revision 422)
@@ -111,16 +111,18 @@
 Bump "last updated" timestamp on this master: <select name=whichmaster>$masterlist</select>
 <input type=submit value="Update timestamp"> (Sets timestamp to "now")</form>
-<a href="admin.cgi?action=listcust">Edit customer data for rWHOIS</a>
+<a href="admin.cgi?action=listcust">Edit customer data for rWHOIS</a> - data used for
+blocks with the SWIP box checkmarked.  Links to edit/add data are on this page.
 
 <hr><a href="admin.cgi?action=showpools">List IP Pools</a> for manual tweaking and updates
+
 <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)
+internal access controls - note that this does NOT include IP-based limits)<br>
+<a href="admin.cgi?action=emailnotice">Manage email notice options</a> (pick which events
+and allocation types cause notifications;  configure recipient lists for notices)
+
 <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)
-<hr>(r)WHOIS<br>
-<a href="list-cust.php">List customer data for WHOIS</a> - data used for blocks with the SWIP box checkmarked.
-Links to edit/add data are on this page.
 );
 } else {
@@ -254,5 +256,5 @@
 	syslog "notice", "$authuser allocated '$webvar{cidr}' to '$webvar{custid}' as ".
 		"'$webvar{alloctype}'";
-	mailNotify($ip_dbh, "$disp_alloctypes{$webvar{alloctype}} allocation",
+	mailNotify($ip_dbh, "a$webvar{alloctype}",
 	  "$disp_alloctypes{$webvar{alloctype}} $webvar{cidr} allocated to customer".
 	  " $webvar{custid}\n".
@@ -312,24 +314,4 @@
 <input type=hidden name=newcust value=1>
 <td>CustID:</td><td><input name=custid></td>
-<!-- <td>Name:</td><td><input name=name></td></tr>
-<tr><td>Street:</td><td><input name=street></td></tr> -->
-<!-- <td>Street2:</td><td><input name=street2></td> -->
-<!-- <tr><td>City:</td><td><input name=city></td>
-<td>Province: (2-letter code)</td><td><input name=province value=ON length=2 size=2></td></tr>
-<tr><td>Country: (2-letter code)</td><td><input name=country value=CA length=2 size=2></td>
-<td>Postal/ZIP Code:</td><td><input name=pocode></td></tr>
-<tr><td>Phone:</td><td><input name=phone></td> -->
-<!-- <td>Default rDNS:</td><td><input name=def_rdns></td></tr>
-<td>Description:</td><td><input name=description></td> -->
-<!-- </tr>
-<tr>
-<td>ARIN Handles:</td><td>
- Tech: <input name=tech_handle value="VH25-ORG-ARIN"><br>
- Abuse: <input name=abuse_handle><br>
- Admin: <input name=admin_handle><br>
-Note:  Only tech is required at the moment.
-</td>
-<td>"Special":</td><td><textarea name=special rows=4 cols=40></textarea></td>
-</tr> -->
 <td align=center><input type=submit value="Go to edit page for this custid"></td></tr>
 </form></table>
@@ -344,37 +326,4 @@
   }
   print "</table>\n";
-} elsif ($webvar{action} eq 'newcust') {
-  if ($webvar{custid} eq '') {
-    print 'No CustID entered.  PTHBT!  (Hit "Back" and fix the problem.)';
-  } else {
-    $sth = $ip_dbh->prepare("insert into customers ".
-	"(custid, name, street, city, province, country, pocode, ".
-	"phone, tech_handle, abuse_handle, admin_handle) values ".
-	"('$webvar{custid}', '$webvar{name}', '$webvar{street}', ".
-	"'$webvar{city}', '$webvar{province}', '$webvar{country}', ".
-	"'$webvar{pocode}', '$webvar{phone}', '$webvar{techhandle}', ".
-	"'$webvar{abusehandle}', '$webvar{adminhandle}')");
-    $sth->execute;
-    if ($sth->err) {
-      print "INSERT failed:  ".$sth->errstr."\n";
-    } else {
-      print "Success!  Added customer contact data:\n".
-	qq(<table border=1><tr>
-<td>CustID:</td>$webvar{custid}</td><td>Name:</td>$webvar{name}</td></tr>
-<tr><td>Street:</td><td>$webvar{street}</td></tr>
-<tr><td>City:</td><td>$webvar{city}</td><td>Province:</td><td>$webvar{province}</td></tr>
-<tr><td>Country:</td><td>$webvar{country}</td>
-<td>Postal/ZIP Code:</td><td>$webvar{pocode}</td></tr>
-<tr><td>Phone:</td><td>$webvar{phone}</td>
-<!-- <td>Default rDNS:</td><td><input name=def_rdns></td></tr>
-<tr><td>Description:</td><td><input name=description></td> -->
-<td>ARIN Handles:</td><td>
- Tech: $webvar{tech_handle}<br>
- Abuse: $webvar{abuse_handle}<br>
- Admin: $webvar{admin_handle}<br>
-</td></tr></table>
-);
-    } # $sth err check
-  } # bad custid
 } elsif ($webvar{action} eq 'edcust') {
   if ($webvar{newcust}) {
@@ -415,10 +364,10 @@
 <div style="margin-left:5px">
 <h3>Explanation for "Special" field:</h3>
-This is the field I've mangled into providing a custom WHOIS netname identifier for blocks tagged "SWIP".
+This is a temporary place to define the WHOIS "net name" for a block.
 It may be removed later, more likely migrated elsewhere.
 <p>It's formatted like this, one line for each custom net name:
 <pre>NetName[CIDR block]: NET-NAME</pre>
 Example:
-<pre>NetName209.91.133.0/24: CYBERSUDBURY-1</pre>
+<pre>NetName192.168.236.0/24: MEGAWIDGET-1</pre>
 Note:
 <ul style="margin-top: 0px;">
@@ -572,4 +521,40 @@
   print qq(<hr><a href="admin.cgi?action=showusers">Back</a> to user listing\n);
 
+} elsif ($webvar{action} eq 'emailnotice') {
+  print "<h4>Email notice management:</h4>\nClick the email addresses to edit that list.";
+  $sth = $ip_dbh->prepare("SELECT action,reciplist FROM notify");
+  $sth->execute;
+
+  print "<table border=1>\n";
+  while (my ($notice_code,$reciplist) = $sth->fetchrow_array() ) {
+##fixme: hairy mess, only a few things call mailNotify() anyway, so many possible notices won't work.
+    my $action_out = dispNoticeCode($notice_code);
+    print "<tr><td>$action_out</td>".
+	qq(<td><a href="admin.cgi?action=ednotice&code=$notice_code">$reciplist</a></td>).
+	qq(<td><a href="admin.cgi?action=delnotice&code=$notice_code">Delete</a></tr>\n);
+  }
+  print "</table>\n";
+} elsif ($webvar{action} eq 'ednotice') {
+  print "<h4>Editing recipient list for '".dispNoticeCode($webvar{code})."':</h4>\n";
+##work
+  $sth = $ip_dbh->prepare("SELECT reciplist FROM notify WHERE action=?");
+  $sth->execute($webvar{code});
+  my ($reciplist) = $sth->fetchrow_array;
+  $reciplist =~ s/,/\n/g;
+  print qq(<form action=admin.cgi method=POST><input type=hidden name=code value="$webvar{code}">\n).
+	qq(<input type=hidden name=action value="updnotice"><table border=1><tr><td>).
+	qq(<textarea cols="40" rows="5" name=reciplist>$reciplist</textarea></td><td><input type=submit value="Update">\n).
+	"</td></tr></table></form>\n";
+} elsif ($webvar{action} eq 'updnotice') {
+  print "<h4>Updating recipient list for '".dispNoticeCode($webvar{code})."':</h4>\n";
+  $sth = $ip_dbh->prepare("UPDATE notify SET reciplist=? WHERE action=?");
+  $webvar{reciplist} =~ s/[\r\n]+/,/g;
+  $sth->execute($webvar{reciplist}, $webvar{code});
+  if ($sth->err) {
+    print "Failed:  DB error: ".$sth->errstr."\n";
+  } else {
+    print "OK!<br>\n"
+  }
+  print qq(<a href="admin.cgi?action=emailnotice">Back to email notice list</a>\n);
 } elsif ($webvar{action} ne '<NULL>') {
   print "webvar{action} check failed: Don't know how to $webvar{action}";
@@ -724,2 +709,29 @@
   print "</form></table>\n";
 }
+
+
+# interpret the notify codes
+sub dispNoticeCode {
+  my $code = shift;
+  my $action_out = '';
+#    my $code = $notice_code;
+  if ($code =~ /^f:(.+)$/) {
+    $code =~ s/^f://;
+    $action_out = "Failure on ";
+  }
+  if (my $target = $code =~ /^n(.+)/) {
+    $action_out .= "New ";
+    if ($1 eq 'ci') { $action_out .= "city"; }
+    elsif ($1 eq 'no') { $action_out .= "node"; }
+    else { $action_out .= '&lt;unknown&gt;'; }
+  } else {
+    my ($action,$target) = ($code =~ /^(.)(.+)$/);
+    if ($action eq 'a')      { $action_out .= 'Add '; }
+    elsif ($action eq 'u')   { $action_out .= 'Update '; }
+    elsif ($action eq 'd')   { $action_out .= 'Delete '; }
+##fixme:  what if we get something funky?
+    if ($target eq 'a') { $action_out .= "all"; }
+    else { $action_out .= $disp_alloctypes{$target}; }
+  }
+  return $action_out;
+}
