File:  [LON-CAPA] / loncom / cgi / userstatus.pl
Revision 1.2: download - view: text, annotated - select for diffs
Wed Feb 26 14:10:38 2003 UTC (21 years, 2 months ago) by www
Branches: MAIN
CVS tags: version_0_99_3, version_0_99_2, version_0_99_1, version_0_99_0, conference_2003, HEAD
$ENV{'remote_host'} made no sense
userstatus counts domains now

    1: #!/usr/bin/perl
    2: $|=1;
    3: # The LearningOnline Network with CAPA
    4: # User Status
    5: # (Versions
    6: # (Running loncron
    7: # 09/06/01 Gerd Kortemeyer)
    8: # 02/18/02,02/19/02 Gerd Kortemeyer)
    9: 
   10: use lib '/home/httpd/lib/perl/';
   11: use LONCAPA::Configuration;
   12: 
   13: use HTTP::Headers;
   14: use IO::File;
   15: 
   16:  
   17: print "Content-type: text/html\n\n".
   18:       "<html><body bgcolor=#FFFFFF>\n";
   19: # -------------------- Read loncapa.conf (and by default, loncapa_apache.conf).
   20: my $perlvarref=LONCAPA::Configuration::read_conf('loncapa.conf');
   21: my %perlvar=%{$perlvarref};
   22: undef $perlvarref; # remove since sensitive and not needed
   23: delete $perlvar{'lonReceipt'}; # remove since sensitive and not needed
   24: delete $perlvar{'lonSqlAccess'}; # remove since sensitive and not needed
   25: 
   26: print "<h1>User Status ".localtime()."</h1>";
   27: 
   28: my $filename;
   29: opendir(DIR,$perlvar{'lonIDsDir'});
   30: %usercounts=();
   31: while ($filename=readdir(DIR)) {
   32:     unless ($filename=~/^\./) {
   33:         my ($dev,$ino,$mode,$nlink,
   34:             $uid,$gid,$rdev,$size,
   35:             $atime,$mtime,$ctime,
   36:             $blksize,$blocks)=stat($perlvar{'lonIDsDir'}.'/'.$filename);
   37:         $now=time;
   38:         $since=$now-$mtime;
   39:         $sinceacc=$now-$atime;
   40: 	print ("\n\n<hr />");
   41:         my %userinfo=();
   42:         undef $userinfo;
   43:         my $fh=IO::File->new($perlvar{'lonIDsDir'}.'/'.$filename);
   44:         while ($line=<$fh>) {
   45:             chomp($line);
   46:             my ($name,$value)=split(/\=/,$line);
   47:             $userinfo{$name}=$value;
   48:         }
   49:         $fh->close();
   50:         $color="#000000";
   51:         $userclass="Active";
   52:         if ($since>300) { $color="#222222"; }
   53:         if ($since>600) { $color="#444444"; }
   54:         if ($since>3600) { $color="#666666"; $userclass="Moderately Active"; }
   55:         if ($since>7200) { $color="#888888"; }
   56:         if ($since>21600) { $color="#AAAAAA"; $userclass="Inactive"; }
   57:         $usercount{$userclass}++;
   58:         $usercount{'in Domain '.$userinfo{'user.domain'}}++;
   59:         print '<font color="'.$color.'">';
   60:         print '<h3>'.$userinfo{'environment.lastname'}.', '.
   61: 	       $userinfo{'environment.firstname'}.' '.
   62: 	       $userinfo{'environment.middlename'}.' '.
   63: 	       $userinfo{'environment.generation'}." (".
   64:                $userinfo{'user.name'}."\@".$userinfo{'user.domain'}.
   65:                ")</h3>\n<b>Login time:</b> ".
   66:                localtime($userinfo{'user.login.time'}).
   67:               ' <b>Browser</b>: '.$userinfo{'browser.type'}." <b>Client:</b> ".
   68:                $userinfo{'request.host'}."<br />\n<b>Role: </b>".
   69:                $userinfo{'request.role'}." ";
   70: 	if ($userinfo{'request.course.id'}) {
   71:             print "<b>Course:</b> ".
   72:           $userinfo{'course.'.$userinfo{'request.course.id'}.'.description'}.
   73:                 ' ('.$userinfo{'request.course.id'}.')';
   74:             $usercount{'in Course '.
   75:    $userinfo{'course.'.$userinfo{'request.course.id'}.'.description'}.
   76: 			   ' ('.$userinfo{'request.course.id'}.')'}++;
   77:         } else {
   78: 	    print "Not in a course.";
   79:         }
   80:         print "<br /><b>Last Transaction:</b> ".localtime($mtime).
   81:        " (".$since." secs ago) <br /><b>Last Access:</b> ".localtime($atime).
   82:        " (".$sinceacc." secs ago)";
   83:        print ("</font>");       
   84:     }
   85: }
   86: closedir(DIR);
   87: print "<hr /><h2>User Count</h2>";
   88: foreach (sort keys %usercount) {
   89:     print "<b>".$_.":</b> ".$usercount{$_}."<br />";
   90: }
   91: 
   92: print "</body></html>";

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>