Ignore:
Timestamp:
02/09/05 17:11:19 (19 years ago)
Author:
Kris Deugau
Message:

/branches/stable

Merged /trunk r157 in. Clean merge required reversing r152,
which isn't a problem as the updated code contains the fix
along with other changes made to the same line(s) of code.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/stable/cgi-bin/main.cgi

    r158 r159  
    5757cleanInput(\%webvar);
    5858
    59 # Stuff that gets loaded from the database
    60 #my @citylist;
    61 #my @poplist;
    62 #my %allocated; # Count for allocated blocks in a master block
    63 #my %free;      # Count for free blocks (routed and unrouted) in a master block
    64 #my %bigfree;   # Tracking largest free block in a master block
    65 #my %routed;    # Number of routed blocks in a master block
    66 
    67 # Slurp up the master block list - we need this several places
    68 # While we're at it, initialize the related hashes.
    69 #$sth = $ip_dbh->prepare("select * from masterblocks order by cidr");
    70 #$sth->execute;
    71 #for (my $i=0; my @data = $sth->fetchrow_array(); $i++) {
    72 #  $masterblocks[$i] = new NetAddr::IP $data[0];
    73 #  $allocated{"$masterblocks[$i]"} = 0;
    74 #  $free{"$masterblocks[$i]"} = 0;
    75 #  $bigfree{"$masterblocks[$i]"} = 128; # Larger number means smaller block.
    76 #                                       # Set to 128 to prepare for IPv6
    77 #  $routed{"$masterblocks[$i]"} = 0;
    78 #}
    79 
    80 
    81 
    8259
    8360#main()
     
    11087# Thus the "routed" flag.
    11188
    112     $sth = $ip_dbh->prepare("insert into freeblocks values ('$webvar{cidr}',".
    113         $cidr->masklen.",'<NULL>','n')");
     89    $sth = $ip_dbh->prepare("insert into freeblocks (cidr,maskbits,city,routed)".
     90        " values ('$webvar{cidr}',".$cidr->masklen.",'<NULL>','n')");
    11491    $sth->execute;
    11592
     
    349326    # Fix up types from pools (which are single-char)
    350327    # Fixing the database would be...  painful.  :(
     328##fixme LEGACY CODE
    351329    if ($data[2] =~ /^[cdsmw]$/) {
    352330      $data[2] .= 'i';
     
    355333        $data[1], $disp_alloctypes{$data[2]}, $data[3], $data[4]);
    356334    # Allow listing of pool if desired/required.
    357     if ($data[2] =~ /^[cdsmw]p$/) {
     335    if ($data[2] =~ /^.[pd]$/) {
    358336      $row[0] .= ' &nbsp; <a href="/ip/cgi-bin/main.cgi?action=listpool'.
    359337        "&pool=$data[0]\">List IPs</a>";
     
    494472
    495473  # Fetch only the blocks relevant to this master
    496   $sth = $ip_dbh->prepare("select * from routed where cidr <<= '$master' order by cidr");
     474  $sth = $ip_dbh->prepare("select cidr,city from routed where cidr <<= '$master' order by cidr");
    497475  $sth->execute();
    498476
     
    505483    $bigfree{"$cidr"} = 128;
    506484    # Retain the routing destination
    507     $routed{"$cidr"} = $data[2];
     485    $routed{"$cidr"} = $data[1];
    508486  }
    509487
     
    597575  my $master = new NetAddr::IP $webvar{block};
    598576
    599   $sth = $ip_dbh->prepare("select * from routed where cidr='$master'");
     577  $sth = $ip_dbh->prepare("select city from routed where cidr='$master'");
    600578  $sth->execute;
    601579  my @data = $sth->fetchrow_array;
    602580
    603581  print qq(<center><div class="heading">Summarizing allocated blocks for ).
    604         qq($master ($data[2]):</div></center><br>\n);
     582        qq($master ($data[0]):</div></center><br>\n);
    605583
    606584  startTable('CIDR allocation','Customer Location','Type','CustID','Description/Name');
    607585
    608586  # Snag the allocations for this block
    609   $sth = $ip_dbh->prepare("select * from allocations where cidr <<= '$master' order by cidr");
     587  $sth = $ip_dbh->prepare("select cidr,city,type,custid,description".
     588        " from allocations where cidr <<= '$master' order by cidr");
    610589  $sth->execute();
    611590
    612591  my $count=0;
    613592  while (my @data = $sth->fetchrow_array()) {
    614     # cidr,custid,type,city,description,notes,maskbits,circuitid
     593    # cidr,city,type,custid,description, as per the SELECT
    615594    my $cidr = new NetAddr::IP $data[0];
    616595
    617596    # Clean up extra spaces that are borking things.
    618     $data[2] =~ s/\s+//g;
     597#    $data[2] =~ s/\s+//g;
    619598
    620599    my @row = ("<a href=\"/ip/cgi-bin/main.cgi?action=edit&block=$data[0]\">$data[0]</a>",
    621         $data[3], $disp_alloctypes{$data[2]}, $data[1], $data[4]);
     600        $data[1], $disp_alloctypes{$data[2]}, $data[3], $data[4]);
    622601    # If the allocation is a pool, allow listing of the IPs in the pool.
    623     if ($data[2] =~ /^[cdsmw]p$/) {
     602    if ($data[2] =~ /^.[pd]$/) {
    624603      $row[0] .= ' &nbsp; <a href="/ip/cgi-bin/main.cgi?action=listpool'.
    625604        "&pool=$data[0]\">List IPs</a>";
     
    654633  # unrouted free blocks, but it's better to let the database do the work if we can.
    655634  $count = 0;
    656   $sth = $ip_dbh->prepare("select * from freeblocks where routed='y' and cidr <<= '$master' order by cidr");
     635  $sth = $ip_dbh->prepare("select cidr from freeblocks where routed='y' and cidr <<= '$master' order by cidr");
    657636  $sth->execute();
    658637  while (my @data = $sth->fetchrow_array()) {
     
    676655  my $cidr = new NetAddr::IP $webvar{pool};
    677656
     657  my ($pooltype,$poolcity);
     658
    678659  # Snag pool info for heading
    679   $sth = $ip_dbh->prepare("select * from allocations where cidr='$cidr'");
     660  $sth = $ip_dbh->prepare("select type,city from allocations where cidr='$cidr'");
    680661  $sth->execute;
    681   my @data = $sth->fetchrow_array;
    682   my $type = $data[2];  # We'll need this later.
     662  $sth->bind_columns(\$pooltype, \$poolcity);
     663  $sth->fetch() || carp $sth->errstr;
    683664
    684665  print qq(<center><div class="heading">Listing pool IPs for $cidr<br>\n).
    685         qq(($disp_alloctypes{$type} in $data[3])</div></center><br>\n);
    686   print qq(<div class="indent"><b>Reserved IPs:</b><br>\n);
    687   print qq(<div class="indent"><table><tr class=color1><td>Network IP:</td><td>).
     666        qq(($disp_alloctypes{$pooltype} in $poolcity)</div></center><br>\n);
     667  # Only display net/gw/bcast if it's a "real" netblock and not a PPP(oE) lunacy
     668  if ($pooltype =~ /^.d$/) {
     669    print qq(<div class="indent"><b>Reserved IPs:</b><br>\n);
     670    print qq(<div class="indent"><table><tr class=color1><td>Network IP:</td><td>).
    688671        $cidr->addr."</td></tr>\n";
    689   $cidr++;
    690   print "<tr class=color2><td>Gateway:</td><td>".$cidr->addr."</td></tr>\n";
    691   $cidr--;  $cidr--;
    692   print "<tr class=color1><td>Broadcast:</td><td>".$cidr->addr."</td></tr>\n".
     672    $cidr++;
     673    print "<tr class=color2><td>Gateway:</td><td>".$cidr->addr."</td></tr>\n";
     674    $cidr--;  $cidr--;
     675    print "<tr class=color1><td>Broadcast:</td><td>".$cidr->addr."</td></tr>\n".
    693676        "<tr><td>Netmask:</td><td>".$cidr->mask."</td></tr>\n".
    694677        "</table></div></div>\n";
     678  }
    695679
    696680# probably have to add an "edit IP allocation" link here somewhere.
    697681
    698682  startTable('IP','Customer ID','Available?','Description','');
    699   $sth = $ip_dbh->prepare("select * from poolips where pool='$webvar{pool}' order by ip");
     683  $sth = $ip_dbh->prepare("select ip,custid,available,description,type".
     684        " from poolips where pool='$webvar{pool}' order by ip");
    700685  $sth->execute;
    701686  my $count = 0;
    702687  while (my @data = $sth->fetchrow_array) {
    703688    # pool,ip,custid,city,ptype,available,notes,description,circuitid
    704     # If desc is null, make it not null.  <g>
    705     if ($data[7] eq '') {
    706       $data[7] = '&nbsp;';
     689    # ip,custid,available,description,type
     690    # If desc is "null", make it not null.  <g>
     691    if ($data[3] eq '') {
     692      $data[3] = '&nbsp;';
    707693    }
    708694    # Some nice hairy Perl to decide whether to allow unassigning each IP
    709     #   -> if $data[5] (aka poolips.available) == 'n' then we print the unassign link
     695    #   -> if $data[2] (aka poolips.available) == 'n' then we print the unassign link
    710696    #      else we print a blank space
    711     my @row = ( qq(<a href="/ip/cgi-bin/main.cgi?action=edit&block=$data[1]">$data[1]</a>),
    712         $data[2],$data[5],$data[7],
    713         ( ($data[5] eq 'n') ?
    714           ("<a href=\"/ip/cgi-bin/main.cgi?action=delete&block=$data[1]&".
    715            "alloctype=$data[4]i\">Unassign this IP</a>") :
     697    my @row = ( qq(<a href="/ip/cgi-bin/main.cgi?action=edit&block=$data[0]">$data[0]</a>),
     698        $data[1],$data[2],$data[3],
     699        ( ($data[2] eq 'n') ?
     700          ("<a href=\"/ip/cgi-bin/main.cgi?action=delete&block=$data[0]&".
     701           "alloctype=$data[4]\">Unassign this IP</a>") :
    716702          ("&nbsp;") )
    717703        );
     
    803789#  + Different flavours of netblock
    804790
    805   if ($webvar{alloctype} =~ /^[cdsmw]i$/) {
     791  if ($webvar{alloctype} =~ /^.i$/) {
    806792    my ($base,undef) = split //, $webvar{alloctype};    # split into individual chars
    807793    my $sql;
     
    810796    # ... aside from #^%#$%#@#^%^^!!!! legacy data.  GRRR.
    811797    # Note that we want to retain the requested city to relate to customer info.
     798##fixme This needs thought.
     799##SELECT DISTINCT pool, Count(*) FROM poolips where available='y' GROUP BY pool;
    812800    if ($base =~ /^[ds]$/) {
    813801      $sql = "select * from poolips where available='y' and".
     
    863851##fixme
    864852# This section needs serious Pondering.
    865         if ($webvar{alloctype} =~ /^[cdsmw]p$/) {
     853        if ($webvar{alloctype} =~ /^.[pd]$/) {
    866854          if (($webvar{city} !~ /^(Sudbury|North Bay)$/) && ($webvar{alloctype} eq 'dp')) {
    867855            printError("You must chose Sudbury or North Bay for DSL pools.");
     
    879867        }
    880868        if ($webvar{allocfrom} ne '-') {
    881           $sql = "select * from freeblocks where city='$city' and maskbits<=$webvar{maskbits}".
     869          $sql = "select cidr from freeblocks where city='$city' and maskbits<=$webvar{maskbits}".
    882870                " and cidr <<= '$webvar{allocfrom}' and routed='y' order by cidr,maskbits desc";
    883871        } else {
    884           $sql = "select * from freeblocks where city='$city' and maskbits<=$webvar{maskbits}".
     872          $sql = "select cidr from freeblocks where city='$city' and maskbits<=$webvar{maskbits}".
    885873                " and routed='y' order by cidr,maskbits desc";
    886874        }
     
    908896      $cidr = $subblocks[0];
    909897    }
    910   } # if ($webvar{alloctype} =~ /^[cdsmw]i$/)
     898  } # if ($webvar{alloctype} =~ /^.i$/)
    911899
    912900  open HTML, "../confirm.html"
     
    974962        "'$webvar{alloctype}' by $authuser failed: '$msg'";
    975963    printError("Allocation of $webvar{fullcidr} as $disp_alloctypes{$webvar{alloctype}}".
    976         " failed: $msg\n");
     964        " failed:<br>\n$msg\n");
    977965  }
    978966
     
    10831071  $data[2] =~ s/\s//;
    10841072
     1073##fixme LEGACY CODE
    10851074  # Postfix "i" on pool IP types
    10861075  if ($data[2] =~ /^[cdsmw]$/) {
     
    11451134    # Relatively simple SQL transaction here.
    11461135    my $sql;
    1147     if (my $pooltype = ($webvar{alloctype} =~ /^([cdsmw])i$/) ) {
     1136    if (my $pooltype = ($webvar{alloctype} =~ /^(.)i$/) ) {
    11481137      $sql = "update poolips set custid='$webvar{custid}',notes='$webvar{notes}',".
    11491138        "circuitid='$webvar{circid}',description='$webvar{desc}' ".
     
    11541143        "type='$webvar{alloctype}',circuitid='$webvar{circid}' where cidr='$webvar{block}'";
    11551144    }
    1156 syslog "debug", $sql;
     1145    # Log the details of the change.
     1146    syslog "debug", $sql;
    11571147    $sth = $ip_dbh->prepare($sql);
    11581148    $sth->execute;
     
    12321222    $desc = "N/A";
    12331223    $notes = "N/A";
    1234   } elsif ($webvar{alloctype} =~ /^[cdsmw]i$/) { # done with alloctype=rr
     1224  } elsif ($webvar{alloctype} =~ /^.i$/) { # done with alloctype=rr
    12351225
    12361226    # Unassigning a static IP
     
    12451235    $alloctype .="i";
    12461236
    1247   } else { # done with alloctype=[cdsmw]i
     1237  } else { # done with alloctype=~ /^.i$/
    12481238
    12491239    my $sth = $ip_dbh->prepare("select cidr,custid,type,city,circuitid,description,notes from ".
     
    12701260
    12711261  # Set the warning text.
    1272   if ($alloctype =~ /^[cdsmw]p$/) {
     1262  if ($alloctype =~ /^.[pd]$/) {
    12731263    $html =~ s|<!--warn-->|<tr bgcolor="black"><td colspan="2"><div class="red">Warning: clicking confirm will remove this record entirely.<br>Any IPs allocated from this pool will also be removed!</div></td></tr>|;
    12741264  } else {
Note: See TracChangeset for help on using the changeset viewer.