Index: trunk/dns.cgi
===================================================================
--- trunk/dns.cgi	(revision 458)
+++ trunk/dns.cgi	(revision 468)
@@ -45,5 +45,5 @@
 use lib '.';	##uselib##
 
-use DNSDB qw(:ALL);
+use DNSDB;
 
 my @debugbits;  # temp, to be spit out near the end of processing
@@ -69,11 +69,25 @@
 # we'll catch a bad DB connect string once we get to trying that
 ##fixme:  pass params to loadConfig, and use them there, to allow one codebase to support multiple sites
-if (!loadConfig()) {
-  warn "Using default configuration;  unable to load custom settings: $DNSDB::errstr";
+my $dnsdb = new DNSDB;
+
+my $header = HTML::Template->new(filename => "$templatedir/header.tmpl");
+my $footer = HTML::Template->new(filename => "$templatedir/footer.tmpl");
+$footer->param(version => $DNSDB::VERSION);
+
+if (!$dnsdb) {
+  print "Content-type: text/html\n\n";
+  print $header->output;
+  my $errpage = HTML::Template->new(filename => "$templatedir/dberr.tmpl");
+  $errpage->param(errmsg => $DNSDB::errstr);
+  print $errpage->output;
+  print $footer->output;
+  exit;
 }
+
+$header->param(orgname => $dnsdb->{orgname}) if $dnsdb->{orgname} ne 'Example Corp';
 
 # persistent stuff needed on most/all pages
 my $sid = ($webvar{sid} ? $webvar{sid} : undef);
-my $session = new CGI::Session("driver:File", $sid, {Directory => $config{sessiondir}})
+my $session = new CGI::Session("driver:File", $sid, {Directory => $dnsdb->{sessiondir}})
 	or die CGI::Session->errstr();
 #$sid = $session->id() if !$sid;
@@ -81,5 +95,5 @@
   # init stuff.  can probably axe this down to just above if'n'when user manipulation happens
   $sid = $session->id();
-  $session->expire($config{timeout});
+  $session->expire($dnsdb->{timeout});
 # need to know the "upper" group the user can deal with;  may as well
 # stick this in the session rather than calling out to the DB every time.
@@ -149,11 +163,4 @@
 push @filterargs, $filter if $filter;
 
-# nrgh, can't handle login here because we don't have a database handle to check the user/pass with yet
-
-my $header = HTML::Template->new(filename => "$templatedir/header.tmpl");
-my $footer = HTML::Template->new(filename => "$templatedir/footer.tmpl");
-$header->param(orgname => $config{orgname}) if $config{orgname} ne 'Example Corp';
-$footer->param(version => $DNSDB::VERSION);
-
 ## set up "URL to self"
 # @#$%@%@#% XHTML - & in a URL must be escaped.  >:(
@@ -179,5 +186,5 @@
 # pagination
 my $perpage = 15;
-$perpage = $config{perpage} if $config{perpage};
+$perpage = $dnsdb->{perpage} if $dnsdb->{perpage};
 my $offset = ($webvar{offset} ? $webvar{offset} : 0);
 
@@ -186,25 +193,8 @@
 my $sortorder = "ASC";
 
-##fixme: quit throwing the database handle around, and put all the SQL and direct DB fiddling into DNSDB.pm
-# dbname, user, pass, host (optional)
-my ($dbh,$msg) = connectDB($config{dbname}, $config{dbuser}, $config{dbpass}, $config{dbhost});
-
-if (!$dbh) {
-  print "Content-type: text/html\n\n";
-  print $header->output;
-  my $errpage = HTML::Template->new(filename => "$templatedir/dberr.tmpl");
-  $errpage->param(errmsg => $msg);
-  print $errpage->output;
-  print $footer->output;
-  exit;
-}
-
-# Load config pieces from the database.  Ideally all but the DB user/pass/etc should be loaded here.
-initGlobals($dbh);
-
 # security check - does the user have permission to view this entity?
 # this is a prep step used "many" places
 my @viewablegroups;
-getChildren($dbh, $logingroup, \@viewablegroups, 'all');
+$dnsdb->getChildren($logingroup, \@viewablegroups, 'all');
 push @viewablegroups, $logingroup;
 
@@ -232,5 +222,5 @@
     # Snag ACL/permissions here too
 
-    my $userdata = login($dbh, $webvar{username}, $webvar{password});
+    my $userdata = $dnsdb->login($webvar{username}, $webvar{password});
 
     if ($userdata) {
@@ -293,5 +283,5 @@
 # but if they keep the session active they'll continue to have access long after being disabled.  :/
 # Treat it as a session expiry.
-if ($session->param('uid') && !userStatus($dbh, $session->param('uid')) ) {
+if ($session->param('uid') && !$dnsdb->userStatus($session->param('uid')) ) {
   $sid = '';
   $session->delete;	# force expiry of the session Right Away
@@ -301,6 +291,6 @@
 
 # Misc Things To Do on most pages
-initPermissions($dbh, $session->param('uid'));
-initActionLog($dbh, $session->param('uid'));
+$dnsdb->initPermissions($session->param('uid'));
+$dnsdb->initActionLog($session->param('uid'));
 
 $page->param(sid => $sid) unless $webvar{page} eq 'login';	# no session ID on the login page
