<%@ page import="com.cyscape.browserhawk.*" %>
<%@ page import="java.io.*" %>

<%--
  browserinfo.jsp
  Created by cyScape, Inc.

  Permission to use and modify the contents of this script for your own
  purposes is hereby granted provided you have a licensed or active 
  evaluation copy of BrowserHawk on the machine this script is used on.

  Copyright (c) 2000-2006 cyScape, Inc.  All rights reserved.

  The purpose of this script is to automatically collect details about a
  visitor's browser to assist with the troubleshooting of browser 
  compatibility issues reported.  By default this script collects 
  information on browser type and version, installed plug-ins, disabled 
  cookies/JavaScript/applets, screen size, color depth, and much more.
 
  NOTE: THIS SCRIPT IS AN EXAMPLE TO HELP YOU GET UP AND RUNNING QUICKLY WITH
  A BROWSER TROUBLESHOOTING PAGE.  HOWEVER THERE ARE MANY REFINEMENTS YOU 
  SHOULD CONSIDER BEFORE USING IT ON A PRODUCTION WEB SITE, SUCH AS FORM
  VALIDATION, BETTER ERROR HANDLING, AND PAGE LAYOUT TO MATCH THE LOOK AND
  FEEL OF YOUR SITE.
--%>

<%
// ------------------- USER CONFIGURATION BEGIN -------------------
// 
// PLEASE READ THROUGH THIS SECTION AND SET VARIABLES AS APPROPRIATE FOR YOUR
// DESIRED USAGE.
// 
// STEP 1
// ------
// Note we specifically don't test for acrobat since it can cause IE to load 
// the Acrobat splash screen.  This is a minor side effect if you need to know 
// whether Acrobat is installed.  However we don't test for it by default for 
// this reason.  If you wish to test for Acrobat change the following variable
// to True
boolean testAcrobat = false;

// STEP 2
// ------
// By default we test the user's connection speed.  If you are not interested
// in this however you should change the variable below to False
boolean testConnectionSpeed = true;

// STEP 3
// ------
// In addition to the main properties we display to the end user and email back
// to us, it may be helpful for you to have a full dump of all the browser
// property settings.  By default we collect this additional information, and 
// although it is not shown to the end user it is transmitted back to us when
// the user submits the troubleshooting form.  If you are not interested in 
// this extra information, set the following variable to false
boolean collectAllDetails = true;

// STEP 4
// ------
// Go to the EMAIL CONFIGURATION SECTION located in the ProcessResults 
// function found in this file to set up your email options so the browser
// settings can be emailed back to you.
// 
// ------------------- USER CONFIGURATION END  -------------------
%>



<%--
  On a GET request, we generate the form;
  on a POST request, we handle the form.
--%>

<%
  if (request.getMethod().equalsIgnoreCase("GET")) {
    try {
      BrowserInfo info = BrowserHawk.getBrowserInfo(request);
    }
    catch (Exception e) {
%>
<html><body>
<h2>Error occurred</h2>
The following exception occurred when trying to create the BrowserHawk object:
<pre>
<%= e %>
</pre>
</body></html>
<%
    }
%>

<%
  // To avoid an exception, we check that the system executing this
  // example has an Enterprise Edition license as required for this test.
  // Note: This is NOT needed in your pages, only for this sample.
  if (BrowserHawk.getVersion().indexOf("Ent") == -1) {
    out.println("Enterprise License Required.  ");
    out.println("You are using " + BrowserHawk.getVersion() + ".  ");
    out.println("See <a href='http://www.cyscape.com/order/'>http://www.cyscape.com/order/</a> for upgrade information.");
    return;
  }
%>

<%--
  Let's get the extended properties including enabled/disabled
  javascript/cookie/applet settings, screen size, plugins, color depth, and
  more.  Note that there are several optional parameters for this method - 
  see the BrowserHawk documentation for important details including how to 
  make this checking look seamless with your site if you change the background
  color.

  For starters, tell BH to execute all its tests (all plugins, connection
  speed, disabled cookies, etc).  Note however that BH detects of 100 
  properties, and checking them all can take several seconds.  Therefore we 
  recommend that you edit this script and make the changes to test only for
  the properties which most interest you.

  If you remove any properties from the test you should also call
  opts.removeProperty() to tell BH not to execute the tests you wish to
  remove.  Otherwise you will be removing the tests from your output but 
  still incurring the cost of the testing time.
--%>
<%
    ExtendedOptions opts = new ExtendedOptions("all");
%>

<%--
  Speed detection is purposesly not included by the 'all' keyword because
  the test can take up to 8 seconds or so for people with slow modems - and 
  'all' of the tests can take several seconds to execute already...  So if 
  we've specifically been told to check for speed, let's add that in
--%>
<%
    if (testConnectionSpeed) {
      opts.addProperty("ConnectionSpeed");
    }
%>

<%--
  Acrobat detection is by default included in the 'all' keyword, but it can
  cause a pop-up window to appear during testing, so remove it unless the 
  user truly wants it.
--%>
<%
    if (!testAcrobat) {
      opts.removeProperties("Plugin_Acrobat,Plugin_AcrobatVerEx");
    }
%>

<%--
  Run the extended test.  Note we return immediately if we get a null.  A
  null indicates the JavaScript testing code has been sent to the client and
  will come back to us on the following request.
--%>
<%
    ExtendedBrowserInfo einfo =
      BrowserHawk.getExtendedBrowserInfo(request, response, opts);
    if (einfo == null) return;
%>

<%--
  If we get here, we have test data.  Fetch some of it for display in our
  form.  For some values, we translate() the answers into human-friendly
  format.
--%>
<%
    BrowserInfo info = BrowserHawk.getBrowserInfo(request);
    String browType = info.getBrowser();
    String browBuild = einfo.translate("BrowserBuild");
    String browVersion = info.getFullversion();
    String browPlatform = info.getPlatform();

    boolean browActiveXEnabled = einfo.getActiveXEnabled();
    boolean browVBScriptEnabled = einfo.getVBScriptEnabled();

    String browJavaVersion = einfo.translate("JavaVersion");
    String browJavaVendor = einfo.translate("JavaVendor");

    boolean browJavaScriptCapable = info.getJavaScript();
    boolean browJavaScriptEnabled = einfo.getJavaScriptEnabled();

    String browScreenSize = einfo.translate("ScreenSize");
    String browBrowserSize = einfo.translate("BrowserSize");

    boolean browCookiesCapable = info.getCookies();
    String browCookiesEnabled = einfo.translate("Cookies");

    boolean browAppletsCapable = info.getJavaApplets();
    String browAppletsEnabled = einfo.translate("JavaApplets");

    String browPluginFlash = einfo.translate("Plugin_Flash");
    String browPluginShockwave = einfo.translate("Plugin_Director");
    String browPluginMediaPlayer = einfo.translate("Plugin_MediaPlayer");
    String browPluginRealPlayer = einfo.translate("Plugin_RealPlayer");
    String browPluginQuickTime = einfo.translate("Plugin_QuickTime");

    String browConnectionSpeed = einfo.translate("ConnectionSpeed");
    String browConnectionType = einfo.translate("ConnectionType");

    String browColorDepth = einfo.translate("ColorDepth");
    String browDateTime = einfo.translate("BrowserDateTime");
    String browTimeZoneDiff = einfo.translate("Timezonediff");

    String browPluginAcrobat = "Not tested by default";
    if (testAcrobat) {
      browPluginAcrobat = einfo.translate("Plugin_Acrobat");
    }

    String allDetails = "Not configured to collect additional details";
    if (collectAllDetails) {
      allDetails = info.toString() + einfo.toString();
    }
%>

<HTML><HEAD><TITLE>Browser troubleshooting tool</TITLE></HEAD>
<BODY>
<BLOCKQUOTE>
The purpose of this page is to collect information from you that
will assist us in troubleshooting the problem you are having.
Details about your browser have been collected for you automatically 
and are displayed in the table below.  
Please answer the following questions and press the "Report Issue" button.
A support representative will contact you shortly.
<P>

<form method="POST" action="<%= request.getRequestURI() %>">
  <table width=450>
  <tr><td align=right>Name:</td>
      <td><input type="text" name="name" size="30"></td></tr>
  <tr><td align=right>Email:</td>
      <td><input type="email" name="email" size="30"></td></tr>
  <tr><td align=right>Description<br>of problem:</td>
      <td><textarea rows="3" name="desc" cols="40"></textarea></td></tr>
  <tr><td>&nbsp;</td>
      <td align=left><input type="submit" value="Report Issue" name="B1"></td></tr>
  </table>
  <input type="hidden"
   name="browTypeAndVer" value="<%=browType%> <%=browVersion%>">
  <input type="hidden"
   name="browBuild" value="<%=browBuild%>">
  <input type="hidden"
   name="browPlatform" value="<%=browPlatform%>">
  <input type="hidden"
   name="browCookiesCapable" value="<%=browCookiesCapable%>">
  <input type="hidden"
   name="browCookiesEnabled" value="<%=browCookiesEnabled%>">
  <input type="hidden"
   name="browJavaScriptCapable" value="<%=browJavaScriptCapable%>">
  <input type="hidden"
   name="browJavaScriptEnabled" value="<%=browJavaScriptEnabled%>">
  <input type="hidden"
   name="browActiveXEnabled" value="<%=browActiveXEnabled%>">
  <input type="hidden"
   name="browVBScriptEnabled" value="<%=browVBScriptEnabled%>">
  <input type="hidden"
   name="browAppletsCapable" value="<%=browAppletsCapable%>">
  <input type="hidden"
   name="browAppletsEnabled" value="<%=browAppletsEnabled%>">
  <input type="hidden"
   name="browJavaVersion" value="<%=browJavaVersion%>">
  <input type="hidden"
   name="browJavaVendor" value="<%=browJavaVendor%>">
  <input type="hidden"
   name="browScreenSize" value="<%=browScreenSize%>">
  <input type="hidden"
   name="browBrowserSize" value="<%=browBrowserSize%>">
  <input type="hidden"
   name="browConnectionType" value="<%=browConnectionType%>">
  <input type="hidden"
   name="browConnectionSpeed" value="<%=browConnectionSpeed%>">
  <input type="hidden"
   name="browColorDepth" value="<%=browColorDepth%>">
  <input type="hidden"
   name="browPluginFlash" value="<%=browPluginFlash%>">
  <input type="hidden"
   name="browPluginShockwave" value="<%=browPluginShockwave%>">
  <input type="hidden"
   name="browPluginMediaPlayer" value="<%=browPluginMediaPlayer%>">
  <input type="hidden"
   name="browPluginRealPlayer" value="<%=browPluginRealPlayer%>">
  <input type="hidden"
   name="browPluginAcrobat" value="<%=browPluginAcrobat%>">
  <input type="hidden"
   name="browPluginQuickTime" value="<%=browPluginQuickTime%>">
  <input type="hidden"
   name="browAllDetails" value="<%=allDetails%>">
  <input type="hidden"
   name="browDateTime" value="<%=browDateTime%>">
  <input type="hidden"
   name="browTimeZoneDiff" value="<%=browTimeZoneDiff%>">
</form>

<%
    String qs = request.getQueryString();
    if (qs != null && !qs.equals("")) {
%>
    <b>Important</b>: If you change any browser settings you must
    <a href="<%=request.getRequestURI()%>"><b>click here</b></a><br>
    to refresh this data instead of hitting your Reload button.<p>
<%
    }
%>

<font size=-1>User agent: <%= request.getHeader("User-Agent") %> </font><P>

<%
    String c1 = "", c2 = "";
    if (info.getTableBGColor()) {
      c1 = " bgcolor=\"#FFFFFF\"";
      c2 = " bgcolor=\"#F0F0F0\"";
    }
%>

<TABLE width=500 bgcolor="#CCCCCC" BORDER=1 cellpadding=5 cellspacing=2>
<TR<%=c1%>><TD WIDTH=175>Browser type and version</TD> <TD><%=browType%> <%=browVersion%></TD></TR>
<TR<%=c2%>><TD>Browser build</TD> <TD><%=browBuild%></TD></TR>
<TR<%=c1%>><TD>Platform</TD> <TD><%=browPlatform%></TD></TR>
<TR<%=c2%>><TD>Cookies supported</TD> <TD><%=browCookiesCapable%></TD></TR>
<TR<%=c1%>><TD>Cookies enabled</TD> <TD><%=browCookiesEnabled%></TD></TR>
<TR<%=c2%>><TD>JavaScript supported</TD> <TD><%=browJavaScriptCapable%></TD></TR>
<TR<%=c1%>><TD>JavaScript enabled</TD> <TD><%=browJavaScriptEnabled%></TD></TR>
<TR<%=c2%>><TD>ActiveX enabled</TD> <TD><%=browActiveXEnabled%></TD></TR>
<TR<%=c1%>><TD>VBScript enabled</TD> <TD><%=browVBScriptEnabled%></TD></TR>
<TR<%=c2%>><TD>Java applets supported</TD> <TD><%=browAppletsCapable%></TD></TR>
<TR<%=c1%>><TD>Java applets enabled</TD> <TD><%=browAppletsEnabled%></TD></TR>
<TR<%=c2%>><TD>Java Version</TD> <TD><%=browJavaVersion%></TD></TR>
<TR<%=c1%>><TD>Java Vendor</TD> <TD><%=browJavaVendor%></TD></TR>
<TR<%=c2%>><TD>Screen size</TD> <TD><%=browScreenSize%></TD></TR>
<TR<%=c1%>><TD>Browser size</TD> <TD><%=browBrowserSize%></TD></TR>
<TR<%=c2%>><TD>Connection type</TD> <TD><%=browConnectionType%></TD></TR>
<TR<%=c1%>><TD>Connection speed</TD> <TD><%=browConnectionSpeed%></TD></TR>
<TR<%=c2%>><TD>Color depth</TD> <TD><%=browColorDepth%></TD></TR>
<TR<%=c1%>><TD>Flash</TD> <TD><%=browPluginFlash%></TD></TR>
<TR<%=c2%>><TD>Shockwave</TD><TD><%=browPluginShockwave%></TD></TR>
<TR<%=c1%>><TD>MediaPlayer</TD> <TD><%=browPluginMediaPlayer%></TD></TR>
<TR<%=c2%>><TD>RealPlayer</TD><TD><%=browPluginRealPlayer%></TD></TR>
<TR<%=c1%>><TD>Acrobat</TD> <TD><%=browPluginAcrobat%></TD></TR>
<TR<%=c2%>><TD>QuickTime</TD> <TD><%=browPluginQuickTime%></TD></TR>
<TR<%=c1%>><TD>Browser time</TD> <TD><%=browDateTime%></TD></TR>
<TR<%=c2%>><TD>Time zone diff</TD> <TD><%=browTimeZoneDiff%></TD></TR>
</TABLE><P>
Note: BrowserHawk can detect over 100 properties.  This list represents 
just a sample of the properties available. You can easily modify this script
to include other properties.
</BLOCKQUOTE>

<P>
<HR>
<P>

<b><a href="browserinfo.jsp">Retry this test</a></b><P>
<b><a href="index.html">Return to list of other JSP samples</a></b><P>
<b><a href="http://www.cyscape.com/order/">BrowserHawk Pricing and Ordering</a></b><P>
<b><a href="http://www.cyscape.com/">cyScape home page</a></b><P>
</font>
</blockquote>
</BODY>
</HTML>

<%
  } else if (request.getMethod().equalsIgnoreCase("POST")) {
%>

<%--
  Our results processing follows.  It consists of formatting an email message
  to contain the results and then sending it to a support representative for
  follow up.  You of course can easily modify this to write the information
  to a file or database as well.
--%>

<%
// ---- EMAIL CONFIGURATION SECTION -----
// By default this script is programmed to email the test results back to you
// (or your support group) using the com.oreilly.servlet.MailMessage component.
// See http://www.servlets.com/cos/ for the component.
// 
// Before submitting the form written out by this script please be sure to
// install this email component or if you prefer you can easily modify this
// script to use whatever email component you like - just update the 
// code found lower in the source accordingly.  
// 
// Set this to the address where you want the script to email the browser test
// results to

String emailToAddr = "someone@somewhere.com";

// Set this to the address of your SMTP server
String emailSmtpServer = "smtp.somewhere.com";

// After you have edited the above two variables change the emailConfigured
// variable below to true
boolean emailConfigured = false;

// ---- END EMAIL CONFIGURATION SECTION -----
%>

<%
  StringBuffer results = new StringBuffer();
  results.append("The following submission was made on ");
  results.append(new java.util.Date());
  results.append(":\r\n");

  HttpServletRequest r = request;

  results.append("                  Name: " + r.getParameter("name") + "\r\n");
  results.append("                 Email: " + r.getParameter("email") + "\r\n");

  results.append("   Problem description: \r\n" + r.getParameter("desc") + "\r\n");

  results.append("            User agent: " + r.getHeader("User-Agent") + "\r\n");

  results.append("               Browser: " + r.getParameter("browTypeAndVer") + "\r\n");
  results.append("         Browser build: " + r.getParameter("browBuild") + "\r\n");
  results.append("              Platform: " + r.getParameter("browPlatform") + "\r\n");

  results.append("     Cookies supported: " + r.getParameter("browCookiesCapable") + "\r\n");
  results.append("       Cookies enabled: " + r.getParameter("browCookiesEnabled") + "\r\n");

  results.append("  JavaScript supported: " + r.getParameter("browJavaScriptCapable") + "\r\n");
  results.append("    JavaScript enabled: " + r.getParameter("browJavaScriptEnabled") + "\r\n");

  results.append("          Java version: " + r.getParameter("browJavaVersion") + "\r\n");
  results.append("           Java vendor: " + r.getParameter("browJavaVendor") + "\r\n");

  results.append("       ActiveX enabled: " + r.getParameter("browActiveXEnabled") + "\r\n");
  results.append("      VBScript enabled: " + r.getParameter("browVBScriptEnabled") + "\r\n");

  results.append("     Applets supported: " + r.getParameter("browAppletsCapable") + "\r\n");
  results.append("       Applets enabled: " + r.getParameter("browAppletsEnabled") + "\r\n");

  results.append("           Screen size: " + r.getParameter("browScreenSize") + "\r\n");
  results.append("          Browser size: " + r.getParameter("browBrowserSize") + "\r\n");
  results.append("           Color depth: " + r.getParameter("browColorDepth") + "\r\n");

  results.append("      Connection speed: " + r.getParameter("browConnectionSpeed") + "\r\n");
  results.append("       Connection type: " + r.getParameter("browConnectionType") + "\r\n");

  results.append("                 Flash: " + r.getParameter("browPluginFlash") + "\r\n");
  results.append("             Shockwave: " + r.getParameter("browPluginShockwave") + "\r\n");
  results.append("           MediaPlayer: " + r.getParameter("browPluginMediaPlayer") + "\r\n");
  results.append("            RealPlayer: " + r.getParameter("browPluginRealPlayer") + "\r\n");
  results.append("               Acrobat: " + r.getParameter("browPluginAcrobat") + "\r\n");
  results.append("             QuickTime: " + r.getParameter("browPluginQuickTime") + "\r\n");

  results.append("          Browser time: " + r.getParameter("browDateTime")
+ "\r\n");
  results.append("        Time zone diff: " + r.getParameter("browTimeZoneDiff") + "\r\n");

  results.append("\r\n");
  results.append("Dump of all property settings: " + "\r\n");
  results.append(r.getParameter("browAllDetails"));
  boolean emailSent = false;  // don't change this
  Exception emailException = null;   // don't change this
%>


<%--
  * * * * * COMMENT IN THE FOLLOWING BLOCK TO ENABLE EMAIL. * * * * *
  YOU'LL NEED THE "com.oreilly.servlet" LIBRARY FROM
  http://www.servlets.com/cos INSTALLED ON YOUR SYSTEM.
--%>
<%--
  <%@ page import="com.oreilly.servlet.*" %>
  <%
  if (emailConfigured) {
    try {
      MailMessage msg = new MailMessage(emailSmtpServer);
      msg.from(request.getParameter("name") + 
               "<" + request.getParameter("email") + ">");
      msg.to(emailToAddr);
      msg.setSubject("Browser troubleshooting information for " +
                     request.getParameter("name"));
      PrintStream msgout = msg.getPrintStream();
      msgout.println(results.toString());
      msg.sendAndClose();
      emailSent = true;
    }
    catch (Exception e) {
      emailException = e;
    }
  }
  %>
--%>


<%
  if (!emailConfigured) {
%>

<H3>Information NOT sent</H3>
No mail was sent.  This JSP is not yet configured to send email.

<%
  } else if (emailConfigured && !emailSent && emailException == null) {
%>

<H3>Information NOT sent</H3>
No mail was sent.  This is a server issue, most likely
caused by the send mail code for this JSP being commented out.

<%
  } else if (emailConfigured && !emailSent && emailException != null) {
    getServletConfig().getServletContext().log(emailException.toString());
%>

<H3>Information NOT sent</H3>
No mail was sent.  The server logged an exception.

<%
  } else {
%>

<blockquote>
<H3>Information sent</H3>
Your submission has been successfully sent.  Thank you for reporting this
issue.  A support representative will get back to you shortly.
<p>
DEBUG: Here's the message that was sent:
<pre>
<%= results %>
</pre>
</blockquote>

<%
  } // end the else
%>

</body></html>

<%
  }
%>
