<%@ page contentType="text/html;charset=GBK"%> <%@page import="com.gpower.services.user.User"%> <%@ page import="java.util.*"%> <%@ page import="java.io.*"%> <%@ page import="java.net.*"%> <%@ page import="java.lang.reflect.Field"%> <%-- <%@ page import="com.gpower.web.service.*"%> --%> <%@ page import="com.gpower.services.content.ContentService"%> <%@ page import="com.gpower.util.*"%> <%! boolean getCanAccessSite(String username,Long siteID,HttpServletRequest request) { try { URL wsUrl = new URL("http://localhost:8080/cms/web/getAccessSiteByUserName.jsp?username="+username); HttpURLConnection conn = (HttpURLConnection)wsUrl.openConnection(); conn.setDoInput(true); conn.setDoOutput(true); conn.setRequestMethod("POST"); conn.setRequestProperty("Content-Type", "text/xml;charset=utf-8"); OutputStream os = conn.getOutputStream(); String soap = "" + " aaa "; os.write(soap.getBytes()); InputStream is = conn.getInputStream(); byte[] b = new byte[1024]; int len = 0; String s = ""; while((len = is.read(b)) != -1){ String ss = new String(b,0,len,"utf-8"); s += ss; } s = s.trim(); System.out.println("-------"+s); Set siteIds = new HashSet(); if(s.length() > 2) { s = s.substring(1,s.length()-1); String[] siteIdsStr = s.split(","); for(String siteIdStr:siteIdsStr) { siteIds.add(Long.parseLong(siteIdStr.trim())); } } siteIds.add(-1l); is.close(); os.close(); conn.disconnect(); Set canSiteIds = siteIds; System.out.print(username+":"); for(Long canSiteId:canSiteIds) { System.out.print(canSiteId+","); } if(canSiteIds.contains(siteID)) return true; else return false; } catch(Exception e) { System.out.println("error:"); e.printStackTrace(); return false; } } %> <% System.out.println("11111111111"); String[] IPs = {"123.52.41.158-123.52.41.163"}; request.setCharacterEncoding("GBK"); String requestURLStr = request.getRequestURL().toString(); System.out.println("URLStr = " + requestURLStr); if ((requestURLStr.contains("/css/")) || (requestURLStr.contains("/images/")) || (requestURLStr.contains("/js/")) || (requestURLStr.contains("/docs"))) { response.sendRedirect(requestURLStr); //chain.doFilter(request, response); } else { String currentUserName = (String) session.getAttribute("currentLanUser"); if ((currentUserName == null) || (currentUserName.equals(""))) { String ip = IPUtil.getIpAddr(request); if(ip == null || ip.length() == 0) { ip = request.getRemoteAddr(); } System.out.println("ip="+ip); String []curIpSeg = ip.split("\\."); // 10.121.0.0-10.123.63.254 for(String ipSeg:IPs){ if(IPUtil.isIPInSegment(ipSeg,ip)){ currentUserName = "isIn"; break; } } System.out.println("currentUserName="+currentUserName); } long siteID = 83l; if ((currentUserName == null) || (currentUserName.equals(""))) { %> <% } else if(!currentUserName.equals("isIn") && !getCanAccessSite(currentUserName,siteID,request)){ %> <% } } %>