Changeset 479


Ignore:
Timestamp:
Sep 17, 2010, 6:49:45 PM (11 years ago)
Author:
Kris Deugau
Message:

/branches/htmlform

Convert initial DB connection error output to a sane page. Could arguably provide
space for this (and other) errors on all normal pages. (See #3).
This allows us to:

  • Remove editError sub in main.cgi
  • Remove printHeader sub in CommonWeb?.pm (see #15, #26)

Removed duplicate "exit if we get this far"
Tweak IPDB::finish so it doesn't spit a fatal error when called with a null database handle

Location:
branches/htmlform/cgi-bin
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/htmlform/cgi-bin/CommonWeb.pm

    r450 r479  
    1616$VERSION     = 1.00;
    1717@ISA         = qw(Exporter);
    18 @EXPORT_OK      = qw( &printHeader &printError &printAndExit &desanitize &cleanInput &desanitize);
     18@EXPORT_OK      = qw( &printError &printAndExit &desanitize &cleanInput &desanitize);
    1919
    2020@EXPORT      = (); #export nothing by default
     
    2525                );
    2626
    27 
    28 sub printHeader {
    29   my $title = shift;
    30   print "Content-type: text/html\n\n";
    31 # This doesn't work well.  Must investigate.
    32 #  my $realm = shift;
    33 #  print qq(WWW-Authenticate: Basic realm="$realm"\n) if $realm;
    34   open FILE, "../header.inc"
    35         or carp $!;
    36   my $html = join('',<FILE>);
    37   close FILE;
    38 
    39   $html =~ s/\$\$TITLE\$\$/$title/;
    40 # Necessary for mangling arbitrary bits of the header
    41   my $i=0;
    42   while (defined(my $param = shift)) {
    43     $html =~ s/\$\$EXTRA$i\$\$/$param/g;
    44     $i++;
    45   }
    46   print $html;
    47 }
    4827
    4928sub printError($)
  • branches/htmlform/cgi-bin/IPDB.pm

    r468 r479  
    174174sub finish {
    175175  my $dbh = $_[0];
    176   $dbh->disconnect;
     176  $dbh->disconnect if $dbh;
    177177} # end finish
    178178
  • branches/htmlform/cgi-bin/main.cgi

    r478 r479  
    4646syslog "debug", "$authuser active, $ENV{'REMOTE_ADDR'}";
    4747
     48##fixme there *must* be a better order to do things in so this can go back where it was
     49# CGI fiddling done here so we can declare %webvar so we can alter $webvar{action}
     50# to show the right page on DB errors.
     51# Set up the CGI object...
     52my $q = new CGI::Simple;
     53# ... and get query-string params as well as POST params if necessary
     54$q->parse_query_string;
     55
     56# Convenience;  saves changing all references to %webvar
     57##fixme:  tweak for handling <select multiple='y' size=3> (list with multiple selection)
     58my %webvar = $q->Vars;
     59
    4860# Why not a global DB handle?  (And a global statement handle, as well...)
    4961# Use the connectDB function, otherwise we end up confusing ourselves
     
    5365($ip_dbh,$errstr) = connectDB_My;
    5466if (!$ip_dbh) {
    55   exitError("Database error: $errstr\n");
    56 }
    57 initIPDBGlobals($ip_dbh);
     67  $webvar{action} = "dberr";
     68} else {
     69  initIPDBGlobals($ip_dbh);
     70}
    5871
    5972# Set up some globals
     
    6679$header->param(addperm => $IPDBacl{$authuser} =~ /a/);
    6780print "Content-type: text/html\n\n", $header->output;
    68 
    69 # Set up the CGI object...
    70 my $q = new CGI::Simple;
    71 # ... and get query-string params as well as POST params if necessary
    72 $q->parse_query_string;
    73 
    74 # Convenience;  saves changing all references to %webvar
    75 ##fixme:  tweak for handling <select multiple='y' size=3> (list with multiple selection)
    76 my %webvar = $q->Vars;
    7781
    7882
     
    153157  }
    154158  $page->param(nodelist => \@nodelist);
     159}
     160
     161# DB failure.  Can't do much here, really.
     162elsif ($webvar{action} eq 'dberr') {
     163  $page->param(errmsg => $errstr);
    155164}
    156165
     
    192201# Just in case something waaaayyy down isn't in place
    193202# properly... we exit explicitly.
    194 exit;
    195 
     203exit 0;
    196204
    197205
     
    12571265
    12581266} # finalDelete
    1259 
    1260 
    1261 # going, going, gone... this sub to be removed Any Day Real Soon Now(TM)
    1262 sub exitError {
    1263   my $errStr = $_[0];
    1264   printHeader('','');
    1265   print qq(<center><p class="regular"> $errStr </p>
    1266 <input type="button" value="Back" onclick="history.go(-1)">
    1267 </center>
    1268 );
    1269 
    1270   # We print the footer here, so we don't have to do it elsewhere.
    1271   # include the admin tools link in the output?
    1272   $footer->param(adminlink => ($IPDBacl{$authuser} =~ /A/));
    1273 
    1274   print $footer->output;
    1275 
    1276   exit;
    1277 } # errorExit
    1278 
    1279 
    1280 # Just in case we manage to get here.
    1281 exit 0;
Note: See TracChangeset for help on using the changeset viewer.