Changeset 546 for branches/stable/DNSDB.pm
- Timestamp:
- 12/11/13 15:31:44 (10 years ago)
- Location:
- branches/stable
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/stable
- Property svn:mergeinfo changed
/trunk merged: 425-429,435,439-440
- Property svn:mergeinfo changed
-
branches/stable/DNSDB.pm
r545 r546 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; … … 3325 3365 my $id = shift; 3326 3366 3327 my $sql = "SELECT record_id,host,type,val,ttl,location".($revrec eq 'n' ? ',distance,weight,port' : ''). 3367 my $sql = "SELECT record_id,host,type,val,ttl". 3368 ($defrec eq 'n' ? ',location' : ''). 3369 ($revrec eq 'n' ? ',distance,weight,port' : ''). 3328 3370 (($defrec eq 'y') ? ',group_id FROM ' : ',domain_id,rdns_id FROM '). 3329 3371 _rectable($defrec,$revrec)." WHERE record_id=?"; … … 3400 3442 $sql .= "WHERE "._recparent($args{defrec},$args{revrec})." = ?"; 3401 3443 $sql .= " AND NOT r.type=$reverse_typemap{SOA}"; 3402 $sql .= " AND host ~* ?" if $args{filter};3444 $sql .= " AND (r.host ~* ? OR r.val ~* ?)" if $args{filter}; 3403 3445 $sql .= " ORDER BY $args{sortby} $args{sortorder}"; 3404 3446 # ensure consistent ordering by sorting on record_id too … … 3407 3449 3408 3450 my @bindvars = ($args{id}); 3409 push @bindvars, $args{filter}if $args{filter};3451 push @bindvars, ($args{filter},$args{filter}) if $args{filter}; 3410 3452 3411 3453 my $ret = $dbh->selectall_arrayref($sql, { Slice => {} }, (@bindvars) ); … … 3548 3590 $logdata{entry} .= " [priority $dist] [weight $weight] [port $port]" 3549 3591 if $typemap{$$rectype} eq 'SRV'; 3550 $logdata{entry} .= "', TTL $ttl, location $location"; 3592 $logdata{entry} .= "', TTL $ttl"; 3593 $logdata{entry} .= ", location ".getLoc($dbh, $location)->{description} if $location; 3551 3594 3552 3595 # Allow transactions, and raise an exception on errors so we can catch it later. … … 3709 3752 $logdata{entry} .= " [priority $oldrec->{distance}] [weight $oldrec->{weight}] [port $oldrec->{port}]" 3710 3753 if $typemap{$oldrec->{type}} eq 'SRV'; 3711 $logdata{entry} .= "', TTL $oldrec->{ttl}, location $oldrec->{location}\nto\n"; 3754 $logdata{entry} .= "', TTL $oldrec->{ttl}"; 3755 $logdata{entry} .= ", location ".getLoc($dbh, $oldrec->{location})->{description} if $oldrec->{location}; 3756 $logdata{entry} .= "\nto\n"; 3712 3757 # More NS special 3713 3758 if ($revrec eq 'y' && $$rectype == 2) { … … 3718 3763 $logdata{entry} .= " [distance $dist]" if $typemap{$$rectype} eq 'MX'; 3719 3764 $logdata{entry} .= " [priority $dist] [weight $weight] [port $port]" if $typemap{$$rectype} eq 'SRV'; 3720 $logdata{entry} .= "', TTL $ttl, location $location"; 3765 $logdata{entry} .= "', TTL $ttl"; 3766 $logdata{entry} .= ", location ".getLoc($dbh, $location)->{description} if $location; 3721 3767 3722 3768 local $dbh->{AutoCommit} = 0; … … 3778 3824 $logdata{entry} .= " [priority $oldrec->{distance}] [weight $oldrec->{weight}] [port $oldrec->{port}]" 3779 3825 if $typemap{$oldrec->{type}} eq 'SRV'; 3780 $logdata{entry} .= "', TTL $oldrec->{ttl}\n"; 3826 $logdata{entry} .= "', TTL $oldrec->{ttl}"; 3827 $logdata{entry} .= ", location ".getLoc($dbh, $oldrec->{location})->{description} if $oldrec->{location}; 3781 3828 3782 3829 eval {
Note:
See TracChangeset
for help on using the changeset viewer.