Changeset 128 for trunk/dns.cgi


Ignore:
Timestamp:
09/21/11 18:13:16 (13 years ago)
Author:
Kris Deugau
Message:

/trunk

Code review/cleanup

  • Move configuration of DB host, user, pass, name into an outside file.
  • Fail more gracefully on DB connection failure. Includes minor CSS tweak that probably doesn't really do what I think it's doing.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/dns.cgi

    r126 r128  
    130130my $sortorder = "ASC";
    131131
    132 #my ($dbh,$msg) = connectDB("dnsdb","dnsdb","secret","newdbhost");
     132# now load some local system defaults (mainly DB connect info)
     133# note this is not *absolutely* fatal, since there's a default dbname/user/pass in DNSDB.pm
     134# we'll catch a bad DB connect string a little further down.
     135if (!loadConfig()) {
     136  warn "Using default configuration;  unable to load custom settings: $DNSDB::errstr";
     137}
     138
     139##fixme: quit throwing the database handle around, and put all the SQL and direct DB fiddling into DNSDB.pm
    133140# dbname, user, pass, host (optional)
    134 my ($dbh,$msg) = connectDB("dnsdb", "dnsdb", "secret", "dnsdbhost");
    135 #my $dbh = DBI->connect("DBI:mysql:database=vegadns","vegadns","secret",
    136 #       { AutoCommit => 0 }) or die $DBI::errstr;
    137 
    138 ##fixme.  PLEASE!  <G>
    139 print $msg if !$dbh;
    140 
    141 # fiddle hardcoded "defaults" as per system/user (?) prefs
     141my ($dbh,$msg) = connectDB($config{dbname}, $config{dbuser}, $config{dbpass}, $config{dbhost});
     142
     143if (!$dbh) {
     144  print "Content-type: text/html\n\n";
     145  print $header->output;
     146  my $errpage = HTML::Template->new(filename => "$templatedir/dberr.tmpl");
     147  $errpage->param(errmsg => $msg);
     148  print $errpage->output;
     149  print $footer->output;
     150  exit;
     151}
     152
     153# Load config pieces from the database.  Ideally all but the DB user/pass/etc should be loaded here.
    142154initGlobals($dbh);
    143155
Note: See TracChangeset for help on using the changeset viewer.