Changeset 468 for trunk/dns.cgi


Ignore:
Timestamp:
03/12/13 13:39:49 (11 years ago)
Author:
Kris Deugau
Message:

/trunk

Object conversion of DNSDB.pm, 4 of <mumble>. See #11.

  • Convert initialization of bundled callers to object calls
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/dns.cgi

    r458 r468  
    4545use lib '.';    ##uselib##
    4646
    47 use DNSDB qw(:ALL);
     47use DNSDB;
    4848
    4949my @debugbits;  # temp, to be spit out near the end of processing
     
    6969# we'll catch a bad DB connect string once we get to trying that
    7070##fixme:  pass params to loadConfig, and use them there, to allow one codebase to support multiple sites
    71 if (!loadConfig()) {
    72   warn "Using default configuration;  unable to load custom settings: $DNSDB::errstr";
     71my $dnsdb = new DNSDB;
     72
     73my $header = HTML::Template->new(filename => "$templatedir/header.tmpl");
     74my $footer = HTML::Template->new(filename => "$templatedir/footer.tmpl");
     75$footer->param(version => $DNSDB::VERSION);
     76
     77if (!$dnsdb) {
     78  print "Content-type: text/html\n\n";
     79  print $header->output;
     80  my $errpage = HTML::Template->new(filename => "$templatedir/dberr.tmpl");
     81  $errpage->param(errmsg => $DNSDB::errstr);
     82  print $errpage->output;
     83  print $footer->output;
     84  exit;
    7385}
     86
     87$header->param(orgname => $dnsdb->{orgname}) if $dnsdb->{orgname} ne 'Example Corp';
    7488
    7589# persistent stuff needed on most/all pages
    7690my $sid = ($webvar{sid} ? $webvar{sid} : undef);
    77 my $session = new CGI::Session("driver:File", $sid, {Directory => $config{sessiondir}})
     91my $session = new CGI::Session("driver:File", $sid, {Directory => $dnsdb->{sessiondir}})
    7892        or die CGI::Session->errstr();
    7993#$sid = $session->id() if !$sid;
     
    8195  # init stuff.  can probably axe this down to just above if'n'when user manipulation happens
    8296  $sid = $session->id();
    83   $session->expire($config{timeout});
     97  $session->expire($dnsdb->{timeout});
    8498# need to know the "upper" group the user can deal with;  may as well
    8599# stick this in the session rather than calling out to the DB every time.
     
    149163push @filterargs, $filter if $filter;
    150164
    151 # nrgh, can't handle login here because we don't have a database handle to check the user/pass with yet
    152 
    153 my $header = HTML::Template->new(filename => "$templatedir/header.tmpl");
    154 my $footer = HTML::Template->new(filename => "$templatedir/footer.tmpl");
    155 $header->param(orgname => $config{orgname}) if $config{orgname} ne 'Example Corp';
    156 $footer->param(version => $DNSDB::VERSION);
    157 
    158165## set up "URL to self"
    159166# @#$%@%@#% XHTML - & in a URL must be escaped.  >:(
     
    179186# pagination
    180187my $perpage = 15;
    181 $perpage = $config{perpage} if $config{perpage};
     188$perpage = $dnsdb->{perpage} if $dnsdb->{perpage};
    182189my $offset = ($webvar{offset} ? $webvar{offset} : 0);
    183190
     
    186193my $sortorder = "ASC";
    187194
    188 ##fixme: quit throwing the database handle around, and put all the SQL and direct DB fiddling into DNSDB.pm
    189 # dbname, user, pass, host (optional)
    190 my ($dbh,$msg) = connectDB($config{dbname}, $config{dbuser}, $config{dbpass}, $config{dbhost});
    191 
    192 if (!$dbh) {
    193   print "Content-type: text/html\n\n";
    194   print $header->output;
    195   my $errpage = HTML::Template->new(filename => "$templatedir/dberr.tmpl");
    196   $errpage->param(errmsg => $msg);
    197   print $errpage->output;
    198   print $footer->output;
    199   exit;
    200 }
    201 
    202 # Load config pieces from the database.  Ideally all but the DB user/pass/etc should be loaded here.
    203 initGlobals($dbh);
    204 
    205195# security check - does the user have permission to view this entity?
    206196# this is a prep step used "many" places
    207197my @viewablegroups;
    208 getChildren($dbh, $logingroup, \@viewablegroups, 'all');
     198$dnsdb->getChildren($logingroup, \@viewablegroups, 'all');
    209199push @viewablegroups, $logingroup;
    210200
     
    232222    # Snag ACL/permissions here too
    233223
    234     my $userdata = login($dbh, $webvar{username}, $webvar{password});
     224    my $userdata = $dnsdb->login($webvar{username}, $webvar{password});
    235225
    236226    if ($userdata) {
     
    293283# but if they keep the session active they'll continue to have access long after being disabled.  :/
    294284# Treat it as a session expiry.
    295 if ($session->param('uid') && !userStatus($dbh, $session->param('uid')) ) {
     285if ($session->param('uid') && !$dnsdb->userStatus($session->param('uid')) ) {
    296286  $sid = '';
    297287  $session->delete;     # force expiry of the session Right Away
     
    301291
    302292# Misc Things To Do on most pages
    303 initPermissions($dbh, $session->param('uid'));
    304 initActionLog($dbh, $session->param('uid'));
     293$dnsdb->initPermissions($session->param('uid'));
     294$dnsdb->initActionLog($session->param('uid'));
    305295
    306296$page->param(sid => $sid) unless $webvar{page} eq 'login';      # no session ID on the login page
Note: See TracChangeset for help on using the changeset viewer.