Changeset 647


Ignore:
Timestamp:
10/17/14 17:16:41 (10 years ago)
Author:
Kris Deugau
Message:

/trunk

admin.cgi cleanup; block listing and allocation (block/IP) update

Location:
trunk
Files:
2 edited

Legend:

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

    r644 r647  
    505505  $page->param(within => $within);
    506506
    507   $sth = $ip_dbh->prepare("select cidr,custid,type,city,description from allocations where cidr <<= '$within' order by cidr");
    508   $sth->execute;
     507
     508  $sth = $ip_dbh->prepare("SELECT id,vrf,cidr,custid,type,city,description FROM allocations".
     509        " WHERE cidr <<= ? ORDER BY vrf,cidr");
     510  $sth->execute($within);
    509511  my @blocklist;
    510   while (my ($cidr,$custid,$type,$city,$desc) = $sth->fetchrow_array) {
     512  while (my ($id,$vrf,$cidr,$custid,$type,$city,$desc) = $sth->fetchrow_array) {
    511513    my %row = (
     514        id => $id,
    512515        cidr => $cidr,
    513516        custid => $custid,
     
    517520
    518521##fixme:  don't wanna retrieve the whole type list *every time around the outer loop*
    519     my $sth2 = $ip_dbh->prepare("select type,listname from alloctypes".
    520         " where listorder < 500 and not (type like '_i') order by listorder");
     522    my $sth2 = $ip_dbh->prepare("SELECT type,listname FROM alloctypes".
     523        " WHERE listorder < 999 AND NOT (type LIKE '_i') ORDER BY listorder");
    521524    $sth2->execute;
    522525    my @typelist;
     
    538541# Stuff updates into DB
    539542sub update {
     543  my $cidr = $ip_dbh->selectrow_array("SELECT cidr FROM allocations WHERE id=?", undef, ($webvar{block}) );
     544
    540545  # Relatively simple SQL transaction here.  Note that we're deliberately NOT
    541546  # updating notes/desc here as it's available through the main interface.
    542   $sth = $ip_dbh->prepare("update allocations set custid='$webvar{custid}',".
    543         "city=?,type='$webvar{alloctype}' where cidr='$webvar{block}'");
    544   $sth->execute($webvar{city});
    545 
    546   $page->param(block => $webvar{block});
    547   if ($sth->err) {
    548     $page->param(updfailed => $sth->errstr);
    549     syslog "err", "$authuser could not update block '$webvar{block}': '".$sth->errstr."'";
     547  $ip_dbh->do("UPDATE allocations SET custid=?, city=?, type=? WHERE id=?", undef,
     548        ($webvar{custid}, $webvar{city}, $webvar{alloctype}, $webvar{block}) );
     549
     550  $page->param(block => $cidr);
     551  if ($ip_dbh->err) {
     552    $page->param(updfailed => $ip_dbh->errstr);
     553    syslog "err", "$authuser could not update block '$cidr': '".$ip_dbh->errstr."'";
    550554  } else {
    551     syslog "notice", "$authuser updated $webvar{block}";
     555    syslog "notice", "$authuser updated $cidr";
    552556  }
    553557  # need to get /24 that block is part of
    554   my @bits = split /\./, $webvar{block};
     558  my @bits = split /\./, $cidr;
    555559  $bits[3] = "0/24";
    556560  showAllocs((join ".", @bits));
     
    562566# Allow changes to ALL fields
    563567sub showPool {
    564   my $pool = new NetAddr::IP $_[0];
    565 
    566   $sth = $ip_dbh->prepare("select type,listname from alloctypes where type like '_i' order by listorder");
    567   $sth->execute;
    568   my @typelist;
    569   while (my ($type,$dispname) = $sth->fetchrow_array) {
    570     my %row = (
    571         type => $type,
    572         dispname => $dispname
    573         );
    574     push @typelist, \%row;
    575   }
    576   $page->param(typelist => \@typelist);
    577 
    578   $sth = $ip_dbh->prepare("SELECT ip,custid,city,type,available,description,notes from poolips".
    579         " WHERE pool=? ORDER BY ip");
     568  my $pool = shift;
     569
     570  # arguably even presenting a list here is Wrong, because Pool IPs Should Alwasy Match The Pool Type, but...
     571  # could also set "selected" on the "correct" type
     572  my $tlist = getTypeList($ip_dbh, 'i');
     573  $page->param(typelist => $tlist);
     574
     575  $sth = $ip_dbh->prepare("SELECT id,ip,custid,city,type,available,description,notes from poolips".
     576        " WHERE parent_id=? ORDER BY ip");
    580577  $sth->execute($pool);
    581578  my @iplist;
    582   while (my ($ip,$custid,$city,$type,$avail,$desc,$notes) = $sth->fetchrow_array) {
     579  while (my ($id,$ip,$custid,$city,$type,$avail,$desc,$notes) = $sth->fetchrow_array) {
    583580    my %row = (
     581        id => $id,
    584582        ip => $ip,
    585583        custid => $custid,
  • trunk/templates/admin/showallocs.tmpl

    r517 r647  
    66<fieldset><legend class="noshow">&nbsp;</legend>
    77<input type="hidden" name="action" value="update">
    8 <td><TMPL_VAR NAME=cidr><input type="hidden" value="<TMPL_VAR NAME=cidr>" name=block></td>
     8<td><TMPL_VAR NAME=cidr><input type="hidden" value="<TMPL_VAR NAME=id>" name=block></td>
    99<td><input name="custid" value="<TMPL_VAR NAME=custid>"></td>
    1010<td>
Note: See TracChangeset for help on using the changeset viewer.