Files
resatennis_tyroltenn/www/cgi-bin/Demos/DEMO_http.pl

163 lines
5.0 KiB
Perl
Executable File

#!/usr/sbin/perl
#**************************************************************************
#* *
#* Copyright (c) 1996 Silicon Graphics, Inc. *
#* All Rights Reserved *
#* *
#* THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF SGI *
#* *
#* The copyright notice above does not evidence any actual of intended *
#* publication of such source code, and is an unpublished work by Silicon *
#* Graphics, Inc. This material contains CONFIDENTIAL INFORMATION that is *
#* the property of Silicon Graphics, Inc. Any use, duplication or *
#* disclosure not specifically authorized by Silicon Graphics is strictly *
#* prohibited. *
#* *
#* RESTRICTED RIGHTS LEGEND: *
#* *
#* Use, duplication or disclosure by the Government is subject to *
#* restrictions as set forth in subdivision (c)(1)(ii) of the Rights in *
#* Technical Data and Computer Software clause at DFARS 52.227-7013, *
#* and/or in similar or successor clauses in the FAR, DOD or NASA FAR *
#* Supplement. Unpublished - rights reserved under the Copyright Laws of *
#* the United States. Contractor is SILICON GRAPHICS, INC., 2011 N. *
#* Shoreline Blvd., Mountain View, CA 94039-7311 *
#**************************************************************************
# DEMO_http.pl
#
# routines to parse CGI input, generate http safe strings, etc
1; # Return true
# Read data in from the user with either GET or POST. If they are using multiple
# selections, add these elements into one variable split by newline.
sub ReadParse {
local (*in) = @_ if @_;
local ($i, $key, $val);
# Read in text
if (&MethGet) {
$in = $ENV{'QUERY_STRING'};
} elsif (&MethPost) {
read(STDIN,$in,$ENV{'CONTENT_LENGTH'});
}
# Split text on the "&"
@in = split(/[&;]/,$in);
foreach $i (0 .. $#in) {
# Convert plus's to spaces
$in[$i] =~ s/\+/ /g;
# Convert hexadecimal numbers
$in[$i] =~ s/%(..)/pack("c",hex($1))/ge;
# Split into key and value.
($key, $val) = split(/=/,$in[$i],2); # splits on the first =.
# Make associative array, with check for multiple selections
if($in{$key}) { $in{$key} .= "\n$val" }
else { $in{$key} = $val; }
}
return scalar(@in);
}
# MethGet
# Return true if this cgi call was using the GET request, false otherwise
sub MethGet {
return ($ENV{'REQUEST_METHOD'} eq "GET");
}
# MethPost
# Return true if this cgi call was using the POST request, false otherwise
sub MethPost {
return ($ENV{'REQUEST_METHOD'} eq "POST");
}
sub alpha {
local(@lowerCase, @indexes, $i, %mixedCase, @output);
@lowerCase = @_;
@indexes = @_;
grep( (tr/A-Z/a-z/) , @lowerCase);
foreach $i (0..$#lowerCase) {
$mixedCase{$lowerCase[$i]} = $indexes[$i];
}
for (sort keys(%mixedCase) ) {
push(@output, $mixedCase{$_});
}
undef @lowerCase;
undef @indexes;
undef $i;
undef %mixedCase;
return(@output);
}
sub Print_HTTP_Header {
print "HTTP/1.0 200 OK\n";
print "Content-type: text/html\n";
print "Server: $ENV{'SERVER_SOFTWARE'}\n\n";
print "<html>\n<head>\n";
print "<title>$_[0]</title>\n";
print "</head>\n" if (!$_[1]);
}
sub Print_HTTP_Refresh_NPH {
print "HTTP/1.0 200 OK\n";
print "Content-type: text/html\n";
print "Server: $ENV{'SERVER_SOFTWARE'}\n\n";
print "<html>\n";
$refreshString = "$REFRESH_WAIT_TIME; URL=http:$WWW_SCRIPT?";
$refreshString .= "$CGI_SWITCH=$FRAME_DIAG&$CGI_SUB_SWITCH=$CGI_UPDATE_FLAG";
# $refreshString .= "&$CGI_AUDIO_SWITCH=$CGI_AUDIO_ON_FLAG" if (&Is_Audio_On);
# print "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"$refreshString\">\n";
print "<head>\n";
print "<title>BLANK</title>\n";
print "</head>\n";
}
sub Print_HTTP_Location {
print "Location: $WWW_SCRIPT\n\n";
}
sub Print_HTTP_Refresh {
print "Content-type: text/html\n\n";
print "<html>\n";
$refreshString = "$REFRESH_WAIT_TIME; URL=http:$WWW_SCRIPT?";
$refreshString .= "$CGI_SWITCH=$FRAME_DIAG&$CGI_SUB_SWITCH=$CGI_UPDATE_FLAG";
# $refreshString .= "&$CGI_AUDIO_SWITCH=$CGI_AUDIO_ON_FLAG" if (&Is_Audio_On);
# print "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"$refreshString\">\n";
print "<head>\n";
print "<title>BLANK</title>\n";
print "</head>\n";
}
sub Print_HTTP_No_Content {
print "HTTP/1.0 204 Nothin Doing\n";
print "Content-type: text/html\n";
print "Server: $ENV{'SERVER_SOFTWARE'}\n\n";
}
sub Print_HTTP_Footer {
print "</body>\n</html>\n";
}
sub Insert_For_Space {
$_[0] =~ s/\s/$_[1]/g;
return($_[0]);
}
sub HTTP_Syntax {
local($string);
$string = $_[0];
$string =~ s/\s+/$HTTP_GET_DELIM/g;
return($string);
}