Changeset 527 for trunk/cgi-bin/main.cgi


Ignore:
Timestamp:
10/23/12 13:32:47 (12 years ago)
Author:
Kris Deugau
Message:

/trunk

Clean up and move SQL for showRBlock to IPDB.pm
Tweak listFree() since the segments in showMaster and showRBlock it
replaced weren't quite as identical as I thought
Convert template to use odd and squeeze a bit more HTML out of
main.cgi and IPDB.pm

See #34.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/cgi-bin/main.cgi

    r524 r527  
    238238  $page->param(routedlist => $rlist);
    239239
    240   my $flist = listFree($ip_dbh, $webvar{block}, 'n');
     240  my $flist = listFree($ip_dbh, $webvar{block});
    241241  $page->param(unrouted => $flist);
    242242} # showMaster
     
    252252sub showRBlock {
    253253
    254   my $master = new NetAddr::IP $webvar{block};
    255 
    256   $sth = $ip_dbh->prepare("select city from routed where cidr='$master'");
    257   $sth->execute;
    258   my ($rcity) = $sth->fetchrow_array;
    259 
    260   $page->param(master => "$master");
     254  $page->param(master => $webvar{block});
     255  $page->param(delrouted => $IPDBacl{$authuser} =~ /d/);
     256
     257  my $rcity = getRoutedCity($ip_dbh, $webvar{block});
    261258  $page->param(rcity => $rcity);
    262259
    263   # Snag the allocations for this block
    264   $sth = $ip_dbh->prepare("select cidr,city,type,custid,swip,description".
    265         " from allocations where cidr <<= '$master' order by cidr");
    266   $sth->execute();
    267 
    268   # hack hack hack
    269   # set up to flag swip=y records if they don't actually have supporting data in the customers table
    270   my $custsth = $ip_dbh->prepare("select count(*) from customers where custid=?");
    271 
    272   my $rowclass = 0;
    273   my @blocklist;
    274   while (my ($cidr,$city,$type,$custid,$swip,$desc) = $sth->fetchrow_array()) {
    275     $custsth->execute($custid);
    276     my ($ncust) = $custsth->fetchrow_array();
    277 
    278     my %row = (
    279         rowclass => $rowclass++ % 2,
    280         block => $cidr,
    281         city => $city,
    282         type => $disp_alloctypes{$type},
    283         custid => $custid,
    284         swip => ($swip eq 'y' ? ($ncust == 0 ? 'Yes<small>*</small>' : 'Yes') : 'No'),
    285         desc => $desc
    286         );
    287     $row{subblock} = ($type =~ /^.r$/);         # hmf.  wonder why these won't work in the hash declaration...
    288     $row{listpool} = ($type =~ /^.[pd]$/);
    289     push (@blocklist, \%row);
    290   }
    291   $page->param(blocklist => \@blocklist);
    292 
    293   $page->param(delrouted => $IPDBacl{$authuser} =~ /d/);
    294 
    295   # Snag the free blocks.  We don't really *need* to be pedantic about avoiding
    296   # unrouted free blocks, but it's better to let the database do the work if we can.
    297   $rowclass = 0;
    298   my @unassigned;
    299   $sth = $ip_dbh->prepare("select cidr,routed from freeblocks where cidr <<= '$master'".
    300         " order by cidr");
    301   $sth->execute();
    302   while (my ($cidr_db,$routed) = $sth->fetchrow_array()) {
    303     my $cidr = new NetAddr::IP $cidr_db;
    304 
    305     my %row = (
    306         rowclass => $rowclass++ % 2,
    307         subblock => ($routed ne 'y' && $routed ne 'n'),
    308         fblock => $cidr_db,
    309         fbtype => $routed,
    310         frange => $cidr->range,
    311         );
    312     push @unassigned, \%row;
    313   }
    314   $page->param(unassigned => \@unassigned);
    315 
     260  my $blist = listRBlock($ip_dbh, $webvar{block});
     261  $page->param(blocklist => $blist);
     262
     263  my $flist = listFree($ip_dbh, $webvar{block}, 'y');
     264  $page->param(unassigned => $flist);
    316265} # showRBlock
    317266
Note: See TracChangeset for help on using the changeset viewer.