440 lines
18 KiB
JavaScript
440 lines
18 KiB
JavaScript
/**
|
||
* 处理IP域值
|
||
*/
|
||
;(function($){
|
||
$.extend({
|
||
ipcommon:function(){
|
||
return {};
|
||
}
|
||
});
|
||
$.extend($.ipcommon, {
|
||
ipType:[],
|
||
srcIpPattern:[],
|
||
destIpPattern:[],
|
||
srcPortPattern:[],
|
||
destPortPattern:[],
|
||
protocol:[],
|
||
direction:[]
|
||
});
|
||
})(jQuery);
|
||
$(function(){
|
||
initCommIpVal();
|
||
//IP域修改时默认展开,不显示show more
|
||
if($("input[name='compileId']")&&$("input[name='compileId']").val()!=0&&($(".btn-red-hollow").parents(".boxSolid").is(":visible")||$("input[name$='cfgRegionCode']").length==1)){
|
||
$(".port").removeClass("hidden").removeClass("disabled");
|
||
$(".destPort").removeClass("hidden").removeClass("disabled");
|
||
$(".protocol").removeClass("hidden").removeClass("disabled");
|
||
$(".ipCol:hidden").removeClass("hidden").removeClass("disabled");
|
||
$(".btn-red-hollow").addClass("hidden");
|
||
}
|
||
});
|
||
window.$.ipcommon=$.ipcommon;
|
||
/**
|
||
* 初始化格式处理
|
||
*/
|
||
var processPattern=function(selector,pattern){
|
||
if("ipType"==selector){
|
||
$.ipcommon.ipType=$("select[name$='ipType'] option");
|
||
}else if("srcIpPattern"==selector){
|
||
$.ipcommon.srcIpPattern=$("select[name$='srcIpPattern'] option");
|
||
}else if("destIpPattern"==selector){
|
||
$.ipcommon.destIpPattern=$("select[name$='destIpPattern'] option");
|
||
}else if("srcPortPattern"==selector){
|
||
$.ipcommon.srcPortPattern=$("select[name$='srcPortPattern'] option");
|
||
}else if("destPortPattern"==selector){
|
||
$.ipcommon.destPortPattern=$("select[name$='destPortPattern'] option");
|
||
}else if("direction"==selector){
|
||
$.ipcommon.direction=$("select[name$='direction'] option");
|
||
}else if("protocol"==selector){
|
||
$.ipcommon.protocol=$("select[name$='protocol'] option");
|
||
}
|
||
if(pattern){
|
||
var arr=pattern.split(',');
|
||
$("select[name$='"+selector+"'] option").each(function(){
|
||
var has=false;
|
||
for(var type in arr){
|
||
if($(this).val()==arr[type]){
|
||
has=true;
|
||
if($(this).attr("disabled")){
|
||
$(this).removeAttr("disabled")
|
||
}
|
||
break;
|
||
}
|
||
}
|
||
if(!has){
|
||
$(this).remove();
|
||
}
|
||
});
|
||
}
|
||
}
|
||
/**
|
||
* ip默认选项处理
|
||
*/
|
||
var initCommIpVal=function(){
|
||
var action,regionCode,ipPortShow,ipType,serviceId,
|
||
srcIpPattern,destIpPattern,srcPortPattern,destPortPattern,
|
||
direction,protocol,regionType;
|
||
if($("input[name$='action']:checked").length>0){
|
||
regionCode=$("input[name$='action']:checked").attr("regionCode");
|
||
action=$("input[name$='action']:checked").val();
|
||
serviceId=$("input[name$='action']:checked").attr("serviceId");
|
||
}else{
|
||
regionCode=$("input[name$='action']").attr("regionCode");
|
||
action=$("input[name$='action']").val();
|
||
serviceId=$("input[name$='action']").attr("serviceId");
|
||
}
|
||
if(regionCode){
|
||
if(regionCode.indexOf(",")==-1){
|
||
$("#cfgRegionCode"+regionCode).attr("name","cfgRegionCode");
|
||
$("#cfgType"+regionCode).attr("name","cfgType");
|
||
}else{
|
||
var _region='';
|
||
var regionArr=regionCode.split(',');
|
||
$("input[name$='cfgRegionCode'][regionType='1']").each(function(){
|
||
for(var re in regionArr){
|
||
if($(this).val()==regionArr[re]){
|
||
_region=regionArr[re];
|
||
break;
|
||
}
|
||
}
|
||
});
|
||
if(_region!=''){
|
||
regionCode=_region;
|
||
}
|
||
}
|
||
}
|
||
if(regionCode){//IP域大于1个,根据action获取ip属性
|
||
|
||
if($("input[name$='cfgRegionCode'][value='"+regionCode+"']")&&$("input[name$='cfgRegionCode'][value='"+regionCode+"']").attr("regionType")==1){
|
||
}else if(serviceId==149||serviceId==37){//ASN比较特殊,action与ip的相同但是service id不同,这里调用regionCode=5的话会导致获取不到正确的属性
|
||
regionCode=$("input[name$='action'][value='"+action+"'][serviceId!='"+serviceId+"']").attr("regionCode");
|
||
}
|
||
ipPortShow=$("input[name$='cfgRegionCode'][value='"+regionCode+"']").attr("ipPortShow"),
|
||
ipType=$("input[name$='cfgRegionCode'][value='"+regionCode+"']").attr("ipType"),
|
||
srcIpPattern=$("input[name$='cfgRegionCode'][value='"+regionCode+"']").attr("srcIpPattern"),
|
||
destIpPattern=$("input[name$='cfgRegionCode'][value='"+regionCode+"']").attr("destIpPattern"),
|
||
srcPortPattern=$("input[name$='cfgRegionCode'][value='"+regionCode+"']").attr("srcPortPattern"),
|
||
destPortPattern=$("input[name$='cfgRegionCode'][value='"+regionCode+"']").attr("destPortPattern"),
|
||
direction=$("input[name$='cfgRegionCode'][value='"+regionCode+"']").attr("direction"),
|
||
protocol=$("input[name$='cfgRegionCode'][value='"+regionCode+"']").attr("protocol"),
|
||
regionType=$("input[name$='cfgRegionCode'][value='"+regionCode+"']").attr("regionType");
|
||
}else{//IP域只有一个,获取regionType为1的
|
||
ipPortShow=$("input[name$='cfgRegionCode'][regionType='1']").attr("ipPortShow"),
|
||
ipType=$("input[name$='cfgRegionCode'][regionType='1']").attr("ipType"),
|
||
srcIpPattern=$("input[name$='cfgRegionCode'][regionType='1']").attr("srcIpPattern"),
|
||
destIpPattern=$("input[name$='cfgRegionCode'][regionType='1']").attr("destIpPattern"),
|
||
srcPortPattern=$("input[name$='cfgRegionCode'][regionType='1']").attr("srcPortPattern"),
|
||
destPortPattern=$("input[name$='cfgRegionCode'][regionType='1']").attr("destPortPattern"),
|
||
direction=$("input[name$='cfgRegionCode'][regionType='1']").attr("direction"),
|
||
protocol=$("input[name$='cfgRegionCode'][regionType='1']").attr("protocol"),
|
||
regionType=$("input[name$='cfgRegionCode'][regionType='1']").attr("regionType");
|
||
}
|
||
//ip,端口处理源ip展示、源端口展示、目的ip展示、目的端口展示1、2、3、4
|
||
if(ipPortShow){
|
||
if(ipPortShow.indexOf('1')>-1){//展示源IP
|
||
$("input[name$='srcIpAddress']").parents(".form-group").removeClass("hidden");
|
||
$("select[name$='srcIpPattern']").parents(".form-group").removeClass("hidden");
|
||
}else{
|
||
$("input[name$='srcIpAddress']").parents(".form-group").addClass("hidden");
|
||
$("select[name$='srcIpPattern']").parents(".form-group").addClass("hidden");
|
||
if(!$("input[name$='srcIpAddress']").parents(".ipCol").is(":hidden")){
|
||
$("input[name$='srcIpAddress']").parents(".ipCol").addClass("hidden");
|
||
}
|
||
}
|
||
if(ipPortShow.indexOf('2')>-1){//展示源端口
|
||
$("input[name$='srcPort']").parents(".form-group").removeClass("hidden");
|
||
$("select[name$='srcPortPattern']").parents(".form-group").removeClass("hidden");
|
||
}else{
|
||
$("input[name$='srcPort']").parents(".form-group").addClass("hidden");
|
||
$("select[name$='srcPortPattern']").parents(".form-group").addClass("hidden");
|
||
}
|
||
if(ipPortShow.indexOf('3')>-1){//展示目的IP
|
||
$("input[name$='destIpAddress']").parents(".form-group").removeClass("hidden");
|
||
$("select[name$='destIpPattern']").parents(".form-group").removeClass("hidden");
|
||
//当源IP不展示的时候目的IP要默认展示
|
||
if($("input[name$='destIpAddress']").parents(".ipCol")&&ipPortShow.indexOf('1')==-1){
|
||
$("input[name$='destIpAddress']").parents(".ipCol").removeClass("hidden");
|
||
}
|
||
}else{
|
||
$("input[name$='destIpAddress']").parents(".form-group").addClass("hidden");
|
||
$("select[name$='destIpPattern']").parents(".form-group").addClass("hidden");
|
||
}
|
||
if(ipPortShow.indexOf('4')>-1){//展示目的端口
|
||
$("input[name$='destPort']").parents(".form-group").removeClass("hidden");
|
||
$("select[name$='destPortPattern']").parents(".form-group").removeClass("hidden");
|
||
}else{
|
||
$("input[name$='destPort']").parents(".form-group").addClass("hidden");
|
||
$("select[name$='destPortPattern']").parents(".form-group").addClass("hidden");
|
||
}
|
||
}
|
||
if(ipType){
|
||
processPattern("ipType",ipType);
|
||
}
|
||
if(srcIpPattern){
|
||
processPattern("srcIpPattern",srcIpPattern);
|
||
}
|
||
if(destIpPattern){
|
||
processPattern("destIpPattern",destIpPattern);
|
||
}
|
||
if(srcPortPattern){
|
||
processPattern("srcPortPattern",srcPortPattern);
|
||
}
|
||
if(destPortPattern){
|
||
processPattern("destPortPattern",destPortPattern);
|
||
}
|
||
if(direction){
|
||
processPattern("direction",direction);
|
||
}
|
||
if(protocol){
|
||
processPattern("protocol",protocol);
|
||
}
|
||
}
|
||
var changePattern=function(o,selector,pattern){
|
||
if(pattern){
|
||
arr=pattern.split(',');
|
||
var ipPatternVal=o.find("select[name$='"+selector+"'] option:selected").attr("value");
|
||
o.find("select[name$='"+selector+"']").empty();
|
||
var patterns=selector=="srcIpPattern"?$.ipcommon.srcIpPattern:
|
||
selector=="destIpPattern"?$.ipcommon.destIpPattern:
|
||
selector=="srcPortPattern"?$.ipcommon.srcPortPattern:
|
||
selector=="destPortPattern"?$.ipcommon.destPortPattern:[];
|
||
$(patterns).each(function(){
|
||
var has=false;
|
||
for(var type in arr){
|
||
if($(this).val()==arr[type]){
|
||
has=true;
|
||
o.find("select[name$='"+selector+"']").append($(this));
|
||
break;
|
||
}
|
||
}
|
||
});
|
||
o.find("select[name$='"+selector+"']").selectpicker("refresh");
|
||
if(o.find("select[name$='"+selector+"'] option[value='"+ipPatternVal+"']").length>0){
|
||
o.find("select[name$='"+selector+"']").selectpicker("val",ipPatternVal);
|
||
}else{
|
||
if(o.find("select[name$='"+selector+"'] option[value=1]").length>0){
|
||
o.find("select[name$='"+selector+"']").selectpicker("val",1);
|
||
}else{
|
||
o.find("select[name$='"+selector+"']").get(0).selectedIndex=0;
|
||
o.find("select[name$='"+selector+"']").selectpicker("refresh");
|
||
}
|
||
}
|
||
}
|
||
}
|
||
/**
|
||
* ip切换默认值处理
|
||
*/
|
||
var changeIPVal=function(obj){
|
||
var action,regionCode,serviceType,ipPortShow,ipType,
|
||
srcIpPattern,destIpPattern,srcPortPattern,destPortPattern,direction,protocol,regionType,o;
|
||
o=$(obj);
|
||
if($("input[name$='action']:checked").length>0){
|
||
regionCode=$("input[name$='action']:checked").attr("regionCode");
|
||
action=$("input[name$='action']:checked").val();
|
||
}else{
|
||
regionCode=$("input[name$='action']").attr("regionCode");
|
||
action=$("input[name$='action']").val();
|
||
}
|
||
if(regionCode){
|
||
if(regionCode.indexOf(",")==-1){
|
||
$("#cfgRegionCode"+regionCode).attr("name","cfgRegionCode");
|
||
$("#cfgType"+regionCode).attr("name","cfgType");
|
||
}else{
|
||
var _region='';
|
||
var regionArr=regionCode.split(',');
|
||
$("input[name$='cfgRegionCode'][regionType='1']").each(function(){
|
||
for(var re in regionArr){
|
||
if($(this).val()==regionArr[re]){
|
||
_region=regionArr[re];
|
||
break;
|
||
}
|
||
}
|
||
});
|
||
if(_region!=''){
|
||
regionCode=_region;
|
||
}
|
||
}
|
||
}
|
||
if(regionCode){//IP域大于1个,根据action获取ip属性
|
||
ipPortShow=$("input[name$='cfgRegionCode'][value='"+regionCode+"']").attr("ipPortShow"),
|
||
ipType=$("input[name$='cfgRegionCode'][value='"+regionCode+"']").attr("ipType"),
|
||
srcIpPattern=$("input[name$='cfgRegionCode'][value='"+regionCode+"']").attr("srcIpPattern"),
|
||
destIpPattern=$("input[name$='cfgRegionCode'][value='"+regionCode+"']").attr("destIpPattern"),
|
||
srcPortPattern=$("input[name$='cfgRegionCode'][value='"+regionCode+"']").attr("srcPortPattern"),
|
||
destPortPattern=$("input[name$='cfgRegionCode'][value='"+regionCode+"']").attr("destPortPattern"),
|
||
direction=$("input[name$='cfgRegionCode'][value='"+regionCode+"']").attr("direction"),
|
||
protocol=$("input[name$='cfgRegionCode'][value='"+regionCode+"']").attr("protocol"),
|
||
regionType=$("input[name$='cfgRegionCode'][value='"+regionCode+"']").attr("regionType");
|
||
}else{//IP域只有一个,获取regionType为1的
|
||
ipPortShow=$("input[name$='cfgRegionCode'][regionType='1']").attr("ipPortShow"),
|
||
ipType=$("input[name$='cfgRegionCode'][regionType='1']").attr("ipType"),
|
||
srcIpPattern=$("input[name$='cfgRegionCode'][regionType='1']").attr("srcIpPattern"),
|
||
destIpPattern=$("input[name$='cfgRegionCode'][regionType='1']").attr("destIpPattern"),
|
||
srcPortPattern=$("input[name$='cfgRegionCode'][regionType='1']").attr("srcPortPattern"),
|
||
destPortPattern=$("input[name$='cfgRegionCode'][regionType='1']").attr("destPortPattern"),
|
||
direction=$("input[name$='cfgRegionCode'][regionType='1']").attr("direction"),
|
||
protocol=$("input[name$='cfgRegionCode'][regionType='1']").attr("protocol"),
|
||
regionType=$("input[name$='cfgRegionCode'][regionType='1']").attr("regionType");
|
||
}
|
||
if(o){
|
||
//ip,端口处理源ip展示、源端口展示、目的ip展示、目的端口展示1、2、3、4
|
||
if(ipPortShow){
|
||
if(ipPortShow.indexOf('1')>-1){//展示源IP
|
||
$("input[name$='srcIpAddress']").parents(".form-group").removeClass("hidden");
|
||
$("select[name$='srcIpPattern']").parents(".form-group").removeClass("hidden");
|
||
}else{
|
||
$("input[name$='srcIpAddress']").parents(".form-group").addClass("hidden");
|
||
$("select[name$='srcIpPattern']").parents(".form-group").addClass("hidden");
|
||
}
|
||
if(ipPortShow.indexOf('2')>-1){//展示源端口
|
||
$("input[name$='srcPort']").parents(".form-group").removeClass("hidden");
|
||
$("select[name$='srcPortPattern']").parents(".form-group").removeClass("hidden");
|
||
}else{
|
||
$("input[name$='srcPort']").parents(".form-group").addClass("hidden");
|
||
$("select[name$='srcPortPattern']").parents(".form-group").addClass("hidden");
|
||
}
|
||
if(ipPortShow.indexOf('3')>-1){//展示目的IP
|
||
$("input[name$='destIpAddress']").parents(".form-group").removeClass("hidden");
|
||
$("select[name$='destIpPattern']").parents(".form-group").removeClass("hidden");
|
||
}else{
|
||
$("input[name$='destIpAddress']").parents(".form-group").addClass("hidden");
|
||
$("select[name$='destIpPattern']").parents(".form-group").addClass("hidden");
|
||
}
|
||
if(ipPortShow.indexOf('4')>-1){//展示目的端口
|
||
$("input[name$='destPort']").parents(".form-group").removeClass("hidden");
|
||
$("select[name$='destPortPattern']").parents(".form-group").removeClass("hidden");
|
||
}else{
|
||
$("input[name$='destPort']").parents(".form-group").addClass("hidden");
|
||
$("select[name$='destPortPattern']").parents(".form-group").addClass("hidden");
|
||
}
|
||
}
|
||
//ip类型处理
|
||
if(ipType){
|
||
var arr=ipType.split(',');
|
||
var ipTypeVal=o.find("select[name$='ipType'] option:selected").attr("value");
|
||
o.find("select[name$='ipType']").empty();
|
||
$.ipcommon.ipType.each(function(){
|
||
var has=false;
|
||
for(var type in arr){
|
||
if($(this).val()==arr[type]){
|
||
has=true;
|
||
o.find("select[name$='ipType']").append($(this));
|
||
break;
|
||
}
|
||
}
|
||
});
|
||
o.find("select[name$='ipType']").selectpicker("refresh");
|
||
if(o.find("select[name$='ipType'] option[value='"+ipTypeVal+"']").length>0){
|
||
o.find("select[name$='ipType']").selectpicker("val",ipTypeVal);
|
||
}else{
|
||
if(o.find("select[name$='ipType'] option[value=4]").length>0){
|
||
o.find("select[name$='ipType']").selectpicker("val",4);
|
||
}else{
|
||
o.find("select[name$='ipType']").get(0).selectedIndex=0;
|
||
o.find("select[name$='ipType']").selectpicker("refresh");
|
||
}
|
||
}
|
||
|
||
}
|
||
//源ip格式处理
|
||
changePattern(o,"srcIpPattern",srcIpPattern);
|
||
//目的ip格式处理
|
||
changePattern(o,"destIpPattern",destIpPattern);
|
||
//源端口格式处理
|
||
changePattern(o,"srcPortPattern",srcPortPattern);
|
||
//目的源端口格式处理
|
||
changePattern(o,"destPortPattern",destPortPattern);
|
||
//方向处理
|
||
if(direction){
|
||
arr=direction.split(',');
|
||
var directionVal=o.find("select[name$='direction'] option:selected").attr("value");
|
||
o.find("select[name$='direction']").empty();
|
||
$.ipcommon.direction.each(function(){
|
||
var has=false;
|
||
for(var type in arr){
|
||
if($(this).val()==arr[type]){
|
||
has=true;
|
||
o.find("select[name$='direction']").append($(this));
|
||
break;
|
||
}
|
||
}
|
||
});
|
||
o.find("select[name$='direction']").selectpicker("refresh");
|
||
if(o.find("select[name$='direction'] option[value='"+directionVal+"']").length>0){
|
||
o.find("select[name$='direction']").selectpicker("val",directionVal);
|
||
}else{
|
||
if(o.find("select[name$='direction'] option[value=0]").length>0){
|
||
o.find("select[name$='direction']").selectpicker("val",0);
|
||
}else{
|
||
o.find("select[name$='direction']").get(0).selectedIndex=0;
|
||
o.find("select[name$='direction']").selectpicker("refresh");
|
||
}
|
||
}
|
||
}
|
||
//协议处理
|
||
if(protocol){
|
||
arr=protocol.split(',');
|
||
var protocolVal=o.find("select[name$='protocol'] option:selected").attr("value");
|
||
o.find("select[name$='protocol']").empty();
|
||
$.ipcommon.protocol.each(function(){
|
||
var has=false;
|
||
for(var type in arr){
|
||
if($(this).val()==arr[type]){
|
||
has=true;
|
||
o.find("select[name$='protocol']").append($(this));
|
||
break;
|
||
}
|
||
}
|
||
});
|
||
o.find("select[name$='protocol']").selectpicker("refresh");
|
||
if(o.find("select[name$='protocol'] option[value='"+protocolVal+"']").length>0){
|
||
o.find("select[name$='protocol']").selectpicker("val",protocolVal);
|
||
}else{
|
||
if(o.find("select[name$='protocol'] option[value=0]").length>0){
|
||
o.find("select[name$='protocol']").selectpicker("val",0);
|
||
}else{
|
||
o.find("select[name$='protocol']").get(0).selectedIndex=0;
|
||
o.find("select[name$='protocol']").selectpicker("refresh");
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
//show more 添加更多属性
|
||
var more=function(obj){
|
||
var moreCols=$(obj).parents(".row").siblings(".ipCol").not(":hidden").last().nextAll(":hidden");
|
||
if(moreCols.length==0){
|
||
var clickTimes=$(obj).data("click-times");
|
||
if(clickTimes==0){
|
||
$(".port").removeClass("hidden").removeClass("disabled");
|
||
$(obj).data("click-times",clickTimes+1);
|
||
}
|
||
if(clickTimes==1){
|
||
$(".destPort").removeClass("hidden").removeClass("disabled");
|
||
$(obj).data("click-times",clickTimes+1);
|
||
}
|
||
if(clickTimes==2){
|
||
$(".protocol").removeClass("hidden").removeClass("disabled");
|
||
$(obj).data("click-times",clickTimes+1);
|
||
}
|
||
var rows=$(obj).parent(".row").siblings(".row:hidden");
|
||
if(rows.size()==0){
|
||
$(obj).addClass("hidden");
|
||
}
|
||
}else{
|
||
if(moreCols.length>0){
|
||
//$(moreCols[0]).removeClass("hidden").removeClass("disabled");
|
||
$(moreCols).each(function(i){
|
||
$(this).removeClass("hidden").removeClass("disabled");
|
||
if($(this).find("form-group:hidden").length>0){
|
||
return true;
|
||
}else{
|
||
return false;
|
||
}
|
||
});
|
||
if($(obj).parents(".row").siblings(".ipCol").not(":hidden").last().nextAll(":hidden").length==0){
|
||
$(obj).addClass("hidden");
|
||
}
|
||
}
|
||
}
|
||
} |