Changeset 691 for trunk/cgi-bin/IPDB.pm


Ignore:
Timestamp:
02/06/15 17:42:26 (9 years ago)
Author:
Kris Deugau
Message:

/trunk

Expose VRF field, and add a similar VLAN field (see #10).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/cgi-bin/IPDB.pm

    r690 r691  
    108108our $sublistlayout = 1;
    109109
     110# VLAN validation mode.  Set to 0 to allow alphanumeric vlan names instead of using the vlan number.
     111our $numeric_vlan = 1;
     112
     113
    110114##
    111115## Internal utility functions
     
    506510
    507511  # Snag the allocations for this block
    508   my $sth = $dbh->prepare("SELECT cidr,city,type,custid,swip,description,id,master_id".
     512  my $sth = $dbh->prepare("SELECT cidr,city,type,custid,swip,description,vrf,id,master_id".
    509513        " FROM allocations WHERE parent_id = ? ORDER BY cidr");
    510514  $sth->execute($args{parent});
     
    524528
    525529  my @blocklist;
    526   while (my ($cidr,$city,$type,$custid,$swip,$desc,$id,$mid) = $sth->fetchrow_array()) {
     530  while (my ($cidr,$city,$type,$custid,$swip,$desc,$vrf,$id,$mid) = $sth->fetchrow_array()) {
     531    $desc .= " - vrf:$vrf" if $desc && $vrf;
     532    $desc = "vrf:$vrf" if !$desc && $vrf;
    527533    $custsth->execute($custid);
    528534    my ($ncust) = $custsth->fetchrow_array();
     
    575581
    576582  # Snag the allocations for this block
    577   my $sth = $dbh->prepare("SELECT cidr,city,type,custid,swip,description,id,master_id".
     583  my $sth = $dbh->prepare("SELECT cidr,city,type,custid,swip,description,vrf,id,master_id".
    578584        " FROM allocations WHERE parent_id = ? AND type ~ '[mc]\$' ORDER BY cidr");
    579585  $sth->execute($args{parent});
     
    586592
    587593  my @blocklist;
    588   while (my ($cidr,$city,$type,$custid,$swip,$desc,$id,$mid) = $sth->fetchrow_array()) {
     594  while (my ($cidr,$city,$type,$custid,$swip,$desc,$vrf,$id,$mid) = $sth->fetchrow_array()) {
     595    $desc .= " - vrf:$vrf" if $desc && $vrf;
     596    $desc = "vrf:$vrf" if !$desc && $vrf;
    589597    $alsth->execute($cidr, $mid);
    590598    my ($alloc) = $alsth->fetchrow_array();
     
    622630
    623631  # Snag the allocations for this block
    624   my $sth = $dbh->prepare("SELECT cidr,city,type,custid,swip,description,id,master_id".
     632  my $sth = $dbh->prepare("SELECT cidr,city,type,custid,swip,description,vrf,id,master_id".
    625633        " FROM allocations WHERE parent_id = ? AND type !~ '[mc]\$' ORDER BY cidr");
    626634  $sth->execute($args{parent});
     
    631639
    632640  my @blocklist;
    633   while (my ($cidr,$city,$type,$custid,$swip,$desc,$id,$mid) = $sth->fetchrow_array()) {
     641  while (my ($cidr,$city,$type,$custid,$swip,$desc,$vrf,$id,$mid) = $sth->fetchrow_array()) {
     642    $desc .= " - vrf:$vrf" if $desc && $vrf;
     643    $desc = "vrf:$vrf" if !$desc && $vrf;
    634644    $custsth->execute($custid);
    635645    my ($ncust) = $custsth->fetchrow_array();
     
    959969  $args{privdata} = '' if !$args{privdata};
    960970  $args{vrf} = '' if !$args{vrf};
     971  $args{vlan} = '' if !$args{vlan};
    961972  $args{rdns} = '' if !$args{rdns};
    962973
     
    10081019# end node hack
    10091020
    1010       $dbh->commit;
     1021      $dbh->commit;  # Allocate IP from pool
    10111022    };
    10121023    if ($@) {
     
    10321043        # Insert the allocations entry
    10331044        $dbh->do("INSERT INTO allocations ".
    1034                 "(cidr,parent_id,master_id,vrf,custid,type,city,description,notes,circuitid,privdata,rdns)".
    1035                 " VALUES (?,?,?,?,?,?,?,?,?,?,?,?)", undef,
    1036                 ($args{cidr}, $fbparent, $fbmaster, $args{vrf}, $args{custid}, $args{type}, $args{city},
     1045                "(cidr,parent_id,master_id,vrf,vlan,custid,type,city,description,notes,circuitid,privdata,rdns)".
     1046                " VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)", undef,
     1047                ($args{cidr}, $fbparent, $fbmaster, $args{vrf}, $args{vlan}, $args{custid}, $args{type}, $args{city},
    10371048                $args{desc}, $args{notes}, $args{circid}, $args{privdata}, $args{rdns}) );
    10381049        my ($bid) = $dbh->selectrow_array("SELECT currval('allocations_id_seq')");
     
    10681079# end node hack
    10691080
    1070         $dbh->commit;
     1081        $dbh->commit;  # Simple block allocation
    10711082      }; # end of eval
    10721083      if ($@) {
     
    11141125        # Insert the allocations entry
    11151126        $dbh->do("INSERT INTO allocations ".
    1116                 "(cidr,parent_id,master_id,vrf,custid,type,city,description,notes,circuitid,privdata,rdns)".
    1117                 " VALUES (?,?,?,?,?,?,?,?,?,?,?,?)", undef,
    1118                 ($args{cidr}, $fbparent, $fbmaster, $args{vrf}, $args{custid}, $args{type}, $args{city},
     1127                "(cidr,parent_id,master_id,vrf,vlan,custid,type,city,description,notes,circuitid,privdata,rdns)".
     1128                " VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)", undef,
     1129                ($args{cidr}, $fbparent, $fbmaster, $args{vrf}, $args{vlan}, $args{custid}, $args{type}, $args{city},
    11191130                $args{desc}, $args{notes}, $args{circid}, $args{privdata}, $args{rdns}) );
    11201131        my ($bid) = $dbh->selectrow_array("SELECT currval('allocations_id_seq')");
     
    11451156# end node hack
    11461157
    1147         $dbh->commit;
     1158        $dbh->commit;  # Complex block allocation
    11481159      }; # end eval
    11491160      if ($@) {
     
    11861197  return ('FAIL',"Refusing to create oversized static IP pool") if $pool->masklen <= 20;
    11871198
     1199  # Retrieve some odds and ends for defaults on the IPs
    11881200  my ($pcustid) = $dbh->selectrow_array("SELECT def_custid FROM alloctypes WHERE type=?", undef, ($type) );
     1201  my ($vrf,$vlan) = $dbh->selectrow_array("SELECT vrf,vlan FROM allocations WHERE allocation_id = ?",
     1202        undef, ($parent) );
     1203
    11891204  $type =~ s/[pd]$/i/;
    11901205  my $sth;
     
    12501265  my @fieldlist;
    12511266  my @vallist;
    1252   foreach ('custid', 'city', 'description', 'notes', 'circuitid', 'privdata', 'rdns') {
     1267  foreach ('custid', 'city', 'description', 'notes', 'circuitid', 'privdata', 'rdns', 'vrf', 'vlan') {
    12531268    if ($args{$_}) {
    12541269      push @fieldlist, $_;
     
    17011716  if ($type eq 'i') {
    17021717    my $binfo = $dbh->selectrow_hashref("SELECT ip AS block, custid, type, city, circuitid, description,".
    1703         " notes, modifystamp AS lastmod, privdata, vrf, rdns, parent_id, master_id".
     1718        " notes, modifystamp AS lastmod, privdata, vrf, vlan, rdns, parent_id, master_id".
    17041719        " FROM poolips WHERE id = ?", undef, ($id) );
    17051720    return $binfo;
    17061721  } else {
    17071722    my $binfo = $dbh->selectrow_hashref("SELECT cidr AS block, custid, type, city, circuitid, ".
    1708         "description, notes, modifystamp AS lastmod, privdata, vrf, swip, rdns, parent_id, master_id".
     1723        "description, notes, modifystamp AS lastmod, privdata, vrf, vlan, swip, rdns, parent_id, master_id".
    17091724        " FROM allocations WHERE id = ?", undef, ($id) );
    17101725    return $binfo;
Note: See TracChangeset for help on using the changeset viewer.