[8] | 1 | # ipdb/cgi-bin/CommonWeb.pm
|
---|
| 2 | ###
|
---|
| 3 | # SVN revision info
|
---|
| 4 | # $Date: 2004-12-01 20:42:57 +0000 (Wed, 01 Dec 2004) $
|
---|
| 5 | # SVN revision $Rev: 94 $
|
---|
| 6 | # Last update by $Author: kdeugau $
|
---|
| 7 | ###
|
---|
| 8 |
|
---|
[4] | 9 | package CommonWeb;
|
---|
| 10 |
|
---|
| 11 | # 08/13/2004 kdeugau@vianet
|
---|
| 12 | # Split DB-related functions into new module; they're not
|
---|
| 13 | # specific to CGI/web stuff.
|
---|
| 14 |
|
---|
| 15 | use strict;
|
---|
| 16 | use warnings;
|
---|
| 17 | use Exporter;
|
---|
| 18 | use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
|
---|
| 19 |
|
---|
| 20 | $VERSION = 1.00;
|
---|
| 21 | @ISA = qw(Exporter);
|
---|
| 22 | @EXPORT_OK = qw(&parse_post &printFooter &printHeader &printError &printAndExit &desanitize &cleanInput &desanitize);
|
---|
| 23 |
|
---|
| 24 | @EXPORT = (); #export nothing by default
|
---|
| 25 | %EXPORT_TAGS = ( ALL => [qw( &parse_post &printFooter &printHeader &printError
|
---|
| 26 | &printAndExit &desanitize &cleanInput )],
|
---|
| 27 | lean => [qw( &parse_post &printFooter &printHeader &printError
|
---|
| 28 | &printAndExit &cleanInput )]
|
---|
| 29 | );
|
---|
| 30 |
|
---|
| 31 | sub parse_post {
|
---|
| 32 | my $buffer;
|
---|
| 33 | if ($ENV{'REQUEST_METHOD'} eq "GET") {
|
---|
| 34 | $buffer=$ENV{'QUERY_STRING'}
|
---|
| 35 | } elsif ($ENV{'REQUEST_METHOD'} eq 'POST' && $ENV{'CONTENT_TYPE'} eq "application/x-www-form-urlencoded") {
|
---|
| 36 | read(STDIN, $buffer, $ENV{CONTENT_LENGTH});
|
---|
| 37 | } else {
|
---|
| 38 | $buffer = $ENV{'QUERY_STRING'};
|
---|
| 39 | $buffer || read(STDIN, $buffer, $ENV{CONTENT_LENGTH});
|
---|
| 40 | }
|
---|
| 41 | my @pairs = split(/&/, $buffer);
|
---|
| 42 | my %webvarLocal;
|
---|
| 43 | foreach my $pair (@pairs) {
|
---|
| 44 | my ($name, $value) = split(/=/, $pair);
|
---|
| 45 | $name =~ tr/+/ /;
|
---|
| 46 | $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
|
---|
| 47 | $value =~ tr/+/ /;
|
---|
| 48 | $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
|
---|
| 49 | $value =~ s/\'/\\\'/g;
|
---|
| 50 | $webvarLocal{$name} = $value;
|
---|
| 51 | }
|
---|
| 52 | return %webvarLocal;
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 | sub printHeader($) #(cgiurl)
|
---|
| 56 | {
|
---|
| 57 | my $cgiURL = $_[0];
|
---|
| 58 | print "Content-type: text/html\n\n";
|
---|
| 59 | open(FILE, "../header.inc") || die $!;
|
---|
| 60 | while (<FILE>)
|
---|
| 61 | {
|
---|
| 62 | $_ =~ s/\$\$CGIURL\$\$/$cgiURL/g;
|
---|
| 63 | print $_;
|
---|
| 64 | }
|
---|
| 65 | close(FILE);
|
---|
| 66 | }
|
---|
| 67 |
|
---|
| 68 | sub printFooter
|
---|
| 69 | {
|
---|
| 70 | open FILE, "../footer.inc"
|
---|
| 71 | or croak $!;
|
---|
| 72 | while (<FILE>)
|
---|
| 73 | {
|
---|
| 74 | print;
|
---|
| 75 | }
|
---|
| 76 | close FILE;
|
---|
| 77 | }
|
---|
| 78 |
|
---|
| 79 | sub printError($)
|
---|
| 80 | {
|
---|
| 81 | my $errStr = $_[0];
|
---|
| 82 |
|
---|
| 83 | print qq(
|
---|
| 84 | <p>There was an error: $errStr</p>
|
---|
| 85 | );
|
---|
| 86 |
|
---|
| 87 | printFooter();
|
---|
| 88 | exit(0);
|
---|
| 89 | }
|
---|
| 90 |
|
---|
| 91 | sub printAndExit($)
|
---|
| 92 | {
|
---|
| 93 | my $errStr = $_[0];
|
---|
| 94 | print qq(
|
---|
| 95 | <center><p class="regular"> $errStr </p>
|
---|
| 96 | <input type="button" value="Back" onclick="history.go(-1)">
|
---|
| 97 | </center>
|
---|
| 98 | );
|
---|
| 99 | printFooter();
|
---|
| 100 | exit(0);
|
---|
| 101 | }
|
---|
| 102 |
|
---|
| 103 | sub loginAgain
|
---|
| 104 | {
|
---|
| 105 | print qq(
|
---|
| 106 | <center><p>Your session has expired. Please login again.</p>
|
---|
| 107 | <p>
|
---|
| 108 | <a href="http://hosttest.vianet.ca"> Click here to login again.</a>
|
---|
| 109 | </p>
|
---|
| 110 | </center>
|
---|
| 111 | );
|
---|
| 112 | printFooter();
|
---|
| 113 | exit(0);
|
---|
| 114 | }
|
---|
| 115 |
|
---|
| 116 | # needs a reference to the webvar hash.
|
---|
| 117 | # takes out backticks and single quotes
|
---|
| 118 | sub cleanInput($)
|
---|
| 119 | {
|
---|
| 120 | my $hashRef = $_[0];
|
---|
| 121 |
|
---|
| 122 | foreach my $key (keys %$hashRef)
|
---|
| 123 | {
|
---|
| 124 | $hashRef->{$key} =~ s/`/\\`/g;
|
---|
| 125 | $hashRef->{$key} =~ s/'/\'/g;
|
---|
| 126 | }
|
---|
| 127 | }
|
---|
| 128 |
|
---|
| 129 | # undoes clean input. takes a string as an arg.
|
---|
| 130 | sub desanitize($)
|
---|
| 131 | {
|
---|
| 132 | my $string = $_[0];
|
---|
| 133 | $string =~ s/\\`/`/g;
|
---|
| 134 | $string =~ s/\\'/'/g;
|
---|
| 135 | return $string;
|
---|
| 136 | }
|
---|
| 137 |
|
---|
| 138 | # indicate that the module loaded okay.
|
---|
| 139 | 1;
|
---|