# # util.pl # Copyright (c) 1996 SurfUtah.Com # written by Rus Berrett # # utilities file with common subroutines # used by pretty much all of the library CGI scripts # ############################################################################## # common subroutines ############################################################################## ################################################ # get the variables by calling parse_form_data # for example, "&parse_form_data(*array)" # thanks Stacey :) sub parse_form_data { local (*FORM_DATA) = @_; local ($request_method, $query_string, @key_value_pairs, $key_value, $key, $value); $request_method = $ENV{'REQUEST_METHOD'}; if ($request_method eq "GET") { $query_string = $ENV{'QUERY_STRING'}; } elsif ($request_method eq "POST") { read(STDIN, $query_string, $ENV{'CONTENT_LENGTH'}); } else { # neither POST nor GET $query_string = $ENV{'QUERY_STRING'}; } @key_value_pairs = split(/&/, $query_string); foreach $key_value (@key_value_pairs) { ($key, $value) = split (/=/, $key_value); $key =~ tr/+/ /; $value =~ tr/+/ /; $value =~ s/%([\dA-Fa-f][\dA-Fa-f])/pack ("C", hex($1))/eg; if (defined($FORM_DATA{$key})) { $FORM_DATA{$key} = join("|", $FORM_DATA{$key}, $value); } else { $FORM_DATA{$key} = $value; } } } ################################################ # print the footer information sub print_footer_info { print "\n"; print "\n"; print "\n"; # print out the copyright footer # NOTE TO RESELLERS/CLIENTS: this is a library specific file, # delete or comment out for you own use if (-e "/www/htdocs/includes/copyright.txt") { open(COPYRIGHT, "/www/htdocs/includes/copyright.txt"); while () { print $_; } close(COPYRIGHT); } # print out the colorstrip footer # NOTE TO RESELLERS/CLIENTS: this is a library specific file, # delete or comment out for you own use if (-e "/www/htdocs/includes/colorstrip.txt") { open(COLORSTRIP, "/www/htdocs/includes/colorstrip.txt"); while () { print $_; } close(COLORSTRIP); } print "\n"; # close it out print "\n"; } ################################################ # print the header information sub print_header_info { local ($title) = @_; print "Content-type: text/html\n\n"; # print out the title print "\n"; print " \n"; print "$title\n"; if (-e "/www/htdocs/includes/javascript/main.js") { print "\n"; } print " \n"; # print out the header, which should include a tage if (-e "/www/htdocs/includes/body.txt") { open(BODY, "/www/htdocs/includes/body.txt"); while () { print $_; } close(BODY); } else { print "\n"; } # print out the toolbar # NOTE TO RESELLERS/CLIENTS: this is a library specific file, # delete or comment out for you own use if (-e "/www/htdocs/includes/toolstrip/support_sub.txt") { open(TOOLBAR, "/www/htdocs/includes/toolstrip/support_sub.txt"); while () { print $_; } close(TOOLBAR); } print < ENDHEADER } ################################################ # print an error sub return_error { local ($message) = @_; print <

Unknown Error

An unknown error has been encountered. The error message is listed below:

    $message

ENDERROR &print_footer_info(); exit(1); } ############################################################################## # eof util.pl 1;