Annotation of loncom/auth/lonacc.pm, revision 1.20
1.1 albertel 1: # The LearningOnline Network
2: # Cookie Based Access Handler
1.4 www 3: # 5/21/99,5/22,5/29,5/31,6/15,16/11,22/11,
1.14 www 4: # 01/06,01/13,05/31,06/01,09/06,09/25,09/28,10/30,11/6,
1.17 www 5: # 12/25,12/26,
1.19 www 6: # 01/06/01,05/28,8/11 Gerd Kortemeyer
1.1 albertel 7:
8: package Apache::lonacc;
9:
10: use strict;
1.8 www 11: use Apache::Constants qw(:common :http :methods);
1.2 www 12: use Apache::File;
1.6 www 13: use Apache::lonnet;
1.1 albertel 14: use CGI::Cookie();
1.16 www 15: use Fcntl qw(:flock);
1.1 albertel 16:
17: sub handler {
18: my $r = shift;
19: my $requrl=$r->uri;
20: my %cookies=CGI::Cookie->parse($r->header_in('Cookie'));
21: my $lonid=$cookies{'lonID'};
22: my $cookie;
23: if ($lonid) {
24: my $handle=$lonid->value;
25: $handle=~s/\W//g;
26: my $lonidsdir=$r->dir_config('lonIDsDir');
27: if ((-e "$lonidsdir/$handle.id") && ($handle ne '')) {
1.6 www 28:
29: # ------------------------------------------- Transfer profile into environment
30:
1.2 www 31: my @profile;
32: {
33: my $idf=Apache::File->new("$lonidsdir/$handle.id");
1.16 www 34: flock($idf,LOCK_SH);
1.2 www 35: @profile=<$idf>;
1.16 www 36: $idf->close();
1.2 www 37: }
38: my $envi;
39: for ($envi=0;$envi<=$#profile;$envi++) {
40: chomp($profile[$envi]);
41: my ($envname,$envvalue)=split(/=/,$profile[$envi]);
1.9 www 42: $ENV{$envname} = $envvalue;
1.2 www 43: }
1.9 www 44: $ENV{'user.environment'} = "$lonidsdir/$handle.id";
1.18 www 45: if ($requrl=~/^\/res\//) {
1.17 www 46: $ENV{'request.state'} = "published";
47: } else {
48: $ENV{'request.state'} = 'unknown';
49: }
1.9 www 50: $ENV{'request.filename'} = $r->filename;
1.12 www 51:
1.6 www 52: # -------------------------------------------------------- Load POST parameters
53:
1.8 www 54:
55:
1.14 www 56: my $buffer;
1.6 www 57:
1.14 www 58: $r->read($buffer,$r->header_in('Content-length'));
59:
60: unless ($buffer=~/^(\-+\w+)\s+Content\-Disposition\:\s*form\-data/si) {
1.5 www 61: my @pairs=split(/&/,$buffer);
1.6 www 62: my $pair;
1.5 www 63: foreach $pair (@pairs) {
1.6 www 64: my ($name,$value) = split(/=/,$pair);
65: $value =~ tr/+/ /;
66: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.10 www 67: $name =~ tr/+/ /;
68: $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.9 www 69: $ENV{"form.$name"}=$value;
1.6 www 70: }
1.14 www 71: } else {
72: my $contentsep=$1;
73: my @lines = split (/\n/,$buffer);
74: my $name='';
75: my $value='';
76: my $fname='';
77: my $fmime='';
78: my $i;
79: for ($i=0;$i<=$#lines;$i++) {
80: if ($lines[$i]=~/^$contentsep/) {
81: if ($name) {
82: chomp($value);
83: if ($fname) {
84: $ENV{"form.$name.filename"}=$fname;
85: $ENV{"form.$name.mimetype"}=$fmime;
1.15 www 86: } else {
87: $value=~s/\s+$//s;
1.14 www 88: }
1.15 www 89: $ENV{"form.$name"}=$value;
1.14 www 90: }
91: if ($i<$#lines) {
92: $i++;
93: $lines[$i]=~
94: /Content\-Disposition\:\s*form\-data\;\s*name\=\"([^\"]+)\"/i;
95: $name=$1;
96: $value='';
97: if ($lines[$i]=~/filename\=\"([^\"]+)\"/i) {
98: $fname=$1;
99: if
100: ($lines[$i+1]=~/Content\-Type\:\s*([\w\-\/]+)/i) {
101: $fmime=$1;
102: $i++;
103: } else {
104: $fmime='';
105: }
106: } else {
107: $fname='';
108: $fmime='';
109: }
110: $i++;
111: }
112: } else {
113: $value.=$lines[$i]."\n";
114: }
115: }
116: }
1.8 www 117: $r->method_number(M_GET);
118: $r->method('GET');
119: $r->headers_in->unset('Content-length');
1.6 www 120:
121: # ---------------------------------------------------------------- Check access
122:
123: if ($requrl!~/^\/adm\//) {
1.7 www 124: my $access=&Apache::lonnet::allowed('bre',$requrl);
125: if ($access eq '1') {
126: $ENV{'user.error.msg'}="$requrl:bre:0:0:Choose Course";
127: return HTTP_NOT_ACCEPTABLE;
128: }
129: if (($access ne '2') && ($access ne 'F')) {
130: $ENV{'user.error.msg'}="$requrl:bre:1:1:Access Denied";
131: return HTTP_NOT_ACCEPTABLE;
132: }
1.5 www 133: }
1.2 www 134: return OK;
1.1 albertel 135: } else {
1.5 www 136: $r->log_reason("Cookie $handle not valid", $r->filename)
1.1 albertel 137: };
138: }
1.6 www 139:
140: # ----------------------------------------------- Store where they wanted to go
141:
142: $ENV{'request.firsturl'}=$requrl;
1.1 albertel 143: return FORBIDDEN;
144: }
145:
146: 1;
147: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>