Changeset 528


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

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/cgi-bin/IPDB.pm

    r527 r528  
    2727        &initIPDBGlobals &connectDB &finish &checkDBSanity
    2828        &addMaster
    29         &listSummary &listMaster &listRBlock &listFree
     29        &listSummary &listMaster &listRBlock &listFree &listPool
    3030        &getRoutedCity
    3131        &allocateBlock &deleteBlock &getBlockData
     
    4040                &initIPDBGlobals &connectDB &finish &checkDBSanity
    4141                &addMaster
    42                 &listSummary &listMaster &listRBlock &listFree
     42                &listSummary &listMaster &listRBlock &listFree &listPool
    4343                &getRoutedCity
    4444                &allocateBlock &deleteBlock &getBlockData
     
    443443  return \@flist;
    444444} # end listFree()
     445
     446
     447## IPDB::listPool()
     448#
     449sub listPool {
     450  my $dbh = shift;
     451  my $pool = shift;
     452
     453  my $sth = $dbh->prepare("SELECT ip,custid,available,description,type".
     454        " FROM poolips WHERE pool = ? ORDER BY ip");
     455  $sth->execute($pool);
     456  my @poolips;
     457  while (my ($ip,$custid,$available,$desc,$type) = $sth->fetchrow_array) {
     458    my %row = (
     459        ip => $ip,
     460        custid => $custid,
     461        available => $available,
     462        desc => $desc,
     463        delme => $available eq 'n'
     464        );
     465    push @poolips, \%row;
     466  }
     467  return \@poolips;
     468} # end listPool()
    445469
    446470
     
    972996  my $block = shift;
    973997
    974   my $sth = $dbh->prepare("select cidr,custid,type,city,description from searchme".
    975         " where cidr='$block'");
    976   $sth->execute();
    977   return $sth->fetchrow_array();
     998  my $binfo = $dbh->selectrow_hashref("SELECT cidr,custid,type,city,description FROM searchme".
     999        " WHERE cidr = ?", undef, ($block) );
     1000  return $binfo;
    9781001} # end getBlockData()
    9791002
  • 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);
  • trunk/templates/listpool.tmpl

    r517 r528  
    2828
    2929<TMPL_LOOP name=poolips>
    30 <tr class="row<TMPL_VAR NAME=rowclass>">
     30<tr class="row<TMPL_IF __odd__>0<TMPL_ELSE>1</TMPL_IF>">
    3131<td><a href="<TMPL_VAR NAME=webpath>/cgi-bin/main.cgi?action=edit&amp;block=<TMPL_VAR NAME=ip>"><TMPL_VAR NAME=ip></a></td>
    3232<td><TMPL_VAR NAME=custid></td>
Note: See TracChangeset for help on using the changeset viewer.