<!DOCTYPE html>

<%@ include file="EgTrackerA.jsp" %>
<%@ include file="listSearchJson.jsp" %>
<%@ page import="java.util.*"%>
<%@ page import="egurkha.UserBean"%>
<%@ page import="com.eg.EgServerList"%>
<%@ page import="com.eg.EgLicenseInfo"%>
<%@ page import="com.eg.EgControlInfo"%>
<%@ taglib prefix="egui" uri="../WEB-INF/eg-taglib.tld"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>

<%
	response.setHeader("Cache-Control","no-store");
	response.setHeader("Pragma","no-cache");
	response.setDateHeader("Expires", -1);

	String selAgentType = "PremiumAgents";
	String agtType = request.getParameter("agentType");
	if(agtType != null && agtType.length() > 0)
	{
		selAgentType = agtType;
	}
	String selAgentStatus = "All";
	String showAgentInformationView = "false";
	String agentRunningStatus = "running";
	String selectedAgentIP = "";
	String isDebugEnabled = "";
	String from = request.getParameter("from");
	String theme = _user.getAdminSkin();
	EgRoleInfo egRoleInfo = EgRoleInfo.getInstance(session.getId(),(String)session.getAttribute("sess_userid"));
	boolean isLimitedAdmin = !egRoleInfo.hasAllComponentAccess();
	String viewFrom = request.getParameter("viewFrom");
	if(viewFrom == null || viewFrom.trim().length() == 0)
		viewFrom = "default";

	EgControlInfo ctrlInfo = new EgControlInfo("manager");
	String timeOutStr = ctrlInfo.getTimeOut();
	int timeOut = 0;
	try {
		timeOut = Integer.parseInt(timeOutStr);
		if (timeOut < 120)
			timeOut = 120;
	}
	catch(Exception e)
	{
		timeOut = 120;	
	}
	if(from != null && from.equals("upgradeAdvancedSearchPage"))
	{
		agentRunningStatus = "notrunning";
		showAgentInformationView = "true";
		selectedAgentIP = com.eg.EgURLDecoder.decode(request.getParameter("agentIp"),"UTF-8");
		UserBean userBean = new UserBean();
		EgLicenseInfo licInfo = new EgLicenseInfo();
		ArrayList allAgents = licInfo.getTotalAgents();
		ArrayList allAgents1=licInfo.getExternalAgents(); 
		ArrayList allAgents2=licInfo.getBasicAgents();
		ArrayList allAgents3=userBean.getPremiumAgents();
		ArrayList allAgents4=licInfo.getRemoteAgents();
		ArrayList allAgents5=userBean.getPremiumAgents(true);

		if(allAgents1 != null && !allAgents1.isEmpty())
		{
			allAgents.addAll(allAgents1);
		}
		if(allAgents2 != null && !allAgents2.isEmpty())
		{
			allAgents.addAll(allAgents2);
		}
		if(allAgents3 != null && !allAgents3.isEmpty())
		{
			allAgents.addAll(allAgents3);
		}
		if(allAgents4 != null && !allAgents4.isEmpty())
		{
			allAgents.addAll(allAgents4);
		}
		if(allAgents5 != null && !allAgents5.isEmpty())
		{
			allAgents.addAll(allAgents5);
		}
		ArrayList agentList = new ArrayList();
		String s_agentIP = selectedAgentIP.toLowerCase();
		for(int j=0;j<allAgents.size(); j++)
		{
			if(((String)allAgents.get(j)).toLowerCase().indexOf(s_agentIP) > -1)
			{
				if(!agentList.contains(allAgents.get(j)))
				{
					agentList.add(allAgents.get(j));
				}
			}
		}
		EgServerList serverList = new EgServerList();
		ArrayList aList = serverList.getAgentListFromDB();
		String currList[] = serverList.getTargetNames();
		ArrayList totalAgents = serverList.getAgentList(agentList,aList,currList);
		if(totalAgents != null && !totalAgents.isEmpty())
		{
			for(int j=0;j<totalAgents.size();j=j+4)
			{
				String agentIP = (String)totalAgents.get(j);
				String message = (String)totalAgents.get(j+1);
				if(agentIP.equalsIgnoreCase(s_agentIP) && message.equals("Installed-Running"))
				{
					agentRunningStatus = "running";
					break;
				}
			}
		}
	}
	else if (from != null && (from.equals("AdminHome") || from.equals("AgentAssign")))
	{
		selAgentType = request.getParameter("agentType");
		selAgentStatus = request.getParameter("agentStatus");
	}
	else if (from != null && from.equals("licenseoverview"))
	{
		backHref = "EgLicenseInfo.jsp?from=agentstatus";
	}
	else if(viewFrom.equalsIgnoreCase("AgentInfo"))
	{
		selectedAgentIP = com.eg.EgURLDecoder.decode(request.getParameter("agentID"),"UTF-8");
		selAgentStatus = request.getParameter("agentStatus");
		isDebugEnabled = request.getParameter("debugEnabled");
	}
	else if(viewFrom.equals("AgentStatus") || viewFrom.equals("AgentXmx") || viewFrom.equals("RemoteControl"))
	{
		selAgentStatus = request.getParameter("agentStatus");
	}
	String agentState = request.getParameter("agentStatus");
	String from_rc_page = request.getParameter("from_remote_control_page");
	from_rc_page=(from_rc_page != null && (from_rc_page.trim().equals("true") || from_rc_page.trim().equals("yes")))?from_rc_page:"no";
	String s_agent_type = request.getParameter("s_agent_type");
	s_agent_type=(s_agent_type != null && s_agent_type.trim().length()>0)?s_agent_type:"PremiumAgents";
%>

<html>
<head>
	<meta charset="utf-8">
	<title>Agent Status</title>

	<!--Skin color--------->
	<egui:skin ui = "admin"/>

	<!---Components, icons, skin and Core ext script--->
	<script type="text/javascript" src="../extjs/ext-all.js"></script>

	<!-- Fancy Scroll-->
	<script src="/final/jquery/jquery.js"></script>
	<script src="/final/styles/jscrollpane/jquery.jscrollpane.js" ></script>
	<script src="/final/styles/jscrollpane/jquery.mousewheel.js" ></script>
	<script src="/final/styles/jscrollpane/mwheelIntent.js" ></script>
	<link rel="stylesheet" href="/final/styles/jscrollpane/jquery.jscrollpane.css"/>

	<!-- Application folder -->
	<script type="text/javascript" src="AgentStatus/app/app.js"></script>

	<script language="javascript">
	Ext.onReady(function(){
		Ext.Ajax.extraParams = {"com.eg.CSRF_NONCE" : csrfToken};
		Ext.data.Connection.prototype.extraParams = {"com.eg.CSRF_NONCE" : csrfToken};
		Ext.data.ScriptTagProxy.prototype.extraParams = {"com.eg.CSRF_NONCE" : csrfToken};

		Ext.Ajax.on('requestexception', function (conn, response, options) {
			var errorStr = response.responseText;
			if (errorStr != undefined && errorStr != 'undefined' && errorStr.indexOf("customerror") != -1)
			{
				if (errorStr.indexOf("user-session-invalid") != -1)
				{
					callWindow(1);
				}
				else if (errorStr.indexOf("user-deleted") != -1)
				{
					callWindow(2);
				}
				else if (errorStr.indexOf("user-timedout") != -1)
				{
					callWindow(3);
				}
			}
			else
			{
				if (response.status == 302 || (response.timedout != undefined && response.timedout == true))
				{
					Ext.Msg.show({
						title : errorTitle,
						msg : requestTimeOut,
						buttons : Ext.Msg.OK,
						icon : 'iconError'
					});
				}
				else
				{
					console.log(response.responseText);
					Ext.Msg.show({
						title : errorTitle,
						msg : probsErrorMessage,
						buttons : Ext.Msg.OK,
						icon : 'iconError'
					});
				}
			}
		});
	});
	function resetView()
	{
		viewFrom = "default";
	}
	</script>

	<Script language="JavaScript1.2">
	var csrfToken = '<%=strCsrfToken%>';
	var pageTitle = '<egui:intnl text="admin.title.AGENTS - STATUS"/>';
	var pageTitle2 = '<egui:intnl text="admin.title.Agent Information"/>';
	var pageDesc = '<egui:intnl description="EgServerList.jsp"/>';
	var pageDesc2 = '<egui:intnl description="EgAgentInfo.jsp"/>';
	
	var publicJSON = '';
	var upgradeStatus = '<egui:intnl text="admin.agents.Upgrade Status"/>';
	var restartAll = '<egui:intnl text="admin.agents.Restart All Agents"/>';
	var agentType = '<egui:intnl text="admin.agents.Agent type"/>';
	var agentStatus = '<egui:intnl text="admin.agents.Agent status"/>';
	var confirmMsg1 = '<egui:intnl text="admin.agents.Do you want to restart the eG agent on host"/>';
	var confirmMsg_stop = '<egui:intnl text="admin.agents.Do you want to stop the eG agent on host"/>';
	var restartAlrtTitle = '<egui:intnl text="admin.agent.Restart agent"/>';
	var stopAlrtTitle = '<egui:intnl text="admin.agent.Stop agent"/>';
	var confirmMsg2 = '<egui:intnl text="admin.agents.Do you want to change the output mode of the agent "/>';
	var loadingMsg1 = '<egui:intnl text="monitor.agentmode.Turning the agent output off will take some time"/>.';
	var loadingMsg2 = '<egui:intnl text="monitor.agentmode.Turning the agent output on will take some time"/>.';
	var plsWait = '<egui:intnl text="admin.agents.Please wait"/>'+'.';
	var confirmMsg3 = '<egui:intnl text="admin.agents.Do you want to restart all the agents"/>' + '?';
	var agentIPNick = '<egui:intnl text="admin.upgrade.Agent IP/Nickname"/>';
	var autoUpgrade = '<egui:intnl text="admin.upgrade.Auto Upgrade"/>';
	var lastUpgradePack = '<egui:intnl text="admin.upgrade.Last Upgraded Package"/>';
	var lastUpgradeTime = '<egui:intnl text="admin.upgrade.Last Upgraded Time"/>';
	var hostName = '<egui:intnl text="admin.upgrade.Host name"/>';
	var os = '<egui:intnl text="admin.upgrade.OS"/>';
	var version = '<egui:intnl text="admin.upgrade.Version"/>';
	var jreVersion = '<egui:intnl text="admin.upgrade.JRE Version"/>';
	var lastUpdatedTime = '<egui:intnl text="admin.upgrade.Last Updated Time"/>';
	var debugMode = '<egui:intnl text="admin.upgrade.Debug Mode"/>';
	var stopAgent = '<egui:intnl text="admin.upgrade.Stop"/>';
	var restartAgent = '<egui:intnl text="admin.upgrade.Restart Agent"/>';
	var reset = '<egui:intnl text="admin.upgrade.Reset"/>';
	var viewAgentLog = '<egui:intnl text="admin.upgrade.View Agent Log Files"/>';
	var back = '<egui:intnl text="admin.common.Back"/>';
	var srcAlert = '<egui:intnl text="admin.agents.No managed host name(s) found for the above selection/search"/>';
	var installed = '<egui:intnl text="admin.agents.Installed"/>';
	var status = '<egui:intnl text="admin.agents.Status"/>';
	var opLog = '<egui:intnl text="admin.agents.Output logging enabled"/>?';
	var restart = '<egui:intnl text="admin.agents.Restart"/>';
	var logs = '<egui:intnl text="admin.agents.Logs"/>';
	var xmx = '<egui:intnl text="admin.agents.Xmx"/>';
	var agentLogEnable = '<egui:intnl text="admin.agents.Agent output log Enable/Disable"/>';
	var noAgentsAlert = '<egui:intnl text="admin.agents.No agents found for your current selection"/>';
	var noAgentsFound = '<egui:intnl text="admin.agents.No agents found for your current search"/>';
	var assoHosts = '<egui:intnl text="admin.agents.Associate hosts"/>';

	var remotecontrol = '<egui:intnl text="admin.agents.Remote control"/>';
	var numberOfAgents = '<egui:intnl text="admin.agents.Total number of agents"/>';
	var agentShared = '<egui:intnl text="admin.agents.Agent Shared"/>';

	var backHref = '<%=backHref%>';
	var theme = '<%=theme%>';
	var probsErrorMessage = '<egui:intnl text="admin.error.Problem encountered while loading the user interface"/>.';
	var requestTimeOut = '<egui:intnl text="admin.error.Response timed out"/>.';
	var errorTitle = '<egui:intnl text="admin.user.Error"/>';
	var agentNotReporting = '<egui:intnl text="admin.agents.Agent is not reporting"/>.';
	var showAgentInformationView = '<%=showAgentInformationView%>';
	var selectedAgentIP = '<%=selectedAgentIP%>';
	var agentRunningStatus = '<%=agentRunningStatus%>';
	var from = '<%=from%>';
	var selAgentType = '<%=selAgentType%>';
	var selAgentStatus = '<%=selAgentStatus%>';
	var timeOut = <%=timeOut%>;
	var userLanguage='<%=trackerLanguage%>';
	var isLimitedAdmin='<%=isLimitedAdmin%>';
	var isFromRemoteControlPage='<%=from_rc_page%>';
	var sel_agent_type='<%=s_agent_type%>';
	var viewFrom='<%=viewFrom%>';
	var isDebugEnabled='<%=isDebugEnabled%>';
	var viewList = ['AgentInfo','AgentStatus','AgentXmx','RemoteControl'];
	</Script>
</head>
<BODY>
	<div id="loadmask" class="x-mask-msg x-layer x-mask-msg-default" style="z-index: 19001;left:45%;top:35%;"><div class="x-mask-loading" style="position:relative">Loading...</div></div>
</BODY>
</html>

<%
	if(request.getQueryString()!=null)
	{
		session.setAttribute("adminLastAccessedURL","/final/admin/EgServerList.jsp?"+request.getQueryString());
	}
	else
	{
		session.setAttribute("adminLastAccessedURL","/final/admin/EgServerList.jsp");
	}
%>



