#!/usr/bin/perl -Tw use strict; use English; # long names for special variables use CGI qw(:standard); use CGI::Carp 'fatalsToBrowser'; $OUTPUT_AUTOFLUSH = 1; # flush output buffer after each output statement ... # ... slower but helpful for output over the network $OUTPUT_RECORD_SEPARATOR = "\n"; print header; # to generate document-type print XHTMLhead(); middle(); print XHTMLtail(); # -- subroutines follow -- # sub middle { my $real_ID = $REAL_USER_ID || -1; my $effect_ID = $EFFECTIVE_USER_ID || -1; my $real_name = ($real_ID != -1) ? ((getpwuid $real_ID)[0]) : "-- unknown --"; my $effect_name = ($effect_ID != -1) ? ((getpwuid $effect_ID)[0]) : "-- unknown --"; print "

About this CGI program

"; print "

How Is It Being Run?

"; print "

"; print " This program is being run by the user with"; print " ID $real_ID (", $real_name,")"; printf "%s ", ($real_ID == $effect_ID) ?"and" :"but"; print "the effective user ID is $effect_ID (", $effect_name, ")."; print "

"; if ($real_ID != $effect_ID) { print "Therefore the program is running as suid."; } elsif ($real_name =~ /^httpd?/) { print "It looks like the program is being run by the server."; } else { print "It looks like the program is being run under suexec."; } print "

"; print "

Some Other Information About $0

"; print ""; print " "; print " "; my $name; my $value; foreach $name (qw($PROGRAM_NAME $PROCESS_ID $REAL_GROUP_ID $EFFECTIVE_GROUP_ID $REAL_USER_ID $EFFECTIVE_USER_ID $OSNAME)) { ($value = $name) =~ s/(\$\w+)/$1/ee; print ""; } printf "\n", '@ARGV', @ARGV; printf "\n", '$PERL_VERION', $PERL_VERSION; print "
Table of All Values
NameValue
$name $value
%s %s
%s %vd
"; } # middle() sub XHTMLhead { return << 'EOHTML' CGI interrogation for Dal CS 4173 : Web-centric Computing

Web-centric Computing

Example Code

EOHTML ; } # XHTMLhead() sub XHTMLtail { return << 'EOHTML'
http://www.cs.dal.ca/~jamie/cgi-bin/4173/about/about.cgi
Version:
14 October 2001
Source code:
examples/CGI/about.source
CS 4173 Prof:
J. Blustein <jamie@cs.dal.ca>

Valid XHTML 1.0!

EOHTML } # XHTMLtail() ## End of Example ##