Commit c81d3133 authored by Xavier Guimard's avatar Xavier Guimard

IPv6 works for session explorer (#1201)

parent f076e2ec
......@@ -45,7 +45,7 @@ foreach my $i ( 1 .. COUNT() ) {
$min = int( rand(60) );
$sec = int( rand(60) );
my $ipAddr = (
int( rand(2) ) == 1
int( rand(2) ) == 2
? join( '.',
int( rand(256) ),
int( rand(256) ),
......
......@@ -6,7 +6,7 @@ use base 'Exporter';
sub isIPv6 {
my($ip) = @_;
return $ip =~ /^[0-9:]+$/;
return $ip =~ /^[a-z0-9:]+$/i;
}
sub net6 {
......
......@@ -106,20 +106,25 @@ sub sessions {
@fields = grep { !$seen{$_}++ } @fields;
}
# Check if a '*' is required
my $function = 'searchOn';
$function = 'searchOnExpr' if ( grep /\*/, values %filters );
# For now, only one argument can be passed to
# Lemonldap::NG::Common::Apache::Session so just the first filter is
# used
my ($firstFilter) = sort {
$a eq '_session_kind' ? 1
: $b eq '_session_kind' ? -1
$filters{$a} =~ m#^[\w:]+/\d+\*?$# ? 1
: $filters{$b} =~ m#^[\w:]+/\d+\*?$# ? -1
: $a eq '_session_kind' ? 1
: $b eq '_session_kind' ? -1
: $a cmp $b
} keys %filters;
# Check if a '*' is required
my $function = 'searchOn';
$function = 'searchOnExpr'
if ( grep { /\*/ and not m#^[\w:]+/\d+\*?$# }
( $filters{$firstFilter} ) );
$self->logger->debug(
"First filter: $firstFilter = $filters{$firstFilter} ($function)");
$res =
Lemonldap::NG::Common::Apache::Session->$function( $moduleOptions,
$firstFilter, $filters{$firstFilter}, @fields );
......@@ -134,15 +139,26 @@ sub sessions {
}
) unless ( $res and %$res );
delete $filters{$firstFilter};
delete $filters{$firstFilter}
unless ( grep { /\*/ and not m#^[\w:]+/\d+\*?$# }
( $filters{$firstFilter} ) );
foreach my $k ( keys %filters ) {
$self->logger->debug("Removing unless $k =~ /^$filters{$k}\$/");
$filters{$k} =~ s/\./\\./g;
$filters{$k} =~ s/\*/\.\*/g;
foreach my $session ( keys %$res ) {
if ( $res->{$session}->{$k} ) {
if ( $filters{$k} =~ m#^([\w:]+)/(\d+)\*?$# ) {
my ( $net, $bits ) = ( $1, $2 );
foreach my $session ( keys %$res ) {
delete $res->{$session}
unless ( $res->{$session}->{$k} =~ /^$filters{$k}$/ );
unless ( net6( $res->{$session}->{$k}, $bits ) eq $net );
}
}
else {
$filters{$k} =~ s/\./\\./g;
$filters{$k} =~ s/\*/\.\*/g;
foreach my $session ( keys %$res ) {
if ( $res->{$session}->{$k} ) {
delete $res->{$session}
unless ( $res->{$session}->{$k} =~ /^$filters{$k}$/ );
}
}
}
}
......@@ -236,7 +252,7 @@ sub sessions {
my $field = $1;
my $bits = $2;
foreach my $k ( keys %$res ) {
$r->{ net6( $res->{$k}->{$field}, $bits ) }++
$r->{ net6( $res->{$k}->{$field}, $bits ) . "/$bits" }++
if ( isIPv6( $res->{$k}->{$field} ) );
}
}
......@@ -244,11 +260,11 @@ sub sessions {
# Both IPv4 and IPv6
elsif ( $group =~ /^net\(([\w:]+),(\d+),(\d+)\)$/ ) {
my $field = $1;
my $bits = $3;
my $bits = $2;
my $nb = $3 - 1;
foreach my $k ( keys %$res ) {
if ( isIPv6( $res->{$k}->{$field} ) ) {
$r->{ net6( $res->{$k}->{$field}, $bits ) }++;
$r->{ net6( $res->{$k}->{$field}, $bits ) . "/$bits" }++;
}
elsif ( $res->{$k}->{$field} =~ /^((((\d+)\.\d+)\.\d+)\.\d+)$/ )
{
......
......@@ -20,11 +20,14 @@ schemes =
(t,v) ->
"groupBy=net(#{t},16,1)"
(t,v) ->
"#{t}=#{v}.*&groupBy=net(#{t},32,2)"
v = v + '.' unless v.match /:/
"#{t}=#{v}*&groupBy=net(#{t},32,2)"
(t,v) ->
"#{t}=#{v}.*&groupBy=net(#{t},48,3)"
v = v + '.' unless v.match /:/
"#{t}=#{v}*&groupBy=net(#{t},48,3)"
(t,v) ->
"#{t}=#{v}.*&groupBy=net(#{t},128,4)"
v = v + '.' unless v.match /:/
"#{t}=#{v}*&groupBy=net(#{t},128,4)"
(t,v) ->
"#{t}=#{v}&groupBy=_whatToTrace"
(t,v,q) ->
......@@ -61,7 +64,12 @@ overScheme =
if level == 1
"#{t}=#{v}*&groupBy=substr(#{t},#{(level+over)})"
else
schemes._whatToTrace[level]
null
ipAddr: (t,v,level,over) ->
if level > 0 and level < 4
"#{t}=#{v}*&groupBy=net(#{t},#{16*level+4*(over+1)},2)"
else
null
hiddenAttributes = '_password'
......@@ -306,9 +314,12 @@ llapp.controller 'SessionsExplorerCtrl', ['$scope', '$translator', '$location',
# If number of session exceeds "max" and overScheme exists, call it
if count > max and overScheme[$scope.type]
over++
query = overScheme[$scope.type] $scope.type, value, level, over, currentQuery
level = level - 1
if tmp = overScheme[$scope.type] $scope.type, value, level, over, currentQuery
over++
query = tmp
level = level - 1
else
over = 0
else
over = 0
......
......@@ -23,11 +23,20 @@
function(t, v) {
return "groupBy=net(" + t + ",16,1)";
}, function(t, v) {
return t + "=" + v + ".*&groupBy=net(" + t + ",32,2)";
if (!v.match(/:/)) {
v = v + '.';
}
return t + "=" + v + "*&groupBy=net(" + t + ",32,2)";
}, function(t, v) {
return t + "=" + v + ".*&groupBy=net(" + t + ",48,3)";
if (!v.match(/:/)) {
v = v + '.';
}
return t + "=" + v + "*&groupBy=net(" + t + ",48,3)";
}, function(t, v) {
return t + "=" + v + ".*&groupBy=net(" + t + ",128,4)";
if (!v.match(/:/)) {
v = v + '.';
}
return t + "=" + v + "*&groupBy=net(" + t + ",128,4)";
}, function(t, v) {
return t + "=" + v + "&groupBy=_whatToTrace";
}, function(t, v, q) {
......@@ -68,7 +77,14 @@
if (level === 1) {
return t + "=" + v + "*&groupBy=substr(" + t + "," + (level + over) + ")";
} else {
return schemes._whatToTrace[level];
return null;
}
},
ipAddr: function(t, v, level, over) {
if (level > 0 && level < 4) {
return t + "=" + v + "*&groupBy=net(" + t + "," + (16 * level + 4 * (over + 1)) + ",2)";
} else {
return null;
}
}
};
......@@ -333,17 +349,22 @@
$scope.$on('$locationChangeSuccess', pathEvent);
autoId = 0;
$scope.updateTree = function(value, node, level, over, currentQuery, count) {
var query, scheme;
var query, scheme, tmp;
$scope.waiting = true;
scheme = schemes[$scope.type] ? schemes[$scope.type] : $scope.type === 'updateTime' ? schemes.startTime : schemes._whatToTrace;
query = scheme[level]($scope.type, value, currentQuery);
if (count > max && overScheme[$scope.type]) {
over++;
query = overScheme[$scope.type]($scope.type, value, level, over, currentQuery);
level = level - 1;
if (tmp = overScheme[$scope.type]($scope.type, value, level, over, currentQuery)) {
over++;
query = tmp;
level = level - 1;
} else {
over = 0;
}
} else {
over = 0;
}
console.log(query);
return $http.get(scriptname + "sessions/" + sessionType + "?" + query).then(function(response) {
var data, i, len, n, ref;
data = response.data;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment