mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-07 05:31:22 +00:00
GUAC-1138: Filter columns based on network address, if they appear to contain network addresses.
This commit is contained in:
@@ -28,6 +28,8 @@ angular.module('list').factory('FilterPattern', ['$injector',
|
|||||||
|
|
||||||
// Required types
|
// Required types
|
||||||
var FilterToken = $injector.get('FilterToken');
|
var FilterToken = $injector.get('FilterToken');
|
||||||
|
var IPv4Network = $injector.get('IPv4Network');
|
||||||
|
var IPv6Network = $injector.get('IPv6Network');
|
||||||
|
|
||||||
// Required services
|
// Required services
|
||||||
var $parse = $injector.get('$parse');
|
var $parse = $injector.get('$parse');
|
||||||
@@ -75,6 +77,99 @@ angular.module('list').factory('FilterPattern', ['$injector',
|
|||||||
getters.push($parse(expression));
|
getters.push($parse(expression));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines whether the given object contains properties that match
|
||||||
|
* the given string, according to the provided getters.
|
||||||
|
*
|
||||||
|
* @param {Object} object
|
||||||
|
* The object to match against.
|
||||||
|
*
|
||||||
|
* @param {String} str
|
||||||
|
* The string to match.
|
||||||
|
*
|
||||||
|
* @returns {Boolean}
|
||||||
|
* true if the object matches the given string, false otherwise.
|
||||||
|
*/
|
||||||
|
var matchesString = function matchesString(object, str) {
|
||||||
|
|
||||||
|
// For each defined getter
|
||||||
|
for (var i=0; i < getters.length; i++) {
|
||||||
|
|
||||||
|
// Retrieve value of current getter
|
||||||
|
var value = getters[i](object);
|
||||||
|
|
||||||
|
// If the value matches the pattern, the whole object matches
|
||||||
|
if (String(value).toLowerCase().indexOf(str) !== -1)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// No matches found
|
||||||
|
return false;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines whether the given object contains properties that match
|
||||||
|
* the given IPv4 network, according to the provided getters.
|
||||||
|
*
|
||||||
|
* @param {Object} object
|
||||||
|
* The object to match against.
|
||||||
|
*
|
||||||
|
* @param {IPv4Network} network
|
||||||
|
* The IPv4 network to match.
|
||||||
|
*
|
||||||
|
* @returns {Boolean}
|
||||||
|
* true if the object matches the given network, false otherwise.
|
||||||
|
*/
|
||||||
|
var matchesIPv4 = function matchesIPv4(object, network) {
|
||||||
|
|
||||||
|
// For each defined getter
|
||||||
|
for (var i=0; i < getters.length; i++) {
|
||||||
|
|
||||||
|
// Test value against IPv4 network
|
||||||
|
var value = IPv4Network.parse(String(getters[i](object)));
|
||||||
|
if (value && network.contains(value))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// No matches found
|
||||||
|
return false;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines whether the given object contains properties that match
|
||||||
|
* the given IPv6 network, according to the provided getters.
|
||||||
|
*
|
||||||
|
* @param {Object} object
|
||||||
|
* The object to match against.
|
||||||
|
*
|
||||||
|
* @param {IPv6Network} network
|
||||||
|
* The IPv6 network to match.
|
||||||
|
*
|
||||||
|
* @returns {Boolean}
|
||||||
|
* true if the object matches the given network, false otherwise.
|
||||||
|
*/
|
||||||
|
var matchesIPv6 = function matchesIPv6(object, network) {
|
||||||
|
|
||||||
|
// For each defined getter
|
||||||
|
for (var i=0; i < getters.length; i++) {
|
||||||
|
|
||||||
|
// Test value against IPv6 network
|
||||||
|
var value = IPv6Network.parse(String(getters[i](object)));
|
||||||
|
if (value && network.contains(value))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// No matches found
|
||||||
|
return false;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines whether the given object matches the given filter pattern
|
* Determines whether the given object matches the given filter pattern
|
||||||
* token.
|
* token.
|
||||||
@@ -89,27 +184,29 @@ angular.module('list').factory('FilterPattern', ['$injector',
|
|||||||
* @returns {Boolean}
|
* @returns {Boolean}
|
||||||
* true if the object matches the token, false otherwise.
|
* true if the object matches the token, false otherwise.
|
||||||
*/
|
*/
|
||||||
var matchesToken = function matchToken(object, token) {
|
var matchesToken = function matchesToken(object, token) {
|
||||||
|
|
||||||
// Only match against literals
|
// Match depending on token type
|
||||||
if (token.type !== 'LITERAL')
|
switch (token.type) {
|
||||||
return false;
|
|
||||||
|
|
||||||
// For each defined getter
|
// Simple string literal
|
||||||
for (var i=0; i < getters.length; i++) {
|
case 'LITERAL':
|
||||||
|
return matchesString(object, token.value);
|
||||||
|
|
||||||
// Retrieve value of current getter
|
// IPv4 network address / subnet
|
||||||
var value = getters[i](object);
|
case 'IPV4_NETWORK':
|
||||||
|
return matchesIPv4(object, token.value);
|
||||||
|
|
||||||
// If the value matches the pattern, the whole object matches
|
// IPv6 network address / subnet
|
||||||
if (String(value).toLowerCase().indexOf(token.value) !== -1)
|
case 'IPV6_NETWORK':
|
||||||
return true;
|
return matchesIPv6(object, token.value);
|
||||||
|
|
||||||
|
// Unsupported token type
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// No matches found
|
|
||||||
return false;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user