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


Ignore:
Timestamp:
10/24/12 16:34:36 (12 years ago)
Author:
Kris Deugau
Message:

/trunk

Clean up and move SQL for static IP pool list to IPDB.pm. See #34.

  • Rename listPool in main.cgi to showPool, so that we can:
  • Add listPool sub in IPDB.pm
  • Convert getBlockData to return a hashref instead of an array, and update the one extant call

Tweak template to use odd for row colors

File:
1 edited

Legend:

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

    r527 r528  
    129129}
    130130elsif($webvar{action} eq 'listpool') {
    131   listPool();
     131  showPool();
    132132}
    133133
     
    267267
    268268# List the IPs used in a pool
    269 sub listPool {
     269sub showPool {
    270270
    271271  my $cidr = new NetAddr::IP $webvar{pool};
     
    280280
    281281  # Snag pool info for heading
    282   $sth = $ip_dbh->prepare("select type,city from allocations where cidr=?");
    283   $sth->execute($webvar{pool});
    284   my ($pooltype, $poolcity) = $sth->fetchrow_array;
    285 
    286   $page->param(disptype => $disp_alloctypes{$pooltype});
    287   $page->param(city => $poolcity);
     282  my $poolinfo = getBlockData($ip_dbh, $webvar{pool});
     283
     284  $page->param(disptype => $disp_alloctypes{$poolinfo->{type}});
     285  $page->param(city => $poolinfo->{city});
    288286
    289287  # Only display net/gw/bcast if it's a "real" netblock and not a PPP(oE) lunacy
    290   $page->param(realblock => $pooltype =~ /^.d$/);
     288  $page->param(realblock => $poolinfo->{type} =~ /^.d$/);
    291289
    292290# probably have to add an "edit IP allocation" link here somewhere.
    293291
    294   $sth = $ip_dbh->prepare("select ip,custid,available,description,type".
    295         " from poolips where pool='$webvar{pool}' order by ip");
    296   $sth->execute;
    297   my @poolips;
    298   my $rowclass = 0;
    299   while (my ($ip,$custid,$available,$desc,$type) = $sth->fetchrow_array) {
    300     my %row = (
    301         rowclass => $rowclass++ % 2,
    302         ip => $ip,
    303         custid => $custid,
    304         available => $available,
    305         desc => $desc,
    306         maydel => $IPDBacl{$authuser} =~ /d/,
    307         delme => $available eq 'n'
    308         );
    309     push @poolips, \%row;
    310   }
    311   $page->param(poolips => \@poolips);
    312 
    313 } # end listPool
     292  my $plist = listPool($ip_dbh, $webvar{pool});
     293  # technically slightly more efficient to check the ACL in an if () once outside the foreach
     294  foreach (@{$plist}) {
     295    $$_{maydel} = $IPDBacl{$authuser} =~ /d/;
     296  }
     297  $page->param(poolips => $plist);
     298} # end showPool
    314299
    315300
     
    10381023
    10391024  # need to retrieve block data before deleting so we can notify on that
    1040   my ($cidr,$custid,$type,$city,$description) = getBlockData($ip_dbh, $webvar{block});
     1025  my $blockinfo = getBlockData($ip_dbh, $webvar{block});
    10411026
    10421027  my ($code,$msg) = deleteBlock($ip_dbh, $webvar{block}, $webvar{alloctype});
     
    10441029  $page->param(block => $webvar{block});
    10451030  if ($code eq 'OK') {
    1046     syslog "notice", "$authuser deallocated '$webvar{alloctype}'-type netblock $webvar{block}".
    1047         " $custid, $city, desc='$description'";
     1031    syslog "notice", "$authuser deallocated '$webvar{alloctype}'-type netblock $webvar{block} ".
     1032        $blockinfo->{custid}.", ".$blockinfo->{city}.", desc='".$blockinfo->{description}."'";
    10481033    mailNotify($ip_dbh, 'da', "REMOVED: $disp_alloctypes{$webvar{alloctype}} $webvar{block}",
    10491034        "$disp_alloctypes{$webvar{alloctype}} $webvar{block} deallocated by $authuser\n".
    1050         "CustID: $custid\nCity: $city\nDescription: $description\n");
     1035        "CustID: ".$blockinfo->{custid}."\nCity: ".$blockinfo->{city}.
     1036        "\nDescription: ".$blockinfo->{description}."\n");
    10511037  } else {
    10521038    $page->param(failmsg => $msg);
Note: See TracChangeset for help on using the changeset viewer.