Changeset 782


Ignore:
Timestamp:
10/08/15 17:09:51 (9 years ago)
Author:
Kris Deugau
Message:

/trunk

Add device-backup fields to pool IP assignment. See #52.

  • allocateBlock() in IPDB.pm
  • new assignment page

Refine CSS hiding space-gobbling fields so it can be used multiple places

Location:
trunk
Files:
4 edited

Legend:

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

    r780 r782  
    14671467                undef, ($args{parent}) );
    14681468      }
    1469       $dbh->do("UPDATE poolips SET custid = ?, city = ?,available='n', description = ?, notes = ?, ".
    1470         "circuitid = ?, privdata = ?, vrf = ?, rdns = ? ".
     1469
     1470      # backup
     1471      my $backupid = 0;
     1472      if ($args{backup}) {
     1473        my $sql = "INSERT INTO backuplist (";
     1474        my @bkvals;
     1475        for my $bk (qw(brand model type port src user vpass epass)) {
     1476          if ($args{"bk$bk"}) {
     1477            $sql .= "bk$bk,";
     1478            push @bkvals, $args{"bk$bk"};
     1479          }
     1480        }
     1481        $sql .= "ip) VALUES (".('?,' x scalar(@bkvals))."?)";
     1482        $dbh->do($sql, undef, @bkvals, $args{cidr});
     1483        ($backupid) = $dbh->selectrow_array("SELECT currval('backuplist_backup_id_seq')");
     1484      }
     1485
     1486      # finally assign the IP
     1487      $dbh->do("UPDATE poolips SET custid = ?, city = ?, available='n', description = ?, notes = ?, ".
     1488        "circuitid = ?, privdata = ?, vrf = ?, rdns = ?, backup_id = ? ".
    14711489        "WHERE ip = ? AND parent_id = ?", undef,
    14721490                ($args{custid}, $args{city}, $args{desc}, $args{notes},
    1473                 $args{circid}, $args{privdata}, $args{vrf}, $args{rdns},
     1491                $args{circid}, $args{privdata}, $args{vrf}, $args{rdns}, $backupid,
    14741492                $args{cidr}, $args{parent}) );
    14751493
  • trunk/cgi-bin/main.cgi

    r780 r782  
    434434## end node hack
    435435
    436   $page->param(privdata => $IPDBacl{$authuser} =~ /s/);
     436  $page->param(nocling => $IPDBacl{$authuser} =~ /s/);
    437437
    438438} # assignBlock
     
    657657
    658658  # Check to see if user is allowed to do anything with sensitive data
    659   my $privdata = '';
    660   $page->param(privdata => $q->escapeHTML($webvar{privdata},'y'))
    661         if $IPDBacl{$authuser} =~ /s/;
     659 if ($IPDBacl{$authuser} =~ /s/) {
     660    $page->param(nocling => 1);
     661    $page->param(privdata => $q->escapeHTML($webvar{privdata},'y'));
     662
     663    $page->param(backupfields => $webvar{backupfields});
     664    $page->param(bkbrand => $webvar{bkbrand});
     665    $page->param(bkmodel => $webvar{bkmodel});
     666    $page->param(bktype  => $webvar{bktype});
     667    $page->param(bksrc   => $webvar{bksrc});
     668    $page->param(bkuser  => $webvar{bkuser});
     669    # these two could use virtually any character
     670    $page->param(bkvpass => $q->escapeHTML($webvar{bkvpass}));
     671    $page->param(bkepass => $q->escapeHTML($webvar{bkepass}));
     672    $page->param(bkport  => $webvar{bkport});
     673  }
    662674
    663675  # Yay!  This now has it's very own little home.
     
    682694  return if !validateInput();
    683695
     696##fixme: permission check
    684697  if (!defined($webvar{privdata})) {
    685698    $webvar{privdata} = '';
     
    717730        );
    718731
     732##fixme: permission check
     733  # fill in backup data, if present/allowed
     734  if ($webvar{backupfields}) {
     735    $insert_args{backup} = 1;
     736    $insert_args{bkbrand} = $webvar{bkbrand};
     737    $insert_args{bkmodel} = $webvar{bkmodel};
     738    for my $bkfield (qw(type src user vpass epass port)) {
     739      $insert_args{"bk$bkfield"} = ($webvar{"bk$bkfield"} ? $webvar{"bk$bkfield"} : '');
     740    }
     741  }
     742
    719743  my $pinfo = getBlockData($ip_dbh, $webvar{parent});
    720744
     
    874898        return;
    875899      }
     900    }
     901  }
     902
     903  # Backup fields.  Minimal sanity checks.
     904  for my $bkfield (qw(brand model)) {
     905    if ($webvar{"bk$bkfield"} && $webvar{"bk$bkfield"} !~ /^[a-zA-Z0-9\s_.-]+$/) {
     906      $page->param(err => "Invalid characters in backup $bkfield");
     907      return;
     908    }
     909  }
     910  for my $bkfield (qw(type src user)) {  # no spaces in these!
     911    if ($webvar{"bk$bkfield"} && $webvar{"bk$bkfield"} !~ /^[a-zA-Z0-9_.-]+$/) {
     912      $page->param(err => "Invalid characters in backup $bkfield");
     913      return;
     914    }
     915  }
     916  if ($webvar{bkport}) {
     917    $webvar{bkport} =~ s/^\s+//g;
     918    $webvar{bkport} =~ s/\s+$//g;
     919    if ($webvar{bkport} !~ /^\d+$/) {
     920      $page->param(err => "Backup port must be numeric");
     921      return;
    876922    }
    877923  }
  • trunk/ipdb.css

    r777 r782  
    205205}
    206206/* hide the checkbox */
    207 .collapsible li > input {
     207.nocheckbox li > input {
    208208        display: none;
    209209        margin: 0em;
  • trunk/templates/assign.tmpl

    r781 r782  
    150150</tr>
    151151
    152 <TMPL_IF privdata>
     152<TMPL_IF nocling>
    153153<tr>
    154154<td>Restricted data:</td>
    155155<td><textarea rows="8" cols="64" name="privdata" class="regular"></textarea></td>
     156</tr>
     157
     158<tr>
     159<td>Configuration backup:</td>
     160<td>
     161<ul class="collapsible notalist"><li>
     162<label for="backupfields">Device/assignment requires backup?</label>
     163<input type="checkbox" id="backupfields" name="backupfields" />
     164<ul class="notalist"><li>
     165<table><tr><td>Brand:</td><td><input name="bkbrand"></td></tr>
     166<tr><td>Model:</td><td><input name="bkmodel"></td></tr>
     167<tr><td colspan="2">Optional settings if different from standard ones for the device type above:</td></tr>
     168<tr><td>Access method:</td><td><select name="bktype">
     169<option selected="selected">telnet</option>
     170<option>SSH</option>
     171</select></td></tr>
     172<tr><td>Connect from:</td><td><input name="bksrc"></td></tr>
     173<tr><td>Username:</td><td><input name="bkuser"></td></tr>
     174<tr><td>VTY password:</td><td><input name="bkvpass"></td></tr>
     175<tr><td>Enable password:</td><td><input name="bkepass"></td></tr>
     176<tr><td>Alternate port (if required):</td><td><input name="bkport"></td></tr>
     177</table>
     178</li></ul>
     179</li></ul>
     180</td>
    156181</tr>
    157182</TMPL_IF>
Note: See TracChangeset for help on using the changeset viewer.