[rt-devel] Listing logged-in users

Michele Bergonzoni bergonz at labs.it
Thu Dec 6 06:27:33 EST 2012


> If I come up with something decent, I'll share it.

Decent? Maybe, at least I don't see any obvious security hole. I don't 
know enough about RT to know if this will make a SQL query per row, or 
if it will take the names from some cache. Anyway that's what I have.

Regards,

				Bergonz

================================================================
<!--
# A Box to show logged in users
# Actually shows who displayed this box in the last 5 mins
# To install:
# - cd $RTHOME
# - save this file as local/html/Elements/ListLogged
# - copy the line with "Set($HomepageComponents ..." from 
etc/RT_Config.pm to etc/RT_SiteConfig.pm
# - change it to include the word ListLogged
# - mkdir var/logged_users
# - chown <your web server user>.<your web server group> var/logged_users
# - clean mason cache and restart apache
-->

<div class="ticket-overview">
<&|/Widgets/TitleBox,
     title => loc("Who's seeing this page (last 5 min)"),
     bodyclass => ""
&>

<table border="0" cellspacing="0" cellpadding="1" width="100%" 
class="queue-summary">
<%perl>
require RT::User;
my $base = $RT::BasePath . '/var/logged_users';
my $file = $session{'CurrentUser'}->id();

# Touch your file
open(F, '> ' . $base . '/' . $file);
close(F);

my $u = RT::User->new($RT::SystemUser);
my $now=time();

if (not opendir(Q,$base)){
   die("Can't scan $base: $!\n");
}

my $tref = [];
my $mtime;
my $uname;

while (defined($file=readdir(Q))){
   $mtime=(stat($base . '/' . $file))[9];
   if ($mtime >= ($now - 300)) {
     if($file =~ /^\d+$/){
       $u->Load(int($file));
       $uname = $u->Name();
       if ($uname){
         push(@$tref, [($uname)]);
       }
     }
   }
}
closedir(Q);

my $i=0;
for my $line (@{$tref}){
</%perl>
   <tr class="<% $i%2 ? 'oddline' : 'evenline'%>">
     <td class="collection-as-table"><% $$line[0] %></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