From 00acc9c94aae34324e8babc16a5585924868fbde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=AE=B5=E5=86=AC=E6=A2=85?= Date: Fri, 19 Apr 2019 18:32:46 +0800 Subject: [PATCH] =?UTF-8?q?=E7=99=BD=E5=90=8D=E5=8D=95=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E5=90=84=E4=B8=AA=E6=93=8D=E4=BD=9C=E7=9A=84=E5=AE=9A=E6=97=B6?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E5=A4=84=E7=90=86=20=E5=90=84=E7=A7=8D?= =?UTF-8?q?=E6=89=B9=E9=87=8F=E6=93=8D=E4=BD=9C=E5=A2=9E=E5=8A=A0=E5=AE=9A?= =?UTF-8?q?=E6=97=B6=E4=BB=BB=E5=8A=A1=E7=9A=84=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../nis/web/controller/BaseController.java | 235 +++++---- .../ntc/WhiteListController.java | 21 - .../java/com/nis/web/service/BaseService.java | 465 ++++++++++-------- .../service/configuration/IpCfgService.java | 27 +- .../messages/message_zh_CN.properties | 11 +- 5 files changed, 413 insertions(+), 346 deletions(-) diff --git a/src/main/java/com/nis/web/controller/BaseController.java b/src/main/java/com/nis/web/controller/BaseController.java index 6d4f887cd..05c9e5416 100644 --- a/src/main/java/com/nis/web/controller/BaseController.java +++ b/src/main/java/com/nis/web/controller/BaseController.java @@ -64,7 +64,6 @@ import com.nis.domain.configuration.BaseCfg; import com.nis.domain.configuration.BaseIpCfg; import com.nis.domain.configuration.BaseStringCfg; import com.nis.domain.configuration.CfgIndexInfo; -import com.nis.domain.configuration.ComplexStringCfgTemplate; import com.nis.domain.configuration.ComplexkeywordCfg; import com.nis.domain.configuration.DdosIpCfg; import com.nis.domain.configuration.DnsIpCfg; @@ -75,7 +74,6 @@ import com.nis.domain.configuration.PxyObjKeyring; import com.nis.domain.configuration.PxyObjTrustedCaCert; import com.nis.domain.configuration.PxyObjTrustedCaCrl; import com.nis.domain.configuration.RequestInfo; -import com.nis.domain.configuration.StringCfgTemplate; import com.nis.domain.configuration.template.AppDomainTemplate; import com.nis.domain.configuration.template.AppPayloadTemplate; import com.nis.domain.configuration.template.AsnIpTemplate; @@ -100,7 +98,6 @@ import com.nis.domain.configuration.template.HttpsReplaceIpTemplate; import com.nis.domain.configuration.template.HttpsReplaceTemplate; import com.nis.domain.configuration.template.IpAllNotDoLogTemplate; import com.nis.domain.configuration.template.IpAllTemplate; -import com.nis.domain.configuration.template.IpCfgTemplate; import com.nis.domain.configuration.template.IpPayloadTemplate; import com.nis.domain.configuration.template.IpRateLimitTemplate; import com.nis.domain.configuration.template.IpSpoofingTemplate; @@ -771,75 +768,6 @@ public class BaseController { } return msgProp; } - @Deprecated - public void importCfgTemplate(HttpServletRequest request, HttpServletResponse response, - RedirectAttributes redirectAttributes, Integer functionId, Integer cfgRegionCode) { - Properties msgProp = getMsgProp(); - try { - List dictList = DictUtils.getFunctionRegionDictList(functionId); - for (FunctionRegionDict dict : dictList) { - if (dict.getConfigRegionCode() == cfgRegionCode) { - String fileName = dict.getConfigRegionValue() + ".xlsx"; - if (dict.getRegionType() == 1) { - List list = Lists.newArrayList(); - list.add(new IpCfgTemplate()); - new ExportExcel(new FunctionServiceDict(), new FunctionRegionDict(), msgProp, null, - IpCfgTemplate.class, 2).setDataList(msgProp, list, null) - .write(request, response, fileName).dispose(); - } else if (dict.getRegionType() == 2) { - List list = Lists.newArrayList(); - list.add(new StringCfgTemplate()); - new ExportExcel(new FunctionServiceDict(), new FunctionRegionDict(), msgProp, null, - StringCfgTemplate.class, 2).setDataList(msgProp, list, null) - .write(request, response, fileName).dispose(); - } else if (dict.getRegionType() == 3) { - List list = Lists.newArrayList(); - list.add(new ComplexStringCfgTemplate()); - new ExportExcel(new FunctionServiceDict(), new FunctionRegionDict(), msgProp, null, - ComplexStringCfgTemplate.class, 2).setDataList(msgProp, list, null) - .write(request, response, fileName).dispose(); - } - } - } - - } catch (Exception e) { - msgProp = null; - e.printStackTrace(); - } - } - @Deprecated - public void importCfgTemplate(HttpServletRequest request, HttpServletResponse response, - RedirectAttributes redirectAttributes, Integer functionId, Integer cfgRegionCode, Class clazz) { - Properties msgProp = getMsgProp(); - try { - List dictList = DictUtils.getFunctionRegionDictList(functionId); - for (FunctionRegionDict dict : dictList) { - if (dict.getConfigRegionCode() == cfgRegionCode) { - String fileName = dict.getConfigRegionValue() + ".xlsx"; - if (dict.getRegionType() == 1) { - List list = Lists.newArrayList(); - list.add((IpCfgTemplate) clazz.newInstance()); - new ExportExcel(new FunctionServiceDict(), new FunctionRegionDict(), msgProp, null, clazz, 2) - .setDataList(msgProp, list, null).write(request, response, fileName).dispose(); - } else if (dict.getRegionType() == 2) { - List list = Lists.newArrayList(); - list.add(new StringCfgTemplate()); - new ExportExcel(new FunctionServiceDict(), new FunctionRegionDict(), msgProp, null, clazz, 2) - .setDataList(msgProp, list, null).write(request, response, fileName).dispose(); - } else if (dict.getRegionType() == 3) { - List list = Lists.newArrayList(); - list.add(new ComplexStringCfgTemplate()); - new ExportExcel(new FunctionServiceDict(), new FunctionRegionDict(), msgProp, null, clazz, 2) - .setDataList(msgProp, list, null).write(request, response, fileName).dispose(); - } - } - } - - } catch (Exception e) { - msgProp = null; - e.printStackTrace(); - } - } public void setLogAction(BaseLogEntity log, List serviceList) { if (!StringUtil.isEmpty(serviceList)) { @@ -3869,7 +3797,8 @@ public class BaseController { maatBean = new ToMaatBean(); configCompileList = new ArrayList(); List list = new ArrayList(); - List newList = new ArrayList(); + List notAuditList = new ArrayList(); + List auditList = new ArrayList(); List ids = new ArrayList(); List compileIds = Lists.newArrayList(); if(entity.getServiceId().equals(3)){//ip drop回调类配置用了主表和子表关系 @@ -3882,9 +3811,21 @@ public class BaseController { List subList = commonPolicyService.getIpDropList("ip_port_cfg", compileIds); for(int i=0;i(); list=commonPolicyService.getPxyObjTrustedCrlCfgListByCertId(ids); for(int i=0;i ipConvert(IpCfg dstIp, BaseIpCfg srcIp) { List ipConvertList = Lists.newArrayList(); - boolean isRange = ((srcIp.getIpPattern() != null && srcIp.getIpPattern() == 2) - || (srcIp.getSrcIpAddress() != null && srcIp.getSrcIpAddress().indexOf("-") > -1) - || (srcIp.getDestIpAddress() != null && srcIp.getDestIpAddress().indexOf("-") > -1)); - if (isRange) { - List tempList = Lists.newArrayList(); - List tempList1 = Lists.newArrayList(); - if (srcIp.getIpType().intValue() == 4) { - if (srcIp.getSrcIpAddress() != null) { - String startIpPart = srcIp.getSrcIpAddress().split("-")[0]; - String endIpPart = srcIp.getSrcIpAddress().split("-")[1]; - Integer startNum = Integer.parseInt(startIpPart.split("\\.")[3]); - Integer endNum = Integer.parseInt(endIpPart.split("\\.")[3]); - for (int i = startNum; i <= endNum; i++) { - IpCfg tempIp = new IpCfg(); - BeanUtils.copyProperties(dstIp, tempIp); - tempIp.setSrcIp(startIpPart.substring(0, startIpPart.lastIndexOf(".") + 1) + i); - tempIp.setSrcIpMask("255.255.255.255"); - tempList.add(tempIp); + List tempList = Lists.newArrayList(); + List tempList1 = Lists.newArrayList(); + if (srcIp.getIpType().equals(4)) {// IP V4 + if(srcIp.getSrcIpPattern().equals(2)) {//源IP范围 + if (srcIp.getSrcIpAddress() != null) { + String startIpPart = srcIp.getSrcIpAddress().split("-")[0]; + String endIpPart = srcIp.getSrcIpAddress().split("-")[1]; + Integer startNum = Integer.parseInt(startIpPart.split("\\.")[3]); + Integer endNum = Integer.parseInt(endIpPart.split("\\.")[3]); + for (int i = startNum; i <= endNum; i++) { + IpCfg tempIp = new IpCfg(); + BeanUtils.copyProperties(dstIp, tempIp); + tempIp.setSrcIp(startIpPart.substring(0, startIpPart.lastIndexOf(".") + 1) + i); + tempIp.setSrcIpMask("255.255.255.255"); + tempList.add(tempIp); + } + }else { + dstIp.setSrcIp("0.0.0.0"); + dstIp.setSrcIpMask("255.255.255.255"); + tempList.add(dstIp); } + }else if(srcIp.getSrcIpPattern().equals(1)){ + Integer srcMaskNum = Integer.parseInt(srcIp.getSrcIpAddress().split("/")[1]); + if (srcMaskNum == 0) { + dstIp.setSrcIpMask("0.0.0.0"); } else { - dstIp.setSrcIp("0.0.0.0"); - dstIp.setSrcIpMask("255.255.255.255"); - tempList.add(dstIp); + dstIp.setSrcIpMask(IpUtil.convertMask(srcMaskNum)); } - if (srcIp.getDestIpAddress() != null) { + dstIp.setSrcIp(srcIp.getSrcIpAddress().split("/")[0]); + tempList.add(dstIp); + }else if(srcIp.getSrcIpPattern().equals(3)){ + dstIp.setSrcIp(srcIp.getSrcIpAddress()); + dstIp.setSrcIpMask("255.255.255.255"); + tempList.add(dstIp); + }else { + throw new RuntimeException("Unsupported IP Pattern " + srcIp.getSrcIpPattern()); + } + if (srcIp.getDestIpAddress() != null) { + if(srcIp.getDestIpPattern().equals(2)) { String startIpPart = srcIp.getDestIpAddress().split("-")[0]; String endIpPart = srcIp.getDestIpAddress().split("-")[1]; Integer startNum = Integer.parseInt(startIpPart.split("\\.")[3]); @@ -1088,217 +1111,93 @@ public abstract class BaseService { } } tempList.clear(); - } else { + }else if(srcIp.getDestIpPattern().equals(1)) { + Integer dstMaskNum = Integer.parseInt(srcIp.getDestIpAddress().split("/")[1]); for (IpCfg _cfg : tempList) { - _cfg.setDstIp("0.0.0.0"); - _cfg.setSrcIpMask("255.255.255.255"); - convertPortValues(_cfg, srcIp); + IpCfg tempIp = new IpCfg(); + BeanUtils.copyProperties(_cfg, tempIp); + if (dstMaskNum == 0) { + tempIp.setDstIpMask("0.0.0.0"); + } else { + tempIp.setDstIpMask(IpUtil.convertMask(dstMaskNum)); + } + tempIp.setDstIp(srcIp.getDestIpAddress().split("/")[0]); + if (!tempIp.getSrcIp().equals(tempIp.getDstIp())) { + // 处理 + convertPortValues(tempIp, srcIp); + tempList1.add(tempIp); + } } + tempList.clear(); + }else { + for (IpCfg _cfg : tempList) { + IpCfg tempIp = new IpCfg(); + BeanUtils.copyProperties(_cfg, tempIp); + tempIp.setDstIp(srcIp.getDestIpAddress()); + if (!tempIp.getSrcIp().equals(tempIp.getDstIp())) { + tempIp.setDstIpMask("255.255.255.255"); + // 处理 + convertPortValues(tempIp, srcIp); + tempList1.add(tempIp); + } + } + tempList.clear(); } - if (tempList1.size() > 0) { - ipConvertList.addAll(tempList1); - } else { - ipConvertList.addAll(tempList); + }else { + for (IpCfg _cfg : tempList) { + _cfg.setDstIp("0.0.0.0"); + _cfg.setSrcIpMask("255.255.255.255"); + convertPortValues(_cfg, srcIp); } - } else if (srcIp.getIpType().intValue() == 6) { - if (srcIp.getSrcIpAddress() != null) { + } + if (tempList1.size() > 0) { + ipConvertList.addAll(tempList1); + } else { + ipConvertList.addAll(tempList); + } + }else if(srcIp.getIpType().equals(6)){// IP V6 + if (srcIp.getSrcIpAddress() != null) { + if(srcIp.getSrcIpPattern().equals(2)) { IPv6Address address1 = IPv6Address.fromString(srcIp.getSrcIpAddress().split("-")[0]); IPv6Address address2 = IPv6Address.fromString(srcIp.getSrcIpAddress().split("-")[1]); IPv6Network network = IPv6Network.fromTwoAddresses(address1, address2); dstIp.setSrcIp(address1.toString()); dstIp.setSrcIpMask(network.getNetmask().asAddress().toString()); - } else { - dstIp.setSrcIp("::"); + }else if(srcIp.getSrcIpPattern().equals(1)){// IP/掩码 + IPv6Network strangeNetwork = IPv6Network.fromString(srcIp.getSrcIpAddress()); + dstIp.setSrcIp(srcIp.getSrcIpAddress().split("/")[0]); + dstIp.setSrcIpMask(strangeNetwork.getNetmask().asAddress().toString()); + }else {// IP + dstIp.setSrcIp(srcIp.getSrcIpAddress()); dstIp.setSrcIpMask("FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF"); } - if (srcIp.getDestIpAddress() != null) { + } else { + dstIp.setSrcIp("::"); + dstIp.setSrcIpMask("FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF"); + } + if (srcIp.getDestIpAddress() != null) { + if(srcIp.getDestIpPattern().equals(2)) { IPv6Address address1 = IPv6Address.fromString(srcIp.getDestIpAddress().split("-")[0]); IPv6Address address2 = IPv6Address.fromString(srcIp.getDestIpAddress().split("-")[1]); IPv6Network network = IPv6Network.fromTwoAddresses(address1, address2); dstIp.setDstIp(address1.toString()); dstIp.setDstIpMask(network.getNetmask().asAddress().toString()); - } else { - dstIp.setDstIp("::"); - dstIp.setDstIpMask("FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF"); - } - - ipConvertList.add(dstIp); - } else { - throw new RuntimeException("Unsupported IP type " + srcIp.getIpType()); - } - } else { - if (srcIp.getSrcIpAddress() != null) { - if (srcIp.getSrcIpAddress().indexOf("/") != -1) { - if (srcIp.getIpType() == 4 /* || srcIp.getIpType()==46 */) {// 46表示源ip为ipv4,目的ip为ipv6 - Integer srcMaskNum = Integer.parseInt(srcIp.getSrcIpAddress().split("/")[1]); - if (srcMaskNum == 0) { - dstIp.setSrcIpMask("0.0.0.0"); - } else { - dstIp.setSrcIpMask(IpUtil.convertMask(srcMaskNum)); - } - - dstIp.setSrcIp(srcIp.getSrcIpAddress().split("/")[0]); - } else if (srcIp.getIpType() == 6/* || srcIp.getIpType()==64 */) {// 64表示源ip为ipv6,目的ip为ipv4 - IPv6Network strangeNetwork = IPv6Network.fromString(srcIp.getSrcIpAddress()); - dstIp.setSrcIp(srcIp.getSrcIpAddress().split("/")[0]); - dstIp.setSrcIpMask(strangeNetwork.getNetmask().asAddress().toString()); - } /* - * else { Pattern - * patternV4Subnet=Pattern.compile(Constants.IPV4_IP_SUBNET_REGEXP); Pattern - * patternV6Subnet=Pattern.compile(Constants.IPV6_IP_SUBNET_REGEXP); Matcher - * matchernV4Subnet=patternV4Subnet.matcher(srcIp.getSrcIpAddress()); Matcher - * matcherV6Subnet=patternV6Subnet.matcher(srcIp.getSrcIpAddress()); - * if(matchernV4Subnet.matches()) { Integer srcMaskNum = - * Integer.parseInt(srcIp.getSrcIpAddress().split("/")[1]); if(srcMaskNum==0){ - * dstIp.setSrcIpMask("0.0.0.0"); }else{ - * dstIp.setSrcIpMask(IpUtil.convertMask(srcMaskNum)); } - * dstIp.setSrcIp(srcIp.getSrcIpAddress().split("/")[0]); }else - * if(matcherV6Subnet.matches()){ IPv6Network strangeNetwork = - * IPv6Network.fromString(srcIp.getSrcIpAddress()); - * dstIp.setSrcIp(srcIp.getSrcIpAddress().split("/")[0]); - * dstIp.setSrcIpMask(strangeNetwork.getNetmask().asAddress().toString()); }else - * { throw new RuntimeException("Invalid IP/subnet mask format"); } } - */ - else { - throw new RuntimeException("Unsupported IP type " + srcIp.getIpType()); - } - } else { - if (srcIp.getIpType() == 4/* || srcIp.getIpType()==46 */) {// 46表示源ip为ipv4,目的ip为ipv6 - dstIp.setSrcIp(srcIp.getSrcIpAddress()); - dstIp.setSrcIpMask("255.255.255.255"); - } else if (srcIp.getIpType() == 6/* || srcIp.getIpType()==64 */) {// 64表示源ip为ipv6,目的ip为ipv4 - dstIp.setSrcIp(srcIp.getSrcIpAddress()); - dstIp.setSrcIpMask("FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF"); - } /* - * else {//all Pattern patternV4=Pattern.compile(Constants.IPV4_IP_REGEXP); - * Pattern patternV6=Pattern.compile(Constants.IPV6_IP_REGEXP); Matcher - * matcherV4=patternV4.matcher(srcIp.getSrcIpAddress()); Matcher - * matcherV6=patternV6.matcher(srcIp.getSrcIpAddress()); if(matcherV4.matches()) - * { dstIp.setSrcIp(srcIp.getSrcIpAddress()); - * dstIp.setSrcIpMask("255.255.255.255"); }else if(matcherV6.matches()) { - * dstIp.setSrcIp(srcIp.getSrcIpAddress()); - * dstIp.setSrcIpMask("FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF"); }else { throw - * new RuntimeException("Invalid IP format"); } } - */ - else { - throw new RuntimeException("Unsupported IP type " + srcIp.getIpType()); - } - } - } else { - if (srcIp.getIpType() == 4/* || srcIp.getIpType()==46 */) {// 46表示源ip为ipv4,目的ip为ipv6 - dstIp.setSrcIp(srcIp.getSrcIpAddress()); - dstIp.setSrcIpMask("255.255.255.255"); - } else if (srcIp.getIpType() == 6/* || srcIp.getIpType()==64 */) {// 64表示源ip为ipv6,目的ip为ipv4 - dstIp.setSrcIp(srcIp.getSrcIpAddress()); - dstIp.setSrcIpMask("FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF"); - } /* - * else {//all dstIp.setSrcIp(srcIp.getSrcIpAddress()); - * dstIp.setSrcIpMask("255.255.255.255"); } - */ - else { - throw new RuntimeException("Unsupported IP type " + srcIp.getIpType()); - } - } - if (srcIp.getDestIpAddress() != null) { - if (srcIp.getDestIpAddress().indexOf("/") != -1) { - if (srcIp.getIpType() == 4/* || srcIp.getIpType()==64 */) {// 64表示源ip为ipv6,目的ip为ipv4 - Integer dstMaskNum = Integer.parseInt(srcIp.getDestIpAddress().split("/")[1]); - if (dstMaskNum == 0) { - dstIp.setDstIpMask("0.0.0.0"); - } else { - dstIp.setDstIpMask(IpUtil.convertMask(dstMaskNum)); - ; - } - dstIp.setDstIp(srcIp.getDestIpAddress().split("/")[0]); - } else if (srcIp.getIpType() == 6/* || srcIp.getIpType()==46 */) {// 46表示源ip为ipv4,目的ip为ipv6 - IPv6Network strangeNetwork = IPv6Network.fromString(srcIp.getDestIpAddress()); - dstIp.setDstIp(srcIp.getDestIpAddress().split("/")[0]); - dstIp.setDstIpMask(strangeNetwork.getNetmask().asAddress().toString()); - } /* - * else { Pattern - * patternV4Subnet=Pattern.compile(Constants.IPV4_IP_SUBNET_REGEXP); Pattern - * patternV6Subnet=Pattern.compile(Constants.IPV6_IP_SUBNET_REGEXP); Matcher - * matchernV4Subnet=patternV4Subnet.matcher(srcIp.getDestIpAddress()); Matcher - * matcherV6Subnet=patternV6Subnet.matcher(srcIp.getDestIpAddress()); - * if(matchernV4Subnet.matches()) { Integer dstMaskNum = - * Integer.parseInt(srcIp.getDestIpAddress().split("/")[1]); if(dstMaskNum==0){ - * dstIp.setDstIpMask("0.0.0.0"); }else{ - * dstIp.setDstIpMask(IpUtil.convertMask(dstMaskNum));; } - * dstIp.setDstIp(srcIp.getDestIpAddress().split("/")[0]); }else - * if(matcherV6Subnet.matches()){ IPv6Network strangeNetwork = - * IPv6Network.fromString(srcIp.getDestIpAddress()); - * dstIp.setDstIp(srcIp.getDestIpAddress().split("/")[0]); - * dstIp.setDstIpMask(strangeNetwork.getNetmask().asAddress().toString()); }else - * { throw new RuntimeException("Invalid IP/subnet mask format"); } } - */ - else { - throw new RuntimeException("Unsupported IP type " + srcIp.getIpType()); - } - - } else { - if (srcIp.getIpType() == 4/* || srcIp.getIpType()==64 */) {// 64表示源ip为ipv6,目的ip为ipv4 - dstIp.setDstIp(srcIp.getDestIpAddress()); - dstIp.setDstIpMask("255.255.255.255"); - } else if (srcIp.getIpType() == 6/* || srcIp.getIpType()==46 */) {// 46表示源ip为ipv4,目的ip为ipv6 - dstIp.setDstIp(srcIp.getDestIpAddress()); - dstIp.setDstIpMask("FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF"); - } /* - * else {//all Pattern patternV4=Pattern.compile(Constants.IPV4_IP_REGEXP); - * Pattern patternV6=Pattern.compile(Constants.IPV6_IP_REGEXP); Matcher - * matcherV4=patternV4.matcher(srcIp.getDestIpAddress()); Matcher - * matcherV6=patternV6.matcher(srcIp.getDestIpAddress()); - * if(matcherV4.matches()) { dstIp.setDstIp(srcIp.getDestIpAddress()); - * dstIp.setDstIpMask("255.255.255.255"); }else if(matcherV6.matches()) { - * dstIp.setDstIp(srcIp.getDestIpAddress()); - * dstIp.setDstIpMask("FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF"); }else { throw - * new RuntimeException("invalid ip format"); } } - */ - else { - throw new RuntimeException("Unsupported IP type " + srcIp.getIpType()); - } - } - } else { - if (srcIp.getIpType() == 4/* || srcIp.getIpType()==64 */) {// 64表示源ip为ipv6,目的ip为ipv4 - dstIp.setDstIp(srcIp.getDestIpAddress()); - dstIp.setDstIpMask("255.255.255.255"); - } else if (srcIp.getIpType() == 6/* || srcIp.getIpType()==46 */) {// 46表示源ip为ipv4,目的ip为ipv6 + }else if(srcIp.getDestIpPattern().equals(1)) {// IP/掩码 + IPv6Network strangeNetwork = IPv6Network.fromString(srcIp.getDestIpAddress()); + dstIp.setDstIp(srcIp.getDestIpAddress().split("/")[0]); + dstIp.setDstIpMask(strangeNetwork.getNetmask().asAddress().toString()); + }else {// IP dstIp.setDstIp(srcIp.getDestIpAddress()); dstIp.setDstIpMask("FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF"); - } /* - * else {//all dstIp.setDstIp(srcIp.getDestIpAddress()); - * dstIp.setDstIpMask("255.255.255.255"); } - */ - else { - throw new RuntimeException("Unsupported IP type " + srcIp.getIpType()); - } - } - if (srcIp.getSrcPort() != null) { - if (srcIp.getSrcPort().indexOf("/") != -1) { - String srcMaskNum = srcIp.getSrcPort().split("/")[1]; - dstIp.setSrcPortMask(srcMaskNum); - dstIp.setSrcPort(srcIp.getSrcPort().split("/")[0]); - } else { - dstIp.setSrcPort(srcIp.getSrcPort()); - dstIp.setSrcPortMask("65535"); } } else { - dstIp.setSrcPort("0"); - dstIp.setSrcPortMask("65535"); - } - if (srcIp.getDestPort() != null) { - if (srcIp.getDestPort().indexOf("/") != -1) { - String dstMaskNum = srcIp.getDestPort().split("/")[1]; - dstIp.setDstPortMask(dstMaskNum); - dstIp.setDstPort(srcIp.getDestPort().split("/")[0]); - } else { - dstIp.setDstPort(srcIp.getDestPort()); - dstIp.setDstPortMask("65535"); - } - } else { - dstIp.setDstPort("0"); - dstIp.setDstPortMask("65535"); + dstIp.setDstIp("::"); + dstIp.setDstIpMask("FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF"); } + convertPortValues(dstIp, srcIp); ipConvertList.add(dstIp); + }else { + throw new RuntimeException("Unsupported IP type " + srcIp.getIpType()); } return ipConvertList; } @@ -2596,7 +2495,15 @@ public abstract class BaseService { if(_cfg.getAction().equals(Constants.MONIT_ACTION)) { maatCfg.setUserRegion(Constants.INTERCEPT_IP_MONIT_USER_REGION_KEY+"="+Constants.USER_REGION_PLACEHOLDER); }*/ - maatCfg.setUserRegion(Constants.INTERCEPT_IP_RATELIMIT_DROPRATE_USER_REGION_KEY+"="+_cfg.getUserRegion2()); + if(serviceDict!=null&&serviceDict.getAction().equals(Constants.MONIT_ACTION)) {// 监测 需要发keyring_id、拦截强度 + _cfg.setUserRegion1(StringUtil.isEmpty(_cfg.getUserRegion1()) ? "0":_cfg.getUserRegion1()); + _cfg.setUserRegion5(StringUtil.isEmpty(_cfg.getUserRegion5()) ? "1":_cfg.getUserRegion5()); + maatCfg.setUserRegion(Constants.INTERCEPT_IP_MONIT_USER_REGION_KEY+"=0"+";"+Constants.INTERCEPT_DOMAN_INTENSITY_USER_REGION_KEY+"="+_cfg.getUserRegion5()); + } + if(serviceDict!=null&&serviceDict.getAction().equals(64)) { + maatCfg.setUserRegion(Constants.INTERCEPT_IP_RATELIMIT_DROPRATE_USER_REGION_KEY+"="+_cfg.getUserRegion2()); + } + }else if(regionDict.getFunctionId()==207 || regionDict.getFunctionId()==208 || regionDict.getFunctionId()==209) {// HTTP(s)阻断、重定向、替换 String userRegion = Constants.USER_REGION_PLACEHOLDER; if(_cfg.getAction().equals(Constants.REJECT_ACTION)) {// 阻断 @@ -3033,6 +2940,140 @@ public abstract class BaseService { } } } + /** + * 新增:修改旧的定时任务为无效(实际不需要)--》新增sche(1)用于生成新的定时任务trigger(清理旧定时任务的trigger) + * 修改:修改旧的定时任务为无效--》新增sche(1)用于生成新的定时任务trigger(清理旧定时任务的trigger) + * 审核通过:不需要操作 + * 审核不通过:修改旧的定时任务为无效--》新增sche(0)用于清理旧定时任务的trigger + * 配置取消:修改旧的定时任务为无效--》新增sche(0)用于清理旧定时任务的trigger + * 删除:修改旧的定时任务为无效--》新增sche(0)用于清理旧定时任务的trigger + * @param parameterObject + * @param tableName + * @throws SQLException + */ + public void handelScheduleCfg(Object parameterObject,String tableName){ + logger.info("handelScheduleCfg==》开始处理定时任务"); + List cfgList = Lists.newArrayList(); + //确保 单个,批量都适用 + if(parameterObject instanceof BaseCfg) {//单个添加 + BaseCfg baseCfg = (BaseCfg)parameterObject; + cfgList.add(baseCfg); + }else if(parameterObject instanceof Collection) { + Collection> bcCollection = (Collection>)parameterObject; + cfgList.addAll(bcCollection); + }else if(parameterObject.getClass().isArray()) { + int length = Array.getLength(parameterObject); + for(int i = 0;i< length;i++) { + BaseCfg baseCfg = (BaseCfg)Array.get(parameterObject, i); + cfgList.add(baseCfg); + } + } + + //存放需要删除的定时任务(根据compileId删除之前所有的定时任务) + String compileIds=""; + //存放需要删除的定时任务trigger的sche + List delScheduleList = Lists.newArrayList(); + //存放需要新增的定时任务 + List addScheduleList = Lists.newArrayList(); + + for(BaseCfg baseCfg : cfgList) { + //定时任务删除需要新增一条无效的sche用来清理旧的trigger + if(baseCfg.getIsValid()==-1 || baseCfg.getIsAudit()==2 || baseCfg.getIsAudit()==3) { + ScheduleCfg scheduleCfgdel =new ScheduleCfg(); + scheduleCfgdel.setDelFlag(0); + scheduleCfgdel.setType(1); + scheduleCfgdel.setTableName(tableName); + scheduleCfgdel.setName("DELETE TRIGGER SCHE"); + scheduleCfgdel.setCompileId(baseCfg.getCompileId()); + scheduleCfgdel.setFunctionId(baseCfg.getFunctionId()); + scheduleCfgdel.setIsValid(baseCfg.getIsValid()); + scheduleCfgdel.setIsAudit(baseCfg.getIsAudit()); + scheduleCfgdel.setCfgId(baseCfg.getCfgId()); + scheduleCfgdel.setCreateTime(new Date()); + scheduleCfgdel.setCreatorId(UserUtils.getUser().getId()); + scheduleCfgdel.setServiceId(baseCfg.getServiceId()); + delScheduleList.add(scheduleCfgdel); + }else { + //有新的定时任务时,不需要在新增无效sche来清理旧的trigger,扫描到新增的sche时,也会有清理操作 + ScheduleCfg scheduleCfgAdd = copyScheduleCfgFromBaseCfg(baseCfg, tableName); + if(scheduleCfgAdd!=null){ + scheduleCfgAdd.setIsValid(0); + scheduleCfgAdd.setIsAudit(0); + scheduleCfgAdd.setDelFlag(1); + addScheduleList.add(scheduleCfgAdd); + } + } + compileIds+=baseCfg.getCompileId()+","; + + } + + //将之前的定时任务置为无效 + if(!StringUtil.isEmpty(compileIds)) { + compileIds=compileIds.substring(0,compileIds.length()-1); + SqlSessionFactory sqlSessionFactory=SpringContextHolder.getBean(SqlSessionFactory.class); + SqlSession batchSqlSession = null; + try { + batchSqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, false); + ((SchedulerDao) batchSqlSession.getMapper(SchedulerDao.class)).deleteByCompileIds(compileIds.toString()); + batchSqlSession.commit(); + } finally { + if(batchSqlSession != null) { + batchSqlSession.close(); + } + } + } + //新增sche,用于删除旧的定时任务 + if(!StringUtil.isEmpty(delScheduleList)) { + compileIds=compileIds.substring(0,compileIds.length()-1); + SqlSessionFactory sqlSessionFactory=SpringContextHolder.getBean(SqlSessionFactory.class); + SqlSession batchSqlSession = null; + try { + batchSqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, false); + for(ScheduleCfg entity : delScheduleList) { + ((SchedulerDao) batchSqlSession.getMapper(SchedulerDao.class)).insert(entity); + } + batchSqlSession.commit(); + } finally { + if(batchSqlSession != null) { + batchSqlSession.close(); + } + } + } + + //新增sche,用于新增新定时任务 + if(!StringUtil.isEmpty(addScheduleList)) { + compileIds=compileIds.substring(0,compileIds.length()-1); + SqlSessionFactory sqlSessionFactory=SpringContextHolder.getBean(SqlSessionFactory.class); + SqlSession batchSqlSession = null; + try { + batchSqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, false); + for(ScheduleCfg entity : addScheduleList) { + ((SchedulerDao) batchSqlSession.getMapper(SchedulerDao.class)).insert(entity); + } + batchSqlSession.commit(); + } finally { + if(batchSqlSession != null) { + batchSqlSession.close(); + } + } + } + logger.info("handelScheduleCfg==》定时任务处理完成"); + } + /** + * 从 basecfg 实体类中获取 schedule cfg + * @param baseCfg + * @param tableName + * @return + */ + private ScheduleCfg copyScheduleCfgFromBaseCfg(BaseCfg baseCfg,String tableName){ + ScheduleCfg schedule = baseCfg.getSchedule(); + if(schedule != null ) { + BeanUtils.copyProperties(baseCfg, schedule,new String[]{"userRegion1","userRegion2","userRegion3","userRegion4","userRegion5"}); + schedule.setTableName(tableName); + schedule.setType(1); + } + return schedule; + } } diff --git a/src/main/java/com/nis/web/service/configuration/IpCfgService.java b/src/main/java/com/nis/web/service/configuration/IpCfgService.java index 6a9d1d74f..1a3797e0c 100644 --- a/src/main/java/com/nis/web/service/configuration/IpCfgService.java +++ b/src/main/java/com/nis/web/service/configuration/IpCfgService.java @@ -99,7 +99,7 @@ public class IpCfgService extends CrudService { c.initDefaultValue(); BeanUtils.copyProperties(cfg, c,new String[]{"cfgId","ipType","direction", "protocol","protocolId","areaEffectiveIds","cfgRegionCode", - "cfgType","ipPattern","srcIpAddress","portPattern","srcPort","destIpAddress","destPort"}); + "cfgType","srcIpPattern","destIpPattern","srcIpAddress","srcPortPattern","destPortPattern","srcPort","destIpAddress","destPort"}); c.setTableName(AreaIpCfg.getTablename()); } this.saveIpBatch(cfg.getAreaCfg()); @@ -194,6 +194,8 @@ public class IpCfgService extends CrudService { } //TODO 处理定时任务【如果有定时任务则新增】 + handelScheduleCfg(entity, entity.getIndexTable()); + if(isValid==1) { entity.setIsAudit(1); entity.setIsValid(1); @@ -273,6 +275,8 @@ public class IpCfgService extends CrudService { } //TODO 处理定时任务【如果有定时任务则删除旧的,新增新的】 + handelScheduleCfg(entity, entity.getIndexTable()); + if(isValid==1) { entity.setIsAudit(1); entity.setIsValid(1); @@ -320,9 +324,9 @@ public class IpCfgService extends CrudService { cfg.setTableName(AreaIpCfg.getTablename()); ipCfgDao.updateCfgValid(cfg); } - + //TODO 处理定时任务【如果有定时任务则删除旧的,新增新的】 + handelScheduleCfg(entity, entity.getIndexTable()); } - //TODO 处理定时任务【如果有定时任务则删除】 } /** @@ -349,7 +353,7 @@ public class IpCfgService extends CrudService { c.initDefaultValue(); BeanUtils.copyProperties(cfg, c,new String[]{"cfgId","ipType","direction", "protocol","protocolId","areaEffectiveIds","cfgRegionCode", - "cfgType","ipPattern","srcIpAddress","portPattern","srcPort","destIpAddress","destPort"}); + "cfgType","srcIpPattern","destIpPattern","srcIpAddress","srcPortPattern","destPortPattern","srcPort","destIpAddress","destPort"}); c.setTableName(AreaIpCfg.getTablename()); c.setCreatorId(cfg.getCurrentUser().getId()); c.setCreateTime(date); @@ -371,9 +375,11 @@ public class IpCfgService extends CrudService { ,"cfgType" ,"cfgId" ,"ipType" - ,"ipPattern" + ,"srcIpPattern" + ,"destIpPattern" ,"srcIpAddress" - ,"portPattern" + ,"srcPortPattern" + ,"destPortPattern" ,"srcPort" ,"destPort" ,"protocol" @@ -638,7 +644,12 @@ public class IpCfgService extends CrudService { areaIpRegionList=map.get("dstList"); } } - //TODO 处理定时任务【审核通过-》增加一条sche_new;审核不通过-》增加一条sche0,2,sche旧的置为无效;配置取消-》增加一条0,3,sche旧的置为无效】。 + + if(isAudit!=1) { + //处理定时任务【如果有定时任务则删除旧的,新增新的】 + handelScheduleCfg(entity, entity.getIndexTable()); + } + //构造提交综合服务参数格式,一条配置提交一次综合服务 if(isAudit==1){ if(maatType==Constants.CALLBACK_TYPE){ @@ -704,7 +715,7 @@ public class IpCfgService extends CrudService { }else { throw new RuntimeException(":"+props.getProperty("unknown_cfg_type")); } - }else if(isAudit==3){ + }else if(isAudit==3 && entity.getIsValid()==1){ if(maatType==Constants.CALLBACK_TYPE){ List ipList=new ArrayList<>(); for(IpPortCfg cfg :entity.getIpPortList()) { diff --git a/src/main/resources/messages/message_zh_CN.properties b/src/main/resources/messages/message_zh_CN.properties index 8f5e3fb59..331c2081c 100644 --- a/src/main/resources/messages/message_zh_CN.properties +++ b/src/main/resources/messages/message_zh_CN.properties @@ -1255,8 +1255,9 @@ user_behavior_data=\u7528\u6237\u7edf\u8ba1 ip_behavior_data=\u7528\u6237IP\u7edf\u8ba1 not_valid_domain=%s\u4e0d\u662f\u4e00\u4e2a\u5408\u6cd5\u57df\u540d cert_not_match_domain=\u57df\u540d\u4e0e\u6240\u9009\u8bc1\u4e66\u4fe1\u606f\u4e0d\u7b26\u5408\uff01 -crl_file_error=CRL\u6587\u4ef6\u683c\u5f0f\u9519\u8bef +certificate_file_error=\u8BC1\u4E66\u683C\u5F0F\u9519\u8BEF PXY_OBJ_TRUSTED_CA_CERT=\u53ef\u4fe1\u8bc1\u4e66 +crl_file_error=CRL\u6587\u4EF6\u683C\u5F0F\u9519\u8BEF crl_issuer_error=crl\u6587\u4ef6\u7684issuer\u4e0e\u8bc1\u4e66\u6587\u4ef6\u7684issuer\u4e0d\u5339\u914d cert_name=\u8bc1\u4e66\u540d\u79f0 add_crl_file=Add CRL File @@ -1507,4 +1508,10 @@ interface_total=\u754c\u9762\u603b\u91cf service_total=\u670d\u52a1\u603b\u91cf unapproved_all=\u5ba1\u6838\u4E0D\u901a\u8fc7\u6240\u6709\u914d\u7f6e! delete_all=\u5220\u9664\u6240\u6709\u914d\u7f6e! -none_file_tip=\u8BF7\u9009\u62E9\u6587\u4EF6! \ No newline at end of file +none_file_tip=\u8BF7\u9009\u62E9\u6587\u4EF6! +the_same_ip_type=\u6e90IP\u4e0e\u76ee\u7684IP\u7684IP\u7c7b\u578b\u5fc5\u987b\u76f8\u540c +src_ip_pattern=\u6E90IP\u683C\u5F0F +dest_ip_pattern=\u76EE\u7684IP\u683C\u5F0F +src_port_pattern=\u6E90\u7AEF\u53E3\u683C\u5F0F +dest_port_pattern=\u76EE\u7684\u7AEF\u53E3\u683C\u5F0F +range_cross=\u6E90IP\u4E0E\u76EE\u7684IP\u8303\u56F4\u6709\u4EA4\u53C9 \ No newline at end of file