Changeset 559 for trunk


Ignore:
Timestamp:
12/17/13 16:33:13 (11 years ago)
Author:
Kris Deugau
Message:

/trunk

Post-release nuisance rollup

  • Forgot to move "use Digest::MD5" to DNSDB.pm, where it's actually needed
  • Minor UI polish for TTLs intended to use "automatic" TTL setting; instead of displaying the underlying -1, show "(auto)"
  • Remember to accept negative TTLs (could probably check for things other than -1, if being picky) to allow use of "automatic" TTLs. Note that tinydns' automatic TTL is.... one day.
  • After all that work developing a caching system to speed up exports, add a knob to turn it off... because it's now slower than just writing everything straight to a collected master file after all the *rest* of the export speed optimizations. (Even with full sets of template records.)
  • Include the dns-rpc.fcgi symlink in the tarball
  • Make sure we have the right name for maxfcgi in all the places it's used. Also update the example dnsdb.conf with the couple of new options introduced recently.
Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/DNSDB.pm

    r543 r559  
    2727use Net::DNS;
    2828use Crypt::PasswdMD5;
     29use Digest::MD5 qw(md5_hex);
    2930use Net::SMTP;
    3031use NetAddr::IP 4.027 qw(:lower);
     
    201202                sessiondir      => 'session/',
    202203                exportcache     => 'cache/',
     204                usecache        => 1,   # do we bother using the cache above?
    203205
    204206                # Session params
     
    208210                log_failures    => 1,   # log all evarthing by default
    209211                perpage         => 15,
    210                 max_fcgi_requests => 100,       # reasonable default?
     212                maxfcgi         => 10,  # reasonable default?
    211213                force_refresh   => 1,
    212214                lowercase       => 0,   # mangle as little as possible by default
     
    13371339      $cfg->{perpage}           = $1 if /^perpage\s*=\s*(\d+)/i;
    13381340      $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;
    13391343      $cfg->{lowercase}         = $1 if /^lowercase\s*=\s*([a-z01]+)/i;
    13401344# not supported in dns.cgi yet
     
    13441348      $cfg->{rpcmode}           = $1 if /^rpc_mode\s*=\s*(socket|HTTP|XMLRPC)\s*$/i;
    13451349      $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;
    13471350      if (my ($tmp) = /^rpc_iplist\s*=\s*(.+)/i) {
    13481351        my @ips = split /[,\s]+/, $tmp;
     
    37313734
    37323735  # do simple validation first
    3733   return ('FAIL', "TTL must be numeric") unless $ttl =~ /^\d+$/;
     3736  return ('FAIL', "TTL must be numeric") unless $ttl =~ /^-?\d+$/;
    37343737
    37353738  # Quick check on hostname parts.  There are enough variations to justify a sub now.
     
    38953898
    38963899  # do simple validation first
    3897   return ('FAIL', "TTL must be numeric") unless $ttl =~ /^\d+$/;
     3900  return ('FAIL', "TTL must be numeric") unless $ttl =~ /^-?\d+$/;
    38983901
    38993902  # Quick check on hostname parts.  There are enough variations to justify a sub now.
     
    49494952  my $dbh = $self->{dbh};
    49504953  my $datafile = shift;
     4954  my $zonefilehandle = $datafile;       # makes cache/no-cache a little simpler
    49514955
    49524956##fixme: slurp up further options to specify particular zone(s) to export
     
    50365040    eval {
    50375041
    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        }
    50415053
    50425054        # need to fetch this separately since the rest of the records all (should) have real IPs in val
    50435055        $soasth->execute($revid);
    50445056        my (@zsoa) = $soasth->fetchrow_array();
    5045         _printrec_tiny(*ZONECACHE,'y',\%recflags,$revzone,
     5057        _printrec_tiny($zonefilehandle,'y',\%recflags,$revzone,
    50465058          $zsoa[0],$zsoa[1],$zsoa[2],$zsoa[3],$zsoa[4],$zsoa[5],$zsoa[6],$zsoa[8],'');
    50475059
     
    50605072#         }
    50615073
    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);
    50655076
    50665077          $recflags{$recid} = 1;
     
    50685079        } # while ($recsth)
    50695080
    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          }
    50765088        }
    50775089
     
    50885100      $zonesth->execute($revid);
    50895101    }
    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    }
    50945110
    50955111  } # while ($revsth)
     
    51125128    eval {
    51135129
    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        }
    51175141
    51185142        $recsth->execute($domid);
     
    51295153          }
    51305154
    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);
    51345157
    51355158          $recflags{$recid} = 1;
     
    51375160        } # while ($recsth)
    51385161
    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          }
    51455170        }
    51465171
     
    51575182      $zonesth->execute($domid);
    51585183    }
    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    }
    51635192
    51645193  } # while ($domsth)
  • trunk/Makefile

    r549 r559  
    6868
    6969SCRIPTS = \
    70         compact-recs.pl dns.cgi dns-rpc.cgi export.pl textrecs.cgi tiny-import.pl vega-import.pl
     70        compact-recs.pl dns.cgi dns-rpc.cgi dns-rpc.fcgi export.pl textrecs.cgi tiny-import.pl vega-import.pl
    7171
    7272MODULES = DNSDB.pm
  • trunk/dns.cgi

    r553 r559  
    2626use HTML::Template;
    2727use CGI::Session;
    28 use Crypt::PasswdMD5;
    29 use Digest::MD5 qw(md5_hex);
    3028use Net::DNS;
    3129use DBI;
     
    20082006    $rec->{type} = $typemap{$rec->{type}};
    20092007    $rec->{fwdzone} = $rev eq 'n';
     2008    $rec->{ttl} = '(auto)' if $rec->{ttl} == -1;
    20102009    $rec->{distance} = 'n/a' unless ($rec->{type} eq 'MX' || $rec->{type} eq 'SRV');
    20112010    $rec->{weight} = 'n/a' unless ($rec->{type} eq 'SRV');
  • trunk/dnsdb.conf

    r525 r559  
    2626# number of entries to display in lists
    2727#perpage = 25
    28 # maximum number of FCGI requests to serve before reloading/restarting FCGI
    29 #max_fcgi_requests = 10
    3028# path for per-zone cache files for export
    3129#exportcache = /var/cache/dnsdb
     
    3634#force_refresh = 1
    3735
    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
    3948# A comma-separated list starting with an abstract "system name"
    4049# (passed by an RPC caller), followed by a list of IP addresses
Note: See TracChangeset for help on using the changeset viewer.