<%
/********************************************************************************************************
*	Name			:	EgCSCLicenseReport.jsp
*	Purpose			:	To decrypt CSC license file
*	CreationDate	:	06-03-2012
*******************************************************************************************************/
%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%@ page import="java.util.*"%>
<%@ page import="com.eg.EgInstallInfo"%>
<%@ page import="com.eg.EgDecryptLicense"%>
<%@ page import="com.eg.*"%>
<%@ page import=" java.io.*"%>
<%@ page import = "com.eg.EgConMonHelper"%>
<%@ page import = "com.eg.EgTestInfo" %>
<%@ page import="com.egurkha.util.StringUtils"%>
<html>
<head> 
<link rel="stylesheet" href="eg_styles/adminstyle_blue.css"/>
<script language="javascript" src="/final/admin/eg_scripts/timeout.js"></script>
<script language="javascript">
function formreset()
{
	document.license.info.value ='';
	document.license.submit();
}
document.onscroll = function()
{
	clearTimeout(time);
	time = setTimeout(logout,timeoutTime); 
}
</script>
<%
	response.setHeader("Cache-Control","no-store");
	response.setHeader("Pragma","no-cache");
	response.setDateHeader("Expires", -1);

	String tool = "cscdecrypt";
	String sessionInUse = request.getParameter("sessionInUse");
	String pwd = request.getParameter("pwd");
	String authenticated = (String)session.getAttribute("authenticated");

	if (authenticated == null)
	{
		// Direct access from the browser address bar or from inside the toolkit via the tool
		if (pwd == null)
		{
			if (sessionInUse == null)
			{
				response.sendRedirect(request.getContextPath()+"/toolkitlogin?comeFrom="+tool+"&tools="+tool);
			}
			else
			{
%>
				<script>
					window.parent.location.href ="/final/toolkitlogin";
				</script>
<%
			}
		}
		else
		{
			// Direct access from the browser address bar
			if (!pwd.equals(EgConMonHelper.executePwd))
			{
				response.sendRedirect(request.getContextPath()+"/toolkitlogin?comeFrom="+tool+"&tools="+tool);
			}
			else
			{
				session.setAttribute("reqFromForTk","cscdecrypt");
				session.setAttribute("validate_tools","true");
				session.setAttribute("tools",tool);
				String redirectURL = request.getContextPath()+"/toolkit";
				response.sendRedirect(redirectURL);
			}
		}
	}
	else
	{ 
		// Direct access from the browser address bar and session in use
		if (sessionInUse == null)
		{
			session.setAttribute("validate_tools","true");
			session.setAttribute("tools",tool);
			response.sendRedirect(request.getContextPath()+"/toolkit");
		}
	}
	session.setAttribute("reqFromForTk","cscdecrypt");

	String comeFrom = request.getParameter("comeFrom");
	if (!StringUtils.isNull(comeFrom) && comeFrom.equals("Csc"))
	{
		session.setAttribute("treeViewSrc","cscdecrypt");
	}

	try
	{
		String content =request.getParameter("info");
		String empty="";
%>

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
</head>

<body>

<table cellpadding="4" cellspacing="0" border="0" align="center" width="100%">
	<tr>
		<td height="10px">&nbsp;</td>
	</tr>
	<tr>
		<td align="center" style="width:900px">
			<form name="license" method="post" action="EgCSCLicenseReport.jsp?sessionInUse=true">
			<table width="900px" cellpadding="4" cellspacing="0" border="0" class="table_border">
				<tr>
					<td  class="eg_8bold table_header" height="20"> Please paste the content of license file from your mail </td>
				</tr>
				<tr>
					<td align="center"><textarea name="info" rows="20" id="info" style="width:880px"><%=(content==null)?empty:content%></textarea>
					</td>
				</tr>
				<tr>
					<td align="center"> <input type="submit" name="b1" value="Decrypt" class="eg_darkbutton"/>&nbsp;&nbsp;&nbsp; <input type="reset" name="b2" value="Clear" onclick="formreset();" class="eg_darkbutton" /> </td>
				</tr>
<%
		com.eg.EgDecryptLicense license=new com.eg.EgDecryptLicense();
		EgTestInfo tokInfo = new EgTestInfo("manager");
		ArrayList list=new ArrayList();
		if (content !=null && content.length()>0)
		{
			StringTokenizer line = new StringTokenizer(content, "\n");
			while(line.hasMoreTokens())
			{
				String st=((String)line.nextToken()).trim();
				if(st.equals(""))
				{
					out.println("Remove extra empty space");  
					return;
				}
				String output=license.decrypt(st);
				list.add(output);
			}
%>
			</table>
			</form>
		</td>
	</tr>
	<tr>
		<td align="center" style="width:900px">
			<table style="width:900px" cellpadding="4" cellspacing="0" border="0" class="table_border">
				<tr>
					<td colspan="2" class="eg_8bold table_header" height="20"> License Information </td>
				</tr>
<%
			String data="";
			int locmark=0;
			for(int i=0;i < list.size();i++)
			{
				data=((String)list.get(i)).trim();
				if(data.indexOf(":")!=-1 )
				{
					int index = data.indexOf(":");
					if(index > 0)
					{
						String info=(data.substring(0,index)).trim();
						String value=data.substring(index+1);
						if (info.equals("Allowed DD Types"))
						{
							value += ", External Agent";
						}
%>
				<tr>
					<td align="left" class="cell_border1" style="width:300px"><%=info%></td>
					<td align="left" class="cell_border1"><%=value%></td>
				</tr>
<% 
					}
				}
			}
%>
			</table>
		</td>
	</tr>
	<tr>
		<td height="10px">&nbsp;</td>
	</tr>
</table>
<%
		}
	}
	catch(Exception e)
	{
		out.println("Decryption failed due to : Input data error {"+e.toString()+"}");
	}
	
%>

</body>
</html>