Changeset 559
Legend:
- Unmodified
- Added
- Removed
-
trunk/DNSDB.pm
r543 r559 27 27 use Net::DNS; 28 28 use Crypt::PasswdMD5; 29 use Digest::MD5 qw(md5_hex); 29 30 use Net::SMTP; 30 31 use NetAddr::IP 4.027 qw(:lower); … … 201 202 sessiondir => 'session/', 202 203 exportcache => 'cache/', 204 usecache => 1, # do we bother using the cache above? 203 205 204 206 # Session params … … 208 210 log_failures => 1, # log all evarthing by default 209 211 perpage => 15, 210 max _fcgi_requests => 100, # reasonable default?212 maxfcgi => 10, # reasonable default? 211 213 force_refresh => 1, 212 214 lowercase => 0, # mangle as little as possible by default … … 1337 1339 $cfg->{perpage} = $1 if /^perpage\s*=\s*(\d+)/i; 1338 1340 $cfg->{exportcache} = $1 if m{^exportcache\s*=\s*([a-z0-9/_.-]+)}i; 1341 $cfg->{usecache} = $1 if m{^usecache\s*=\s*([a-z01]+)}i; 1342 $cfg->{force_refresh} = $1 if /^force_refresh\s*=\s*([a-z01]+)/i; 1339 1343 $cfg->{lowercase} = $1 if /^lowercase\s*=\s*([a-z01]+)/i; 1340 1344 # not supported in dns.cgi yet … … 1344 1348 $cfg->{rpcmode} = $1 if /^rpc_mode\s*=\s*(socket|HTTP|XMLRPC)\s*$/i; 1345 1349 $cfg->{maxfcgi} = $1 if /^max_fcgi_requests\s*=\s*(\d+)\s*$/i; 1346 $cfg->{force_refresh} = $1 if /^force_refresh\s*=\s*([a-z01]+)/i;1347 1350 if (my ($tmp) = /^rpc_iplist\s*=\s*(.+)/i) { 1348 1351 my @ips = split /[,\s]+/, $tmp; … … 3731 3734 3732 3735 # do simple validation first 3733 return ('FAIL', "TTL must be numeric") unless $ttl =~ /^ \d+$/;3736 return ('FAIL', "TTL must be numeric") unless $ttl =~ /^-?\d+$/; 3734 3737 3735 3738 # Quick check on hostname parts. There are enough variations to justify a sub now. … … 3895 3898 3896 3899 # do simple validation first 3897 return ('FAIL', "TTL must be numeric") unless $ttl =~ /^ \d+$/;3900 return ('FAIL', "TTL must be numeric") unless $ttl =~ /^-?\d+$/; 3898 3901 3899 3902 # Quick check on hostname parts. There are enough variations to justify a sub now. … … 4949 4952 my $dbh = $self->{dbh}; 4950 4953 my $datafile = shift; 4954 my $zonefilehandle = $datafile; # makes cache/no-cache a little simpler 4951 4955 4952 4956 ##fixme: slurp up further options to specify particular zone(s) to export … … 5036 5040 eval { 5037 5041 5038 # only update the cache file if the zone has changed, or if the cache file has nothing in it. 5039 if ($self->{force_refresh} || $changed || !-e $cachefile || -z $cachefile) { 5040 open ZONECACHE, ">$tmpcache" or die "Error creating temporary file $tmpcache: $!\n"; 5042 # write fresh records if: 5043 # - we are not using the cache 5044 # - force_refresh is set 5045 # - the zone has changed 5046 # - the cache file does not exist 5047 # - the cache file is empty 5048 if (!$self->{usecache} || $self->{force_refresh} || $changed || !-e $cachefile || -z $cachefile) { 5049 if ($self->{usecache}) { 5050 open ZONECACHE, ">$tmpcache" or die "Error creating temporary file $tmpcache: $!\n"; 5051 $zonefilehandle = *ZONECACHE; 5052 } 5041 5053 5042 5054 # need to fetch this separately since the rest of the records all (should) have real IPs in val 5043 5055 $soasth->execute($revid); 5044 5056 my (@zsoa) = $soasth->fetchrow_array(); 5045 _printrec_tiny( *ZONECACHE,'y',\%recflags,$revzone,5057 _printrec_tiny($zonefilehandle,'y',\%recflags,$revzone, 5046 5058 $zsoa[0],$zsoa[1],$zsoa[2],$zsoa[3],$zsoa[4],$zsoa[5],$zsoa[6],$zsoa[8],''); 5047 5059 … … 5060 5072 # } 5061 5073 5062 _printrec_tiny(*ZONECACHE, 'y', \%recflags, $revzone, 5063 $host, $type, $val, $dist, $weight, $port, $ttl, $loc, $stamp, $expires, $stampactive) 5064 if *ZONECACHE; 5074 _printrec_tiny($zonefilehandle, 'y', \%recflags, $revzone, 5075 $host, $type, $val, $dist, $weight, $port, $ttl, $loc, $stamp, $expires, $stampactive); 5065 5076 5066 5077 $recflags{$recid} = 1; … … 5068 5079 } # while ($recsth) 5069 5080 5070 close ZONECACHE; # force the file to be written 5071 5072 # catch obvious write errors that leave an empty temp file 5073 if (-s $tmpcache) { 5074 rename $tmpcache, $cachefile 5075 or die "Error overwriting cache file $cachefile with temporary file: $!\n"; 5081 if ($self->{usecache}) { 5082 close ZONECACHE; # force the file to be written 5083 # catch obvious write errors that leave an empty temp file 5084 if (-s $tmpcache) { 5085 rename $tmpcache, $cachefile 5086 or die "Error overwriting cache file $cachefile with temporary file: $!\n"; 5087 } 5076 5088 } 5077 5089 … … 5088 5100 $zonesth->execute($revid); 5089 5101 } 5090 # Always stream the cache (even if stale or obsolete due to errors creating the new cache) 5091 open CACHE, "<$cachefile"; 5092 print $datafile $_ while <CACHE>; 5093 close CACHE; 5102 5103 if ($self->{usecache}) { 5104 # We've already made as sure as we can that a cached zone file is "good", 5105 # although possibly stale/obsolete due to errors creating a new one. 5106 open CACHE, "<$cachefile"; 5107 print $datafile $_ while <CACHE>; 5108 close CACHE; 5109 } 5094 5110 5095 5111 } # while ($revsth) … … 5112 5128 eval { 5113 5129 5114 # only update the cache file if the zone has changed, or if the cache file has nothing in it. 5115 if ($self->{force_refresh} || $changed || !-e $cachefile || -z $cachefile) { 5116 open ZONECACHE, ">$tmpcache" or die "Error creating temporary file $tmpcache: $!\n"; 5130 # write fresh records if: 5131 # - we are not using the cache 5132 # - force_refresh is set 5133 # - the zone has changed 5134 # - the cache file does not exist 5135 # - the cache file is empty 5136 if (!$self->{usecache} || $self->{force_refresh} || $changed || !-e $cachefile || -z $cachefile) { 5137 if ($self->{usecache}) { 5138 open ZONECACHE, ">$tmpcache" or die "Error creating temporary file $tmpcache: $!\n"; 5139 $zonefilehandle = *ZONECACHE; 5140 } 5117 5141 5118 5142 $recsth->execute($domid); … … 5129 5153 } 5130 5154 5131 _printrec_tiny(*ZONECACHE, 'n', \%recflags, 5132 $dom, $host, $type, $val, $dist, $weight, $port, $ttl, $loc, $stamp, $expires, $stampactive) 5133 if *ZONECACHE; 5155 _printrec_tiny($zonefilehandle, 'n', \%recflags, 5156 $dom, $host, $type, $val, $dist, $weight, $port, $ttl, $loc, $stamp, $expires, $stampactive); 5134 5157 5135 5158 $recflags{$recid} = 1; … … 5137 5160 } # while ($recsth) 5138 5161 5139 close ZONECACHE; # force the file to be written 5140 5141 # catch obvious write errors that leave an empty temp file 5142 if (-s $tmpcache) { 5143 rename $tmpcache, $cachefile 5144 or die "Error overwriting cache file $cachefile with temporary file: $!\n"; 5162 5163 if ($self->{usecache}) { 5164 close ZONECACHE; # force the file to be written 5165 # catch obvious write errors that leave an empty temp file 5166 if (-s $tmpcache) { 5167 rename $tmpcache, $cachefile 5168 or die "Error overwriting cache file $cachefile with temporary file: $!\n"; 5169 } 5145 5170 } 5146 5171 … … 5157 5182 $zonesth->execute($domid); 5158 5183 } 5159 # Always stream the cache (even if stale or obsolete due to errors creating the new cache) 5160 open CACHE, "<$cachefile"; 5161 print $datafile $_ while <CACHE>; 5162 close CACHE; 5184 5185 if ($self->{usecache}) { 5186 # We've already made as sure as we can that a cached zone file is "good", 5187 # although possibly stale/obsolete due to errors creating a new one. 5188 open CACHE, "<$cachefile"; 5189 print $datafile $_ while <CACHE>; 5190 close CACHE; 5191 } 5163 5192 5164 5193 } # while ($domsth) -
trunk/Makefile
r549 r559 68 68 69 69 SCRIPTS = \ 70 compact-recs.pl dns.cgi dns-rpc.cgi export.pl textrecs.cgi tiny-import.pl vega-import.pl70 compact-recs.pl dns.cgi dns-rpc.cgi dns-rpc.fcgi export.pl textrecs.cgi tiny-import.pl vega-import.pl 71 71 72 72 MODULES = DNSDB.pm -
trunk/dns.cgi
r553 r559 26 26 use HTML::Template; 27 27 use CGI::Session; 28 use Crypt::PasswdMD5;29 use Digest::MD5 qw(md5_hex);30 28 use Net::DNS; 31 29 use DBI; … … 2008 2006 $rec->{type} = $typemap{$rec->{type}}; 2009 2007 $rec->{fwdzone} = $rev eq 'n'; 2008 $rec->{ttl} = '(auto)' if $rec->{ttl} == -1; 2010 2009 $rec->{distance} = 'n/a' unless ($rec->{type} eq 'MX' || $rec->{type} eq 'SRV'); 2011 2010 $rec->{weight} = 'n/a' unless ($rec->{type} eq 'SRV'); -
trunk/dnsdb.conf
r525 r559 26 26 # number of entries to display in lists 27 27 #perpage = 25 28 # maximum number of FCGI requests to serve before reloading/restarting FCGI29 #max_fcgi_requests = 1030 28 # path for per-zone cache files for export 31 29 #exportcache = /var/cache/dnsdb … … 36 34 #force_refresh = 1 37 35 38 # RPC ACL 36 # fold domain names and hostnames to lowercase? 37 # strictly speaking, DNS is case-insensitive, but some people insist on Capital Letters anyway. 38 #lowercase = 0 39 40 ## General RPC options 41 # may already be obsolete. how do we want to run RPC requests? 42 # bare socket, plain HTTP, or standard XMLRPC? 43 #rpcmode = http 44 # maximum number of FCGI requests to serve before reloading/restarting FCGI 45 #maxfcgi = 10 46 47 ## RPC ACL 39 48 # A comma-separated list starting with an abstract "system name" 40 49 # (passed by an RPC caller), followed by a list of IP addresses
Note:
See TracChangeset
for help on using the changeset viewer.