Ignore:
Timestamp:
07/26/10 17:00:00 (14 years ago)
Author:
Kris Deugau
Message:

/branches/stable

Bring /branches/stable up to date with /trunk. See #13.

Location:
branches/stable
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/stable

    • Property svn:ignore
      •  

        old new  
        11local.css
         2*.tar.gz
    • Property svn:mergeinfo changed
      /trunkmerged: 415-420,​422-443
  • branches/stable/cgi-bin/admin.cgi

    r414 r445  
    1010# Last update by $Author$
    1111###
    12 # Copyright (C) 2004-2006 - Kris Deugau
     12# Copyright (C) 2004-2010 - Kris Deugau
    1313
    1414use strict;
     
    1717use DBI;
    1818use CommonWeb qw(:ALL);
    19 use MyIPDB;
    2019use CustIDCK;
    2120#use POSIX qw(ceil);
     
    2423use Sys::Syslog;
    2524
    26 openlog "IPDB-admin","pid","local2";
     25# don't remove!  required for GNU/FHS-ish install from tarball
     26##uselib##
     27
     28use MyIPDB;
     29
     30openlog "IPDB-admin","pid","$IPDB::syslog_facility";
    2731
    2832# Collect the username from HTTP auth.  If undefined, we're in a test environment.
     
    5357        qq(\t<link rel="stylesheet" type="text/css" href="/ip/local.css">\n).
    5458        "</head>\n<body>\n".
    55         qq(Access to this tool is restricted.  Contact <a href="mailto:kdeugau\@vianet.ca">Kris</a> \n).
     59        qq(Access to this tool is restricted.  Contact the <a href="mailto:ipdbadmin\@example.com">IPDB administrator</a> \n).
    5660        "for more information.\n</body>\n</html>\n";
    5761  exit;
     
    8993  print qq(WARNING:  There are FAR fewer controls on what you can do here.  Use the
    9094main interface if at all possible.
    91 <hr>
    92 <a href="admin.cgi?action=newalloc">Add allocation</a>
    9395<hr>
    9496<form action="admin.cgi" method="POST">
     
    107109Bump "last updated" timestamp on this master: <select name=whichmaster>$masterlist</select>
    108110<input type=submit value="Update timestamp"> (Sets timestamp to "now")</form>
    109 <a href="admin.cgi?action=listcust">Edit customer data for rWHOIS</a>
     111<a href="admin.cgi?action=listcust">Edit customer data for rWHOIS</a> - data used for
     112blocks with the SWIP box checkmarked.  Links to edit/add data are on this page.
    110113
    111114<hr><a href="admin.cgi?action=showpools">List IP Pools</a> for manual tweaking and updates
     115
    112116<hr><a href="admin.cgi?action=showusers">Manage users</a> (add/remove users;  change
    113 internal access controls - note that this does NOT include IP-based limits)
     117internal access controls - note that this does NOT include IP-based limits)<br>
     118<a href="admin.cgi?action=emailnotice">Manage email notice options</a> (pick which events
     119and allocation types cause notifications;  configure recipient lists for notices)
     120
    114121<hr>Consistency check tools<br>
    115122<a href="consistency-check.pl">General</a>:  Check general netblock consistency.<br>
    116123<a href="freespace.pl">Free space</a>:  List total and aggregate free space.  Does not
    117124include private networks (192.168.0.0/16, 172.16.0.0/12, 10.0.0.0/8)
    118 <hr>(r)WHOIS<br>
    119 <a href="list-cust.php">List customer data for WHOIS</a> - data used for blocks with the SWIP box checkmarked.
    120 Links to edit/add data are on this page.
    121125);
    122126} else {
     
    149153      if (!$status) {
    150154        printError("Customer ID not valid.  Make sure the Customer ID ".
    151           "is correct.<br>\nUse STAFF for staff static IPs, and 6750400 for any other ".
     155          "is correct.<br>\nUse STAFF for staff static IPs, and $IPDB::defcustid for any other ".
    152156          "non-customer assignments.");
    153157        return;
     
    250254        syslog "notice", "$authuser allocated '$webvar{cidr}' to '$webvar{custid}' as ".
    251255                "'$webvar{alloctype}'";
    252         # Notify tech@example.com
    253         mailNotify('tech@example.com',"$disp_alloctypes{$webvar{alloctype}} allocation",
     256        mailNotify($ip_dbh, "a$webvar{alloctype}",
    254257          "$disp_alloctypes{$webvar{alloctype}} $webvar{cidr} allocated to customer".
    255258          " $webvar{custid}\n".
     
    306309<form action=admin.cgi method=POST>
    307310<table border=1><tr>
    308 <input type=hidden name=action value=newcust>
     311<input type=hidden name=action value=edcust>
     312<input type=hidden name=newcust value=1>
    309313<td>CustID:</td><td><input name=custid></td>
    310 <td>Name:</td><td><input name=name></td></tr>
    311 <tr><td>Street:</td><td><input name=street></td></tr>
    312 <!-- <td>Street2:</td><td><input name=street2></td> -->
    313 <tr><td>City:</td><td><input name=city></td>
    314 <td>Province: (2-letter code)</td><td><input name=province value=ON length=2 size=2></td></tr>
    315 <tr><td>Country: (2-letter code)</td><td><input name=country value=CA length=2 size=2></td>
    316 <td>Postal/ZIP Code:</td><td><input name=pocode></td></tr>
    317 <tr><td>Phone:</td><td><input name=phone></td>
    318 <!-- <td>Default rDNS:</td><td><input name=def_rdns></td></tr>
    319 <td>Description:</td><td><input name=description></td> -->
    320 <td>ARIN Handles:</td><td>
    321  Tech: <input name=tech_handle value="VH25-ORG-ARIN"><br>
    322  Abuse: <input name=abuse_handle><br>
    323  Admin: <input name=admin_handle><br>
    324 Note:  Only tech is required at the moment.
    325 </td></tr>
    326 <tr><td colspan=4 align=center><input type=submit value="Add"></td></tr>
     314<td align=center><input type=submit value="Go to edit page for this custid"></td></tr>
    327315</form></table>
    328316);
     
    336324  }
    337325  print "</table>\n";
    338 } elsif ($webvar{action} eq 'newcust') {
    339   if ($webvar{custid} eq '') {
    340     print 'No CustID entered.  PTHBT!  (Hit "Back" and fix the problem.)';
    341   } else {
    342     $sth = $ip_dbh->prepare("insert into customers ".
    343         "(custid, name, street, city, province, country, pocode, ".
    344         "phone, tech_handle, abuse_handle, admin_handle) values ".
    345         "('$webvar{custid}', '$webvar{name}', '$webvar{street}', ".
    346         "'$webvar{city}', '$webvar{province}', '$webvar{country}', ".
    347         "'$webvar{pocode}', '$webvar{phone}', '$webvar{techhandle}', ".
    348         "'$webvar{abusehandle}', '$webvar{adminhandle}')");
    349     $sth->execute;
    350     if ($sth->err) {
    351       print "INSERT failed:  ".$sth->errstr."\n";
    352     } else {
    353       print "Success!  Added customer contact data:\n".
    354         qq(<table border=1><tr>
    355 <td>CustID:</td>$webvar{custid}</td><td>Name:</td>$webvar{name}</td></tr>
    356 <tr><td>Street:</td><td>$webvar{street}</td></tr>
    357 <tr><td>City:</td><td>$webvar{city}</td><td>Province:</td><td>$webvar{province}</td></tr>
    358 <tr><td>Country:</td><td>$webvar{country}</td>
    359 <td>Postal/ZIP Code:</td><td>$webvar{pocode}</td></tr>
    360 <tr><td>Phone:</td><td>$webvar{phone}</td>
    361 <!-- <td>Default rDNS:</td><td><input name=def_rdns></td></tr>
    362 <tr><td>Description:</td><td><input name=description></td> -->
    363 <td>ARIN Handles:</td><td>
    364  Tech: $webvar{tech_handle}<br>
    365  Abuse: $webvar{abuse_handle}<br>
    366  Admin: $webvar{admin_handle}<br>
    367 </td></tr></table>
    368 );
    369     } # $sth err check
    370   } # bad custid
    371326} elsif ($webvar{action} eq 'edcust') {
     327  if ($webvar{newcust}) {
     328    print "got here?\n";
     329    $sth = $ip_dbh->prepare("INSERT INTO customers (custid) VALUES (?)");
     330    $sth->execute($webvar{custid});
     331  }
    372332  $sth = $ip_dbh->prepare("select custid,name,street,city,province,".
    373         "country,pocode,phone,tech_handle,abuse_handle,admin_handle ".
     333        "country,pocode,phone,tech_handle,abuse_handle,admin_handle,special ".
    374334        "from customers where custid='$webvar{custid}'");
    375335  $sth->execute;
    376   my ($custid, $name, $street, $city, $prov, $country, $pocode, $phone, $tech, $abuse, $admin) =
     336  my ($custid, $name, $street, $city, $prov, $country, $pocode, $phone, $tech, $abuse, $admin, $special) =
    377337        $sth->fetchrow_array;
    378338  print qq(<form action=admin.cgi method=POST>
     
    381341<td>CustID:</td><td>$custid<input type=hidden name=custid value=$custid></td>
    382342<td>Name:</td><td><input name=name value="$name"></td></tr>
    383 <tr><td>Street:</td><td><input name=street value="$street"></td></tr>
     343<tr><td>Street:</td><td><input name=street value="$street"></td>
    384344<!-- <td>Street2:</td><td><input name=street2></td> -->
    385 <tr><td>City:</td><td><input name=city value="$city"></td>
    386 <td>Province: (2-letter code)</td><td><input name=province value="$prov" length=2 size=2></td></tr>
    387 <tr><td>Country: (2-letter code)</td><td><input name=country value="$country" length=2 size=2></td>
    388 <td>Postal/ZIP Code:</td><td><input name=pocode value="$pocode"></td></tr>
    389 <tr><td>Phone:</td><td><input name=phone value="$pocode"></td>
     345<td>City:</td><td><input name=city value="$city"></td></tr>
     346<tr><td>Province/State: (2-letter code)</td><td><input name=province value="$prov" length=2 size=2></td>
     347<td>Country: (2-letter code)</td><td><input name=country value="$country" length=2 size=2></td></tr>
     348<tr><td>Postal/ZIP Code:</td><td><input name=pocode value="$pocode"></td>
     349<td>Phone:</td><td><input name=phone value="$pocode"></td></tr>
    390350<!-- <td>Default rDNS:</td><td><input name=def_rdns></td></tr>
    391351<td>Description:</td><td><input name=description></td> -->
    392 <td>ARIN Handles:</td><td>
     352<tr><td>Contacts/ARIN Handles:</td><td>
    393353 Tech: <input name=tech_handle value="$tech"><br>
    394354 Abuse: <input name=abuse_handle value="$abuse"><br>
    395355 Admin: <input name=admin_handle value="$admin"><br>
    396356Note:  Only tech is required at the moment.
    397 </td></tr>
     357</td>
     358<td>"Special":</td><td><textarea name=special rows=4 cols=50>$special</textarea></td>
     359</tr>
    398360<tr><td colspan=4 align=center><input type=submit value="Update"></td></tr>
    399361</form></table>
     362<div style="margin-left:5px">
     363<h3>Explanation for "Special" field:</h3>
     364This is a temporary place to define the WHOIS "net name" for a block.
     365It may be removed later, more likely migrated elsewhere.
     366<p>It's formatted like this, one line for each custom net name:
     367<pre>NetName[CIDR block]: NET-NAME</pre>
     368Example:
     369<pre>NetName192.168.236.0/24: MEGAWIDGET-1</pre>
     370Note:
     371<ul style="margin-top: 0px;">
     372<li>Spacing is important - there should only be ONE space, in between the colon and the net name.
     373<li>The CIDR block name nust include all four octets - no short forms are accepted.
     374<li>Net names must be all uppercase, and consist only of A-Z, 0-9, and - (same as for SWIPed net names).
     375</ul>
     376</div>
    400377);
    401378
    402379} elsif ($webvar{action} eq 'updcust') {
    403   print "Updated $webvar{custid}\n";
     380  $sth = $ip_dbh->prepare("UPDATE customers SET".
     381        " name=?, street=?, city=?, province=?, country=?, pocode=?,".
     382        " phone=?, tech_handle=?, abuse_handle=?, admin_handle=?, special=?".
     383        " WHERE custid=?");
     384  $sth->execute($webvar{name}, $webvar{street}, $webvar{city}, $webvar{province},
     385        $webvar{country}, $webvar{pocode}, $webvar{phone}, $webvar{tech_handle},
     386        $webvar{abuse_handle}, $webvar{admin_handle}, $webvar{special}, $webvar{custid});
     387  print "Updated $webvar{custid}<br>\n".
     388        qq(<table border=1>
     389<tr><td>CustID:</td><td>$webvar{custid}</td></tr>
     390<tr><td>Name:</td><td>$webvar{name}</td></tr>
     391<tr><td>Street:</td><td>$webvar{street}</td></tr>
     392<tr><td>City:</td><td>$webvar{city}</td></tr>
     393<tr><td>Province/State:</td><td>$webvar{province}</td></tr>
     394<tr><td>Country:</td><td>$webvar{country}</td></tr>
     395<tr><td>Postal/ZIP Code:</td><td>$webvar{pocode}</td></tr>
     396<tr><td>Phone:</td><td>$webvar{phone}</td></tr>
     397<!-- <td>Default rDNS:</td><td>$webvar{def_rdns}</td></tr> -->
     398<tr><td>Contacts/ARIN Handles:</td><td>
     399 Tech: $webvar{tech_handle}<br>
     400 Abuse: $webvar{abuse_handle}<br>
     401 Admin: $webvar{admin_handle}<br>
     402</td></tr>
     403<tr><td>"Special":</td><td><pre>$webvar{special}</pre></td></tr>
     404</table>
     405<a href="admin.cgi?action=listcust">Back</a> to rWHOIS customer list<br>\n);
     406
    404407} elsif ($webvar{action} eq 'showpools') {
    405408  print "IP Pools currently allocated:\n".
     
    516519  print qq(<hr><a href="admin.cgi?action=showusers">Back</a> to user listing\n);
    517520
     521} elsif ($webvar{action} eq 'emailnotice') {
     522  print "<h4>Email notice management:</h4>\nClick the email addresses to edit that list.";
     523  $sth = $ip_dbh->prepare("SELECT action,reciplist FROM notify");
     524  $sth->execute;
     525
     526  print "<table border=1>\n";
     527  while (my ($notice_code,$reciplist) = $sth->fetchrow_array() ) {
     528##fixme: hairy mess, only a few things call mailNotify() anyway, so many possible notices won't work.
     529    my $action_out = dispNoticeCode($notice_code);
     530    print "<tr><td>$action_out</td>".
     531        qq(<td><a href="admin.cgi?action=ednotice&code=$notice_code">$reciplist</a></td>).
     532        qq(<td><a href="admin.cgi?action=delnotice&code=$notice_code">Delete</a></tr>\n);
     533  }
     534  print qq(<tr><td colspan=2>Known "special" codes:<br>
     535<ul style="margin-top: 0px; margin-bottom: 0px;">
     536        <li>swi: Notify if block being updated has SWIP flag set</li>
     537</ul></td></tr>
     538</table>
     539);
     540
     541# add new entries from this tangle:
     542  print "<h4>Add new notification:</h4>\n".
     543        "Note:  Failure notices on most conditions are not yet supported.\n";
     544
     545  print qq(<table border=1><form action=admin.cgi method="POST">
     546<input type=hidden name=action value=addnotice>
     547<tr>
     548<td>Recipients</td><td colspan=3><textarea name=reciplist cols=50 rows=5></textarea></td></tr>
     549<tr><td>Action</td><td>
     550        <table><tr>
     551                <td><input type=radio name=msgaction value=a>Add &nbsp;
     552                <input type=radio name=msgaction value=u>Update &nbsp;
     553                <input type=radio name=msgaction value=d>Delete &nbsp;
     554                <input type=radio name=msgaction value=n>New listitem</td>
     555        </tr><tr>
     556                <td>
     557                <input type=radio name=msgaction value=s:>Special: <input name=special>(requires code changes)
     558        </td></tr></table>
     559</td>
     560<td>Failure?</td><td><input type=checkbox name=onfail></td></tr>
     561<tr><td>Event/Allocation type:</td><td colspan=3>
     562        <table>
     563        <tr>
     564                <td><input type=radio name=alloctype value=a>All allocations</td>
     565                <td><input type=radio name=alloctype value=.i>All static IPs</td>
     566                <td><input type=radio name=alloctype value=ci>New city</td>
     567                <td><input type=radio name=alloctype value=no>New node</td>
     568        </tr>
     569        <tr>
     570);
     571
     572  $sth = $ip_dbh->prepare("SELECT type,dispname FROM alloctypes WHERE listorder < 500 ".
     573        "ORDER BY listorder");
     574  $sth->execute;
     575  my $i=0;
     576  while (my ($type,$disp) = $sth->fetchrow_array) {
     577    print "             <td><input type=radio name=alloctype value=$type>$disp</td>";
     578    $i++;
     579    print "     </tr>\n\t<tr>"
     580        if ($i % 4 == 0);
     581  }
     582
     583  print qq(     </tr>
     584        </table>
     585</tr>
     586<tr><td colspan=4 align=center><input type=submit value="Add notice"></td></tr>
     587</table>
     588</form>
     589);
     590  ## done spitting out add-new-spam-me-now table
     591
     592} elsif ($webvar{action} eq 'addnotice') {
     593  $webvar{alloctype} = $webvar{special} if $webvar{msgaction} eq 's:';
     594  if ($webvar{msgaction} && $webvar{alloctype} && $webvar{reciplist}) {
     595    $webvar{reciplist} =~ s/[\r\n]+/,/g;
     596    $webvar{msgaction} = "f:$webvar{msgaction}" if $webvar{onfail};
     597    print "Adding notice to $webvar{reciplist} for ".dispNoticeCode($webvar{msgaction}.$webvar{alloctype}).":\n";
     598    $sth = $ip_dbh->prepare("INSERT INTO notify (action, reciplist) VALUES (?,?)");
     599##fixme:  automagically merge reciplists iff action already exists
     600    $sth->execute($webvar{msgaction}.$webvar{alloctype}, $webvar{reciplist});
     601    if ($sth->err) {
     602      print "Failed:  DB error: ".$sth->errstr."\n";
     603    } else {
     604      print "OK!<br>\n"
     605    }
     606  } else {
     607    print "Need to specify at least one recipient, an action, and an allocation type. ".
     608        qq{("Special" content is considered an allocation type).  Hit the Back button and try again.<br>\n};
     609  }
     610  print qq(<a href="admin.cgi?action=emailnotice">Back to email notice list</a>\n);
     611
     612} elsif ($webvar{action} eq 'delnotice') {
     613  print "Deleting notices on ".dispNoticeCode($webvar{code}.$webvar{alloctype}).":\n";
     614  $sth = $ip_dbh->prepare("DELETE FROM notify WHERE action=?");
     615  $sth->execute($webvar{code});
     616  if ($sth->err) {
     617    print "Failed:  DB error: ".$sth->errstr."\n";
     618  } else {
     619    print "OK!<br>\n"
     620  }
     621  print qq(<a href="admin.cgi?action=emailnotice">Back to email notice list</a>\n);
     622
     623} elsif ($webvar{action} eq 'ednotice') {
     624  print "<h4>Editing recipient list for '".dispNoticeCode($webvar{code})."':</h4>\n";
     625  $sth = $ip_dbh->prepare("SELECT reciplist FROM notify WHERE action=?");
     626  $sth->execute($webvar{code});
     627  my ($reciplist) = $sth->fetchrow_array;
     628  $reciplist =~ s/,/\n/g;
     629  print qq(<form action=admin.cgi method=POST><input type=hidden name=code value="$webvar{code}">\n).
     630        qq(<input type=hidden name=action value="updnotice"><table border=1><tr><td>).
     631        qq(<textarea cols="40" rows="5" name=reciplist>$reciplist</textarea></td><td><input type=submit value="Update">\n).
     632        "</td></tr></table></form>\n";
     633} elsif ($webvar{action} eq 'updnotice') {
     634  print "<h4>Updating recipient list for '".dispNoticeCode($webvar{code})."':</h4>\n";
     635  $sth = $ip_dbh->prepare("UPDATE notify SET reciplist=? WHERE action=?");
     636  $webvar{reciplist} =~ s/[\r\n]+/,/g;
     637  $sth->execute($webvar{reciplist}, $webvar{code});
     638  if ($sth->err) {
     639    print "Failed:  DB error: ".$sth->errstr."\n";
     640  } else {
     641    print "OK!<br>\n"
     642  }
     643  print qq(<a href="admin.cgi?action=emailnotice">Back to email notice list</a>\n);
    518644} elsif ($webvar{action} ne '<NULL>') {
    519645  print "webvar{action} check failed: Don't know how to $webvar{action}";
     
    668794  print "</form></table>\n";
    669795}
     796
     797
     798# interpret the notify codes
     799sub dispNoticeCode {
     800  my $code = shift;
     801  my $action_out = '';
     802
     803  if ($code =~ /^s:/) {
     804    $code =~ s/^s:/Special: /;
     805    return $code;
     806  }
     807  if ($code =~ /^f:(.+)$/) {
     808    $code =~ s/^f://;
     809    $action_out = "Failure on ";
     810  }
     811  if (my $target = $code =~ /^n(.+)/) {
     812    $action_out .= "New ";
     813    if ($1 eq 'ci') { $action_out .= "city"; }
     814    elsif ($1 eq 'no') { $action_out .= "node"; }
     815    else { $action_out .= '&lt;unknown&gt;'; }
     816  } else {
     817    my ($action,$target) = ($code =~ /^(.)(.+)$/);
     818    if ($action eq 'a')      { $action_out .= 'Add '; }
     819    elsif ($action eq 'u')   { $action_out .= 'Update '; }
     820    elsif ($action eq 'd')   { $action_out .= 'Delete '; }
     821##fixme:  what if we get something funky?
     822# What about the eleventy-billion odd combinations possible?
     823# this should give an idea of the structure tho
     824    if ($target eq 'a') { $action_out .= "all"; }
     825    elsif ($target eq '.i') {
     826      $action_out .= "all static IPs";
     827    }
     828    else { $action_out .= $disp_alloctypes{$target}; }
     829  }
     830  return $action_out;
     831}
Note: See TracChangeset for help on using the changeset viewer.