修改拦截策略配置导入模板;修正http(s) 重定向配置导入校验

This commit is contained in:
zhangwenqing
2019-01-08 10:08:33 +08:00
parent 0bbb751020
commit 2c0ab8687b
8 changed files with 133 additions and 46 deletions

View File

@@ -193,7 +193,7 @@ public class ExportExcel {
commentStr=commentStr+msgProp.getProperty(sysDataDictionaryItem.getItemValue(),sysDataDictionaryItem.getItemValue())+"\n";
index++;
}
defaultValue=ratelimit.get(0).getItemCode();
defaultValue="0.1";
}
commentStr=msgProp.getProperty("select")+":\n"+commentStr;
index++;
@@ -215,18 +215,18 @@ public class ExportExcel {
commentStr=commentStr+sysDataDictionaryItem.getItemCode()+""+msgProp.getProperty(sysDataDictionaryItem.getItemValue(),sysDataDictionaryItem.getItemValue())+"\n";
index++;
}
//defaultValue=dict.get(0).getItemCode();
defaultValue = "1";
}
commentStr=msgProp.getProperty("select")+":\n"+commentStr;
index++;
/*commentStr=commentStr+"\n"+msgProp.getProperty("rule_desc_tip")+":\n";
commentStr=commentStr+"\n"+msgProp.getProperty("rule_desc_tip")+":\n";
index++;
if(!StringUtil.isEmpty(defaultValue)){
//1、默认值说明
commentStr=commentStr+""+msgProp.getProperty("default_value")+":"+defaultValue+"\n";
index++;
index++;
}*/
}
}
/*** HTTP(s)重定向 重定向应答码 ***/
if("redirect_response_code".equals(headerStr)){
@@ -237,7 +237,7 @@ public class ExportExcel {
commentStr=commentStr+sysDataDictionaryItem.getItemCode()+""+msgProp.getProperty(sysDataDictionaryItem.getItemValue(),sysDataDictionaryItem.getItemValue())+"\n";
index++;
}
defaultValue = "1";
defaultValue = dict.get(0).getItemCode();
}
commentStr=msgProp.getProperty("select")+":\n"+commentStr;
index++;
@@ -908,8 +908,13 @@ public class ExportExcel {
commentStr="";
List<SysDataDictionaryItem> protocol=DictUtils.getDictList("PROTOCOL");
if(protocol !=null && protocol.size()>0){
// 拦截策略(限速)
if(region.getFunctionId().equals(200) && service.getAction().equals(64)) {
commentStr=commentStr+"0"+msgProp.getProperty("arbitrary")+""+"\n";
index++;
}
for (SysDataDictionaryItem sysDataDictionaryItem : protocol) {
// IP拦截 监测
// 拦截策略(监测
if((sysDataDictionaryItem.getItemCode().equals("17")) && (region.getFunctionId().equals(200) && service.getAction().equals(1))){
continue;
}
@@ -936,7 +941,10 @@ public class ExportExcel {
defaultValue=region.getConfigProtocol().split(",")[0];
}
// 拦截策略(限速)
if(region.getFunctionId().equals(200) && service.getAction().equals(64)) {
defaultValue="0";
}
}
/*}*/
}
@@ -1263,7 +1271,11 @@ public class ExportExcel {
commentStr=commentStr+msgProp.getProperty("rule_desc_tip")+":\n";
index++;
//2、默认值说明
commentStr=commentStr+""+msgProp.getProperty("default_value")+":0\n";
if(region.getFunctionId().equals(200)) {
commentStr=commentStr+""+msgProp.getProperty("default_value")+":1\n";
}else {
commentStr=commentStr+""+msgProp.getProperty("default_value")+":0\n";
}
index++;
}
}

View File

@@ -130,6 +130,9 @@ public class CheckComplexStringFormatThread implements Callable<String>{
}
// 代理 HTTP(s)重定向
if (regionDict.getFunctionId().equals(208)) {
if(StringUtils.isBlank(baseStringCfg.getUserRegion1())) {
baseStringCfg.setUserRegion1("301");
}
String userRegion1 = baseStringCfg.getUserRegion1();// 重定向应答码
String userRegion2 = baseStringCfg.getUserRegion2();// 重定向URL
if (StringUtils.isNotBlank(userRegion1)) {
@@ -146,6 +149,11 @@ public class CheckComplexStringFormatThread implements Callable<String>{
prop.getProperty("redirect_response_code") + " ") + ";");
}
}
if(StringUtils.isBlank(userRegion2)) {
errInfo.append(
String.format(prop.getProperty("can_not_null"), prop.getProperty("redirect_url"))
+ ";");
}
if(StringUtils.isNotBlank(userRegion2)){
Pattern pat = Pattern.compile("^[hH][tT][tT][pP]([sS]?):\\/\\/(\\S+\\.)+\\S{2,}$");
boolean bl = pat.matcher(userRegion2).matches();

View File

@@ -404,6 +404,9 @@ public class CheckIpFormatThread implements Callable<String>{
}
// 代理 HTTP(s)重定向
if (regionDict.getFunctionId().equals(208)) {
if(StringUtils.isBlank(baseIpCfg.getUserRegion1())) {
baseIpCfg.setUserRegion1("301");
}
String userRegion1 = baseIpCfg.getUserRegion1();// 重定向应答码
String userRegion2 = baseIpCfg.getUserRegion2();// 重定向URL
if (StringUtils.isNotBlank(userRegion1)) {
@@ -420,6 +423,11 @@ public class CheckIpFormatThread implements Callable<String>{
prop.getProperty("redirect_response_code") + " ") + ";");
}
}
if(StringUtils.isBlank(userRegion2)) {
errInfo.append(
String.format(prop.getProperty("can_not_null"), prop.getProperty("redirect_url"))
+ ";");
}
if(StringUtils.isNotBlank(userRegion2)){
Pattern pat = Pattern.compile("^[hH][tT][tT][pP]([sS]?):\\/\\/(\\S+\\.)+\\S{2,}$");
boolean bl = pat.matcher(userRegion2).matches();
@@ -449,6 +457,29 @@ public class CheckIpFormatThread implements Callable<String>{
}
// 拦截策略(限速)
if (regionDict.getFunctionId().equals(200) && serviceDict.getAction().equals(64)) {
baseIpCfg.setUserRegion1("0");// limit_rate_type限速方式默认值
if(StringUtils.isBlank(baseIpCfg.getUserRegion2())) {
baseIpCfg.setUserRegion2("0.1");
}
String userRegion2 = baseIpCfg.getUserRegion2();// 丢包率
if (StringUtils.isNotBlank(userRegion2)) {
List<SysDataDictionaryItem> dicts = DictUtils.getDictList("RATE_LIMIT");
boolean has = false;
for (SysDataDictionaryItem dict : dicts) {
if (dict.getItemCode().equals(userRegion2)) {
has = true;
break;
}
}
if (!has) {
errInfo.append(String.format(prop.getProperty("is_incorrect"),
prop.getProperty("ratelimit") + " ") + ";");
}
}
}
if (regionDict.getRegionType().equals(1)) {
boolean srcIpEmpty = false;
boolean destIpEmpty = false;
@@ -743,7 +774,7 @@ public class CheckIpFormatThread implements Callable<String>{
//packet ip reject
if(regionDict.getFunctionId().equals(5)&&serviceDict!=null&&serviceDict.getServiceId().equals(16)) {
baseIpCfg.setProtocol(6);
}else {
}else if(!regionDict.getFunctionId().equals(200)) {
if (StringUtils.isBlank(regionDict.getConfigProtocol())) {
baseIpCfg.setProtocol(0);
} else {
@@ -763,6 +794,9 @@ public class CheckIpFormatThread implements Callable<String>{
+ String.format(prop.getProperty("alternative_values"), 6) + ";");
}
}
if(regionDict.getFunctionId().equals(200) && (serviceDict.getAction().equals(64))) {
protocol = "0,6,17";
}
// TODO 判断Protocol的值
if(baseIpCfg.getProtocol()==null) {
if(protocol.indexOf("0")>-1) {

View File

@@ -92,9 +92,6 @@ public class CheckStringFormatThread implements Callable<String>{
if(baseStringCfg.getCfgDesc().length() > 128) {
errInfo.append(prop.getProperty("config_describe")+prop.getProperty("length_error")+" "+String.format(prop.getProperty("max_length")+":128") + ";");
}
if(baseStringCfg.getCfgKeywords().length() < 4 || baseStringCfg.getCfgKeywords().length() > 1024){
errInfo.append(prop.getProperty("key_word")+prop.getProperty("length_error")+" "+String.format(prop.getProperty("min_length")+":4,"+prop.getProperty("max_length")+":1024") + ";");
}
if (regionDict.getRegionType().equals(2)) {
if (regionDict.getFunctionId().equals(510) && "p2p_hash".equals(regionDict.getConfigServiceType())) {
@@ -115,37 +112,50 @@ public class CheckStringFormatThread implements Callable<String>{
}
}
// 代理-域名拦截
if (regionDict.getFunctionId().equals(201) && "intercept_domain".equals(regionDict.getConfigServiceType())) {
String userRegion5 = baseStringCfg.getUserRegion5();// 拦截强度
String userRegion2 = baseStringCfg.getUserRegion2();// 丢包率
if (StringUtils.isNotBlank(userRegion5)) {
List<SysDataDictionaryItem> dicts = DictUtils.getDictList("INTERCEPT_DOMAIN_INTENSITY");
boolean has = false;
for (SysDataDictionaryItem dict : dicts) {
if (dict.getItemCode().equals(userRegion5)) {
has = true;
break;
if (regionDict.getFunctionId().equals(200) && "intercept_domain".equals(regionDict.getConfigServiceType())) {
if(serviceDict.getAction().equals(1)) {
if(StringUtils.isBlank(baseStringCfg.getUserRegion5())) {
baseStringCfg.setUserRegion5("1");
}
String userRegion5 = baseStringCfg.getUserRegion5();// 拦截强度
if (StringUtils.isNotBlank(userRegion5)) {
List<SysDataDictionaryItem> dicts = DictUtils.getDictList("INTERCEPT_DOMAIN_INTENSITY");
boolean has = false;
for (SysDataDictionaryItem dict : dicts) {
if (dict.getItemCode().equals(userRegion5)) {
has = true;
break;
}
}
if (!has) {
errInfo.append(String.format(prop.getProperty("is_incorrect"),
prop.getProperty("intercept_intensity") + " ") + ";");
}
}
if (!has) {
errInfo.append(String.format(prop.getProperty("is_incorrect"),
prop.getProperty("intercept_intensity") + " ") + ";");
}else if(serviceDict.getAction().equals(64)) {
baseStringCfg.setUserRegion1("0");// limit_rate_type限速方式默认值
if(StringUtils.isBlank(baseStringCfg.getUserRegion2())) {
baseStringCfg.setUserRegion2("0.1");
}
}
if (StringUtils.isNotBlank(userRegion2)) {
List<SysDataDictionaryItem> dicts = DictUtils.getDictList("RATE_LIMIT");
boolean has = false;
for (SysDataDictionaryItem dict : dicts) {
if (dict.getItemCode().equals(userRegion2)) {
has = true;
break;
String userRegion2 = baseStringCfg.getUserRegion2();// 丢包率
if (StringUtils.isNotBlank(userRegion2)) {
List<SysDataDictionaryItem> dicts = DictUtils.getDictList("RATE_LIMIT");
boolean has = false;
for (SysDataDictionaryItem dict : dicts) {
if (dict.getItemCode().equals(userRegion2)) {
has = true;
break;
}
}
if (!has) {
errInfo.append(String.format(prop.getProperty("is_incorrect"),
prop.getProperty("ratelimit") + " ") + ";");
}
}
if (!has) {
errInfo.append(String.format(prop.getProperty("is_incorrect"),
prop.getProperty("ratelimit") + " ") + ";");
}
}
}
// 代理HTTP(s)阻断
if (regionDict.getFunctionId().equals(207)) {
@@ -168,6 +178,9 @@ public class CheckStringFormatThread implements Callable<String>{
}
// 代理 HTTP(s)重定向
if (regionDict.getFunctionId().equals(208)) {
if(StringUtils.isBlank(baseStringCfg.getUserRegion1())) {
baseStringCfg.setUserRegion1("301");
}
String userRegion1 = baseStringCfg.getUserRegion1();// 重定向应答码
String userRegion2 = baseStringCfg.getUserRegion2();// 重定向URL
if (StringUtils.isNotBlank(userRegion1)) {
@@ -184,6 +197,11 @@ public class CheckStringFormatThread implements Callable<String>{
prop.getProperty("redirect_response_code") + " ") + ";");
}
}
if(StringUtils.isBlank(userRegion2)) {
errInfo.append(
String.format(prop.getProperty("can_not_null"), prop.getProperty("redirect_url"))
+ ";");
}
if(StringUtils.isNotBlank(userRegion2)){
Pattern pat = Pattern.compile("^[hH][tT][tT][pP]([sS]?):\\/\\/(\\S+\\.)+\\S{2,}$");
boolean bl = pat.matcher(userRegion2).matches();
@@ -214,10 +232,12 @@ public class CheckStringFormatThread implements Callable<String>{
}
String keyword = baseStringCfg.getCfgKeywords();
if (!regionDict.getFunctionId().equals(403) && !regionDict.getFunctionId().equals(201)) {// 201域名拦截
if (!regionDict.getFunctionId().equals(403) && !regionDict.getFunctionId().equals(200)) {// 201域名拦截
if (StringUtils.isBlank(keyword)) {
errInfo.append(
String.format(prop.getProperty("can_not_null"), prop.getProperty("key_word") + " ") + ";");
}else if(keyword.length() < 4 || keyword.length() > 1024){
errInfo.append(prop.getProperty("key_word")+prop.getProperty("length_error")+" "+String.format(prop.getProperty("min_length")+":4,"+prop.getProperty("max_length")+":1024") + ";");
}
if (mulityKeywordsP.equals("0")) {
if (keyword.indexOf("\n") > -1) {
@@ -260,6 +280,8 @@ public class CheckStringFormatThread implements Callable<String>{
if (StringUtils.isBlank(keyword)) {
errInfo.append(
String.format(prop.getProperty("can_not_null"), prop.getProperty("domain_name") + " ") + ";");
}else if(keyword.length() < 4 || keyword.length() > 1024){
errInfo.append(prop.getProperty("domain_name")+prop.getProperty("length_error")+" "+String.format(prop.getProperty("min_length")+":4,"+prop.getProperty("max_length")+":1024") + ";");
}else {
Matcher m = pattern.matcher(keyword);
if (m.find()) {

View File

@@ -1365,7 +1365,10 @@ public class BaseController {
}else if(regionDict.getFunctionId().equals(209)){// HTTP(s)替换
BlockingQueue<HttpsReplaceIpTemplate> list = ei.getDataList(HttpsReplaceIpTemplate.class );
ipPortCfgs=this.checkIpCfgMulity(errTip,serviceDict, regionDict, null,asnGroupInfos, list);
} else {
}else if(regionDict.getFunctionId().equals(200) && serviceDict.getAction().equals(64)) {// 拦截策略(限速)
BlockingQueue<IpRateLimitTemplate> list = ei.getDataList(IpRateLimitTemplate.class );
ipPortCfgs=this.checkIpCfgMulity(errTip,serviceDict, regionDict,null,asnGroupInfos, list);
}else {
BlockingQueue<IpAllTemplate> list = ei.getDataList(IpAllTemplate.class );
ipPortCfgs=this.checkIpCfgMulity(errTip,serviceDict, regionDict, null,asnGroupInfos, list);
}
@@ -1379,7 +1382,7 @@ public class BaseController {
BlockingQueue<AppDomainTemplate> list = ei.getDataList(AppDomainTemplate.class
);
stringCfgs=this.checkStringCfgMulity(errTip,serviceDict, regionDict, list);
}else if (regionDict.getFunctionId().equals(201)){// Domain Intercept
}else if (regionDict.getFunctionId().equals(200)){// 拦截策略
if(serviceDict.getAction().equals(1)){// 监测
BlockingQueue<DomainInterceptMonitTemplate> list = ei.getDataList(DomainInterceptMonitTemplate.class);
stringCfgs=this.checkStringCfgMulity(errTip,serviceDict, regionDict, list);
@@ -2150,6 +2153,8 @@ public class BaseController {
ei.loadInitParams(HttpsRedirectIpTemplate.class, this.getMsgProp(), regionDict, serviceDict);
} else if(regionDict.getFunctionId().equals(209)){// HTTP(s)替换
ei.loadInitParams(HttpsReplaceIpTemplate.class, this.getMsgProp(), regionDict, serviceDict);
} else if(regionDict.getFunctionId().equals(200) && serviceDict.getAction().intValue()==64){// 拦截策略(限速)
ei.loadInitParams(IpRateLimitTemplate.class, msgProp, regionDict, serviceDict);
} else {
ei.loadInitParams(IpAllTemplate.class, msgProp, regionDict, serviceDict);
}
@@ -2159,7 +2164,7 @@ public class BaseController {
ei.loadInitParams(P2pHashStringTemplate.class, msgProp, regionDict, serviceDict);
}else if (regionDict.getFunctionId().equals(403)) {
ei.loadInitParams(AppDomainTemplate.class, msgProp, regionDict, serviceDict);
} else if(regionDict.getFunctionId().equals(201)){// Domain Intercept
} else if(regionDict.getFunctionId().equals(200)){// 拦截策略 domain
if(serviceDict.getAction().equals(1)){// 监测
ei.loadInitParams(DomainInterceptMonitTemplate.class, msgProp, regionDict, serviceDict);
}else if(serviceDict.getAction().equals(64)){// 限速

View File

@@ -386,6 +386,11 @@ public class IpController extends BaseController{
ExportExcel excel=new ExportExcel(serviceDict,regionDict,this.getMsgProp(),null, HttpsReplaceIpTemplate.class, 2);
excel.setDataList(this.getMsgProp(),classList,null).
write(request,response, fileName).dispose();
}else if(regionDict.getFunctionId().equals(200) && serviceDict.getAction().equals(64)) {// 拦截策略IP限速
List<IpRateLimitTemplate> classList=new ArrayList<IpRateLimitTemplate>();
ExportExcel excel=new ExportExcel(serviceDict,regionDict,pro,null, IpRateLimitTemplate.class, 2);
excel.setDataList(pro,classList,null).
write(request,response, fileName).dispose();
}else{
List<IpAllTemplate> classList=new ArrayList<IpAllTemplate>();
ExportExcel excel=new ExportExcel(serviceDict,regionDict,pro,null, IpAllTemplate.class, 2);
@@ -405,7 +410,7 @@ public class IpController extends BaseController{
ExportExcel excel=new ExportExcel(serviceDict,regionDict,pro,null, AppDomainTemplate.class, 2);
excel.setDataList(pro,classList,null).
write(request,response, fileName).dispose();
}else if(regionDict.getFunctionId().equals(201)){// Domain Intercept
}else if(regionDict.getFunctionId().equals(200)){// 拦截策略(域名)
if(serviceDict.getAction().equals(1)){// 监测
List<DomainInterceptMonitTemplate> classList=new ArrayList<DomainInterceptMonitTemplate>();
ExportExcel excel=new ExportExcel(serviceDict,regionDict,pro,null, DomainInterceptMonitTemplate.class, 2);

View File

@@ -2340,10 +2340,11 @@ public abstract class BaseService {
umap.put("pps_threadshold", _cfg.getPpsThreadshold());
maatCfg.setUserRegion(new Gson().toJson(umap));
}else if(regionDict.getFunctionId()==200) {// IP Intercept
maatCfg.setUserRegion(Constants.USER_REGION_PLACEHOLDER);
/*maatCfg.setUserRegion(Constants.USER_REGION_PLACEHOLDER);
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());
}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)) {// 阻断
@@ -2448,7 +2449,7 @@ public abstract class BaseService {
}
}else if(regionDict.getDictId()==159) {
maatCfg.setUserRegion(Constants.P2P_HASH_TYPE_USER_REGION_KEY+"="+_cfg.getUserRegion1());
}else if(regionDict.getFunctionId()==201) {// Domain Intercept
}else if(regionDict.getFunctionId()==200) {// Domain Intercept
String userRegion = Constants.USERREGION_DOMAIN_ID+"="+_cfg.getCompileId()+";"+Constants.USERREGION_DOMAIN_STR+"="+_cfg.getCfgKeywords();
if(_cfg.getAction().equals(Constants.MONIT_ACTION)) {// 监测 需要发keyring_id、拦截强度
userRegion = Constants.INTERCEPT_IP_MONIT_USER_REGION_KEY+"=0"+";"+Constants.INTERCEPT_DOMAN_INTENSITY_USER_REGION_KEY+"="+_cfg.getUserRegion5()+";" + userRegion;

View File

@@ -137,7 +137,7 @@ var resetIndex = function(){
<label class="control-label col-md-3"><font color="red">*</font><spring:message code="address_pool"/></label>
<div class="col-md-6">
<!-- 地址池名称 -->
<input class="form-control required addrPoolUnique" type="text" name="addrPoolName" value="${_cfg.addrPoolName}" autocomplete="off" ctx="${ctx}">
<input class="form-control required addrPoolUnique" type="text" name="addrPoolName" value="${_cfg.addrPoolName}" maxlength="128" autocomplete="off" ctx="${ctx}">
</div>
<div for="addrPoolName"></div>
</div>