Changeset 468
- Timestamp:
- 03/12/13 13:39:49 (12 years ago)
- Location:
- trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/dns-rpc.cgi
r460 r468 39 39 #package main; 40 40 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); 41 my $dnsdb = DNSDB->new(); 48 42 49 43 my $methods = { … … 80 74 81 75 # "Can't do that" errors 82 if (!$d bh) {76 if (!$dnsdb) { 83 77 print "Content-type: text/xml\n\n".$res->{_decode}->encode_fault(5, $msg); 84 78 exit; -
trunk/dns.cgi
r458 r468 45 45 use lib '.'; ##uselib## 46 46 47 use DNSDB qw(:ALL);47 use DNSDB; 48 48 49 49 my @debugbits; # temp, to be spit out near the end of processing … … 69 69 # we'll catch a bad DB connect string once we get to trying that 70 70 ##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"; 71 my $dnsdb = new DNSDB; 72 73 my $header = HTML::Template->new(filename => "$templatedir/header.tmpl"); 74 my $footer = HTML::Template->new(filename => "$templatedir/footer.tmpl"); 75 $footer->param(version => $DNSDB::VERSION); 76 77 if (!$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; 73 85 } 86 87 $header->param(orgname => $dnsdb->{orgname}) if $dnsdb->{orgname} ne 'Example Corp'; 74 88 75 89 # persistent stuff needed on most/all pages 76 90 my $sid = ($webvar{sid} ? $webvar{sid} : undef); 77 my $session = new CGI::Session("driver:File", $sid, {Directory => $ config{sessiondir}})91 my $session = new CGI::Session("driver:File", $sid, {Directory => $dnsdb->{sessiondir}}) 78 92 or die CGI::Session->errstr(); 79 93 #$sid = $session->id() if !$sid; … … 81 95 # init stuff. can probably axe this down to just above if'n'when user manipulation happens 82 96 $sid = $session->id(); 83 $session->expire($ config{timeout});97 $session->expire($dnsdb->{timeout}); 84 98 # need to know the "upper" group the user can deal with; may as well 85 99 # stick this in the session rather than calling out to the DB every time. … … 149 163 push @filterargs, $filter if $filter; 150 164 151 # nrgh, can't handle login here because we don't have a database handle to check the user/pass with yet152 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 158 165 ## set up "URL to self" 159 166 # @#$%@%@#% XHTML - & in a URL must be escaped. >:( … … 179 186 # pagination 180 187 my $perpage = 15; 181 $perpage = $ config{perpage} if $config{perpage};188 $perpage = $dnsdb->{perpage} if $dnsdb->{perpage}; 182 189 my $offset = ($webvar{offset} ? $webvar{offset} : 0); 183 190 … … 186 193 my $sortorder = "ASC"; 187 194 188 ##fixme: quit throwing the database handle around, and put all the SQL and direct DB fiddling into DNSDB.pm189 # 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 205 195 # security check - does the user have permission to view this entity? 206 196 # this is a prep step used "many" places 207 197 my @viewablegroups; 208 getChildren($dbh,$logingroup, \@viewablegroups, 'all');198 $dnsdb->getChildren($logingroup, \@viewablegroups, 'all'); 209 199 push @viewablegroups, $logingroup; 210 200 … … 232 222 # Snag ACL/permissions here too 233 223 234 my $userdata = login($dbh,$webvar{username}, $webvar{password});224 my $userdata = $dnsdb->login($webvar{username}, $webvar{password}); 235 225 236 226 if ($userdata) { … … 293 283 # but if they keep the session active they'll continue to have access long after being disabled. :/ 294 284 # Treat it as a session expiry. 295 if ($session->param('uid') && ! userStatus($dbh,$session->param('uid')) ) {285 if ($session->param('uid') && !$dnsdb->userStatus($session->param('uid')) ) { 296 286 $sid = ''; 297 287 $session->delete; # force expiry of the session Right Away … … 301 291 302 292 # 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')); 305 295 306 296 $page->param(sid => $sid) unless $webvar{page} eq 'login'; # no session ID on the login page -
trunk/export.pl
r262 r468 25 25 use lib '.'; ##uselib## 26 26 27 use DNSDB qw(:ALL);27 use DNSDB; 28 28 29 loadConfig();29 my $dnsdb = new DNSDB; 30 30 31 31 open TINYDATA, ">tinydata"; 32 32 33 my ($dbh,$msg) = connectDB($config{dbname}, $config{dbuser}, $config{dbpass}, $config{dbhost});34 initGlobals($dbh);35 36 33 export($dbh,'tiny',*TINYDATA); -
trunk/textrecs.cgi
r440 r468 31 31 use lib '.'; ##uselib## 32 32 33 use DNSDB qw(:ALL);33 use DNSDB; 34 34 35 35 # Let's do these templates right... … … 48 48 $webvar{revrec} = 'n' if !$webvar{revrec}; # non-reverse (domain) records 49 49 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 } 50 my $dnsdb = new DNSDB; 57 51 58 52 # Check the session and if we have a zone ID to retrieve. Call a failure sub if not. 59 53 my $sid = ($webvar{sid} ? $webvar{sid} : undef); 60 my $session = new CGI::Session("driver:File", $sid, {Directory => $ config{sessiondir}})54 my $session = new CGI::Session("driver:File", $sid, {Directory => $dnsdb->{sessiondir}}) 61 55 or die CGI::Session->errstr(); 62 56 do_not_pass_go() if !$sid; 63 57 do_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.pm66 # 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);70 58 71 59 my $zone; -
trunk/tiny-import.pl
r461 r468 27 27 28 28 use lib '.'; 29 use DNSDB qw(:ALL); 30 31 if (!loadConfig()) { 32 warn "Using default configuration; unable to load custom settings: $DNSDB::errstr"; 33 } 29 use DNSDB; 30 31 my $dnsdb = new DNSDB; 34 32 35 33 usage() if !@ARGV; … … 77 75 78 76 my $code; 79 my ($dbh,$msg) = connectDB($config{dbname}, $config{dbuser}, $config{dbpass}, $config{dbhost}); 80 initGlobals($dbh) if $dbh; 77 my $dbh = $dnsdb->{dbh}; 81 78 82 79 $dbh->{AutoCommit} = 0; … … 251 248 my $nodefer = shift || 0; 252 249 my $impok = 1; 250 my $msg; 253 251 254 252 $errstr = $rec; # this way at least we have some idea what went <splat> … … 269 267 $loc = '' if !$loc; 270 268 $loc = '' if $loc =~ /^:+$/; 271 my $fparent = DNSDB::_hostparent($dbh,$host);269 my $fparent = $dnsdb->_hostparent($host); 272 270 my ($rparent) = $dbh->selectrow_array("SELECT rdns_id FROM revzones WHERE revnet >> ?", undef, ($ip)); 273 271 if ($fparent && $rparent) { … … 308 306 309 307 } else { 310 my $fparent = DNSDB::_hostparent($dbh,$host);308 my $fparent = $dnsdb->_hostparent($host); 311 309 if ($fparent) { 312 310 $recsth->execute($fparent, 0, $host, 5, $targ, 0, 0, 0, $ttl, $loc); … … 344 342 } 345 343 } else { 346 my $fparent = DNSDB::_hostparent($dbh,$zone);344 my $fparent = $dnsdb->_hostparent($zone); 347 345 if ($fparent) { 348 346 $recsth->execute($fparent, 0, $zone, 2, $ns, 0, 0, 0, $ttl, $loc); … … 396 394 $loc = '' if $loc =~ /^:+$/; 397 395 398 my $domid = DNSDB::_hostparent($dbh,$host);396 my $domid = $dnsdb->_hostparent($host); 399 397 if ($domid) { 400 398 $recsth->execute($domid, 0, $host, 1, $ip, 0, 0, 0, $ttl, $loc); … … 447 445 448 446 # 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); 450 448 if ($domid) { 451 449 $recsth->execute($domid, 0, $zone, 15, $host, $dist, 0, 0, $ttl, $loc); … … 473 471 $recsth->execute(0, $rparent, $rdata, 16, "$msg", 0, 0, 0, $ttl, $loc); 474 472 } else { 475 my $domid = DNSDB::_hostparent($dbh,$fqdn);473 my $domid = $dnsdb->_hostparent($fqdn); 476 474 if ($domid) { 477 475 $recsth->execute($domid, 0, $fqdn, 16, $rdata, 0, 0, 0, $ttl, $loc); … … 588 586 # } 589 587 590 my $domid = DNSDB::_hostparent($dbh,$fqdn);588 my $domid = $dnsdb->_hostparent($fqdn); 591 589 if ($domid) { 592 590 $recsth->execute($domid, 0, $fqdn, 33, $target, $prio, $weight, $port, $ttl, $loc) if $domid; … … 606 604 my $val = NetAddr::IP->new(join(':', @v6)); 607 605 608 my $fparent = DNSDB::_hostparent($dbh,$fqdn);606 my $fparent = $dnsdb->_hostparent($fqdn); 609 607 if ($fparent) { 610 608 $recsth->execute($fparent, 0, $fqdn, 28, $val->addr, 0, 0, 0, $ttl, $loc); … … 628 626 } 629 627 } else { 630 my $domid = DNSDB::_hostparent($dbh,$fqdn);628 my $domid = $dnsdb->_hostparent($fqdn); 631 629 if ($domid) { 632 630 $recsth->execute($domid, 0, $fqdn, 16, $txtstring, 0, 0, 0, $ttl, $loc); … … 656 654 } 657 655 } else { 658 my $domid = DNSDB::_hostparent($dbh,$fqdn);656 my $domid = $dnsdb->_hostparent($fqdn); 659 657 if ($domid) { 660 658 $recsth->execute($domid, 0, $fqdn, 17, "$email $txtrec", 0, 0, 0, $ttl, $loc); … … 672 670 673 671 # 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); 675 673 if ($domid) { 676 674 $recsth->execute($domid, 0, $fqdn, 44, $sshfp, 0, 0, 0, $ttl, $loc); -
trunk/vega-import.pl
r320 r468 29 29 use Data::Dumper; 30 30 31 use DNSDB qw(:ALL); 32 33 if (!loadConfig()) { 34 warn "Using default configuration; unable to load custom settings: $DNSDB::errstr"; 35 } 31 use DNSDB; 32 33 my $dnsdb = new DNSDB; 36 34 37 35 my $mode = 'add'; … … 45 43 $mode = $ARGV[0] if $ARGV[0]; 46 44 47 my ($newdbh,$msg) = connectDB($config{dbname}, $config{dbuser}, $config{dbpass}, $config{dbhost});45 my $newdbh = $dnsdb->{dbh}; 48 46 $newdbh->{PrintError} = 1; 49 47 $newdbh->{PrintWarn} = 1; 50 initGlobals($newdbh);51 48 52 49 my %vegatypes = ('S' => 'SOA', 'N' => 'NS', 'A' => 'A', 'T' => 'TXT',
Note:
See TracChangeset
for help on using the changeset viewer.