Changeset 154 for branches/sql-cleanup/cgi-bin
- Timestamp:
- 02/04/05 17:29:30 (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/sql-cleanup/cgi-bin/main.cgi
r149 r154 56 56 cleanInput(\%webvar); 57 57 58 # Stuff that gets loaded from the database59 #my @citylist;60 #my @poplist;61 #my %allocated; # Count for allocated blocks in a master block62 #my %free; # Count for free blocks (routed and unrouted) in a master block63 #my %bigfree; # Tracking largest free block in a master block64 #my %routed; # Number of routed blocks in a master block65 66 # Slurp up the master block list - we need this several places67 # While we're at it, initialize the related hashes.68 #$sth = $ip_dbh->prepare("select * from masterblocks order by cidr");69 #$sth->execute;70 #for (my $i=0; my @data = $sth->fetchrow_array(); $i++) {71 # $masterblocks[$i] = new NetAddr::IP $data[0];72 # $allocated{"$masterblocks[$i]"} = 0;73 # $free{"$masterblocks[$i]"} = 0;74 # $bigfree{"$masterblocks[$i]"} = 128; # Larger number means smaller block.75 # # Set to 128 to prepare for IPv676 # $routed{"$masterblocks[$i]"} = 0;77 #}78 79 80 81 58 82 59 #main() … … 109 86 # Thus the "routed" flag. 110 87 111 $sth = $ip_dbh->prepare("insert into freeblocks values ('$webvar{cidr}',".112 $cidr->masklen.",'<NULL>','n')");88 $sth = $ip_dbh->prepare("insert into freeblocks (cidr,maskbits,city,routed)". 89 " values ('$webvar{cidr}',".$cidr->masklen.",'<NULL>','n')"); 113 90 $sth->execute; 114 91 … … 493 470 494 471 # Fetch only the blocks relevant to this master 495 $sth = $ip_dbh->prepare("select *from routed where cidr <<= '$master' order by cidr");472 $sth = $ip_dbh->prepare("select cidr,city from routed where cidr <<= '$master' order by cidr"); 496 473 $sth->execute(); 497 474 … … 504 481 $bigfree{"$cidr"} = 128; 505 482 # Retain the routing destination 506 $routed{"$cidr"} = $data[ 2];483 $routed{"$cidr"} = $data[1]; 507 484 } 508 485 … … 596 573 my $master = new NetAddr::IP $webvar{block}; 597 574 598 $sth = $ip_dbh->prepare("select *from routed where cidr='$master'");575 $sth = $ip_dbh->prepare("select city from routed where cidr='$master'"); 599 576 $sth->execute; 600 577 my @data = $sth->fetchrow_array; 601 578 602 579 print qq(<center><div class="heading">Summarizing allocated blocks for ). 603 qq($master ($data[ 2]):</div></center><br>\n);580 qq($master ($data[0]):</div></center><br>\n); 604 581 605 582 startTable('CIDR allocation','Customer Location','Type','CustID','Description/Name'); 606 583 607 584 # Snag the allocations for this block 608 $sth = $ip_dbh->prepare("select * from allocations where cidr <<= '$master' order by cidr"); 585 $sth = $ip_dbh->prepare("select cidr,city,type,custid,description". 586 " from allocations where cidr <<= '$master' order by cidr"); 609 587 $sth->execute(); 610 588 611 589 my $count=0; 612 590 while (my @data = $sth->fetchrow_array()) { 613 # cidr,c ustid,type,city,description,notes,maskbits,circuitid591 # cidr,city,type,custid,description, as per the SELECT 614 592 my $cidr = new NetAddr::IP $data[0]; 615 593 616 594 # Clean up extra spaces that are borking things. 617 $data[2] =~ s/\s+//g;595 # $data[2] =~ s/\s+//g; 618 596 619 597 my @row = ("<a href=\"/ip/cgi-bin/main.cgi?action=edit&block=$data[0]\">$data[0]</a>", 620 $data[ 3], $disp_alloctypes{$data[2]}, $data[1], $data[4]);598 $data[1], $disp_alloctypes{$data[2]}, $data[3], $data[4]); 621 599 # If the allocation is a pool, allow listing of the IPs in the pool. 622 600 if ($data[2] =~ /^.[pd]$/) { … … 653 631 # unrouted free blocks, but it's better to let the database do the work if we can. 654 632 $count = 0; 655 $sth = $ip_dbh->prepare("select *from freeblocks where routed='y' and cidr <<= '$master' order by cidr");633 $sth = $ip_dbh->prepare("select cidr from freeblocks where routed='y' and cidr <<= '$master' order by cidr"); 656 634 $sth->execute(); 657 635 while (my @data = $sth->fetchrow_array()) { … … 701 679 702 680 startTable('IP','Customer ID','Available?','Description',''); 703 $sth = $ip_dbh->prepare("select * from poolips where pool='$webvar{pool}' order by ip"); 681 $sth = $ip_dbh->prepare("select ip,custid,available,description,type". 682 " from poolips where pool='$webvar{pool}' order by ip"); 704 683 $sth->execute; 705 684 my $count = 0; 706 685 while (my @data = $sth->fetchrow_array) { 707 686 # pool,ip,custid,city,ptype,available,notes,description,circuitid 708 # If desc is null, make it not null. <g> 709 if ($data[7] eq '') { 710 $data[7] = ' '; 687 # ip,custid,available,description,type 688 # If desc is "null", make it not null. <g> 689 if ($data[3] eq '') { 690 $data[3] = ' '; 711 691 } 712 692 # Some nice hairy Perl to decide whether to allow unassigning each IP 713 # -> if $data[ 5] (aka poolips.available) == 'n' then we print the unassign link693 # -> if $data[2] (aka poolips.available) == 'n' then we print the unassign link 714 694 # else we print a blank space 715 my @row = ( qq(<a href="/ip/cgi-bin/main.cgi?action=edit&block=$data[ 1]">$data[1]</a>),716 $data[ 2],$data[5],$data[7],717 ( ($data[ 5] eq 'n') ?718 ("<a href=\"/ip/cgi-bin/main.cgi?action=delete&block=$data[ 1]&".719 "alloctype=$data[4] i\">Unassign this IP</a>") :695 my @row = ( qq(<a href="/ip/cgi-bin/main.cgi?action=edit&block=$data[0]">$data[0]</a>), 696 $data[1],$data[2],$data[3], 697 ( ($data[2] eq 'n') ? 698 ("<a href=\"/ip/cgi-bin/main.cgi?action=delete&block=$data[0]&". 699 "alloctype=$data[4]\">Unassign this IP</a>") : 720 700 (" ") ) 721 701 ); … … 814 794 # ... aside from #^%#$%#@#^%^^!!!! legacy data. GRRR. 815 795 # Note that we want to retain the requested city to relate to customer info. 796 ##fixme This needs thought. 797 ##SELECT DISTINCT pool, Count(*) FROM poolips where available='y' GROUP BY pool; 816 798 if ($base =~ /^[ds]$/) { 817 799 $sql = "select * from poolips where available='y' and". … … 883 865 } 884 866 if ($webvar{allocfrom} ne '-') { 885 $sql = "select *from freeblocks where city='$city' and maskbits<=$webvar{maskbits}".867 $sql = "select cidr from freeblocks where city='$city' and maskbits<=$webvar{maskbits}". 886 868 " and cidr <<= '$webvar{allocfrom}' and routed='y' order by cidr,maskbits desc"; 887 869 } else { 888 $sql = "select *from freeblocks where city='$city' and maskbits<=$webvar{maskbits}".870 $sql = "select cidr from freeblocks where city='$city' and maskbits<=$webvar{maskbits}". 889 871 " and routed='y' order by cidr,maskbits desc"; 890 872 } … … 1143 1125 "type='$webvar{alloctype}',circuitid='$webvar{circid}' where cidr='$webvar{block}'"; 1144 1126 } 1145 syslog "debug", $sql; 1127 # Log the details of the change. 1128 syslog "debug", $sql; 1146 1129 $sth = $ip_dbh->prepare($sql); 1147 1130 $sth->execute;
Note:
See TracChangeset
for help on using the changeset viewer.