#1 2015-03-16 19:10:07

karolina
Member
Registered: 2014-08-09

How to check if anyone is logged in?

Hi,

How to check if anyone is logged in? Or to list currently logged in users?

Karolina

Offline

#2 2015-03-17 16:56:43

Thorsten J. Krause
datenwerke
Registered: 2012-02-15
Website

Re: How to check if anyone is logged in?

Hi Karolina,

the best we can do here is a list of recent requests that lists for each user when he was last seen:

import net.datenwerke.security.service.authenticator.*;
import net.datenwerke.security.service.usermanager.*;
import java.util.GregorianCalendar;
 
def uservice = GLOBALS.getRsService(UserManagerService.class);
def diff = 1000*60*60;
def now = new GregorianCalendar().getTimeInMillis();
GLOBALS.getRsService(AuthenticatorService.class).getLastRequests().collect({ key, value ->
    uservice.getNodeById(key)?.getUsername() + " " + ((now-value)/1000/60) + " minutes ago\n";
}).join();

Does that help?

Cheers,
Thorsten

Offline

#3 2015-03-17 17:15:33

karolina
Member
Registered: 2014-08-09

Re: How to check if anyone is logged in?

Hi Thorsten,

Thanks, I will try it.
Last seen = last activity, including logging out?

Cheers,
Karolina

Offline

#4 2015-03-17 19:45:02

karolina
Member
Registered: 2014-08-09

Re: How to check if anyone is logged in?

Hi Thorsten,

The script works smile
Additionally, for my needs (i.e. to clearly see that no other user is currently logged in), I've made a dynamic list similar to the audit log report with the following query:

SELECT 
  rs_user.username as username,
  rs_audit_log_entry.action as action,
  MAX(rs_audit_log_entry.date_field) AS datetime
FROM
  rs_audit_log_entry
  INNER JOIN rs_user ON (rs_audit_log_entry.user_id = rs_user.id)
WHERE
  rs_audit_log_entry.action LIKE 'LOGIN' OR 
  rs_audit_log_entry.action LIKE 'LOGOUT'
GROUP BY
  rs_user.username,
  rs_audit_log_entry.action
ORDER BY
  datetime DESC

It looks like some logouts are not in the log, but the script and the report should work well together.

Cheers,
Karolina

Last edited by karolina (2015-03-17 19:46:15)

Offline

Board footer

Powered by FluxBB