2019-06-03 14:53:39 +08:00
|
|
|
package com.nis.web.controller.basics;
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.concurrent.BlockingQueue;
|
|
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
|
|
|
|
|
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
|
|
|
|
import org.jets3t.service.ServiceException;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
|
|
import org.springframework.ui.Model;
|
|
|
|
|
import org.springframework.web.bind.annotation.ModelAttribute;
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
|
|
|
|
|
|
|
|
|
|
import com.beust.jcommander.internal.Lists;
|
|
|
|
|
import com.nis.domain.FunctionRegionDict;
|
|
|
|
|
import com.nis.domain.FunctionServiceDict;
|
|
|
|
|
import com.nis.domain.Page;
|
|
|
|
|
import com.nis.domain.basics.CommonGroupInfo;
|
|
|
|
|
import com.nis.domain.basics.IpCommCfg;
|
|
|
|
|
import com.nis.domain.configuration.BaseIpCfg;
|
|
|
|
|
import com.nis.domain.configuration.CfgIndexInfo;
|
|
|
|
|
import com.nis.domain.configuration.template.IpCommCfgTemplate;
|
|
|
|
|
import com.nis.exceptions.MaatConvertException;
|
2019-06-10 18:31:52 +08:00
|
|
|
import com.nis.util.ConfigServiceUtil;
|
2019-06-03 14:53:39 +08:00
|
|
|
import com.nis.util.Constants;
|
|
|
|
|
import com.nis.util.DictUtils;
|
|
|
|
|
import com.nis.util.StringUtil;
|
|
|
|
|
import com.nis.util.excel.ImportBigExcel;
|
|
|
|
|
import com.nis.web.controller.BaseController;
|
|
|
|
|
import com.nis.web.security.UserUtils;
|
|
|
|
|
import com.nis.web.service.basics.IpCommGroupCfgService;
|
|
|
|
|
|
|
|
|
|
@Controller
|
|
|
|
|
@RequestMapping(value = "${adminPath}/basics/ip")
|
|
|
|
|
public class IpCommGroupController extends BaseController {
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private IpCommGroupCfgService ipCommGroupCfgService;
|
|
|
|
|
|
|
|
|
|
@RequestMapping(value = { "/list" })
|
|
|
|
|
public String list(Model model, @ModelAttribute("cfg") IpCommCfg entity, HttpServletRequest request, HttpServletResponse response) {
|
|
|
|
|
Page<IpCommCfg> page = ipCommGroupCfgService.findPage(new Page<IpCommCfg>(request, response, "r"),entity);
|
|
|
|
|
List<FunctionRegionDict> regionList = DictUtils.getFunctionRegionDictList(entity.getFunctionId());
|
|
|
|
|
List<FunctionServiceDict> serviceList = DictUtils.getFunctionServiceDictList(entity.getFunctionId());
|
2019-06-14 17:12:41 +08:00
|
|
|
List<CommonGroupInfo> policyGroupInfos=commonGroupManageService.findCommonGroupInfosByType(Constants.IP_OBJ_GROUP_TYPE);
|
2019-06-05 17:49:39 +08:00
|
|
|
|
2019-06-03 14:53:39 +08:00
|
|
|
model.addAttribute("page", page);
|
|
|
|
|
model.addAttribute("regionList", regionList);
|
|
|
|
|
model.addAttribute("serviceList", serviceList);
|
|
|
|
|
model.addAttribute("policyGroupInfos", policyGroupInfos);
|
|
|
|
|
|
|
|
|
|
return "/basics/ipCommonGroupCfgList";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@RequestMapping(value = { "/addForm" })
|
|
|
|
|
public String addForm(Model model, @ModelAttribute("cfg") CfgIndexInfo cfg, RedirectAttributes redirectAttributes,
|
|
|
|
|
HttpServletRequest request, HttpServletResponse response) {
|
|
|
|
|
cfg.setGroupType(5);
|
|
|
|
|
initFormCondition(model, cfg);
|
|
|
|
|
|
2019-06-14 17:12:41 +08:00
|
|
|
/*List<CommonGroupInfo> groupInfos=commonGroupManageService.findCommonGroupInfosByType(5);
|
|
|
|
|
model.addAttribute("policyGroupInfos", groupInfos);*/
|
2019-06-03 14:53:39 +08:00
|
|
|
model.addAttribute("_cfg", cfg);
|
|
|
|
|
return "/basics/ipCommGroupFormAdd";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@RequestMapping(value = { "/save" })
|
|
|
|
|
@RequiresPermissions(value = { "ip:common:config" })
|
|
|
|
|
public String save(Model model, @ModelAttribute("cfg") CfgIndexInfo cfg, RedirectAttributes redirectAttributes,
|
|
|
|
|
HttpServletRequest request, HttpServletResponse response) {
|
|
|
|
|
try {
|
|
|
|
|
ipCommGroupCfgService.saveIpCommGroupCfg(cfg);
|
2019-06-05 17:49:39 +08:00
|
|
|
addMessage(redirectAttributes, "success", "save_success");
|
2019-06-03 14:53:39 +08:00
|
|
|
} catch (Exception e) {
|
|
|
|
|
logger.error("信息保存失败", e);
|
|
|
|
|
if (e instanceof MaatConvertException) {
|
|
|
|
|
addMessage(redirectAttributes, "error", e.getMessage());
|
|
|
|
|
} else {
|
|
|
|
|
addMessage(redirectAttributes, "error", "save_failed");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return "redirect:" + adminPath + "/basics/ip/list?functionId=" + cfg.getFunctionId();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@RequestMapping(value = { "/updateForm" })
|
|
|
|
|
public String updateForm(Model model, @ModelAttribute("cfg") IpCommCfg cfg, RedirectAttributes redirectAttributes, String ids,
|
|
|
|
|
HttpServletRequest request, HttpServletResponse response) {
|
|
|
|
|
cfg = ipCommGroupCfgService.get(Long.parseLong(ids));
|
|
|
|
|
cfg.setGroupType(5);
|
2019-06-05 10:40:36 +08:00
|
|
|
|
2019-06-03 14:53:39 +08:00
|
|
|
initUpdateFormCondition(model, cfg);
|
2019-06-14 17:12:41 +08:00
|
|
|
List<CommonGroupInfo> groupInfos = commonGroupManageService.findCommonGroupInfosByType(Constants.IP_OBJ_GROUP_TYPE);
|
2019-06-03 14:53:39 +08:00
|
|
|
model.addAttribute("policyGroupInfos", groupInfos);
|
|
|
|
|
model.addAttribute("_cfg", cfg);
|
|
|
|
|
return "/basics/ipCommGroupFormUpdate";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@RequestMapping(value = { "/update" })
|
|
|
|
|
@RequiresPermissions(value = { "ip:common:config" })
|
2019-06-05 10:40:36 +08:00
|
|
|
public String update(Model model, @ModelAttribute("cfg") IpCommCfg cfg, RedirectAttributes redirectAttributes,
|
|
|
|
|
HttpServletRequest request, HttpServletResponse response) {
|
2019-06-03 14:53:39 +08:00
|
|
|
try {
|
|
|
|
|
ipCommGroupCfgService.update(cfg);
|
|
|
|
|
addMessage(redirectAttributes, "success", "save_success");
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
logger.error("信息保存失败", e);
|
|
|
|
|
addMessage(redirectAttributes, "error", "save_failed");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return "redirect:" + adminPath + "/basics/ip/list?functionId=" + cfg.getFunctionId();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@RequestMapping(value = { "/delete" })
|
|
|
|
|
@RequiresPermissions(value = { "ip:common:config" })
|
2019-06-11 17:25:10 +08:00
|
|
|
public String delete(String groupIds, String ids, Integer functionId, RedirectAttributes redirectAttributes) {
|
2019-06-03 14:53:39 +08:00
|
|
|
try {
|
2019-06-11 17:25:10 +08:00
|
|
|
ipCommGroupCfgService.delete(ids, groupIds);
|
2019-06-03 14:53:39 +08:00
|
|
|
addMessage(redirectAttributes, "success", "delete_success");
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
logger.error("Delete failed", e);
|
|
|
|
|
if (e instanceof MaatConvertException) {
|
|
|
|
|
addMessage(redirectAttributes, "error", e.getMessage());
|
|
|
|
|
} else {
|
|
|
|
|
addMessage(redirectAttributes, "error", "delete_failed");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return "redirect:" + adminPath + "/basics/ip/list?functionId=" + functionId;
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-05 10:40:36 +08:00
|
|
|
// 数据导出
|
2019-06-03 14:53:39 +08:00
|
|
|
@RequestMapping(value = "/exportIpComm")
|
2019-06-05 10:40:36 +08:00
|
|
|
public void exportIpCommonCfg(Model model, @ModelAttribute("cfg") IpCommCfg entity, String ids, RedirectAttributes redirectAttributes,
|
|
|
|
|
HttpServletRequest request, HttpServletResponse response) {
|
2019-06-03 14:53:39 +08:00
|
|
|
try {
|
|
|
|
|
List<String> titleList = new ArrayList<String>();
|
|
|
|
|
Map<String, Class<?>> classMap = new HashMap<String, Class<?>>();
|
|
|
|
|
Map<String, List> dataMap = new HashMap<String, List>();
|
|
|
|
|
Map<String, String> noExportMap = new HashMap<String, String>();
|
|
|
|
|
List<IpCommCfg> list = new ArrayList<IpCommCfg>();
|
|
|
|
|
if (!StringUtil.isEmpty(ids)) {
|
|
|
|
|
list = ipCommGroupCfgService.findByPage(ids);
|
|
|
|
|
} else {
|
|
|
|
|
Page<IpCommCfg> pageInfo = new Page<IpCommCfg>(request, response, "r");
|
|
|
|
|
pageInfo.setPageNo(1);
|
|
|
|
|
pageInfo.setPageSize(Constants.MAX_EXPORT_SIZE);
|
|
|
|
|
Page<IpCommCfg> page = ipCommGroupCfgService.findPage(pageInfo, entity);
|
|
|
|
|
list = page.getList();
|
|
|
|
|
}
|
2019-06-10 18:31:52 +08:00
|
|
|
|
|
|
|
|
CommonGroupInfo groupInfo = new CommonGroupInfo();
|
|
|
|
|
for (IpCommCfg cfg : list) {
|
|
|
|
|
groupInfo.setServiceGroupId(cfg.getGroupId());
|
|
|
|
|
CommonGroupInfo commonGroupInfo = commonGroupManageService.getGroupInfo(groupInfo);
|
|
|
|
|
cfg.setGroupName(commonGroupInfo.getGroupName());
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-03 14:53:39 +08:00
|
|
|
titleList.add(entity.getMenuNameCode());
|
2019-06-10 18:31:52 +08:00
|
|
|
classMap.put(entity.getMenuNameCode(), IpCommCfg.class);
|
2019-06-03 14:53:39 +08:00
|
|
|
String cfgIndexInfoNoExport = ",block_type,do_log,action"
|
2019-06-10 18:31:52 +08:00
|
|
|
+ ",letter,whether_area_block,classification,attribute,label,userregion1,userregion2,userregion3,userregion4,userregion5"
|
|
|
|
|
+ ",src_ip_pattern,src_port_pattern,client_port,dest_ip_pattern,dest_port_pattern,server_port,cfg_id,is_audit,auditor,valid_identifier,ir_type,";
|
2019-06-03 14:53:39 +08:00
|
|
|
// 时间过滤
|
|
|
|
|
if (entity.getSearch_create_time_start() == null) {
|
|
|
|
|
cfgIndexInfoNoExport = ",config_time" + cfgIndexInfoNoExport;
|
|
|
|
|
}
|
|
|
|
|
if (entity.getSearch_edit_time_start() == null) {
|
|
|
|
|
cfgIndexInfoNoExport = ",edit_time" + cfgIndexInfoNoExport;
|
|
|
|
|
}
|
|
|
|
|
if (entity.getSearch_audit_time_start() == null) {
|
|
|
|
|
cfgIndexInfoNoExport = ",audit_time" + cfgIndexInfoNoExport;
|
|
|
|
|
}
|
|
|
|
|
if (!StringUtil.isEmpty(entity.gethColumns())) {
|
|
|
|
|
cfgIndexInfoNoExport = "," + entity.gethColumns() + "," + cfgIndexInfoNoExport;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
noExportMap.put(entity.getMenuNameCode(), cfgIndexInfoNoExport);
|
|
|
|
|
dataMap.put(entity.getMenuNameCode(), list);
|
|
|
|
|
String timeRange = initTimeMap(entity);
|
|
|
|
|
noExportMap.put("timeRange", timeRange);
|
|
|
|
|
|
|
|
|
|
if ("csv".equals(entity.getExType())) {
|
|
|
|
|
this._exportCsv(model, request, response, redirectAttributes, entity.getMenuNameCode(), titleList,
|
|
|
|
|
classMap, dataMap, noExportMap);
|
|
|
|
|
} else {
|
|
|
|
|
this._export(model, request, response, redirectAttributes, entity.getMenuNameCode(), titleList,
|
|
|
|
|
classMap, dataMap, noExportMap);
|
|
|
|
|
}
|
2019-06-05 10:40:36 +08:00
|
|
|
|
2019-06-03 14:53:39 +08:00
|
|
|
} catch (Exception e) {
|
|
|
|
|
logger.error("IpCommGroupCfg export failed", e);
|
|
|
|
|
addMessage(redirectAttributes, "error", "export_failed");
|
2019-06-05 10:40:36 +08:00
|
|
|
|
2019-06-03 14:53:39 +08:00
|
|
|
}
|
2019-06-05 10:40:36 +08:00
|
|
|
|
2019-06-03 14:53:39 +08:00
|
|
|
}
|
2019-06-10 18:31:52 +08:00
|
|
|
|
|
|
|
|
// 数据导入
|
2019-06-03 14:53:39 +08:00
|
|
|
@RequestMapping(value = "import", method=RequestMethod.POST)
|
|
|
|
|
public String importIp(HttpServletRequest request,HttpServletResponse response,RedirectAttributes redirectAttributes,
|
|
|
|
|
@RequestParam("files") MultipartFile[] files, Integer serviceDictId ,Integer requestId ,String attribute ,String classify
|
|
|
|
|
,String regionDictIds ,String importPath) {
|
|
|
|
|
logger.warn("import start...");
|
|
|
|
|
long start=System.currentTimeMillis();
|
|
|
|
|
ImportBigExcel ei=null;
|
|
|
|
|
try {
|
|
|
|
|
FunctionServiceDict serviceDict = DictUtils.getFunctionServiceDict(serviceDictId);
|
|
|
|
|
StringBuffer errTip=new StringBuffer();
|
|
|
|
|
BlockingQueue<BaseIpCfg> ipPortCfgs =null;
|
2019-06-10 18:31:52 +08:00
|
|
|
|
2019-06-03 14:53:39 +08:00
|
|
|
for (int i = 0; i < files.length; i++) {
|
|
|
|
|
MultipartFile file = files[i];
|
|
|
|
|
ei = new ImportBigExcel(file, 0, 1);
|
|
|
|
|
FunctionRegionDict regionDict = DictUtils.getFunctionRegionDict(Integer.parseInt(regionDictIds.split(",")[i]));
|
|
|
|
|
//加载模板
|
|
|
|
|
loadTemplate(ei,regionDict, serviceDict);
|
|
|
|
|
//------------------------------------check format start----------------------------
|
|
|
|
|
if (regionDict.getRegionType().equals(1)) {// IP
|
|
|
|
|
BlockingQueue<IpCommCfgTemplate> list = ei.getDataList(IpCommCfgTemplate.class );
|
|
|
|
|
ipPortCfgs=this.checkIpCfgMulity(errTip,serviceDict, regionDict, null,null, list);
|
|
|
|
|
}
|
|
|
|
|
//删除文件
|
|
|
|
|
if(ei.getUploadFile()!=null&&ei.getUploadFile().exists()) {
|
|
|
|
|
ei.getUploadFile().delete();
|
|
|
|
|
}
|
|
|
|
|
//------------------------------------check format end----------------------------
|
|
|
|
|
Date date = new Date();
|
|
|
|
|
String isSend = request.getParameter("isSend")==null?"":request.getParameter("isSend");
|
|
|
|
|
|
|
|
|
|
if (regionDict.getRegionType().equals(1)) {// IP
|
|
|
|
|
List<BaseIpCfg> _ipPortCfgs=Lists.newArrayList(Constants.MAAT_JSON_SEND_SIZE);
|
|
|
|
|
while(!ipPortCfgs.isEmpty()) {
|
|
|
|
|
ipPortCfgs.drainTo(_ipPortCfgs, Constants.MAAT_JSON_SEND_SIZE);
|
2019-06-10 18:31:52 +08:00
|
|
|
List<Integer> regionIds = Lists.newArrayList(_ipPortCfgs.size());
|
|
|
|
|
try {
|
|
|
|
|
regionIds = ConfigServiceUtil.getId(3,_ipPortCfgs.size());
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
logger.info("获取域ID出错");
|
|
|
|
|
throw new MaatConvertException("<spring:message code=\"request_service_failed\"/>:"+e.getMessage());
|
|
|
|
|
}
|
2019-06-03 14:53:39 +08:00
|
|
|
|
2019-06-10 18:31:52 +08:00
|
|
|
int index = 0;
|
2019-06-03 14:53:39 +08:00
|
|
|
for (BaseIpCfg cfg : _ipPortCfgs) {
|
|
|
|
|
cfg.setAction(serviceDict==null?null:serviceDict.getAction());
|
|
|
|
|
cfg.setCfgRegionCode(regionDict.getConfigRegionCode());
|
|
|
|
|
cfg.setCfgType(regionDict.getConfigRegionValue());
|
|
|
|
|
cfg.setCreateTime(date);
|
|
|
|
|
cfg.setCreatorId(UserUtils.getUser().getId());
|
|
|
|
|
//cfg.setDoLog(2);
|
|
|
|
|
cfg.setCompileId(0);
|
|
|
|
|
cfg.setFunctionId(regionDict.getFunctionId());
|
2019-06-10 18:31:52 +08:00
|
|
|
cfg.setIsAudit(Constants.AUDIT_NOT_YET);
|
|
|
|
|
cfg.setIsValid(Constants.VALID_NO);
|
2019-06-03 14:53:39 +08:00
|
|
|
cfg.setIsAreaEffective(0);
|
|
|
|
|
cfg.setLable("0");
|
|
|
|
|
cfg.setRequestId(StringUtil.isEmpty(requestId) ? 0 : requestId);
|
|
|
|
|
cfg.setAttribute(attribute);
|
|
|
|
|
cfg.setClassify(classify);
|
|
|
|
|
cfg.setServiceId(serviceDict==null?null:serviceDict.getServiceId());
|
|
|
|
|
cfg.setTableName("ip_comm_cfg");
|
2019-06-10 18:31:52 +08:00
|
|
|
cfg.setRegionId(regionIds.get(index));
|
2019-06-14 17:12:41 +08:00
|
|
|
cfg.setGroupName(cfg.getGroupName().toUpperCase());
|
2019-06-10 18:31:52 +08:00
|
|
|
index++;
|
|
|
|
|
|
2019-06-03 14:53:39 +08:00
|
|
|
}
|
2019-06-10 18:31:52 +08:00
|
|
|
ipCommGroupCfgService.saveAndSend(regionDict, serviceDict, _ipPortCfgs);
|
2019-06-03 14:53:39 +08:00
|
|
|
_ipPortCfgs.clear();
|
|
|
|
|
}
|
2019-06-10 18:31:52 +08:00
|
|
|
|
2019-06-03 14:53:39 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(errTip.toString().length()>0) {
|
|
|
|
|
addMessage(redirectAttributes,"error", errTip.toString());
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
if(ei!=null) {
|
|
|
|
|
if(ei.getUploadFile().exists()) {
|
|
|
|
|
ei.getUploadFile().delete();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(e instanceof MaatConvertException) {
|
|
|
|
|
addMessage(redirectAttributes,"error", "request_service_failed");
|
|
|
|
|
}else if(e instanceof ServiceException) {
|
|
|
|
|
addMessage(redirectAttributes,"error", e.getMessage());
|
|
|
|
|
}else if(e instanceof IndexOutOfBoundsException){
|
|
|
|
|
addMessage(redirectAttributes,"error", "template_error");
|
|
|
|
|
}else {
|
|
|
|
|
addMessage(redirectAttributes,"error", "import_failed");
|
|
|
|
|
}
|
|
|
|
|
logger.error("import failed", e);
|
|
|
|
|
}
|
|
|
|
|
long end=System.currentTimeMillis();
|
|
|
|
|
logger.warn("import finish,cost:"+(end-start));
|
|
|
|
|
return "redirect:" + adminPath+ importPath;
|
|
|
|
|
}
|
2019-06-05 10:40:36 +08:00
|
|
|
|
2019-06-03 14:53:39 +08:00
|
|
|
}
|