1 | # ipdb/cgi-bin/CommonWeb.pm
|
---|
2 | ###
|
---|
3 | # SVN revision info
|
---|
4 | # $Date$
|
---|
5 | # SVN revision $Rev$
|
---|
6 | # Last update by $Author$
|
---|
7 | ###
|
---|
8 |
|
---|
9 | package CommonWeb;
|
---|
10 |
|
---|
11 | use strict;
|
---|
12 | use warnings;
|
---|
13 | use Exporter;
|
---|
14 | use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
|
---|
15 |
|
---|
16 | $VERSION = 1.00;
|
---|
17 | @ISA = qw(Exporter);
|
---|
18 | @EXPORT_OK = qw(&printFooter &printHeader &printError &printAndExit &desanitize &cleanInput &desanitize);
|
---|
19 |
|
---|
20 | @EXPORT = (); #export nothing by default
|
---|
21 | %EXPORT_TAGS = ( ALL => [qw( &printFooter &printHeader &printError
|
---|
22 | &printAndExit &desanitize &cleanInput )],
|
---|
23 | lean => [qw( &printFooter &printHeader &printError
|
---|
24 | &printAndExit &cleanInput )]
|
---|
25 | );
|
---|
26 |
|
---|
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 | }
|
---|
48 |
|
---|
49 | sub printFooter
|
---|
50 | {
|
---|
51 | open FILE, "../footer.inc"
|
---|
52 | or croak $!;
|
---|
53 | while (<FILE>)
|
---|
54 | {
|
---|
55 | print;
|
---|
56 | }
|
---|
57 | close FILE;
|
---|
58 | }
|
---|
59 |
|
---|
60 | sub printError($)
|
---|
61 | {
|
---|
62 | my $errStr = $_[0];
|
---|
63 | print qq(
|
---|
64 | <center><p class="regular"> $errStr </p>
|
---|
65 | <input type="button" value="Back" onclick="history.go(-1)">
|
---|
66 | </center>
|
---|
67 | );
|
---|
68 | }
|
---|
69 |
|
---|
70 | sub printAndExit($)
|
---|
71 | {
|
---|
72 | my $errStr = $_[0];
|
---|
73 | print qq(
|
---|
74 | <center><p class="regular"> $errStr </p>
|
---|
75 | <input type="button" value="Back" onclick="history.go(-1)">
|
---|
76 | </center>
|
---|
77 | );
|
---|
78 | printFooter();
|
---|
79 | exit(0);
|
---|
80 | }
|
---|
81 |
|
---|
82 | # needs a reference to the webvar hash.
|
---|
83 | # takes out backticks and single quotes
|
---|
84 | sub cleanInput($)
|
---|
85 | {
|
---|
86 | my $hashRef = $_[0];
|
---|
87 |
|
---|
88 | foreach my $key (keys %$hashRef)
|
---|
89 | {
|
---|
90 | $hashRef->{$key} =~ s/`/\\`/g;
|
---|
91 | $hashRef->{$key} =~ s/'/\'/g;
|
---|
92 | }
|
---|
93 | }
|
---|
94 |
|
---|
95 | # undoes clean input. takes a string as an arg.
|
---|
96 | sub desanitize($)
|
---|
97 | {
|
---|
98 | my $string = $_[0];
|
---|
99 | $string =~ s/\\`/`/g;
|
---|
100 | $string =~ s/\\'/'/g;
|
---|
101 | return $string;
|
---|
102 | }
|
---|
103 |
|
---|
104 | # indicate that the module loaded okay.
|
---|
105 | 1;
|
---|