asn相关功能修改

This commit is contained in:
duandongmei
2019-01-16 13:55:12 +06:00
parent cc0b7dc86c
commit 616a80555d
8 changed files with 346 additions and 49 deletions

View File

@@ -356,7 +356,7 @@ public class ConfigServiceUtil {
}else if(type==2){
url = url+Constants.CALLBACK_CFG;
}else if(type==3) {
url = url+Constants.GROUP_REUSE_SOURCES;
url = url+Constants.DELETE_COMMON_REIGON;
}
//创建连接
WebTarget wt = ClientUtil.getWebTarger(url);
@@ -400,9 +400,9 @@ public class ConfigServiceUtil {
url = url+Constants.MAAT_CFG;
}else if(type==2){
url = url+Constants.CALLBACK_CFG;
}else if(type==3) {
}/*else if(type==3) {
url = url+Constants.GROUP_REUSE_SOURCES;
}
}*/
logger.info("put url:"+url);
//创建连接
try {
@@ -463,26 +463,43 @@ public class ConfigServiceUtil {
return bean;
}
/**
* 分组复用域配置新增
* 分组复用域配置新增,修改,删除
* @param params
* @return
* @throws MaatConvertException
*/
public static ToMaatResult postGroupReuseSources(String params) throws MaatConvertException{
public static ToMaatResult auditCommonGroupRegionSources(String params,Integer action) throws MaatConvertException{
ToMaatResult bean = null;
Response response=null;
try {
logger.warn("postGroupReuseSources start");
long start=System.currentTimeMillis();
String result = null;
String url = Constants.SERVICE_URL+Constants.GROUP_REUSE_SOURCES;
String url = "";
if(action.equals(Constants.OPACTION_POST)){
url=Constants.SERVICE_URL+Constants.ADD_COMMON_REGION;
}
if(action.equals(Constants.OPACTION_PUT)){
url=Constants.SERVICE_URL+Constants.UPDATE_COMMON_REIGON;
}
if(action.equals(Constants.OPACTION_DELETE)){
url=Constants.SERVICE_URL+Constants.DELETE_COMMON_REIGON;
}
//创建连接
WebTarget wt = ClientUtil.getWebTarger(url);
logger.info("postGroupReuseSources url:"+url);
logger.info("auditCommonGroupRegionSources url:"+url);
//获取响应结果
Builder header = wt.request(MediaType.APPLICATION_JSON).header("Content-Type", MediaType.APPLICATION_JSON);
try {
response= header.post(Entity.entity(params, MediaType.APPLICATION_JSON));
if(action.equals(Constants.OPACTION_POST)){
response= header.post(Entity.entity(params, MediaType.APPLICATION_JSON));
}
if(action.equals(Constants.OPACTION_PUT)){
response= header.put(Entity.entity(params, MediaType.APPLICATION_JSON));
}
if(action.equals(Constants.OPACTION_DELETE)){
response= header.put(Entity.entity(params, MediaType.APPLICATION_JSON));
}
if(response != null) {
result=response.readEntity(String.class);
}
@@ -498,7 +515,7 @@ public class ConfigServiceUtil {
throw new MaatConvertException("<spring:message code=\"request_service_failed\"/>:"+result);
}
long end=System.currentTimeMillis();
logger.warn("postGroupReuseSources end,cost:"+(end-start));
logger.warn("auditCommonGroupRegionSources end,cost:"+(end-start));
} catch (Exception e) {
throw e;
} finally {
@@ -508,6 +525,7 @@ public class ConfigServiceUtil {
}
return bean;
}
/**
*
* getReport(配置日志总量统计查询)
@@ -566,6 +584,64 @@ public class ConfigServiceUtil {
}
return result;
}
/**
*
* getReport(配置日志总量统计查询)
* (这里描述这个方法适用条件 可选)
* @param type 1- 配置命中总量业务2- 配置报表业务
* @param ids
* @param serviceIds
* @param searchReportStartTime
* @param searchReportEndTime
* @param connTimeOut httpclient 连接超时时间
* @param readTimeOut httpclient 读取超时时间
* @return
* @throws MaatConvertException
*/
public static String getReport(int type,String ids,String serviceIds,String searchReportStartTime,String searchReportEndTime,Integer connTimeOut,Integer readTimeOut) throws MaatConvertException{
String result = null;
Response response=null;
try {
if(StringUtils.isBlank(ids)||StringUtils.isBlank(serviceIds)){
throw new MaatConvertException("<spring:message code=\"request_service_failed\"/>");
}
UriBuilder builder=UriBuilder.fromPath(Constants.LOG_BASE_URL+Constants.NTC_PZ_REPORT);
builder.queryParam("searchBusinessType",type);
builder.queryParam("searchService",serviceIds);
builder.queryParam("searchCfgId",ids);
if(StringUtils.isNotBlank(searchReportStartTime)) {
builder.queryParam("searchReportStartTime",searchReportStartTime);
}
if(StringUtils.isNotBlank(searchReportEndTime)) {
builder.queryParam("searchReportEndTime",searchReportEndTime);
}
URI uri=builder.build();
//创建连接
ClientUtil.initClient(connTimeOut,readTimeOut);
Client client=ClientUtil.getClient();
WebTarget wt = client.target(uri);
logger.info("getReport url:"+uri.toString());
Builder header = wt.request();
try {
response= header.get();
} catch (Exception e) {
throw new MaatConvertException("<spring:message code=\"request_service_failed\"/>");
}
if(response !=null && response.getStatus() == 200){
result= response.readEntity(String.class);
}else{
throw new MaatConvertException("<spring:message code=\"request_service_failed\"/>:"+result);
}
} catch (Exception e) {
throw e;
} finally {
if (response != null) {
response.close();
}
}
return result;
}
public static String getReport(String reportUrl, SearchReport searchCondition) throws MaatConvertException{
// if(StringUtils.isBlank(searchCondition.getSearchService())){
// throw new MaatConvertException("<spring:message code=\"request_service_failed\"/>");

View File

@@ -13,7 +13,9 @@ public final class Constants {
*/
public static final int IMPORT_LIMIT=Configurations.getIntProperty("import_limit",10000);
public static final Object IMPORT_LOCK=new Object();
public static final String GROUP_REUSE_SOURCES=Configurations.getStringProperty("groupReuseSources","groupReuseSources");
public static final String ADD_COMMON_REGION=Configurations.getStringProperty("addRegionToCommonGroup","");
public static final String UPDATE_COMMON_REIGON=Configurations.getStringProperty("updateRegionToCommonGroup","");
public static final String DELETE_COMMON_REIGON=Configurations.getStringProperty("deleteRegionToCommonGroup","");
public static Integer APP_SPEC_SERVICE_CODE_MIN_VAL=Configurations.getIntProperty("app_spec_service_code_min_val", 300001);
public static Integer APP_SPEC_SERVICE_CODE_MAX_VAL=Configurations.getIntProperty("app_spec_service_code_max_val", 268435455);
public static String APP_CFG_USERREGION_SPLITOR=Configurations.getStringProperty("app_cfg_userregion_splitor", "&");
@@ -494,6 +496,7 @@ public final class Constants {
public static final String HTTP_URL_REGION = Configurations.getStringProperty("http_url_region","http_url");
public static final String VOIP_IP_REGION = Configurations.getStringProperty("voip_ip","av_voip_ip");
public static final String VOIP_ACCOUNT_REGION = Configurations.getStringProperty("voip_account","av_voip_account");
public static final String NTC_ASN_NUMBER = Configurations.getStringProperty("ntc_asn_number","NTC_ASN_NUMBER");
public static final String MAAT_VERSION = Configurations.getStringProperty("maat_version","1.0");
public static final Integer INSERT_ACTION = Configurations.getIntProperty("insert_action",1);
public static final Integer UPDATE_ACTION = Configurations.getIntProperty("update_action",2);
@@ -805,4 +808,9 @@ public final class Constants {
//配置启停服务接口方法
public static final String CONFIG_START_STOP_UPDATE=Configurations.getStringProperty("configStartStop", "configStartStop");
/**
* 流量日志的SSL泛收接口URL
*/
public static final String NTC_SSL_RECORD_LOG = Configurations.getStringProperty("ntcSslRecordLog","");
}

View File

@@ -106,12 +106,22 @@ public class CheckIpFormatThread implements Callable<String>{
BeanUtils.copyProperties(list.get(i), baseIpCfg);
String cfgDesc = baseIpCfg.getCfgDesc();
// 配置描述限制
if(StringUtils.isBlank(cfgDesc)) {
errInfo.append(
String.format(prop.getProperty("can_not_null"), prop.getProperty("config_describe")) + ";");
}else if(cfgDesc.length() > 128) {
errInfo.append(prop.getProperty("config_describe")+prop.getProperty("length_error")+" "+String.format(prop.getProperty("max_length")+":128") + ";");
if(!regionDict.getFunctionId().equals(600)){
if(StringUtils.isBlank(cfgDesc)) {
errInfo.append(
String.format(prop.getProperty("can_not_null"), prop.getProperty("config_describe")) + ";");
}else if(cfgDesc.length() > 128) {
errInfo.append(prop.getProperty("config_describe")+prop.getProperty("length_error")+" "+String.format(prop.getProperty("max_length")+":128") + ";");
}
}
if(regionDict.getFunctionId().equals(200)) {
if(!serviceDict.getAction().equals(1)) {
baseIpCfg.setDoLog(0);
}
}
// doLog属性检验
this.validDoLog(baseIpCfg,errInfo);
// 特殊字段验证
// packet ip ratelimit
@@ -158,16 +168,17 @@ public class CheckIpFormatThread implements Callable<String>{
// payload ip
if (regionDict.getFunctionId().equals(212)) {
// replace_zone
if (StringUtils.isBlank(baseIpCfg.getUserRegion1())) {
List<SysDataDictionaryItem> dict=DictUtils.getDictList("INTERCEPT_REPLACE_ZONE");
baseIpCfg.setUserRegion1(dict.get(0).getItemCode());
}
String userRegion1 = baseIpCfg.getUserRegion1();
if (StringUtils.isNotBlank(userRegion1)) {
Object val = DictUtils.getDictLabel("INTERCEPT_REPLACE_ZONE", userRegion1);
if (StringUtils.isBlank(val.toString())) {
if (StringUtils.isBlank(val.toString())||"默认".equals(val.toString())) {
errInfo.append(String.format(prop.getProperty("is_incorrect"), prop.getProperty("replace_zone"))
+ ";");
}
} else {
errInfo.append(
String.format(prop.getProperty("can_not_null"), prop.getProperty("replace_zone")) + ";");
}
// replaced_content
@@ -369,16 +380,31 @@ public class CheckIpFormatThread implements Callable<String>{
String.format(prop.getProperty("is_incorrect"), prop.getProperty("antiddos_protocol"))
+ ";");
}
if(bpsThreadshold==null) {
errInfo.append(
String.format(prop.getProperty("can_not_null"), prop.getProperty("bps_threadshold"))
+ ";");
}else {
if(bpsThreadshold < 1000000) {
errInfo.append(prop.getProperty("bps_threadshold")+prop.getProperty("min_value")+"1000000;");
}else if(String.valueOf(bpsThreadshold).length() > 18) {
errInfo.append(prop.getProperty("bps_threadshold")+prop.getProperty("length_error")+" "+String.format(prop.getProperty("max_length")+":18") + ";");
}
}
if(ppsThreadshold==null) {
errInfo.append(
String.format(prop.getProperty("can_not_null"), prop.getProperty("pps_threadshold"))
+ ";");
}else {
if(ppsThreadshold < 1000) {
errInfo.append(prop.getProperty("pps_threadshold")+prop.getProperty("min_value")+"1000;");
}else if(String.valueOf(ppsThreadshold).length() > 18) {
errInfo.append(prop.getProperty("pps_threadshold")+prop.getProperty("length_error")+" "+String.format(prop.getProperty("max_length")+":18") + ";");
}
}
if("TCP_SYN".equals(antiddosProtocol)) {
baseIpCfg.setProtocol(6);
}else if("UDP_NTP".equals(antiddosProtocol)) {
@@ -512,6 +538,38 @@ public class CheckIpFormatThread implements Callable<String>{
}
}
// IpSpoofing
if (regionDict.getFunctionId().equals(214)) {
List<SysDataDictionaryItem> dicts = DictUtils.getDictList("SPOOFING_IP_TYPE");
if(StringUtils.isBlank(baseIpCfg.getUserRegion1())) {
baseIpCfg.setUserRegion1(dicts.get(0).getItemCode());
}
String userRegion1 = baseIpCfg.getUserRegion1(); // SpooFing
String userRegion2 = baseIpCfg.getUserRegion2(); // With
if (StringUtils.isNotBlank(userRegion1)) {
boolean has = false;
for (SysDataDictionaryItem dict : dicts) {
if (dict.getItemCode().equals(userRegion1)) {
has = true;
break;
}
}
if (!has) {
errInfo.append(String.format(prop.getProperty("is_incorrect"),prop.getProperty("spoofing") + " ") + ";");
}
}
String errMsg = null == prop.getProperty("With")?"With ":prop.getProperty("With");
if(StringUtils.isBlank(userRegion2)) {
errInfo.append(
String.format(prop.getProperty("can_not_null"),errMsg + " ") + ";");
}else {
String regex = "^((25[0-5]|2[0-4]\\d|[01]?\\d\\d?)\\.){3}(25[0-5]|2[0-4]\\d|[01]?\\d\\d?)$";
if(!userRegion2.matches(regex)) {
errInfo.append(String.format(prop.getProperty("is_in_wrong_format"),errMsg +" ") + ";");
}
}
}
if (regionDict.getRegionType().equals(1)) {
boolean srcIpEmpty = false;
boolean destIpEmpty = false;
@@ -1153,7 +1211,31 @@ public class CheckIpFormatThread implements Callable<String>{
errInfo.append(prop.get(ipName) + " " + prop.get("ip_range_smaller") + ";");
}
}
/**
* doLog属性校验
* @param baseIpCfg
* @param errInfo
*/
public void validDoLog(IpPortCfg baseIpCfg, StringBuffer errInfo) {
String configDoLog = serviceDict.getConfigDoLog();
if(StringUtils.isNotBlank(configDoLog)) {
String defaultValue = configDoLog.substring(configDoLog.lastIndexOf(";")+1);
String doLogOption = configDoLog.substring(configDoLog.indexOf(";")+1, configDoLog.lastIndexOf(";"));
if(baseIpCfg.getDoLog() == null) {
baseIpCfg.setDoLog(Integer.parseInt(defaultValue));
}
Integer doLog = baseIpCfg.getDoLog();
if(!doLogOption.contains(doLog+"")) {
errInfo.append(
String.format(prop.getProperty("is_incorrect"), prop.getProperty("do_log"))
+ ";");
}
}
}
/**
* 根据位运算把 byte[] -> int
*