diff --git a/pom.xml b/pom.xml index 421f4e1..bd11301 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ com.yutou tools - 1.0.7 + 1.0.7.1 tools Demo project for Spring Boot diff --git a/src/main/java/com/yutou/tools/utils/Tools.java b/src/main/java/com/yutou/tools/utils/Tools.java index 9c8803d..a11aa69 100644 --- a/src/main/java/com/yutou/tools/utils/Tools.java +++ b/src/main/java/com/yutou/tools/utils/Tools.java @@ -89,7 +89,9 @@ public class Tools { inputStream.close(); connection.disconnect(); if (UpdateIp.nas_ip != null) { - connection = (HttpURLConnection) new URL("http://" + UpdateIp.nas_ip + ":8000/localhome/bot/send.do?msg=" + URLEncoder.encode((title + "\n" + msg), "UTF-8") + "&token=zIrsh9TUZP2lfRW753PannG49E7VJvor").openConnection(); + String url="http://" + UpdateIp.nas_ip + ":8000/localhome/bot/send.do?msg=" + URLEncoder.encode((title + "\n" + msg), "UTF-8") + "&token=zIrsh9TUZP2lfRW753PannG49E7VJvor"; + System.out.println(url); + connection = (HttpURLConnection) new URL(url).openConnection(); connection.connect(); inputStream=connection.getInputStream(); i=inputStream.read(); diff --git a/src/main/java/com/yutou/tools/web/userController.java b/src/main/java/com/yutou/tools/web/userController.java index 3532d98..d22ae6e 100644 --- a/src/main/java/com/yutou/tools/web/userController.java +++ b/src/main/java/com/yutou/tools/web/userController.java @@ -14,6 +14,8 @@ import javax.annotation.Resource; import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.io.PrintWriter; import java.util.Objects; import java.util.UUID; @@ -68,28 +70,37 @@ public class userController { cc += value; } RedisTools.set("login", cc, 5 * 60 * 1000); - String token=UUID.randomUUID().toString().replace("-",""); - RedisTools.set(token,Tools.getRemoteAddress(request),10 * 60 * 1000); - String url="http://tools.yutou233.cn/login/ban.do?token="+token; + String token = UUID.randomUUID().toString().replace("-", ""); + RedisTools.set(token, Tools.getRemoteAddress(request), 10 * 60 * 1000); + String url = "http://tools.yutou233.cn/login/ban.do?token=" + token; Tools.sendServer("管理后台登录验证码", "本次登录验证码为:" + cc + ",登录IP:" + Tools.getRemoteAddress(request) - + ",非正常登录,封禁IP:"+url); + + ",非正常登录,封禁IP:" + url); return "ok"; } + @RequestMapping("/login/ban.do") - @ResponseBody - public String banIp(String token){ - String ip=RedisTools.get(token); - if(ip!=null){ - JSONArray array = new JSONArray(); + public void banIp(HttpServletResponse response, String token, String model) throws IOException { + String ip = RedisTools.get(token); + PrintWriter writer = response.getWriter(); + if (ip != null && model != null && model.equals("yes")) { + JSONArray array = null; if (RedisTools.get("ban") != null) { array = JSONArray.parseArray(RedisTools.get("bean")); } + if(array==null){ + array=new JSONArray(); + } array.add(ip); - RedisTools.set("ban",array.toJSONString()); - return "已封禁"; + RedisTools.set("ban", array.toJSONString()); + writer.write("已封禁"); + } else { + String url = "http://tools.yutou233.cn/login/ban.do?token=" + token + "&model=yes"; + String html = "
click my is ban this IP :" + ip + "
"; + writer.write(html); } - return "ERROR"; + writer.flush(); + writer.close(); } @RequestMapping(value = "/login/login.do", method = RequestMethod.POST)