Changeset 598 for branches/stable


Ignore:
Timestamp:
05/16/13 16:43:45 (11 years ago)
Author:
Kris Deugau
Message:

/branches/stable

Introduce informational VRF tags on allocations to match uncomitted patch
in production.
Also add a minor main.cgi error-log-cleanup hack around deleting routed
blocks and master blocks instead of bending getBlockData() out of shape
only to have to put it back when the database structure changes get merged.

Location:
branches/stable
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • branches/stable/cgi-bin/IPDB.pm

    r595 r598  
    396396
    397397  # Snag the allocations for this block
    398   my $sth = $dbh->prepare("SELECT cidr,city,type,custid,swip,description".
     398  my $sth = $dbh->prepare("SELECT cidr,city,type,custid,swip,description,vrf".
    399399        " FROM allocations WHERE cidr <<= ? ORDER BY cidr");
    400400  $sth->execute($routed);
     
    405405
    406406  my @blocklist;
    407   while (my ($cidr,$city,$type,$custid,$swip,$desc) = $sth->fetchrow_array()) {
     407  while (my ($cidr,$city,$type,$custid,$swip,$desc,$vrf) = $sth->fetchrow_array()) {
     408    $desc .= " - vrf:$vrf" if $desc && $vrf;
     409    $desc = "vrf:$vrf" if !$desc && $vrf;
    408410    $custsth->execute($custid);
    409411    my ($ncust) = $custsth->fetchrow_array();
     
    462464  my $pool = shift;
    463465
    464   my $sth = $dbh->prepare("SELECT ip,custid,available,description,type".
     466  my $sth = $dbh->prepare("SELECT ip,custid,available,description,type,vrf".
    465467        " FROM poolips WHERE pool = ? ORDER BY ip");
    466468  $sth->execute($pool);
    467469  my @poolips;
    468   while (my ($ip,$custid,$available,$desc,$type) = $sth->fetchrow_array) {
     470  while (my ($ip,$custid,$available,$desc,$type,$vrf) = $sth->fetchrow_array) {
     471    $desc .= " - vrf:$vrf" if $desc && $vrf;
     472    $desc = "vrf:$vrf" if !$desc && $vrf;
    469473    my %row = (
    470474        ip => $ip,
     
    673677# Returns a success code and optional error message.
    674678sub allocateBlock {
    675   my ($dbh,undef,undef,$custid,$type,$city,$desc,$notes,$circid,$privdata,$nodeid) = @_;
     679  my ($dbh,undef,undef,$custid,$type,$city,$desc,$notes,$circid,$privdata,$nodeid,$vrf) = @_;
    676680  $privdata = '' if !defined($privdata);
     681  $vrf = '' if !defined($vrf);
    677682
    678683  my $cidr = new NetAddr::IP $_[1];
     
    720725                undef, ($alloc_from) );
    721726      }
    722       $dbh->do("UPDATE poolips SET custid=?,city=?,available='n',description=?,notes=?,circuitid=?,privdata=? ".
    723         "WHERE ip=?", undef, ($custid, $city, $desc, $notes, $circid, $privdata, $cidr) );
     727      $dbh->do("UPDATE poolips SET custid=?,city=?,available='n',description=?,".
     728        "notes=?,circuitid=?,privdata=?,vrf=? ".
     729        "WHERE ip=?", undef, ($custid, $city, $desc, $notes, $circid, $privdata, $vrf, $cidr) );
    724730
    725731# node hack
     
    771777          }
    772778          $sth = $dbh->prepare("insert into allocations".
    773                 " (cidr,custid,type,city,description,notes,maskbits,circuitid,privdata)".
    774                 " values (?,?,?,?,?,?,?,?,?)");
    775           $sth->execute("$cidr", $custid, $type, $city, $desc, $notes, $cidr->masklen, $circid, $privdata);
     779                " (cidr,custid,type,city,description,notes,maskbits,circuitid,privdata,vrf)".
     780                " values (?,?,?,?,?,?,?,?,?,?)");
     781          $sth->execute("$cidr", $custid, $type, $city, $desc, $notes, $cidr->masklen, $circid, $privdata, $vrf);
    776782
    777783          # And initialize the pool, if necessary
     
    884890          # Insert the allocations entry
    885891          $sth = $dbh->prepare("insert into allocations (cidr,custid,type,city,".
    886                 "description,notes,maskbits,circuitid,privdata)".
    887                 " values (?,?,?,?,?,?,?,?,?)");
    888           $sth->execute("$cidr", $custid, $type, $city, $desc, $notes, $cidr->masklen, $circid, $privdata);
     892                "description,notes,maskbits,circuitid,privdata,vrf)".
     893                " values (?,?,?,?,?,?,?,?,?,?)");
     894          $sth->execute("$cidr", $custid, $type, $city, $desc, $notes, $cidr->masklen, $circid, $privdata, $vrf);
    889895
    890896          # And initialize the pool, if necessary
     
    9971003  my @fieldlist;
    9981004  my @vallist;
    999   foreach ('custid', 'city', 'description', 'notes', 'circuitid', 'privdata') {
     1005  foreach ('custid', 'city', 'description', 'notes', 'circuitid', 'privdata', 'vrf') {
    10001006    if ($args{$_}) {
    10011007      push @fieldlist, $_;
     
    11001106    $msg = "Unable to delete master block $cidr";
    11011107    eval {
    1102       $sth = $dbh->prepare("delete from masterblocks where cidr='$cidr'");
    1103       $sth->execute;
    1104       $sth = $dbh->prepare("delete from freeblocks where cidr <<= '$cidr'");
    1105       $sth->execute;
     1108      $sth = $dbh->prepare("delete from masterblocks where cidr=?");
     1109      $sth->execute($cidr);
     1110      $sth = $dbh->prepare("delete from freeblocks where cidr <<= ?");
     1111      $sth->execute($cidr);
    11061112      $dbh->commit;
    11071113    };
     
    12641270## IPDB::getBlockData()
    12651271# Get CIDR or IP, custid, type, city, circuit ID, description, notes, modification time, private/restricted
    1266 # data, for a CIDR block or pool IP
     1272# data, and VRF tag, for a CIDR block or pool IP
    12671273# Also returns SWIP status flag for CIDR blocks
    12681274# Takes the block/IP to look up
     
    12861292  }
    12871293  my $binfo = $dbh->selectrow_hashref("SELECT $keycol AS block, custid, type, city, circuitid, description,".
    1288         " notes, modifystamp AS lastmod, privdata".($poolip ? '' : ', swip')." FROM $blocktable".
     1294        " notes, modifystamp AS lastmod, privdata, vrf".($poolip ? '' : ', swip')." FROM $blocktable".
    12891295        " WHERE $keycol = ?", undef, ($block) );
    12901296  return $binfo;
  • branches/stable/cgi-bin/ipdb.psql

    r592 r598  
    3333);
    3434
    35 CREATE TABLE "temp" (
    36         "ofs" integer
    37 );
    38 
    3935CREATE TABLE "freeblocks" (
    4036        "cidr" cidr DEFAULT '255.255.255.255/32' NOT NULL PRIMARY KEY,
     
    5753        "createstamp" timestamp DEFAULT now(),
    5854        "modifystamp" timestamp DEFAULT now(),
     55        "vrf" character varying(128) DEFAULT '' NOT NULL,
    5956        CHECK (((available = 'y'::bpchar) OR (available = 'n'::bpchar)))
    6057);
     
    7370        "custid" character varying(16) DEFAULT '',
    7471        swip character(1) DEFAULT 'n'
     72        "vrf" character varying(128) DEFAULT '' NOT NULL,
    7573);
    7674
    77 CREATE VIEW "searchme" as SELECT allocations.cidr, allocations.custid, allocations."type", allocations.city, allocations.description, allocations.notes, allocations.circuitid FROM allocations UNION SELECT poolips.ip, poolips.custid, poolips.type, poolips.city, poolips.description, poolips.notes, poolips.circuitid FROM poolips;
     75CREATE VIEW "searchme" as SELECT allocations.cidr, allocations.custid, allocations."type", allocations.city, allocations.description, allocations.notes, allocations.circuitid, allocations.vrf FROM allocations UNION SELECT poolips.ip, poolips.custid, poolips.type, poolips.city, poolips.description, poolips.notes, poolips.circuitid, poolips.vrf FROM poolips;
    7876
    7977CREATE TABLE "alloctypes" (
     
    154152
    155153CREATE TABLE "users" (
    156         "username" varchar(16) NOT NULL PRIMARY KEY,
    157         "password" varchar(16) DEFAULT '',
    158         "acl" varchar(16) DEFAULT 'b'
     154        "username" varchar(40) NOT NULL PRIMARY KEY,
     155        "password" varchar(60) DEFAULT '',
     156        "acl" varchar(30) DEFAULT 'b'
    159157);
    160158
    161159-- Default password is admin
    162160INSERT INTO users VALUES ('admin','luef5C4XumqIs','bacdsA');
    163 
    164 CREATE TABLE "dns" (
    165         "ip" inet NOT NULL PRIMARY KEY,
    166         "hostname" character varying(128),
    167         "auto" character(1) DEFAULT 'y'
    168 );
    169161
    170162-- Network nodes - allows finding customers affected by a broken <x> quickly
  • branches/stable/cgi-bin/main.cgi

    r596 r598  
    331331        type => $ipinfo->{type},
    332332        allocfrom => $pool,
     333        vrf => $ipinfo->{vrf},
    333334        );
    334335    } elsif ($webvar{fbtype} eq 'n') {
     
    477478  $page->param(cidr => $cidr);
    478479  $page->param(city => $q->escapeHTML($webvar{city}));
     480  $page->param(vrf => $webvar{vrf});
    479481  $page->param(custid => $webvar{custid});
    480482  $page->param(circid => $q->escapeHTML($webvar{circid}));
     
    521523  my ($code,$msg) = allocateBlock($ip_dbh, $webvar{fullcidr}, $webvar{alloc_from},
    522524        $webvar{custid}, $webvar{alloctype}, $webvar{city}, $webvar{desc}, $webvar{notes},
    523         $webvar{circid}, $webvar{privdata}, $webvar{node});
     525        $webvar{circid}, $webvar{privdata}, $webvar{node}, $webvar{vrf});
    524526
    525527  if ($code eq 'OK' || $code eq 'WARN') {
     
    695697## end node hack
    696698
     699  $page->param(vrf => $blockinfo->{vrf});
     700
    697701  my ($lastmod,undef) = split /\s+/, $blockinfo->{lastmod};
    698702  $page->param(lastmod => $lastmod);
     
    735739        type            => $webvar{alloctype},
    736740        swip            => $webvar{swip},
     741        vrf             => $webvar{vrf},
    737742        );
    738743
     
    784789  $page->param(city => $webvar{city});
    785790  $page->param(disptype => $disp_alloctypes{$webvar{alloctype}});
     791  $page->param(vrf => $webvar{vrf});
    786792  $page->param(custid => $webvar{custid});
    787793  $page->param(swip => $webvar{swip} eq 'on' ? 'Yes' : 'No');
     
    869875  # need to retrieve block data before deleting so we can notify on that
    870876  my $blockinfo = getBlockData($ip_dbh, $webvar{block});
     877# hack pthui.  This goes away with the new structure, since routed
     878# and master blocks can be retrieved with getBlockData()
     879if ($webvar{alloctype} eq 'rm') {
     880  $blockinfo = { custid => 'N/A', city => $webvar{city}, description => 'N/A' };
     881} elsif ($webvar{alloctype} eq 'mm') {
     882  $blockinfo = { custid => 'N/A', city => 'N/A', description => 'N/A' };
     883}
    871884
    872885  my ($code,$msg) = deleteBlock($ip_dbh, $webvar{block}, $webvar{alloctype});
  • branches/stable/templates/assign.tmpl

    r595 r598  
    9292</tr>
    9393
     94<tr class="<TMPL_VAR NAME=rowa>"><td>VRF instance</td><td><input name="vrf" size="40" value="<TMPL_VAR NAME=vrf>"></td></tr>
     95
    9496<TMPL_UNLESS allocfrom>
    95 <tr class="<TMPL_VAR NAME=rowa>">
     97<tr class="<TMPL_VAR NAME=rowb>">
    9698<td>Limit to blocks in this location:</td>
    9799<td>
     
    104106</tr>
    105107
    106 <tr class="<TMPL_VAR NAME=rowb>">
     108<tr class="<TMPL_VAR NAME=rowa>">
    107109<td>Limit to blocks in this master:&nbsp;</td>
    108110<td>
     
    116118</TMPL_UNLESS>
    117119
    118 <tr class="<TMPL_VAR NAME=rowa>">
     120<tr class="<TMPL_VAR NAME=rowb>">
    119121<td>Circuit ID:</td>
    120122<td><input name="circid" size="40"></td>
    121123</tr>
    122124
    123 <tr class="<TMPL_VAR NAME=rowb>">
     125<tr class="<TMPL_VAR NAME=rowa>">
    124126<td>Description/Name:</td>
    125127<td><input name="desc" size="40"></td>
    126128</tr>
    127129
    128 <tr class="<TMPL_VAR NAME=rowa>">
     130<tr class="<TMPL_VAR NAME=rowb>">
    129131<td>Notes:&nbsp;</td>
    130132<td><textarea name="notes" rows="3" cols="40"></textarea></td>
     
    132134
    133135<TMPL_IF privdata>
    134 <tr class="<TMPL_VAR NAME=rowb>">
     136<tr class="<TMPL_VAR NAME=rowa>">
    135137<td>Restricted data:</td>
    136138<td><textarea rows="3" cols="64" name="privdata" class="regular"></textarea></td>
     
    138140</TMPL_IF>
    139141
    140 <tr class="<TMPL_IF privdata><TMPL_VAR NAME=rowa><TMPL_ELSE><TMPL_VAR NAME=rowb></TMPL_IF>">
     142<tr class="<TMPL_IF privdata><TMPL_VAR NAME=rowb><TMPL_ELSE><TMPL_VAR NAME=rowb></TMPL_IF>">
    141143<td class="center" colspan="2"><input type="submit" value="  Assign  "></td>
    142144</tr>
  • branches/stable/templates/confirm.tmpl

    r593 r598  
    4242
    4343<tr class="row0">
     44<td>VRF instance:&nbsp;</td>
     45<td><TMPL_VAR NAME=vrf><input type="hidden" name="vrf" value="<TMPL_VAR NAME=vrf>"></td>
     46</tr>
     47
     48<tr class="row1">
    4449<td>Allocation type:</td>
    4550<td><TMPL_VAR NAME=typefull></td>
    4651</tr>
    4752
    48 <tr class="row1">
     53<tr class="row0">
    4954<td>Customer ID:</td>
    5055<td><TMPL_VAR NAME=custid></td>
    5156</tr>
    5257
    53 <tr class="row0">
     58<tr class="row1">
    5459<td valign="top">Circuit ID:</td>
    5560<td><TMPL_VAR NAME=circid></td>
    5661</tr>
    5762
    58 <tr class="row1">
     63<tr class="row0">
    5964<td valign="top">Description/name:</td>
    6065<td><TMPL_VAR NAME=desc></td>
    6166</tr>
    6267
    63 <tr class="row0">
     68<tr class="row1">
    6469<td valign="top">Notes:</td>
    6570<td><TMPL_VAR NAME=notes></td>
     
    6772
    6873<TMPL_IF privdata>
    69 <tr class="row1">
     74<tr class="row0">
    7075<td>Restricted data:</td>
    7176<td><TMPL_VAR NAME=privdata></td>
     
    7479
    7580<!-- warn -->
    76 <tr class="<TMPL_IF privdata>row0<TMPL_ELSE>row1</TMPL_IF>">
     81<tr class="<TMPL_IF privdata>row1<TMPL_ELSE>row0</TMPL_IF>">
    7782<td class="center" colspan="2">
    7883<TMPL_UNLESS poollist><input type="hidden" name="alloc_from" value="<TMPL_VAR NAME=alloc_from>"></TMPL_UNLESS>
  • branches/stable/templates/delete.tmpl

    r594 r598  
    6161<input type="hidden" name="block" value="<TMPL_VAR NAME=block>">
    6262<input type="hidden" name="alloctype" value="<TMPL_VAR NAME=type>">
     63<input type="hidden" name="city" value="<TMPL_VAR NAME=city>">
    6364<input type="hidden" name="action" value="finaldelete">
    6465</fieldset>
  • branches/stable/templates/edit.tmpl

    r594 r598  
    6767
    6868<tr class="row0">
     69<td class=heading>VRF instance:</td>
     70<td class="regular">
     71<TMPL_IF maychange>
     72<input type="text" name="vrf" value="<TMPL_VAR NAME=vrf>">
     73<TMPL_ELSE>
     74<TMPL_VAR NAME=vrf>
     75</TMPL_IF>
     76</td>
     77</tr>
     78
     79<tr class="row1">
    6980<td class=heading>CustID:</td>
    7081<td class="regular">
     
    7788</tr>
    7889
    79 <tr class="row1">
     90<tr class="row0">
    8091<td class=heading>SWIPed?:</td>
    8192<td class=regular>
     
    92103</tr>
    93104
    94 <tr class="row0">
     105<tr class="row1">
    95106<td class=heading>Last modified:</td>
    96107<td class=regular><TMPL_VAR NAME=lastmod></td>
    97108</tr>
    98109
    99 <tr class="row1">
     110<tr class="row0">
    100111<td class="heading">Circuit ID:</td>
    101112<td class="regular">
     
    108119</tr>
    109120
    110 <tr class="row0">
     121<tr class="row1">
    111122<td class="heading">Description/Name:</td>
    112123<td class="regular">
     
    119130</tr>
    120131
    121 <tr class="row1">
     132<tr class="row0">
    122133<td class="heading" valign="top">Notes:</td>
    123134<td class="regular">
     
    130141
    131142<TMPL_IF nocling>
    132 <tr class="row0">
     143<tr class="row1">
    133144<td class="heading" valign="top">Restricted data:</td>
    134145<td class="regular">
     
    143154
    144155<TMPL_IF maychange>
    145 <tr class="row<TMPL_IF nocling>1<TMPL_ELSE>0</TMPL_IF>">
     156<tr class="row<TMPL_IF nocling>0<TMPL_ELSE>1</TMPL_IF>">
    146157<td colspan="2" class="center">
    147158<input type="submit" value=" Update this block " class="regular">
     
    160171<form method="POST" action="main.cgi">
    161172<fieldset><legend class="noshow">&nbsp;</legend>
    162 <div class="row<TMPL_IF nocling><TMPL_IF maychange>0<TMPL_ELSE>1</TMPL_IF><TMPL_ELSE><TMPL_IF maychange>1<TMPL_ELSE>0</TMPL_IF></TMPL_IF>">
     173<div class="row<TMPL_IF nocling><TMPL_IF maychange>1<TMPL_ELSE>0</TMPL_IF><TMPL_ELSE><TMPL_IF maychange>0<TMPL_ELSE>1</TMPL_IF></TMPL_IF>">
    163174<input type="hidden" name="action" value="delete">
    164175<input type="hidden" name="block" value="<TMPL_VAR NAME=block>">
  • branches/stable/templates/update.tmpl

    r594 r598  
    3030
    3131<tr class="row0">
     32<td>VRF Instance:</td>
     33<td><TMPL_VAR NAME=vrf></td>
     34</tr>
     35
     36<tr class="row1">
    3237<td>Customer ID:</td>
    3338<td><TMPL_VAR NAME=custid></td>
    3439</tr>
    3540
    36 <tr class="row1">
     41<tr class="row0">
    3742<td>SWIPed?:</td>
    3843<td><TMPL_VAR NAME=swip></td>
    3944</tr>
    4045
    41 <tr class="row0">
     46<tr class="row1">
    4247<td>Circuit ID:</td>
    4348<td><TMPL_VAR ESCAPE=HTML NAME=circid></td>
    4449</tr>
    4550
    46 <tr class="row1">
     51<tr class="row0">
    4752<td valign="top">Description/Name:</td>
    4853<td><TMPL_VAR ESCAPE=HTML NAME=desc></td>
    4954</tr>
    5055
    51 <tr class="row0">
     56<tr class="row1">
    5257<td valign="top">Notes:</td>
    5358<td><TMPL_VAR NAME=notes></td>
     
    5560
    5661<TMPL_IF privdata>
    57 <tr class="row1">
     62<tr class="row0">
    5863<td valign="top">Restricted data:</td>
    5964<td><TMPL_VAR NAME=privdata></td>
Note: See TracChangeset for help on using the changeset viewer.