From 35bc01f6d36fb24abd6fc6ee7b60a887ccfb6523 Mon Sep 17 00:00:00 2001
From: Yutousama <583819556@qq.com>
Date: Fri, 29 May 2020 10:26:55 +0800
Subject: [PATCH] =?UTF-8?q?banip=E6=93=8D=E4=BD=9C=E9=9C=80=E8=A6=81?=
=?UTF-8?q?=E4=BA=8C=E6=AC=A1=E7=A1=AE=E8=AE=A4?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
pom.xml | 2 +-
.../java/com/yutou/tools/utils/Tools.java | 4 ++-
.../com/yutou/tools/web/userController.java | 35 ++++++++++++-------
3 files changed, 27 insertions(+), 14 deletions(-)
diff --git a/pom.xml b/pom.xml
index f254abd..4bbdbf9 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 322ace4..f93ca2a 100644
--- a/src/main/java/com/yutou/tools/utils/Tools.java
+++ b/src/main/java/com/yutou/tools/utils/Tools.java
@@ -91,7 +91,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 = "
";
+ writer.write(html);
}
- return "ERROR";
+ writer.flush();
+ writer.close();
}
@RequestMapping(value = "/login/login.do", method = RequestMethod.POST)