[rt-devel] Listing logged-in users

Michele Bergonzoni bergonz at labs.it
Mon Dec 10 12:25:58 EST 2012


> This is something I didn't realize. I'll restore my previous attempt
> from backups and send you something.

That's the "ListSessions" box. The code mimics rt-clean-sessions. If a 
user has two sessions, this will show him twice, so it is not really 
"done" but Christian, you might want to play with this and see if you 
like it.

There is surely a lot of things I don't understand about the 
"LastUpdated" field. Thomas knows better, because he told to use 
callbacks (but I got lost trying to figure out their ARGS).

Thanks everybody for the help and the suggestions,

			Bergonz

===================================================
<!--
# A Box to show sessions active in last 5 mins
# To install:
# - cd $RTHOME
# - save this file as local/html/Elements/ListSessions
# - copy the line with "Set($HomepageComponents ..." from 
etc/RT_Config.pm to etc/RT_SiteConfig.pm
# - change it to include the word ListSessions
# - clean mason cache and restart apache
-->

<div class="ticket-overview">
<&|/Widgets/TitleBox,
     title => loc("Active sessions (last 5 min)"),
     bodyclass => ""
&>


<table border="0" cellspacing="0" cellpadding="1" width="100%" 
class="queue-summary">
<%perl>
require RT::Interface::Web::Session;

my $class = RT::Interface::Web::Session->Class();
my $attrs = RT::Interface::Web::Session->Attributes();

require POSIX;
my $date = POSIX::strftime("%Y-%m-%d %H:%M:%S", localtime(time - 300));
my $sth = $RT::Handle->dbh->prepare("select id from sessions where 
LastUpdated > ? order by LastUpdated desc");
die "couldn't prepare query: ". $RT::Handle->dbh->errstr unless $sth;
my $rv = $sth->execute($date);
die "couldn't execute query: ". $RT::Handle->dbhdbh->errstr unless 
defined $rv;
my $arr = $sth->fetchall_arrayref();
my $i=0;
while ($i <= $#$arr){
   my %session;
   local $@;
   eval { tie %session, $class, $$arr[$i][0], $attrs };
   if( $@ ) {
     $RT::Logger->debug("skipped session " . $$arr[$i][0] . ", couldn't 
load: $@");
     next;
   }
</%perl>
   <tr class="<% $i%2 ? 'oddline' : 'evenline'%>"><td>
   <% $session{'CurrentUser'}->UserObj->Name() %>
   </td></tr>
<%perl>
   $i++;
}
</%perl>
</table>
</&>
</div>
===================================================


-- 
Ing. Michele Bergonzoni - Laboratori Guglielmo Marconi S.p.a.
Phone:+39-051-6781926 e-mail: bergonz at labs.it
alt.advanced.networks.design.configure.operate


More information about the rt-devel mailing list