Changeset 481 for trunk/dns-rpc.cgi


Ignore:
Timestamp:
03/14/13 15:33:42 (12 years ago)
Author:
Kris Deugau
Message:

/trunk

Object conversion of DNSDB.pm, 14 of <mumble>. See #11.

  • record manipulation: getSOA(), getRecLine(), getDomRecs(), getRecCount(), addRec(), updateRec(), downconvert(), and delRec() and callers.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/dns-rpc.cgi

    r480 r481  
    313313  _commoncheck(\%args);
    314314
    315   my $ret = DNSDB::getSOA($dbh, $args{defrec}, $args{revrec}, $args{id});
     315  my $ret = $dnsdb->getSOA($args{defrec}, $args{revrec}, $args{id});
    316316  if (!$ret) {
    317317    if ($args{defrec} eq 'y') {
     
    331331  _commoncheck(\%args);
    332332
    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;
    336336
    337337  return $ret;
     
    350350  $args{direction} = 'ASC' if !$args{direction};
    351351
    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},
    353353        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;
    357357
    358358  return $ret;
     
    371371  $args{direction} = 'ASC' if !$args{direction};
    372372
    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;
    376376
    377377  return $ret;
     
    386386  _ttlcheck(\%args);
    387387
    388   my @recargs = ($dbh, $args{defrec}, $args{revrec}, $args{parent_id},
     388  my @recargs = ($args{defrec}, $args{revrec}, $args{parent_id},
    389389        \$args{name}, \$args{type}, \$args{address}, $args{ttl}, $args{location});
    390390  if ($args{type} == $DNSDB::reverse_typemap{MX} or $args{type} == $DNSDB::reverse_typemap{SRV}) {
     
    396396  }
    397397
    398   my ($code, $msg) = DNSDB::addRec(@recargs);
     398  my ($code, $msg) = $dnsdb->addRec(@recargs);
    399399
    400400  die $msg if $code eq 'FAIL';
     
    409409  # get old line, so we can update only the bits that the caller passed to change
    410410  # 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});
    412412  foreach my $field (qw(name type address ttl location distance weight port)) {
    413413    $args{$field} = $oldrec->{$field} if !$args{$field} && defined($oldrec->{$field});
     
    416416  # note dist, weight, port are not required on all types;  will be ignored if not needed.
    417417  # 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},
    419419        \$args{name}, \$args{type}, \$args{address}, $args{ttl}, $args{location},
    420420        $args{distance}, $args{weight}, $args{port});
     
    440440      # We need to strip the CIDR mask on IPv4 /32 assignments, or we just add a new record all the time.
    441441      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',
    443443        id => $zonelist->[0]->{rdns_id}, filter => $filt);
    444444      if (scalar(@$reclist) == 0) {
     
    454454                || $rec->{type} == 65282 || $rec->{type} == 65283 || $rec->{type} == 65284;
    455455          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},
    457457            parent_id => $zonelist->[0]->{rdns_id}, %args);
    458458          $flag = 1;
     
    463463          # Aren't Magic Numbers Fun?  See pseudotype list in dnsadmin.
    464464          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,
    466466            address => "$cidr", %args);
    467467        }
     
    474474    # that spans multiple reverse zones (eg, /23 CIDR -> 2 /24 rzones)
    475475    foreach my $zdata (@$zonelist) {
    476       my $reclist = DNSDB::getDomRecs($dbh, defrec => 'n', revrec => 'y',
     476      my $reclist = $dnsdb->getDomRecs(defrec => 'n', revrec => 'y',
    477477        id => $zdata->{rdns_id}, filter => $zdata->{revnet});
    478478      if (scalar(@$reclist) == 0) {
    479479        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,
    481481          address => "$args{cidr}", %args);
    482482      } else {
     
    485485          # types are nominally impossible here.
    486486          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},
    488488            parent_id => $zdata->{rdns_id}, %args);
    489489          last; # only do one record.
     
    499499  _commoncheck(\%args, 'y');
    500500
    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});
    502502
    503503  die $msg if $code eq 'FAIL';
     
    524524      if ($args{delsubs}) {
    525525        # 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});
    527527        foreach my $rec (@$reclist) {
    528528          my $reccidr = new NetAddr::IP $rec->{val};
     
    534534              $rec->{type} == 12 || $rec->{type} == 65282 ||
    535535              $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});
    537537          } 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});
    539539          }
    540540        }
     
    542542          # Edge case;  we've just gone and axed all the records in the reverse zone.
    543543          # 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},
    545545                 type => ($zone->{isv6} ? 65284 : 65283), address => "$cidr", %args);
    546546        }
     
    551551        # We need to strip the CIDR mask on IPv4 /32 assignments, or we can't find single-IP records
    552552        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',
    554554          id => $zonelist->[0]->{rdns_id}, filter => $filt, sortby => 'val', sortorder => 'DESC');
    555555        foreach my $rec (@$reclist) {
     
    559559                      $rec->{type} == 65282 || $rec->{type} == 65283 ||$rec->{type} == 65284;
    560560          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});
    562562            die $msg if $code eq 'FAIL';
    563563            return $msg;
    564564          } 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;
    567567            return "A+PTR for $args{cidr} split and PTR removed";
    568568          }
     
    579579    # that spans multiple reverse zones (eg, /23 CIDR -> 2 /24 rzones)
    580580    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});
    582582      if (scalar(@$reclist) == 0) {
    583583# nothing to do?  or do we (re)add a record based on the parent?
     
    595595              $rec->{type} == 12 || $rec->{type} == 65282 ||
    596596              $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});
    598598          } 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});
    600600          }
    601601        } # foreach @$reclist
     
    604604        # We've just gone and axed all the records in the reverse zone.
    605605        # 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},
    607607               type => ($cidr->{isv6} ? 65284 : 65283),
    608608               address => $zdata->{revnet}, name => $args{parpatt}, %args);
Note: See TracChangeset for help on using the changeset viewer.