Changeset 691 for trunk


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

/trunk

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

Location:
trunk
Files:
8 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;
  • trunk/cgi-bin/MyIPDB.pm

    r682 r691  
    8484# $IPDB::sublistlayout = 1;
    8585
     86## VLAN validation mode
     87# Set to 0 to allow alphanumerics and _  .  - (VLAN name instead of number)
     88#$IPDB::numeric_vlan = 1;
     89
    8690## connectDB_My()
    8791# Wrapper for IPDB::connectDB
  • trunk/cgi-bin/ipdb-2.7-3.0.sql

    r670 r691  
    99
    1010ALTER TABLE allocations ADD COLUMN vrf text NOT NULL DEFAULT '';
     11ALTER TABLE allocations ADD COLUMN vlan text NOT NULL DEFAULT '';
    1112ALTER TABLE allocations ADD COLUMN rdns text NOT NULL DEFAULT '';
    1213ALTER TABLE allocations ADD COLUMN parent_id integer NOT NULL DEFAULT 0;
     
    2324
    2425ALTER TABLE poolips ADD COLUMN vrf text NOT NULL DEFAULT '';
     26ALTER TABLE poolips ADD COLUMN vlan text NOT NULL DEFAULT '';
    2527ALTER TABLE poolips ADD COLUMN rdns text NOT NULL DEFAULT '';
    2628ALTER TABLE poolips ADD COLUMN parent_id integer NOT NULL DEFAULT 0;
     
    3739CREATE VIEW "searchme" AS
    3840    SELECT allocations.cidr, allocations.custid, allocations."type", allocations.city,
    39       allocations.description, allocations.notes, allocations.circuitid, allocations.id,
    40       allocations.parent_id, 'n' AS available
     41      allocations.description, allocations.notes, allocations.circuitid, allocations.vrf,
     42      allocations.vlan, allocations.id, allocations.parent_id, 'n' AS available
    4143    FROM allocations
    4244  UNION
    4345    SELECT poolips.ip, poolips.custid, poolips.type, poolips.city,
    44       poolips.description, poolips.notes, poolips.circuitid, poolips.id,
    45       poolips.parent_id, poolips.available
     46      poolips.description, poolips.notes, poolips.circuitid, poolips.vrf,
     47      poolips.vlan, poolips.id, poolips.parent_id, poolips.available
    4648    FROM poolips;
    4749
  • trunk/cgi-bin/main.cgi

    r687 r691  
    345345    $page->param(cached => $cached);
    346346
     347    my $pinfo = getBlockData($ip_dbh, $webvar{parent});
     348    # seems reasonable that a new allocation would share a VRF with its parent
     349    $page->param(pvrf => $pinfo->{vrf});
     350
    347351    $webvar{fbtype} = '' if !$webvar{fbtype};
    348352    if ($webvar{fbtype} eq 'i') {
    349353      my $ipinfo = getBlockData($ip_dbh, $webvar{block}, 'i');
    350       my $pinfo = getBlockData($ip_dbh, $webvar{parent});
    351354      $page->param(
    352355        fbip => 1,
     
    529532  $page->param(cidr => $cidr);
    530533  $page->param(rdns => $webvar{rdns});
     534  $page->param(vrf => $webvar{vrf});
     535  $page->param(vlan => $webvar{vlan});
    531536  $page->param(city => $q->escapeHTML($webvar{city}));
    532537  $page->param(custid => $webvar{custid});
     
    583588  }
    584589
    585   my ($code,$msg) = allocateBlock($ip_dbh, cidr => $webvar{fullcidr}, fbid => $webvar{fbid},
    586         parent => $webvar{parent}, custid => $webvar{custid}, type => $webvar{alloctype}, city => $webvar{city},
    587         desc => $webvar{desc}, notes => $webvar{notes}, circid => $webvar{circid},
    588         privdata => $webvar{privdata}, nodeid => $webvar{node}, rdns => $webvar{rdns}, user => $authuser,
    589         iprev => \%iprev);
     590  # Easier to see and cosmetically fiddle the list like this
     591  my %insert_args = (
     592        cidr            => $webvar{fullcidr},
     593        fbid            => $webvar{fbid},
     594        parent          => $webvar{parent},
     595        custid          => $webvar{custid},
     596        type            => $webvar{alloctype},
     597        city            => $webvar{city},
     598        desc            => $webvar{desc},
     599        notes           => $webvar{notes},
     600        circid          => $webvar{circid},
     601        privdata        => $webvar{privdata},
     602        nodeid          => $webvar{node},
     603        rdns            => $webvar{rdns},
     604        vrf             => $webvar{vrf},
     605        vlan            => $webvar{vlan},
     606        user            => $authuser,
     607        );
     608
     609  my ($code,$msg) = allocateBlock($ip_dbh, %insert_args, iprev => \%iprev);
    590610
    591611  if ($code eq 'OK') {
     
    705725}
    706726
     727  # VRF.  Not a full validity check, just a basic sanity check.
     728  if ($webvar{vrf}) {
     729    # Trim leading and trailing whitespace first
     730    $webvar{vrf} =~ s/^\s+//;
     731    $webvar{vrf} =~ s/\s+$//;
     732    if ($webvar{vrf} !~ /^[\w\d_.-]{1,32}$/) {
     733      $page->param(err => "VRF values may only contain alphanumerics, and may not be more than 32 characters");
     734      return;
     735    }
     736  }
     737
     738  # VLAN.  Should we allow/use VLAN names, or just the numeric ID?
     739  if ($webvar{vlan}) {
     740    # Trim leading and trailing whitespace first
     741    $webvar{vlan} =~ s/^\s+//;
     742    $webvar{vlan} =~ s/\s+$//;
     743    # ...  ve make it ze configurable thingy!
     744    if ($IPDB::numeric_vlan) {
     745      if ($webvar{vlan} !~ /^\d+$/) {
     746        $page->param(err => "VLANs must be numeric");
     747        return;
     748      }
     749    } else {
     750      if ($webvar{vlan} !~ /^[\w\d_.-]+$/) {
     751        $page->param(err => "VLANs must be alphanumeric");
     752        return;
     753      }
     754    }
     755  }
     756
    707757  return 'OK';
    708758} # end validateInput
     
    716766  # snag block info from db
    717767  my $blockinfo = getBlockData($ip_dbh, $webvar{id}, $webvar{basetype});
    718   $page->param(id => $webvar{id});
     768  $page->param(id       => $webvar{id});
    719769  $page->param(basetype => $webvar{basetype});
    720770
     
    726776  ($blockinfo->{rdns},$cached) = getBlockRDNS($ip_dbh, id => $webvar{id}, type => $blockinfo->{type}, user => $authuser);
    727777  # visual flag that we're working IPDB-local, not off more authoritative data in dnsadmin
    728   $page->param(cached => $cached);
     778  $page->param(cached   => $cached);
    729779
    730780  my $cidr = new NetAddr::IP $blockinfo->{block};
     
    743793  }
    744794
    745   $page->param(block    => $blockinfo->{block});
    746   $page->param(rdns     => $blockinfo->{rdns});
    747 
    748   $page->param(custid   => $blockinfo->{custid});
    749   $page->param(city     => $blockinfo->{city});
    750   $page->param(circid   => $blockinfo->{circuitid});
    751   $page->param(desc     => $blockinfo->{description});
    752   $page->param(notes    => $blockinfo->{notes});
     795  # consider extending this to show time as well as date
     796  my ($lastmod,undef) = split /\s+/, $blockinfo->{lastmod};
     797  $page->param(lastmod  => $lastmod);
     798#  $page->param(lastmod  => $blockinfo->{lastmod});
     799
     800  $page->param(block    => $blockinfo->{block});
     801  $page->param(city     => $blockinfo->{city});
     802  $page->param(custid   => $blockinfo->{custid});
    753803
    754804##fixme The check here should be built from the database
     
    789839## end node hack
    790840
    791   my ($lastmod,undef) = split /\s+/, $blockinfo->{lastmod};
    792   $page->param(lastmod => $lastmod);
     841  $page->param(rdns     => $blockinfo->{rdns});
     842  $page->param(vrf      => $blockinfo->{vrf});
     843  $page->param(vlan     => $blockinfo->{vlan});
    793844
    794845  # not happy with the upside-down logic, but...
    795846  $page->param(swipable => $blockinfo->{type} !~ /.i/);
    796   $page->param(swip => $blockinfo->{swip} ne 'n') if $blockinfo->{swip};
     847  $page->param(swip     => $blockinfo->{swip} ne 'n') if $blockinfo->{swip};
     848
     849  $page->param(circid   => $blockinfo->{circuitid});
     850  $page->param(desc     => $blockinfo->{description});
     851  $page->param(notes    => $blockinfo->{notes});
    797852
    798853  # Check to see if we can display sensitive data
    799   $page->param(nocling => $IPDBacl{$authuser} =~ /s/);
     854  $page->param(nocling  => $IPDBacl{$authuser} =~ /s/);
    800855  $page->param(privdata => $blockinfo->{privdata});
    801856
     
    830885        swip            => $webvar{swip},
    831886        rdns            => $webvar{rdns},
     887        vrf             => $webvar{vrf},
     888        vlan            => $webvar{vlan},
    832889        user            => $authuser,
    833890        );
  • trunk/ipdb.css

    r689 r691  
    248248        text-align: left;
    249249}
     250.rjust {
     251        text-align: right;
     252        float: right;
     253}
    250254.topalign {
    251255        vertical-align: top;
  • trunk/templates/assign.tmpl

    r687 r691  
    121121
    122122<tr>
     123<td>VRF Instance:</td>
     124<td><input name="vrf" size="40" value="<TMPL_VAR NAME=pvrf>"></td>
     125</tr>
     126
     127<tr>
     128<td>VLAN:</td>
     129<td><input name="vlan" size="40" value="<TMPL_VAR NAME=pvlan>"></td>
     130</tr>
     131
     132<tr>
    123133<td>Circuit ID:</td>
    124134<td><input name="circid" size="40"></td>
  • trunk/templates/confirm.tmpl

    r687 r691  
    7272
    7373<tr>
     74<td>VRF instance:</td>
     75<td><TMPL_VAR NAME=vrf></td>
     76</tr>
     77
     78<tr>
     79<td>VLAN:</td>
     80<td><TMPL_VAR NAME=vlan></td>
     81</tr>
     82
     83<tr>
    7484<td>Allocation type:</td>
    7585<td><TMPL_VAR NAME=typefull></td>
     
    113123<input type="hidden" name="city" value="<TMPL_VAR NAME=city>">
    114124<input type="hidden" name="node" value="<TMPL_VAR NAME=nodeid>">
     125<input type="hidden" name="vrf" value="<TMPL_VAR NAME=vrf>">
     126<input type="hidden" name="vlan" value="<TMPL_VAR NAME=vlan>">
    115127<input type="hidden" name="alloctype" value="<TMPL_VAR NAME=alloc_type>">
    116128<input type="hidden" name="custid" value="<TMPL_VAR NAME=custid>">
  • trunk/templates/edit.tmpl

    r687 r691  
    9595<TMPL_ELSE>
    9696<TMPL_IF nodename><TMPL_VAR NAME=nodename><TMPL_ELSE>N/A</TMPL_IF>
     97</TMPL_IF>
     98</td>
     99</tr>
     100
     101<tr>
     102<td class="heading">VRF instance:</td>
     103<td class="regular">
     104<TMPL_IF maychange>
     105<input type="text" name="vrf" value="<TMPL_VAR NAME=vrf>">
     106<TMPL_ELSE>
     107<TMPL_VAR NAME=vrf>
     108</TMPL_IF>
     109</td>
     110</tr>
     111
     112<tr>
     113<td class="heading">VLAN:</td>
     114<td class="regular">
     115<TMPL_IF maychange>
     116<input type="text" name="vlan" value="<TMPL_VAR NAME=vlan>">
     117<TMPL_ELSE>
     118<TMPL_VAR NAME=vlan>
    97119</TMPL_IF>
    98120</td>
Note: See TracChangeset for help on using the changeset viewer.