Annotation of loncom/publisher/lonunauthorized.pm, revision 1.13
1.1 www 1: # The LearningOnline Network
2: # Unauthorized to access construction space
3: #
1.13 ! raeburn 4: # $Id: lonunauthorized.pm,v 1.12 2011/11/14 02:12:42 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.11 raeburn 49: my ($ownername,$ownerdomain,$ownerhome);
50: if ($env{'request.editurl'} ne '') {
51: ($ownername,$ownerdomain,$ownerhome) =
52: &Apache::loncacc::constructaccess($env{'request.editurl'});
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.12 raeburn 60: 'href' => &Apache::loncommon::authorspace($env{'request.editurl'}),
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.11 raeburn 78: if ($ownerhome eq 'no_host') {
79: $r->print('<p class="LC_error">'.
80: &mt('Unable to determine home server for this resource: [_1]',
81: '<span class="LC_filename">'.$env{'request.editurl'}.'</span>').
82: '</p>');
83: } else {
84: my @hosts = &Apache::lonnet::current_machine_ids();
85: if (!grep(/^\Q$ownerhome\E$/,@hosts)) {
86: my $switchlink = '/adm/switchserver?otherserver='.$ownerhome.
87: '&origurl='.&HTML::Entities::encode($env{'request.editurl'},'<>&"');
88: $r->print('<p class="LC_warning">'.
89: &mt('The construction space for this resource is located on a different server: [_1]',
90: '<b><tt>'.&Apache::lonnet::hostname($ownerhome).'</b></tt>').
91: '</p>'.
92: '<p class="LC_error"><a href="'.$switchlink.'">'.
93: &mt('Switch Server').'</a>'.
94: '</p>');
95: } else {
96: $r->print('<p class="LC_error">'.
97: &mt('You do not have authoring privileges for this resource').' '.
98: '<span class="LC_filename">'.$env{'request.editurl'}.'</span>'.
99: '</p>');
100: }
1.1 www 101: }
1.10 www 102: } elsif (!$env{'request.editurl'}) {
1.11 raeburn 103: if ($ENV{'REDIRECT_URL'} =~ m{^/adm/([^/]+)}) {
104: my $action = $1;
105: my ($option,$filename,$filename1,$filename2,$decompress,
106: $qualifiedfilename);
107: if ($ENV{'REDIRECT_QUERY_STRING'} ne '') {
108: foreach my $pair (split(/&/,$ENV{'REDIRECT_QUERY_STRING'})) {
109: my ($name,$value) = split(/=/,$pair);
110: if ($name eq 'filename') {
111: if (($action eq 'publish') || ($action eq 'cfile')) {
112: $filename = &LONCAPA::unescape($value);
113: } else {
114: $filename = $value;
115: }
116: } elsif ($name eq 'filename1') {
117: $filename1 = $value;
118: } elsif ($name eq 'filename2') {
119: $filename2 = $value;
120: } elsif ($name eq 'decompress') {
121: $decompress = $value;
122: $option = 'decompress';
123: } elsif ($name eq 'qualifiedfilename') {
124: $qualifiedfilename = $value;
125: } elsif ($name = 'versionone') {
126: if ($value eq 'priv') {
127: $option = 'cstr';
128: }
129: } elsif ($name eq 'versiontwo') {
130: if ($value eq 'priv') {
131: $option = 'cstr';
132: }
133: } elsif ($name eq 'filetwo') {
134: $option = $value;
135: }
136: }
137: if (($action eq 'upload') || ($action eq 'testbank')) {
138: if (($filename1 ne '') && ($filename ne '')) {
139: $filename = $filename1.$filename2;
140: }
141: } elsif ($action eq 'cfile') {
142: if ($decompress ne '') {
143: $filename = $decompress;
144: } elsif ($qualifiedfilename ne '') {
145: $filename = $qualifiedfilename;
146: }
147: }
148: my %deniedactions = &get_denied_action_text();
149: my $warning;
150: if ($option eq 'decompress') {
151: $warning = $deniedactions{$option};
152: } else {
153: $warning = $deniedactions{$action};
154: }
155: if ($warning) {
156: if (($action eq 'diff') && ($option ne 'cstr')) {
157: $r->print('<p class="LC_error">'.
1.13 ! raeburn 158: $deniedactions{$action}.'</p><p class="LC_warning">'.
1.11 raeburn 159: &mt('You do not have privileges to view the published resource').' '.
160: '<span class="LC_filename">'.$filename.'</span>'.
161: '</p>');
162: } else {
163: if (($action eq 'diff') && ($option eq 'cstr')) {
164: $filename =~ s{^/res/}{/priv/};
165: }
166: $r->print('<p class="LC_error">'.
167: $deniedactions{$action}.'</p><p class="LC_warning">'.
168: &mt('You do not have authoring privileges for this resource').' '.
169: '<span class="LC_filename">'.$filename.'</span>'.
170: '</p>');
171: }
172: } else {
173: $r->print('<p class="LC_error">'.
174: &mt('You are not permitted to take this action.').
175: '</p>');
176: }
177: }
178: } elsif ($r->uri =~ m{priv/.+\.\d+\.[^.]+$}) {
179: $r->print('<p class="LC_error">'.
180: &mt('There is a problem with the filename').' '.
181: '<span class="LC_filename">'.$r->uri.'</span></p>'.
182: '<p class="LC_warning">'.
183: &mt('You may be attempting to edit a versioned file (files in construction space may not include a version number before the extension).').
184: '</p>');
185: } else {
186: $r->print('<p class="LC_error">'.
187: &mt('You are not permitted to take this action.').
188: '</p>');
189: }
190: } elsif ($env{'request.editurl'} =~ m{priv/.+\.\d+\.[^.]+$}) {
191: $r->print('<p class="LC_error">'.
192: &mt('There is a problem with the filename').' '.
193: '<span class="LC_filename">'.$env{'request.editurl'}.'</span></p>'.
194: '<p class="LC_warning">'.
195: &mt('You may be attempting to edit a versioned file (files in construction space may not include a version number before the extension).').
196: '</p>');
1.1 www 197: } else {
1.9 bisitz 198: $r->print('<p class="LC_error">'
1.11 raeburn 199: .&mt('You do not have authoring privileges for this resource').' '
200: .'<span class="LC_filename">'.$env{'request.editurl'}.'</span>'
1.9 bisitz 201: .'</p>');
1.11 raeburn 202: my ($realownerdom,$realownername) =
203: ($env{'request.editurl'}=~m{^/priv/($LONCAPA::domain_re)/($LONCAPA::username_re)});
1.1 www 204: my $realownerhome=
1.11 raeburn 205: &Apache::lonnet::homeserver($realownername,$realownerdom);
1.1 www 206: unless ($realownerhome eq 'no_host') {
1.11 raeburn 207: my $plainname=&Apache::loncommon::plainname($realownername,$realownerdom);
208: my $user=$realownername.':'.$realownerdom;
1.8 bisitz 209: my $userlink=&Apache::loncommon::aboutmewrapper(
210: $plainname.' ('.$user.')'
211: ,$realownername
1.11 raeburn 212: ,$realownerdom);
1.8 bisitz 213: $r->print('<p>'
214: .&mt('Contact [_1] for access.',$userlink)
215: .'</p>');
1.1 www 216: }
217: }
1.5 albertel 218: $r->print(&Apache::loncommon::end_page());
1.1 www 219: return OK;
1.11 raeburn 220: }
221:
222: sub get_denied_action_text {
223: my %deniedtext =
224: &Apache::lonlocal::texthash(
225: cfile => 'Copying, moving, renaming or creating file not allowed.',
226: publish => 'Publishing not allowed.',
227: upload => 'Uploading file not allowed.',
228: testbank => 'Uploading testbank file not allowed',
229: retrieve => 'Retrieving version information not allowed.',
230: cleanup => 'Clean up of file not allowed.',
231: diff => 'Display of differences between file versions disallowed.',
232: decompress => 'Decompression of archive file disallowed.',
233: );
234: return %deniedtext;
235: }
1.1 www 236:
237: 1;
238: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>