Changeset 811 for trunk/cgi-bin
- Timestamp:
- 03/08/16 13:54:14 (9 years ago)
- Location:
- trunk/cgi-bin
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/cgi-bin/IPDB.pm
r808 r811 28 28 $errstr 29 29 &initIPDBGlobals &connectDB &finish &checkDBSanity 30 &add Master &touchMaster30 &addVRF &addMaster &touchMaster 31 31 &listVRF &listSummary &listSubs &listContainers &listAllocations &listForMerge &listFree &listPool 32 32 &getMasterList &getTypeList &getPoolSelect &findAllocateFrom … … 44 44 $errstr 45 45 &initIPDBGlobals &connectDB &finish &checkDBSanity 46 &add Master &touchMaster46 &addVRF &addMaster &touchMaster 47 47 &listVRF &listSummary &listSubs &listContainers &listAllocations &listForMerge &listFree &listPool 48 48 &getMasterList &getTypeList &getPoolSelect &findAllocateFrom … … 640 640 # $dbh->disconnect; 641 641 } # end checkDBSanity 642 643 644 ## IPDB::addVRF() 645 # 646 sub 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() 642 677 643 678 -
trunk/cgi-bin/main.cgi
r810 r811 126 126 $page->param(loclist => $result); 127 127 } 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 128 150 129 151 } elsif ($webvar{action} eq 'addmaster') {
Note:
See TracChangeset
for help on using the changeset viewer.