peternameyakj
2025-04-29 acf1c75a32aa05f34d9d60b6ae3f3e052b532e9f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
package project.web.admin;
 
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
 
import javax.servlet.http.HttpServletRequest;
 
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
 
import kernel.exception.BusinessException;
import kernel.util.JsonUtils;
import kernel.util.StringUtils;
import kernel.web.Page;
import kernel.web.PageActionSupport;
import project.ddos.AdminIpCountService;
import project.ddos.AdminIpMenuService;
import project.ddos.IpMenuService;
import project.ddos.model.IpMenu;
 
/**
 * IP请求管理
 */
@RestController
public class AdminIpCountController extends PageActionSupport {
 
    private Logger logger = LoggerFactory.getLogger(AdminIpCountController.class);
 
    @Autowired
    private AdminIpCountService adminIpCountService;
    @Autowired
    private AdminIpMenuService adminIpMenuService;
    @Autowired
    private IpMenuService ipMenuService;
    
    private final String action = "normal/adminIpCountAction!";
 
    /**
     * 获取IP请求 列表
     */
    @RequestMapping(action + "list.action")
    public ModelAndView list(HttpServletRequest request) {
        String message = request.getParameter("message");
        String error = request.getParameter("error");
        String ip_para = request.getParameter("ip_para");
        String type_para = request.getParameter("type_para");
 
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("ip_count_list");
 
        int pageNo = 1;
        int pageSize = 50;
        Page page = null;
        try {
            
            pageNo = this.checkAndSetPageNo(request.getParameter("pageNo"));
            page = this.adminIpCountService.cachePagedQuery(pageNo, pageSize, ip_para, type_para, null);
 
            Map<String, Object> sumdata = this.adminIpCountService.sumDates();
            modelAndView.addObject("sumdata", sumdata);
 
        } catch (BusinessException e) {
            modelAndView.addObject("error", e.getMessage());
            return modelAndView;
        } catch (Throwable t) {
            logger.error(" error ", t);
            modelAndView.addObject("error", "[ERROR] " + t.getMessage());
            return modelAndView;
        }
 
        modelAndView.addObject("pageNo", pageNo);
        modelAndView.addObject("pageSize", pageSize);
        modelAndView.addObject("page", page);
        modelAndView.addObject("message", message);
        modelAndView.addObject("error", error);
        modelAndView.addObject("ip_para", ip_para);
        modelAndView.addObject("type_para", type_para);
        return modelAndView;
    }
 
    /**
     * addBlack
     */
    @RequestMapping(action + "addBlack.action")
    public ModelAndView addBlack(HttpServletRequest request) {
        String menu_ip = request.getParameter("menu_ip");
        String login_safeword = request.getParameter("login_safeword");
 
        ModelAndView modelAndView = new ModelAndView();
 
        try {
            
            this.check();
            
            String error = this.verif_add(menu_ip);
            if (!StringUtils.isNullOrEmpty(error)) {
                throw new BusinessException(error);
            }
            
            if (StringUtils.isNullOrEmpty(login_safeword)) {
                throw new BusinessException("请输入登录人资金密码");
            }
 
            IpMenu ipMenu = new IpMenu();
            ipMenu.setIp(menu_ip);
            ipMenu.setLast_opera_time(new Date());
            ipMenu.setDelete_status(0);
            ipMenu.setType(IpMenu.IP_BLACK);
 
            IpMenu cacheMenu = this.ipMenuService.cacheByIp(menu_ip);
            if (cacheMenu != null && cacheMenu.getDelete_status() == 0) {
                this.adminIpMenuService.update(ipMenu, this.getUsername_login(), login_safeword, this.getIp());
            } else {
                this.adminIpMenuService.save(ipMenu, this.getUsername_login(), login_safeword, this.getIp());
            }
 
        } catch (BusinessException e) {
            modelAndView.addObject("error", e.getMessage());
            modelAndView.setViewName("redirect:/" + action + "list.action");
            return modelAndView;
        } catch (Throwable t) {
            logger.error(" error ", t);
            modelAndView.addObject("error", "[ERROR] " + t.getMessage());
            modelAndView.setViewName("redirect:/" + action + "list.action");
            return modelAndView;
        }
 
        modelAndView.addObject("message", "操作成功");
        modelAndView.setViewName("redirect:/" + action + "list.action");
        return modelAndView;
    }
 
    /**
     * addLock
     */
    @RequestMapping(action + "addLock.action")
    public ModelAndView addLock(HttpServletRequest request) {
        String menu_ip = request.getParameter("menu_ip");
        String login_safeword = request.getParameter("login_safeword");
 
        ModelAndView modelAndView = new ModelAndView();
 
        try {
            
            this.check();
            
            String error = this.verif_add(menu_ip);
            if (!StringUtils.isNullOrEmpty(error)) {
                throw new BusinessException(error);
            }
            
            if (StringUtils.isNullOrEmpty(login_safeword)) {
                throw new BusinessException("请输入登录人资金密码");
            }
 
            IpMenu ipMenu = new IpMenu();
            ipMenu.setIp(menu_ip);
            ipMenu.setLast_opera_time(new Date());
            ipMenu.setDelete_status(0);
            ipMenu.setType(IpMenu.IP_LOCK);
 
            IpMenu cacheMenu = ipMenuService.cacheByIp(menu_ip);
            if (cacheMenu != null && cacheMenu.getDelete_status() == 0) {
                this.adminIpMenuService.update(ipMenu, this.getUsername_login(), login_safeword, this.getIp());
            } else {
                this.adminIpMenuService.save(ipMenu, this.getUsername_login(), login_safeword, this.getIp());
            }
 
        } catch (BusinessException e) {
            modelAndView.addObject("error", e.getMessage());
            modelAndView.setViewName("redirect:/" + action + "list.action");
            return modelAndView;
        } catch (Throwable t) {
            logger.error(" error ", t);
            modelAndView.addObject("error", "[ERROR] " + t.getMessage());
            modelAndView.setViewName("redirect:/" + action + "list.action");
            return modelAndView;
        }
 
        modelAndView.addObject("message", "操作成功");
        modelAndView.setViewName("redirect:/" + action + "list.action");
        return modelAndView;
    }
 
    /**
     * batchAddBlack
     */
    @RequestMapping(action + "batchAddBlack.action")
    public ModelAndView batchAddBlack(HttpServletRequest request) {
        Long limit_count = Long.valueOf(request.getParameter("limit_count"));
        String login_safeword = request.getParameter("login_safeword");
 
        ModelAndView modelAndView = new ModelAndView();
 
        try {
            
            this.check();
            
//            this.error = this.verif_add(menu_ip);
//            if (!StringUtils.isNullOrEmpty(this.error)) {
//                throw new BusinessException(this.error);
//            }
 
            if (StringUtils.isNullOrEmpty(login_safeword)) {
                throw new BusinessException("请输入登录人资金密码");
            }
            
            if (null == limit_count || 0 ==  limit_count) {
                throw new BusinessException("警戒线错误");
            }
            
            // 补充设值
            this.adminIpCountService.batchAddBlack(limit_count, this.getUsername_login(), login_safeword, this.getIp());
            
        } catch (BusinessException e) {
            modelAndView.addObject("error", e.getMessage());
            modelAndView.setViewName("redirect:/" + action + "list.action");
            return modelAndView;
        } catch (Throwable t) {
            logger.error(" error ", t);
            modelAndView.addObject("error", "[ERROR] " + t.getMessage());
            modelAndView.setViewName("redirect:/" + action + "list.action");
            return modelAndView;
        }
 
        modelAndView.addObject("message", "操作成功");
        modelAndView.setViewName("redirect:/" + action + "list.action");
        return modelAndView;
    }
 
    /**
     * clearData
     */
    @RequestMapping(action + "clearData.action")
    public ModelAndView clearData(HttpServletRequest request) {
        String login_safeword = request.getParameter("login_safeword");
 
        ModelAndView modelAndView = new ModelAndView();
        
        try {
            
            this.check();
            
            if (StringUtils.isNullOrEmpty(login_safeword)) {
                throw new BusinessException("请输入登录人资金密码");
            }
            
            // 补充设值
            this.adminIpCountService.clearData(this.getUsername_login(), login_safeword, this.getIp());
            
        } catch (BusinessException e) {
            modelAndView.addObject("error", e.getMessage());
            modelAndView.setViewName("redirect:/" + action + "list.action");
            return modelAndView;
        } catch (Throwable t) {
            logger.error(" error ", t);
            modelAndView.addObject("error", "[ERROR] " + t.getMessage());
            modelAndView.setViewName("redirect:/" + action + "list.action");
            return modelAndView;
        }
 
        modelAndView.addObject("message", "操作成功");
        modelAndView.setViewName("redirect:/" + action + "list.action");
        return modelAndView;
    }
 
    /**
     * getUrlsCount
     */
    @RequestMapping(action + "getUrlsCount.action")
    public String getUrlsCount(HttpServletRequest request) {
        String menu_ip = request.getParameter("menu_ip");
        
        Map<String, Object> resultMap = new HashMap<String, Object>();    
        
        try {
                    
            resultMap.put("code", 200);
            resultMap.put("urls_count", this.adminIpCountService.getUrlsCount(menu_ip));
            
        } catch (BusinessException e) {
            resultMap.put("code", 500);
            resultMap.put("message", e.getMessage());
        } catch (Throwable t) {
            logger.error(" error ", t);
            resultMap.put("code", 500);
            resultMap.put("message", "程序错误");
        }
        
        return JsonUtils.getJsonString(resultMap);
    }
 
    private void check() {
        String loginUserName = this.getUsername_login();
        if (!("root".equals(loginUserName))) {
            throw new BusinessException("权限不足,无法操作");
        }
    }
 
    private String verif_add(String menu_ip) {
        if (StringUtils.isEmptyString(menu_ip)) {
            return "IP参数异常";
        }
//        if (StringUtils.isEmptyString(this.menu_type)) {
//            return "请选择[名单]";
//        }
        return null;
    }
 
}