Annotation of loncom/publisher/lonunauthorized.pm, revision 1.13.2.2
1.1 www 1: # The LearningOnline Network
2: # Unauthorized to access construction space
3: #
1.13.2.2! raeburn 4: # $Id: lonunauthorized.pm,v 1.13.2.1 2011/11/14 16:05:44 raeburn Exp $
1.1 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: #
28:
29: package Apache::lonunauthorized;
30:
31: use strict;
32: use Apache::Constants qw(:common);
33: use Apache::loncommon;
34: use Apache::lonnet;
35: use Apache::loncacc;
1.2 www 36: use Apache::lonlocal;
1.6 albertel 37: use LONCAPA();
1.11 raeburn 38: use HTML::Entities();
1.1 www 39:
40: sub handler {
41: my $r = shift;
1.2 www 42: &Apache::loncommon::content_type($r,'text/html');
1.1 www 43: $r->send_http_header;
44: return OK if $r->header_only;
45:
46: # ------------------------------------------------------------ Print the screen
47: # Figure out who the user is and what they wanted to access
48:
1.13.2.1 raeburn 49: my ($ownername,$ownerdomain);
1.11 raeburn 50: if ($env{'request.editurl'} ne '') {
1.13.2.1 raeburn 51: ($ownername,$ownerdomain) =
52: &Apache::loncacc::constructaccess($env{'request.editurl'},$r->dir_config('lonDefDomain'));
1.11 raeburn 53: }
54:
55: # Breadcrumbs
56: &Apache::lonhtmlcommon::clear_breadcrumbs();
57: if ($env{'request.role'} =~ /^(au|ca|aa)/) {
58: &Apache::lonhtmlcommon::add_breadcrumb({
59: 'text' => 'Construction Space',
1.13.2.1 raeburn 60: 'href' => &Apache::loncommon::authorspace(),
1.11 raeburn 61: });
62: } elsif (($env{'request.course.id'}) &&
63: (&Apache::lonnet::allowed('mdc',$env{'request.course.id'}))) {
64: &Apache::lonhtmlcommon::add_breadcrumb({
65: 'text' => 'Course Contents',
66: 'href' => '/adm/coursedocs',
67: });
68: }
69:
1.1 www 70: # print header
1.5 albertel 71: $r->print(&Apache::loncommon::start_page("Failed Access to Construction Space",
72: undef,
1.11 raeburn 73: {'domain' => $ownerdomain,}).
74: &Apache::lonhtmlcommon::breadcrumbs());
1.1 www 75: # figure out what went wrong
76:
77: if ($ownerdomain) {
1.13.2.1 raeburn 78: my $ownerhome=&Apache::lonnet::homeserver($ownername,$ownerdomain);
1.11 raeburn 79: if ($ownerhome eq 'no_host') {
80: $r->print('<p class="LC_error">'.
81: &mt('Unable to determine home server for this resource: [_1]',
82: '<span class="LC_filename">'.$env{'request.editurl'}.'</span>').
83: '</p>');
84: } else {
85: my @hosts = &Apache::lonnet::current_machine_ids();
86: if (!grep(/^\Q$ownerhome\E$/,@hosts)) {
87: my $switchlink = '/adm/switchserver?otherserver='.$ownerhome.
88: '&origurl='.&HTML::Entities::encode($env{'request.editurl'},'<>&"');
89: $r->print('<p class="LC_warning">'.
1.13.2.1 raeburn 90: &mt('The construction space for this resource is located on another server.').
91: ' <b><tt>'.&Apache::lonnet::hostname($ownerhome).'</b></tt>'.
1.11 raeburn 92: '</p>'.
93: '<p class="LC_error"><a href="'.$switchlink.'">'.
94: &mt('Switch Server').'</a>'.
95: '</p>');
96: } else {
97: $r->print('<p class="LC_error">'.
98: &mt('You do not have authoring privileges for this resource').' '.
99: '<span class="LC_filename">'.$env{'request.editurl'}.'</span>'.
100: '</p>');
101: }
1.1 www 102: }
1.10 www 103: } elsif (!$env{'request.editurl'}) {
1.11 raeburn 104: if ($ENV{'REDIRECT_URL'} =~ m{^/adm/([^/]+)}) {
105: my $action = $1;
106: my ($option,$filename,$filename1,$filename2,$decompress,
107: $qualifiedfilename);
108: if ($ENV{'REDIRECT_QUERY_STRING'} ne '') {
109: foreach my $pair (split(/&/,$ENV{'REDIRECT_QUERY_STRING'})) {
110: my ($name,$value) = split(/=/,$pair);
111: if ($name eq 'filename') {
112: if (($action eq 'publish') || ($action eq 'cfile')) {
113: $filename = &LONCAPA::unescape($value);
114: } else {
115: $filename = $value;
116: }
117: } elsif ($name eq 'filename1') {
118: $filename1 = $value;
119: } elsif ($name eq 'filename2') {
120: $filename2 = $value;
121: } elsif ($name eq 'decompress') {
122: $decompress = $value;
123: $option = 'decompress';
124: } elsif ($name eq 'qualifiedfilename') {
125: $qualifiedfilename = $value;
1.13.2.2! raeburn 126: } elsif ($name eq 'versionone') {
1.11 raeburn 127: if ($value eq 'priv') {
128: $option = 'cstr';
129: }
130: } elsif ($name eq 'versiontwo') {
131: if ($value eq 'priv') {
132: $option = 'cstr';
133: }
134: } elsif ($name eq 'filetwo') {
135: $option = $value;
136: }
137: }
138: if (($action eq 'upload') || ($action eq 'testbank')) {
139: if (($filename1 ne '') && ($filename ne '')) {
140: $filename = $filename1.$filename2;
141: }
142: } elsif ($action eq 'cfile') {
143: if ($decompress ne '') {
144: $filename = $decompress;
145: } elsif ($qualifiedfilename ne '') {
146: $filename = $qualifiedfilename;
147: }
148: }
149: my %deniedactions = &get_denied_action_text();
150: my $warning;
151: if ($option eq 'decompress') {
152: $warning = $deniedactions{$option};
153: } else {
154: $warning = $deniedactions{$action};
155: }
156: if ($warning) {
157: if (($action eq 'diff') && ($option ne 'cstr')) {
158: $r->print('<p class="LC_error">'.
1.13 raeburn 159: $deniedactions{$action}.'</p><p class="LC_warning">'.
1.11 raeburn 160: &mt('You do not have privileges to view the published resource').' '.
161: '<span class="LC_filename">'.$filename.'</span>'.
162: '</p>');
163: } else {
164: if (($action eq 'diff') && ($option eq 'cstr')) {
1.13.2.1 raeburn 165: $filename =~ s{^/res/$LONCAPA::domain_re/($LONCAPA::username_re)}{/priv/$1};
1.11 raeburn 166: }
167: $r->print('<p class="LC_error">'.
168: $deniedactions{$action}.'</p><p class="LC_warning">'.
169: &mt('You do not have authoring privileges for this resource').' '.
170: '<span class="LC_filename">'.$filename.'</span>'.
171: '</p>');
172: }
173: } else {
174: $r->print('<p class="LC_error">'.
175: &mt('You are not permitted to take this action.').
176: '</p>');
177: }
178: }
179: } elsif ($r->uri =~ m{priv/.+\.\d+\.[^.]+$}) {
180: $r->print('<p class="LC_error">'.
181: &mt('There is a problem with the filename').' '.
182: '<span class="LC_filename">'.$r->uri.'</span></p>'.
183: '<p class="LC_warning">'.
184: &mt('You may be attempting to edit a versioned file (files in construction space may not include a version number before the extension).').
185: '</p>');
186: } else {
187: $r->print('<p class="LC_error">'.
188: &mt('You are not permitted to take this action.').
189: '</p>');
190: }
191: } elsif ($env{'request.editurl'} =~ m{priv/.+\.\d+\.[^.]+$}) {
192: $r->print('<p class="LC_error">'.
193: &mt('There is a problem with the filename').' '.
194: '<span class="LC_filename">'.$env{'request.editurl'}.'</span></p>'.
195: '<p class="LC_warning">'.
196: &mt('You may be attempting to edit a versioned file (files in construction space may not include a version number before the extension).').
197: '</p>');
1.1 www 198: } else {
1.9 bisitz 199: $r->print('<p class="LC_error">'
1.11 raeburn 200: .&mt('You do not have authoring privileges for this resource').' '
201: .'<span class="LC_filename">'.$env{'request.editurl'}.'</span>'
1.9 bisitz 202: .'</p>');
1.13.2.1 raeburn 203: my ($realownername) =
204: ($env{'request.editurl'}=~m{(?:~|priv/|home/)($LONCAPA::username_re)});
1.1 www 205: my $realownerhome=
1.13.2.1 raeburn 206: &Apache::lonnet::homeserver($realownername,
207: $r->dir_config('lonDefDomain'));
1.1 www 208: unless ($realownerhome eq 'no_host') {
1.13.2.1 raeburn 209: my $plainname=&Apache::loncommon::plainname($realownername,$r->dir_config('lonDefDomain'));
210: my $user=$realownername.':'.$r->dir_config('lonDefDomain');
1.8 bisitz 211: my $userlink=&Apache::loncommon::aboutmewrapper(
212: $plainname.' ('.$user.')'
213: ,$realownername
1.13.2.1 raeburn 214: ,$r->dir_config('lonDefDomain'));
1.8 bisitz 215: $r->print('<p>'
216: .&mt('Contact [_1] for access.',$userlink)
217: .'</p>');
1.1 www 218: }
219: }
1.5 albertel 220: $r->print(&Apache::loncommon::end_page());
1.1 www 221: return OK;
1.11 raeburn 222: }
223:
224: sub get_denied_action_text {
225: my %deniedtext =
226: &Apache::lonlocal::texthash(
227: cfile => 'Copying, moving, renaming or creating file not allowed.',
228: publish => 'Publishing not allowed.',
229: upload => 'Uploading file not allowed.',
230: testbank => 'Uploading testbank file not allowed',
231: retrieve => 'Retrieving version information not allowed.',
232: cleanup => 'Clean up of file not allowed.',
233: diff => 'Display of differences between file versions disallowed.',
234: decompress => 'Decompression of archive file disallowed.',
235: );
236: return %deniedtext;
237: }
1.1 www 238:
239: 1;
240: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>