From c81dd92acabba4614a0f348bbfbbfc8e681eeac3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E7=9A=93=E5=AE=B8?= Date: Tue, 14 May 2019 16:57:13 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20=E5=AF=BC=E5=85=A5?= =?UTF-8?q?=E6=97=B6=E5=8F=AA=E6=9C=89=E6=BA=90IP=E6=88=96=E7=9B=AE?= =?UTF-8?q?=E7=9A=84IP=E7=9A=84=E9=85=8D=E7=BD=AE=20=E4=B8=8D=E8=83=BD?= =?UTF-8?q?=E4=B8=BA0.0.0.0=20=E5=90=8C=E6=97=B6=E6=9C=89=E6=BA=90IP?= =?UTF-8?q?=E5=92=8C=E7=9B=AE=E7=9A=84IP=E4=B8=A4=E4=B8=AAIP=E4=B8=8D?= =?UTF-8?q?=E8=83=BD=E4=B8=80=E6=A0=B7=EF=BC=8C=E4=BB=85=E6=9C=89=E4=B8=80?= =?UTF-8?q?=E4=B8=AA=E5=8F=AF=E4=B8=BA0.0.0.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../excel/thread/CheckIpFormatThread.java | 66 ++++++++++++------- 1 file changed, 44 insertions(+), 22 deletions(-) diff --git a/src/main/java/com/nis/util/excel/thread/CheckIpFormatThread.java b/src/main/java/com/nis/util/excel/thread/CheckIpFormatThread.java index 3020d1882..30d7765fa 100644 --- a/src/main/java/com/nis/util/excel/thread/CheckIpFormatThread.java +++ b/src/main/java/com/nis/util/excel/thread/CheckIpFormatThread.java @@ -138,8 +138,6 @@ public class CheckIpFormatThread implements Callable{ // doLog属性检验 this.validDoLog(baseIpCfg,errInfo); - //IP校验 - this.validSrcAndDescIp(baseIpCfg.getSrcIpAddress(), baseIpCfg.getDestIpAddress(), configIpPortShow,errInfo); // 特殊字段验证 // packet ip ratelimit @@ -597,6 +595,20 @@ public class CheckIpFormatThread implements Callable{ String subfix=baseIpCfg.getSrcIpAddress().split("-")[1]; baseIpCfg.setSrcIpAddress(prefix+"-"+prefix.substring(0, prefix.lastIndexOf(".")+1)+subfix); } + //Tip:判断业务是否只展示源IP列,如果是,判断源IP是否是默认值,如果是默认值,提示源IP不能是默认值 + if (configIpPortShow.indexOf("1") > -1 && configIpPortShow.indexOf("3") == -1) {// 源IP必填 + String srcIpAddress = baseIpCfg.getSrcIpAddress(); + Pattern ip4 = Constants.IPV4_IP_PATTERN; + Pattern ip6 = Constants.IPV6_IP_PATTERN; + Matcher ip4Matcher = ip4.matcher(srcIpAddress); + Matcher ip6Matcher = ip6.matcher(srcIpAddress); + if ((ip4Matcher.matches() && srcIpAddress.startsWith("0.0.0.0")) + || (ip6Matcher.matches() && srcIpAddress.startsWith("::"))) { + errInfo.append(prop.getProperty("client_ip") + + String.format(prop.getProperty("can_not_be"), prop.getProperty("default_value")) + + ";"); + } + } } if (StringUtils.isBlank(baseIpCfg.getDestIpAddress())) { destIpEmpty = true; @@ -608,6 +620,20 @@ public class CheckIpFormatThread implements Callable{ String subfix=baseIpCfg.getDestIpAddress().split("-")[1]; baseIpCfg.setDestIpAddress(prefix+"-"+prefix.substring(0, prefix.lastIndexOf(".")+1)+subfix); } + //Tip:判断业务是否只展示目的IP列,如果是,判断目的IP是否是默认值,如果是默认值,提示目的IP不能是默认值 + if (configIpPortShow.indexOf("3") > -1 && configIpPortShow.indexOf("1") == -1) {// 目的IP必填 + String destIpAddress = baseIpCfg.getDestIpAddress(); + Pattern ip4 = Constants.IPV4_IP_PATTERN; + Pattern ip6 = Constants.IPV6_IP_PATTERN; + Matcher ip4Matcher = ip4.matcher(destIpAddress); + Matcher ip6Matcher = ip6.matcher(destIpAddress); + if ((ip4Matcher.matches() && destIpAddress.startsWith("0.0.0.0")) + || (ip6Matcher.matches() && destIpAddress.startsWith("::"))) { + errInfo.append(prop.getProperty("server_ip") + + String.format(prop.getProperty("can_not_be"), prop.getProperty("default_value")) + + ";"); + } + } } if (StringUtils.isBlank(baseIpCfg.getSrcPort())) { srcPortEmpty = true; @@ -669,6 +695,12 @@ public class CheckIpFormatThread implements Callable{ } baseIpCfg.setIpType(4); } + //Tip:增加源IP和目的IP是否相等,如果相等,提示目的IP不能为空 + if ((configIpPortShow.indexOf("3") > -1 && configIpPortShow.indexOf("1") > -1) + && (baseIpCfg.getDestIpAddress().equals(baseIpCfg.getSrcIpAddress()))) { + errInfo.append(String.format(prop.getProperty("can_not_null"), + prop.getProperty("server_ip", "Server IP")) + ";"); + } } } else if (srcIpEmpty) {// 源IP为空 @@ -710,6 +742,12 @@ public class CheckIpFormatThread implements Callable{ } baseIpCfg.setIpType(4); } + //Tip:增加源IP和目的IP是否相等,如果相等,提示源的IP不能为空 + if ((configIpPortShow.indexOf("3") > -1 && configIpPortShow.indexOf("1") > -1) + && (baseIpCfg.getSrcIpAddress().equals(baseIpCfg.getDestIpAddress()))) { + errInfo.append(String.format(prop.getProperty("can_not_null"), + prop.getProperty("client_ip", "Client IP")) + ";"); + } } } else {// 全不为空 String srcMatchType = this.validIPAddress("client_ip", errInfo, baseIpCfg.getSrcIpAddress(), ipType, @@ -904,6 +942,10 @@ public class CheckIpFormatThread implements Callable{ // TODO 判断Direction的值 this.validDirection(errInfo, baseIpCfg.getDirection(), direction); } + + //IP校验 +// this.validSrcAndDescIp(baseIpCfg.getSrcIpAddress(), baseIpCfg.getDestIpAddress(), configIpPortShow,errInfo); + if (errInfo.toString().length() > 0) {// errTip.append(String.format(prop.getProperty("line"), baseIpCfg.getIndex()) + ","); errTip.append(errInfo); @@ -1331,24 +1373,4 @@ public class CheckIpFormatThread implements Callable{ public void setAsnGroupInfos(Map asnGroupInfos) { this.asnGroupInfos = asnGroupInfos; } - - public void validSrcAndDescIp(String srcIp, String descIp, String configIpPortShow, StringBuffer errInfo) { - if (configIpPortShow.contains("1") && configIpPortShow.contains("3")) { - if (srcIp.equals(descIp)) { - errInfo.append( - String.format(prop.getProperty("are_the_same"), prop.getProperty("server_ip"), prop.getProperty("client_ip")) - + ";"); - } - } else if (configIpPortShow.contains("1")) { - if ("0.0.0.0".equals(srcIp)) { - errInfo.append( - String.format(prop.getProperty("is_in_wrong_format"), prop.getProperty("server_ip")) + ";"); - } - } else if (configIpPortShow.contains("3")) { - if ("0.0.0.0".equals(descIp)) { - errInfo.append( - String.format(prop.getProperty("is_in_wrong_format"), prop.getProperty("client_ip")) + ";"); - } - } - } }