Annotation of loncom/auth/lonacc.pm, revision 1.82

1.1       albertel    1: # The LearningOnline Network
                      2: # Cookie Based Access Handler
1.22      www         3: #
1.82    ! albertel    4: # $Id: lonacc.pm,v 1.81 2006/06/22 13:20:46 raeburn Exp $
1.22      www         5: #
                      6: # Copyright Michigan State University Board of Trustees
                      7: #
                      8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
                      9: #
                     10: # LON-CAPA is free software; you can redistribute it and/or modify
                     11: # it under the terms of the GNU General Public License as published by
                     12: # the Free Software Foundation; either version 2 of the License, or
                     13: # (at your option) any later version.
                     14: #
                     15: # LON-CAPA is distributed in the hope that it will be useful,
                     16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
                     17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     18: # GNU General Public License for more details.
                     19: #
                     20: # You should have received a copy of the GNU General Public License
                     21: # along with LON-CAPA; if not, write to the Free Software
                     22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
                     23: #
                     24: # /home/httpd/html/adm/gpl.txt
                     25: #
                     26: # http://www.lon-capa.org/
                     27: #
1.25      harris41   28: ###
1.1       albertel   29: 
                     30: package Apache::lonacc;
                     31: 
                     32: use strict;
1.8       www        33: use Apache::Constants qw(:common :http :methods);
1.2       www        34: use Apache::File;
1.6       www        35: use Apache::lonnet;
1.25      harris41   36: use Apache::loncommon();
1.47      www        37: use Apache::lonlocal;
1.1       albertel   38: use CGI::Cookie();
1.16      www        39: use Fcntl qw(:flock);
1.1       albertel   40: 
1.75      albertel   41: sub cleanup {
                     42:     my ($r)=@_;
                     43:     if (! $r->is_initial_req()) { return DECLINED; }
                     44:     &Apache::lonnet::save_cache();
                     45:     return OK;
                     46: }
                     47: 
                     48: sub goodbye {
                     49:     my ($r)=@_;
                     50:     &Apache::lonnet::goodbye();
                     51:     return DONE;
                     52: }
                     53: 
1.76      albertel   54: ###############################################
                     55: 
                     56: sub get_posted_cgi {
                     57:     my ($r) = @_;
                     58: 
                     59:     my $buffer;
                     60:     if ($r->header_in('Content-length')) {
                     61: 	$r->read($buffer,$r->header_in('Content-length'),0);
                     62:     }
                     63:     unless ($buffer=~/^(\-+\w+)\s+Content\-Disposition\:\s*form\-data/si) {
                     64: 	my @pairs=split(/&/,$buffer);
                     65: 	my $pair;
                     66: 	foreach $pair (@pairs) {
                     67: 	    my ($name,$value) = split(/=/,$pair);
                     68: 	    $value =~ tr/+/ /;
                     69: 	    $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
                     70: 	    $name  =~ tr/+/ /;
                     71: 	    $name  =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.77      albertel   72: 	    &Apache::loncommon::add_to_env("form.$name",$value);
1.76      albertel   73: 	}
                     74:     } else {
                     75: 	my $contentsep=$1;
                     76: 	my @lines = split (/\n/,$buffer);
                     77: 	my $name='';
                     78: 	my $value='';
                     79: 	my $fname='';
                     80: 	my $fmime='';
                     81: 	my $i;
                     82: 	for ($i=0;$i<=$#lines;$i++) {
                     83: 	    if ($lines[$i]=~/^$contentsep/) {
                     84: 		if ($name) {
                     85: 		    chomp($value);
                     86: 		    if ($fname) {
                     87: 			$env{"form.$name.filename"}=$fname;
                     88: 			$env{"form.$name.mimetype"}=$fmime;
                     89: 		    } else {
                     90: 			$value=~s/\s+$//s;
                     91: 		    }
1.77      albertel   92: 		    &Apache::loncommon::add_to_env("form.$name",$value);
1.76      albertel   93: 		}
                     94: 		if ($i<$#lines) {
                     95: 		    $i++;
                     96: 		    $lines[$i]=~
                     97: 		/Content\-Disposition\:\s*form\-data\;\s*name\=\"([^\"]+)\"/i;
                     98: 		    $name=$1;
                     99: 		    $value='';
                    100: 		    if ($lines[$i]=~/filename\=\"([^\"]+)\"/i) {
                    101: 			$fname=$1;
                    102: 			if 
                    103:                             ($lines[$i+1]=~/Content\-Type\:\s*([\w\-\/]+)/i) {
                    104: 				$fmime=$1;
                    105: 				$i++;
                    106: 			    } else {
                    107: 				$fmime='';
                    108: 			    }
                    109: 		    } else {
                    110: 			$fname='';
                    111: 			$fmime='';
                    112: 		    }
                    113: 		    $i++;
                    114: 		}
                    115: 	    } else {
                    116: 		$value.=$lines[$i]."\n";
                    117: 	    }
                    118: 	}
                    119:     }
                    120: #
                    121: # Digested POSTed values
                    122: #
                    123: # Remember the way this was originally done (GET or POST)
                    124: #
                    125:     $env{'request.method'}=$ENV{'REQUEST_METHOD'};
                    126: #
                    127: # There may also be stuff in the query string
                    128: # Tell subsequent handlers that this was GET, not POST, so they can access query string.
                    129: # Also, unset POSTed content length to cover all tracks.
                    130: #
                    131: 
                    132:     $r->method_number(M_GET);
                    133: 
                    134:     $r->method('GET');
                    135:     $r->headers_in->unset('Content-length');
                    136: }
                    137: 
1.79      raeburn   138: sub portfolio_access {
                    139:     my ($udom,$unum,$file_name,$group) = @_;
                    140:     my $current_perms = &Apache::lonnet::get_portfile_permissions($udom,$unum);
                    141:     my %access_controls = &Apache::lonnet::get_access_controls(
                    142:                                              $current_perms,$group,$file_name);
1.81      raeburn   143:     my ($public,$guest,@domains,@users,@courses,@groups);
1.79      raeburn   144:     my $now = time;
                    145:     my $access_hash = $access_controls{$file_name};
                    146:     if (ref($access_hash) eq 'HASH') {
                    147:         foreach my $key (keys(%{$access_hash})) {
                    148:             my ($num,$scope,$end,$start) = ($key =~ /^([^:]+):([a-z]+)_(\d*)_?(\d*)$/);
                    149:             if ($start > $now) {
                    150:                 next;
                    151:             }
                    152:             if ($end && $end<$now) {
                    153:                 next;
                    154:             }
                    155:             if ($scope eq 'public') {
                    156:                 $public = $key;
                    157:                 last;
1.81      raeburn   158:             } elsif ($scope eq 'guest') {
                    159:                 $guest = $key;
                    160:             } elsif ($scope eq 'domains') {
                    161:                 push(@domains,$key);
                    162:             } elsif ($scope eq 'users') {
                    163:                 push(@users,$key);
                    164:             } elsif ($scope eq 'course') {
                    165:                 push(@courses,$key);
                    166:             } elsif ($scope eq 'group') {
                    167:                 push(@groups,$key);
1.79      raeburn   168:             }
                    169:         }
                    170:         if ($public) {
                    171:             return 'ok';
                    172:         }
1.81      raeburn   173:         if ($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public') {
                    174:             if ($guest) {
                    175:                 return 'guest:'.$guest;
                    176:             }
                    177:         } else {
                    178:             if (@domains > 0) {
                    179:                 foreach my $domkey (@domains) {
                    180:                     my %content = &Apache::lonnet::parse_access_controls($$access_hash{$domkey});
                    181:                     if (ref($content{'dom'}) eq 'ARRAY') {
                    182:                         if (grep(/^\Q$env{'user.domain'}\E$/,@{$content{'dom'}})) {
                    183:                             return 'ok';
                    184:                         }
                    185:                     }
                    186:                 }
                    187:             }
                    188:             if (@users > 0) {
                    189:                 foreach my $userkey (@users) {
                    190:                     my %content = &Apache::lonnet::parse_access_controls($$access_hash{$userkey});
                    191:                     if (exists($content{'users'}{$env{'user.name'}.':'.$env{'user.domain'}})) {
                    192:                         return 'ok';
                    193:                     }
                    194:                 }
                    195:             }
                    196:             my %roleshash;
                    197:             my @courses_and_groups = @courses;
                    198:             push(@courses_and_groups,@groups); 
                    199:             if (@courses_and_groups > 0) {
                    200:                 my (%allgroups,%allroles); 
                    201:                 my ($start,$end,$role,$sec,$group);
                    202:                 foreach my $envkey (%env) {
                    203:                     if ($envkey =~ m-^user\.role\.(gr|cc|in|ta|ep|st)\./([^/]+)/([^/]+)/?([^/]*)$-) {
                    204:                         my $cid = $2.'_'.$3; 
                    205:                         if ($1 eq 'gr') {
                    206:                             $group = $4;
                    207:                             $allgroups{$cid}{$group} = $env{$envkey};
                    208:                         } else {
                    209:                             if ($4 eq '') {
                    210:                                 $sec = 'none';
                    211:                             } else {
                    212:                                 $sec = $4;
                    213:                             }
                    214:                             $allroles{$cid}{$1}{$sec} = $env{$envkey};
                    215:                         }
                    216:                     } elsif ($envkey =~ m-^user\.role\./cr/(\w+/\w+/\w*)./([^/]+)/([^/]+)/?([^/]*)$-) {
                    217:                         my $cid = $2.'_'.$3;
                    218:                         if ($4 eq '') {
                    219:                             $sec = 'none';
                    220:                         } else {
                    221:                             $sec = $4;
                    222:                         }
                    223:                         $allroles{$cid}{$1}{$sec} = $env{$envkey};
                    224:                     }
                    225:                 }
                    226:                 if (keys(%allroles) == 0) {
                    227:                     return;
                    228:                 }
                    229:                 foreach my $key (@courses_and_groups) {
                    230:                     my %content = &Apache::lonnet::parse_access_controls($$access_hash{$key});
                    231:                     my $cnum = $content{'number'};
                    232:                     my $cdom = $content{'domain'};
                    233:                     my $cid = $cdom.'_'.$cnum;
                    234:                     if (!exists($allroles{$cid})) {
                    235:                         next;
                    236:                     }    
                    237:                     foreach my $role_id (keys(%{$content{'roles'}})) {
                    238:                         my @sections = @{$content{'roles'}{$role_id}{'section'}};
                    239:                         my @groups = @{$content{'roles'}{$role_id}{'group'}};
                    240:                         my @status = @{$content{'roles'}{$role_id}{'access'}};
                    241:                         my @roles = @{$content{'roles'}{$role_id}{'role'}};
                    242:                         foreach my $role (keys(%{$allroles{$cid}})) {
                    243:                             if ((grep/^all$/,@roles) || (grep/^\Q$role\E$/,@roles)) {
                    244:                                 foreach my $sec (keys(%{$allroles{$cid}{$role}})) {
                    245:                                     if (&course_group_datechecker($allroles{$cid}{$role}{$sec},$now,\@status) eq 'ok') {
                    246:                                         if (grep/^all$/,@sections) {
                    247:                                             return 'ok';
                    248:                                         } else {
                    249:                                             if (grep/^$sec$/,@sections) {
                    250:                                                 return 'ok' 
                    251:                                             }
                    252:                                         }
                    253:                                     }
                    254:                                 }
                    255:                                 if (keys(%{$allgroups{$cid}}) == 0) {
                    256:                                     if (grep/^none$/,@groups) {
                    257:                                         return 'ok';
                    258:                                     }
                    259:                                 } else {
                    260:                                     if (grep/^all$/,@groups) {
                    261:                                         return 'ok';
                    262:                                     } 
                    263:                                     foreach my $group (keys(%{$allgroups{$cid}})) {
                    264:                                         if (grep/^$group$/,@groups) {
                    265:                                             return 'ok';
                    266:                                         }
                    267:                                     }
                    268:                                 } 
                    269:                             }
                    270:                         }
                    271:                     }
                    272:                 }
                    273:             }
                    274:             if ($guest) {
                    275:                 return 'guest:'.$guest;
                    276:             }
                    277:         }
1.79      raeburn   278:     }
                    279:     return;
                    280: }
1.76      albertel  281: 
1.81      raeburn   282: sub course_group_datechecker {
                    283:     my ($dates,$now,$status) = @_;
                    284:     my ($start,$end) = split(/\./,$dates);
                    285:     if (!$start && !$end) {
                    286:         return 'ok';
                    287:     }
                    288:     if (grep/^active$/,@{$status}) {
                    289:         if (((!$start) || ($start && $start <= $now)) && ((!$end) || ($end && $end >= $now))) {
                    290:             return 'ok';
                    291:         }
                    292:     }
                    293:     if (grep/^previous$/,@{$status}) {
                    294:         if ($end > $now ) {
                    295:             return 'ok';
                    296:         }
                    297:     }
                    298:     if (grep/^future$/,@{$status}) {
                    299:         if ($start > $now) {
                    300:             return 'ok';
                    301:         }
                    302:     }
                    303:     return; 
                    304: }
                    305: 
1.1       albertel  306: sub handler {
                    307:     my $r = shift;
                    308:     my $requrl=$r->uri;
                    309:     my %cookies=CGI::Cookie->parse($r->header_in('Cookie'));
                    310:     my $lonid=$cookies{'lonID'};
                    311:     my $cookie;
1.70      albertel  312:     my $lonidsdir=$r->dir_config('lonIDsDir');
                    313: 
                    314:     my $handle;
1.1       albertel  315:     if ($lonid) {
1.70      albertel  316: 	$handle=$lonid->value;
1.1       albertel  317:         $handle=~s/\W//g;
1.70      albertel  318:     }
                    319:       
1.78      albertel  320:     my ($sso_login);
1.70      albertel  321:     if ($r->user 
                    322: 	&& (!$lonid || !-e "$lonidsdir/$handle.id" || $handle eq '') ) {
1.78      albertel  323: 	$sso_login = 1;
1.70      albertel  324: 	my $domain = $r->dir_config('lonDefDomain');
                    325: 	my $home=&Apache::lonnet::homeserver($r->user,$domain);
                    326: 	if ($home !~ /(con_lost|no_such_host)/) {
                    327: 	    $handle=&Apache::lonauth::success($r,$r->user,$domain,
                    328: 					     $home,'noredirect');
                    329: 	    $r->header_out('Set-cookie',"lonID=$handle; path=/");
                    330: 	}
                    331:     }
                    332: 
1.78      albertel  333:     if ($sso_login) {
                    334: 	&Apache::lonnet::appenv('request.sso.login' => 1);
                    335:     }
                    336: 
1.70      albertel  337:     if ($r->dir_config("lonBalancer") eq 'yes') {
                    338: 	$r->set_handlers('PerlResponseHandler'=>
                    339: 			 [\&Apache::switchserver::handler]);
                    340:     }
                    341: 
                    342:     if ($handle ne '') {
1.1       albertel  343:         if ((-e "$lonidsdir/$handle.id") && ($handle ne '')) {
1.6       www       344: 
1.46      www       345: # ------------------------------------------------------ Initialize Environment
                    346: 
                    347:             &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle);
1.47      www       348: 
                    349: # --------------------------------------------------------- Initialize Language
                    350: 
1.48      www       351: 	    &Apache::lonlocal::get_language_handle($r);
1.46      www       352: 
                    353: # -------------------------------------------------------------- Resource State
1.6       www       354: 
1.51      albertel  355:             if ($requrl=~/^\/+(res|uploaded)\//) {
1.64      albertel  356:                $env{'request.state'} = "published";
1.17      www       357: 	    } else {
1.64      albertel  358: 	       $env{'request.state'} = 'unknown';
1.17      www       359:             }
1.64      albertel  360:             $env{'request.filename'} = $r->filename;
                    361:             $env{'request.noversionuri'} = &Apache::lonnet::deversion($requrl);
1.6       www       362: # -------------------------------------------------------- Load POST parameters
                    363: 
1.76      albertel  364: 	    &Apache::lonacc::get_posted_cgi($r);
1.6       www       365: 
                    366: # ---------------------------------------------------------------- Check access
1.79      raeburn   367:             my $now = time;
1.80      albertel  368:             if ($requrl =~ m|/+uploaded/([^/]+)/([^/]+)/portfolio(/.+)$|) {
1.79      raeburn   369:                 my $result = &portfolio_access($1,$2,$3);
                    370:                 if ($result eq 'ok') {
                    371:                     return OK;
1.81      raeburn   372:                 } elsif ($result =~ /^guest:(\w+)$/) {
                    373:                     my $guestkey = $1;
                    374:                     #FIXME need to cause generation of an intermediate page
1.79      raeburn   375:                 }
1.80      albertel  376:             } elsif ($requrl =~ m|/+uploaded/([^/]+)/([^/]+)/groups/([^/]+)/portfolio/(.+)$|) {
1.81      raeburn   377:                 my $result = &portfolio_access($1,$2,$3.'/'.$4,$3);
1.79      raeburn   378:                 if ($result eq 'ok') {
                    379:                     return OK;
1.81      raeburn   380:                 } elsif ($result =~ /^guest:(\w+)$/) {
                    381:                     my $guestkey = $1;
                    382:                     #FIXME need to cause generation of an intermediate page
                    383: }
1.79      raeburn   384:             }
1.37      albertel  385:             if ($requrl!~/^\/adm|public|prtspool\//) {
1.7       www       386: 		my $access=&Apache::lonnet::allowed('bre',$requrl);
                    387:                 if ($access eq '1') {
1.64      albertel  388: 		   $env{'user.error.msg'}="$requrl:bre:0:0:Choose Course";
1.7       www       389: 	           return HTTP_NOT_ACCEPTABLE; 
                    390:                 }
                    391:                 if (($access ne '2') && ($access ne 'F')) {
1.64      albertel  392: 		   $env{'user.error.msg'}="$requrl:bre:1:1:Access Denied";
1.7       www       393: 	           return HTTP_NOT_ACCEPTABLE; 
                    394:                 }
1.23      www       395:             }
1.37      albertel  396: 	    if ($requrl =~ m|^/prtspool/|) {
1.64      albertel  397: 		my $start='/prtspool/'.$env{'user.name'}.'_'.
                    398: 		    $env{'user.domain'};
1.37      albertel  399: 		if ($requrl !~ /^\Q$start\E/) {
1.64      albertel  400: 		    $env{'user.error.msg'}="$requrl:bre:1:1:Access Denied";
1.37      albertel  401: 		    return HTTP_NOT_ACCEPTABLE;
                    402: 		}
                    403: 	    }
1.67      albertel  404: 	    if ($env{'user.name'} eq 'public' && 
                    405: 		$env{'user.domain'} eq 'public' &&
                    406: 		$requrl !~ m{^/+(res|public)/} &&
1.69      www       407: 		$requrl !~ m{^/+adm/(help|logout|randomlabel\.png)}) {
1.67      albertel  408: 		$env{'request.querystring'}=$r->args;
                    409: 		$env{'request.firsturl'}=$requrl;
                    410: 		return FORBIDDEN;
                    411: 	    }
1.23      www       412: # ------------------------------------------------------------- This is allowed
1.64      albertel  413:           if ($env{'request.course.id'}) {
1.24      www       414: 	    &Apache::lonnet::countacc($requrl);
1.23      www       415:             $requrl=~/\.(\w+)$/;
1.39      www       416:             if ((&Apache::loncommon::fileembstyle($1) eq 'ssi') ||
1.44      www       417:  ($requrl=~/^\/adm\/.*\/(aboutme|navmaps|smppg|bulletinboard)(\?|$)/) ||
                    418:  ($requrl=~/^\/adm\/wrapper\//) ||
1.72      albertel  419:  ($requrl=~m|^/adm/coursedocs/showdoc/|) ||
1.53      albertel  420:  ($requrl=~m|\.problem/smpedit$|) ||
1.39      www       421:  ($requrl=~/^\/public\/.*\/syllabus$/)) {
1.23      www       422: # ------------------------------------- This is serious stuff, get symb and log
1.29      www       423: 		my $query=$r->args;
                    424:                 my $symb;
                    425:                 if ($query) {
                    426: 		    &Apache::loncommon::get_unprocessed_cgi($query,['symb']);
                    427:                 }
1.64      albertel  428:                 if ($env{'form.symb'}) {
                    429: 		    $symb=&Apache::lonnet::symbclean($env{'form.symb'});
1.72      albertel  430:                     if ($requrl =~ m|^/adm/wrapper/|
                    431: 			|| $requrl =~ m|^/adm/coursedocs/showdoc/|) {
1.52      raeburn   432:                         my ($map,$mid,$murl)=&Apache::lonnet::decode_symb($symb);
1.63      albertel  433:                         &Apache::lonnet::symblist($map,$murl => [$murl,$mid],
                    434: 						  'last_known' =>[$murl,$mid]);
1.53      albertel  435:                     } elsif ((&Apache::lonnet::symbverify($symb,$requrl)) ||
                    436: 			     (($requrl=~m|(.*)/smpedit$|) &&
                    437: 			      &Apache::lonnet::symbverify($symb,$1))) {
1.50      albertel  438:                       my ($map,$mid,$murl)=&Apache::lonnet::decode_symb($symb);
1.74      albertel  439: 		      &Apache::lonnet::symblist($map,$murl => [$murl,$mid],
1.63      albertel  440: 						'last_known' =>[$murl,$mid]);
1.31      www       441: 		    } else {
                    442: 			$r->log_reason('Invalid symb for '.$requrl.': '.
                    443:                                        $symb);
1.64      albertel  444: 		        $env{'user.error.msg'}=
1.31      www       445:                                 "$requrl:bre:1:1:Invalid Access";
                    446:   	                return HTTP_NOT_ACCEPTABLE; 
                    447:                     }
1.29      www       448:                 } else {
1.44      www       449: 	            $symb=&Apache::lonnet::symbread($requrl);
1.58      albertel  450: 		    if (&Apache::lonnet::is_on_map($requrl) && $symb &&
1.56      albertel  451: 			!&Apache::lonnet::symbverify($symb,$requrl)) {
1.58      albertel  452: 			$r->log_reason('Invalid symb for '.$requrl.': '.$symb);
1.64      albertel  453: 		        $env{'user.error.msg'}=
1.55      albertel  454:                                 "$requrl:bre:1:1:Invalid Access";
                    455:   	                return HTTP_NOT_ACCEPTABLE; 
                    456: 		    }
1.61      albertel  457: 		    if ($symb) {
1.65      albertel  458: 			my ($map,$mid,$murl)=
                    459: 			    &Apache::lonnet::decode_symb($symb);
1.63      albertel  460: 			&Apache::lonnet::symblist($map,$murl =>[$murl,$mid],
                    461: 						'last_known' =>[$murl,$mid]);
1.61      albertel  462: 		    }
1.29      www       463:                 }
1.64      albertel  464:                 $env{'request.symb'}=$symb;
1.23      www       465:                 &Apache::lonnet::courseacclog($symb);
                    466:             } else {
                    467: # ------------------------------------------------------- This is other content
                    468:                 &Apache::lonnet::courseacclog($requrl);    
                    469:             }
                    470: 	  }
1.2       www       471:             return OK; 
1.1       albertel  472:         } else { 
1.73      raeburn   473:             $r->log_reason("Cookie $handle not valid", $r->filename); 
                    474:         }
1.1       albertel  475:     }
1.6       www       476: 
1.21      www       477: # -------------------------------------------- See if this is a public resource
1.37      albertel  478:     if ($requrl=~m|^/public/|
                    479: 	|| (&Apache::lonnet::metadata($requrl,'copyright') eq 'public')) {
1.21      www       480:         &Apache::lonnet::logthis('Granting public access: '.$requrl);
1.71      www       481:         &Apache::lonlocal::get_language_handle($r);
1.66      albertel  482: 	my $cookie=
                    483: 	    &Apache::lonauth::success($r,'public','public','public');
                    484:         my $lonidsdir=$r->dir_config('lonIDsDir');
                    485: 	&Apache::lonnet::transfer_profile_to_env($lonidsdir,$cookie);
1.76      albertel  486: 	&Apache::lonacc::get_posted_cgi($r);
1.64      albertel  487:         $env{'request.state'} = "published";
                    488:         $env{'request.publicaccess'} = 1;
                    489:         $env{'request.filename'} = $r->filename;
1.59      albertel  490: 
1.66      albertel  491: 	$r->header_out('Set-cookie',"lonID=$cookie; path=/");
1.21      www       492:         return OK;
                    493:     }
1.68      albertel  494:     if ($requrl=~m|^/+adm/+help/+|) {
                    495: 	return OK;
                    496:     }
1.79      raeburn   497: # ------------------------------------- See if this is a viewable portfolio file
1.80      albertel  498:     if ($requrl =~ m|/+uploaded/([^/]+)/([^/]+)/portfolio(/.+)$|) {
1.79      raeburn   499:         my $result = &portfolio_access($1,$2,$3);
                    500:         if ($result eq 'ok') {
                    501:             return OK;
1.81      raeburn   502:         } elsif ($result =~ /^guest:(\w+)$/) {
                    503:             my $guestkey = $1;
                    504:             #FIXME need to cause generation of an intermediate page
1.79      raeburn   505:         }
1.80      albertel  506:     } elsif ($requrl =~ m|/+uploaded/([^/]+)/([^/]+)/groups/([^/]+)/portfolio/(.+)$|) {
1.82    ! albertel  507:         my $result = &portfolio_access($1,$2,$3.'/'.$4,$3);
1.79      raeburn   508:         if ($result eq 'ok') {
                    509:             return OK;
1.81      raeburn   510:         } elsif ($result =~ /^guest:(\w+)$/) {
                    511:             my $guestkey = $1;
                    512:             #FIXME need to cause generation of an intermediate page
1.79      raeburn   513:         }
                    514:     }
1.34      www       515: # -------------------------------------------------------------- Not authorized
                    516:     $requrl=~/\.(\w+)$/;
1.62      albertel  517: #    if ((&Apache::loncommon::fileembstyle($1) eq 'ssi') ||
                    518: #        ($requrl=~/^\/adm\/(roles|logout|email|menu|remote)/) ||
                    519: #        ($requrl=~m|^/prtspool/|)) {
1.34      www       520: # -------------------------- Store where they wanted to go and get login screen
1.64      albertel  521: 	$env{'request.querystring'}=$r->args;
                    522: 	$env{'request.firsturl'}=$requrl;
1.34      www       523:        return FORBIDDEN;
1.62      albertel  524: #   } else {
1.34      www       525: # --------------------------------------------------------------------- Goodbye
1.62      albertel  526: #       return HTTP_BAD_REQUEST;
                    527: #   }
1.1       albertel  528: }
                    529: 
                    530: 1;
                    531: __END__
1.25      harris41  532: 
                    533: =head1 NAME
                    534: 
                    535: Apache::lonacc - Cookie Based Access Handler
                    536: 
                    537: =head1 SYNOPSIS
                    538: 
                    539: Invoked (for various locations) by /etc/httpd/conf/srm.conf:
                    540: 
                    541:  PerlAccessHandler       Apache::lonacc
                    542: 
                    543: =head1 INTRODUCTION
                    544: 
                    545: This module enables cookie based authentication and is used
                    546: to control access for many different LON-CAPA URIs.
                    547: 
                    548: Whenever the client sends the cookie back to the server, 
                    549: this cookie is handled by either lonacc.pm or loncacc.pm
                    550: (see srm.conf for what is invoked when).  If
                    551: the cookie is missing or invalid, the user is re-challenged
                    552: for login information.
                    553: 
                    554: This is part of the LearningOnline Network with CAPA project
                    555: described at http://www.lon-capa.org.
                    556: 
                    557: =head1 HANDLER SUBROUTINE
                    558: 
                    559: This routine is called by Apache and mod_perl.
                    560: 
                    561: =over 4
                    562: 
                    563: =item *
                    564: 
                    565: transfer profile into environment
                    566: 
                    567: =item *
                    568: 
                    569: load POST parameters
                    570: 
                    571: =item *
                    572: 
                    573: check access
                    574: 
                    575: =item *
                    576: 
                    577: if allowed, get symb, log, generate course statistics if applicable
                    578: 
                    579: =item *
                    580: 
                    581: otherwise return error
                    582: 
                    583: =item *
                    584: 
                    585: see if public resource
                    586: 
                    587: =item *
                    588: 
                    589: store attempted access
                    590: 
                    591: =back
                    592: 
                    593: =cut

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