#!/usr/local/bin/perl # # Switching Script # # This script checks the user's operating platform (Mac or Windows) and # switches them to a corresponding page. # # Nagarajan Gopalan # Interactive Media Specialist # Eisenhower National Clearinghouse # The Ohio State University $ENV{'SCRIPT_NAME'} =~ m#(/.*/)(.*)$#; $SCRIPTDIR = $1; $SCRIPT = $2; # Receive and decode information &cgi_receive; &cgi_decode; # Print out usage information if not receiving a URL &print_info unless $FORM{'mac'}; $user_platform = lc($ENV{HTTP_USER_AGENT}); if (index ($user_platform, 'mac') gt 0) {$url = $FORM{'mac'};} elsif (index ($user_platform, 'win') gt 0) {$url = $FORM{'win'};} else {$url = $FORM{'other'};} # Redirect output to requested URL (or updated URL) print <<"EndResponse"; Status: 302 Redirected Content-type: text/html Location: $url Client Redirected The CGI script has redirected your browser to this location. EndResponse exit; sub cgi_receive { if ($ENV{'REQUEST_METHOD'} eq "POST") { read(STDIN, $incoming, $ENV{'CONTENT_LENGTH'}); } else { $incoming = $ENV{'QUERY_STRING'}; } } sub cgi_decode { @pairs = split(/&/, $incoming); foreach (@pairs) { ($name, $value) = split(/=/, $_); $name =~ tr/+/ /; $value =~ tr/+/ /; $name =~ s/%([A-F0-9][A-F0-9])/pack("C", hex($1))/gie; $value =~ s/%([A-F0-9][A-F0-9])/pack("C", hex($1))/gie; #### Strip out semicolons unless for special character $value =~ s/;/$$/g; $value =~ s/&(\S{1,6})$$/&\1;/g; $value =~ s/$$/ /g; $value =~ s/\|/ /g; $value =~ s/^!/ /g; ## Allow exclamation points in sentences #### Skip generally blank fields next if ($value eq ""); #### Allow for multiple values of a single name $FORM{$name} .= ", " if ($FORM{$name}); #### Check to see if input NAME is the URL, i.e. SUBMIT button if ($name =~ m|^\w+:\S+$|) { $FORM{'url'} = $name; } $FORM{$name} .= $value; } } sub print_info { print <<"EndHelp"; Content-type: text/plain This script checks the user's patform: Mac or Windows. It then sends a 300-level HTTP status code to redirect the browser to the appropriate location. The call to this script has the form http://www.enc.org/cdrom-cgi/steve_or_bill.pl?mac=url1&win=url2&other=url3 EndHelp exit; }