Annotation of loncom/auth/publiccheck.pm, revision 1.13
1.1 albertel 1: # The LearningOnline Network
2: # Cookie Based Access Handler
3: #
1.13 ! albertel 4: # $Id: publiccheck.pm,v 1.12 2006/12/11 14:06:04 raeburn Exp $
1.1 albertel 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: #
28: ###
29:
30: package Apache::publiccheck;
31:
32: use strict;
33: use Apache::Constants qw(:common :http :methods);
34: use Apache::lonnet;
35: use Apache::loncommon();
36: use Apache::lonlocal;
37: use CGI::Cookie();
38: use Fcntl qw(:flock);
1.2 albertel 39: use Apache::lonacc();
1.13 ! albertel 40: use LONCAPA();
1.1 albertel 41:
42: sub handler {
43: my $r = shift;
1.8 albertel 44:
1.1 albertel 45: my $requrl=$r->uri;
46: my %cookies=CGI::Cookie->parse($r->header_in('Cookie'));
47: my $lonid=$cookies{'lonID'};
48: if ($lonid) {
1.11 albertel 49: my $handle=&LONCAPA::clean_handle($lonid->value);
1.1 albertel 50: my $lonidsdir=$r->dir_config('lonIDsDir');
51: if ((-e "$lonidsdir/$handle.id") && ($handle ne '')) {
52: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle);
53: if ($env{'user.name'} ne 'public'
54: && $env{'user.domain'} ne 'public') {
55: return OK;
56: }
57: }
58: }
59: if ($requrl=~m|^/public/|
1.4 albertel 60: || $requrl=~m|^/adm/help/.*\.hlp$|
1.10 albertel 61: || $requrl=~m|^/adm/[^/]+/[^/]+/aboutme/portfolio$|
1.1 albertel 62: || (&Apache::lonnet::metadata($requrl,'copyright') eq 'public')) {
1.3 raeburn 63: &process_public($r,$requrl);
1.1 albertel 64: return OK;
1.8 albertel 65: } elsif (&Apache::lonnet::is_portfolio_url($requrl)) {
1.7 albertel 66: my (undef,$udom,$unum,$file_name,$group) =
1.8 albertel 67: &Apache::lonnet::parse_portfolio_url($requrl);
1.7 albertel 68: my $access = &process_portfolio($udom,$unum,$file_name,$group);
1.5 raeburn 69: if ($access) {
70: &process_public($r,$requrl,$access);
1.3 raeburn 71: return OK;
72: }
1.5 raeburn 73: } elsif ($requrl eq '/adm/restrictedaccess') {
74: &process_public($r,$requrl);
1.8 albertel 75: return OK;
1.12 raeburn 76: } elsif ($requrl eq '/adm/blockedaccess') {
77: &process_public($r,$requrl);
78: return OK;
1.5 raeburn 79: }
1.1 albertel 80: return DECLINED;
81: }
82:
1.3 raeburn 83: sub process_public {
1.5 raeburn 84: my ($r,$requrl,$access) = @_;
1.3 raeburn 85: &Apache::lonnet::logthis('Granting public access: '.$requrl);
86: if ($env{'user.name'} ne 'public' && $env{'user.domain'} ne 'public') {
87: my $cookie=&Apache::lonauth::success($r,'public','public','public');
88: my $lonidsdir=$r->dir_config('lonIDsDir');
89: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$cookie);
1.9 albertel 90: $r->err_header_out('Set-cookie',"lonID=$cookie; path=/");
1.3 raeburn 91: }
92: &Apache::lonacc::get_posted_cgi($r);
93: $env{'request.state'} = "published";
94: $env{'request.publicaccess'} = 1;
95: $env{'request.filename'} = $r->filename;
96: return;
97: }
98:
99: sub process_portfolio {
100: my ($udom,$unum,$file_name,$group) = @_;
101: my $current_perms = &Apache::lonnet::get_portfile_permissions($udom,$unum);
102: my %access_controls = &Apache::lonnet::get_access_controls($current_perms,$group,$file_name);
1.5 raeburn 103: my $access = '';
1.3 raeburn 104: my $now = time;
105: foreach my $key (keys(%{$access_controls{$file_name}})) {
106: my ($num,$scope,$end,$start) = ($key =~ /^([^:]+):([a-z]+)_(\d*)_?(\d*)$/);
107: if ($start > $now) {
108: next;
109: }
110: if ($end && $end<$now) {
111: next;
112: }
113: if ($scope eq 'public') {
1.5 raeburn 114: $access = 'public';
1.3 raeburn 115: last;
116: }
1.5 raeburn 117: if ($scope eq 'guest') {
118: $access = 'guest';
119: }
1.3 raeburn 120: }
1.5 raeburn 121: return $access;
1.3 raeburn 122: }
123:
1.1 albertel 124: 1;
125:
126: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>