Changeset 320 for trunk/cgi-bin/main.cgi


Ignore:
Timestamp:
04/04/06 18:25:28 (19 years ago)
Author:
Kris Deugau
Message:

/trunk

Merge all bugfixes, hacks, tweaks, and miscellaneous updates from
/branches/stable necessary to bring code into line. Aside from
CustID verification and notification bits, /trunk and
/branches/stable should now be identical.

File:
1 edited

Legend:

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

    r314 r320  
    103103
    104104    if ($@) {
    105       carp "Transaction aborted because $@";
     105      my $msg = $@;
     106      carp "Transaction aborted because $msg";
    106107      eval { $ip_dbh->rollback; };
    107       syslog "err", "Could not add master block '$webvar{cidr}' to database: '$@'";
    108       printError("Could not add master block $webvar{cidr} to database: $@");
     108      syslog "err", "Could not add master block '$webvar{cidr}' to database: '$msg'";
     109      printError("Could not add master block $webvar{cidr} to database: $msg");
    109110    } else {
    110111      print "<div type=heading align=center>Success!</div>\n";
     
    414415        qq($master ($data[0]):</div></center><br>\n);
    415416
    416   startTable('CIDR allocation','Customer Location','Type','CustID','Description/Name');
     417  startTable('CIDR allocation','Customer Location','Type','CustID','SWIPed?','Description/Name');
    417418
    418419  # Snag the allocations for this block
    419   $sth = $ip_dbh->prepare("select cidr,city,type,custid,description".
     420  $sth = $ip_dbh->prepare("select cidr,city,type,custid,swip,description".
    420421        " from allocations where cidr <<= '$master' order by cidr");
    421422  $sth->execute();
     
    423424  my $count=0;
    424425  while (my @data = $sth->fetchrow_array()) {
    425     # cidr,city,type,custid,description, as per the SELECT
     426    # cidr,city,type,custid,swip,description, as per the SELECT
    426427    my $cidr = new NetAddr::IP $data[0];
    427428
     
    432433    my @row = ( (($data[2] =~ /^.r$/) ? 'Sub ' : '').
    433434        qq(<a href="/ip/cgi-bin/main.cgi?action=edit&block=$data[0]">$data[0]</a>),
    434         $data[1], $disp_alloctypes{$data[2]}, $data[3], $data[4]);
     435        $data[1], $disp_alloctypes{$data[2]}, $data[3],
     436        ($data[4] eq 'y' ? 'Yes' : 'No'), $data[5]);
    435437    # If the allocation is a pool, allow listing of the IPs in the pool.
    436438    if ($data[2] =~ /^.[pd]$/) {
     
    710712      my $city;
    711713      my $failmsg;
     714      my $extracond = '';
     715      if ($webvar{allocfrom} eq '-') {
     716        $extracond = ($webvar{allowpriv} eq 'on' ? '' :
     717                " and not (cidr <<= '192.168.0.0/16'".
     718                        " or cidr <<= '10.0.0.0/8'".
     719                        " or cidr <<= '172.16.0.0/12')");
     720      }
     721      my $sortorder;
    712722      if ($webvar{alloctype} eq 'rm') {
    713723        if ($webvar{allocfrom} ne '-') {
    714724          $sql = "select * from freeblocks where maskbits<=$webvar{maskbits} and routed='n'".
    715                 " and cidr <<= '$webvar{allocfrom}' order by maskbits desc";
     725                " and cidr <<= '$webvar{allocfrom}'";
     726          $sortorder = "maskbits desc";
    716727        } else {
    717           $sql = "select * from freeblocks where maskbits<=$webvar{maskbits} and routed='n'".
    718                 " order by maskbits desc";
     728          $sql = "select * from freeblocks where maskbits<=$webvar{maskbits} and routed='n'";
     729          $sortorder = "maskbits desc";
    719730        }
    720731        $failmsg = "No suitable free block found.<br>\nWe do not have a free".
     
    745756          $sql = "select cidr from freeblocks where city='$city' and maskbits<=$webvar{maskbits}".
    746757                " and cidr <<= '$webvar{allocfrom}' and routed='".
    747                 (($webvar{alloctype} =~ /^(.)r$/) ? "$1" : 'y')."' order by maskbits desc,cidr";
     758                (($webvar{alloctype} =~ /^(.)r$/) ? "$1" : 'y')."'";
     759          $sortorder = "maskbits desc,cidr";
    748760        } else {
    749761          $sql = "select cidr from freeblocks where city='$city' and maskbits<=$webvar{maskbits}".
    750                 " and routed='".(($webvar{alloctype} =~ /^(.)r$/) ? "$1" : 'y').
    751                 "' order by maskbits desc,cidr";
     762                " and routed='".(($webvar{alloctype} =~ /^(.)r$/) ? "$1" : 'y')."'";
     763          $sortorder = "maskbits desc,cidr";
    752764        }
    753765      }
     766      $sql = $sql.$extracond." order by ".$sortorder;
    754767      $sth = $ip_dbh->prepare($sql);
    755768      $sth->execute;
     
    914927  } else {
    915928    # New!  Improved!  And now Loaded From The Database!!
    916     $webvar{custid} = $def_custids{$webvar{alloctype}};
     929    if ((!$webvar{custid}) || ($webvar{custid} ne 'STAFF')) {
     930      $webvar{custid} = $def_custids{$webvar{alloctype}};
     931    }
    917932  }
    918933
     
    929944  } else {
    930945    $flag = 'n';
    931     if ($webvar{alloctype} =~ /[wp][cr]|[ds][pi]/) {
     946    if ($webvar{alloctype} =~ /[wp][cr]|d[pi]/) {
    932947      # Set this forcibly rather than messing around elsewhere.  Yes, this *is* a hack.  PTHBTT!!
    933       $webvar{pop} = 'Sudbury';
    934     }
    935     if ($webvar{pop} =~ /^-$/) {
     948      # Match CORE/WAN types (wc, wr, pc, pr), DSL pool and IP (dp, di).
     949      $webvar{pop} = "Sudbury";
     950    } elsif ($webvar{pop} =~ /^-$/) {
    936951      $flag = 'to route the block from/through';
    937952    }
     
    957972  # because I'm lazy, we'll try to make the SELECT's bring out identical)ish) data
    958973  if ($webvar{block} =~ /\/32$/) {
    959     $sql = "select ip,custid,type,city,circuitid,description,notes,modifystamp,privdata from poolips where ip='$webvar{block}'";
     974    $sql = "select ip,custid,type,city,circuitid,description,notes,modifystamp,privdata,oldcustid from poolips where ip='$webvar{block}'";
    960975  } else {
    961     $sql = "select cidr,custid,type,city,circuitid,description,notes,modifystamp,privdata from allocations where cidr='$webvar{block}'"
     976    $sql = "select cidr,custid,type,city,circuitid,description,notes,modifystamp,privdata,oldcustid,swip from allocations where cidr='$webvar{block}'"
    962977  }
    963978
     
    10061021      $html =~ s/\$\$TYPESELECT\$\$/$disp_alloctypes{$data[2]}<input type=hidden name=alloctype value="$data[2]">/g;
    10071022    }
     1023    $html =~ s/\$\$OLDCUSTID\$\$/$data[9]/g;
    10081024    $html =~ s/\$\$CITY\$\$/<input type=text name=city value="$data[3]">/g;
    10091025    $html =~ s/\$\$CIRCID\$\$/<input type="text" name="circid" value="$data[4]" maxlength=64 size=64 class="regular">/g;
     
    10121028  } else {
    10131029    $html =~ s/\$\$CUSTID\$\$/$data[1]/g;
     1030    $html =~ s/\$\$OLDCUSTID\$\$/$data[9]/g;
    10141031    $html =~ s/\$\$TYPESELECT\$\$/$disp_alloctypes{$data[2]}/g;
    10151032    $html =~ s/\$\$CITY\$\$/$data[3]/g;
     
    10201037  my ($lastmod,undef) = split /\s+/, $data[7];
    10211038  $html =~ s/\$\$LASTMOD\$\$/$lastmod/g;
     1039
     1040## Hack time!  SWIP isn't going to stay, so I'm not going to integrate it with ACLs.
     1041if ($data[2] =~ /.i/) {
     1042  $html =~ s/\$\$SWIP\$\$/N\/A/;
     1043} else {
     1044  my $tmp = (($data[10] eq 'n') ? '<input type=checkbox name=swip>' :
     1045        '<input type=checkbox name=swip checked=yes>');
     1046  $html =~ s/\$\$SWIP\$\$/$tmp/;
     1047}
    10221048
    10231049  # Allows us to "correctly" colour backgrounds in table
     
    10911117      $sql = "update allocations set custid='$webvar{custid}',".
    10921118        "description='$webvar{desc}',notes='$webvar{notes}',city='$webvar{city}',".
    1093         "type='$webvar{alloctype}',circuitid='$webvar{circid}'$privdata ".
     1119        "type='$webvar{alloctype}',circuitid='$webvar{circid}'$privdata,".
     1120        "swip='".($webvar{swip} eq 'on' ? 'y' : 'n')."' ".
    10941121        "where cidr='$webvar{block}'";
    10951122    }
     
    11151142  my $html = join('', <HTML>);
    11161143
     1144my $swiptmp = ($webvar{swip} eq 'on' ? 'Yes' : 'No');
    11171145  $html =~ s/\$\$BLOCK\$\$/$webvar{block}/g;
    11181146  $webvar{city} = desanitize($webvar{city});
     
    11211149  $html =~ s/\$\$TYPEFULL\$\$/$disp_alloctypes{$webvar{alloctype}}/g;
    11221150  $html =~ s/\$\$CUSTID\$\$/$webvar{custid}/g;
     1151  $html =~ s/\$\$SWIP\$\$/$swiptmp/g;
    11231152  $webvar{circid} = desanitize($webvar{circid});
    11241153  $html =~ s/\$\$CIRCID\$\$/$webvar{circid}/g;
Note: See TracChangeset for help on using the changeset viewer.