1    1 package CLPElog;
   2    2 @ISA = qw (Exporter);
   3    3 @EXPORT = qw(
   4    4                allParametersHash
   5    5                checkOKtoSearch
   6    6                cleanHtmlTxt
   7    7                createFileSearchForm
   8    8                getDirInfo
   9    9                getElogDirs
  10   10                getMatchWords
  11   11                logWelcomeForm
  12   12                name
  13   13                printFormItems
  14   14                printNewDayForm
  15   15                printQueryHeader
  16   16                thisMonthForward
  17   17            );
  18      use constant CDF   => "CDF";
  19      use constant FNALU => "FNALU";
  20      use constant CERN  => "CERN";
  21      use constant LOCAL => "LOCAL";
  22      use DateTime;
  23   18 use Data::Dumper;
  24   19 use strict;
  25   20 use warnings;
  26   21 use CGI;
  27   22 use CGI::Carp qw(warningsToBrowser fatalsToBrowser  set_message); 
  28   23 use Exporter;
  29   24 # Package Variables.
  30   25 #
  31   26 # IMPORTANT: Do not initialize any variables here IF they are
  32   27 # initialized by the BEGIN block - if you do, they will be reset.
  33   28 my $base;
  34   29 my $host;
  35   30 my $mode;
  36   31 my $query;
  37   32 my $printQuery;
  38   33 my $okfile;
  39   34 my $loghtml = "log.html";
  40   35 my $homedirbase;
  41   36 my ($basedir, $htmlbase);
  42   37 my @neededParams;
  43   38 my %defaults;
  44   39 my %description;
  45   40 my %config;
  46   41 my $hashRef;
  47   42 sub name {
  48   43    my %options = @_;
  49   44    my $name = $query->param('name') || "";
  50   45    if ($options{asis}) {
  51   46       return $name;
  52   47    }
  53   48    if ($name !~ m|'|) {
  54   49       $name .= "'s"
  55   50    }
  56   51    if ($options{nolog}) {
  57   52       $name =~ s|(\s\w*log\b)||i;
  58   53    } else {
  59   54       if ($name !~ m|log\b|i) {
  60   55          $name .= " Elog"
  61   56       }
  62   57    }
  63   58    return $name;
  64   59 }
  65   60 sub allParametersHash {
  66   61    my @names = $query->param();
  67   62    my %retHash;
  68   63    foreach my $name (@names) {
  69   64       $retHash{$name} = cleanMatchWord ($query->param($name));
  70   65    }
  71   66    return %retHash;
  72   67 }
  73   68 sub logWelcomeForm {
  74   69    if ($query->param('logHtml')) {
  75   70       # print personalized version of 'log.html'
  76   71       printQueryHeader();
  77   72       my $name = name (nolog => "true");
  78   73       my $url = $query->url."?".formIdentityString("inline");
  79   74       (my $dir = $0) =~ s|[^/]+$||;
  80   75       open (LOGHTML, "<", "$dir/log.html.template") or die;
  81   76       while (<LOGHTML>) {
  82   77          s/YourNameHere/$name/g;
  83   78          s/WWW/$url/g;
  84   79          print;
  85   80       }
  86   81       return;
  87   82    } elsif ($query->param('Action')) {      
  88   83       # process form
  89   84       printQueryHeader();
  90   85       my $url = $query->url."?".formIdentityString("inline");
  91   86       $url =~ s|\s+|%20|g;
  92   87       $url =~ s|'|%27|g;
  93   88       my $value = cleanHtmlTxt ($url);
  94   89       print "<ul>\n";
  95   90       print "<li> Bookmark the link to your Elog Welcome page:<br>\n";
  96   91       print "<a href=\"$url\"><tt>", $value, "</tt></a><br><br>\n";
  97   92       print "<li>After chaing to your log directory, paste these instructions at your prompt:\n";
  98   93       print "<pre><font color=\"red\">";
  99   94       print "wget \"<a href=\"$url&logHtml=true\">$value&logHtml=true</a>\" -O log.html\n";
 100   95       print "wget http://home.fnal.gov/~cplager/log/elogHowTo/elog.css\n";
 101   96       print "wget http://home.fnal.gov/~cplager/log/elogHowTo/cal2links.pl\n";
 102   97       print "wget http://home.fnal.gov/~cplager/log/elogHowTo/newMonth.py\n";
 103   98       print "chmod +x cal2links.pl newMonth.py\n";
 104            print "touch $okfile\n" if ($okfile !~ /\.html/);
       99       print "touch $okfile\n" if ($okfile && $okfile !~ /\.html/);
 105  100       print "\n</font></pre>";
 106  101       print "</ul>\n";
 107  102    } else {
 108  103       # make form
 109  104       print "Needed:@neededParams\n";
 110  105       foreach my $param (@neededParams) {
 111  106          $defaults{$param}    = $hashRef->{"$param\_default"} || "";
 112  107          $description{$param} = $hashRef->{"$param\_descrip"} || "";
 113  108       } # foreach param
 114  109       $defaults{'name'}        = "Your Name -or- Your Name's Something Elog";
 115  110       $description{'name'}     = "Your name, as you'd like to see it";
 116  111       printQueryHeader();
 117  112       $query->start_html ("Elog Welcome Form");
 118  113       print $query->startform (-method => "get");
 119  114       print "<table border=1 cellpadding=3>\n";
 120  115       print "<tr><th>Parameter</th><th>Value</th><th>Description</th></tr>\n";
 121  116       foreach my $needed (@neededParams) {
 122  117          print "<tr><th>$needed:</th><td>";
 123  118          print $query->textfield(-name    => $needed,
 124  119                                  -default => $defaults{$needed},
 125  120                                  -size    => 50);
 126  121          print "</td><td> $description{$needed}</td></tr>\n";
 127  122       } # foreach needed
 128  123       print "<tr><td colspan=3 align=\"center\">", $query->submit('Action','Submit'), "</td>\n";
 129  124    } # if making form
 130  125    print "</table>\n";
 131  126    print $query->hidden (-name => 'doForm', -default => "true");
 132  127    print $query->endform, "\n";   
 133  128 }
 134  129 sub createFileSearchForm {
 135  130    printQueryHeader();
 136  131    my $name = name();
 137  132    $query->start_html ();
 138  133    print "<link rel =\"stylesheet\" type=\"text/css\" href =\"$htmlbase/elog.css\">\n";
 139  134    print "<title>$name File Search Form</title>\n";
 140  135    print "<h1>$name File Search Form</h1>\n";
 141  136    print $query->startform (-method => "get");
 142  137    print "<table>\n";
 143  138    # Words to match
 144  139    for my $index (1..4) {
 145  140       print "<tr><th>Word $index:</th><td>";
 146  141       print $query->textfield (-name => "word$index"), "</td></tr>\n";
 147  142    }
 148  143    # File match
 149  144    print "<tr><th>File Match:</th><td>";
 150  145    print $query->textfield (-name => "filematch"), "</td></tr>\n";
 151  146    # Check case
 152  147    print "<tr><th>Check case:</th><td>";
 153  148    print $query->checkbox(-name    => 'case',
 154  149                           -checked => '',
 155  150                           -value   => '1',
 156  151                           -label   => ''), "</td></tr>\n";
 157  152    # Line and
 158  153    print "<tr><th>All words on same line:</th><td>";
 159  154    print $query->checkbox(-name    => 'doand',
 160  155                           -checked => '',
 161  156                           -value   => '1',
 162  157                           -label   => ''), "</td></tr>\n";
 163  158    # file and
 164  159    print "<tr><th>All words in same file:</th><td>";
 165  160    print $query->checkbox(-name    => 'dofileand',
 166  161                           -checked => '',
 167  162                           -value   => '1',
 168  163                           -label   => ''), "</td></tr>\n";
 169  164    print $query->hidden (-name => 'search', -default => "true");
 170  165    print formIdentityString();
 171  166    print "<tr><td colspan=\"2\">", 
 172  167      $query->submit('Action','Submit'),
 173  168      $query->reset("Clear Form"),
 174  169      "</td></tr></table>\n";  
 175  170    print $query->endform, "\n";
 176  171    exit;
 177  172 }
 178  173 sub printFormItems {
 179  174    printQueryHeader();
 180  175    my $inlineFormID = formIdentityString("inline");
 181  176    my $formID = formIdentityString();
 182  177    (my $basecgi = $query->url) =~ s|/[^/]+$||;
 183  178    print "<ul>\n";
 184  179    print "  <!-- Log Forward -->\n";
 185  180    print "  <li> <a href=\"$basecgi/LogForward.pl?$inlineFormID\">Go to Current Log</a>\n";
 186  181    print "  <!-- Log Search -->\n";
 187  182    print "  <li> <form action=\"$basecgi/LogSearch.pl\" method=\"get\"> Search my log book: <input name=\"match\" type=\"text\">$formID
 188  183 			<input name=\"Action\" value=\"Go\" type=\"submit\">			
 189  184 			</form>\n";
 190  185    print "  <!-- Log File Search -->\n";
 191  186    print "  <li> <a href=\"$basecgi/LogFileSearch.pl?$inlineFormID\">Search my elog files</a>\n";
 192  187    print "  <!-- Log Summary -->\n";
 193  188    print "  <li> <a href=\"$basecgi/LogSummary.pl?$inlineFormID\">Elog summary</a>\n";
 194  189    print "  <!-- New Day HTML Code -->\n";
 195  190    print "  <li> <a href=\"$basecgi/NewDay.pl\">HTML code for a new day</a>\n";
 196  191    print "  <!-- Elog Instructions -->\n";
 197  192    print "  <li> <a href=\"http://home.fnal.gov/~cplager/log/elogHowTo/howTo.html\">Elog documentation and hints</a>\n";
 198  193    print "</ul>\n";
 199  194 }
 200  195 sub printNewDayForm {
 201  196    printQueryHeader();
 202  197    print $query->start_html("Text for New Day");
 203  198    print "<h1>Text For New Day</h1>\n";
 204  199    my $month = $query->param ('month') || "";
 205  200    my $day   = $query->param ('day')   || 0;
 206  201    my $year  = $query->param ('year')  || 0;
 207  202    $month =~ s/\W//g;
 208  203    $day   =~ s/\D//g;
 209  204    $year  =~ s/\D//g;
 210         #print "<pre>year $year month $month day $day</pre>\n";
 211  205    my $monthOK = 0;
 212  206    my $monthIndex = 1;
 213  207    {
 214  208       no warnings;
 215  209       foreach my $shortMonth (@Date::kShortMonthNames) {
 216  210          if ($month =~ m|$shortMonth|i) {
 217  211             $monthOK = "true";
 218  212             last;
 219  213          }
 220  214          ++$monthIndex;
 221  215       } # foreach $shortMonth
 222  216    } # no warnings
 223  217    my $date;
 224  218    if (! $monthOK || $day < 1 || $day > 31 || $year < 0) {
 225  219    #if (! $monthOK ){#|| $day < 1 || $day > 31 || $year < 0) {
 226            $date = DateTime->now();
      220       $date = Date->today();
 227  221    } else {
 228  222       if ($year < 1000) {
 229  223          $year += 2000;
 230  224       }
 231            $date = DateTime->new( year  => $year,
 232                                   month => $monthIndex,
 233                                   day   => $day );
      225       my $string = "\$date = Date->new($monthIndex, $day, $year)";
      226       my $retval = eval $string;
      227       if ($@ || ! $date) {
      228          # Something didn't work
      229          $date = Date->today();
 234         }
      230       }
      231    } # else if
      232    print "<h2> HTML Code for $date</h2>\n";
 235         my @days = qw (Monday Tuesday Wednesday Thursday Friday Saturday Sunday);
 236         my $dateString = sprintf ("%s, %s %d", 
 237                                   $date->day_name, $date->month_name, $date->day);
 238         my $dateKey = sprintf ("%02d%02d%02d",
 239                                $date->year - 2000, $date->month, $date->day);
 240                                   
 241         print "<h2> HTML Code for ",$date->strftime ("%A, %B %d, 20%y"),"</h2>\n";
 242  233    my $length = 74;
 243  234    print "HTML for a new day:<br>\n";
 244  235    print "<pre><font color=\"red\">\n";
 245  236    print "&lt;!", "-" x $length, "&gt;\n";
 246         my $monthDay = " $dateString ";
      237    my $monthDay = " ". $date->weekdayNameFull.", ".$date->monthNameFull . " " . $date->day . " ";
 247  238    my $shortLength = int (($length - length($monthDay)) / 2);
 248  239    my $otherLength = $length - length ($monthDay) - $shortLength;
 249  240    print "&lt;!", "-" x $shortLength, $monthDay, "-" x $otherLength, "&gt;\n";
 250  241    print "&lt;!", "-" x $length, "&gt;\n";
 251         print "&lt;p&gt; &lt;a name=\"", $dateKey,"\"&gt;&lt/a&gt;\n";
      242    print "&lt;p&gt; &lt;a name=\"", $date->key,"\"&gt;&lt/a&gt;\n";
 252  243    print "&lt;h2&gt;$monthDay&lt;/h2&gt;\n";
 253  244    print "</font></pre>\n";
 254  245    if ($query->param ('subhead')) {
 255  246       my $subhead = $query->param ('subhead');
 256  247       (my $tag = $subhead) =~ s|[^<>/\w\s]||g;
 257  248       $tag =~ s|<.*?>||g;
 258  249       $tag =~ s|\s+|_|g;
 259            $tag = $dateKey."_$tag";
      250       $tag = $date->key."_$tag";
 260  251       (my $prettySubhead = $subhead) =~  s|<.*?>||g;
 261  252       $subhead = cleanHtmlTxt ($subhead);
 262            print "<pre><font color=\"red\">&lt;!-- $prettySubhead -->\n&lt;p&gt;&lt;a name=\"$tag\"&gt;&lt;/a&gt;\n&lt;h3&gt;$subhead\n&lt;a href=\"#$tag\"&gt;&amp;nbsp;&lt;/a&gt;&lt;/h3&gt;\n\n&lt;p&gt;\n\n</font></pre>";
      253       print "<pre><font color=\"red\">&lt;!-- $prettySubhead -->\n&lt;p&gt;&lt;a name=\"$tag\"&gt;&lt;/a&gt;\n&lt;h3&gt;$subhead\n&lt;a href=\"#$tag\"&gt;&amp;nbsp;&lt;/a&gt;&lt;/h3&gt;\n\n&lt;p&gt;\n\n</pre>";
 263  254    } # if subhead
 264  255    else {
 265            print "<br><br></font>\n";
      256       print "<br><br>\n";
 266  257    }
 267  258    print $query->startform (-method => "get");
 268  259    print "<table>\n";
 269  260    # month
 270  261    print "<tr><th>Month:</th><td>";
 271  262    {
 272  263       no warnings;
 273  264       print $query->popup_menu (-name => "month", 
 274  265                                 -values => \@Date::kMonthNames,
 275                                      -default => $date->month_name),
      266                                 -default => $date->monthNameFull), 
 276  267                                   "</td></tr>\n";
 277  268    }
 278  269    # day
 279  270    print "<tr><th>Day:</th><td>";
 280  271    print $query->textfield (-name => "day", 
 281  272                             -value => $date->day), "</td></tr>\n";
 282  273    # year
 283  274    print "<tr><th>Year:</th><td>";
 284  275    print $query->textfield (-name => "year", 
 285  276                             -value => $date->year), "</td></tr>\n";
 286  277    # year
 287  278    print "<tr><th>Name of Subheader (optional):</th><td>";
 288  279    print $query->textfield (-name => "subhead"), "</td></tr>\n";
 289  280    print "<tr><td colspan=\"2\">", 
 290  281      $query->submit('Action','Submit'),
 291  282      "</td></tr></table>\n";  
 292  283    print $query->endform, "\n";
 293  284    exit;
 294  285 }
 295  286 sub thisMonthForward {
 296  287    getDirInfo();
      288    chomp (my $date = `date +%y%m`);
 297         my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
 298         my $date = sprintf ("%02d%02d", $year - 100, $mon + 1);
 299  289    my @dirs = getElogDirs();
 300  290    my $max = "0000";
 301  291    foreach my $dir (@dirs) {
 302  292       if ($dir <= $date && $dir > $max) {
 303  293          $max = $dir
 304  294       } # if new max
 305  295    } # foreach dir
 306         #print "<pre>date $date $year $mon : $max</pre>\n";
 307  296    my $url;
 308  297    if ($max) {
 309  298       $url = "$htmlbase/$max/$loghtml";
 310  299    } else {
 311  300       $url = "$htmlbase/$date/$loghtml";
 312  301    }
 313  302    # I don't understand why, but the status redirect doesn't seem to
 314  303    # be working when using the simple python web server.  So, if I am
 315  304    # running locally, go to the old fashioned forward.
 316         if (LOCAL == $mode) {
      305    if ('LOCAL' == $mode) {
 317  306       printQueryHeader();
 318  307       print "<html><head>\n".
 319  308         "<meta http-equiv=\"Refresh\" content=\"0; URL=$url\">\n".
 320              "<meta http-equiv=\"Content-Type\"></head></html>\n";
      309           "<meta http-equiv=\"Content-Type\"></head></html>\n";
 321  310    } else {
 322  311       print "Status: 302 Redirect\nPragma: no-cache\nLocation: $url\n\n";
 323  312    }
 324  313 }
 325  314 sub printQueryHeader {
 326  315    return if $printQuery;
 327  316    $printQuery = "true";
 328  317    print $query->header();
 329  318 }
 330  319 sub checkOKtoSearch {
 331  320    # Make sure we have the base directory
 332  321    getDirInfo() unless $basedir;
 333         if (! -e "$basedir/$okfile") {
      322    if ($okfile && ! -e "$basedir/$okfile") {
 334  323       error ("File '$basedir/$okfile' does not exist.  ".
 335  324              "Create to avoid this error.");
 336  325    } # if we are not allowed to search
 337  326    return "true";
 338  327 }
 339  328 sub getMatchWords {
 340  329    my $match = $query->param('match') || "";
 341  330    return split /\s+/, cleanMatchWord ($match);   
 342  331 }
 343  332 sub getElogDirs {
 344  333    getDirInfo();
 345  334    chdir $basedir;
 346  335    my @files = glob ("????");
 347  336    my @retval;
 348  337    foreach my $dir (@files) {
 349  338       next unless (-d $dir);
 350  339       if ($dir =~ m|^(\d{2})(\d{2})|) {
 351  340          my $month = $2;
 352  341          next if ($month < 1 || $month > 12);
 353  342       } else {
 354  343          next;
 355  344       }
 356  345       push @retval, $dir;
 357  346    } # foreach dir
 358  347    return sort @retval;
 359  348 }
 360  349 sub cleanMatchWord {
 361  350    my $match = shift;
 362  351    $match =~ s/^\s*//;
 363  352    $match =~ s/\s*$//;
 364  353    $match =~ s/[^\w\\\.\+\*\-\/\s\{\}\[\]\(\)\!\@\#\$\%\^\&<>,?'"~`;]//g; # get rid of undesireable characters
 365  354    return $match
 366  355 }
 367  356 sub error {
 368  357    my $comment = shift;
 369  358    printQueryHeader();
 370  359    print "<title>Error</title>\n<h1>Error</h1>\n\n";
 371  360    print "You can only use this script to look at a log directory. Aborting.\n";
 372  361    print "<br>$comment\n" if $comment;
 373  362    exit();
 374  363 }
 375  364 sub cleanHtmlTxt {
 376  365    my $text = shift;
 377  366    $text =~ s|&|&amp;|g;
 378  367    $text =~ s|\<|&lt;|g;
 379  368    $text =~ s|\>|&gt;|g;
 380  369    return $text;
 381  370 }
 382  371 sub expand_tilda {
 383  372     my $file = shift;
 384  373     if ($file =~ m|^~([^/]+)/|) {
 385  374        my $homedir;
 386  375        my $user = $1;
 387  376        #print "Looking for user $user\n";
 388  377        while (my @list = getpwent) {
 389  378           if ($list[0] eq $user) {
 390  379              #print "found $user\n";
 391  380              $homedir = $list[7];
 392  381              last;
 393  382           } # if I found the right user
 394  383        } # while looping over all users
 395  384        if ($homedir) {
 396  385           $file =~ s|^~[^/]+/|$homedir/|;
 397  386           return $file;
 398  387        } # if $homedir       
 399  388     } # if $file contains '~'
 400  389     return $file;
 401  390 }
 402  391 sub formIdentityString {
 403  392    my $inlineMode = shift || "";
 404  393    my $retval = "";
 405  394    my @params = @neededParams;
 406  395    #push @params, "name";
 407  396    if ("inline" eq $inlineMode) {
 408  397       my $first = "true";
 409  398       foreach my $param (@params) {
 410  399          if ($first) {
 411  400             $first = 0;
 412  401          } else {
 413  402             $retval .= "&";
 414  403          }
 415  404          $retval .= $param."=".$query->param($param);
 416  405       }
 417  406    } else {
 418  407       $retval .= "\n";
 419  408       foreach my $param (@params) {
 420  409          $retval .= $query->hidden(-name => $param, 
 421  410                                    -default => $query->param($param))."\n";
 422  411       }
 423  412    }
 424  413    return $retval;
 425  414 }
 426  415 sub loadConfigFile {
 427  416    (my $dir = $0) =~ s|[^/]+$||;
 428  417    open (CONFIG, "<", "$dir/CLPElog.config") or die;
 429  418    my $host = "";
 430         my @neededKeys = qw (hostname needed basedir htmlbase okfile);
      419    my @neededKeys = qw (hostname needed basedir htmlbase);
 431  420    # my %neededHash = map {$_ => $_} @neededKeys;
 432  421    while (<CONFIG>) {
      422       # gete rid of comments and extra spaces
 433            chomp;
      423       chomp;      
 434  424       s/#.+$//;
      425       s|^\s*||;
      426       s|\s*$||;
 435  427       next unless /\S/;
 436  428       if (m|^\s*\-\s*(\w+)|) {
 437  429          $host = $1;
 438  430          next;
 439  431       } # if -
 440            if (m|^\s*\+\s*(\w+)\s*=\s*(.+\S)\s*|) {
      432       if (m|^\s*\+\s*(\w+)\s*=\s*(.*\S?)\s*|) {
 441  433          my $key = $1;
 442  434          my $value = $2;
 443  435          $config{$host}->{$key} = $value;
 444  436       }
 445  437    } # while CONFIG
 446  438    #print Dumper (%config);
 447  439    # Verify contents are good (enough)
 448  440    my $problems = "";
 449  441    foreach my $computer (keys %config) {
 450  442       foreach my $neededKey (@neededKeys) {
 451  443          if (! $config{$computer}->{$neededKey}) {
 452  444             $problems .= "$computer:$neededKey ";
 453  445          }
 454  446       } # foreach neededkey
 455  447    } # foreach computer
 456  448    if ($problems) {
 457  449       print "Configuration not valid: $problems\n";
 458  450       die;
 459  451    }
 460  452    $mode = $query->param ('mode') || "";
 461  453    if (! $mode ) {
 462  454       $host = $ENV{HOSTNAME} || `hostname`;
 463  455       my $default = "";
 464  456       my $found = "";
 465  457       foreach my $computer (keys %config) {
 466  458          my $matches = $config{$computer}->{'hostname'};
 467  459          if ($matches eq '__DEFAULT__') {
 468  460             $default = $computer;
 469  461             next;
 470  462          }
 471  463          foreach my $match (split /\s+/, $matches) {
 472  464             if ($host =~ /$match/) {
 473  465                $found = "true";
 474  466                $mode = $computer;
 475  467                last;
 476  468             } # if match
 477  469          } # foreach match
 478  470          last if $found;
 479  471       } # foreach mode
 480  472       $mode = $default if ! $found;
 481  473    }
 482  474    $hashRef = $config{$mode};
 483  475    if (! $hashRef) {
 484  476       print "Illegal configuration: $mode\n";
 485  477       die;
 486  478    }
 487  479    # make sure all of the parameters being passed in pass their checks
 488  480    @neededParams = split /\s+/, $hashRef->{'needed'};
 489         $okfile   = $hashRef->{'okfile'};
      481    $okfile   = $hashRef->{'okfile'} || "";
 490  482    unshift @neededParams, 'name';
 491  483 }
 492  484 sub getDirInfo {
 493  485    # has this already been called?
 494  486    if ($basedir) {
 495  487       # We've already figured this out.  Just return what we've got
 496  488       return ($basedir, $htmlbase);
 497  489    }
 498  490    my %paramHash;
 499  491    foreach my $param (@neededParams) {
 500  492       $paramHash{$param} = $query->param ($param) || "";
 501  493       $paramHash{$param} =~ s|\.\./||g;
 502  494       #print "param $param:$paramHash{$param}\n";
 503  495       my @checks = split /\s+/, $hashRef->{"$param\_checks"} || "";
 504  496       foreach my $check (@checks) {
 505  497          if ( $paramHash{$param} !~ m|$check| ) {
 506  498             error ("Parameter '$param:$paramHash{$param}' ".
 507  499                    "failed check '$check'");
 508  500          } # if failed check
 509  501       } # foreach check
 510  502       $defaults{$param}    = $hashRef->{"$param\_default"} || "";
 511  503       $description{$param} = $hashRef->{"$param\_descrip"} || "";
 512  504    } # foreach param
 513         $okfile   = $hashRef->{'okfile'};
      505    $okfile   = $hashRef->{'okfile'} || "";
 514  506    $basedir  = $hashRef->{'basedir'};
 515  507    $htmlbase = $hashRef->{'htmlbase'};
 516  508    my $basedir_tilda  = $hashRef->{'basedir_tilda'}  || "";
 517  509    my $htmlbase_tilda = $hashRef->{'htmlbase_tilda'} || "";
 518  510    foreach my $param (@neededParams) {
 519  511       $basedir        =~ s|\{$param\}|$paramHash{$param}|g;
 520  512       $htmlbase       =~ s|\{$param\}|$paramHash{$param}|g;
 521  513       $basedir_tilda  =~ s|\{$param\}|$paramHash{$param}|g;
 522  514       $htmlbase_tilda =~ s|\{$param\}|$paramHash{$param}|g;      
 523  515    } # foreach param
 524  516    if ($basedir_tilda) {
 525  517       $basedir =~ s|~(\w+)|eval ($basedir_tilda)|ge;
 526  518    } # if basedir_tilda
 527  519    if ($htmlbase_tilda) {
 528  520       $htmlbase =~ s|~(\w+)|eval ($htmlbase_tilda)|ge;
 529  521    } # if htmlbase_tilda
 530  522    if ($htmlbase !~ m|^https?://|) {
 531  523       $htmlbase = "http://".$htmlbase;
 532  524    }
 533  525    return $basedir, $htmlbase;
 534  526 }
 535  527 sub testConfig {
 536  528    printQueryHeader();
 537  529    my $name = name (asis => "true");
 538  530    #print "<link rel =\"stylesheet\" type=\"text/css\" href =\"$htmlbase/elog.css\">\n";
 539  531    print "<title>Elog Test Configuration</title>\n";
 540  532    print "   <h1>Elog Test Configuration</h1>\n";
 541  533    print "<pre>\n";
 542  534    print "host:     $host\n";
 543  535    print "mode:     $mode\n";
 544  536    print "name:     $name\n" if $name;
 545  537    getDirInfo();
 546  538    print "basedir:  $basedir\n";
 547  539    print "htmlbase: $htmlbase\n";
 548  540    print "okfile:   $okfile\n";
 549  541    print "needed:   @neededParams\n";
 550  542    print "Defaults:\n",     Dumper (%defaults);
 551  543    print "Descriptions:\n", Dumper (%description);
 552  544    print "</pre>\n";
 553  545 }
 554  546 BEGIN {
 555  547    $query = new CGI;
 556  548    chomp ($host = $ENV{HOSTNAME} || `hostname`);
 557  549    loadConfigFile();
 558  550    set_message("Please <a href=\"&#x6d;&#x61;&#105;&#x6c;&#116;&#111;&#x3a;&#99;&#112;&#x6c;&#97;&#103;&#x65;&#114;&#43;&#67;&#x4c;&#x50;&#69;&#x6c;&#x6f;&#103;&#64;&#102;&#110;&#97;&#x6c;&#x2e;&#103;&#x6f;&#118;&#63;&#115;&#x75;&#x62;&#x6a;&#x65;&#x63;&#116;&#61;&#x45;&#x4c;&#111;&#103;&#32;&#69;&#x72;&#114;&#x6f;&#x72;&#32;&#111;&#x72;&#x20;&#x57;&#x61;&#x72;&#110;&#105;&#110;&#103; \">email Charles Plager</a> the details of the problem (<i>e.g.,</i> the HTML address and the error or warning message).");
 559  551 }
 560  552 1;