File:  [LON-CAPA] / loncom / auth / loncacc.pm
Revision 1.5: download - view: text, annotated - select for diffs
Fri Jan 14 21:12:40 2000 UTC (24 years, 4 months ago) by www
Branches: MAIN
CVS tags: LATEST, HEAD, Bacillus, Aquifex
Roles have starting and end time
Bug fixes after replication shift
New login screen
Authenticator routes to roles screen
Form variables are transfered to environment (not tested)

    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)
    4: # 6/15,16/11,22/11,
    5: # 01/06,01/11 Gerd Kortemeyer
    6: 
    7: package Apache::loncacc;
    8: 
    9: use strict;
   10: use Apache::Constants qw(:common :http);
   11: use CGI::Cookie();
   12: 
   13: sub handler {
   14:     my $r = shift;
   15:     my $requrl=$r->uri;
   16:     my %cookies=CGI::Cookie->parse($r->header_in('Cookie'));
   17:     my $lonid=$cookies{'lonID'};
   18:     my $cookie;
   19:     if ($lonid) {
   20: 	my $handle=$lonid->value;
   21:         $handle=~s/\W//g;
   22:         my $lonidsdir=$r->dir_config('lonIDsDir');
   23:         if ((-e "$lonidsdir/$handle.id") && ($handle ne '')) {
   24:             my $ownername=$requrl;
   25:             $ownername=~s/\/\~(\w+).*/\1/;
   26:             my $ownerdomain=$r->dir_config('lonDefDomain');
   27:             my @handleparts=split(/\_/,$handle);
   28:             my $username=$handleparts[0];
   29:             my $domain=$handleparts[2];
   30:             if (($username ne $ownername) || ($domain ne $ownerdomain)) {
   31:                 $r->log_reason
   32:                    ("$username at $domain not authorized", $r->filename); 
   33: 	        return HTTP_NOT_ACCEPTABLE;
   34:             }
   35:             my @profile;
   36: 	    {
   37:              my $idf=Apache::File->new("$lonidsdir/$handle.id");
   38:              @profile=<$idf>;
   39: 	    }
   40:             my $envi;
   41:             for ($envi=0;$envi<=$#profile;$envi++) {
   42: 		chomp($profile[$envi]);
   43: 		my ($envname,$envvalue)=split(/=/,$profile[$envi]);
   44:                 $r->subprocess_env("$envname" => "$envvalue");
   45:             }
   46:             $r->subprocess_env("user.environment" => "$lonidsdir/$handle.id",
   47:                                "request.state"    => "construct",
   48:                                "request.filename" => $r->filename);
   49:             my $buffer;
   50:             $r->read($buffer,$r->header_in('Content-length'));
   51:             my @pairs=split(/&/,$buffer);
   52:             my $pair; my $name; my $value;
   53:             foreach $pair (@pairs) {
   54:                ($name,$value) = split(/=/,$pair);
   55:                $r->subprocess_env("form.$name" => $value);
   56:             } 
   57:             return OK; 
   58:         } else { 
   59:             $r->log_reason("Cookie $handle not valid", $r->filename) 
   60:         };
   61:     }
   62:     $cookie=CGI::Cookie->new(-name  => 'lonURL',
   63:                              -value => $requrl, 
   64:                              -path  => '/');
   65:     $r->err_headers_out->add('Set-Cookie' => $cookie);
   66:     return FORBIDDEN;
   67: }
   68: 
   69: 1;
   70: __END__
   71: 
   72: 
   73: 
   74: 
   75: 
   76: 
   77: 
   78: 

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