2018-01-10 21:56:30 +00:00
|
|
|
/*! Parser: network - updated 2018-01-10 (v2.29.3) */
|
2015-03-28 20:03:50 +00:00
|
|
|
/* IPv4, IPv6 and MAC Addresses */
|
2013-10-17 23:36:46 +00:00
|
|
|
/*global jQuery: false */
|
2018-03-17 20:30:25 +00:00
|
|
|
;(function($) {
|
2015-05-04 12:42:00 +00:00
|
|
|
'use strict';
|
2013-10-17 23:36:46 +00:00
|
|
|
|
2014-10-26 19:10:04 +00:00
|
|
|
var ts = $.tablesorter,
|
|
|
|
ipv4Format,
|
|
|
|
ipv4Is;
|
2013-10-17 23:36:46 +00:00
|
|
|
|
2015-03-28 20:03:50 +00:00
|
|
|
/*! IPv6 Address parser (WIP) *//*
|
2014-09-17 04:10:45 +00:00
|
|
|
* IPv6 Address (ffff:0000:0000:0000:0000:0000:0000:0000)
|
2015-05-04 12:42:00 +00:00
|
|
|
* needs to support short versions like '::8' or '1:2::7:8'
|
|
|
|
* and '::00:192.168.10.184' (embedded IPv4 address)
|
2014-09-17 04:10:45 +00:00
|
|
|
* see http://www.intermapper.com/support/tools/IPV6-Validator.aspx
|
|
|
|
*/
|
2013-10-17 23:36:46 +00:00
|
|
|
$.extend( ts.regex, {}, {
|
|
|
|
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})/,
|
|
|
|
ipv4Extract : /([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})/,
|
|
|
|
|
2015-03-28 20:03:50 +00:00
|
|
|
// simplified regex from http://www.intermapper.com/support/tools/IPV6-Validator.aspx
|
|
|
|
// (specifically from http://download.dartware.com/thirdparty/ipv6validator.js)
|
2013-10-17 23:36:46 +00:00
|
|
|
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
|
|
|
|
});
|
|
|
|
|
2018-01-10 21:56:30 +00:00
|
|
|
// used for internal testing; it's not useful to set this to true because the natural sort algorithm
|
|
|
|
// is set up to only sort solitary hex values ("ffff") vs separated hex values ("ffff.ffff")
|
|
|
|
ts.defaults.ipv6HexFormat = false;
|
|
|
|
|
2013-10-17 23:36:46 +00:00
|
|
|
ts.addParser({
|
2014-09-17 04:10:45 +00:00
|
|
|
id: 'ipv6Address',
|
2013-10-17 23:36:46 +00:00
|
|
|
is: function(s) {
|
|
|
|
return ts.regex.ipv6Validate.test(s);
|
|
|
|
},
|
|
|
|
format: function(address, table) {
|
2015-07-28 20:57:01 +00:00
|
|
|
// code modified from http://zurb.com/forrst/posts/JS_Expand_Abbreviated_IPv6_Addresses-1OR
|
|
|
|
// Saved to https://gist.github.com/Mottie/7018157
|
2013-10-17 23:36:46 +00:00
|
|
|
var i, t, sides, groups, groupsPresent,
|
2014-09-17 04:10:45 +00:00
|
|
|
hex = table ? (typeof table === 'boolean' ? table : table && table.config.ipv6HexFormat || false) : false,
|
2013-10-17 23:36:46 +00:00
|
|
|
fullAddress = '',
|
|
|
|
expandedAddress = '',
|
2015-07-28 20:57:01 +00:00
|
|
|
validGroupCount = 8;
|
|
|
|
// validGroupSize = 4; <- removed while loop
|
2013-10-17 23:36:46 +00:00
|
|
|
// remove any extra spaces
|
|
|
|
address = address.replace(/\s*/g, '');
|
|
|
|
// look for embedded ipv4
|
|
|
|
if (ts.regex.ipv4Validate.test(address)) {
|
|
|
|
groups = address.match(ts.regex.ipv4Extract);
|
|
|
|
t = '';
|
2018-03-17 20:30:25 +00:00
|
|
|
for (i = 1; i < groups.length; i++) {
|
2013-10-17 23:36:46 +00:00
|
|
|
t += ('00' + (parseInt(groups[i], 10).toString(16)) ).slice(-2) + ( i === 2 ? ':' : '' );
|
|
|
|
}
|
|
|
|
address = address.replace( ts.regex.ipv4Extract, t );
|
|
|
|
}
|
|
|
|
|
2018-03-17 20:30:25 +00:00
|
|
|
if (address.indexOf('::') === -1) {
|
2013-10-17 23:36:46 +00:00
|
|
|
// All eight groups are present
|
|
|
|
fullAddress = address;
|
|
|
|
} else {
|
2014-09-17 04:10:45 +00:00
|
|
|
// Consecutive groups of zeroes have been collapsed with '::'.
|
|
|
|
sides = address.split('::');
|
2013-10-17 23:36:46 +00:00
|
|
|
groupsPresent = 0;
|
|
|
|
for (i = 0; i < sides.length; i++) {
|
2014-09-17 04:10:45 +00:00
|
|
|
groupsPresent += sides[i].split(':').length;
|
2013-10-17 23:36:46 +00:00
|
|
|
}
|
2014-09-17 04:10:45 +00:00
|
|
|
fullAddress += sides[0] + ':';
|
2013-10-17 23:36:46 +00:00
|
|
|
for (i = 0; i < validGroupCount - groupsPresent; i++) {
|
2014-09-17 04:10:45 +00:00
|
|
|
fullAddress += '0000:';
|
2013-10-17 23:36:46 +00:00
|
|
|
}
|
|
|
|
fullAddress += sides[1];
|
|
|
|
}
|
2014-09-17 04:10:45 +00:00
|
|
|
groups = fullAddress.split(':');
|
2013-10-17 23:36:46 +00:00
|
|
|
for (i = 0; i < validGroupCount; i++) {
|
|
|
|
// it's fastest & easiest for tablesorter to sort decimal values (vs hex)
|
|
|
|
groups[i] = hex ? ('0000' + groups[i]).slice(-4) :
|
|
|
|
('00000' + (parseInt(groups[i], 16) || 0)).slice(-5);
|
2018-03-17 20:30:25 +00:00
|
|
|
expandedAddress += ( i !== validGroupCount - 1) ? groups[i] + ':' : groups[i];
|
2013-10-17 23:36:46 +00:00
|
|
|
}
|
2018-01-10 21:56:30 +00:00
|
|
|
return expandedAddress;
|
2013-10-17 23:36:46 +00:00
|
|
|
},
|
|
|
|
// uses natural sort hex compare
|
2018-01-10 21:56:30 +00:00
|
|
|
type: 'text'
|
2014-09-17 04:10:45 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// ipv4 address
|
|
|
|
// moved here from jquery.tablesorter.js (core file)
|
2014-10-26 19:10:04 +00:00
|
|
|
ipv4Is = function(s) {
|
|
|
|
return (/^\d{1,3}[\.]\d{1,3}[\.]\d{1,3}[\.]\d{1,3}$/).test(s);
|
|
|
|
};
|
2018-01-10 21:56:30 +00:00
|
|
|
ipv4Format = function(s) {
|
|
|
|
var i,
|
|
|
|
a = s ? s.split('.') : '',
|
|
|
|
r = [],
|
2015-03-28 20:03:50 +00:00
|
|
|
l = a.length;
|
2014-10-26 19:10:04 +00:00
|
|
|
for (i = 0; i < l; i++) {
|
2018-01-10 21:56:30 +00:00
|
|
|
r.push(('000' + a[i]).slice(-3));
|
2014-10-26 19:10:04 +00:00
|
|
|
}
|
2018-01-10 21:56:30 +00:00
|
|
|
return s ? r.join('.') : s;
|
2014-10-26 19:10:04 +00:00
|
|
|
};
|
|
|
|
|
2015-03-28 20:03:50 +00:00
|
|
|
/*! Parser: ipv4Address (a.k.a. ipAddress) */
|
2015-05-04 12:42:00 +00:00
|
|
|
// duplicate 'ipAddress' as 'ipv4Address' (to maintain backwards compatility)
|
2014-09-17 04:10:45 +00:00
|
|
|
ts.addParser({
|
|
|
|
id: 'ipAddress',
|
2014-10-26 19:10:04 +00:00
|
|
|
is: ipv4Is,
|
|
|
|
format: ipv4Format,
|
2018-01-10 21:56:30 +00:00
|
|
|
type: 'text'
|
2014-10-26 19:10:04 +00:00
|
|
|
});
|
|
|
|
ts.addParser({
|
|
|
|
id: 'ipv4Address',
|
|
|
|
is: ipv4Is,
|
|
|
|
format: ipv4Format,
|
2018-01-10 21:56:30 +00:00
|
|
|
type: 'text'
|
2014-09-17 04:10:45 +00:00
|
|
|
});
|
|
|
|
|
2015-03-28 20:03:50 +00:00
|
|
|
/*! Parser: MAC address */
|
2015-05-04 12:42:00 +00:00
|
|
|
/* MAC examples: 12:34:56:78:9A:BC, 1234.5678.9ABC, 12-34-56-78-9A-BC, and 123456789ABC
|
|
|
|
*/
|
2014-09-17 04:10:45 +00:00
|
|
|
ts.addParser({
|
2015-05-04 12:42:00 +00:00
|
|
|
id : 'MAC',
|
2015-07-28 20:57:01 +00:00
|
|
|
is : function() {
|
2015-05-04 12:46:39 +00:00
|
|
|
return false;
|
2014-09-17 04:10:45 +00:00
|
|
|
},
|
2015-05-04 12:42:00 +00:00
|
|
|
format : function( str ) {
|
|
|
|
var indx, len,
|
2018-01-10 21:56:30 +00:00
|
|
|
mac = [],
|
2015-05-04 12:42:00 +00:00
|
|
|
val = ( str || '' ).replace( /[:.-]/g, '' ).match( /\w{2}/g );
|
|
|
|
if ( val ) {
|
|
|
|
// not assuming all mac addresses in the column will end up with six
|
|
|
|
// groups of two to process, so it's not actually validating the address
|
|
|
|
len = val.length;
|
|
|
|
for ( indx = 0; indx < len; indx++ ) {
|
2018-01-10 21:56:30 +00:00
|
|
|
mac.push(( '000' + parseInt( val[ indx ], 16 ) ).slice( -3 ));
|
2015-05-04 12:42:00 +00:00
|
|
|
}
|
2018-01-10 21:56:30 +00:00
|
|
|
return mac.join('.');
|
2015-05-04 12:42:00 +00:00
|
|
|
}
|
|
|
|
return str;
|
2014-09-17 04:10:45 +00:00
|
|
|
},
|
|
|
|
// uses natural sort hex compare
|
2018-01-10 21:56:30 +00:00
|
|
|
type : 'text'
|
2013-10-17 23:36:46 +00:00
|
|
|
});
|
|
|
|
|
2015-05-04 12:42:00 +00:00
|
|
|
})( jQuery );
|