Annotation of loncom/auth/lonroles.pm, revision 1.4
1.1 harris41 1: # The LearningOnline Network with CAPA
2: # User Roles Screen
3: # (Directory Indexer
4: # (Login Screen
5: # 5/21/99,5/22,5/25,5/26,5/31,6/2,6/10,7/12,7/14 Gerd Kortemeyer)
6: # 11/23 Gerd Kortemeyer)
1.4 ! www 7: # 1/14,03/06,06/01,07/22,07/24,07/25 Gerd Kortemeyer
1.1 harris41 8: #
9: package Apache::lonroles;
10:
11: use strict;
12: use Apache::lonnet();
13: use Apache::Constants qw(:common);
1.2 www 14: use Apache::File();
1.1 harris41 15:
16: sub handler {
17: my $r = shift;
18: $r->content_type('text/html');
19: $r->send_http_header;
20: return OK if $r->header_only;
21:
22: # ---------------------------------------------------------------- Print Header
23: $r->print(<<ENDHEADER);
24: <html>
25: <head>
26: <title>LON-CAPA User Roles</title>
27: </head>
28: <body bgcolor="#FFFFFF">
29: ENDHEADER
30:
1.2 www 31: # ------------------------------------------ Get Error Message from Environment
32:
33: my ($fn,$priv,$nochoose,$error,$msg)=split(/:/,$ENV{'user.error.msg'});
1.1 harris41 34:
1.2 www 35: # -------------------------------------------------------- Generate Page Output
36:
37: if ($error) {
38: $r->print("<h1>LON-CAPA Access Control</h1>");
1.4 ! www 39: $r->print("<hr><pre>Access : ".
! 40: Apache::lonnet::plaintext($priv)."\n");
! 41: $r->print("Resource: $fn\n");
! 42: $r->print("Action : $msg\n</pre><hr>");
1.2 www 43: $r->log_reason(
44: "$msg for $ENV{'user.name'} domain $ENV{'user.domain'} access $priv",$fn);
45: } else {
46: $r->print("<h1>LON-CAPA User Roles</h1>");
47: }
48:
1.4 ! www 49: my $now=time;
! 50: my $then=$ENV{'user.login.time'};
! 51:
1.2 www 52: if ($nochoose) {
1.4 ! www 53: $r->print("<h2>Assigned User Roles</h2>\n");
1.2 www 54: } else {
55: $r->print("<h2>Select a User Role</h2>\n");
56: $r->print('<form method=get action="'.$fn.'">');
57: }
1.4 ! www 58:
! 59: $r->print('<table><tr><th>User Role</th><th colspan=2>Extent</th>'.
! 60: '<th>Start</th><th>End</th><th>Remark</th></tr>'."\n");
1.1 harris41 61: my $envkey;
1.3 albertel 62: foreach $envkey (sort keys %ENV) {
1.2 www 63: if ($envkey=~/^user\.role\./) {
1.4 ! www 64: my ($dum1,$dum2,$role,@pwhere)=split(/\./,$envkey);
! 65: my $where=join('.',@pwhere);
! 66: my ($tstart,$tend)=split(/\./,$ENV{$envkey});
! 67: my $tremark='';
! 68: my $tstatus='is';
! 69: my $tpstart=' ';
! 70: my $tpend=' ';
! 71: if ($tstart) {
! 72: if ($tstart>$then) {
! 73: $tstatus='future';
! 74: if ($tstart<$now) { $tstatus='will'; }
! 75: }
! 76: $tpstart=localtime($tstart);
! 77: }
! 78: if ($tend) {
! 79: if ($tend<$then) { $tstatus='expired'; }
! 80: if ($tend>$now) { $tstatus='will_not'; }
! 81: $tpend=localtime($tend);
! 82: }
! 83: my $tbg;
! 84: if ($tstatus eq 'is') {
! 85: $tbg='#77FF77';
! 86: } elsif ($tstatus eq 'future') {
! 87: $tbg='#FFFF77';
! 88: } elsif ($tstatus eq 'will') {
! 89: $tbg='#FFAA77';
! 90: $tremark.='Active at next login.';
! 91: } elsif ($tstatus eq 'expired') {
! 92: $tbg='#FF7777';
! 93: } elsif ($tstatus eq 'will_not') {
! 94: $tbg='#AAFF77';
! 95: $tremark.='Expired after logout.';
! 96: }
! 97: my $trole;
! 98: if ($role =~ /^cr\//) {
! 99: my ($rdummy,$rdomain,$rauthor,$rrole)=split(/\//,$role);
! 100: $tremark.='<br>Defined by '.$rauthor.' at '.$rdomain.'.';
! 101: $trole=$rrole;
! 102: } else {
! 103: $trole=Apache::lonnet::plaintext($role);
! 104: }
! 105: my $ttype;
! 106: my $twhere;
! 107: my ($tres,$tdom,@trest)=split(/\//,$where);
! 108: if ($where=~/\.course$/) {
! 109: $ttype='Course';
! 110: $twhere=$tdom.'/'.join('/',@trest);
! 111: } elsif ($tdom) {
! 112: $ttype='Domain';
! 113: $twhere=$tdom;
! 114: } else {
! 115: $ttype='System';
! 116: $twhere='/';
! 117: }
! 118:
! 119: $r->print('<tr bgcolor='.$tbg.'><td>'.$trole.'</td><td>'.
! 120: $ttype.'</td><td>'.$twhere.'</td><td>'.$tpstart.
! 121: '</td><td>'.$tpend.
! 122: '</td><td>'.$tremark.' </td></tr>'."\n");
! 123: }
! 124: }
! 125:
! 126: $r->print('</table>');
! 127: unless ($nochoose) {
! 128: $r->print("</form>\n");
! 129: }
! 130: # ----------------------------------------------------------------- Priviledges
! 131:
! 132: $r->print('<hr><h2>Priviledges</h2>');
! 133:
! 134: foreach $envkey (sort keys %ENV) {
! 135: if ($envkey=~/^user\.priv\./) {
! 136: my ($dum1,$dum2,@pwhere)=split(/\./,$envkey);
! 137: my $where=join('.',@pwhere);
! 138: my $ttype;
! 139: my $twhere;
! 140: my ($tres,$tdom,@trest)=split(/\//,$where);
! 141: if ($where=~/\.course$/) {
! 142: $ttype='Course';
! 143: $twhere=$tdom.'/'.join('/',@trest);
! 144: } elsif ($tdom) {
! 145: $ttype='Domain';
! 146: $twhere=$tdom;
! 147: } else {
! 148: $ttype='System';
! 149: $twhere='/';
! 150: }
! 151: $r->print("\n<h3>".$ttype.': '.$twhere.'</h3><ul>');
! 152: map {
! 153: if ($_) {
! 154: my ($prv,$restr)=split(/\&/,$_);
! 155: my $trestr='';
! 156: if ($restr ne 'F') {
! 157: my $i;
! 158: for ($i=0;$i<length($restr);$i++) {
! 159: $trestr=' ('.
! 160: Apache::lonnet::plaintext(substr($restr,$i,1)).') ';
! 161: }
! 162: }
! 163: $r->print('<li>'.Apache::lonnet::plaintext($prv).$trestr.
! 164: '</li>');
! 165: }
! 166: } sort split(/:/,$ENV{$envkey});
! 167: $r->print('</ul>');
1.2 www 168: }
1.4 ! www 169: }
! 170:
! 171: # -------------------------------------------------------------- Debug - remove
! 172:
! 173: $->print("<hr><h1>Debugging</h1><hr>\n");
! 174:
! 175: foreach $envkey (sort keys %ENV) {
! 176: $r->print("$envkey ---- $ENV{$envkey}<br>");
1.1 harris41 177: }
1.2 www 178:
1.1 harris41 179: $r->print("</body></html>\n");
180: return OK;
181: }
182:
183: 1;
184: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>