Ignore:
Timestamp:
01/02/14 13:26:38 (10 years ago)
Author:
Kris Deugau
Message:

/branches/stable

Merge forward bugfixes and option additions from /trunk r570 through r581

Location:
branches/stable
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/stable

  • branches/stable/DNSDB.pm

    r568 r582  
    213213                force_refresh   => 1,
    214214                lowercase       => 0,   # mangle as little as possible by default
     215                showrec_arpa_ns => 0,   # show formal .arpa zone name instead of logical CIDR on reverse NS records
    215216        );
    216217
     
    242243
    243244  # Several settings are booleans.  Handle multiple possible ways of setting them.
    244   for my $boolopt ('log_failures', 'force_refresh', 'lowercase', 'usecache') {
     245  for my $boolopt ('log_failures', 'force_refresh', 'lowercase', 'usecache', 'showrec_arpa_ns') {
    245246    if ($self->{$boolopt} ne '1' && $self->{$boolopt} ne '0') {
    246247      # true/false, on/off, yes/no all valid.
     
    11361137    my $tmpzone = $zone;
    11371138    $tmpzone =~ s/\.in-addr\.arpa\.?//;
    1138     return ('FAIL', "Non-numerics in apparent IPv4 reverse zone name") if $tmpzone !~ /^(?:\d+-)?[\d\.]+$/;
     1139    return ('FAIL', "Non-numerics in apparent IPv4 reverse zone name [$tmpzone]") if $tmpzone !~ m{^(?:\d+[/-])?[\d\.]+$};
    11391140
    11401141    # Snag the octet pieces
     
    11531154    # Alternate form:  The second number is actually the real netmask, not the end of the range.
    11541155    my $masklen = 0;
    1155     if ($octs[0] =~ /^((\d+)-(\d+))$/) {        # take the range...
     1156    if ($octs[0] =~ m{^((\d+)[/-](\d+))$}) {    # take the range...
    11561157      if (24 < $3 && $3 < 31) {
    11571158        # we have a real netmask
     
    13421343      $cfg->{force_refresh}     = $1 if /^force_refresh\s*=\s*([a-z01]+)/i;
    13431344      $cfg->{lowercase}         = $1 if /^lowercase\s*=\s*([a-z01]+)/i;
     1345      $cfg->{showrec_arpa_ns}   = $1 if /^showrec_arpa_ns\s*=\s*([a-z01]+)/i;
    13441346# not supported in dns.cgi yet
    13451347#      $cfg->{templatedir}      = $1 if m{^templatedir\s*=\s*([a-z0-9/_.-]+)}i;
     
    23072309  if ($args{revrec} eq 'n') {
    23082310    $args{sortby} = 'domain' if !$args{sortby} || !grep /^$args{sortby}$/, ('domain','group','status');
    2309     $sql = "SELECT domain_id,domain,status,groups.group_name AS group FROM domains".
     2311    $sql = "SELECT domain_id AS zoneid,domain AS zone,status,groups.group_name AS group FROM domains".
    23102312        " INNER JOIN groups ON domains.group_id=groups.group_id".
    23112313        " WHERE domains.group_id IN ($args{curgroup}".($args{childlist} ? ",$args{childlist}" : '').")".
     
    23152317##fixme:  arguably startwith here is irrelevant.  depends on the UI though.
    23162318    $args{sortby} = 'revnet' if !$args{sortby} || !grep /^$args{sortby}$/, ('revnet','group','status');
    2317     $sql = "SELECT rdns_id,revnet,status,groups.group_name AS group FROM revzones".
     2319    $sql = "SELECT rdns_id AS zoneid,revnet AS zone,status,groups.group_name AS group FROM revzones".
    23182320        " INNER JOIN groups ON revzones.group_id=groups.group_id".
    23192321        " WHERE revzones.group_id IN ($args{curgroup}".($args{childlist} ? ",$args{childlist}" : '').")".
     
    23252327        ($args{offset} eq 'all' ? '' : " LIMIT $self->{perpage}".
    23262328        " OFFSET ".$args{offset}*$self->{perpage});
    2327   my $sth = $dbh->prepare($sql);
    2328   $sth->execute(@filterargs);
    2329   my $rownum = 0;
    2330 
    2331   while (my @data = $sth->fetchrow_array) {
    2332     my %row;
    2333     $row{domain_id} = $data[0];
    2334     $row{domain} = $data[1];
    2335     $row{status} = $data[2];
    2336     $row{group} = $data[3];
    2337     push @zonelist, \%row;
    2338   }
    2339 
    2340   return \@zonelist;
     2329
     2330  my $ret = $dbh->selectall_arrayref($sql, { Slice => {} }, @filterargs);
     2331  return $ret;
    23412332} # end getZoneList()
    23422333
     
    47124703      } elsif ($type eq 'NS') {
    47134704# hmm.  should we warn here if subdomain NS'es are left alone?
    4714         next if ($args{rwns} && ($rr->name eq $zone));
    47154705        if ($rev eq 'y') {
    47164706          # revzones have records more or less reversed from forward zones.
    47174707          my ($tmpcode,$tmpmsg) = _zone2cidr($host);
    47184708          die "Error converting NS record: $tmpmsg\n" if $tmpcode eq 'FAIL';    # hmm.  may not make sense...
     4709          next if ($args{rwns} && ($tmpmsg eq "$cidr"));
    47194710          $val = "$tmpmsg";
    47204711          $host = $rr->nsdname;
     
    47264717#}
    47274718        } else {
     4719          next if ($args{rwns} && ($rr->name eq $zone));
    47284720          $val = $rr->nsdname;
    47294721        }
     
    48794871    if ($args{rwsoa}) {
    48804872      $soaflag = 1;
    4881       my $sthgetsoa = $dbh->prepare("SELECT host,val,ttl FROM default_records WHERE group_id=? AND type=?");
    4882       my $sthputsoa = $dbh->prepare("INSERT INTO records (domain_id,host,type,val,ttl) VALUES (?,?,?,?,?)");
     4873      my $sthgetsoa = $dbh->prepare("SELECT host,val,ttl FROM "._rectable('y', $rev)." WHERE group_id=? AND type=?");
     4874      my $sthputsoa = $dbh->prepare("INSERT INTO records (".
     4875        ($rev eq 'n' ? 'domain_id' : 'rdns_id').",host,type,val,ttl) VALUES (?,?,?,?,?)");
    48834876      $sthgetsoa->execute($group,$reverse_typemap{SOA});
    48844877      while (my ($host,$val,$ttl) = $sthgetsoa->fetchrow_array()) {
    4885         $host =~ s/DOMAIN/$zone/g;
    4886         $val =~ s/DOMAIN/$zone/g;
     4878        if ($rev eq 'n') {
     4879          $host =~ s/DOMAIN/$zone/g;
     4880          $val =~ s/DOMAIN/$zone/g;     # arguably useless
     4881        } else {
     4882          $host =~ s/ADMINDOMAIN/$self->{domain}/g;
     4883        }
    48874884        $sthputsoa->execute($zone_id,$host,$reverse_typemap{SOA},$val,$ttl);
    48884885      }
    48894886    }
    48904887
    4891     # Overwrite NS records
     4888    # Add standard NS records.  The old one(s) should have been skipped by this point.
    48924889    if ($args{rwns}) {
    48934890      $nsflag = 1;
    4894       my $sthgetns = $dbh->prepare("SELECT host,val,ttl FROM default_records WHERE group_id=? AND type=?");
    4895       my $sthputns = $dbh->prepare("INSERT INTO records (domain_id,host,type,val,ttl) VALUES (?,?,?,?,?)");
     4891      my $sthgetns = $dbh->prepare("SELECT host,val,ttl FROM "._rectable('y',$rev)." WHERE group_id=? AND type=?");
     4892      my $sthputns = $dbh->prepare("INSERT INTO records (".
     4893        ($rev eq 'n' ? 'domain_id' : 'rdns_id').",host,type,val,ttl) VALUES (?,?,?,?,?)");
    48964894      $sthgetns->execute($group,$reverse_typemap{NS});
    48974895      while (my ($host,$val,$ttl) = $sthgetns->fetchrow_array()) {
    4898         $host =~ s/DOMAIN/$zone/g;
    4899         $val =~ s/DOMAIN/$zone/g;
     4896        if ($rev eq 'n') {
     4897          $host =~ s/DOMAIN/$zone/g;
     4898          $val =~ s/DOMAIN/$zone/g;     #hmm.
     4899        } else {
     4900          $host =~ s/ADMINDOMAIN/$self->{domain}/g;     #hmm.
     4901          $val =~ s/ZONE/$cidr/g;
     4902        }
    49004903        $sthputns->execute($zone_id,$host,$reverse_typemap{NS},$val,$ttl);
    49014904      }
     
    50535056        "FROM records WHERE rdns_id=? AND type=6");
    50545057  my $recsth = $dbh->prepare("SELECT host,type,val,distance,weight,port,ttl,record_id,location,extract(epoch from stamp),expires,stampactive ".
    5055         "FROM records WHERE rdns_id=? AND not type=6 ".
     5058        "FROM records WHERE rdns_id=? AND NOT type=6 ".
    50565059        "ORDER BY masklen(CAST(val AS inet)) DESC, CAST(val AS inet)");
    50575060  my $revsth = $dbh->prepare("SELECT rdns_id,revnet,status,changed FROM revzones WHERE status=1 ".
     
    50895092        $soasth->execute($revid);
    50905093        my (@zsoa) = $soasth->fetchrow_array();
    5091         _printrec_tiny($zonefilehandle,'y',\%recflags,$revzone,
     5094        _printrec_tiny($zonefilehandle, $zsoa[7], 'y',\%recflags,$revzone,
    50925095          $zsoa[0],$zsoa[1],$zsoa[2],$zsoa[3],$zsoa[4],$zsoa[5],$zsoa[6],$zsoa[8],'');
    50935096
    50945097        $recsth->execute($revid);
    5095         while (my ($host,$type,$val,$dist,$weight,$port,$ttl,$recid,$loc,$stamp,$expires,$stampactive) = $recsth->fetchrow_array) {
     5098        while (my ($host, $type, $val, $dist, $weight, $port, $ttl, $recid, $loc, $stamp, $expires, $stampactive)
     5099                = $recsth->fetchrow_array) {
    50965100          next if $recflags{$recid};
    50975101
     
    51065110#         }
    51075111
    5108           _printrec_tiny($zonefilehandle, 'y', \%recflags, $revzone,
     5112          _printrec_tiny($zonefilehandle, $recid, 'y', \%recflags, $revzone,
    51095113            $host, $type, $val, $dist, $weight, $port, $ttl, $loc, $stamp, $expires, $stampactive);
    51105114
     
    51485152  } # while ($revsth)
    51495153
     5154  $soasth = $dbh->prepare("SELECT host,type,val,distance,weight,port,ttl,record_id,location ".
     5155        "FROM records WHERE domain_id=? AND type=6");
     5156  $recsth = $dbh->prepare("SELECT host,type,val,distance,weight,port,ttl,record_id,location,extract(epoch from stamp),expires,stampactive ".
     5157        "FROM records WHERE domain_id=? AND NOT type=6");       # Just exclude all types relating to rDNS
     5158#       "FROM records WHERE domain_id=? AND type < 65280");     # Just exclude all types relating to rDNS
    51505159  my $domsth = $dbh->prepare("SELECT domain_id,domain,status,changed FROM domains WHERE status=1 ORDER BY domain_id");
    5151   $recsth = $dbh->prepare("SELECT host,type,val,distance,weight,port,ttl,record_id,location,extract(epoch from stamp),expires,stampactive ".
    5152         "FROM records WHERE domain_id=?");      # Just exclude all types relating to rDNS
    5153 #       "FROM records WHERE domain_id=? AND type < 65280");     # Just exclude all types relating to rDNS
    51545160  $zonesth = $dbh->prepare("UPDATE domains SET changed='n' WHERE domain_id=?");
    51555161  $domsth->execute();
     
    51775183        }
    51785184
     5185        # need to fetch this separately so the SOA comes first in the flatfile....
     5186        # Just In Case we need/want to reimport from the flatfile later on.
     5187        $soasth->execute($domid);
     5188        my (@zsoa) = $soasth->fetchrow_array();
     5189        _printrec_tiny($zonefilehandle, $zsoa[7], 'n',\%recflags,$dom,
     5190          $zsoa[0],$zsoa[1],$zsoa[2],$zsoa[3],$zsoa[4],$zsoa[5],$zsoa[6],$zsoa[8],'');
     5191
    51795192        $recsth->execute($domid);
    51805193        while (my ($host,$type,$val,$dist,$weight,$port,$ttl,$recid,$loc,$stamp,$expires,$stampactive) = $recsth->fetchrow_array) {
     
    51905203          }
    51915204
    5192           _printrec_tiny($zonefilehandle, 'n', \%recflags,
     5205          _printrec_tiny($zonefilehandle, $recid, 'n', \%recflags,
    51935206                $dom, $host, $type, $val, $dist, $weight, $port, $ttl, $loc, $stamp, $expires, $stampactive);
    51945207
     
    52395252# Utility sub for __export_tiny above
    52405253sub _printrec_tiny {
    5241   my ($datafile,$revrec,$recflags,$zone,$host,$type,$val,$dist,$weight,$port,$ttl,$loc,$stamp,$expires,$stampactive) = @_;
     5254  my ($datafile, $recid, $revrec, $recflags, $zone, $host, $type, $val, $dist, $weight, $port, $ttl,
     5255        $loc, $stamp, $expires, $stampactive) = @_;
    52425256
    52435257  $loc = '' if !$loc;   # de-nullify - just in case
Note: See TracChangeset for help on using the changeset viewer.