Annotation of loncom/cgi/userstatus.pl, revision 1.1

1.1     ! www         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:         print '<font color="'.$color.'">';
        !            59:         print '<h3>'.$userinfo{'environment.lastname'}.', '.
        !            60: 	       $userinfo{'environment.firstname'}.' '.
        !            61: 	       $userinfo{'environment.middlename'}.' '.
        !            62: 	       $userinfo{'environment.generation'}." (".
        !            63:                $userinfo{'user.name'}."\@".$userinfo{'user.domain'}.
        !            64:                ")</h3>\n<b>Login time:</b> ".
        !            65:                localtime($userinfo{'user.login.time'}).
        !            66:               ' <b>Browser</b>: '.$userinfo{'browser.type'}." <b>Client:</b> ".
        !            67:                $userinfo{'request.host'}."<br />\n<b>Role: </b>".
        !            68:                $userinfo{'request.role'}." ";
        !            69: 	if ($userinfo{'request.course.id'}) {
        !            70:             print "<b>Course:</b> ".
        !            71:           $userinfo{'course.'.$userinfo{'request.course.id'}.'.description'}.
        !            72:                 ' ('.$userinfo{'request.course.id'}.')';
        !            73:             $usercount{'in Course '.
        !            74:    $userinfo{'course.'.$userinfo{'request.course.id'}.'.description'}.
        !            75: 			   ' ('.$userinfo{'request.course.id'}.')'}++;
        !            76:         } else {
        !            77: 	    print "Not in a course.";
        !            78:         }
        !            79:         print "<br /><b>Last Transaction:</b> ".localtime($mtime).
        !            80:        " (".$since." secs ago) <br /><b>Last Access:</b> ".localtime($atime).
        !            81:        " (".$sinceacc." secs ago)";
        !            82:        print ("</font>");       
        !            83:     }
        !            84: }
        !            85: closedir(DIR);
        !            86: print "<hr /><h2>User Count</h2>";
        !            87: foreach (sort keys %usercount) {
        !            88:     print "<b>".$_.":</b> ".$usercount{$_}."<br />";
        !            89: }
        !            90: 
        !            91: print "</body></html>";

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