Index: trunk/DNSDB.pm
===================================================================
--- trunk/DNSDB.pm	(revision 123)
+++ trunk/DNSDB.pm	(revision 128)
@@ -28,5 +28,5 @@
 	&initPermissions &getPermissions &changePermissions &comparePermissions
 	&changeGroup
-	&connectDB &finish
+	&loadConfig &connectDB &finish
 	&addDomain &delDomain &domainName &domainID
 	&addGroup &delGroup &getChildren &groupName
@@ -38,5 +38,5 @@
 	&domStatus &importAXFR
 	&export
-	%typemap %reverse_typemap
+	%typemap %reverse_typemap %config
 	%permissions @permtypes $permlist
 	);
@@ -47,5 +47,5 @@
 		&initPermissions &getPermissions &changePermissions &comparePermissions
 		&changeGroup
-		&connectDB &finish
+		&loadConfig &connectDB &finish
 		&addDomain &delDomain &domainName &domainID
 		&addGroup &delGroup &getChildren &groupName
@@ -57,5 +57,5 @@
 		&domStatus &importAXFR
 		&export
-		%typemap %reverse_typemap
+		%typemap %reverse_typemap %config
 		%permissions @permtypes $permlist
 		)]
@@ -97,7 +97,102 @@
 our %permissions;
 
+# Prepopulate a basic config.  Note some of these *will* cause errors if left unset.
+our %config = (
+		# Database connection info
+		dbname	=> 'dnsdb',
+		dbuser	=> 'dnsdb',
+		dbpass	=> 'secret',
+		dbhost	=> '',
+
+		# Email notice settings
+		mailhost	=> 'smtp.example.com',
+		mailsender	=> 'dnsdb@example.com',
+		mailname	=> 'DNS Administration',
+
+		# Template directory
+		templatedir	=> 'templates/',
+# fmeh.  this is a real web path, not a logical internal one.  hm..
+#		cssdir	=> 'templates/';
+	);
+
+
 ##
 ## Initialization and cleanup subs
 ##
+
+
+## DNSDB::loadConfig()
+# Load the minimum required initial state (DB connect info) from a config file
+# Load misc other bits while we're at it.
+# Takes an optional basename and config path to look for
+# Populates the %config and %def hashes
+sub loadConfig {
+  my $basename = shift || '';	# this will work OK
+
+  my $deferr = '';	# place to put error from default config file in case we can't find either one
+
+  my $configroot = '/etc/dnsdb';
+  $configroot = '' if $basename =~ m|^/|;
+  $basename .= ".conf" if $basename !~ /\.conf$/;
+  my $defconfig = "$configroot/dnsdb.conf";
+  my $siteconfig = "$configroot/$basename";
+
+  # System defaults
+  __cfgload("$configroot/dnsdb.conf") or $deferr = $errstr;
+
+  # Per-site-ish settings
+  unless (__cfgload("$configroot/$basename")) {
+    $errstr = ($deferr ? "Error opening default config file $defconfig: $deferr\n" : '').
+	"Error opening site config file $siteconfig";
+    return;
+  }
+
+  # All good, clear the error and go home.
+  $errstr = '';
+  return 1;
+} # end loadConfig()
+
+
+## DNSDB::__cfgload()
+# Private sub to parse a config file and load it into %config
+# Takes a file handle on an open config file
+sub __cfgload {
+  $errstr = '';
+  my $cfgfile = shift;
+  if (open CFG, "<$cfgfile") {
+#  my $mode = '';
+    while (<CFG>) {
+      chomp;
+      s/^\s*//;
+      next if /^#/;
+      next if /^$/;
+# hmm.  more complex bits in this file might require [heading] headers, maybe?
+#    $mode = $1 if /^\[(a-z)+]/;
+    # DB connect info
+      $config{dbname}	= $1 if /^dbname\s*=\s*([a-z0-9_.-]+)/i;
+      $config{dbuser}	= $1 if /^dbuser\s*=\s*([a-z0-9_.-]+)/i;
+      $config{dbpass}	= $1 if /^dbpass\s*=\s*([a-z0-9_.-]+)/i;
+      $config{dbhost}	= $1 if /^dbhost\s*=\s*([a-z0-9_.-]+)/i;
+      # SOA defaults
+      $def{contact}	= $1 if /^contact\s*=\s*([a-z0-9_.-]+)/i;
+      $def{prins}	= $1 if /^prins\s*=\s*([a-z0-9_.-]+)/i;
+      $def{soattl}	= $1 if /^soattl\s*=\s*([a-z0-9_.-]+)/i;
+      $def{refresh}	= $1 if /^refresh\s*=\s*([a-z0-9_.-]+)/i;
+      $def{retry}	= $1 if /^retry\s*=\s*([a-z0-9_.-]+)/i;
+      $def{expire}	= $1 if /^expire\s*=\s*([a-z0-9_.-]+)/i;
+      $def{minttl}	= $1 if /^minttl\s*=\s*([a-z0-9_.-]+)/i;
+      $def{ttl}		= $1 if /^ttl\s*=\s*([a-z0-9_.-]+)/i;
+      # Mail settings
+      $config{mailhost}		= $1 if /^mailhost\s*=\s*([a-z0-9_.-]+)/i;
+      $config{mailsender}	= $1 if /^mailsender\s*=\s*([a-z0-9_.@-]+)/i;
+      $config{mailname}		= $1 if /^mailname\s*=\s*([a-z0-9\s_.-]+)/i;
+    }
+    close CFG;
+  } else {
+    $errstr = $!;
+    return;
+  }
+  return 1;
+} # end __cfgload()
 
 
