Changeset 428
Legend:
- Unmodified
- Added
- Removed
-
trunk/DNSDB.pm
r425 r428 3074 3074 3075 3075 ## DNSDB::updateLoc() 3076 # Update details of a location. 3077 # Takes a database handle, location ID, group ID, short description, 3078 # long comments/notes, and comma/space-separated IP list 3079 # Returns a result code and message 3076 3080 sub updateLoc { 3077 3081 my $dbh = shift; … … 3116 3120 3117 3121 ## DNSDB::delLoc() 3118 sub delLoc {} 3122 sub delLoc { 3123 my $dbh = shift; 3124 my $loc = shift; 3125 3126 # Allow transactions, and raise an exception on errors so we can catch it later. 3127 # Use local to make sure these get "reset" properly on exiting this block 3128 local $dbh->{AutoCommit} = 0; 3129 local $dbh->{RaiseError} = 1; 3130 3131 my $oldloc = getLoc($dbh, $loc); 3132 my $olddesc = ($oldloc->{description} ? $oldloc->{description} : $loc); 3133 my $okmsg = "Deleted location ($olddesc, '".$oldloc->{iplist}."')"; 3134 3135 eval { 3136 # Check for records with this location first. Deleting a location without deleting records 3137 # tagged for that location will render them unpublished without other warning. 3138 my ($r) = $dbh->selectrow_array("SELECT record_id FROM records WHERE location=? LIMIT 1", undef, ($loc) ); 3139 die "Records still exist in location $olddesc\n" if $r; 3140 $dbh->do("DELETE FROM locations WHERE location=?", undef, ($loc) ); 3141 _log($dbh, entry => $okmsg); 3142 $dbh->commit; 3143 }; 3144 if ($@) { 3145 my $msg = $@; 3146 eval { $dbh->rollback; }; 3147 if ($config{log_failures}) { 3148 _log($dbh, (entry => "Failed to delete location ($olddesc, '$oldloc->{iplist}'): $msg")); 3149 $dbh->commit; 3150 } 3151 return ('FAIL', "Failed to delete location ($olddesc, '$oldloc->{iplist}'): $msg"); 3152 } 3153 3154 return ('OK',$okmsg); 3155 } # end delLoc() 3119 3156 3120 3157 3121 3158 ## DNSDB::getLoc() 3159 # Get details about a location/view 3160 # Takes a database handle and location ID. 3161 # Returns a reference to a hash containing the group ID, IP list, description, and comments/notes 3122 3162 sub getLoc { 3123 3163 my $dbh = shift; -
trunk/dns.cgi
r397 r428 1362 1362 # } 1363 1363 1364 if ($webvar{locact} eq 'new') {1365 # uuhhmm.... 1366 } elsif ($webvar{locact} eq 'add') {1364 $webvar{locact} = '' if !$webvar{locact}; 1365 1366 if ($webvar{locact} eq 'add') { 1367 1367 changepage(page => "loclist", errmsg => "You are not permitted to add locations/views", id => $webvar{parentid}) 1368 1368 unless ($permissions{admin} || $permissions{location_create}); … … 1430 1430 1431 1431 show_msgs(); 1432 } 1433 1434 } elsif ($webvar{page} eq 'delloc') { 1435 1436 changepage(page=> "loclist", errmsg => "You are not allowed to delete locations") 1437 unless $permissions{admin} || $permissions{location_delete}; 1438 1439 # security check - does the user have permission to access this entity? 1440 # if (!check_scope(id => $webvar{id}, type => 'loc')) { 1441 # changepage(page => "loclist", errmsg => "You are not permitted to <foo> the requested location/view"); 1442 # } 1443 1444 $page->param(locid => $webvar{locid}); 1445 my $locdata = getLoc($dbh, $webvar{locid}); 1446 $locdata->{description} = $webvar{locid} if !$locdata->{description}; 1447 # first pass = confirm y/n (sorta) 1448 if (!defined($webvar{del})) { 1449 $page->param(del_getconf => 1); 1450 $page->param(location => $locdata->{description}); 1451 } elsif ($webvar{del} eq 'ok') { 1452 my ($code,$msg) = delLoc($dbh, $webvar{locid}); 1453 if ($code eq 'OK') { 1454 # success. go back to the user list, do not pass "GO" 1455 changepage(page => "loclist", resultmsg => $msg); 1456 } else { 1457 changepage(page => "loclist", errmsg => $msg); 1458 } 1459 } else { 1460 # cancelled. whee! 1461 changepage(page => "loclist"); 1432 1462 } 1433 1463
Note:
See TracChangeset
for help on using the changeset viewer.