#! /usr/bin/perl

use CGI ':standard';
use CGI::Carp "fatalsToBrowser";  
# W. Sterner CS101  -- Homework 5, problem 1

#ASSIGMENT 5
#
#Basic Perl CGI operations
#
#Due: Monday, Feb 21, 11:59:59 pm

#Document status: FINAL
#
#
#1. Write a CGI script that detects the HTTP_USER_AGENT and the 
#HTTP_HOST from the server environment. Your script should produce 
#a simple HTML page indicating whether the user logged on to 
#the page is using either Mozilla/Netscape or Internet Explorer.
#(Suggestion: Use a simple regular expression match that tests
#whether the user-agent includes the string 'MSIE'.  If not, we
#assume it's Netscape/Mozilla.  You may decide to handle other browsers
#as well, but this is not a requirement.) 
#(25 pts.) 


print header, start_html('Tracking What Browsers are Used');
print br;

print '<font style="font-size: 3em">Here is a little web page to ',br;
print 'tell you what browser you are using',br;
print 'and what the IP address of the server is.</font>',br, br;

$IPadd = $ENV{ 'REMOTE_ADDR'};

print '<font style="font-size: 3em">Your Server IP is:   ', "$IPadd",'</font>', br, br;

$browser=$ENV{ 'HTTP_USER_AGENT'} ;
if ($browser =~ m/Safari/ ) {
    print "<font size=7>You are using Safari Browser on a Mac<br />";
    print br,  '<font style="font-size: 1em">Full Data: ',"$browser",' </font>', br, br;
}
elsif ($browser =~ m/MSIE/ ) {
    print "<font size=7>You are using Internet Explorer Browser <br />";
    print br,  '<font style="font-size: 1em">Full Data: ',"$browser",' </font>', br, br;
}
elsif ($browser =~ m/Firefox/ ) {
    print "<font size=7>You are using Firefox Browser <br />";
    print br,  '<font style="font-size: 1em">Full Data: ',"$browser",' </font>', br, br;
}

else {print "<font size=7>Your browser data is: $browser";}



print end_html;
