| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
;(function($) { |
| 5 |
'use strict'; |
| 6 |
|
| 7 |
var ts = $.tablesorter, |
| 8 |
ipv4Format, |
| 9 |
ipv4Is; |
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
$.extend( ts.regex, {}, { |
| 18 |
ipv4Validate : /((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})/, |
| 19 |
ipv4Extract : /([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})/, |
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
ipv6Validate : /^\s*((([0-9a-f]{1,4}:){7}([0-9a-f]{1,4}|:))|(([0-9a-f]{1,4}:){6}(:[0-9a-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9a-f]{1,4}:){5}(((:[0-9a-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9a-f]{1,4}:){4}(((:[0-9a-f]{1,4}){1,3})|((:[0-9a-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){3}(((:[0-9a-f]{1,4}){1,4})|((:[0-9a-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){2}(((:[0-9a-f]{1,4}){1,5})|((:[0-9a-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){1}(((:[0-9a-f]{1,4}){1,6})|((:[0-9a-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9a-f]{1,4}){1,7})|((:[0-9a-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(%.+)?\s*$/i |
| 24 |
}); |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
ts.defaults.ipv6HexFormat = false; |
| 29 |
|
| 30 |
ts.addParser({ |
| 31 |
id: 'ipv6Address', |
| 32 |
is: function(s) { |
| 33 |
return ts.regex.ipv6Validate.test(s); |
| 34 |
}, |
| 35 |
format: function(address, table) { |
| 36 |
|
| 37 |
|
| 38 |
var i, t, sides, groups, groupsPresent, |
| 39 |
hex = table ? (typeof table === 'boolean' ? table : table && table.config.ipv6HexFormat || false) : false, |
| 40 |
fullAddress = '', |
| 41 |
expandedAddress = '', |
| 42 |
validGroupCount = 8; |
| 43 |
|
| 44 |
|
| 45 |
address = address.replace(/\s*/g, ''); |
| 46 |
|
| 47 |
if (ts.regex.ipv4Validate.test(address)) { |
| 48 |
groups = address.match(ts.regex.ipv4Extract); |
| 49 |
t = ''; |
| 50 |
for (i = 1; i < groups.length; i++) { |
| 51 |
t += ('00' + (parseInt(groups[i], 10).toString(16)) ).slice(-2) + ( i === 2 ? ':' : '' ); |
| 52 |
} |
| 53 |
address = address.replace( ts.regex.ipv4Extract, t ); |
| 54 |
} |
| 55 |
|
| 56 |
if (address.indexOf('::') === -1) { |
| 57 |
|
| 58 |
fullAddress = address; |
| 59 |
} else { |
| 60 |
|
| 61 |
sides = address.split('::'); |
| 62 |
groupsPresent = 0; |
| 63 |
for (i = 0; i < sides.length; i++) { |
| 64 |
groupsPresent += sides[i].split(':').length; |
| 65 |
} |
| 66 |
fullAddress += sides[0] + ':'; |
| 67 |
for (i = 0; i < validGroupCount - groupsPresent; i++) { |
| 68 |
fullAddress += '0000:'; |
| 69 |
} |
| 70 |
fullAddress += sides[1]; |
| 71 |
} |
| 72 |
groups = fullAddress.split(':'); |
| 73 |
for (i = 0; i < validGroupCount; i++) { |
| 74 |
|
| 75 |
groups[i] = hex ? ('0000' + groups[i]).slice(-4) : |
| 76 |
('00000' + (parseInt(groups[i], 16) || 0)).slice(-5); |
| 77 |
expandedAddress += ( i !== validGroupCount - 1) ? groups[i] + ':' : groups[i]; |
| 78 |
} |
| 79 |
return expandedAddress; |
| 80 |
}, |
| 81 |
|
| 82 |
type: 'text' |
| 83 |
}); |
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
ipv4Is = function(s) { |
| 88 |
return (/^\d{1,3}[\.]\d{1,3}[\.]\d{1,3}[\.]\d{1,3}$/).test(s); |
| 89 |
}; |
| 90 |
ipv4Format = function(s) { |
| 91 |
var i, |
| 92 |
a = s ? s.split('.') : '', |
| 93 |
r = [], |
| 94 |
l = a.length; |
| 95 |
for (i = 0; i < l; i++) { |
| 96 |
r.push(('000' + a[i]).slice(-3)); |
| 97 |
} |
| 98 |
return s ? r.join('.') : s; |
| 99 |
}; |
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
ts.addParser({ |
| 104 |
id: 'ipAddress', |
| 105 |
is: ipv4Is, |
| 106 |
format: ipv4Format, |
| 107 |
type: 'text' |
| 108 |
}); |
| 109 |
ts.addParser({ |
| 110 |
id: 'ipv4Address', |
| 111 |
is: ipv4Is, |
| 112 |
format: ipv4Format, |
| 113 |
type: 'text' |
| 114 |
}); |
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
ts.addParser({ |
| 120 |
id : 'MAC', |
| 121 |
is : function() { |
| 122 |
return false; |
| 123 |
}, |
| 124 |
format : function( str ) { |
| 125 |
var indx, len, |
| 126 |
mac = [], |
| 127 |
val = ( str || '' ).replace( /[:.-]/g, '' ).match( /\w{2}/g ); |
| 128 |
if ( val ) { |
| 129 |
|
| 130 |
|
| 131 |
len = val.length; |
| 132 |
for ( indx = 0; indx < len; indx++ ) { |
| 133 |
mac.push(( '000' + parseInt( val[ indx ], 16 ) ).slice( -3 )); |
| 134 |
} |
| 135 |
return mac.join('.'); |
| 136 |
} |
| 137 |
return str; |
| 138 |
}, |
| 139 |
|
| 140 |
type : 'text' |
| 141 |
}); |
| 142 |
|
| 143 |
})( jQuery ); |