Annotation of loncom/auth/loncacc.pm, revision 1.3
1.1 albertel 1: # The LearningOnline Network
2: # Cookie Based Access Handler for Construction Area
3: # (lonacc: 5/21/99,5/22,5/29,5/31 Gerd Kortemeyer)
1.2 www 4: # 6/15,16/11 Gerd Kortemeyer
1.1 albertel 5:
6: package Apache::loncacc;
7:
8: use strict;
9: use Apache::Constants qw(:common :http);
10: use CGI::Cookie();
11:
12: sub handler {
13: my $r = shift;
14: my $requrl=$r->uri;
15: my %cookies=CGI::Cookie->parse($r->header_in('Cookie'));
16: my $lonid=$cookies{'lonID'};
17: my $cookie;
18: if ($lonid) {
19: my $handle=$lonid->value;
20: $handle=~s/\W//g;
21: my $lonidsdir=$r->dir_config('lonIDsDir');
22: if ((-e "$lonidsdir/$handle.id") && ($handle ne '')) {
23: my $ownername=$requrl;
24: $ownername=~s/\/\~(\w+).*/\1/;
25: my $ownerdomain=$r->dir_config('lonDefDomain');
26: my @handleparts=split(/\_/,$handle);
27: my $username=$handleparts[0];
28: my $domain=$handleparts[2];
29: if (($username ne $ownername) || ($domain ne $ownerdomain)) {
30: $r->log_reason
31: ("$username at $domain not authorized", $r->filename);
32: return HTTP_NOT_ACCEPTABLE;
33: }
1.2 www 34: my @profile;
35: {
36: my $idf=Apache::File->new("$lonidsdir/$handle.id");
37: @profile=<$idf>;
38: }
39: my $envi;
40: for ($envi=0;$envi<=$#profile;$envi++) {
41: chomp($profile[$envi]);
42: my ($envname,$envvalue)=split(/=/,$profile[$envi]);
43: $r->subprocess_env("profile.$envname" => "$envvalue");
44: }
1.3 ! www 45: $r->subprocess_env("user.environment" => "$lonidsdir/$handle.id");
1.2 www 46: $r->subprocess_env("request.state" => "construct");
1.1 albertel 47: return OK;
48: } else {
49: $r->log_reason("Cookie $handle not valid", $r->filename)
50: };
51: }
52: $cookie=CGI::Cookie->new(-name => 'lonURL',
53: -value => $requrl,
54: -path => '/');
55: $r->err_headers_out->add('Set-Cookie' => $cookie);
56: return FORBIDDEN;
57: }
58:
59: 1;
60: __END__
61:
62:
63:
64:
65:
66:
67:
68:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>