#!/usr/bin/perl # # ICS 243d - Internet Technology # Spring Quarter 2001 # Roberto Silveira Silva Filho ID# 85849631 # UnixADM daemon # Finl project # # This script receives commands from the browser and redirects # to the appropriate server. It then colects the server output and presents # on the screen. # ------------------------------------------------------------ use LWP; use LWP::Simple; #------------------------------------------------------------- # Collect the review from a given address and a given cuisine # Returns the response content sub collectData { my $address = shift; my $command = shift; $address =~ s/^\s*//; # ltrim $address =~ s/\s*$//; # rtrim # print "

Hostname = ".$address."<\/H3>
\n"; # Create the request my $url = "http://".$address."/?".$command; my $agent = LWP::UserAgent->new(); my $request = HTTP::Request->new(GET => $url); #print "URL requested: $url
\n"; my $response = $agent->request($request); #$response->is_success or next; # used to avoid quit when url is wrong #$response->is_success or die "$url: ",$response->message,"\n"; $response->is_success or print " Server is down:
\n".$response->message."
\n"; return $response->content(); } #----------------------------------------------------------------------------- print "Connection: close\n"; print "Content-type: text/html\n\n"; print "\n"; print " Information Collector \n"; # Get the input for GET method my $buffer = $ENV{'QUERY_STRING'}; #print "Buffer = ".$buffer."
\n"; # Split the name-value pairs my @pairs = split(/&/, $buffer); my %FORM; foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; # Uncomment for debugging purposes #print "Setting $name to $value
\n"; $FORM{$name} = $value; #print "

Testing...
\n"; #print "Pair: ".$FORM{$name}."="; #print $value."
\n"; } $hostname = $FORM{"hostname"}; $command = $FORM{"command"}; $update = $FORM{"update"}; #$hostname = "rodan.ics.uci.edu:16004"; #$command = "finger"; if ( $command eq "activate" ) { print "\n"; getprint("http://".$FORM{"hostname"}."/~rsilvafi/cgi-bin/UnixAdm/server.pl"); } else { ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); my $reloadPage = "http://rodan.ics.uci.edu:8080/~rsilvafi/cgi-bin/UnixAdm/collectInfo.pl?".$buffer; my $execTime = "$hour:$min:$sec"; print ''."\n"; print "\n"; print "
"; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print '

Command

Hostname

Last execution time

Update interval (seconds)

'.$command.'

'.$hostname.'

'.$execTime.'

'.$update.'

'; print "
"; print collectData($hostname.":16004",$command)."
\n"; } print "\n";