Changeset 811 for trunk/cgi-bin


Ignore:
Timestamp:
03/08/16 13:54:14 (9 years ago)
Author:
Kris Deugau
Message:

/trunk

"add VRF" action etc. See #54.

Location:
trunk/cgi-bin
Files:
2 edited

Legend:

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

    r808 r811  
    2828        $errstr
    2929        &initIPDBGlobals &connectDB &finish &checkDBSanity
    30         &addMaster &touchMaster
     30        &addVRF &addMaster &touchMaster
    3131        &listVRF &listSummary &listSubs &listContainers &listAllocations &listForMerge &listFree &listPool
    3232        &getMasterList &getTypeList &getPoolSelect &findAllocateFrom
     
    4444                $errstr
    4545                &initIPDBGlobals &connectDB &finish &checkDBSanity
    46                 &addMaster &touchMaster
     46                &addVRF &addMaster &touchMaster
    4747                &listVRF &listSummary &listSubs &listContainers &listAllocations &listForMerge &listFree &listPool
    4848                &getMasterList &getTypeList &getPoolSelect &findAllocateFrom
     
    640640#  $dbh->disconnect;
    641641} # end checkDBSanity
     642
     643
     644## IPDB::addVRF()
     645#
     646sub addVRF {
     647  my $dbh = shift;
     648  my $newvrf = shift;
     649  my %args = @_;
     650
     651  $args{comment} = '' if !$args{comment};
     652  $args{location} = '' if !$args{location};
     653
     654  # Allow transactions, and raise an exception on errors so we can catch it later.
     655  # Use local to make sure these get "reset" properly on exiting this block
     656  local $dbh->{AutoCommit} = 0;
     657  local $dbh->{RaiseError} = 1;
     658
     659  eval {
     660    # Check if the VRF exists.  Arguably should check for "looks similar", but that gets ugly fast.
     661    my $vrfex = $dbh->selectrow_array("SELECT vrf FROM vrfs WHERE vrf=?", undef, $newvrf);
     662    die "VRF already exists!\n" if $vrfex;
     663
     664    # Nothing there yet, so we can insert the new VRF
     665    $dbh->do("INSERT INTO vrfs (vrf,comment,location) VALUES (?,?,?)", undef,
     666        $newvrf, $args{comment}, $args{location});
     667
     668    $dbh->commit;
     669  };
     670  if ($@) {
     671    my $msg = $@;
     672    eval { $dbh->rollback; };
     673    return ('FAIL',$msg);
     674  }
     675  return ('OK',$newvrf);
     676} # end addVRF()
    642677
    643678
  • trunk/cgi-bin/main.cgi

    r810 r811  
    126126    $page->param(loclist => $result);
    127127  }
     128
     129} elsif ($webvar{action} eq 'newvrf') {
     130  if ($IPDBacl{$authuser} !~ /s/) {
     131    $aclerr = 'addvrf';
     132  } else {
     133    my ($code,$msg) = addVRF($ip_dbh, $webvar{vrf}, comment => $webvar{comment}, location => $webvar{loc});
     134
     135    if ($code eq 'FAIL') {
     136      syslog "err", "Could not add VRF '$webvar{vrf}' to database: '$msg'";
     137      $page->param(err => $msg);
     138      $page->param(vrf => $webvar{vrf});
     139    } else {
     140      $page->param(vrf => $msg);
     141      if ($code eq 'WARN') {
     142        $IPDB::errstr =~ s/\n\n/<br>\n/g;
     143        $IPDB::errstr =~ s/:\n/:<br>\n/g;
     144        $page->param(warn => $IPDB::errstr);
     145      }
     146      syslog "info", "$authuser added VRF $webvar{vrf}";
     147    }
     148
     149  } # ACL check
    128150
    129151} elsif ($webvar{action} eq 'addmaster') {
Note: See TracChangeset for help on using the changeset viewer.