Changeset 481
Legend:
- Unmodified
- Added
- Removed
-
trunk/DNSDB.pm
r480 r481 3350 3350 sub getSOA { 3351 3351 $errstr = ''; 3352 my $dbh = shift; 3352 my $self = shift; 3353 my $dbh = $self->{dbh}; 3353 3354 my $def = shift; 3354 3355 my $rev = shift; … … 3442 3443 sub getRecLine { 3443 3444 $errstr = ''; 3444 my $dbh = shift; 3445 my $self = shift; 3446 my $dbh = $self->{dbh}; 3445 3447 my $defrec = shift; 3446 3448 my $revrec = shift; … … 3486 3488 sub getDomRecs { 3487 3489 $errstr = ''; 3488 my $dbh = shift; 3490 my $self = shift; 3491 my $dbh = $self->{dbh}; 3489 3492 3490 3493 my %args = @_; … … 3541 3544 # Returns the count 3542 3545 sub getRecCount { 3543 my $dbh = shift; 3546 my $self = shift; 3547 my $dbh = $self->{dbh}; 3544 3548 my $defrec = shift; 3545 3549 my $revrec = shift; … … 3575 3579 sub addRec { 3576 3580 $errstr = ''; 3577 my $dbh = shift; 3581 my $self = shift; 3582 my $dbh = $self->{dbh}; 3578 3583 my $defrec = shift; 3579 3584 my $revrec = shift; … … 3626 3631 3627 3632 # Call the validation sub for the type requested. 3628 ($retcode,$retmsg) = $validators{$$rectype}($ dbh, (defrec => $defrec, revrec => $revrec, id => $id,3633 ($retcode,$retmsg) = $validators{$$rectype}($self, defrec => $defrec, revrec => $revrec, id => $id, 3629 3634 host => $host, rectype => $rectype, val => $val, addr => $addr, 3630 3635 dist => \$dist, port => \$port, weight => \$weight, 3631 fields => \$fields, vallist => \@vallist) );3636 fields => \$fields, vallist => \@vallist); 3632 3637 3633 3638 return ($retcode,$retmsg) if $retcode eq 'FAIL'; 3634 3639 3635 3640 # Set up database fields and bind parameters 3636 $fields .= "host,type,val,ttl,location,"._recparent($defrec,$revrec); 3637 push @vallist, ($$host,$$rectype,$$val,$ttl,$location,$id); 3641 $fields .= "host,type,val,ttl,"._recparent($defrec,$revrec); 3642 push @vallist, ($$host,$$rectype,$$val,$ttl,$id); 3643 3644 # locations are not for default records, silly coder! 3645 if ($defrec eq 'n') { 3646 $fields .= ",location"; 3647 push @vallist, $location; 3648 } 3638 3649 my $vallen = '?'.(',?'x$#vallist); 3639 3650 … … 3700 3711 $errstr = ''; 3701 3712 3702 my $dbh = shift; 3713 my $self = shift; 3714 my $dbh = $self->{dbh}; 3703 3715 my $defrec = shift; 3704 3716 my $revrec = shift; … … 3754 3766 # get old record data so we have the right parent ID 3755 3767 # and for logging (eventually) 3756 my $oldrec = getRecLine($dbh,$defrec, $revrec, $id);3768 my $oldrec = $self->getRecLine($defrec, $revrec, $id); 3757 3769 3758 3770 # Call the validation sub for the type requested. 3759 3771 # Note the ID to pass here is the *parent*, not the record 3760 ($retcode,$retmsg) = $validators{$$rectype}($ dbh, (defrec => $defrec, revrec => $revrec,3772 ($retcode,$retmsg) = $validators{$$rectype}($self, defrec => $defrec, revrec => $revrec, 3761 3773 id => ($defrec eq 'y' ? $oldrec->{group_id} : ($revrec eq 'n' ? $oldrec->{domain_id} : $oldrec->{rdns_id})), 3762 3774 host => $host, rectype => $rectype, val => $val, addr => $addr, 3763 3775 dist => \$dist, port => \$port, weight => \$weight, 3764 3776 fields => \$fields, vallist => \@vallist, 3765 update => $id) );3777 update => $id); 3766 3778 3767 3779 return ($retcode,$retmsg) if $retcode eq 'FAIL'; … … 3877 3889 # Takes the record ID and the new type. Returns boolean. 3878 3890 sub downconvert { 3879 my $dbh = shift; 3891 my $self = shift; 3892 my $dbh = $self->{dbh}; 3880 3893 my $recid = shift; 3881 3894 my $newtype = shift; 3882 3895 3883 3896 # also, only work on live records; little to no value trying to do this on default records. 3884 my $rec = getRecLine($dbh,'n', 'y', $recid);3897 my $rec = $self->getRecLine('n', 'y', $recid); 3885 3898 3886 3899 # hm? … … 3930 3943 sub delRec { 3931 3944 $errstr = ''; 3932 my $dbh = shift; 3945 my $self = shift; 3946 my $dbh = $self->{dbh}; 3933 3947 my $defrec = shift; 3934 3948 my $revrec = shift; 3935 3949 my $id = shift; 3936 3950 3937 my $oldrec = getRecLine($dbh,$defrec, $revrec, $id);3951 my $oldrec = $self->getRecLine($defrec, $revrec, $id); 3938 3952 3939 3953 # Allow transactions, and raise an exception on errors so we can catch it later. -
trunk/dns-rpc.cgi
r480 r481 313 313 _commoncheck(\%args); 314 314 315 my $ret = DNSDB::getSOA($dbh,$args{defrec}, $args{revrec}, $args{id});315 my $ret = $dnsdb->getSOA($args{defrec}, $args{revrec}, $args{id}); 316 316 if (!$ret) { 317 317 if ($args{defrec} eq 'y') { … … 331 331 _commoncheck(\%args); 332 332 333 my $ret = DNSDB::getRecLine($dbh,$args{defrec}, $args{revrec}, $args{id});334 335 die $ DNSDB::errstr if !$ret;333 my $ret = $dnsdb->getRecLine($args{defrec}, $args{revrec}, $args{id}); 334 335 die $dnsdb->errstr if !$ret; 336 336 337 337 return $ret; … … 350 350 $args{direction} = 'ASC' if !$args{direction}; 351 351 352 my $ret = DNSDB::getDomRecs($dbh,(defrec => $args{defrec}, revrec => $args{revrec}, id => $args{id},352 my $ret = $dnsdb->getDomRecs(defrec => $args{defrec}, revrec => $args{revrec}, id => $args{id}, 353 353 offset => $args{offset}, sortby => $args{sortby}, sortorder => $args{sortorder}, 354 filter => $args{filter}) );355 356 die $ DNSDB::errstr if !$ret;354 filter => $args{filter}); 355 356 die $dnsdb->errstr if !$ret; 357 357 358 358 return $ret; … … 371 371 $args{direction} = 'ASC' if !$args{direction}; 372 372 373 my $ret = DNSDB::getRecCount($dbh,$args{defrec}, $args{revrec}, $args{id}, $args{filter});374 375 die $ DNSDB::errstr if !$ret;373 my $ret = $dnsdb->getRecCount($args{defrec}, $args{revrec}, $args{id}, $args{filter}); 374 375 die $dnsdb->errstr if !$ret; 376 376 377 377 return $ret; … … 386 386 _ttlcheck(\%args); 387 387 388 my @recargs = ($ dbh, $args{defrec}, $args{revrec}, $args{parent_id},388 my @recargs = ($args{defrec}, $args{revrec}, $args{parent_id}, 389 389 \$args{name}, \$args{type}, \$args{address}, $args{ttl}, $args{location}); 390 390 if ($args{type} == $DNSDB::reverse_typemap{MX} or $args{type} == $DNSDB::reverse_typemap{SRV}) { … … 396 396 } 397 397 398 my ($code, $msg) = DNSDB::addRec(@recargs);398 my ($code, $msg) = $dnsdb->addRec(@recargs); 399 399 400 400 die $msg if $code eq 'FAIL'; … … 409 409 # get old line, so we can update only the bits that the caller passed to change 410 410 # note we subbed address for val since it's a little more caller-friendly 411 my $oldrec = DNSDB::getRecLine($dbh,$args{defrec}, $args{revrec}, $args{id});411 my $oldrec = $dnsdb->getRecLine($args{defrec}, $args{revrec}, $args{id}); 412 412 foreach my $field (qw(name type address ttl location distance weight port)) { 413 413 $args{$field} = $oldrec->{$field} if !$args{$field} && defined($oldrec->{$field}); … … 416 416 # note dist, weight, port are not required on all types; will be ignored if not needed. 417 417 # parent_id is the "primary" zone we're updating; necessary for forward/reverse voodoo 418 my ($code, $msg) = DNSDB::updateRec($dbh,$args{defrec}, $args{revrec}, $args{id}, $args{parent_id},418 my ($code, $msg) = $dnsdb->updateRec($args{defrec}, $args{revrec}, $args{id}, $args{parent_id}, 419 419 \$args{name}, \$args{type}, \$args{address}, $args{ttl}, $args{location}, 420 420 $args{distance}, $args{weight}, $args{port}); … … 440 440 # We need to strip the CIDR mask on IPv4 /32 assignments, or we just add a new record all the time. 441 441 my $filt = ($cidr->{isv6} || $cidr->masklen != 32 ? "$cidr" : $cidr->addr); 442 my $reclist = DNSDB::getDomRecs($dbh,defrec => 'n', revrec => 'y',442 my $reclist = $dnsdb->getDomRecs(defrec => 'n', revrec => 'y', 443 443 id => $zonelist->[0]->{rdns_id}, filter => $filt); 444 444 if (scalar(@$reclist) == 0) { … … 454 454 || $rec->{type} == 65282 || $rec->{type} == 65283 || $rec->{type} == 65284; 455 455 next unless $rec->{val} eq $filt; # make sure we really update the record we want to update. 456 updateRec(defrec =>'n', revrec => 'y', id => $rec->{record_id},456 $dnsdb->updateRec(defrec =>'n', revrec => 'y', id => $rec->{record_id}, 457 457 parent_id => $zonelist->[0]->{rdns_id}, %args); 458 458 $flag = 1; … … 463 463 # Aren't Magic Numbers Fun? See pseudotype list in dnsadmin. 464 464 my $type = ($cidr->{isv6} ? 65282 : ($cidr->masklen == 32 ? 65280 : 65283) ); 465 addRec(defrec =>'n', revrec => 'y', parent_id => $zonelist->[0]->{rdns_id}, type => $type,465 $dnsdb->addRec(defrec =>'n', revrec => 'y', parent_id => $zonelist->[0]->{rdns_id}, type => $type, 466 466 address => "$cidr", %args); 467 467 } … … 474 474 # that spans multiple reverse zones (eg, /23 CIDR -> 2 /24 rzones) 475 475 foreach my $zdata (@$zonelist) { 476 my $reclist = DNSDB::getDomRecs($dbh,defrec => 'n', revrec => 'y',476 my $reclist = $dnsdb->getDomRecs(defrec => 'n', revrec => 'y', 477 477 id => $zdata->{rdns_id}, filter => $zdata->{revnet}); 478 478 if (scalar(@$reclist) == 0) { 479 479 my $type = ($args{cidr}->{isv6} ? 65282 : ($args{cidr}->masklen == 32 ? 65280 : 65283) ); 480 addRec(defrec =>'n', revrec => 'y', parent_id => $zdata->{rdns_id}, type => $type,480 $dnsdb->addRec(defrec =>'n', revrec => 'y', parent_id => $zdata->{rdns_id}, type => $type, 481 481 address => "$args{cidr}", %args); 482 482 } else { … … 485 485 # types are nominally impossible here. 486 486 next unless $rec->{type} == 65282 || $rec->{type} == 65283 || $rec->{type} == 65284; 487 updateRec(defrec =>'n', revrec => 'y', id => $rec->{record_id},487 $dnsdb->updateRec(defrec =>'n', revrec => 'y', id => $rec->{record_id}, 488 488 parent_id => $zdata->{rdns_id}, %args); 489 489 last; # only do one record. … … 499 499 _commoncheck(\%args, 'y'); 500 500 501 my ($code, $msg) = DNSDB::delRec($dbh,$args{defrec}, $args{recrev}, $args{id});501 my ($code, $msg) = $dnsdb->delRec($args{defrec}, $args{recrev}, $args{id}); 502 502 503 503 die $msg if $code eq 'FAIL'; … … 524 524 if ($args{delsubs}) { 525 525 # Delete ALL EVARYTHING!!one11!! in $args{cidr} 526 my $reclist = DNSDB::getDomRecs($dbh,defrec => 'n', revrec => 'y', id => $zonelist->[0]->{rdns_id});526 my $reclist = $dnsdb->getDomRecs(defrec => 'n', revrec => 'y', id => $zonelist->[0]->{rdns_id}); 527 527 foreach my $rec (@$reclist) { 528 528 my $reccidr = new NetAddr::IP $rec->{val}; … … 534 534 $rec->{type} == 12 || $rec->{type} == 65282 || 535 535 $rec->{type} == 65283 || $rec->{type} == 65284) { 536 my ($code,$msg) = DNSDB::delRec($dbh,'n', 'y', $rec->{record_id});536 my ($code,$msg) = $dnsdb->delRec('n', 'y', $rec->{record_id}); 537 537 } else { 538 my $ret = DNSDB::downconvert($dbh,$rec->{record_id}, $DNSDB::reverse_typemap{A});538 my $ret = $dnsdb->downconvert($rec->{record_id}, $DNSDB::reverse_typemap{A}); 539 539 } 540 540 } … … 542 542 # Edge case; we've just gone and axed all the records in the reverse zone. 543 543 # Re-add one to match the parent if we've been given a pattern to use. 544 addRec(defrec =>'n', revrec => 'y', parent_id => $zonelist->[0]->{rdns_id},544 $dnsdb->addRec(defrec =>'n', revrec => 'y', parent_id => $zonelist->[0]->{rdns_id}, 545 545 type => ($zone->{isv6} ? 65284 : 65283), address => "$cidr", %args); 546 546 } … … 551 551 # We need to strip the CIDR mask on IPv4 /32 assignments, or we can't find single-IP records 552 552 my $filt = ($cidr->{isv6} || $cidr->masklen != 32 ? "$cidr" : $cidr->addr); 553 my $reclist = DNSDB::getDomRecs($dbh,defrec => 'n', revrec => 'y',553 my $reclist = $dnsdb->getDomRecs(defrec => 'n', revrec => 'y', 554 554 id => $zonelist->[0]->{rdns_id}, filter => $filt, sortby => 'val', sortorder => 'DESC'); 555 555 foreach my $rec (@$reclist) { … … 559 559 $rec->{type} == 65282 || $rec->{type} == 65283 ||$rec->{type} == 65284; 560 560 if ($args{delforward} || $rec->{type} == 12) { 561 my ($code,$msg) = DNSDB::delRec($dbh,'n', 'y', $rec->{record_id});561 my ($code,$msg) = $dnsdb->delRec('n', 'y', $rec->{record_id}); 562 562 die $msg if $code eq 'FAIL'; 563 563 return $msg; 564 564 } else { 565 my $ret = DNSDB::downconvert($dbh,$rec->{record_id}, $DNSDB::reverse_typemap{A});566 die $ DNSDB::errstr if !$ret;565 my $ret = $dnsdb->downconvert($rec->{record_id}, $DNSDB::reverse_typemap{A}); 566 die $dnsdb->errstr if !$ret; 567 567 return "A+PTR for $args{cidr} split and PTR removed"; 568 568 } … … 579 579 # that spans multiple reverse zones (eg, /23 CIDR -> 2 /24 rzones) 580 580 foreach my $zdata (@$zonelist) { 581 my $reclist = DNSDB::getDomRecs($dbh,defrec => 'n', revrec => 'y', id => $zdata->{rdns_id});581 my $reclist = $dnsdb->getDomRecs(defrec => 'n', revrec => 'y', id => $zdata->{rdns_id}); 582 582 if (scalar(@$reclist) == 0) { 583 583 # nothing to do? or do we (re)add a record based on the parent? … … 595 595 $rec->{type} == 12 || $rec->{type} == 65282 || 596 596 $rec->{type} == 65283 || $rec->{type} == 65284) { 597 my ($code,$msg) = DNSDB::delRec($dbh,'n', 'y', $rec->{record_id});597 my ($code,$msg) = $dnsdb->delRec('n', 'y', $rec->{record_id}); 598 598 } else { 599 my $ret = DNSDB::downconvert($dbh,$rec->{record_id}, $DNSDB::reverse_typemap{A});599 my $ret = $dnsdb->downconvert($rec->{record_id}, $DNSDB::reverse_typemap{A}); 600 600 } 601 601 } # foreach @$reclist … … 604 604 # We've just gone and axed all the records in the reverse zone. 605 605 # Re-add one to match the parent if we've been given a pattern to use. 606 addRec(defrec =>'n', revrec => 'y', parent_id => $zdata->{rdns_id},606 $dnsdb->addRec(defrec =>'n', revrec => 'y', parent_id => $zdata->{rdns_id}, 607 607 type => ($cidr->{isv6} ? 65284 : 65283), 608 608 address => $zdata->{revnet}, name => $args{parpatt}, %args); -
trunk/dns.cgi
r480 r481 443 443 444 444 # prepopulate revpatt with the matching default record 445 # getRecByName($dbh, (revrec => $webvar{revrec}, defrec => $webvar{defrec}, host => 'string'));445 # $dnsdb->getRecByName(revrec => $webvar{revrec}, defrec => $webvar{defrec}, host => 'string'); 446 446 447 447 if ($session->param('add_failed')) { … … 543 543 $page->param(curpage => $webvar{page}); 544 544 545 my $count = getRecCount($dbh,$webvar{defrec}, $webvar{revrec}, $webvar{id}, $filter);545 my $count = $dnsdb->getRecCount($webvar{defrec}, $webvar{revrec}, $webvar{id}, $filter); 546 546 547 547 $sortby = 'host'; … … 638 638 $webvar{location} = $parloc unless ($permissions{admin} || $permissions{record_locchg}); 639 639 640 my @recargs = ($ dbh,$webvar{defrec},$webvar{revrec},$webvar{parentid},641 \$webvar{name}, \$webvar{type},\$webvar{address},$webvar{ttl},$webvar{location});640 my @recargs = ($webvar{defrec}, $webvar{revrec}, $webvar{parentid}, 641 \$webvar{name}, \$webvar{type}, \$webvar{address}, $webvar{ttl}, $webvar{location}); 642 642 if ($webvar{type} == $reverse_typemap{MX} or $webvar{type} == $reverse_typemap{SRV}) { 643 643 push @recargs, $webvar{distance}; … … 648 648 } 649 649 650 my ($code,$msg) = addRec(@recargs);650 my ($code,$msg) = $dnsdb->addRec(@recargs); 651 651 652 652 if ($code eq 'OK' || $code eq 'WARN') { … … 679 679 $page->param(parentid => $webvar{parentid}); 680 680 $page->param(id => $webvar{id}); 681 my $recdata = getRecLine($dbh,$webvar{defrec}, $webvar{revrec}, $webvar{id});681 my $recdata = $dnsdb->getRecLine($webvar{defrec}, $webvar{revrec}, $webvar{id}); 682 682 $page->param(name => $recdata->{host}); 683 683 $page->param(address => $recdata->{val}); … … 698 698 699 699 # retain old location if user doesn't have permission to fiddle locations 700 my $oldrec = getRecLine($dbh,$webvar{defrec}, $webvar{revrec}, $webvar{id});700 my $oldrec = $dnsdb->getRecLine($webvar{defrec}, $webvar{revrec}, $webvar{id}); 701 701 $webvar{location} = $oldrec->{location} unless ($permissions{admin} || $permissions{record_locchg}); 702 702 703 my ($code,$msg) = updateRec($dbh,$webvar{defrec},$webvar{revrec},$webvar{id},$webvar{parentid},704 \$webvar{name}, \$webvar{type},\$webvar{address},$webvar{ttl},$webvar{location},705 $webvar{distance}, $webvar{weight},$webvar{port});703 my ($code,$msg) = $dnsdb->updateRec($webvar{defrec}, $webvar{revrec}, $webvar{id}, $webvar{parentid}, 704 \$webvar{name}, \$webvar{type}, \$webvar{address}, $webvar{ttl}, $webvar{location}, 705 $webvar{distance}, $webvar{weight}, $webvar{port}); 706 706 707 707 if ($code eq 'OK' || $code eq 'WARN') { … … 756 756 if (!defined($webvar{del})) { 757 757 $page->param(del_getconf => 1); 758 my $rec = getRecLine($dbh,$webvar{defrec}, $webvar{revrec}, $webvar{id});758 my $rec = $dnsdb->getRecLine($webvar{defrec}, $webvar{revrec}, $webvar{id}); 759 759 $page->param(host => $rec->{host}); 760 760 $page->param(ftype => $typemap{$rec->{type}}); 761 761 $page->param(recval => $rec->{val}); 762 762 } elsif ($webvar{del} eq 'ok') { 763 my ($code,$msg) = delRec($dbh,$webvar{defrec}, $webvar{revrec}, $webvar{id});763 my ($code,$msg) = $dnsdb->delRec($webvar{defrec}, $webvar{revrec}, $webvar{id}); 764 764 if ($code eq 'OK') { 765 765 changepage(page => "reclist", id => $webvar{parentid}, defrec => $webvar{defrec}, … … 816 816 unless ($permissions{admin} || $permissions{domain_edit}); 817 817 818 my ($code, $msg) = updateSOA($dbh,$webvar{defrec}, $webvar{revrec},818 my ($code, $msg) = $dnsdb->updateSOA($webvar{defrec}, $webvar{revrec}, 819 819 (contact => $webvar{contact}, prins => $webvar{prins}, refresh => $webvar{refresh}, 820 820 retry => $webvar{retry}, expire => $webvar{expire}, minttl => $webvar{minttl}, … … 1863 1863 if ($preserve eq 'd') { 1864 1864 # there are probably better ways to do this. TMTOWTDI. 1865 my $soa = getSOA($dbh,$defrec,$revrec,$id);1865 my $soa = $dnsdb->getSOA($defrec, $revrec, $id); 1866 1866 1867 1867 $page->param(prins => ($soa->{prins} ? $soa->{prins} : $DNSDB::def{prins})); … … 1889 1889 1890 1890 # get the SOA first 1891 my $soa = getSOA($dbh,$def,$rev,$id);1891 my $soa = $dnsdb->getSOA($def, $rev, $id); 1892 1892 1893 1893 $page->param(contact => $soa->{contact}); … … 1899 1899 $page->param(ttl => $soa->{ttl}); 1900 1900 1901 my $foo2 = getDomRecs($dbh,(defrec => $def, revrec => $rev, id => $id, offset => $webvar{offset},1902 sortby => $sortby, sortorder => $sortorder, filter => $filter) );1901 my $foo2 = $dnsdb->getDomRecs(defrec => $def, revrec => $rev, id => $id, offset => $webvar{offset}, 1902 sortby => $sortby, sortorder => $sortorder, filter => $filter); 1903 1903 1904 1904 foreach my $rec (@$foo2) { … … 1941 1941 } 1942 1942 # retrieve the right ttl instead of falling (way) back to the hardcoded system default 1943 my $soa = getSOA($dbh,$webvar{defrec},$webvar{revrec},$webvar{parentid});1943 my $soa = $dnsdb->getSOA($webvar{defrec}, $webvar{revrec}, $webvar{parentid}); 1944 1944 $page->param(ttl => ($webvar{ttl} ? $webvar{ttl} : $soa->{minttl})); 1945 1945 }
Note:
See TracChangeset
for help on using the changeset viewer.