Changeset 468


Ignore:
Timestamp:
03/12/13 13:39:49 (12 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
Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/dns-rpc.cgi

    r460 r468  
    3939#package main;
    4040
    41 DNSDB::loadConfig(rpcflag => 1);
    42 
    43 # need to create a DNSDB object too
    44 my ($dbh,$msg) = DNSDB::connectDB($DNSDB::config{dbname}, $DNSDB::config{dbuser},
    45         $DNSDB::config{dbpass}, $DNSDB::config{dbhost});
    46 
    47 DNSDB::initGlobals($dbh);
     41my $dnsdb = DNSDB->new();
    4842
    4943my $methods = {
     
    8074
    8175# "Can't do that" errors
    82 if (!$dbh) {
     76if (!$dnsdb) {
    8377  print "Content-type: text/xml\n\n".$res->{_decode}->encode_fault(5, $msg);
    8478  exit;
  • 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
  • trunk/export.pl

    r262 r468  
    2525use lib '.';    ##uselib##
    2626
    27 use DNSDB qw(:ALL);
     27use DNSDB;
    2828
    29 loadConfig();
     29my $dnsdb = new DNSDB;
    3030
    3131open TINYDATA, ">tinydata";
    3232
    33 my ($dbh,$msg) = connectDB($config{dbname}, $config{dbuser}, $config{dbpass}, $config{dbhost});
    34 initGlobals($dbh);
    35 
    3633export($dbh,'tiny',*TINYDATA);
  • trunk/textrecs.cgi

    r440 r468  
    3131use lib '.';    ##uselib##
    3232
    33 use DNSDB qw(:ALL);
     33use DNSDB;
    3434
    3535# Let's do these templates right...
     
    4848$webvar{revrec} = 'n' if !$webvar{revrec};      # non-reverse (domain) records
    4949
    50 # load some local system defaults (mainly DB connect info)
    51 # note this is not *absolutely* fatal, since there's a default dbname/user/pass in DNSDB.pm
    52 # we'll catch a bad DB connect string once we get to trying that
    53 ##fixme:  pass params to loadConfig, and use them there, to allow one codebase to support multiple sites
    54 if (!loadConfig()) {
    55   warn "Using default configuration;  unable to load custom settings: $DNSDB::errstr";
    56 }
     50my $dnsdb = new DNSDB;
    5751
    5852# Check the session and if we have a zone ID to retrieve.  Call a failure sub if not.
    5953my $sid = ($webvar{sid} ? $webvar{sid} : undef);
    60 my $session = new CGI::Session("driver:File", $sid, {Directory => $config{sessiondir}})
     54my $session = new CGI::Session("driver:File", $sid, {Directory => $dnsdb->{sessiondir}})
    6155        or die CGI::Session->errstr();
    6256do_not_pass_go() if !$sid;
    6357do_not_pass_go() if !$webvar{id};
    64 
    65 ##fixme: quit throwing the database handle around, and put all the SQL and direct DB fiddling into DNSDB.pm
    66 # dbname, user, pass, host (optional)
    67 my ($dbh,$msg) = connectDB($config{dbname}, $config{dbuser}, $config{dbpass}, $config{dbhost});
    68 # Load config pieces from the database.  Ideally all but the DB user/pass/etc should be loaded here.
    69 initGlobals($dbh);
    7058
    7159my $zone;
  • trunk/tiny-import.pl

    r461 r468  
    2727
    2828use lib '.';
    29 use DNSDB qw(:ALL);
    30 
    31 if (!loadConfig()) {
    32   warn "Using default configuration;  unable to load custom settings: $DNSDB::errstr";
    33 }
     29use DNSDB;
     30
     31my $dnsdb = new DNSDB;
    3432
    3533usage() if !@ARGV;
     
    7775
    7876my $code;
    79 my ($dbh,$msg) = connectDB($config{dbname}, $config{dbuser}, $config{dbpass}, $config{dbhost});
    80 initGlobals($dbh) if $dbh;
     77my $dbh = $dnsdb->{dbh};
    8178
    8279$dbh->{AutoCommit} = 0;
     
    251248    my $nodefer = shift || 0;
    252249    my $impok = 1;
     250    my $msg;
    253251
    254252    $errstr = $rec;  # this way at least we have some idea what went <splat>
     
    269267      $loc = '' if !$loc;
    270268      $loc = '' if $loc =~ /^:+$/;
    271       my $fparent = DNSDB::_hostparent($dbh, $host);
     269      my $fparent = $dnsdb->_hostparent($host);
    272270      my ($rparent) = $dbh->selectrow_array("SELECT rdns_id FROM revzones WHERE revnet >> ?", undef, ($ip));
    273271      if ($fparent && $rparent) {
     
    308306
    309307      } else {
    310         my $fparent = DNSDB::_hostparent($dbh, $host);
     308        my $fparent = $dnsdb->_hostparent($host);
    311309        if ($fparent) {
    312310          $recsth->execute($fparent, 0, $host, 5, $targ, 0, 0, 0, $ttl, $loc);
     
    344342        }
    345343      } else {
    346         my $fparent = DNSDB::_hostparent($dbh, $zone);
     344        my $fparent = $dnsdb->_hostparent($zone);
    347345        if ($fparent) {
    348346          $recsth->execute($fparent, 0, $zone, 2, $ns, 0, 0, 0, $ttl, $loc);
     
    396394      $loc = '' if $loc =~ /^:+$/;
    397395
    398       my $domid = DNSDB::_hostparent($dbh, $host);
     396      my $domid = $dnsdb->_hostparent($host);
    399397      if ($domid) {
    400398        $recsth->execute($domid, 0, $host, 1, $ip, 0, 0, 0, $ttl, $loc);
     
    447445
    448446      # allow for subzone MXes, since it's perfectly legitimate to simply stuff it all in a single parent zone
    449       my $domid = DNSDB::_hostparent($dbh, $zone);
     447      my $domid = $dnsdb->_hostparent($zone);
    450448      if ($domid) {
    451449        $recsth->execute($domid, 0, $zone, 15, $host, $dist, 0, 0, $ttl, $loc);
     
    473471        $recsth->execute(0, $rparent, $rdata, 16, "$msg", 0, 0, 0, $ttl, $loc);
    474472      } else {
    475         my $domid = DNSDB::_hostparent($dbh, $fqdn);
     473        my $domid = $dnsdb->_hostparent($fqdn);
    476474        if ($domid) {
    477475          $recsth->execute($domid, 0, $fqdn, 16, $rdata, 0, 0, 0, $ttl, $loc);
     
    588586#  }
    589587
    590         my $domid = DNSDB::_hostparent($dbh, $fqdn);
     588        my $domid = $dnsdb->_hostparent($fqdn);
    591589        if ($domid) {
    592590          $recsth->execute($domid, 0, $fqdn, 33, $target, $prio, $weight, $port, $ttl, $loc) if $domid;
     
    606604        my $val = NetAddr::IP->new(join(':', @v6));
    607605
    608         my $fparent = DNSDB::_hostparent($dbh, $fqdn);
     606        my $fparent = $dnsdb->_hostparent($fqdn);
    609607        if ($fparent) {
    610608          $recsth->execute($fparent, 0, $fqdn, 28, $val->addr, 0, 0, 0, $ttl, $loc);
     
    628626          }
    629627        } else {
    630           my $domid = DNSDB::_hostparent($dbh, $fqdn);
     628          my $domid = $dnsdb->_hostparent($fqdn);
    631629          if ($domid) {
    632630            $recsth->execute($domid, 0, $fqdn, 16, $txtstring, 0, 0, 0, $ttl, $loc);
     
    656654          }
    657655        } else {
    658           my $domid = DNSDB::_hostparent($dbh, $fqdn);
     656          my $domid = $dnsdb->_hostparent($fqdn);
    659657          if ($domid) {
    660658            $recsth->execute($domid, 0, $fqdn, 17, "$email $txtrec", 0, 0, 0, $ttl, $loc);
     
    672670
    673671        # these do not make sense in a reverse zone, since they're logically attached to an A record
    674         my $domid = DNSDB::_hostparent($dbh, $fqdn);
     672        my $domid = $dnsdb->_hostparent($fqdn);
    675673        if ($domid) {
    676674          $recsth->execute($domid, 0, $fqdn, 44, $sshfp, 0, 0, 0, $ttl, $loc);
  • trunk/vega-import.pl

    r320 r468  
    2929use Data::Dumper;
    3030
    31 use DNSDB qw(:ALL);
    32 
    33 if (!loadConfig()) {
    34   warn "Using default configuration;  unable to load custom settings: $DNSDB::errstr";
    35 }
     31use DNSDB;
     32
     33my $dnsdb = new DNSDB;
    3634
    3735my $mode = 'add';
     
    4543$mode = $ARGV[0] if $ARGV[0];
    4644
    47 my ($newdbh,$msg) = connectDB($config{dbname}, $config{dbuser}, $config{dbpass}, $config{dbhost});
     45my $newdbh = $dnsdb->{dbh};
    4846$newdbh->{PrintError} = 1;
    4947$newdbh->{PrintWarn} = 1;
    50 initGlobals($newdbh);
    5148
    5249my %vegatypes = ('S' => 'SOA', 'N' => 'NS', 'A' => 'A', 'T' => 'TXT',
Note: See TracChangeset for help on using the changeset viewer.