Commit 8c4ead48 authored by Yadd's avatar Yadd
Browse files

Split queries when number of sessions id too big (closes: #1171)

parent a6bc1cbc
#!/usr/bin/perl
package Test::Request;
use Mouse;
has userData => ( is => 'rw' );
has sessionInfo => ( is => 'rw' );
has id => ( is => 'rw' );
package main;
use Test::More;
use strict;
use lib 'lemonldap-ng-common/blib/lib';
use lib 'lemonldap-ng-handler/blib/lib';
use lib 'lemonldap-ng-portal/blib/lib';
use lib 'lemonldap-ng-manager/blib/lib';
require './lemonldap-ng-portal/t/test-lib.pm';
my $portal = LLNG::Manager::Test->new(
{
ini => {
configStorage => {
type => 'File',
dirName => 'e2e-tests/conf',
},
}
}
)->p;
my @chars = ( "A" .. "Z", "a" .. "z" );
foreach my $i ( 1 .. 100000 ) {
my $string;
$string .= $chars[ rand @chars ] for 1 .. 8;
my $req = Test::Request->new(
{
sessionInfo => {
_user => $string,
uid => $string,
cn => uc($string),
sn => $string,
mail => "$string\@badwolf.org",
}
}
);
$portal->setMacros($req);
$portal->store($req);
}
done_testing( count() );
......@@ -2,6 +2,9 @@
# Session explorer
###
# Max number of session to display (see overScheme)
max = 25
# Queries to do each type of display: each array item corresponds to the depth
# of opened nodes in the tree
schemes =
......@@ -50,6 +53,13 @@ schemes =
q.replace(/\&groupBy.*$/, '') + "&ipAddr=#{v}"
]
overScheme =
_whatToTrace: (t,v,l) ->
if level == 1
"#{t}=#{v}*&groupBy=substr(#{t},#{l})"
else
schemes._whatToTrace[level]
hiddenAttributes = '_password'
# Attributes to group in session display
......@@ -133,7 +143,7 @@ llapp.controller 'SessionsExplorerCtrl', ['$scope', '$translator', '$location',
$scope.stoggle = (scope) ->
node = scope.$modelValue
if node.nodes.length == 0
$scope.updateTree node.value, node.nodes, node.level, node.query
$scope.updateTree node.value, node.nodes, node.level, node.over, node.query
scope.toggle()
# Display selected session
......@@ -271,7 +281,7 @@ llapp.controller 'SessionsExplorerCtrl', ['$scope', '$translator', '$location',
# Function to update tree: download value of opened subkey
autoId = 0
$scope.updateTree = (value, node, level, currentQuery) ->
$scope.updateTree = (value, node, level, over, currentQuery) ->
$scope.waiting = true
# Query scheme selection:
......@@ -291,6 +301,14 @@ llapp.controller 'SessionsExplorerCtrl', ['$scope', '$translator', '$location',
# Build query using schemes
query = scheme[level] $scope.type, value, currentQuery
# 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
else
over = 0
# Launch HTTP query
$http.get("#{scriptname}sessions/#{sessionType}?#{query}").then (response) ->
data = response.data
......@@ -302,6 +320,7 @@ llapp.controller 'SessionsExplorerCtrl', ['$scope', '$translator', '$location',
n.nodes = []
n.level = level + 1
n.query = query
n.over = over
# Date display in tree
if $scope.type.match /^(?:start|update)Time$/
......@@ -328,7 +347,7 @@ llapp.controller 'SessionsExplorerCtrl', ['$scope', '$translator', '$location',
$scope.data = []
$q.all [
$translator.init $scope.lang
$scope.updateTree '', $scope.data, 0
$scope.updateTree '', $scope.data, 0, 0
]
.then ->
$scope.waiting = false
......
......@@ -7,6 +7,14 @@
(function() {
var categories, hiddenAttributes, llapp, menu, schemes;
var toMuch = {
_whatToTrace: function(t, v, level, over) {
if(level===1) {
return t + "=" + v + "*&groupBy=substr(" + t + "," + (level+over) + ")";
}
return schemes._whatToTrace[level];
}
};
schemes = {
_whatToTrace: [
function(t, v) {
......@@ -147,7 +155,7 @@
var node;
node = scope.$modelValue;
if (node.nodes.length === 0) {
$scope.updateTree(node.value, node.nodes, node.level, node.query);
$scope.updateTree(node.value, node.nodes, node.level, node.over, node.query, node.count);
}
return scope.toggle();
};
......@@ -317,11 +325,19 @@
};
$scope.$on('$locationChangeSuccess', pathEvent);
autoId = 0;
$scope.updateTree = function(value, node, level, currentQuery) {
$scope.updateTree = function(value, node, level, over, currentQuery, count) {
var query, scheme;
$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 > 20 && toMuch[$scope.type]) {
over++;
query = toMuch[$scope.type]($scope.type, value, level, over, currentQuery);
level = level-1;
}
else {
over=0;
}
return $http.get(scriptname + "sessions/" + sessionType + "?" + query).then(function(response) {
var data, i, len, n, ref;
data = response.data;
......@@ -334,6 +350,7 @@
if (level < scheme.length - 1) {
n.nodes = [];
n.level = level + 1;
n.over = over;
n.query = query;
if ($scope.type.match(/^(?:start|update)Time$/)) {
n.title = n.value.replace(/^(\d{8})(\d{2})(\d{2})$/, '$2:$3').replace(/^(\d{8})(\d{2})(\d)$/, '$2:$30').replace(/^(\d{8})(\d{2})$/, '$2h').replace(/^(\d{4})(\d{2})(\d{2})/, '$1-$2-$3');
......@@ -353,7 +370,7 @@
$scope.init = function() {
$scope.waiting = true;
$scope.data = [];
return $q.all([$translator.init($scope.lang), $scope.updateTree('', $scope.data, 0)]).then(function() {
return $q.all([$translator.init($scope.lang), $scope.updateTree('', $scope.data, 0, 0)]).then(function() {
return $scope.waiting = false;
}, function(resp) {
return $scope.waiting = false;
......
(function(){var b,d,c,e,a;a={_whatToTrace:[function(g,f){return"groupBy=substr("+g+",1)"},function(g,f){return g+"="+f+"*&groupBy="+g},function(g,f){return g+"="+f}],ipAddr:[function(g,f){return g+"="+f+"*&groupBy=net4("+g+",1)"},function(g,f){return g+"="+f+"*&groupBy=net4("+g+",2)"},function(g,f){return g+"="+f+"*&groupBy=net4("+g+",3)"},function(g,f){return g+"="+f+"&groupBy=net4("+g+",4)"},function(g,f){return g+"="+f+"&groupBy=_whatToTrace"},function(g,f,h){return h.replace(/\&groupBy.*$/,"")+("&_whatToTrace="+f)}],startTime:[function(g,f){return"groupBy=substr("+g+",8)"},function(g,f){return"groupBy=substr("+g+",10)"},function(g,f){return"groupBy=substr("+g+",11)"},function(g,f){return"groupBy=substr("+g+",12)"},function(g,f){return g+"="+f+"*&groupBy=_whatToTrace"},function(g,f,h){return h.replace(/\&groupBy.*$/,"")+("&_whatToTrace="+f)}],doubleIp:[function(g,f){return g},function(g,f){return"_whatToTrace="+f+"&groupBy=ipAddr"},function(g,f,h){return h.replace(/\&groupBy.*$/,"")+("&ipAddr="+f)}]};d="_password";b={dateTitle:["_utime","startTime","updateTime","_lastAuthnUTime","_lastSeen"],connectionTitle:["ipAddr","_timezone","_url"],authenticationTitle:["_session_id","_user","_password","authenticationLevel"],modulesTitle:["_auth","_userDB","_passwordDB","_issuerDB","_authChoice","_authMulti","_userDBMulti"],saml:["_idp","_idpConfKey","_samlToken","_lassoSessionDump","_lassoIdentityDump"],groups:["groups","hGroups"],ldap:["dn"],BrowserID:["_browserIdAnswer","_browserIdAnswerRaw"],OpenIDConnect:["OpenIDConnect_IDToken","OpenIDConnect_OP","OpenIDConnect_access_token"]};e={session:[{title:"deleteSession",icon:"trash"}],home:[]};c=angular.module("llngSessionsExplorer",["ui.tree","ui.bootstrap","llApp"]);c.controller("SessionsExplorerCtrl",["$scope","$translator","$location","$q","$http",function(n,f,g,h,k){var l,j,i,m;n.links=links;n.menulinks=menulinks;n.staticPrefix=staticPrefix;n.scriptname=scriptname;n.formPrefix=formPrefix;n.availableLanguages=availableLanguages;n.waiting=true;n.showM=false;n.showT=true;n.data=[];n.currentScope=null;n.currentSession=null;n.menu=e;n.translateP=f.translateP;n.translate=f.translate;n.translateTitle=function(o){return f.translateField(o,"title")};m="global";n.menuClick=function(o){if(o.popup){window.open(o.popup)}else{if(!o.action){o.action=o.title}switch(typeof o.action){case"function":o.action(n.currentNode,n);break;case"string":n[o.action]();break;default:console.log(typeof o.action)}}return n.showM=false};n.deleteSession=function(){n.waiting=true;return k["delete"](scriptname+"sessions/"+m+"/"+n.currentSession.id).then(function(o){n.currentSession=null;n.currentScope.remove();return n.waiting=false},function(o){n.currentSession=null;n.currentScope.remove();return n.waiting=false})};n.stoggle=function(o){var p;p=o.$modelValue;if(p.nodes.length===0){n.updateTree(p.value,p.nodes,p.level,p.query)}return o.toggle()};n.displaySession=function(p){var q,o;o=function(r){var w,y,C,A,E,H,z,G,F,M,D,I,v,u,s,x,L,K,t,J,B;y=function(N){return N};w=function(Q,S){var O,P,N,R;N=[];P=new RegExp(Q);for(O in r){R=r[O];if(O.match(P)&&R){N.push({title:O,value:R});delete r[O]}}if(N.length>0){return L.push({title:S,nodes:N})}};t=r._utime;z=r._session_id;for(M in r){B=r[M];if(!B){delete r[M]}else{if(typeof r==="string"&&B.match(/; /)){r[M]=B.split("; ")}if(typeof r[M]!=="object"){if(d.match(new RegExp("\b"+M+"\b"))){r[M]="********"}else{if(M.match(/^(_utime|_lastAuthnUTime|_lastSeen|notification)$/)){r[M]=n.localeDate(B)}else{if(M.match(/^(startTime|updateTime)$/)){r[M]=y(B)}}}}}}L=[];for(E in b){A=b[E];K=[];for(H=0,I=A.length;H<I;H++){C=A[H];if(r[C]){K.push({title:C,value:r[C]});delete r[C]}}if(K.length>0){L.push({title:"__"+E+"__",nodes:K})}}w("^openid","OpenID");w("^notification_(.+)","__notificationsDone__");if(r.loginHistory){J=[];if(r.loginHistory.successLogin){s=r.loginHistory.successLogin;for(G=0,v=s.length;G<v;G++){D=s[G];J.push({t:D._utime,title:n.localeDate(D._utime),value:"Success (IP "+D.ipAddr+")"})}}if(r.loginHistory.failedLogin){x=r.loginHistory.failedLogin;for(F=0,u=x.length;F<u;F++){D=x[F];J.push({t:D._utime,title:n.localeDate(D._utime),value:D.error+" (IP "+D.ipAddr+")"})}}delete r.loginHistory;J.sort(function(O,N){return O.t-N.t});L.push({title:"__loginHistory__",nodes:J})}J=[];for(M in r){B=r[M];J.push({title:M,value:B})}J.sort(function(O,N){if(O.title>N.title){return 1}else{if(O.title<N.title){return -1}else{return 0}}});L.push({title:"__attributesAndMacros__",nodes:J});return{_utime:t,id:z,nodes:L}};n.currentScope=p;q=p.$modelValue.session;k.get(scriptname+"sessions/"+m+"/"+q).then(function(r){return n.currentSession=o(r.data)});return n.showT=false};n.localeDate=function(o){var p;p=new Date(o*1000);return p.toLocaleString()};n.getLanguage=function(o){n.lang=o;n.form="white";n.init();return n.showM=false};i=function(p,o,q){var r;r=o.match(/#\/(\w+)/);m="global";if(r===null){n.type="_whatToTrace"}else{if(r[1].match(/^(persistent)$/)){m=RegExp.$1;n.type="_session_uid"}else{n.type=r[1]}}return n.init()};n.$on("$locationChangeSuccess",i);l=0;n.updateTree=function(s,q,t,p){var r,o;n.waiting=true;o=a[n.type]?a[n.type]:n.type==="updateTime"?a.startTime:a._whatToTrace;r=o[t](n.type,s,p);return k.get(scriptname+"sessions/"+m+"?"+r).then(function(v){var y,w,u,z,x;y=v.data;if(y.result){x=y.values;for(w=0,u=x.length;w<u;w++){z=x[w];l++;z.id="node"+l;if(t<o.length-1){z.nodes=[];z.level=t+1;z.query=r;if(n.type.match(/^(?:start|update)Time$/)){z.title=z.value.replace(/^(\d{8})(\d{2})(\d{2})$/,"$2:$3").replace(/^(\d{8})(\d{2})(\d)$/,"$2:$30").replace(/^(\d{8})(\d{2})$/,"$2h").replace(/^(\d{4})(\d{2})(\d{2})/,"$1-$2-$3")}}q.push(z)}if(s===""){n.total=y.total}}return n.waiting=false},function(u){return n.waiting=false})};n.init=function(){n.waiting=true;n.data=[];return h.all([f.init(n.lang),n.updateTree("",n.data,0)]).then(function(){return n.waiting=false},function(o){return n.waiting=false})};j=g.path().match(/^\/(\w+)/);return n.type=j?j[1]:"_whatToTrace"}])}).call(this);
\ No newline at end of file
(function(){var c,e,d,f,a;var b={_whatToTrace:function(h,g,j,i){if(j===1){return h+"="+g+"*&groupBy=substr("+h+","+(j+i)+")"}return a._whatToTrace[j]}};a={_whatToTrace:[function(h,g){return"groupBy=substr("+h+",1)"},function(h,g){return h+"="+g+"*&groupBy="+h},function(h,g){return h+"="+g}],ipAddr:[function(h,g){return h+"="+g+"*&groupBy=net4("+h+",1)"},function(h,g){return h+"="+g+"*&groupBy=net4("+h+",2)"},function(h,g){return h+"="+g+"*&groupBy=net4("+h+",3)"},function(h,g){return h+"="+g+"&groupBy=net4("+h+",4)"},function(h,g){return h+"="+g+"&groupBy=_whatToTrace"},function(h,g,i){return i.replace(/\&groupBy.*$/,"")+("&_whatToTrace="+g)}],startTime:[function(h,g){return"groupBy=substr("+h+",8)"},function(h,g){return"groupBy=substr("+h+",10)"},function(h,g){return"groupBy=substr("+h+",11)"},function(h,g){return"groupBy=substr("+h+",12)"},function(h,g){return h+"="+g+"*&groupBy=_whatToTrace"},function(h,g,i){return i.replace(/\&groupBy.*$/,"")+("&_whatToTrace="+g)}],doubleIp:[function(h,g){return h},function(h,g){return"_whatToTrace="+g+"&groupBy=ipAddr"},function(h,g,i){return i.replace(/\&groupBy.*$/,"")+("&ipAddr="+g)}]};e="_password";c={dateTitle:["_utime","startTime","updateTime","_lastAuthnUTime","_lastSeen"],connectionTitle:["ipAddr","_timezone","_url"],authenticationTitle:["_session_id","_user","_password","authenticationLevel"],modulesTitle:["_auth","_userDB","_passwordDB","_issuerDB","_authChoice","_authMulti","_userDBMulti"],saml:["_idp","_idpConfKey","_samlToken","_lassoSessionDump","_lassoIdentityDump"],groups:["groups","hGroups"],ldap:["dn"],BrowserID:["_browserIdAnswer","_browserIdAnswerRaw"],OpenIDConnect:["OpenIDConnect_IDToken","OpenIDConnect_OP","OpenIDConnect_access_token"]};f={session:[{title:"deleteSession",icon:"trash"}],home:[]};d=angular.module("llngSessionsExplorer",["ui.tree","ui.bootstrap","llApp"]);d.controller("SessionsExplorerCtrl",["$scope","$translator","$location","$q","$http",function(o,g,h,i,l){var m,k,j,n;o.links=links;o.menulinks=menulinks;o.staticPrefix=staticPrefix;o.scriptname=scriptname;o.formPrefix=formPrefix;o.availableLanguages=availableLanguages;o.waiting=true;o.showM=false;o.showT=true;o.data=[];o.currentScope=null;o.currentSession=null;o.menu=f;o.translateP=g.translateP;o.translate=g.translate;o.translateTitle=function(p){return g.translateField(p,"title")};n="global";o.menuClick=function(p){if(p.popup){window.open(p.popup)}else{if(!p.action){p.action=p.title}switch(typeof p.action){case"function":p.action(o.currentNode,o);break;case"string":o[p.action]();break;default:console.log(typeof p.action)}}return o.showM=false};o.deleteSession=function(){o.waiting=true;return l["delete"](scriptname+"sessions/"+n+"/"+o.currentSession.id).then(function(p){o.currentSession=null;o.currentScope.remove();return o.waiting=false},function(p){o.currentSession=null;o.currentScope.remove();return o.waiting=false})};o.stoggle=function(p){var q;q=p.$modelValue;if(q.nodes.length===0){o.updateTree(q.value,q.nodes,q.level,q.over,q.query,q.count)}return p.toggle()};o.displaySession=function(q){var r,p;p=function(s){var x,z,D,B,F,I,A,H,G,N,E,J,w,v,t,y,M,L,u,K,C;z=function(O){return O};x=function(R,T){var P,Q,O,S;O=[];Q=new RegExp(R);for(P in s){S=s[P];if(P.match(Q)&&S){O.push({title:P,value:S});delete s[P]}}if(O.length>0){return M.push({title:T,nodes:O})}};u=s._utime;A=s._session_id;for(N in s){C=s[N];if(!C){delete s[N]}else{if(typeof s==="string"&&C.match(/; /)){s[N]=C.split("; ")}if(typeof s[N]!=="object"){if(e.match(new RegExp("\b"+N+"\b"))){s[N]="********"}else{if(N.match(/^(_utime|_lastAuthnUTime|_lastSeen|notification)$/)){s[N]=o.localeDate(C)}else{if(N.match(/^(startTime|updateTime)$/)){s[N]=z(C)}}}}}}M=[];for(F in c){B=c[F];L=[];for(I=0,J=B.length;I<J;I++){D=B[I];if(s[D]){L.push({title:D,value:s[D]});delete s[D]}}if(L.length>0){M.push({title:"__"+F+"__",nodes:L})}}x("^openid","OpenID");x("^notification_(.+)","__notificationsDone__");if(s.loginHistory){K=[];if(s.loginHistory.successLogin){t=s.loginHistory.successLogin;for(H=0,w=t.length;H<w;H++){E=t[H];K.push({t:E._utime,title:o.localeDate(E._utime),value:"Success (IP "+E.ipAddr+")"})}}if(s.loginHistory.failedLogin){y=s.loginHistory.failedLogin;for(G=0,v=y.length;G<v;G++){E=y[G];K.push({t:E._utime,title:o.localeDate(E._utime),value:E.error+" (IP "+E.ipAddr+")"})}}delete s.loginHistory;K.sort(function(P,O){return P.t-O.t});M.push({title:"__loginHistory__",nodes:K})}K=[];for(N in s){C=s[N];K.push({title:N,value:C})}K.sort(function(P,O){if(P.title>O.title){return 1}else{if(P.title<O.title){return -1}else{return 0}}});M.push({title:"__attributesAndMacros__",nodes:K});return{_utime:u,id:A,nodes:M}};o.currentScope=q;r=q.$modelValue.session;l.get(scriptname+"sessions/"+n+"/"+r).then(function(s){return o.currentSession=p(s.data)});return o.showT=false};o.localeDate=function(p){var q;q=new Date(p*1000);return q.toLocaleString()};o.getLanguage=function(p){o.lang=p;o.form="white";o.init();return o.showM=false};j=function(q,p,r){var s;s=p.match(/#\/(\w+)/);n="global";if(s===null){o.type="_whatToTrace"}else{if(s[1].match(/^(persistent)$/)){n=RegExp.$1;o.type="_session_uid"}else{o.type=s[1]}}return o.init()};o.$on("$locationChangeSuccess",j);m=0;o.updateTree=function(u,s,w,v,q,r){var t,p;o.waiting=true;p=a[o.type]?a[o.type]:o.type==="updateTime"?a.startTime:a._whatToTrace;t=p[w](o.type,u,q);if(r>20&&b[o.type]){v++;t=b[o.type](o.type,u,w,v,q);w=w-1}else{v=0}return l.get(scriptname+"sessions/"+n+"?"+t).then(function(y){var B,z,x,C,A;B=y.data;if(B.result){A=B.values;for(z=0,x=A.length;z<x;z++){C=A[z];m++;C.id="node"+m;if(w<p.length-1){C.nodes=[];C.level=w+1;C.over=v;C.query=t;if(o.type.match(/^(?:start|update)Time$/)){C.title=C.value.replace(/^(\d{8})(\d{2})(\d{2})$/,"$2:$3").replace(/^(\d{8})(\d{2})(\d)$/,"$2:$30").replace(/^(\d{8})(\d{2})$/,"$2h").replace(/^(\d{4})(\d{2})(\d{2})/,"$1-$2-$3")}}s.push(C)}if(u===""){o.total=B.total}}return o.waiting=false},function(x){return o.waiting=false})};o.init=function(){o.waiting=true;o.data=[];return i.all([g.init(o.lang),o.updateTree("",o.data,0,0)]).then(function(){return o.waiting=false},function(p){return o.waiting=false})};k=h.path().match(/^\/(\w+)/);return o.type=k?k[1]:"_whatToTrace"}])}).call(this);
\ No newline at end of file
Supports Markdown
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