Merge remote-tracking branch 'origin/master'

This commit is contained in:
Yutousama 2020-06-03 00:01:48 +08:00
commit 7ad84e9dba
3 changed files with 27 additions and 14 deletions

View File

@ -10,7 +10,7 @@
</parent>
<groupId>com.yutou</groupId>
<artifactId>tools</artifactId>
<version>1.0.7</version>
<version>1.0.7.1</version>
<name>tools</name>
<description>Demo project for Spring Boot</description>

View File

@ -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();

View File

@ -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"));
}
array.add(ip);
RedisTools.set("ban",array.toJSONString());
return "已封禁";
if(array==null){
array=new JSONArray();
}
return "ERROR";
array.add(ip);
RedisTools.set("ban", array.toJSONString());
writer.write("已封禁");
} else {
String url = "http://tools.yutou233.cn/login/ban.do?token=" + token + "&model=yes";
String html = "<div><a href=" + url + ">click my is ban this IP :" + ip + "</a></div>";
writer.write(html);
}
writer.flush();
writer.close();
}
@RequestMapping(value = "/login/login.do", method = RequestMethod.POST)