Changeset 273
- Timestamp:
- 03/13/12 15:44:07 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/DNSDB.pm
r272 r273 396 396 " WHERE val = ?", undef, ($checkme)) }; 397 397 return ('WARN', "PTR record for $checkme already exists; adding another will probably not do what you want") 398 unless (grep /^$args{update}$/, @ptrs);398 if @ptrs && (!grep /^$args{update}$/, @ptrs); 399 399 } else { 400 400 # New record. Always warn if a PTR exists … … 436 436 my $pname = ($args{defrec} eq 'y' ? 'DOMAIN' : domainName($dbh,$args{id})); 437 437 ${$args{host}} =~ s/\.*$/\.$pname/ if ${$args{host}} !~ /$pname$/; 438 439 # hmm.. this might work. except possibly for something pointing to "deadbeef.ca". <g> 440 # if ($type == $reverse_typemap{NS} || $type == $reverse_typemap{MX} || $type == $reverse_typemap{SRV}) { 441 # if ($val =~ /^\s*[\da-f:.]+\s*$/) { 442 # return ('FAIL',"$val is not a valid IP address") if !$addr; 443 # } 444 # } 438 445 439 446 return ('OK','OK'); … … 563 570 my @ptrs = @{ $dbh->selectcol_arrayref("SELECT record_id FROM "._rectable($args{defrec},$args{revrec}). 564 571 " WHERE val = ?", undef, (${$args{val}})) }; 565 unless (grep /^$args{update}$/, @ptrs) {572 if (@ptrs && (!grep /^$args{update}$/, @ptrs)) { 566 573 $msg = "PTR record for ${$args{val}} already exists; adding another will probably not do what you want"; 567 574 $code = 'WARN'; … … 2360 2367 ## DNSDB::updateRec() 2361 2368 # Update a record 2369 # Takes a database handle, default and reverse flags, record ID, immediate parent ID, and new record data. 2370 # Returns a status code and message 2362 2371 sub updateRec { 2363 2372 $errstr = ''; … … 2369 2378 my $parid = shift; # immediate parent entity that we're descending from to update the record 2370 2379 2371 # all records have these2380 # all records have these 2372 2381 my $host = shift; 2373 2382 my $hostbk = $$host; # Keep a backup copy of the original, so we can WARN if the update mangles the domain … … 2386 2395 my $retmsg = ''; 2387 2396 2388 # do simple validation first2397 # do simple validation first 2389 2398 return ('FAIL', "TTL must be numeric") unless $ttl =~ /^\d+$/; 2390 2399 … … 2392 2401 # domain names technically are case-insensitive, and we use printf-like % codes for a couple 2393 2402 # of types. Other things may also be added to validate default records of several flavours. 2394 return ('FAIL', "Hostnames may not contain anything other than (0-9 a-z . _)")2403 return ('FAIL', "Hostnames may not contain anything other than (0-9 a-z - . _)") 2395 2404 if $defrec eq 'n' && $$host !~ /^[0-9a-z_%.-]+$/i; 2396 ##work 2397 2398 # only MX and SRV will use these 2405 2406 # only MX and SRV will use these 2399 2407 my $dist = 0; 2400 2408 my $weight = 0; 2401 2409 my $port = 0; 2402 2410 2403 # standard validation2404 2411 my $fields; 2405 2412 my @vallist; 2406 2413 2407 ##fixme 2408 # get old record data so we can compare the old/new domain_id and rdns_id 2409 my $oldrec = getRecLine($dbh, $defrec, $revrec, $id); 2410 use Data::Dumper; 2411 #print Dumper($oldrec); 2414 # get old record data so we have the right parent ID 2415 # and for logging (eventually) 2416 my $oldrec = getRecLine($dbh, $defrec, $revrec, $id); 2412 2417 2413 2418 # Call the validation sub for the type requested. … … 2422 2427 return ($retcode,$retmsg) if $retcode eq 'FAIL'; 2423 2428 2424 # Set up database fields and bind parameters 2425 $fields .= "host,type,val,ttl"; 2426 push @vallist, ($$host,$$rectype,$$val,$ttl); 2427 #push @vallist, 2428 #($defrec eq 'y' ? $oldrec->{group_id} : ($revrec eq 'n' ? $oldrec->{domain_id} : $oldrec->{rdns_id})); 2429 2430 my $vallen = '?'.(',?'x$#vallist); 2431 2432 #print "$fields\n"; 2433 #print join(',', @vallist)."\n"; 2434 2435 # hmm.. this might work. except possibly for something pointing to "deadbeef.ca". <g> 2436 # if ($type == $reverse_typemap{NS} || $type == $reverse_typemap{MX} || $type == $reverse_typemap{SRV}) { 2437 # if ($val =~ /^\s*[\da-f:.]+\s*$/) { 2438 # return ('FAIL',"$val is not a valid IP address") if !$addr; 2439 # } 2440 # } 2429 # Set up database fields and bind parameters. Note only the optional fields 2430 # (distance, weight, port, secondary parent ID) are added in the validation call above 2431 $fields .= "host,type,val,ttl,"._recparent($defrec,$revrec); 2432 push @vallist, ($$host,$$rectype,$$val,$ttl, 2433 ($defrec eq 'y' ? $oldrec->{group_id} : ($revrec eq 'n' ? $oldrec->{domain_id} : $oldrec->{rdns_id})) ); 2434 2435 # hack hack PTHUI 2436 # need to forcibly make sure we disassociate a record with a parent it's no longer related to. 2437 # eg, PTR records may not have a domain parent, or A/AAAA records may not have a revzone parent. 2438 # mainly needed for crossover types that got coerced down to "standard" types 2439 if ($defrec eq 'n') { 2440 if ($$rectype == $reverse_typemap{PTR}) { 2441 $fields .= ",domain_id"; 2442 push @vallist, 0; 2443 } 2444 if ($$rectype == $reverse_typemap{A} || $$rectype == $reverse_typemap{AAAA}) { 2445 $fields .= ",rdns_id"; 2446 push @vallist, 0; 2447 } 2448 } 2449 2450 # Fiddle the field list into something suitable for updates 2451 $fields =~ s/,/=?,/g; 2452 $fields .= "=?"; 2441 2453 2442 2454 local $dbh->{AutoCommit} = 0; … … 2444 2456 2445 2457 eval { 2446 $dbh->do("UPDATE ".($defrec eq 'y' ? 'default_' : '')."records ". 2447 "SET host=?,val=?,type=?,ttl=?,distance=?,weight=?,port=? ". 2448 "WHERE record_id=?", undef, ($$host, $$val, $$rectype, $ttl, $dist, $weight, $port, $id) ); 2449 #die "horribly"; 2458 $dbh->do("UPDATE "._rectable($defrec,$revrec)." SET $fields WHERE record_id=?", undef, (@vallist, $id) ); 2450 2459 $dbh->commit; 2451 2460 }; … … 2457 2466 2458 2467 return ($retcode, $retmsg); 2459 # return ('OK','OK');2460 2468 } # end updateRec() 2461 2469
Note:
See TracChangeset
for help on using the changeset viewer.