Changeset 644 for trunk


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

/trunk

admin.cgi cleanup; update SQL and related coding conventions for IP pool
section

File:
1 edited

Legend:

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

    r643 r644  
    302302} elsif ($webvar{action} eq 'showpools') {
    303303
    304   $sth = $ip_dbh->prepare("select pool, count(*) from poolips where available='y' group by pool order by pool");
    305   $sth->execute;
    306   my @poollist;
    307   while (my ($pool,$free) = $sth->fetchrow_array) {
    308     my %row = (
    309         pool => $pool,
    310         free => $free
    311         );
    312     push @poollist, \%row;
    313   }
    314   $page->param(poollist => \@poollist);
     304  my $plist = $ip_dbh->selectall_arrayref("SELECT a.id,a.cidr AS pool, count(*) AS free FROM poolips p ".
     305        "JOIN allocations a ON a.id=p.parent_id ".
     306        "WHERE available='y' GROUP BY a.cidr,a.id ORDER BY a.cidr", { Slice => {} });
     307  $page->param(poollist => $plist);
    315308
    316309} elsif ($webvar{action} eq 'tweakpool') {
     
    320313} elsif ($webvar{action} eq 'updatepool') {
    321314
    322   $sth = $ip_dbh->prepare("update poolips set custid='$webvar{custid}', ".
    323         "city=?, type='$webvar{type}', available='".
     315  my $ip = $ip_dbh->selectrow_array("SELECT ip FROM poolips WHERE id=?", undef, ($webvar{id}) );
     316  $page->param(ip => $ip);
     317  $sth = $ip_dbh->prepare("UPDATE poolips SET custid=?, city=?, type=?, available='".
    324318        (($webvar{available} eq 'y') ? 'y' : 'n').
    325319        "', notes=?, description=? ".
    326         "where ip='$webvar{ip}'");
    327   $sth->execute($webvar{city},$webvar{notes},$webvar{desc});
    328   $page->param(ip => $webvar{ip});
     320        "WHERE id=?");
     321  $sth->execute($webvar{custid}, $webvar{city}, $webvar{type}, $webvar{notes}, $webvar{desc}, $webvar{id});
    329322  if ($sth->err) {
    330323    $page->param(errmsg => $sth->errstr);
    331     syslog "err", "$authuser could not update pool IP $webvar{ip}: ".$sth->errstr;
     324    syslog "err", "$authuser could not update pool IP $ip: ".$sth->errstr;
    332325  } else {
    333     syslog "notice", "$authuser updated pool IP $webvar{ip}";
    334   }
    335   $sth = $ip_dbh->prepare("select pool from poolips where ip='$webvar{ip}'");
    336   $sth->execute;
    337   my @data = $sth->fetchrow_array;
    338   $page->param(pool => $data[0]);
     326    syslog "notice", "$authuser updated pool IP $ip";
     327  }
     328  my $poolid = $ip_dbh->selectrow_array("SELECT parent_id FROM poolips WHERE id=?", undef, ($webvar{id}) );
     329  $page->param(poolid => $poolid);
     330  my $pool = $ip_dbh->selectrow_array("SELECT cidr FROM allocations WHERE id=?", undef, ($poolid) );
     331  $page->param(pool => $pool);
    339332
    340333} elsif ($webvar{action} eq 'showusers') {
Note: See TracChangeset for help on using the changeset viewer.