
<%@ page language="java" contentType="text/html; charset=GBK" %>
<%@ taglib uri="/WEB-INF/weaver.tld" prefix="wea"%>
<%@ page import="weaver.general.Util,java.util.*" %>
<%@ page import="weaver.hrm.HrmUserVarify" %>
<%@ page import="weaver.hrm.User" %>
<%@ page import="weaver.general.BaseBean" %>
<%@ page import="weaver.security.core.MD5" %>
<%@ page import="java.util.concurrent.ConcurrentHashMap" %>
<%@ page import="java.io.File" %>
<%@ page import="java.net.InetAddress,java.net.UnknownHostException" %>
<%@ page import="org.apache.commons.io.FileUtils" %>
<jsp:useBean id="xssUtil" class="weaver.filter.XssUtil" scope="page"></jsp:useBean>
<jsp:useBean id="rs" class="weaver.conn.RecordSet" scope="page"></jsp:useBean>
<jsp:useBean id="csui" class="weaver.filter.msg.CheckSecurityUpdateInfo"></jsp:useBean>
<%
    response.setHeader("cache-control", "no-cache");
    response.setHeader("pragma", "no-cache");
    response.setHeader("expires", "Mon 1 Jan 1990 00:00:00 GMT");
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>刷新缓存</title>

<LINK href="/css/Weaver_wev8.css" type=text/css rel=STYLESHEET>
	<style type="text/css">
		*{
			font-family: 微软雅黑;
			mso-hansi-font-family: 微软雅黑
		}
		.listTable{
			width:100%;
			border:1px solid #dcdcdc;
			border-collapse:collapse;
		}
		.listTable th{
			height:40px;
			background-color:#f0f3f4;
		}
		.listTable th, .listTable td{
			border:1px solid #dcdcdc;
			font-size:12px;
			color:#384049;
		}
		.listTable td{
			height:50px;
			text-align:center;
		}
	</style>
	<script type="text/javascript" src="/security/monitor/jquery.min.js"></script>

	<script type="text/javascript">
		function refresh(node, src){
			var s = true;
			if(src == "xml" || src=="class"){
				s = confirm("确定刷新"+src+"缓存吗？");
			}
			if(s) {
				var url = "/security/monitor/updateCacheAjax.jsp";
				if(node == "local"){
					url = "/security/monitor/updateCacheInner.jsp";
				}
				jQuery.ajax({
					url: url,
					method: "POST",
					data: {
						node: node,
						src: src
					},
					beforeSend:function(request){
						document.getElementById("msg").innerHTML="正在刷新...";
						document.getElementById("shadow").style.display = "block";
					},
					dataType: "json",
					success: function (data) {
						if (!!data && data.result) {
							if(src == "status"){
								jQuery("#status_" + node).text(data.firewallStatusLabel);
								jQuery("#version_" + node).text(data.version);
							}else{
								jQuery("#lastAccessTime_" + node).text(data.refreshTime);
								alert("刷新缓存完成，请等待1-2分钟后再测试相关功能。");
								//alert(data.msg);
							}
						} else {
							alert("刷新失败.原因：" + data.msg);
						}
					},
					error: function (data) {
						alert("刷新失败.")
					},
					complete:function(data){
						document.getElementById("msg").innerHTML="";
						document.getElementById("shadow").style.display = "none";
					}

				});
			}
		}
	</script>

</head>

<body>
<div id="shadow" style="display:none;background-color:#eaeaea;filter:alpha(opacity=70); -moz-opacity:0.7; opacity:0.7;position:absolute;width:100%;height:100%;text-align:center;line-height:100%;">
	<div id="msg" style="margin-top:40px;width:180px;line-height:30px;height:30px;color:#0B84E0;font-size:14px;margin-right:auto;margin-left:auto;"></div>
</div>
<%!
 private static Map<String, String> ipMap = new ConcurrentHashMap<String, String>();
%>
<%
	User user = HrmUserVarify.getUser (request , response) ;
	if(user == null)  {
		out.println("please login with admin.");
		return;
	} ;
	int UID = xssUtil.getIntValue(""+xssUtil.getRule().get("userID"),1);
	if (user.getUID()!=UID)
	{
		out.println("please login with admin.");
		return;
	}
	
	 String ipAddress = "127.0.0.1";
	 try {
            InetAddress localHost = InetAddress.getLocalHost();
            ipAddress = localHost.getHostAddress();
			ipAddress = ipAddress.replaceAll("(\\d{1,3}\\.)","*.");
        } catch (UnknownHostException e) {
         
        }
	
	File tokenFile = new File(xssUtil.getRootPath() + File.separatorChar + "WEB-INF" + File.separatorChar+"securityRule"+File.separatorChar+"weaver_security_cache_token");
	if(!tokenFile.exists()){
		tokenFile.createNewFile();
	}
	String token = UUID.randomUUID().toString();
	FileUtils.writeStringToFile(tokenFile, token);
%>

		<%
			String nodes = new BaseBean().getPropValue("weaver","initial_hosts");
			String version = csui.getVersion();
			String firewallStatusLabel = xssUtil.enableFirewall()?"已生效":"未生效";
		
		%>
		<script type="text/javascript">
			jQuery(document).ready(function(){
				
				<%
					if(nodes!=null && !"".equals(nodes)){
						String[] nodeArr = nodes.split(",");
						for(String node : nodeArr){
							String md5 = new MD5().getMD5ofStr(node);
							
				%>
					refresh('<%=md5%>', 'status');
				<%
						}
					}
				%>
				
			});
		</script>
		<div style="margin:0 10px 0 10px">
			<div style="font-size:14px;font-weight:bold;margin-top:42px;padding-bottom:18px;border-bottom:1px solid #e0e0e0;color:#384009">ecology系统安全情况</div>
	<div style="margin-top:20px;max-height:600px;overflow:auto;">
		<table class="listTable">
					<thead>
						<th>节点IP</th>
						<th>安全补丁版本</th>
						<th>安全补丁状态</th>
						<th>最近缓存刷新时间</th>
						<th>操作</th>
					</thead>
				<tbody>
					<tr>
							<td style="text-align:center;"><%=ipAddress%>（本机）</td>
							<td style="text-align: center" id="version_local"><%=version%></td>
							<td style="text-align: center" id="status_local"><%=firewallStatusLabel%></td>
							<td style="text-align: center" id="lastAccessTime_local"></td>
							<td style="text-align:center;">
							<span style="margin-left:auto;margin-right:auto;text-align:center;cursor:pointer;color:#f25f1e;width:120px;height:26px;line-height:26px;border:1px solid #d6d6d6;" title="检测安全补丁包状态" onclick="refresh('local','status');">刷新安全包状态</span>&nbsp;&nbsp;
								<span style="margin-left:auto;margin-right:auto;text-align:center;cursor:pointer;color:#f25f1e;width:120px;height:26px;line-height:26px;border:1px solid #d6d6d6;" title="如果更新的是xml文件，则点击此按钮刷新缓存" onclick="refresh('local','xml');">刷新xml缓存</span>&nbsp;&nbsp;
								<span style="margin-left:auto;margin-right:auto;text-align:center;cursor:pointer;color:#f25f1e;width:120px;height:26px;line-height:26px;border:1px solid #d6d6d6;"  title="如果更新的是class文件，则点击此按钮刷新缓存" onclick="refresh('local','class');">刷新class缓存</span>
							</td>
						</tr>
					<%
					if(nodes!=null && !"".equals(nodes)){
						String[] nodeArr = nodes.split(",");
						for(String node : nodeArr){
							String md5 = new MD5().getMD5ofStr(node);
							ipMap.put(md5, node);
					%>
						<tr>
							<td style="text-align:center;"><%=node.replaceAll("(\\d{1,3}\\.)","*.")%></td>
							<td style="text-align: center" id="version_<%=md5%>"></td>
							<td style="text-align: center" id="status_<%=md5%>"></td>
							<td style="text-align: center" id="lastAccessTime_<%=md5%>"><%%></td>
							<td style="text-align:center;">
							<span style="margin-left:auto;margin-right:auto;text-align:center;cursor:pointer;color:#f25f1e;width:120px;height:26px;line-height:26px;border:1px solid #d6d6d6;" title="检测安全补丁包状态" onclick="refresh('<%=md5%>','status');">刷新安全包状态</span>&nbsp;&nbsp;
								<span style="margin-left:auto;margin-right:auto;text-align:center;cursor:pointer;color:#f25f1e;width:120px;height:26px;line-height:26px;border:1px solid #d6d6d6;" title="如果更新的是xml文件，则点击此按钮刷新缓存" onclick="refresh('<%=md5%>','xml');">刷新xml缓存</span>&nbsp;&nbsp;
								<span style="margin-left:auto;margin-right:auto;text-align:center;cursor:pointer;color:#f25f1e;width:120px;height:26px;line-height:26px;border:1px solid #d6d6d6;"  title="如果更新的是class文件，则点击此按钮刷新缓存" onclick="refresh('<%=md5%>','class');">刷新class缓存</span>
							</td>
						</tr>
					<%}}
					%>
				</tbody>
				</table>
	</div>
	</div>

<%



	if("detail".equals(request.getParameter("cmd"))){
		try{
			out.println(xssUtil.getIsParamKeyCheck());
			out.println(xssUtil.getParamKeyRule());
		}catch(Exception e){}
		try{
			out.println("paramsCache size::"+xssUtil.getParamsMap().toString().length());
		}catch(Exception e){}
		out.println("<br/><br/>paramsMap::<br/>");
		try{
			out.println(xssUtil.getParamsMap().toString());
		}catch(Exception e){}
		out.println("<br/><br/>forbiddenUrlList::<br/>");
		try{
			out.println(xssUtil.getForbiddenUrlList().toString());
		}catch(Exception e){}
		out.println("<br/><br/>encList:<br/>");
		try{
			out.println(xssUtil.getEncList().toString());
		}catch(Exception e){}
		out.println("<br/><br/>refList:<br/>");
		try{
			out.println(xssUtil.getRefList().toString());
		}catch(Exception e){}
		out.println("<br/><br/>enable webservice check:<br/>");
		try{
			out.println(xssUtil.getEnableWebserviceCheck());
		}catch(Exception e){}
		out.println("<br/><br/>webserviceList:<br/>");
		try{
			out.println(xssUtil.getWebserviceList().toString());
		}catch(Exception e){}
		out.println("<br/><br/>webserviceIpList:<br/>");
		try{
			out.println(xssUtil.getWebserviceIpList().toString());
		}catch(Exception e){}
		out.println("<br/><br/>isSkipHost::"+xssUtil.getIsSkipHost()+"---->hostList:<br/>");
		try{
			out.println(xssUtil.getHostList().toString());
		}catch(Exception e){}
		out.println("<br/><br/>exceptList:<br/>");
		try{
			out.println(xssUtil.getExceptList().toString());
		}catch(Exception e){}
		out.println("<br/><br/>mustXss:<br/>");
		out.println(xssUtil.getMustXss());
		out.println("<br/><br/>xssList:<br/>");
		try{
			out.println(xssUtil.getXssList().toString());
		}catch(Exception e){}
		out.println("<br/><br/>isSkipRule::"+xssUtil.getIsSkipRule()+"---->rules:<br/>");
		try{
			out.println(xssUtil.getRule().toString());
		}catch(Exception e){}
	}else{
	//	xssUtil.initRules(true);
	}
	//out.println("complete...");
%>
</body>
</html>
