File:  [LON-CAPA] / loncom / cgi / userstatus.pl
Revision 1.4: download - view: text, annotated - select for diffs
Tue Jul 29 20:23:17 2003 UTC (20 years, 9 months ago) by www
Branches: MAIN
CVS tags: version_1_0_3, version_1_0_2, version_1_0_1, version_1_0_0, version_0_99_5, version_0_99_4, HEAD
Actually, this should go into 1.0

    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:       
   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: my $oneline=($ENV{'QUERY_STRING'} eq 'simple');
   27: unless ($oneline) { print "<html><body bgcolor=#FFFFFF>\n<h1>User Status ".localtime()."</h1>"; }
   28: 
   29: my $filename;
   30: opendir(DIR,$perlvar{'lonIDsDir'});
   31: %usercounts=();
   32: while ($filename=readdir(DIR)) {
   33:     unless ($filename=~/^\./) {
   34:         my ($dev,$ino,$mode,$nlink,
   35:             $uid,$gid,$rdev,$size,
   36:             $atime,$mtime,$ctime,
   37:             $blksize,$blocks)=stat($perlvar{'lonIDsDir'}.'/'.$filename);
   38:         $now=time;
   39:         $since=$now-$mtime;
   40:         $sinceacc=$now-$atime;
   41: 	unless ($oneline) { print ("\n\n<hr />"); }
   42:         my %userinfo=();
   43:         undef $userinfo;
   44:         my $fh=IO::File->new($perlvar{'lonIDsDir'}.'/'.$filename);
   45:         while ($line=<$fh>) {
   46:             chomp($line);
   47:             my ($name,$value)=split(/\=/,$line);
   48:             $userinfo{$name}=$value;
   49:         }
   50:         $fh->close();
   51:         $color="#000000";
   52:         $userclass="Active";
   53:         if ($since>300) { $color="#222222"; }
   54:         if ($since>600) { $color="#444444"; }
   55:         if ($since>3600) { $color="#666666"; $userclass="Moderately Active"; }
   56:         if ($since>7200) { $color="#888888"; }
   57:         if ($since>21600) { $color="#AAAAAA"; $userclass="Inactive"; }
   58:         $usercount{$userclass}++;
   59:         $usercount{'in Domain '.$userinfo{'user.domain'}}++;
   60:       unless ($oneline) {
   61:         print '<font color="'.$color.'">';
   62:         print '<h3>'.$userinfo{'environment.lastname'}.', '.
   63: 	       $userinfo{'environment.firstname'}.' '.
   64: 	       $userinfo{'environment.middlename'}.' '.
   65: 	       $userinfo{'environment.generation'}." (".
   66:                $userinfo{'user.name'}."\@".$userinfo{'user.domain'}.
   67:                ")</h3>\n<b>Login time:</b> ".
   68:                localtime($userinfo{'user.login.time'}).
   69:               ' <b>Browser</b>: '.$userinfo{'browser.type'}." <b>Client:</b> ".
   70:                $userinfo{'request.host'}."<br />\n<b>Role: </b>".
   71:                $userinfo{'request.role'}." ";
   72: 	if ($userinfo{'request.course.id'}) {
   73:             print "<b>Course:</b> ".
   74:           $userinfo{'course.'.$userinfo{'request.course.id'}.'.description'}.
   75:                 ' ('.$userinfo{'request.course.id'}.')';
   76:             $usercount{'in Course '.
   77:    $userinfo{'course.'.$userinfo{'request.course.id'}.'.description'}.
   78: 			   ' ('.$userinfo{'request.course.id'}.')'}++;
   79:         } else {
   80: 	    print "Not in a course.";
   81:         }
   82:         print "<br /><b>Last Transaction:</b> ".localtime($mtime).
   83:        " (".$since." secs ago) <br /><b>Last Access:</b> ".localtime($atime).
   84:        " (".$sinceacc." secs ago)";
   85:        print ("</font>"); 
   86:      }      
   87:     }
   88: }
   89: closedir(DIR);
   90: open (LOADAVGH,"/proc/loadavg");
   91: $loadavg=<LOADAVGH>;
   92: close(LOADAVGH);
   93: unless ($oneline) { 
   94: print "<hr /><h2>User Count</h2>";
   95: foreach (sort keys %usercount) {
   96:     print "<b>".$_.":</b> ".$usercount{$_}."<br />";
   97: }
   98: print "<b>Load Average:<b> ".$loadavg;
   99: print "</body></html>";
  100: } else {
  101: foreach (sort keys %usercount) {
  102:     print $_.'='.$usercount{$_}.'&';
  103: }
  104: print 'loadavg='.$loadavg;
  105: }

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