Changeset 517


Ignore:
Timestamp:
05/31/13 17:23:13 (11 years ago)
Author:
Kris Deugau
Message:

/trunk

Review, clean up, and refiddle configuration handling:

  • Drop %config hash as a global, and replace it with a local hash in new(), for much more elegant per-object configuration handling
  • Replace references to %config with $self->
  • Remove obsolete loadConfig() sub; new() can call the lightly revised cfgload() directly
  • Revise cfgload() to accept a hashref to put the parsed configuration entries in
  • Clean up example config file, including new rpc_iplist and max_fcgi_requests options

Plus a few miscellaneous extra bits of cleanup:

  • Remove obsolete, never-used %def hash.
  • Only try to disconnect the database handle in DESTROY if it was active in the first place
Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/DNSDB.pm

    r516 r517  
    4040        &getPermissions &changePermissions &comparePermissions
    4141        &changeGroup
    42         &loadConfig &connectDB &finish
     42        &connectDB &finish
    4343        &addDomain &delZone &domainName &revName &domainID &revID &addRDNS
    4444        &getZoneCount &getZoneList &getZoneLocation
     
    5959        &export
    6060        &mailNotify
    61         %typemap %reverse_typemap %config
     61        %typemap %reverse_typemap
    6262        @permtypes $permlist %permchains
    6363        );
     
    6868                &getPermissions &changePermissions &comparePermissions
    6969                &changeGroup
    70                 &loadConfig &connectDB &finish
     70                &connectDB &finish
    7171                &addDomain &delZone &domainName &revName &domainID &revID &addRDNS
    7272                &getZoneCount &getZoneList &getZoneLocation
     
    8787                &export
    8888                &mailNotify
    89                 %typemap %reverse_typemap %config
     89                %typemap %reverse_typemap
    9090                @permtypes $permlist %permchains
    9191                )]
     
    9494our $errstr = '';
    9595our $resultstr = '';
    96 
    97 # Halfway sane defaults for SOA, TTL, etc.
    98 # serial defaults to 0 for convenience.
    99 # value will be either YYYYMMDDNN for BIND/etc, or auto-internal for tinydns
    100 our %def = qw (
    101         contact hostmaster.DOMAIN
    102         prins   ns1.myserver.com
    103         serial  0
    104         soattl  86400
    105         refresh 10800
    106         retry   3600
    107         expire  604800
    108         minttl  10800
    109         ttl     10800
    110 );
    11196
    11297# Arguably defined wholly in the db, but little reason to change without supporting code changes
     
    135120our %typemap;
    136121our %reverse_typemap;
    137 
    138 # Prepopulate a basic config.  Note some of these *will* cause errors if left unset.
    139 # note:  add appropriate stanzas in loadConfig to parse these
    140 our %config = (
    141                 # Database connection info
    142                 dbname  => 'dnsdb',
    143                 dbuser  => 'dnsdb',
    144                 dbpass  => 'secret',
    145                 dbhost  => '',
    146 
    147                 # Email notice settings
    148                 mailhost        => 'smtp.example.com',
    149                 mailnotify      => 'dnsdb@example.com', # to
    150                 mailsender      => 'dnsdb@example.com', # from
    151                 mailname        => 'DNS Administration',
    152                 orgname         => 'Example Corp',
    153                 domain          => 'example.com',
    154 
    155                 # Template directory
    156                 templatedir     => 'templates/',
    157 # fmeh.  this is a real web path, not a logical internal one.  hm..
    158 #               cssdir  => 'templates/',
    159                 sessiondir      => 'session/',
    160                 exportcache     => 'cache/',
    161 
    162                 # Session params
    163                 timeout         => '3600',      # 1 hour default
    164 
    165                 # Other miscellanea
    166                 log_failures    => 1,   # log all evarthing by default
    167                 perpage         => 15,
    168                 maxfcgi         => 100, # reasonable default?
    169         );
    170122
    171123## (Semi)private variables
     
    221173  my $class = ref($this) || $this;
    222174  my %args = @_;
    223 ##fixme?  to ponder:  do we do some magic if the caller sets eg dbname to prevent parsing of the config file?
    224   if (!loadConfig(basename => $args{configfile})) {
    225     warn "Using default configuration;  unable to load custom settings: $errstr\n";
    226   }
    227   my $self = \%config;
    228   $self->{configfile} = $args{configfile};
     175
     176  # Prepopulate a basic config.  Note some of these *will* cause errors if left unset.
     177  # note:  add appropriate stanzas in __cfgload() to parse these
     178  my %defconfig = (
     179                # The only configuration option not loadable from a config file.
     180                configfile => '/etc/dnsdb/dnsdb.conf',
     181
     182                # Database connection info
     183                dbname  => 'dnsdb',
     184                dbuser  => 'dnsdb',
     185                dbpass  => 'secret',
     186                dbhost  => '',
     187
     188                # Email notice settings
     189                mailhost        => 'smtp.example.com',
     190                mailnotify      => 'dnsdb@example.com', # to
     191                mailsender      => 'dnsdb@example.com', # from
     192                mailname        => 'DNS Administration',
     193                orgname         => 'Example Corp',
     194                domain          => 'example.com',
     195
     196                # Template directory
     197                templatedir     => 'templates/',
     198# fmeh.  this is a real web path, not a logical internal one.  hm..
     199#               cssdir  => 'templates/',
     200                sessiondir      => 'session/',
     201                exportcache     => 'cache/',
     202
     203                # Session params
     204                timeout         => '1h',        # passed as-is to CGI::Session
     205
     206                # Other miscellanea
     207                log_failures    => 1,   # log all evarthing by default
     208                perpage         => 15,
     209                max_fcgi_requests => 100,       # reasonable default?
     210        );
     211
     212  # Config file parse calls.
     213  # If we are passed a blank argument for $args{configfile},
     214  #   we should NOT parse the default config file - we will
     215  #   rely on hardcoded defaults OR caller-specified values.
     216  # If we are passed a non-blank argument, parse that file.
     217  # If no config file is specified, parse the default one.
     218  my %siteconfig;
     219  if (defined($args{configfile})) {
     220    if ($args{configfile}) {
     221      return if !__cfgload($args{configfile}, \%siteconfig);
     222    }
     223  } else {
     224    return if !__cfgload($defconfig{configfile}, \%siteconfig);
     225  }
     226
     227  # Assemble the object.  Apply configuration hashes in order of precedence.
     228  my $self = {
     229        # Hardcoded defaults
     230        %defconfig,
     231        # Default config file OR caller-specified one, loaded above
     232        %siteconfig,
     233        # Caller-specified arguments
     234        %args
     235        };
    229236  bless $self, $class;
     237
     238  # Try to connect to the DB, and initialize a number of handy globals.
    230239  $self->{dbh} = connectDB($self->{dbname}, $self->{dbuser}, $self->{dbpass}, $self->{dbhost}) or return;
    231240  $self->initGlobals();
     
    236245sub DESTROY {
    237246  my $self = shift;
    238   $self->{dbh}->disconnect;
     247  $self->{dbh}->disconnect if $self->{dbh};
    239248}
    240249
     
    372381
    373382##fixme:  farm out the actual logging to different subs for file, syslog, internal, etc based on config
    374 #  if ($config{log_channel} eq 'sql') {
     383#  if ($self->{log_channel} eq 'sql') {
    375384  $dbh->do("INSERT INTO log (domain_id,rdns_id,group_id,entry,user_id,email,name) VALUES (?,?,?,?,?,?,?)",
    376385        undef,
    377386        ($args{domain_id}, $args{rdns_id}, $args{group_id}, $args{entry},
    378387                $self->{loguserid}, $self->{logusername}, $self->{logfullname}) );
    379 #  } elsif ($config{log_channel} eq 'file') {
    380 #  } elsif ($config{log_channel} eq 'syslog') {
     388#  } elsif ($self->{log_channel} eq 'file') {
     389#  } elsif ($self->{log_channel} eq 'syslog') {
    381390#  }
    382391} # end _log
     
    528537        ${$args{val}} = "ZONE,${$args{val}}" unless ${$args{val}} =~ /^ZONE/;
    529538      }
    530       ${$args{host}} =~ s/\.*$/\.$config{domain}/ if ${$args{host}} !~ /(?:$config{domain}|ADMINDOMAIN)$/;
     539      ${$args{host}} =~ s/\.*$/\.$self->{domain}/ if ${$args{host}} !~ /(?:$self->{domain}|ADMINDOMAIN)$/;
    531540    }
    532541
     
    12391248##
    12401249
    1241 ## DNSDB::loadConfig()
    1242 # Load the minimum required initial state (DB connect info) from a config file
    1243 # Load misc other bits while we're at it.
    1244 # Takes an optional hash that may contain:
    1245 #  - basename and config path to look for
    1246 # Populates the %config and %def hashes
    1247 sub loadConfig {
    1248   my %args = @_;
    1249   $args{configfile} = '' if !$args{configfile};
    1250 
    1251 ##fixme  this is *intended* to load a system-default config template, and allow
    1252 # overriding on a per-tool or per-web-UI-instance basis with a secondary config
    1253 # file.  The "default" config file can't be deleted in the current form.
    1254 
    1255   my $deferr = '';      # place to put error from default config file in case we can't find either one
    1256 
    1257   my $configroot = "/etc/dnsdb";        ##CFG_LEAF##
    1258   $configroot = '' if $args{configfile} =~ m|^/|;  # allow passed siteconfig to specify an arbitrary absolute path
    1259   $args{configfile} .= ".conf" if $args{configfile} !~ /\.conf$/;
    1260   my $defconfig = "$configroot/dnsdb.conf";
    1261   my $siteconfig = "$configroot/$args{configfile}";
    1262 
    1263   # System defaults
    1264   __cfgload("$defconfig") or $deferr = $errstr;
    1265 
    1266   # Per-site-ish settings.
    1267   if ($args{configfile} ne '.conf') {
    1268     unless (__cfgload("$siteconfig")) {
    1269       $errstr = ($deferr ? "Error opening default config file $defconfig: $deferr\n" : '').
    1270         "Error opening site config file $siteconfig";
    1271       return;
    1272     }
    1273   }
    1274 
    1275   # Munge log_failures.
    1276   if ($config{log_failures} ne '1' && $config{log_failures} ne '0') {
    1277     # true/false, on/off, yes/no all valid.
    1278     if ($config{log_failures} =~ /^(?:true|false|on|off|yes|no)$/) {
    1279       if ($config{log_failures} =~ /(?:true|on|yes)/) {
    1280         $config{log_failures} = 1;
    1281       } else {
    1282         $config{log_failures} = 0;
    1283       }
    1284     } else {
    1285       $errstr = "Bad log_failures setting $config{log_failures}";
    1286       $config{log_failures} = 1;
    1287       # Bad setting shouldn't be fatal.
    1288       # return 2;
    1289     }
    1290   }
    1291 
    1292   # All good, clear the error and go home.
    1293   $errstr = '';
    1294   return 1;
    1295 } # end loadConfig()
    1296 
    1297 
    12981250## DNSDB::__cfgload()
    12991251# Private sub to parse a config file and load it into %config
    1300 # Takes a filename
     1252# Takes a filename and a hashref to put the parsed entries in
    13011253sub __cfgload {
    13021254  $errstr = '';
    13031255  my $cfgfile = shift;
     1256  my $cfg = shift;
    13041257
    13051258  if (open CFG, "<$cfgfile") {
     
    13121265#    $mode = $1 if /^\[(a-z)+]/;
    13131266    # DB connect info
    1314       $config{dbname}   = $1 if /^dbname\s*=\s*([a-z0-9_.-]+)/i;
    1315       $config{dbuser}   = $1 if /^dbuser\s*=\s*([a-z0-9_.-]+)/i;
    1316       $config{dbpass}   = $1 if /^dbpass\s*=\s*([a-z0-9_.-]+)/i;
    1317       $config{dbhost}   = $1 if /^dbhost\s*=\s*([a-z0-9_.-]+)/i;
    1318       # SOA defaults
    1319       $def{contact}     = $1 if /^contact\s*=\s*([a-z0-9_.-]+)/i;
    1320       $def{prins}       = $1 if /^prins\s*=\s*([a-z0-9_.-]+)/i;
    1321       $def{soattl}      = $1 if /^soattl\s*=\s*(\d+)/i;
    1322       $def{refresh}     = $1 if /^refresh\s*=\s*(\d+)/i;
    1323       $def{retry}       = $1 if /^retry\s*=\s*(\d+)/i;
    1324       $def{expire}      = $1 if /^expire\s*=\s*(\d+)/i;
    1325       $def{minttl}      = $1 if /^minttl\s*=\s*(\d+)/i;
    1326       $def{ttl}         = $1 if /^ttl\s*=\s*(\d+)/i;
     1267      $cfg->{dbname}    = $1 if /^dbname\s*=\s*([a-z0-9_.-]+)/i;
     1268      $cfg->{dbuser}    = $1 if /^dbuser\s*=\s*([a-z0-9_.-]+)/i;
     1269      $cfg->{dbpass}    = $1 if /^dbpass\s*=\s*([a-z0-9_.-]+)/i;
     1270      $cfg->{dbhost}    = $1 if /^dbhost\s*=\s*([a-z0-9_.-]+)/i;
    13271271      # Mail settings
    1328       $config{mailhost}         = $1 if /^mailhost\s*=\s*([a-z0-9_.-]+)/i;
    1329       $config{mailnotify}       = $1 if /^mailnotify\s*=\s*([a-z0-9_.\@-]+)/i;
    1330       $config{mailsender}       = $1 if /^mailsender\s*=\s*([a-z0-9_.\@-]+)/i;
    1331       $config{mailname}         = $1 if /^mailname\s*=\s*([a-z0-9\s_.-]+)/i;
    1332       $config{orgname}          = $1 if /^orgname\s*=\s*([a-z0-9\s_.,'-]+)/i;
    1333       $config{domain}           = $1 if /^domain\s*=\s*([a-z0-9_.-]+)/i;
     1272      $cfg->{mailhost}          = $1 if /^mailhost\s*=\s*([a-z0-9_.-]+)/i;
     1273      $cfg->{mailnotify}        = $1 if /^mailnotify\s*=\s*([a-z0-9_.\@-]+)/i;
     1274      $cfg->{mailsender}        = $1 if /^mailsender\s*=\s*([a-z0-9_.\@-]+)/i;
     1275      $cfg->{mailname}          = $1 if /^mailname\s*=\s*([a-z0-9\s_.-]+)/i;
     1276      $cfg->{orgname}           = $1 if /^orgname\s*=\s*([a-z0-9\s_.,'-]+)/i;
     1277      $cfg->{domain}            = $1 if /^domain\s*=\s*([a-z0-9_.-]+)/i;
    13341278      # session - note this is fed directly to CGI::Session
    1335       $config{timeout}          = $1 if /^[tT][iI][mM][eE][oO][uU][tT]\s*=\s*(\d+[smhdwMy]?)/;
    1336       $config{sessiondir}       = $1 if m{^sessiondir\s*=\s*([a-z0-9/_.-]+)}i;
     1279      $cfg->{timeout}           = $1 if /^[tT][iI][mM][eE][oO][uU][tT]\s*=\s*(\d+[smhdwMy]?)/;
     1280      $cfg->{sessiondir}        = $1 if m{^sessiondir\s*=\s*([a-z0-9/_.-]+)}i;
    13371281      # misc
    1338       $config{log_failures}     = $1 if /^log_failures\s*=\s*([a-z01]+)/i;
    1339       $config{perpage}          = $1 if /^perpage\s*=\s*(\d+)/i;
    1340       $config{exportcache}      = $1 if m{^exportcache\s*=\s*([a-z0-9/_.-]+)}i;
     1282      $cfg->{log_failures}      = $1 if /^log_failures\s*=\s*([a-z01]+)/i;
     1283      $cfg->{perpage}           = $1 if /^perpage\s*=\s*(\d+)/i;
     1284      $cfg->{exportcache}       = $1 if m{^exportcache\s*=\s*([a-z0-9/_.-]+)}i;
     1285# not supported in dns.cgi yet
     1286#      $cfg->{templatedir}      = $1 if m{^templatedir\s*=\s*([a-z0-9/_.-]+)}i;
     1287#      $cfg->{templateoverride} = $1 if m{^templateoverride\s*=\s*([a-z0-9/_.-]+)}i;
    13411288      # RPC options
    1342       $config{rpcmode}          = $1 if /^rpc_mode\s*=\s*(socket|HTTP|XMLRPC)\s*$/i;
    1343       $config{maxfcgi}          = $1 if /^max_fcgi_requests\s*=\s*(\d+)\s*$/i;
     1289      $cfg->{rpcmode}           = $1 if /^rpc_mode\s*=\s*(socket|HTTP|XMLRPC)\s*$/i;
     1290      $cfg->{maxfcgi}           = $1 if /^max_fcgi_requests\s*=\s*(\d+)\s*$/i;
    13441291      if (my ($tmp) = /^rpc_iplist\s*=\s*(.+)/i) {
    13451292        my @ips = split /[,\s]+/, $tmp;
    13461293        my $rpcsys = shift @ips;
    1347         push @{$config{rpcacl}{$rpcsys}}, @ips;
     1294        push @{$cfg->{rpcacl}{$rpcsys}}, @ips;
    13481295      }
    13491296    }
    13501297    close CFG;
    13511298  } else {
    1352     $errstr = $!;
     1299    $errstr = "Couldn't load configuration file $cfgfile: $!";
    13531300    return;
    13541301  }
     
    15331480# about having to open a file or a syslog channel
    15341481##fixme Need to call _initActionLog_blah() for various logging channels, configured
    1535 # via dnsdb.conf, in $config{log_channel} or something
     1482# via dnsdb.conf, in $self->{log_channel} or something
    15361483# See https://secure.deepnet.cx/trac/dnsadmin/ticket/21
    15371484sub initActionLog {
     
    15541501
    15551502  # convert to real check once we have other logging channels
    1556   # if ($config{log_channel} eq 'sql') {
     1503  # if ($self->{log_channel} eq 'sql') {
    15571504  #   Open Log, Sez Me!
    15581505  # }
     
    17811728    my $msg = $@;
    17821729    eval { $dbh->rollback; };
    1783     if ($config{log_failures}) {
     1730    if ($self->{log_failures}) {
    17841731      $self->_log(group_id => $oldgid, entry => "Error moving $type $entname to $newgname: $msg");
    17851732      $dbh->commit;     # since we enabled transactions earlier
     
    18811828    eval { $dbh->rollback; };
    18821829    $self->_log(group_id => $group, entry => "Failed adding domain $domain ($msg)")
    1883         if $config{log_failures};
     1830        if $self->{log_failures};
    18841831    $dbh->commit;       # since we enabled transactions earlier
    18851832    return ('FAIL',$msg);
     
    19121859  return ('FAIL', ($revrec eq 'n' ? 'Domain' : 'Reverse zone')." ID $zoneid doesn't exist") if !$zone;
    19131860
    1914   # Set this up here since we may use if if $config{log_failures} is enabled
     1861  # Set this up here since we may use if if $self->{log_failures} is enabled
    19151862  my %loghash;
    19161863  $loghash{domain_id} = $zoneid if $revrec eq 'n';
     
    19601907    eval { $dbh->rollback; };
    19611908    $loghash{entry} = "Error deleting $zone: $msg ($failmsg)";
    1962     if ($config{log_failures}) {
     1909    if ($self->{log_failures}) {
    19631910      $self->_log(%loghash);
    19641911      $dbh->commit;     # since we enabled transactions earlier
     
    21052052      }
    21062053
    2107       $host =~ s/ADMINDOMAIN/$config{domain}/g;
     2054      $host =~ s/ADMINDOMAIN/$self->{domain}/g;
    21082055
    21092056      # Check to make sure the IP stubs will fit in the zone.  Under most usage failures here should be rare.
     
    21992146    eval { $dbh->rollback; };
    22002147    $self->_log(group_id => $group, entry => "Failed adding reverse zone $zone ($msg)")
    2201         if $config{log_failures};
     2148        if $self->{log_failures};
    22022149    $dbh->commit;       # since we enabled transactions earlier
    22032150    return ('FAIL',$msg);
     
    23152262  # A common tail.
    23162263  $sql .= " ORDER BY ".($args{sortby} eq 'group' ? 'groups.group_name' : $args{sortby})." $args{sortorder} ".
    2317         ($args{offset} eq 'all' ? '' : " LIMIT $config{perpage}".
    2318         " OFFSET ".$args{offset}*$config{perpage});
     2264        ($args{offset} eq 'all' ? '' : " LIMIT $self->{perpage}".
     2265        " OFFSET ".$args{offset}*$self->{perpage});
    23192266  my $sth = $dbh->prepare($sql);
    23202267  $sth->execute(@filterargs);
     
    24422389    my $msg = $@;
    24432390    eval { $dbh->rollback; };
    2444     if ($config{log_failures}) {
     2391    if ($self->{log_failures}) {
    24452392      $self->_log(group_id => $pargroup, entry => "Failed to add group $groupname: $msg");
    24462393      $dbh->commit;
     
    25082455    my $msg = $@;
    25092456    eval { $dbh->rollback; };
    2510     if ($config{log_failures}) {
     2457    if ($self->{log_failures}) {
    25112458      $self->_log(group_id => $parid, entry => "$failmsg: $msg");
    25122459      $dbh->commit;     # since we enabled transactions earlier
     
    26552602        " GROUP BY g.group_id, g.group_name, g2.group_name ".
    26562603        " ORDER BY $args{sortby} $args{sortorder} ".
    2657         ($args{offset} eq 'all' ? '' : " LIMIT $config{perpage} OFFSET ".$args{offset}*$config{perpage});
     2604        ($args{offset} eq 'all' ? '' : " LIMIT $self->{perpage} OFFSET ".$args{offset}*$self->{perpage});
    26582605  my $glist = $dbh->selectall_arrayref($sql, { Slice => {} }, (@filterargs) );
    26592606  $errstr = $dbh->errstr if !$glist;
     
    28102757    my $msg = $@;
    28112758    eval { $dbh->rollback; };
    2812     if ($config{log_failures}) {
     2759    if ($self->{log_failures}) {
    28132760      $self->_log(group_id => $group, entry => "Error adding user $username: $msg");
    28142761      $dbh->commit;     # since we enabled transactions earlier
     
    29052852        " AND NOT u.type = 'R' ".
    29062853        " ORDER BY $args{sortby} $args{sortorder} ".
    2907         ($args{offset} eq 'all' ? '' : " LIMIT $config{perpage} OFFSET ".$args{offset}*$config{perpage});
     2854        ($args{offset} eq 'all' ? '' : " LIMIT $self->{perpage} OFFSET ".$args{offset}*$self->{perpage});
    29082855  my $ulist = $dbh->selectall_arrayref($sql, { Slice => {} }, (@filterargs) );
    29092856  $errstr = $dbh->errstr if !$ulist;
     
    29882935    my $msg = $@;
    29892936    eval { $dbh->rollback; };
    2990     if ($config{log_failures}) {
     2937    if ($self->{log_failures}) {
    29912938      $self->_log(group_id => $group, entry => "Error updating user $username: $msg");
    29922939      $dbh->commit;     # since we enabled transactions earlier
     
    30272974    my $msg = $@;
    30282975    eval { $dbh->rollback; };
    3029     if ($config{log_failures}) {
     2976    if ($self->{log_failures}) {
    30302977      $self->_log(group_id => $userdata->{group_id}, entry => "Error deleting user ID ".
    30312978        "$userid/".$userdata->{username}.": $msg");
     
    32003147    my $msg = $@;
    32013148    eval { $dbh->rollback; };
    3202     if ($config{log_failures}) {
     3149    if ($self->{log_failures}) {
    32033150      $shdesc = $loc if !$shdesc;
    32043151      $self->_log(entry => "Failed adding location ($shdesc, '$iplist'): $msg");
     
    32473194    my $msg = $@;
    32483195    eval { $dbh->rollback; };
    3249     if ($config{log_failures}) {
     3196    if ($self->{log_failures}) {
    32503197      $shdesc = $loc if !$shdesc;
    32513198      $self->_log(entry => "Failed updating location ($shdesc, '$iplist'): $msg");
     
    32863233    my $msg = $@;
    32873234    eval { $dbh->rollback; };
    3288     if ($config{log_failures}) {
     3235    if ($self->{log_failures}) {
    32893236      $self->_log(entry => "Failed to delete location ($olddesc, '$oldloc->{iplist}'): $msg");
    32903237      $dbh->commit;
     
    33903337        ($args{filter} ? " AND l.description ~* ?" : '').
    33913338        " ORDER BY $args{sortby} $args{sortorder} ".
    3392         ($args{offset} eq 'all' ? '' : " LIMIT $config{perpage} OFFSET ".$args{offset}*$config{perpage});
     3339        ($args{offset} eq 'all' ? '' : " LIMIT $self->{perpage} OFFSET ".$args{offset}*$self->{perpage});
    33933340  my $ulist = $dbh->selectall_arrayref($sql, { Slice => {} }, (@filterargs) );
    33943341  $errstr = $dbh->errstr if !$ulist;
     
    35103457    $logdata{entry} = "Error updating ".($defrec eq 'y' ? ($revrec eq 'y' ? 'default reverse zone ' : 'default ') : '').
    35113458        "SOA record for $parname: $msg";
    3512     if ($config{log_failures}) {
     3459    if ($self->{log_failures}) {
    35133460      $self->_log(%logdata);
    35143461      $dbh->commit;
     
    35893536  $args{sortby} = $defsort if $args{sortby} !~ /^[\w_,.]+$/;
    35903537  $args{offset} = 0 if !$args{offset} || $args{offset} !~ /^(?:all|\d+)$/; 
    3591   my $perpage = ($args{nrecs} ? $args{nrecs} : $config{perpage});
     3538  my $perpage = ($args{nrecs} ? $args{nrecs} : $self->{perpage});
    35923539
    35933540  # sort reverse zones on IP, correctly
     
    37783725    my $msg = $@;
    37793726    eval { $dbh->rollback; };
    3780     if ($config{log_failures}) {
     3727    if ($self->{log_failures}) {
    37813728      $logdata{entry} = "Failed adding ".($defrec eq 'y' ? 'default ' : '').
    37823729        "record '$$host $typemap{$$rectype} $$val', TTL $ttl ($msg)";
     
    39613908    my $msg = $@;
    39623909    eval { $dbh->rollback; };
    3963     if ($config{log_failures}) {
     3910    if ($self->{log_failures}) {
    39643911      $logdata{entry} = "Failed updating ".($defrec eq 'y' ? 'default ' : '').
    39653912        "record '$oldrec->{host} $typemap{$oldrec->{type}} $oldrec->{val}', TTL $oldrec->{ttl} ($msg)";
     
    40724019    my $msg = $@;
    40734020    eval { $dbh->rollback; };
    4074     if ($config{log_failures}) {
     4021    if ($self->{log_failures}) {
    40754022      $logdata{entry} = "Error deleting ".($defrec eq 'y' ? 'default record' : 'record').
    40764023        " '$oldrec->{host} $typemap{$oldrec->{type}} $oldrec->{val}', TTL $oldrec->{ttl} ($msg)";
     
    41554102        ($args{filter} ? " AND entry ~* ?" : '').
    41564103        " ORDER BY $args{sortby} $args{sortorder}, log_id $args{sortorder}".
    4157         ($args{offset} eq 'all' ? '' : " LIMIT $config{perpage} OFFSET ".$args{offset}*$config{perpage});
     4104        ($args{offset} eq 'all' ? '' : " LIMIT $self->{perpage} OFFSET ".$args{offset}*$self->{perpage});
    41584105  my $loglist = $dbh->selectall_arrayref($sql, { Slice => {} }, ($args{id}, @filterargs) );
    41594106  $errstr = $dbh->errstr if !$loglist;
     
    49484895#              still be followed.
    49494896# but that doesn't help other platforms.  :/
    4950     sysopen(ZONECACHE, "$config{exportcache}/$dom", O_RDWR|O_CREAT);
     4897    sysopen(ZONECACHE, "$self->{exportcache}/$dom", O_RDWR|O_CREAT);
    49514898    flock(ZONECACHE, LOCK_EX);
    4952     if ($changed || -s "$config{exportcache}/$dom" == 0) {
     4899    if ($changed || -s "$self->{exportcache}/$dom" == 0) {
    49534900      $recsth->execute($domid);
    49544901      while (my ($host,$type,$val,$dist,$weight,$port,$ttl,$recid,$loc) = $recsth->fetchrow_array) {
     
    50264973# but that doesn't help other platforms.  :/
    50274974    my $tmpzone = NetAddr::IP->new($revzone);
    5028     sysopen(ZONECACHE, "$config{exportcache}/".$tmpzone->network->addr, O_RDWR|O_CREAT);
     4975    sysopen(ZONECACHE, "$self->{exportcache}/".$tmpzone->network->addr, O_RDWR|O_CREAT);
    50294976    flock(ZONECACHE, LOCK_EX);
    5030     if ($changed || -s "$config{exportcache}/".$tmpzone->network->addr == 0) {
     4977    if ($changed || -s "$self->{exportcache}/".$tmpzone->network->addr == 0) {
    50314978      # need to fetch this separately since the rest of the records all (should) have real IPs in val
    50324979      $soasth->execute($revid);
     
    54045351  my ($subj,$message) = @_;
    54055352
    5406   return if $config{mailhost} eq 'smtp.example.com';   # do nothing if still using default SMTP host.
    5407 
    5408   my $mailer = Net::SMTP->new($config{mailhost}, Hello => "dnsadmin.$config{domain}");
    5409 
    5410   my $mailsender = ($config{mailsender} ? $config{mailsender} : $config{mailnotify});
     5353  return if $self->{mailhost} eq 'smtp.example.com';   # do nothing if still using default SMTP host.
     5354
     5355  my $mailer = Net::SMTP->new($self->{mailhost}, Hello => "dnsadmin.$self->{domain}");
     5356
     5357  my $mailsender = ($self->{mailsender} ? $self->{mailsender} : $self->{mailnotify});
    54115358
    54125359  $mailer->mail($mailsender);
    5413   $mailer->to($config{mailnotify});
    5414   $mailer->data("From: \"$config{mailname}\" <$mailsender>\n",
    5415         "To: <$config{mailnotify}>\n",
     5360  $mailer->to($self->{mailnotify});
     5361  $mailer->data("From: \"$self->{mailname}\" <$mailsender>\n",
     5362        "To: <$self->{mailnotify}>\n",
    54165363        "Date: ".strftime("%a, %d %b %Y %H:%M:%S %z",localtime)."\n",
    54175364        "Subject: $subj\n",
    54185365        "X-Mailer: DNSAdmin Notify v".sprintf("%.1d",$DNSDB::VERSION)."\n",
    5419         "Organization: $config{orgname}\n",
     5366        "Organization: $self->{orgname}\n",
    54205367        "\n$message\n");
    54215368  $mailer->quit;
  • trunk/dnsdb.conf

    r216 r517  
    22
    33# Database connection info
    4 #dbname=dsndb
    5 #dbuser=dnsdb
    6 #dbpass=dnsdbpwd
    7 #dbhost=dnsdbhost
     4#dbname = dsndb
     5#dbuser = dnsdb
     6#dbpass = dnsdbpwd
     7#dbhost = dnsdbhost
    88
    9 # SOA defaults.  contact and prins may only contain a-z, 0-9, . and -,
    10 # the rest are expected to be numeric.
    11 #contact=hostmaster.example.com
    12 #prins=ns1.example.com
    13 #soattl=7200
    14 #refresh=86400
    15 #retry=14400
    16 #expire=28800
    17 #minttl=900
    18 #ttl=900
    19      
    209# Mail settings
    21 #mailhost=smtp.example.com
    22 #mailnotify=dns@example.com
    23 #mailsender=hostmaster@example.com
    24 #mailname=Example Corp DNS Administrator
    25 #orgname=Example Corp
    26 #domain=example.com
     10#mailhost = smtp.example.com
     11#mailnotify = dns@example.com
     12#mailsender = hostmaster@example.com
     13#mailname = Example Corp DNS Administrator
     14#orgname = Example Corp
     15#domain = example.com
    2716     
    2817# session - note this is fed directly to CGI::Session
    2918# timeout supports (s)econds, (m)inutes, (h)ours, (d)ays, (w)eeks, (M)months, or (y)ears
    30 #timeout=3h
    31 #sessiondir=/var/lib/dnsdb
     19#timeout = 3h
     20#sessiondir = /var/lib/dnsdb
    3221
    33 # misc
     22## misc
     23
    3424# flag to indicate if failed changes should be logged
    35 #log_failures=0
     25#log_failures = 1
    3626# number of entries to display in lists
    37 #perpage=25
     27#perpage = 25
     28# maximum number of FCGI requests to serve before reloading/restarting FCGI
     29#max_fcgi_requests = 10
     30# path for per-zone cache files for export
     31#exportcache = /var/cache/dnsdb
     32
     33# RPC ACL
     34# A comma-separated list starting with an abstract "system name"
     35# (passed by an RPC caller), followed by a list of IP addresses
     36# allowed to make RPC calls with that name.
     37# Finer-grained access control must be handled by the caller.
     38#rpc_iplist = billing, 192.168.0.11
     39#rpc_iplist = billing, 172.12.12.12
     40#rpc_iplist = custportal, 192.168.1.12, 192.168.1.13
Note: See TracChangeset for help on using the changeset viewer.