- Timestamp:
- 10/17/14 17:16:41 (10 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/cgi-bin/admin.cgi
r644 r647 505 505 $page->param(within => $within); 506 506 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); 509 511 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) { 511 513 my %row = ( 514 id => $id, 512 515 cidr => $cidr, 513 516 custid => $custid, … … 517 520 518 521 ##fixme: don't wanna retrieve the whole type list *every time around the outer loop* 519 my $sth2 = $ip_dbh->prepare(" select type,listname fromalloctypes".520 " where listorder < 500 and not (type like '_i') order bylistorder");522 my $sth2 = $ip_dbh->prepare("SELECT type,listname FROM alloctypes". 523 " WHERE listorder < 999 AND NOT (type LIKE '_i') ORDER BY listorder"); 521 524 $sth2->execute; 522 525 my @typelist; … … 538 541 # Stuff updates into DB 539 542 sub update { 543 my $cidr = $ip_dbh->selectrow_array("SELECT cidr FROM allocations WHERE id=?", undef, ($webvar{block}) ); 544 540 545 # Relatively simple SQL transaction here. Note that we're deliberately NOT 541 546 # 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."'"; 550 554 } else { 551 syslog "notice", "$authuser updated $ webvar{block}";555 syslog "notice", "$authuser updated $cidr"; 552 556 } 553 557 # need to get /24 that block is part of 554 my @bits = split /\./, $ webvar{block};558 my @bits = split /\./, $cidr; 555 559 $bits[3] = "0/24"; 556 560 showAllocs((join ".", @bits)); … … 562 566 # Allow changes to ALL fields 563 567 sub 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"); 580 577 $sth->execute($pool); 581 578 my @iplist; 582 while (my ($i p,$custid,$city,$type,$avail,$desc,$notes) = $sth->fetchrow_array) {579 while (my ($id,$ip,$custid,$city,$type,$avail,$desc,$notes) = $sth->fetchrow_array) { 583 580 my %row = ( 581 id => $id, 584 582 ip => $ip, 585 583 custid => $custid, -
trunk/templates/admin/showallocs.tmpl
r517 r647 6 6 <fieldset><legend class="noshow"> </legend> 7 7 <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> 9 9 <td><input name="custid" value="<TMPL_VAR NAME=custid>"></td> 10 10 <td>
Note:
See TracChangeset
for help on using the changeset viewer.