Skip to content

Commit 6cc6016

Browse files
committed
feat(middleware): 添加IP访问频率限制和自动封禁功能
- 当IP访问次数达到100次时自动执行封禁命令 - 使用ipset工具将违规IP添加到fishpi集合中 - 封禁操作通过shell命令执行,超时时间为3秒 - 添加封禁成功日志输出 - 在现有访问计数逻辑后插入封禁检查机制
1 parent 46a5f61 commit 6cc6016

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/main/java/org/b3log/symphony/processor/middleware/AnonymousViewCheckMidware.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,11 @@ public void handle(final RequestContext context) {
203203
count++;
204204
ipVisitCountCache.put(ip, count);
205205

206+
if (count >= 100) {
207+
String result = Execs.exec(new String[]{"sh", "-c", "ipset add fishpi " + ip}, 1000 * 3);
208+
System.out.println(ip + " 已封禁");
209+
}
210+
206211
// 判断是否需要进入验证码流程
207212
boolean needCaptcha = false;
208213

0 commit comments

Comments
 (0)