IP导入4OVER6,6OVER4,ALL格式校验

This commit is contained in:
wangxin
2018-08-13 11:46:58 +08:00
parent d6352b3939
commit 522bd14dbb

View File

@@ -784,7 +784,7 @@ public class BaseController {
}else if("6over4".equals(ipTypeString)) {
value.setDestIpAddress(Constants.IPV4_DEFAULT_IP_SUBNET_VALUE);
}else if("all".equals(ipTypeString)) {
value.setDestIpAddress(Constants.IPV4_DEFAULT_IP_SUBNET_VALUE);
}
}else if("ip_range".equals(ipPatternString)) {
if("ipv4".equals(ipTypeString)) {
@@ -796,7 +796,7 @@ public class BaseController {
}else if("6over4".equals(ipTypeString)) {
value.setDestIpAddress(Constants.IPV4_DEFAULT_IP_RANGE_VALUE);
}else if("all".equals(ipTypeString)) {
value.setDestIpAddress(Constants.IPV4_DEFAULT_IP_RANGE_VALUE);
}
}else if("ip".equals(ipPatternString)) {
if("ipv4".equals(ipTypeString)) {
@@ -808,7 +808,7 @@ public class BaseController {
}else if("6over4".equals(ipTypeString)) {
value.setDestIpAddress(Constants.IPV4_DEFAULT_IP_VALUE);
}else if("all".equals(ipTypeString)) {
value.setDestIpAddress(Constants.IPV4_DEFAULT_IP_VALUE);
}
}
}
@@ -822,6 +822,12 @@ public class BaseController {
errInfo.append(_msg);
}
}
if(!"ipmulitiplex".equals(specialItem)&&("4over6".equals(ipTypeString)||"6over4".equals(ipTypeString)||"all".equals(ipTypeString))) {
_msg=checkIp(prop, prop.getProperty("client_ip"), srcIp, prop.getProperty("server_ip"), destIp, ipTypeString, ipPatternString);
if(StringUtils.isNotBlank(_msg)){
errInfo.append(_msg);
}
}
//server_ip check end
//port_pattern check start
Integer portPattern=value.getPortPattern();
@@ -1136,6 +1142,122 @@ public class BaseController {
}
return msg.toString();
}
public static String checkIp(Properties prop,String srcIpName,String srcIp,String destIpName,String destIp,String ipType,String ipPattern) {
StringBuffer msg=new StringBuffer();
if("4over6".equals(ipType)){
if("ip_subnet".equals(ipPattern)){
Pattern patternV4=Pattern.compile(Constants.IPV4_IP_SUBNET_REGEXP);
Pattern patternV6=Pattern.compile(Constants.IPV6_IP_SUBNET_REGEXP);
Matcher matcherV4=patternV4.matcher(srcIp);
Matcher matcherV6=patternV6.matcher(destIp);
if(!matcherV4.matches()){//完全匹配
msg.append(String.format(prop.getProperty("is_in_wrong_format"), srcIpName)+";");
}
if(!matcherV6.matches()){//完全匹配
msg.append(String.format(prop.getProperty("is_in_wrong_format"), destIpName)+";");
}
}else if("ip_range".equals(ipPattern)){
Pattern patternV4=Pattern.compile(Constants.IPV4_IP_RANGE_REGEXP);
Pattern patternV6=Pattern.compile(Constants.IPV6_IP_RANGE_REGEXP);
Matcher matcherV4=patternV4.matcher(srcIp);
Matcher matcherV6=patternV6.matcher(destIp);
if(!matcherV4.matches()){//完全匹配
msg.append(String.format(prop.getProperty("is_in_wrong_format"), srcIpName)+";");
}
if(!matcherV6.matches()){//完全匹配
msg.append(String.format(prop.getProperty("is_in_wrong_format"), destIpName)+";");
}
}else if("ip".equals(ipPattern)){
Pattern patternV4=Pattern.compile(Constants.IPV4_IP_REGEXP);
Pattern patternV6=Pattern.compile(Constants.IPV6_IP_REGEXP);
Matcher matcherV4=patternV4.matcher(srcIp);
Matcher matcherV6=patternV6.matcher(destIp);
if(!matcherV4.matches()){//完全匹配
msg.append(String.format(prop.getProperty("is_in_wrong_format"), srcIpName)+";");
}
if(!matcherV6.matches()){//完全匹配
msg.append(String.format(prop.getProperty("is_in_wrong_format"), destIpName)+";");
}
}
}else if("6over4".equals(ipType)) {
if("ip_subnet".equals(ipPattern)){
Pattern patternV4=Pattern.compile(Constants.IPV4_IP_SUBNET_REGEXP);
Pattern patternV6=Pattern.compile(Constants.IPV6_IP_SUBNET_REGEXP);
Matcher matcherV4=patternV4.matcher(destIp);
Matcher matcherV6=patternV6.matcher(srcIp);
if(!matcherV4.matches()){//完全匹配
msg.append(String.format(prop.getProperty("is_in_wrong_format"), destIpName)+";");
}
if(!matcherV6.matches()){//完全匹配
msg.append(String.format(prop.getProperty("is_in_wrong_format"), srcIpName)+";");
}
}else if("ip_range".equals(ipPattern)){
Pattern patternV4=Pattern.compile(Constants.IPV4_IP_RANGE_REGEXP);
Pattern patternV6=Pattern.compile(Constants.IPV6_IP_RANGE_REGEXP);
Matcher matcherV4=patternV4.matcher(destIp);
Matcher matcherV6=patternV6.matcher(srcIp);
if(!matcherV4.matches()){//完全匹配
msg.append(String.format(prop.getProperty("is_in_wrong_format"),destIpName)+";");
}
if(!matcherV6.matches()){//完全匹配
msg.append(String.format(prop.getProperty("is_in_wrong_format"), srcIpName )+";");
}
}else if("ip".equals(ipPattern)){
Pattern patternV4=Pattern.compile(Constants.IPV4_IP_REGEXP);
Pattern patternV6=Pattern.compile(Constants.IPV6_IP_REGEXP);
Matcher matcherV4=patternV4.matcher(destIp);
Matcher matcherV6=patternV6.matcher(srcIp);
if(!matcherV4.matches()){//完全匹配
msg.append(String.format(prop.getProperty("is_in_wrong_format"), destIpName)+";");
}
if(!matcherV6.matches()){//完全匹配
msg.append(String.format(prop.getProperty("is_in_wrong_format"), srcIpName)+";");
}
}
}else if("all".equals(ipType)) {
if("ip_subnet".equals(ipPattern)){
Pattern patternV4=Pattern.compile(Constants.IPV4_IP_SUBNET_REGEXP);
Pattern patternV6=Pattern.compile(Constants.IPV6_IP_SUBNET_REGEXP);
Matcher matcherSrcIpV4=patternV4.matcher(srcIp);
Matcher matcherSrcIpV6=patternV6.matcher(srcIp);
Matcher matcherDestIpV4=patternV4.matcher(destIp);
Matcher matcherDestIpV6=patternV6.matcher(destIp);
if(!matcherSrcIpV4.matches()&&!matcherSrcIpV6.matches()){//完全匹配
msg.append(String.format(prop.getProperty("is_in_wrong_format"), srcIpName)+";");
}
if(!matcherDestIpV4.matches()&&!matcherDestIpV6.matches()){//完全匹配
msg.append(String.format(prop.getProperty("is_in_wrong_format"), destIpName)+";");
}
}else if("ip_range".equals(ipPattern)){
Pattern patternV4=Pattern.compile(Constants.IPV4_IP_RANGE_REGEXP);
Pattern patternV6=Pattern.compile(Constants.IPV6_IP_RANGE_REGEXP);
Matcher matcherSrcIpV4=patternV4.matcher(srcIp);
Matcher matcherSrcIpV6=patternV6.matcher(srcIp);
Matcher matcherDestIpV4=patternV4.matcher(destIp);
Matcher matcherDestIpV6=patternV6.matcher(destIp);
if(!matcherSrcIpV4.matches()&&!matcherSrcIpV6.matches()){//完全匹配
msg.append(String.format(prop.getProperty("is_in_wrong_format"), srcIpName)+";");
}
if(!matcherDestIpV4.matches()&&!matcherDestIpV6.matches()){//完全匹配
msg.append(String.format(prop.getProperty("is_in_wrong_format"), destIpName)+";");
}
}else if("ip".equals(ipPattern)){
Pattern patternV4=Pattern.compile(Constants.IPV4_IP_REGEXP);
Pattern patternV6=Pattern.compile(Constants.IPV6_IP_REGEXP);
Matcher matcherSrcIpV4=patternV4.matcher(srcIp);
Matcher matcherSrcIpV6=patternV6.matcher(srcIp);
Matcher matcherDestIpV4=patternV4.matcher(destIp);
Matcher matcherDestIpV6=patternV6.matcher(destIp);
if(!matcherSrcIpV4.matches()&&!matcherSrcIpV6.matches()){//完全匹配
msg.append(String.format(prop.getProperty("is_in_wrong_format"), srcIpName)+";");
}
if(!matcherDestIpV4.matches()&&!matcherDestIpV6.matches()){//完全匹配
msg.append(String.format(prop.getProperty("is_in_wrong_format"), destIpName)+";");
}
}
}
return msg.toString();
}
public static String checkPort(Properties prop,String portName,String port,String portPattern){
StringBuffer msg=new StringBuffer();
if(StringUtils.isBlank(port)){