- Timestamp:
- 01/02/14 13:26:38 (11 years ago)
- Location:
- branches/stable
- Files:
-
- 9 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 -
branches/stable/dns.cgi
r562 r582 275 275 # and reconstruct the URI argument list. 276 276 my %target = (page => "domlist"); 277 if ($webvar{target} && $webvar{target} =~ /\?/ ) {277 if ($webvar{target} && $webvar{target} =~ /\?/ && $webvar{target} !~ /page=login/) { 278 278 my $tmp = (split /\?/, $webvar{target})[1]; 279 279 $tmp =~ s/^\&//; … … 2004 2004 2005 2005 foreach my $rec (@$foo2) { 2006 # NS records. Need to do this first before we convert the type-value to the text representation 2007 if ($rev eq 'y' && $dnsdb->{showrec_arpa_ns} && $rec->{type} == $reverse_typemap{NS}) { 2008 my $tmp = new NetAddr::IP $rec->{val}; 2009 $rec->{val} = DNSDB::_ZONE($tmp, 'ZONE', 'r', '.').($tmp->{isv6} ? '.ip6.arpa' : '.in-addr.arpa'); 2010 } 2006 2011 $rec->{type} = $typemap{$rec->{type}}; 2007 2012 $rec->{fwdzone} = $rev eq 'n'; -
branches/stable/dnsdb.conf
r562 r582 38 38 #lowercase = 0 39 39 40 # Show formal .arpa zone name instead of usual CIDR for reverse zone NS records? 41 #showrec_arpa_ns = 0 42 40 43 ## General RPC options 41 44 # may already be obsolete. how do we want to run RPC requests? -
branches/stable/export.pl
r548 r582 29 29 my $dnsdb = new DNSDB; 30 30 31 #open TINYDATA, ">small/tinydata"; 31 32 open TINYDATA, ">tinydata"; 32 33 33 $dnsdb->export('tiny', *TINYDATA) ;34 $dnsdb->export('tiny', *TINYDATA) or die "fatal: ".$dnsdb->errstr."\n"; -
branches/stable/templates/bulkdomain.tmpl
r548 r582 38 38 <table> 39 39 <tr> 40 <TMPL_LOOP NAME=domtable><td><input type="checkbox" name="dom_<TMPL_VAR NAME= domain_id>" value="<TMPL_VAR NAME=domain_id>" /> <TMPL_VAR NAME=domain></td>40 <TMPL_LOOP NAME=domtable><td><input type="checkbox" name="dom_<TMPL_VAR NAME=zoneid>" value="<TMPL_VAR NAME=zoneid>" /> <TMPL_VAR NAME=zone></td> 41 41 <TMPL_IF newrow></tr> 42 42 <tr> -
branches/stable/templates/domlist.tmpl
r548 r582 39 39 <TMPL_LOOP name=domtable> 40 40 <tr class="row<TMPL_IF __odd__>0<TMPL_ELSE>1</TMPL_IF>"> 41 <td align="left"><a href="<TMPL_VAR NAME=script_self>&page=reclist&id=<TMPL_VAR NAME=domain_id>&defrec=n<TMPL_UNLESS domlist>&revrec=y</TMPL_UNLESS>"><TMPL_VAR NAME=domain></a></td>41 <td align="left"><a href="<TMPL_VAR NAME=script_self>&page=reclist&id=<TMPL_VAR NAME=zoneid>&defrec=n<TMPL_UNLESS domlist>&revrec=y</TMPL_UNLESS>"><TMPL_VAR NAME=zone></a></td> 42 42 <td><TMPL_IF status>Active<TMPL_ELSE>Inactive</TMPL_IF></td> 43 43 <td><TMPL_VAR name=group></td> 44 <TMPL_IF domain_edit> <td align="center"><a href="<TMPL_VAR NAME=script_self>&page=<TMPL_VAR NAME=curpage><TMPL_IF NAME=offset>&offset=<TMPL_VAR NAME=offset></TMPL_IF>&id=<TMPL_VAR NAME= domainid>&zonestatus=<TMPL_IF status>domoff<TMPL_ELSE>domon</TMPL_IF>"><TMPL_IF status>deactivate<TMPL_ELSE>activate</TMPL_IF></a></td></TMPL_IF>45 <TMPL_IF domain_delete> <td align="center"><a href="<TMPL_VAR NAME=script_self>&page=<TMPL_IF domlist>deldom<TMPL_ELSE>delrevzone</TMPL_IF>&id=<TMPL_VAR NAME= domain_id>"><img src="images/trash2.png" alt="[ Delete ]" /></a></td></TMPL_IF>44 <TMPL_IF domain_edit> <td align="center"><a href="<TMPL_VAR NAME=script_self>&page=<TMPL_VAR NAME=curpage><TMPL_IF NAME=offset>&offset=<TMPL_VAR NAME=offset></TMPL_IF>&id=<TMPL_VAR NAME=zoneid>&zonestatus=<TMPL_IF status>domoff<TMPL_ELSE>domon</TMPL_IF>"><TMPL_IF status>deactivate<TMPL_ELSE>activate</TMPL_IF></a></td></TMPL_IF> 45 <TMPL_IF domain_delete> <td align="center"><a href="<TMPL_VAR NAME=script_self>&page=<TMPL_IF domlist>deldom<TMPL_ELSE>delrevzone</TMPL_IF>&id=<TMPL_VAR NAME=zoneid>"><img src="images/trash2.png" alt="[ Delete ]" /></a></td></TMPL_IF> 46 46 </tr> 47 47 </TMPL_LOOP> -
branches/stable/textrecs.cgi
r550 r582 75 75 76 76 my $reclist = $dnsdb->getRecList(defrec => $webvar{defrec}, revrec => $webvar{revrec}, id => $webvar{id}, 77 sortby => ($webvar{revrec} eq 'n' ? 'type,host' : 'type,val'), sortorder => 'ASC' );77 sortby => ($webvar{revrec} eq 'n' ? 'type,host' : 'type,val'), sortorder => 'ASC', offset => 'all'); 78 78 foreach my $rec (@$reclist) { 79 79 $rec->{type} = $typemap{$rec->{type}}; … … 83 83 $rec->{val} = "$rec->{distance} $rec->{weight} $rec->{port} $rec->{val}" if $rec->{type} eq 'SRV'; 84 84 if ($webvar{revrec} eq 'y') { 85 if ($dnsdb->{showrec_arpa_ns} && $rec->{type} eq 'NS') { 86 my $tmp = new NetAddr::IP $rec->{val}; 87 $rec->{val} = DNSDB::_ZONE($tmp, 'ZONE', 'r', '.').($tmp->{isv6} ? '.ip6.arpa' : '.in-addr.arpa'); 88 } 85 89 printf "%-16s\t%d\t%s\t%s\n", $rec->{val}, $rec->{ttl}, $rec->{type}, $rec->{host}; 86 90 } else { -
branches/stable/tiny-import.pl
r548 r582 39 39 conv => 0, 40 40 trial => 0, 41 legacy => 0, 41 legacy => 0, 42 merge => 0, 43 group => 1, 42 44 ); 45 my $gnum = ''; 43 46 # Handle some command-line arguments 44 47 while ($ARGV[0] =~ /^-/) { 45 48 my $arg = shift @ARGV; 46 usage() if $arg !~ /^- [rclt]+$/;49 usage() if $arg !~ /^-(?:[rclmt]+|g\d*)$/; 47 50 # -r rewrite imported files to comment imported records 48 51 # -c coerce/downconvert A+PTR = records to PTR 49 52 # -l swallow A+PTR as-is 53 # -m merge PTR and A/AAAA as possible 50 54 # -t trial mode; don't commit to DB or actually rewrite flatfile (disables -r) 55 # -g import to specified group (name or ID) instead of group 1 51 56 $arg =~ s/^-//; 52 my @tmp = split //, $arg; 53 foreach (@tmp) { 54 $importcfg{rw} = 1 if $_ eq 'r'; 55 $importcfg{conv} = 1 if $_ eq 'c'; 56 $importcfg{legacy} = 1 if $_ eq 'l'; 57 $importcfg{trial} = 1 if $_ eq 't'; 58 } 57 # for Reasons (none clear), $arg is undefined yet defined, but only when number characters are involved. Ebbeh? 58 no warnings qw(uninitialized); 59 if ($arg =~ /^g/) { 60 if ($arg eq 'g') { 61 $importcfg{group} = shift @ARGV; 62 } else { 63 $arg =~ s/^g//; 64 $importcfg{group} = $arg; 65 } 66 } else { 67 my @tmp = split //, $arg; 68 foreach (@tmp) { 69 $importcfg{rw} = 1 if $_ eq 'r'; 70 $importcfg{conv} = 1 if $_ eq 'c'; 71 $importcfg{legacy} = 1 if $_ eq 'l'; 72 $importcfg{merge} = 1 if $_ eq 'm'; 73 $importcfg{trial} = 1 if $_ eq 't'; 74 } 75 } 76 use warnings qw(uninitialized); 59 77 } 60 78 $importcfg{rw} = 0 if $importcfg{trial}; 61 79 80 # allow group names 81 if ($importcfg{group} =~ /^\d+$/) { 82 $importcfg{groupname} = $dnsdb->groupName($importcfg{group}); 83 } else { 84 $importcfg{groupname} = $importcfg{group}; 85 $importcfg{group} = $dnsdb->groupID($importcfg{groupname}); 86 } 87 88 die usage() if $importcfg{group} !~ /^\d+$/; 89 62 90 sub usage { 63 die q(usage: tiny-import.pl [-r ] [-c] datafile1 datafile2 ... datafileN ...91 die q(usage: tiny-import.pl [-rclt] [-gnn] [-g name] datafile1 datafile2 ... datafileN ... 64 92 -r Rewrite all specified data files with a warning header indicating the 65 93 records are now managed by web, and commenting out all imported records. … … 72 100 -l (for "legacy") Force import of A+PTR records as-is. Mutually exclusive 73 101 with -c. -l takes precedence as -c is lossy. 102 -m Merge PTR and A or AAAA records to A+PTR or AAAA+PTR records where possible 103 -gnnn or -g nnn or -g name 104 Import new zones into this group (group name or ID accepted) instead of 105 the root/default group 1 74 106 -t Trial run mode; spits out records that would be left unimported. 75 107 Disables -r if set. … … 83 115 my $code; 84 116 my $dbh = $dnsdb->{dbh}; 117 118 # collect some things for logging 119 ($dnsdb->{logusername}, undef, undef, undef, undef, undef, $dnsdb->{logfullname}) = getpwuid($<); 120 $dnsdb->{loguserid} = 0; # not worth setting up a pseudouser the way the RPC system does 121 $dnsdb->{logusername} = $dnsdb->{logusername}."/tiny-import.pl"; 122 $dnsdb->{logfullname} = $dnsdb->{logusername} if !$dnsdb->{logfullname}; 85 123 86 124 $dbh->{AutoCommit} = 0; … … 129 167 our $recsth = $dbh->prepare("INSERT INTO records (domain_id,rdns_id,host,type,val,distance,weight,port,ttl,location,stamp,expires,stampactive) ". 130 168 " VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)"); 169 170 # for A/AAAA records 171 our $revcheck = $dbh->prepare("SELECT rdns_id,record_id,ttl FROM records WHERE host=? AND val=? AND type=12"); 172 our $mergefwd = $dbh->prepare("UPDATE records SET type=?,domain_id=?,ttl=? WHERE record_id=?"); 173 # for PTR records 174 our $fwdcheck = $dbh->prepare("SELECT domain_id,record_id,ttl FROM records WHERE host=? AND val=? AND (type=1 OR type=28)"); 175 our $mergerev = $dbh->prepare("UPDATE records SET type=?,rdns_id=?,ttl=? WHERE record_id=?"); 131 176 132 177 my %deleg; … … 451 496 ($rparent) = $dbh->selectrow_array("SELECT rdns_id FROM revzones WHERE revnet >> ?", undef, ("$msg")); 452 497 } 498 453 499 if ($rparent) { 454 ($ttl, $stampactive, $expires, $stamp) = calcstamp($stamp, $ttl, $rparent, 'y'); 455 $recsth->execute(0, $rparent, $host, 12, $msg->addr, 0, 0, 0, $ttl, $loc, $stamp, $expires, $stampactive); 500 ##fixme: really want to pull this DB call inside an if $importcfg{merge}, 501 # but then we need to duplicate the insert for the case where the matching 502 # reverse doesn't exist. 503 $host =~ s/\.$//g; # pure sytactic sugar, we don't store this trailing dot. 504 $fwdcheck->execute($host, $msg->addr); 505 my ($domid, $recid, $rttl) = $fwdcheck->fetchrow_array; 506 if ($importcfg{merge} && $domid) { 507 $ttl = ($rttl < $ttl ? $rttl : $ttl); # Take the shorter TTL 508 $mergerev->execute(($msg->{isv6} ? 65281 : 65280), $rparent, $ttl, $recid); 509 $dnsdb->_log(rdns_id => $rparent, domain_id => $domid, group_id => $importcfg{group}, 510 entry => "[ import ] PTR ".$msg->addr." -> $host merged with matching ". 511 ($msg->{isv6} ? 'AAAA' : 'A')." record"); 512 } else { 513 ($ttl, $stampactive, $expires, $stamp) = calcstamp($stamp, $ttl, $rparent, 'y'); 514 $recsth->execute(0, $rparent, $host, 12, $msg->addr, 0, 0, 0, $ttl, $loc, $stamp, $expires, $stampactive); 515 } 456 516 } else { 457 517 push @deferred, $rec unless $nodefer; … … 476 536 my $domid = $dnsdb->_hostparent($host); 477 537 if ($domid) { 478 ($ttl, $stampactive, $expires, $stamp) = calcstamp($stamp, $ttl, $domid, 'n'); 479 $recsth->execute($domid, 0, $host, 1, $ip, 0, 0, 0, $ttl, $loc, $stamp, $expires, $stampactive); 538 ##fixme: really want to pull this DB call inside an if $importcfg{merge}, 539 # but then we need to duplicate the insert for the case where the matching 540 # reverse doesn't exist. 541 $revcheck->execute($host, $ip); 542 my ($revid, $recid, $rttl) = $revcheck->fetchrow_array; 543 if ($importcfg{merge} && $revid) { 544 $ttl = ($rttl < $ttl ? $rttl : $ttl); # Take the shorter TTL 545 $mergefwd->execute(65280, $domid, $ttl, $recid); 546 $dnsdb->_log(rdns_id => $revid, domain_id => $domid, group_id => $importcfg{group}, 547 entry => "[ import ] ".($msg->{isv6} ? 'AAAA' : 'A')." record $host -> $ip". 548 " merged with matching PTR record"); 549 } else { 550 ($ttl, $stampactive, $expires, $stamp) = calcstamp($stamp, $ttl, $domid, 'n'); 551 $recsth->execute($domid, 0, $host, 1, $ip, 0, 0, 0, $ttl, $loc, $stamp, $expires, $stampactive); 552 } 480 553 } else { 481 554 push @deferred, $rec unless $nodefer; … … 514 587 if ($zone =~ /\.arpa$/) { 515 588 ($code,$msg) = DNSDB::_zone2cidr($zone); 516 $dbh->do("INSERT INTO revzones (revnet,group_id,status,default_location) VALUES (?, 1,1,?)",517 undef, ($msg, $ loc));589 $dbh->do("INSERT INTO revzones (revnet,group_id,status,default_location) VALUES (?,?,1,?)", 590 undef, ($msg, $importcfg{group}, $loc)); 518 591 my ($rdns) = $dbh->selectrow_array("SELECT currval('revzones_rdns_id_seq')"); 519 592 my $newttl; … … 523 596 $loc, $stamp, $expires, $stampactive); 524 597 } else { 525 $dbh->do("INSERT INTO domains (domain,group_id,status,default_location) VALUES (?, 1,1,?)",526 undef, ($zone, $ loc));598 $dbh->do("INSERT INTO domains (domain,group_id,status,default_location) VALUES (?,?,1,?)", 599 undef, ($zone, $importcfg{group}, $loc)); 527 600 my ($domid) = $dbh->selectrow_array("SELECT currval('domains_domain_id_seq')"); 528 601 my $newttl; … … 748 821 my $fparent = $dnsdb->_hostparent($fqdn); 749 822 750 if ($fparent) { 751 ($ttl, $stampactive, $expires, $stamp) = calcstamp($stamp, $ttl, $fparent, 'n'); 752 $recsth->execute($fparent, 0, $fqdn, 28, $val->addr, 0, 0, 0, $ttl, $loc, $stamp, $expires, $stampactive); 753 } else { 754 push @deferred, $rec unless $nodefer; 755 $impok = 0; 756 } 823 ##fixme: really want to pull this DB call inside an if $importcfg{merge}, 824 # but then we need to duplicate the insert for the case where the matching 825 # reverse doesn't exist. 826 $revcheck->execute($fqdn, $val); 827 my ($revid, $recid, $rttl) = $revcheck->fetchrow_array; 828 829 # If we have a revzone and merging is enabled, update the existing 830 # record with a reverse ID, set the type to one of the internal 831 # pseudotypes, and set the TTL to the lower of the two. 832 if ($importcfg{merge} && $revid) { 833 $ttl = ($rttl < $ttl ? $rttl : $ttl); # Take the shorter TTL 834 $mergefwd->execute(65281, $fparent, $ttl, $recid); 835 $dnsdb->_log(rdns_id => $revid, domain_id => $fparent, group_id => $importcfg{group}, 836 entry => "[ import ] ".($msg->{isv6} ? 'AAAA' : 'A')." record $fqdn -> $val". 837 " merged with matching PTR record"); 838 } else { 839 if ($fparent) { 840 ($ttl, $stampactive, $expires, $stamp) = calcstamp($stamp, $ttl, $fparent, 'n'); 841 $recsth->execute($fparent, 0, $fqdn, 28, $val->addr, 0, 0, 0, $ttl, $loc, $stamp, $expires, $stampactive); 842 } else { 843 push @deferred, $rec unless $nodefer; 844 $impok = 0; 845 } 846 } 757 847 758 848 } elsif ($type == 16) {
Note:
See TracChangeset
for help on using the changeset viewer.