#!/usr/local/bin/perl ########################################################################### ## ## ## Simplex Database v1.24 ## ## (c) Copyright 2003 Black Jester Pty. Ltd. (trading as Aborior). ## ## All rights reserved. ## ## ## ## Governs all Simplex application pages. ## ## ## ########################################################################### ## The two lines below this paragraph should be uncommented only if you ## are on a Windows NT or 2000 server. Do this by removing the two hashes ## and space ('## ') from the beginning of each line. Then, change the ## path in each line to the correct system path of your 'datacgi' directory. ## When entering the system path, use forward slashes to separate directory ## names, not backslashes as you may be used to. ## ## chdir 'c:/Inetpub/wwwroot/cgi-bin/datacgi'; ## push (@INC, 'c:/Inetpub/wwwroot/cgi-bin/datacgi'); #use Benchmark; #$timestamp1 = new Benchmark; require 'libs/simpsubs.cgi'; require 'libs/appsubs.cgi'; &ReadParse(1, 1); if ($fileset{LOCKDOWN} eq 'On') { quitit (($fileset{LOCKDOWNMESSAGE} or 'This application is currently under maintenance. Please try again later.'), 1); } $includes = 0; local %include = %in; $cachehits = 1; if ($in{form} ne '') { $object = "$in{form}.fh"; $include{part} = 'handler'; } elsif ($in{report} ne '') { $object = "$in{report}.rh"; } if (&CheckAccess ($object)) { my $cachelog = ''; # Status of page to write in access log if ($fileset{CACHEPAGES} eq 'On') { # Attempt to recover cached version #my $request = $ENV{QUERY_STRING}; my $request = $formdata; $request =~ s/\&?cache=\w+//g; if (length ($request) > 250) { $request =~ s/^(.{250}).+?$/$1/g; # Will be used as file name, so truncate to within file name length limit } if (exists $include{cache}) { $cachestatus = $include{cache}; delete $include{cache}; } if ($ENV{REQUEST_METHOD} eq 'GET' and -e "admin/temp/cache/$request.html" and $cachestatus ne 'refresh' and $cachestatus ne 'kill' and $cachestatus ne 'no' and $request !~ /(?:^|&)(?:user|pass|user_?name|pass_?word|e_?mail|form)=/i and (stat("admin/temp/cache/$request.html"))[9] > time - $fileset{CACHELIFE} * 60) { # Alive cache page exists print "HTTP/1.0 200 OK\n" if ($ENV{PerlXS} eq PerlIS); print "Content-type: text/html\n\n"; open (CACHEPAGE, "admin/temp/cache/$request.html") or quitit ("Could not open cached page [admin/temp/cache/$request.html].", 1); while () { print; } close CACHEPAGE; # Record cached hit if (!-e "admin/temp/cache/$request.dat") { undef $!; # -e has erred open (CACHEHITS, ">admin/temp/cache/$request.dat") or quitit ("Could not create cached hits file [admin/temp/cache/$request.dat].", 1); close CACHEHITS; chmod (0666, "admin/temp/cache/$request.dat"); } open (CACHEHITS, "+; chomp $hits; $hits ++; seek (CACHEHITS, 0, 0); print CACHEHITS "$hits\n"; close CACHEHITS; $cachelog = ' (cache)'; # Write trace of cache in log } else { undef $!; # -e in if above may have erred # No cached page, or cache page expired # Get number of cached hits if (-e "admin/temp/cache/$request.dat") { open (CACHEHITS, "admin/temp/cache/$request.dat") or quitit ("Could not open cached hits file [admin/temp/cache/$request.dat].", 1); $cachehits = int(); # Global variable so that can be replaced close CACHEHITS; $cachehits ++; # Record this hit } undef $!; # -e may have erred unlink "admin/temp/cache/$request.dat"; # No longer required $template = &IncludeObject; # Wrap up replacements &SetCookies(\$template); &ReplaceCode(\$template, 1); &ReplaceCache(\$template); &ConditionalCheck(\$template); &StripTags(\$template); # Strip remaining comment tags &FinalParse(\$template); &UndoParseErrors(\$template); # Print report print "HTTP/1.0 200 OK\n" if ($ENV{PerlXS} eq PerlIS); print "Content-type: text/html\n\n"; print $template; # Drop timed-out cache pages if ($cachestatus eq 'kill') { if (-e "admin/temp/cache/$request.html") { unlink "admin/temp/cache/$request.html"; } if (-e "admin/temp/cache/$request.dat") { unlink "admin/temp/cache/$request.dat"; } undef $!; # -e may have erred } opendir (CACHE, 'admin/temp/cache'); my @files = readdir CACHE; closedir CACHE; @files = grep (/(?:^|\&)file=$in{file}(?:\&.*?)?\.html$/, @files); # Don't drop hits files, or pages from other applications foreach $key (@files) { if ((stat ("admin/temp/cache/$key"))[9] <= time - $fileset{CACHELIFE} * 60) { unlink "admin/temp/cache/$key"; } } # Cache page for future use unless ($cachestatus eq 'no' or $cachestatus eq 'kill' or $ENV{REQUEST_METHOD} ne 'GET') { open (CACHEPAGE, ">admin/temp/cache/$request.html") or quitit ("Could not write cached page [admin/temp/cache/$request.html].", 1); filelock (CACHEPAGE); print CACHEPAGE $template; close CACHEPAGE; chmod (0666, "admin/temp/cache/$request.html"); } } } else { $template = &IncludeObject; # Wrap up replacements &SetCookies(\$template); &ReplaceCode(\$template, 1); &ReplaceCache(\$template); &ConditionalCheck(\$template); &StripTags(\$template); # Strip remaining comment tags &FinalParse(\$template); &UndoParseErrors(\$template); # Print report print "HTTP/1.0 200 OK\n" if ($ENV{PerlXS} eq PerlIS); print "Content-type: text/html\n\n"; print $template; } # Check status of search engine front collection if (-e "admin/data/$in{file}.log" and -s "admin/data/$in{file}.log" < 20 * 1024 ** 2) { # Search engine front collection is active, and log has room (20 MB max limit on log) my $request = $ENV{QUERY_STRING}; # Note, only GET requests accepted, POST implies forms usually, which we don't want $request =~ s/file=\w*\&?//g; # We know the file, so we don't need that in the request if ($request ne '' and $request !~ /(?:^|&)(?:user|pass|user_?name|pass_?word|e_?mail|form|session|token)=/i) { # Strip as many requests as possible with security or personal information open (SEARCHENGLOG, ">>admin/data/$in{file}.log"); filelock (SEARCHENGLOG); print SEARCHENGLOG "$request\n"; close SEARCHENGLOG; } } undef $!; # -e may have erred # Log this request if (-s "admin/data/accesslog.log" < 20 * 1024 ** 2) { # 20 MB limit imposed open (ACCESSLOG, ">>admin/data/accesslog.log"); filelock (ACCESSLOG); my $logobject = (length $object) ? "$in{file}.$object" : 'No object'; my $logaddr = (length $ENV{REMOTE_ADDR}) ? $ENV{REMOTE_ADDR} : 'No IP'; print ACCESSLOG &DateString(time) . ' ' . &TimeString(time) . ", $logaddr, $logobject$cachelog\n"; close ACCESSLOG; } } ENDOFFILE: #$timestamp2 = new Benchmark; #print '

' . timestr (timediff ($timestamp2, $timestamp1)); &WrapUp;