日期:2014-05-16 浏览次数:20320 次
/** * IP自动联想 * * @param input IP * @return IP/Task */ function getIpArray(input){ var ipArray = input.split('.'); for( var i = 0; i < 4; i++){ if (ipArray[i] == undefined || ipArray[i] == ''){ ipArray[i] = 0; } // // if(ipArray[i].indexOf('0') == 0 && ipArray[i].length > 1){ // ipArray[i] = ipArray[i].substring(1, ipArray[i].length); // } } return ipArray; } function every(arr, func){ var aa = []; for( var i = 0; i < arr.length; i++){ aa.push(func(arr[i])); } return aa; } function indexOfEnd(str){ for( var i = str.length - 1; i >= 0; i--){ if (str.charAt(i) == '1') { return 8 - (str.length - i) + 1; } } return 0; } function getPermissions(input){ var ipArray = getIpArray(input); var ip = ipArray.join('.'); var binaryIpArray = every(ipArray, function(oct){ return Number(oct).toString(2); }); var yanma = 0; for( var i = binaryIpArray.length - 1; i >= 0; i--){ if(binaryIpArray[i] != 0){ yanma = indexOfEnd(binaryIpArray[i]) + i * 8; break; } } var abc = [ 8, 16, 24, 32 ]; var rstArray = [ ip + '/' + yanma ]; for( var i = 0; i < abc.length; i++){ if(abc[i] > yanma){ rstArray.push(ip + '/' + abc[i]); } } return rstArray; }
/** * 创建安全组自动联想DOM */ function createSgDom(input){ var arrayObj = new Array(); var ary = new Array(); this.setNewAry([]); this.setAry([]); var autoData = jsonData.substring(1, jsonData.length -1).split(', '); for ( var element in autoData) { arrayObj.push(autoData[element]); } var permissions = /^((?:(?:25[0-5]|2[0-4]\d|((1\d{2})|([1-9]?\d)))\.){3}(?:25[0-5]|2[0-4]\d|((1\d{2})|([1-9]?\d))))$/; var ip_1 = /^((?:(?:25[0-5]|2[0-4]\d|((1\d{2})|([1-9]?\d)))[\.]?){1,3})$/; var str = /^[a-zA-Z]*([a-zA-Z]|[-])*$/; if(null != input && !str.test(input)){ if(ip_1.test(input) || permissions.test(input)){ var except = false; if(input.indexOf('.') > -1){ var value = input.split('.'); for(var val in value){ var inVal = value[val]; if(inVal.indexOf('0') == 0 && inVal.length > 1){ except = true; } if(inVal>255){ except = true; } } } else { if(input>255){ except = true; } } if(!except){ var ips = getPermissions(input); for(var ip in ips){ ary.push(ips[ip]); } } } } if(ary != null){ newAry = arrayObj.concat(ary); } else { newAry = arrayObj; } this.setNewAry(newAry); $('#suggest_value').autocomplete({ source: this.getNewAry(), minLength: 0, close: function(event, ui){ }, focus: function(event, ui){ return false; }, change: function(event, ui){ }, select: function(event, ui){