From 0119e3a229f89fa73ad327cd1c399d5ceb6d513c Mon Sep 17 00:00:00 2001 From: Maxime Besson Date: Mon, 29 Aug 2022 17:49:24 +0200 Subject: [PATCH] Eliminate hardcoded SFA types from manager JS --- lemonldap-ng-manager/site/coffee/2ndfa.coffee | 43 ++++++------ .../site/coffee/sessions.coffee | 37 +++++----- .../site/htdocs/static/js/2ndfa.js | 70 +++++++++++-------- .../site/htdocs/static/js/2ndfa.min.js | 2 +- .../site/htdocs/static/js/2ndfa.min.js.map | 2 +- .../site/htdocs/static/js/sessions.js | 52 +++++++------- .../site/htdocs/static/js/sessions.min.js | 2 +- .../site/htdocs/static/js/sessions.min.js.map | 2 +- lemonldap-ng-manager/site/templates/2ndfa.tpl | 25 +++---- .../site/templates/sessions.tpl | 3 - 10 files changed, 123 insertions(+), 115 deletions(-) diff --git a/lemonldap-ng-manager/site/coffee/2ndfa.coffee b/lemonldap-ng-manager/site/coffee/2ndfa.coffee index f1ba0ac2a..9e2198d3d 100644 --- a/lemonldap-ng-manager/site/coffee/2ndfa.coffee +++ b/lemonldap-ng-manager/site/coffee/2ndfa.coffee @@ -70,10 +70,7 @@ llapp.controller 'SessionsExplorerCtrl', ['$scope', '$translator', '$location', $scope.currentSession = null $scope.menu = menu $scope.searchString = '' - $scope.U2FCheck = "1" - $scope.TOTPCheck = "1" - $scope.UBKCheck = "1" - $scope.WebAuthnCheck = "1" + $scope.sfatypes = {} # Import translations functions $scope.translateP = $translator.translateP @@ -202,24 +199,26 @@ llapp.controller 'SessionsExplorerCtrl', ['$scope', '$translator', '$location', subres = [] for attr in attrs if session[attr] - if session[attr].toString().match(/"type":\s*"(?:TOTP|U2F|UBK|WebAuthn)"/) - subres.push - title: "type" - value: "name" - epoch: "date" + if attr == "_2fDevices" && session[attr] array = JSON.parse(session[attr]) - for sfDevice in array - for key, value of sfDevice - if key == 'type' - title = value - if key == 'name' - name = value - if key == 'epoch' - epoch = value + if array.length > 0 subres.push - title: title - value: name - epoch: epoch + title: "type" + value: "name" + epoch: "date" + for sfDevice in array + for key, value of sfDevice + if key == 'type' + title = value + if key == 'name' + name = value + if key == 'epoch' + epoch = value + subres.push + title: title + value: name + epoch: epoch + sfrow: true delete session[attr] else if session[attr].toString().match(/\w+/) subres.push @@ -296,7 +295,7 @@ llapp.controller 'SessionsExplorerCtrl', ['$scope', '$translator', '$location', over = 0 # Launch HTTP query - $http.get("#{scriptname}sfa/#{sessionType}?#{query}&U2FCheck=#{$scope.U2FCheck}&TOTPCheck=#{$scope.TOTPCheck}&UBKCheck=#{$scope.UBKCheck}&WebAuthnCheck=#{$scope.WebAuthnCheck}").then (response) -> + $http.get("#{scriptname}sfa/#{sessionType}?#{query}"+Object.entries($scope.sfatypes).map((x) -> if x[1] then "&type=" + x[0] else "").join("")).then (response) -> data = response.data if data.result for n in data.values @@ -347,7 +346,7 @@ llapp.controller 'SessionsExplorerCtrl', ['$scope', '$translator', '$location', over = 0 # Launch HTTP - $http.get("#{scriptname}sfa/#{sessionType}?_session_uid=#{$scope.searchString}*&groupBy=substr(_session_uid,#{$scope.searchString.length})&U2FCheck=#{$scope.U2FCheck}&TOTPCheck=#{$scope.TOTPCheck}&UBKCheck=#{$scope.UBKCheck}&WebAuthnCheck=#{$scope.WebAuthnCheck}").then (response) -> + $http.get("#{scriptname}sfa/#{sessionType}?_session_uid=#{$scope.searchString}*&groupBy=substr(_session_uid,#{$scope.searchString.length})"+Object.entries($scope.sfatypes).map((x) -> if x[1] then "&type=" + x[0] else "").join("")).then (response) -> data = response.data if data.result for n in data.values diff --git a/lemonldap-ng-manager/site/coffee/sessions.coffee b/lemonldap-ng-manager/site/coffee/sessions.coffee index ad0e2aa7b..b10c920da 100644 --- a/lemonldap-ng-manager/site/coffee/sessions.coffee +++ b/lemonldap-ng-manager/site/coffee/sessions.coffee @@ -254,26 +254,27 @@ llapp.controller 'SessionsExplorerCtrl', ['$scope', '$translator', '$location', subres = [] for attr in attrs if session[attr] - if session[attr].toString().match(/"type":\s*"(?:TOTP|U2F|UBK|WebAuthn)"/) - subres.push - title: "type" - value: "name" - epoch: "date" - td: "0" + if attr == "_2fDevices" && session[attr] array = JSON.parse(session[attr]) - for sfDevice in array - for key, value of sfDevice - if key == 'type' - title = value - if key == 'name' - name = value - if key == 'epoch' - epoch = value + if array.length > 0 subres.push - title: title - value: name - epoch: epoch - td: "1" + title: "type" + value: "name" + epoch: "date" + td: "0" + for sfDevice in array + for key, value of sfDevice + if key == 'type' + title = value + if key == 'name' + name = value + if key == 'epoch' + epoch = value + subres.push + title: title + value: name + epoch: epoch + td: "1" delete session[attr] else if session[attr].toString().match(/"rp":\s*"[\w-]+"/) subres.push diff --git a/lemonldap-ng-manager/site/htdocs/static/js/2ndfa.js b/lemonldap-ng-manager/site/htdocs/static/js/2ndfa.js index 06857b174..b023164be 100644 --- a/lemonldap-ng-manager/site/htdocs/static/js/2ndfa.js +++ b/lemonldap-ng-manager/site/htdocs/static/js/2ndfa.js @@ -86,10 +86,7 @@ $scope.currentSession = null; $scope.menu = menu; $scope.searchString = ''; - $scope.U2FCheck = "1"; - $scope.TOTPCheck = "1"; - $scope.UBKCheck = "1"; - $scope.WebAuthnCheck = "1"; + $scope.sfatypes = {}; $scope.translateP = $translator.translateP; $scope.translate = $translator.translate; $scope.translateTitle = function(node) { @@ -206,32 +203,35 @@ for (i = 0, len = attrs.length; i < len; i++) { attr = attrs[i]; if (session[attr]) { - if (session[attr].toString().match(/"type":\s*"(?:TOTP|U2F|UBK|WebAuthn)"/)) { - subres.push({ - title: "type", - value: "name", - epoch: "date" - }); + if (attr === "_2fDevices" && session[attr]) { array = JSON.parse(session[attr]); - for (k = 0, len1 = array.length; k < len1; k++) { - sfDevice = array[k]; - for (key in sfDevice) { - value = sfDevice[key]; - if (key === 'type') { - title = value; - } - if (key === 'name') { - name = value; - } - if (key === 'epoch') { - epoch = value; - } - } + if (array.length > 0) { subres.push({ - title: title, - value: name, - epoch: epoch + title: "type", + value: "name", + epoch: "date" }); + for (k = 0, len1 = array.length; k < len1; k++) { + sfDevice = array[k]; + for (key in sfDevice) { + value = sfDevice[key]; + if (key === 'type') { + title = value; + } + if (key === 'name') { + name = value; + } + if (key === 'epoch') { + epoch = value; + } + } + subres.push({ + title: title, + value: name, + epoch: epoch, + sfrow: true + }); + } } delete session[attr]; } else if (session[attr].toString().match(/\w+/)) { @@ -304,7 +304,13 @@ } else { over = 0; } - return $http.get(scriptname + "sfa/" + sessionType + "?" + query + "&U2FCheck=" + $scope.U2FCheck + "&TOTPCheck=" + $scope.TOTPCheck + "&UBKCheck=" + $scope.UBKCheck + "&WebAuthnCheck=" + $scope.WebAuthnCheck).then(function(response) { + return $http.get((scriptname + "sfa/" + sessionType + "?" + query) + Object.entries($scope.sfatypes).map(function(x) { + if (x[1]) { + return "&type=" + x[0]; + } else { + return ""; + } + }).join("")).then(function(response) { var data, i, len, n, ref; data = response.data; if (data.result) { @@ -346,7 +352,13 @@ } else { over = 0; } - return $http.get(scriptname + "sfa/" + sessionType + "?_session_uid=" + $scope.searchString + "*&groupBy=substr(_session_uid," + $scope.searchString.length + ")&U2FCheck=" + $scope.U2FCheck + "&TOTPCheck=" + $scope.TOTPCheck + "&UBKCheck=" + $scope.UBKCheck + "&WebAuthnCheck=" + $scope.WebAuthnCheck).then(function(response) { + return $http.get((scriptname + "sfa/" + sessionType + "?_session_uid=" + $scope.searchString + "*&groupBy=substr(_session_uid," + $scope.searchString.length + ")") + Object.entries($scope.sfatypes).map(function(x) { + if (x[1]) { + return "&type=" + x[0]; + } else { + return ""; + } + }).join("")).then(function(response) { var data, i, len, n, ref; data = response.data; if (data.result) { diff --git a/lemonldap-ng-manager/site/htdocs/static/js/2ndfa.min.js b/lemonldap-ng-manager/site/htdocs/static/js/2ndfa.min.js index 32a45b1b7..857e6fcca 100644 --- a/lemonldap-ng-manager/site/htdocs/static/js/2ndfa.min.js +++ b/lemonldap-ng-manager/site/htdocs/static/js/2ndfa.min.js @@ -1 +1 @@ -!function(){var a={_whatToTrace:[function(e,t){return"groupBy=substr("+e+",1)"},function(e,t){return e+"="+t+"*"}]},d={_whatToTrace:function(e,t,n,r){return console.log("overSchema => level",n,"over",r),1===n&&t.length>r?e+"="+t+"*&groupBy=substr("+e+","+(n+r+1)+")":null}},v={dateTitle:["_utime","_startTime","_updateTime"],sfaTitle:["_2fDevices"]},i={home:[]};angular.module("llngSessionsExplorer",["ui.tree","ui.bootstrap","llApp"]).controller("SessionsExplorerCtrl",["$scope","$translator","$location","$q","$http",function(y,t,e,n,h){var p,r,f;return y.links=links,y.menulinks=menulinks,y.staticPrefix=staticPrefix,y.scriptname=scriptname,y.formPrefix=formPrefix,y.availableLanguages=availableLanguages,y.waiting=!0,y.showM=!1,y.showT=!0,y.data=[],y.currentScope=null,y.currentSession=null,y.menu=i,y.searchString="",y.U2FCheck="1",y.TOTPCheck="1",y.UBKCheck="1",y.WebAuthnCheck="1",y.translateP=t.translateP,y.translate=t.translate,y.translateTitle=function(e){return t.translateField(e,"title")},f="persistent",y.menuClick=function(e){if(e.popup)window.open(e.popup);else switch(e.action||(e.action=e.title),typeof e.action){case"function":e.action(y.currentNode,y),y[e.action]();break;case"string":y[e.action]();break;default:console.log(typeof e.action)}return y.showM=!1},y.search2FA=function(e){return e&&(y.searchString=""),y.currentSession=null,y.data=[],y.updateTree2("",y.data,0,0)},y.delete2FA=function(e,t){for(var n=document.querySelectorAll(".data-"+t),r=0,a=n.length;r level",n,"over",r),1===n&&t.length>r?e+"="+t+"*&groupBy=substr("+e+","+(n+r+1)+")":null}},_={dateTitle:["_utime","_startTime","_updateTime"],sfaTitle:["_2fDevices"]},i={home:[]};angular.module("llngSessionsExplorer",["ui.tree","ui.bootstrap","llApp"]).controller("SessionsExplorerCtrl",["$scope","$translator","$location","$q","$http",function(v,t,e,n,p){var f,r,h;return v.links=links,v.menulinks=menulinks,v.staticPrefix=staticPrefix,v.scriptname=scriptname,v.formPrefix=formPrefix,v.availableLanguages=availableLanguages,v.waiting=!0,v.showM=!1,v.showT=!0,v.data=[],v.currentScope=null,v.currentSession=null,v.menu=i,v.searchString="",v.sfatypes={},v.translateP=t.translateP,v.translate=t.translate,v.translateTitle=function(e){return t.translateField(e,"title")},h="persistent",v.menuClick=function(e){if(e.popup)window.open(e.popup);else switch(e.action||(e.action=e.title),typeof e.action){case"function":e.action(v.currentNode,v),v[e.action]();break;case"string":v[e.action]();break;default:console.log(typeof e.action)}return v.showM=!1},v.search2FA=function(e){return e&&(v.searchString=""),v.currentSession=null,v.data=[],v.updateTree2("",v.data,0,0)},v.delete2FA=function(e,t){for(var n=document.querySelectorAll(".data-"+t),r=0,a=n.length;r 0) { subres.push({ - title: title, - value: name, - epoch: epoch, - td: "1" + title: "type", + value: "name", + epoch: "date", + td: "0" }); + for (j = 0, len1 = array.length; j < len1; j++) { + sfDevice = array[j]; + for (key in sfDevice) { + value = sfDevice[key]; + if (key === 'type') { + title = value; + } + if (key === 'name') { + name = value; + } + if (key === 'epoch') { + epoch = value; + } + } + subres.push({ + title: title, + value: name, + epoch: epoch, + td: "1" + }); + } } delete session[attr]; } else if (session[attr].toString().match(/"rp":\s*"[\w-]+"/)) { diff --git a/lemonldap-ng-manager/site/htdocs/static/js/sessions.min.js b/lemonldap-ng-manager/site/htdocs/static/js/sessions.min.js index ad8a2f878..037ae827c 100644 --- a/lemonldap-ng-manager/site/htdocs/static/js/sessions.min.js +++ b/lemonldap-ng-manager/site/htdocs/static/js/sessions.min.js @@ -1 +1 @@ -!function(){var f={_whatToTrace:[function(e,t){return"groupBy=substr("+e+",1)"},function(e,t){return e+"="+t+"*&groupBy="+e},function(e,t){return e+"="+t}],ipAddr:[function(e,t){return"groupBy=net("+e+",16,1)"},function(e,t){return t.match(/:/)||(t+="."),e+"="+t+"*&groupBy=net("+e+",32,2)"},function(e,t){return t.match(/:/)||(t+="."),e+"="+t+"*&groupBy=net("+e+",48,3)"},function(e,t){return t.match(/:/)||(t+="."),e+"="+t+"*&groupBy=net("+e+",128,4)"},function(e,t){return e+"="+t+"&groupBy=_whatToTrace"},function(e,t,n){return n.replace(/\&groupBy.*$/,"")+"&_whatToTrace="+t}],_startTime:[function(e,t){return"groupBy=substr("+e+",8)"},function(e,t){return e+"="+t+"*&groupBy=substr("+e+",10)"},function(e,t){return e+"="+t+"*&groupBy=substr("+e+",11)"},function(e,t){return e+"="+t+"*&groupBy=substr("+e+",12)"},function(e,t){return e+"="+t+"*&groupBy=_whatToTrace"},function(e,t,n){return console.log(e),console.log(t),console.log(n),n.replace(/\&groupBy.*$/,"")+"&_whatToTrace="+t}],doubleIp:[function(e,t){return e},function(e,t){return"_whatToTrace="+t+"&groupBy=ipAddr"},function(e,t,n){return n.replace(/\&groupBy.*$/,"")+"&ipAddr="+t}],_session_uid:[function(e,t){return"groupBy=substr("+e+",1)"},function(e,t){return e+"="+t+"*&groupBy="+e},function(e,t){return e+"="+t}]},g={_whatToTrace:function(e,t,n,o){return console.log("overScheme => level",n,"over",o),1===n&&t.length>o?e+"="+t+"*&groupBy=substr("+e+","+(n+o+1)+")":null},ipAddr:function(e,t,n,o){return console.log("overScheme => level",n,"over",o),0 level",n,"over",o),3 level",n,"over",o),1===n&&t.length>o?e+"="+t+"*&groupBy=substr("+e+","+(n+o+1)+")":null}},M={dateTitle:["_utime","_startTime","_updateTime","_lastAuthnUTime","_lastSeen"],connectionTitle:["ipAddr","_timezone","_url"],authenticationTitle:["_session_id","_user","_password","authenticationLevel"],modulesTitle:["_auth","_userDB","_passwordDB","_issuerDB","_authChoice","_authMulti","_userDBMulti","_2f"],saml:["_idp","_idpConfKey","_samlToken","_lassoSessionDump","_lassoIdentityDump"],groups:["groups","hGroups"],ldap:["dn"],OpenIDConnect:["_oidc_id_token","_oidc_OP","_oidc_access_token","_oidc_refresh_token","_oidc_access_token_eol"],sfaTitle:["_2fDevices"],oidcConsents:["_oidcConsents"]},i={session:[{title:"deleteSession",icon:"trash"}],home:[]};angular.module("llngSessionsExplorer",["ui.tree","ui.bootstrap","llApp"]).controller("SessionsExplorerCtrl",["$scope","$translator","$location","$q","$http",function(H,t,r,e,o){var p,n,d;return H.links=links,H.menulinks=menulinks,H.staticPrefix=staticPrefix,H.scriptname=scriptname,H.formPrefix=formPrefix,H.impPrefix=impPrefix,H.sessionTTL=sessionTTL,H.availableLanguages=availableLanguages,H.waiting=!0,H.showM=!1,H.showT=!0,H.data=[],H.currentScope=null,H.currentSession=null,H.menu=i,H.translateP=t.translateP,H.translate=t.translate,H.translateTitle=function(e){return t.translateField(e,"title")},d="global",H.menuClick=function(e){if(e.popup)window.open(e.popup);else switch(e.action||(e.action=e.title),typeof e.action){case"function":e.action(H.currentNode,H);break;case"string":H[e.action]();break;default:console.log(typeof e.action)}return H.showM=!1},H.deleteOIDCConsent=function(e,t){var i=document.querySelectorAll(".data-"+t);return H.waiting=!0,o.delete(scriptname+"sessions/OIDCConsent/"+d+"/"+H.currentSession.id+"?rp="+e+"&epoch="+t).then(function(e){var t,n,o,r;for(H.waiting=!1,r=[],n=0,o=i.length;nt.title?1:e.title real attribute"),A.push(c)):k.push(c);return s=k.concat(A),d.push({title:"__attributesAndMacros__",nodes:s}),{_utime:E,nodes:d}};return H.currentScope=e,t=e.$modelValue.session,o.get(scriptname+"sessions/"+d+"/"+t).then(function(e){return H.currentSession=n(e.data),H.currentSession.id=t}),H.showT=!1},H.localeDate=function(e){return new Date(1e3*e).toLocaleString()},H.isValid=function(e,t){var n=r.path(),o=Date.now()/1e3;return console.log("Path",n),console.log("Session epoch",e),console.log("Current date",o),console.log("Session TTL",sessionTTL),n=o-e level",n,"over",o),1===n&&t.length>o?e+"="+t+"*&groupBy=substr("+e+","+(n+o+1)+")":null},ipAddr:function(e,t,n,o){return console.log("overScheme => level",n,"over",o),0 level",n,"over",o),3 level",n,"over",o),1===n&&t.length>o?e+"="+t+"*&groupBy=substr("+e+","+(n+o+1)+")":null}},O={dateTitle:["_utime","_startTime","_updateTime","_lastAuthnUTime","_lastSeen"],connectionTitle:["ipAddr","_timezone","_url"],authenticationTitle:["_session_id","_user","_password","authenticationLevel"],modulesTitle:["_auth","_userDB","_passwordDB","_issuerDB","_authChoice","_authMulti","_userDBMulti","_2f"],saml:["_idp","_idpConfKey","_samlToken","_lassoSessionDump","_lassoIdentityDump"],groups:["groups","hGroups"],ldap:["dn"],OpenIDConnect:["_oidc_id_token","_oidc_OP","_oidc_access_token","_oidc_refresh_token","_oidc_access_token_eol"],sfaTitle:["_2fDevices"],oidcConsents:["_oidcConsents"]},i={session:[{title:"deleteSession",icon:"trash"}],home:[]};angular.module("llngSessionsExplorer",["ui.tree","ui.bootstrap","llApp"]).controller("SessionsExplorerCtrl",["$scope","$translator","$location","$q","$http",function(M,t,r,e,o){var p,n,d;return M.links=links,M.menulinks=menulinks,M.staticPrefix=staticPrefix,M.scriptname=scriptname,M.formPrefix=formPrefix,M.impPrefix=impPrefix,M.sessionTTL=sessionTTL,M.availableLanguages=availableLanguages,M.waiting=!0,M.showM=!1,M.showT=!0,M.data=[],M.currentScope=null,M.currentSession=null,M.menu=i,M.translateP=t.translateP,M.translate=t.translate,M.translateTitle=function(e){return t.translateField(e,"title")},d="global",M.menuClick=function(e){if(e.popup)window.open(e.popup);else switch(e.action||(e.action=e.title),typeof e.action){case"function":e.action(M.currentNode,M);break;case"string":M[e.action]();break;default:console.log(typeof e.action)}return M.showM=!1},M.deleteOIDCConsent=function(e,t){var i=document.querySelectorAll(".data-"+t);return M.waiting=!0,o.delete(scriptname+"sessions/OIDCConsent/"+d+"/"+M.currentSession.id+"?rp="+e+"&epoch="+t).then(function(e){var t,n,o,r;for(M.waiting=!1,r=[],n=0,o=i.length;nt.title?1:e.title real attribute"),B.push(i)):P.push(i);return I=P.concat(B),L.push({title:"__attributesAndMacros__",nodes:I}),{_utime:H,nodes:L}};return M.currentScope=e,t=e.$modelValue.session,o.get(scriptname+"sessions/"+d+"/"+t).then(function(e){return M.currentSession=n(e.data),M.currentSession.id=t}),M.showT=!1},M.localeDate=function(e){return new Date(1e3*e).toLocaleString()},M.isValid=function(e,t){var n=r.path(),o=Date.now()/1e3;return console.log("Path",n),console.log("Session epoch",e),console.log("Current date",o),console.log("Session TTL",sessionTTL),e=o-e @@ -107,17 +107,14 @@
- {{translate(node.title)}} - {{node.title}} - {{translate(node.value)}} - {{node.value}} - {{translate(node.epoch)}} - {{localeDate(node.epoch)}} + {{translate(node.title)}} + {{node.title}} + {{translate(node.value)}} + {{node.value}} + {{translate(node.epoch)}} + {{localeDate(node.epoch)}} - - +
diff --git a/lemonldap-ng-manager/site/templates/sessions.tpl b/lemonldap-ng-manager/site/templates/sessions.tpl index db561bb10..90a6f5b49 100644 --- a/lemonldap-ng-manager/site/templates/sessions.tpl +++ b/lemonldap-ng-manager/site/templates/sessions.tpl @@ -107,9 +107,6 @@ {{localeDate(node.epoch)}} -