Changeset 582 for branches/stable/DNSDB.pm
- Timestamp:
- 01/02/14 13:26:38 (10 years ago)
- Location:
- branches/stable
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/stable
-
branches/stable/DNSDB.pm
r568 r582 213 213 force_refresh => 1, 214 214 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 215 216 ); 216 217 … … 242 243 243 244 # 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') { 245 246 if ($self->{$boolopt} ne '1' && $self->{$boolopt} ne '0') { 246 247 # true/false, on/off, yes/no all valid. … … 1136 1137 my $tmpzone = $zone; 1137 1138 $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\.]+$}; 1139 1140 1140 1141 # Snag the octet pieces … … 1153 1154 # Alternate form: The second number is actually the real netmask, not the end of the range. 1154 1155 my $masklen = 0; 1155 if ($octs[0] =~ /^((\d+)-(\d+))$/) { # take the range...1156 if ($octs[0] =~ m{^((\d+)[/-](\d+))$}) { # take the range... 1156 1157 if (24 < $3 && $3 < 31) { 1157 1158 # we have a real netmask … … 1342 1343 $cfg->{force_refresh} = $1 if /^force_refresh\s*=\s*([a-z01]+)/i; 1343 1344 $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; 1344 1346 # not supported in dns.cgi yet 1345 1347 # $cfg->{templatedir} = $1 if m{^templatedir\s*=\s*([a-z0-9/_.-]+)}i; … … 2307 2309 if ($args{revrec} eq 'n') { 2308 2310 $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". 2310 2312 " INNER JOIN groups ON domains.group_id=groups.group_id". 2311 2313 " WHERE domains.group_id IN ($args{curgroup}".($args{childlist} ? ",$args{childlist}" : '').")". … … 2315 2317 ##fixme: arguably startwith here is irrelevant. depends on the UI though. 2316 2318 $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". 2318 2320 " INNER JOIN groups ON revzones.group_id=groups.group_id". 2319 2321 " WHERE revzones.group_id IN ($args{curgroup}".($args{childlist} ? ",$args{childlist}" : '').")". … … 2325 2327 ($args{offset} eq 'all' ? '' : " LIMIT $self->{perpage}". 2326 2328 " 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; 2341 2332 } # end getZoneList() 2342 2333 … … 4712 4703 } elsif ($type eq 'NS') { 4713 4704 # hmm. should we warn here if subdomain NS'es are left alone? 4714 next if ($args{rwns} && ($rr->name eq $zone));4715 4705 if ($rev eq 'y') { 4716 4706 # revzones have records more or less reversed from forward zones. 4717 4707 my ($tmpcode,$tmpmsg) = _zone2cidr($host); 4718 4708 die "Error converting NS record: $tmpmsg\n" if $tmpcode eq 'FAIL'; # hmm. may not make sense... 4709 next if ($args{rwns} && ($tmpmsg eq "$cidr")); 4719 4710 $val = "$tmpmsg"; 4720 4711 $host = $rr->nsdname; … … 4726 4717 #} 4727 4718 } else { 4719 next if ($args{rwns} && ($rr->name eq $zone)); 4728 4720 $val = $rr->nsdname; 4729 4721 } … … 4879 4871 if ($args{rwsoa}) { 4880 4872 $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 (?,?,?,?,?)"); 4883 4876 $sthgetsoa->execute($group,$reverse_typemap{SOA}); 4884 4877 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 } 4887 4884 $sthputsoa->execute($zone_id,$host,$reverse_typemap{SOA},$val,$ttl); 4888 4885 } 4889 4886 } 4890 4887 4891 # Overwrite NS records4888 # Add standard NS records. The old one(s) should have been skipped by this point. 4892 4889 if ($args{rwns}) { 4893 4890 $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 (?,?,?,?,?)"); 4896 4894 $sthgetns->execute($group,$reverse_typemap{NS}); 4897 4895 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 } 4900 4903 $sthputns->execute($zone_id,$host,$reverse_typemap{NS},$val,$ttl); 4901 4904 } … … 5053 5056 "FROM records WHERE rdns_id=? AND type=6"); 5054 5057 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 nottype=6 ".5058 "FROM records WHERE rdns_id=? AND NOT type=6 ". 5056 5059 "ORDER BY masklen(CAST(val AS inet)) DESC, CAST(val AS inet)"); 5057 5060 my $revsth = $dbh->prepare("SELECT rdns_id,revnet,status,changed FROM revzones WHERE status=1 ". … … 5089 5092 $soasth->execute($revid); 5090 5093 my (@zsoa) = $soasth->fetchrow_array(); 5091 _printrec_tiny($zonefilehandle, 'y',\%recflags,$revzone,5094 _printrec_tiny($zonefilehandle, $zsoa[7], 'y',\%recflags,$revzone, 5092 5095 $zsoa[0],$zsoa[1],$zsoa[2],$zsoa[3],$zsoa[4],$zsoa[5],$zsoa[6],$zsoa[8],''); 5093 5096 5094 5097 $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) { 5096 5100 next if $recflags{$recid}; 5097 5101 … … 5106 5110 # } 5107 5111 5108 _printrec_tiny($zonefilehandle, 'y', \%recflags, $revzone,5112 _printrec_tiny($zonefilehandle, $recid, 'y', \%recflags, $revzone, 5109 5113 $host, $type, $val, $dist, $weight, $port, $ttl, $loc, $stamp, $expires, $stampactive); 5110 5114 … … 5148 5152 } # while ($revsth) 5149 5153 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 5150 5159 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 rDNS5153 # "FROM records WHERE domain_id=? AND type < 65280"); # Just exclude all types relating to rDNS5154 5160 $zonesth = $dbh->prepare("UPDATE domains SET changed='n' WHERE domain_id=?"); 5155 5161 $domsth->execute(); … … 5177 5183 } 5178 5184 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 5179 5192 $recsth->execute($domid); 5180 5193 while (my ($host,$type,$val,$dist,$weight,$port,$ttl,$recid,$loc,$stamp,$expires,$stampactive) = $recsth->fetchrow_array) { … … 5190 5203 } 5191 5204 5192 _printrec_tiny($zonefilehandle, 'n', \%recflags,5205 _printrec_tiny($zonefilehandle, $recid, 'n', \%recflags, 5193 5206 $dom, $host, $type, $val, $dist, $weight, $port, $ttl, $loc, $stamp, $expires, $stampactive); 5194 5207 … … 5239 5252 # Utility sub for __export_tiny above 5240 5253 sub _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) = @_; 5242 5256 5243 5257 $loc = '' if !$loc; # de-nullify - just in case
Note:
See TracChangeset
for help on using the changeset viewer.