source: branches/htmlform/cgi-bin/CommonWeb.pm@ 447

Last change on this file since 447 was 447, checked in by Kris Deugau, 14 years ago

/branches/htmlform

Switch all scripts to use CGI::Simple for HTML form data munging
instead of legacy CommonWeb.pm sub. Remove parse_post() sub from
CommonWeb.pm. See #15.

File size: 2.0 KB
Line 
1# ipdb/cgi-bin/CommonWeb.pm
2###
3# SVN revision info
4# $Date$
5# SVN revision $Rev$
6# Last update by $Author$
7###
8
9package CommonWeb;
10
11use strict;
12use warnings;
13use Exporter;
14use 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
28sub 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
49sub printFooter
50{
51 open FILE, "../footer.inc"
52 or croak $!;
53 while (<FILE>)
54 {
55 print;
56 }
57 close FILE;
58}
59
60sub 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
70sub 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
84sub 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.
96sub 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.
1051;
Note: See TracBrowser for help on using the repository browser.