Changeset 481


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.
Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/DNSDB.pm

    r480 r481  
    33503350sub getSOA {
    33513351  $errstr = '';
    3352   my $dbh = shift;
     3352  my $self = shift;
     3353  my $dbh = $self->{dbh};
    33533354  my $def = shift;
    33543355  my $rev = shift;
     
    34423443sub getRecLine {
    34433444  $errstr = '';
    3444   my $dbh = shift;
     3445  my $self = shift;
     3446  my $dbh = $self->{dbh};
    34453447  my $defrec = shift;
    34463448  my $revrec = shift;
     
    34863488sub getDomRecs {
    34873489  $errstr = '';
    3488   my $dbh = shift;
     3490  my $self = shift;
     3491  my $dbh = $self->{dbh};
    34893492
    34903493  my %args = @_;
     
    35413544# Returns the count
    35423545sub getRecCount {
    3543   my $dbh = shift;
     3546  my $self = shift;
     3547  my $dbh = $self->{dbh};
    35443548  my $defrec = shift;
    35453549  my $revrec = shift;
     
    35753579sub addRec {
    35763580  $errstr = '';
    3577   my $dbh = shift;
     3581  my $self = shift;
     3582  my $dbh = $self->{dbh};
    35783583  my $defrec = shift;
    35793584  my $revrec = shift;
     
    36263631
    36273632  # 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,
    36293634        host => $host, rectype => $rectype, val => $val, addr => $addr,
    36303635        dist => \$dist, port => \$port, weight => \$weight,
    3631         fields => \$fields, vallist => \@vallist) );
     3636        fields => \$fields, vallist => \@vallist);
    36323637
    36333638  return ($retcode,$retmsg) if $retcode eq 'FAIL';
    36343639
    36353640  # 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  }
    36383649  my $vallen = '?'.(',?'x$#vallist);
    36393650
     
    37003711  $errstr = '';
    37013712
    3702   my $dbh = shift;
     3713  my $self = shift;
     3714  my $dbh = $self->{dbh};
    37033715  my $defrec = shift;
    37043716  my $revrec = shift;
     
    37543766  # get old record data so we have the right parent ID
    37553767  # and for logging (eventually)
    3756   my $oldrec = getRecLine($dbh, $defrec, $revrec, $id);
     3768  my $oldrec = $self->getRecLine($defrec, $revrec, $id);
    37573769
    37583770  # Call the validation sub for the type requested.
    37593771  # 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,
    37613773        id => ($defrec eq 'y' ? $oldrec->{group_id} : ($revrec eq 'n' ? $oldrec->{domain_id} : $oldrec->{rdns_id})),
    37623774        host => $host, rectype => $rectype, val => $val, addr => $addr,
    37633775        dist => \$dist, port => \$port, weight => \$weight,
    37643776        fields => \$fields, vallist => \@vallist,
    3765         update => $id) );
     3777        update => $id);
    37663778
    37673779  return ($retcode,$retmsg) if $retcode eq 'FAIL';
     
    38773889# Takes the record ID and the new type.  Returns boolean.
    38783890sub downconvert {
    3879   my $dbh = shift;
     3891  my $self = shift;
     3892  my $dbh = $self->{dbh};
    38803893  my $recid = shift;
    38813894  my $newtype = shift;
    38823895
    38833896  # 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);
    38853898
    38863899  # hm?
     
    39303943sub delRec {
    39313944  $errstr = '';
    3932   my $dbh = shift;
     3945  my $self = shift;
     3946  my $dbh = $self->{dbh};
    39333947  my $defrec = shift;
    39343948  my $revrec = shift;
    39353949  my $id = shift;
    39363950
    3937   my $oldrec = getRecLine($dbh, $defrec, $revrec, $id);
     3951  my $oldrec = $self->getRecLine($defrec, $revrec, $id);
    39383952
    39393953  # Allow transactions, and raise an exception on errors so we can catch it later.
  • 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);
  • trunk/dns.cgi

    r480 r481  
    443443
    444444  # 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');
    446446
    447447  if ($session->param('add_failed')) {
     
    543543    $page->param(curpage => $webvar{page});
    544544
    545     my $count = getRecCount($dbh, $webvar{defrec}, $webvar{revrec}, $webvar{id}, $filter);
     545    my $count = $dnsdb->getRecCount($webvar{defrec}, $webvar{revrec}, $webvar{id}, $filter);
    546546
    547547    $sortby = 'host';
     
    638638    $webvar{location} = $parloc unless ($permissions{admin} || $permissions{record_locchg});
    639639
    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});
    642642    if ($webvar{type} == $reverse_typemap{MX} or $webvar{type} == $reverse_typemap{SRV}) {
    643643      push @recargs, $webvar{distance};
     
    648648    }
    649649
    650     my ($code,$msg) = addRec(@recargs);
     650    my ($code,$msg) = $dnsdb->addRec(@recargs);
    651651
    652652    if ($code eq 'OK' || $code eq 'WARN') {
     
    679679    $page->param(parentid       => $webvar{parentid});
    680680    $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});
    682682    $page->param(name           => $recdata->{host});
    683683    $page->param(address        => $recdata->{val});
     
    698698
    699699    # 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});
    701701    $webvar{location} = $oldrec->{location} unless ($permissions{admin} || $permissions{record_locchg});
    702702
    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});
    706706
    707707    if ($code eq 'OK' || $code eq 'WARN') {
     
    756756  if (!defined($webvar{del})) {
    757757    $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});
    759759    $page->param(host => $rec->{host});
    760760    $page->param(ftype => $typemap{$rec->{type}});
    761761    $page->param(recval => $rec->{val});
    762762  } 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});
    764764    if ($code eq 'OK') {
    765765      changepage(page => "reclist", id => $webvar{parentid}, defrec => $webvar{defrec},
     
    816816        unless ($permissions{admin} || $permissions{domain_edit});
    817817
    818   my ($code, $msg) = updateSOA($dbh, $webvar{defrec}, $webvar{revrec},
     818  my ($code, $msg) = $dnsdb->updateSOA($webvar{defrec}, $webvar{revrec},
    819819        (contact => $webvar{contact}, prins => $webvar{prins}, refresh => $webvar{refresh},
    820820        retry => $webvar{retry}, expire => $webvar{expire}, minttl => $webvar{minttl},
     
    18631863  if ($preserve eq 'd') {
    18641864    # 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);
    18661866
    18671867    $page->param(prins  => ($soa->{prins} ? $soa->{prins} : $DNSDB::def{prins}));
     
    18891889
    18901890  # get the SOA first
    1891   my $soa = getSOA($dbh,$def,$rev,$id);
     1891  my $soa = $dnsdb->getSOA($def, $rev, $id);
    18921892
    18931893  $page->param(contact  => $soa->{contact});
     
    18991899  $page->param(ttl      => $soa->{ttl});
    19001900
    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);
    19031903
    19041904  foreach my $rec (@$foo2) {
     
    19411941  }
    19421942# 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});
    19441944  $page->param(ttl      => ($webvar{ttl} ? $webvar{ttl} : $soa->{minttl}));
    19451945}
Note: See TracChangeset for help on using the changeset viewer.