Changeset 483


Ignore:
Timestamp:
Sep 20, 2010, 5:16:54 PM (11 years ago)
Author:
Kris Deugau
Message:

/branches/htmlform

Start converting admin.cgi to templates (to make removal of references to CommonWeb?.pm
subs simpler; see #3, #15, #26)
Completed:

  • Main page
  • ACL error page
  • rWHOIS customer data editing - list, edit new/update, confirm update
Location:
branches/htmlform
Files:
7 added
1 edited

Legend:

Unmodified
Added
Removed
  • branches/htmlform/cgi-bin/admin.cgi

    r468 r483  
    5353initIPDBGlobals($ip_dbh);
    5454
    55 ##fixme - need to autofill this somehow
    56 $ENV{HTML_TEMPLATE_ROOT} = '/home/kdeugau/dev/ipdb/trunk/templates';
     55# anyone got a better name?  :P
     56my $thingroot = $ENV{SCRIPT_FILENAME};
     57$thingroot =~ s|cgi-bin/admin.cgi||;
     58
     59# Set up some globals
     60$ENV{HTML_TEMPLATE_ROOT} = $thingroot."templates";
    5761
    5862if ($IPDBacl{$authuser} !~ /A/) {
    59   print "Content-Type: text/html\n\n".
    60         "<html>\n<head>\n\t<title>Access denied</title>\n".
    61         qq(\t<link rel="stylesheet" type="text/css" href="/ip/ipdb.css">\n).
    62         qq(\t<link rel="stylesheet" type="text/css" href="/ip/local.css">\n).
    63         "</head>\n<body>\n".
    64         qq(Access to this tool is restricted.  Contact the <a href="mailto:ipdbadmin\@example.com">IPDB administrator</a> \n).
    65         "for more information.\n</body>\n</html>\n";
     63  my $page = HTML::Template->new(filename => "admin/aclerr.tmpl");
     64##fixme:  need params for IPDB admin email and name
     65  $page->param(ipdbadmin_email => 'ipdbadmin@example.com');
     66  $page->param(ipdbadmin_name => 'the IPDB administrator');
     67  print "Content-Type: text/html\n\n".$page->output;
    6668  exit;
    6769}
     
    7678my %webvar = $q->Vars;
    7779
    78 print "Content-type: text/html\n\n".
    79         "<html>\n<head>\n\t<title>[IPDB admin tools]</title>\n".
    80         qq(\t<link rel="stylesheet" type="text/css" href="/ip/ipdb.css">\n).
    81         qq(\t<link rel="stylesheet" type="text/css" href="/ip/local.css">\n).
    82         "</head>\n<body>\n".
    83         "<h2>IPDB - Administrative Tools</h2>\n<hr>\n";
     80my $header = HTML::Template->new(filename => "admin/header.tmpl");
    8481
    8582if(!defined($webvar{action})) {
    86   $webvar{action} = "<NULL>";   #shuts up the warnings.
    87 
    88   my $typelist = '';
     83  $webvar{action} = "main";   #shuts up the warnings.
     84}
     85
     86#print "Content-type: text/html\n\n".$header->output;
     87my $page = HTML::Template->new(filename => "admin/$webvar{action}.tmpl");
     88
     89if ($webvar{action} eq 'main') {
     90  $header->param(mainpage => 1);
     91
    8992  $sth = $ip_dbh->prepare("select type,listname from alloctypes where listorder < 900 order by listorder");
    9093  $sth->execute;
    91   my @data = $sth->fetchrow_array;
    92   $typelist .= "<option value='$data[0]' selected>$data[1]</option>\n";
    93   while (my @data = $sth->fetchrow_array) {
    94     $typelist .= "<option value='$data[0]'>$data[1]</option>\n";
    95   }
    96 
    97   my $masterlist = '';
     94
     95  my @typelist;
     96  my $count = 0;
     97  while (my ($type,$listname) = $sth->fetchrow_array) {
     98    my %row = (
     99        selected => $count++,
     100        type => $type,
     101        dispname => $listname
     102        );
     103    push @typelist, \%row;
     104  }
     105  $page->param(typelist => \@typelist);
     106
     107  my @masterlist;
    98108  $sth = $ip_dbh->prepare("select cidr,mtime from masterblocks order by cidr");
    99109  $sth->execute;
    100   while (my @data = $sth->fetchrow_array) {
    101     $masterlist .= "<option value='$data[0]'>$data[0] ($data[1])</option>\n";
    102   }
    103 
    104   print qq(WARNING:  There are FAR fewer controls on what you can do here.  Use the
    105 main interface if at all possible.
    106 <hr>
    107 <form action="admin.cgi" method="POST">
    108 <input type=hidden name=action value=alloc>
    109 Allocate block/IP: <input name=cidr> as <select name=alloctype>$typelist</select> to <input name=custid>
    110 <input type=submit value=" GIMME!! "></form>
    111 <hr><form action="admin.cgi" method="POST">
    112 <input type=hidden name=action value=alloctweak>
    113 Manually update allocation data in this /24: <input name=allocfrom>
    114 <input type=submit value="Show allocations">
    115 </form>
    116 
    117 <hr>rWHOIS tools:
    118 <form action="admin.cgi" method="POST">
    119 <input type=hidden name=action value=touch>
    120 Bump "last updated" timestamp on this master: <select name=whichmaster>$masterlist</select>
    121 <input type=submit value="Update timestamp"> (Sets timestamp to "now")</form>
    122 <a href="admin.cgi?action=listcust">Edit customer data for rWHOIS</a> - data used for
    123 blocks with the SWIP box checkmarked.  Links to edit/add data are on this page.
    124 
    125 <hr><a href="admin.cgi?action=showpools">List IP Pools</a> for manual tweaking and updates
    126 
    127 <hr><a href="admin.cgi?action=showusers">Manage users</a> (add/remove users;  change
    128 internal access controls - note that this does NOT include IP-based limits)<br>
    129 <a href="admin.cgi?action=emailnotice">Manage email notice options</a> (pick which events
    130 and allocation types cause notifications;  configure recipient lists for notices)
    131 
    132 <hr>Consistency check tools<br>
    133 <a href="consistency-check.pl">General</a>:  Check general netblock consistency.<br>
    134 <a href="freespace.pl">Free space</a>:  List total and aggregate free space.  Does not
    135 include private networks (192.168.0.0/16, 172.16.0.0/12, 10.0.0.0/8)
    136 );
    137 } else {
    138   print '<a href="/ip/cgi-bin/admin.cgi">Back</a> to main<hr>';
     110  while (my ($cidr,$mtime) = $sth->fetchrow_array) {
     111    my %row = (
     112        master => $cidr,
     113        masterdate => $mtime
     114        );
     115    push @masterlist, \%row;
     116  }
     117  $page->param(masterlist => \@masterlist);
     118
     119#} else {
     120#  print '<a href="/ip/cgi-bin/admin.cgi">Back</a> to main<hr>';
    139121}
    140122
    141123
    142124## Possible actions.
    143 if ($webvar{action} eq 'alloc') {
     125elsif ($webvar{action} eq 'alloc') {
    144126  # OK, we know what we're allocating.
    145127
     
    315297    print "<p>Error updating modified timestamp on master $webvar{whichmaster}: ".$sth->errstr."\n";
    316298  }
     299
    317300} elsif ($webvar{action} eq 'listcust') {
    318   print qq(Add new entry:\n
    319 <form action=admin.cgi method=POST>
    320 <table border=1><tr>
    321 <input type=hidden name=action value=edcust>
    322 <input type=hidden name=newcust value=1>
    323 <td>CustID:</td><td><input name=custid></td>
    324 <td align=center><input type=submit value="Go to edit page for this custid"></td></tr>
    325 </form></table>
    326 );
    327   print "<p>Click CustID to edit existing customer contact data:\n".
    328         "<table border=1>\n<tr><td>CustID</td><td>Name</td><td>Tech handle</td></tr>\n";
     301
    329302  $sth = $ip_dbh->prepare("select custid,name,tech_handle from customers order by custid");
    330303  $sth->execute;
     304  my @custlist;
    331305  while (my @data = $sth->fetchrow_array) {
    332     print qq(<tr><td><a href="admin.cgi?action=edcust&custid=$data[0]">$data[0]</td>).
    333         "<td>$data[1]</td><td>$data[2]</td></tr>\n";
    334   }
    335   print "</table>\n";
     306    my %row = (
     307        custid => $data[0],
     308        custname => $data[1],
     309        tech => $data[2]
     310        );
     311    push @custlist, \%row;
     312  }
     313  $page->param(custlist => \@custlist);
     314
    336315} elsif ($webvar{action} eq 'edcust') {
     316
    337317  if ($webvar{newcust}) {
    338     print "got here?\n";
    339318    $sth = $ip_dbh->prepare("INSERT INTO customers (custid) VALUES (?)");
    340319    $sth->execute($webvar{custid});
     
    346325  my ($custid, $name, $street, $city, $prov, $country, $pocode, $phone, $tech, $abuse, $admin, $special) =
    347326        $sth->fetchrow_array;
    348   print qq(<form action=admin.cgi method=POST>
    349 <table border=1><tr>
    350 <input type=hidden name=action value=updcust>
    351 <td>CustID:</td><td>$custid<input type=hidden name=custid value=$custid></td>
    352 <td>Name:</td><td><input name=name value="$name"></td></tr>
    353 <tr><td>Street:</td><td><input name=street value="$street"></td>
    354 <!-- <td>Street2:</td><td><input name=street2></td> -->
    355 <td>City:</td><td><input name=city value="$city"></td></tr>
    356 <tr><td>Province/State: (2-letter code)</td><td><input name=province value="$prov" length=2 size=2></td>
    357 <td>Country: (2-letter code)</td><td><input name=country value="$country" length=2 size=2></td></tr>
    358 <tr><td>Postal/ZIP Code:</td><td><input name=pocode value="$pocode"></td>
    359 <td>Phone:</td><td><input name=phone value="$pocode"></td></tr>
    360 <!-- <td>Default rDNS:</td><td><input name=def_rdns></td></tr>
    361 <td>Description:</td><td><input name=description></td> -->
    362 <tr><td>Contacts/ARIN Handles:</td><td>
    363  Tech: <input name=tech_handle value="$tech"><br>
    364  Abuse: <input name=abuse_handle value="$abuse"><br>
    365  Admin: <input name=admin_handle value="$admin"><br>
    366 Note:  Only tech is required at the moment.
    367 </td>
    368 <td>"Special":</td><td><textarea name=special rows=4 cols=50>$special</textarea></td>
    369 </tr>
    370 <tr><td colspan=4 align=center><input type=submit value="Update"></td></tr>
    371 </form></table>
    372 <div style="margin-left:5px">
    373 <h3>Explanation for "Special" field:</h3>
    374 This is a temporary place to define the WHOIS "net name" for a block.
    375 It may be removed later, more likely migrated elsewhere.
    376 <p>It's formatted like this, one line for each custom net name:
    377 <pre>NetName[CIDR block]: NET-NAME</pre>
    378 Example:
    379 <pre>NetName192.168.236.0/24: MEGAWIDGET-1</pre>
    380 Note:
    381 <ul style="margin-top: 0px;">
    382 <li>Spacing is important - there should only be ONE space, in between the colon and the net name.
    383 <li>The CIDR block name nust include all four octets - no short forms are accepted.
    384 <li>Net names must be all uppercase, and consist only of A-Z, 0-9, and - (same as for SWIPed net names).
    385 </ul>
    386 </div>
    387 );
     327
     328  $page->param(
     329        custid => $custid,
     330        name => $name,
     331        street => $street,
     332        city => $city,
     333        prov => $prov,
     334        country => $country,
     335        pocode => $pocode,
     336        phone => $phone,
     337        tech => $tech,
     338        abuse => $abuse,
     339        admin => $admin,
     340        special => $special
     341        );
    388342
    389343} elsif ($webvar{action} eq 'updcust') {
     344
    390345  $sth = $ip_dbh->prepare("UPDATE customers SET".
    391346        " name=?, street=?, city=?, province=?, country=?, pocode=?,".
     
    395350        $webvar{country}, $webvar{pocode}, $webvar{phone}, $webvar{tech_handle},
    396351        $webvar{abuse_handle}, $webvar{admin_handle}, $webvar{special}, $webvar{custid});
    397   print "Updated $webvar{custid}<br>\n".
    398         qq(<table border=1>
    399 <tr><td>CustID:</td><td>$webvar{custid}</td></tr>
    400 <tr><td>Name:</td><td>$webvar{name}</td></tr>
    401 <tr><td>Street:</td><td>$webvar{street}</td></tr>
    402 <tr><td>City:</td><td>$webvar{city}</td></tr>
    403 <tr><td>Province/State:</td><td>$webvar{province}</td></tr>
    404 <tr><td>Country:</td><td>$webvar{country}</td></tr>
    405 <tr><td>Postal/ZIP Code:</td><td>$webvar{pocode}</td></tr>
    406 <tr><td>Phone:</td><td>$webvar{phone}</td></tr>
    407 <!-- <td>Default rDNS:</td><td>$webvar{def_rdns}</td></tr> -->
    408 <tr><td>Contacts/ARIN Handles:</td><td>
    409  Tech: $webvar{tech_handle}<br>
    410  Abuse: $webvar{abuse_handle}<br>
    411  Admin: $webvar{admin_handle}<br>
    412 </td></tr>
    413 <tr><td>"Special":</td><td><pre>$webvar{special}</pre></td></tr>
    414 </table>
    415 <a href="admin.cgi?action=listcust">Back</a> to rWHOIS customer list<br>\n);
     352  $page->param(
     353        custid => $webvar{custid},
     354        name => $webvar{name},
     355        street => $webvar{street},
     356        city => $webvar{city},
     357        prov => $webvar{province},
     358        country => $webvar{country},
     359        pocode => $webvar{pocode},
     360        phone => $webvar{phone},
     361        tech => $webvar{tech_handle},
     362        abuse => $webvar{abuse_handle},
     363        admin => $webvar{admin_handle},
     364        special => $webvar{special}
     365        );
    416366
    417367} elsif ($webvar{action} eq 'showpools') {
     
    656606}
    657607
     608print "Content-type: text/html\n\n".$header->output;
     609print $page->output;
     610
     611##fixme:  make me a footer param!
     612print qq(<hr><div><a href="/ip/">Back</a> to main interface</div>\n);
     613
     614# We print the footer here, so we don't have to do it elsewhere.
     615my $footer = HTML::Template->new(filename => "footer.tmpl");
     616# we're already in the admin tools, no need to provide a bottom link.  maybe.
     617#$footer->param(adminlink => ($IPDBacl{$authuser} =~ /A/));
     618
     619print $footer->output;
     620
     621$ip_dbh->disconnect;
     622
     623exit;
     624
     625
    658626# Hokay.  This is a little different.  We have a few specific functions here:
    659627#  -> Assign arbitrary subnet from arbitrary free space
    660628#  -> Tweak individual DB fields
    661629#
    662 
    663 print qq(<hr><a href="/ip/">Back</a> to main interface</a>\n);
    664 
    665 # We print the footer here, so we don't have to do it elsewhere.
    666 my $footer = HTML::Template->new(filename => "footer.tmpl");
    667 # we're already in the admin tools, no need to provide a bottom link.  maybe.
    668 #$footer->param(adminlink => ($IPDBacl{$authuser} =~ /A/));
    669 
    670 print $footer->output;
    671 
    672 $ip_dbh->disconnect;
    673 
    674 exit;
    675630
    676631
Note: See TracChangeset for help on using the changeset viewer.