Changeset 484 for trunk/DNSDB.pm


Ignore:
Timestamp:
03/15/13 12:09:59 (11 years ago)
Author:
Kris Deugau
Message:

/trunk

Object conversion of DNSDB.pm, part 16. See #11.

  • importAXFR(). While we're meddling, update the calling convention so it's easier to set the various flags separately.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/DNSDB.pm

    r483 r484  
    43404340# Import a domain via AXFR
    43414341# Takes AXFR host, domain to transfer, group to put the domain in,
    4342 # and optionally:
    4343 #  - active/inactive state flag (defaults to active)
    4344 #  - overwrite-SOA flag (defaults to off)
    4345 #  - overwrite-NS flag (defaults to off, doesn't affect subdomain NS records)
     4342# and an optional hash containing:
     4343#  status - active/inactive state flag (defaults to active)
     4344#  rwsoa - overwrite-SOA flag (defaults to off)
     4345#  rwns - overwrite-NS flag (defaults to off, doesn't affect subdomain NS records)
     4346#  merge - flag to automerge A or AAAA records with matching PTR records
    43464347# Returns a status code (OK, WARN, or FAIL) and message - message should be blank
    43474348# if status is OK, but WARN includes conditions that are not fatal but should
    43484349# really be reported.
    43494350sub importAXFR {
    4350   my $dbh = shift;
     4351  my $self = shift;
     4352  my $dbh = $self->{dbh};
    43514353  my $ifrom_in = shift;
    43524354  my $zone = shift;
    43534355  my $group = shift;
    4354   my $status = shift;
    4355   $status = (defined($status) ? $status : 0);   # force sane semantics, and allow passing "null" (inactive) status
    4356   my $rwsoa = shift || 0;
    4357   my $rwns = shift || 0;
    4358   my $newttl = shift;
    4359   my $merge = shift || 0;       # do we attempt to merge A/AAAA and PTR records whenever possible?
    4360                                 # do we overload this with the fixme below?
     4356
     4357  my %args = @_;
     4358
    43614359##fixme:  add mode to delete&replace, merge+overwrite, merge new?
     4360
     4361  $args{status} = (defined($args{status}) ? $args{status} : 0);
     4362  $args{status} = 1 if $args{status} eq 'on';
    43624363
    43634364  my $nrecs = 0;
     
    44654466    if ($rev eq 'n') {
    44664467##fixme:  serial
    4467       $dbh->do("INSERT INTO domains (domain,group_id,status) VALUES (?,?,?)", undef, ($zone,$group,$status) );
     4468      $dbh->do("INSERT INTO domains (domain,group_id,status) VALUES (?,?,?)", undef,
     4469        ($zone, $group, $args{status}) );
    44684470      # get domain id so we can do the records
    44694471      ($zone_id) = $dbh->selectrow_array("SELECT currval('domains_domain_id_seq')");
     
    44734475    } else {
    44744476##fixme:  serial
    4475       $dbh->do("INSERT INTO revzones (revnet,group_id,status) VALUES (?,?,?)", undef, ($cidr,$group,$status) );
     4477      $dbh->do("INSERT INTO revzones (revnet,group_id,status) VALUES (?,?,?)", undef,
     4478        ($cidr,$group,$args{status}) );
    44764479      # get revzone id so we can do the records
    44774480      ($zone_id) = $dbh->selectrow_array("SELECT currval('revzones_rdns_id_seq')");
     
    45124515      my $type = $rr->type;
    45134516      my $host = $rr->name;
    4514       my $ttl = ($newttl ? $newttl : $rr->ttl); # allow force-override TTLs
     4517      my $ttl = ($args{newttl} ? $args{newttl} : $rr->ttl);     # allow force-override TTLs
    45154518
    45164519      $soaflag = 1 if $type eq 'SOA';
     
    45424545      } elsif ($type eq 'NS') {
    45434546# hmm.  should we warn here if subdomain NS'es are left alone?
    4544         next if ($rwns && ($rr->name eq $zone));
     4547        next if ($args{rwns} && ($rr->name eq $zone));
    45454548        if ($rev eq 'y') {
    45464549          # revzones have records more or less reversed from forward zones.
     
    45784581        }
    45794582      } elsif ($type eq 'SOA') {
    4580         next if $rwsoa;
     4583        next if $args{rwsoa};
    45814584        $host = $rr->rname.":".$rr->mname;
    45824585        $val = $rr->refresh.":".$rr->retry.":".$rr->expire.":".$rr->minimum;
     
    46264629      my $logentry = "[AXFR ".($rev eq 'n' ? $zone : $cidr)."] ";
    46274630
    4628       if ($merge) {
     4631      if ($args{merge}) {
    46294632        if ($rev eq 'n') {
    46304633          # importing a domain;  we have A and AAAA records that could be merged with matching PTR records
     
    46724675          }
    46734676        } # $rev eq 'y'
    4674       } # if $merge
     4677      } # if $args{merge}
    46754678
    46764679      # Insert the new record
     
    46814684
    46824685      if ($type eq 'SOA') {
    4683         # also !$rwsoa, but if that's set, it should be impossible to get here.
     4686        # also !$args{rwsoa}, but if that's set, it should be impossible to get here.
    46844687        my @tmp1 = split /:/, $host;
    46854688        my @tmp2 = split /:/, $val;
     
    47074710
    47084711    # Overwrite SOA record
    4709     if ($rwsoa) {
     4712    if ($args{rwsoa}) {
    47104713      $soaflag = 1;
    47114714      my $sthgetsoa = $dbh->prepare("SELECT host,val,ttl FROM default_records WHERE group_id=? AND type=?");
     
    47204723
    47214724    # Overwrite NS records
    4722     if ($rwns) {
     4725    if ($args{rwns}) {
    47234726      $nsflag = 1;
    47244727      my $sthgetns = $dbh->prepare("SELECT host,val,ttl FROM default_records WHERE group_id=? AND type=?");
Note: See TracChangeset for help on using the changeset viewer.