Annotation of loncom/publisher/lonunauthorized.pm, revision 1.17.2.1

1.1       www         1: # The LearningOnline Network
                      2: # Unauthorized to access construction space
                      3: #
1.17.2.1! raeburn     4: # $Id: lonunauthorized.pm,v 1.17 2013/06/07 16:07:49 bisitz 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;
1.2       www        35: use Apache::lonlocal;
1.6       albertel   36: use LONCAPA();
1.11      raeburn    37: use HTML::Entities();
1.1       www        38: 
                     39: sub handler {
                     40:     my $r = shift;
1.2       www        41:     &Apache::loncommon::content_type($r,'text/html');
1.1       www        42:     $r->send_http_header;
                     43:     return OK if $r->header_only;
                     44: 
                     45: # ------------------------------------------------------------ Print the screen
                     46: # Figure out who the user is and what they wanted to access
                     47: 
1.11      raeburn    48:     my ($ownername,$ownerdomain,$ownerhome);
                     49:     if ($env{'request.editurl'} ne '') {
                     50:         ($ownername,$ownerdomain,$ownerhome) = 
1.15      raeburn    51:             &Apache::lonnet::constructaccess($env{'request.editurl'});
1.11      raeburn    52:     }
                     53: 
                     54:     # Breadcrumbs
                     55:     &Apache::lonhtmlcommon::clear_breadcrumbs();
                     56:     if ($env{'request.role'} =~ /^(au|ca|aa)/) { 
                     57:         &Apache::lonhtmlcommon::add_breadcrumb({
1.16      raeburn    58:             'text' => 'Authoring Space',
1.12      raeburn    59:             'href' => &Apache::loncommon::authorspace($env{'request.editurl'}),
1.11      raeburn    60:         });
                     61:     } elsif (($env{'request.course.id'}) && 
                     62:              (&Apache::lonnet::allowed('mdc',$env{'request.course.id'}))) {
                     63:         &Apache::lonhtmlcommon::add_breadcrumb({
                     64:             'text' => 'Course Contents',
                     65:             'href' => '/adm/coursedocs',
                     66:         });
                     67:     }
                     68: 
1.1       www        69: # print header
1.16      raeburn    70:     $r->print(&Apache::loncommon::start_page("Failed Access to Authoring Space",
1.5       albertel   71: 					     undef,
1.11      raeburn    72: 					     {'domain' => $ownerdomain,}).
                     73:                                              &Apache::lonhtmlcommon::breadcrumbs());
1.1       www        74: # figure out what went wrong
                     75: 
                     76:     if ($ownerdomain) {
1.11      raeburn    77:         if ($ownerhome eq 'no_host') {
                     78:             $r->print('<p class="LC_error">'.
                     79:                       &mt('Unable to determine home server for this resource: [_1]',
                     80:                       '<span class="LC_filename">'.$env{'request.editurl'}.'</span>').
                     81:                       '</p>');
                     82:         } else {
                     83:             my @hosts = &Apache::lonnet::current_machine_ids();
                     84:             if (!grep(/^\Q$ownerhome\E$/,@hosts)) {
                     85:                 my $switchlink = '/adm/switchserver?otherserver='.$ownerhome.
                     86:                                  '&origurl='.&HTML::Entities::encode($env{'request.editurl'},'<>&"');
                     87: 	        $r->print('<p class="LC_warning">'.
1.17      bisitz     88:                           &mt('The Authoring Space for this resource is located on a different server: [_1]',
1.11      raeburn    89:                           '<b><tt>'.&Apache::lonnet::hostname($ownerhome).'</b></tt>').
                     90:                           '</p>'.
                     91:                           '<p class="LC_error"><a href="'.$switchlink.'">'.
                     92:                           &mt('Switch Server').'</a>'.
                     93:                           '</p>');
                     94:             } else {
                     95:                 $r->print('<p class="LC_error">'.
                     96:                           &mt('You do not have authoring privileges for this resource').' '.
                     97:                           '<span class="LC_filename">'.$env{'request.editurl'}.'</span>'.
                     98:                           '</p>');
                     99:             }
1.1       www       100:         }
1.10      www       101:     } elsif (!$env{'request.editurl'}) {
1.11      raeburn   102:         if ($ENV{'REDIRECT_URL'} =~ m{^/adm/([^/]+)}) {
                    103:             my $action = $1;   
                    104:             my ($option,$filename,$filename1,$filename2,$decompress,
1.17.2.1! raeburn   105:                 $qualifiedfilename,$warning);
        !           106:             my %deniedactions = &get_denied_action_text();
1.11      raeburn   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;
1.14      raeburn   125:                     } elsif ($name eq 'versionone') {
1.11      raeburn   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') {
1.17.2.1! raeburn   134:                         $option = $value;
1.11      raeburn   135:                     }
                    136:                 }
                    137:                 if (($action eq 'upload') || ($action eq 'testbank')) {
1.17.2.1! raeburn   138:                     if (($filename1 ne '') && ($filename2 ne '')) {
1.11      raeburn   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:                 if ($option eq 'decompress') {
                    149:                     $warning = $deniedactions{$option};
                    150:                 } else {
                    151:                     $warning = $deniedactions{$action};
                    152:                 }
                    153:                 if ($warning) {
                    154:                     if (($action eq 'diff') && ($option ne 'cstr')) {
                    155:                         $r->print('<p class="LC_error">'.
1.13      raeburn   156:                                   $deniedactions{$action}.'</p><p class="LC_warning">'.
1.11      raeburn   157:                                   &mt('You do not have privileges to view the published resource').' '.
                    158:                                       '<span class="LC_filename">'.$filename.'</span>'.
                    159:                                   '</p>');
                    160:                     } else {
                    161:                         if (($action eq 'diff') && ($option eq 'cstr')) {
                    162:                             $filename =~ s{^/res/}{/priv/};
                    163:                         }
                    164:                         $r->print('<p class="LC_error">'.
                    165:                                   $deniedactions{$action}.'</p><p class="LC_warning">'.
                    166:                                   &mt('You do not have authoring privileges for this resource').' '.
                    167:                                       '<span class="LC_filename">'.$filename.'</span>'.
                    168:                                   '</p>');
                    169:                     }
                    170:                 } else {
                    171:                     $r->print('<p class="LC_error">'.
                    172:                               &mt('You are not permitted to take this action.').
                    173:                               '</p>');
                    174:                 }
1.17.2.1! raeburn   175:             } elsif (($action eq 'upload') || ($action eq 'testbank')) {
        !           176:                 $filename1 = $env{'form.filename1'};
        !           177:                 $filename2 = $env{'form.filename2'};
        !           178:                 if (($filename1 ne '') && ($filename2 ne '')) {
        !           179:                     $filename = $filename1.$filename2;
        !           180:                 }
        !           181:                 $warning = $deniedactions{$action};
        !           182:                 if ($warning) {
        !           183:                     if ($filename =~ m{^/priv/.+\.\d+\.[^.]+$}) {
        !           184:                         $r->print('<p class="LC_error">'.
        !           185:                                   &mt('There is a problem with the filename').' '.
        !           186:                                   '<span class="LC_filename">'.$filename.'</span></p>'.
        !           187:                                   '<p class="LC_warning">'.
        !           188:                                   &mt('The suggested filename may not include the pattern ".number.extension" as LON-CAPA reserves that pattern for its internal versioning mechanism.').
        !           189:                                   '</p>');
        !           190:                     } else {
        !           191:                         $r->print('<p class="LC_error">'.
        !           192:                                   $deniedactions{$action}.'</p><p class="LC_warning">'.
        !           193:                                   &mt('You do not have authoring privileges for this resource').' '.
        !           194:                                       '<span class="LC_filename">'.$filename.'</span>'.
        !           195:                                   '</p>');
        !           196:                     }
        !           197:                 } else {
        !           198:                     $r->print('<p class="LC_error">'.
        !           199:                               &mt('You are not permitted to take this action.').
        !           200:                               '</p>');
        !           201:                 }
1.11      raeburn   202:             }
                    203:         } elsif ($r->uri =~ m{priv/.+\.\d+\.[^.]+$}) {
                    204:             $r->print('<p class="LC_error">'.
                    205:                       &mt('There is a problem with the filename').' '.
                    206:                       '<span class="LC_filename">'.$r->uri.'</span></p>'.
                    207:                       '<p class="LC_warning">'.
1.17      bisitz    208:                       &mt('You may be attempting to edit a versioned file (files in Authoring Space may not include a version number before the extension).').
1.11      raeburn   209:                       '</p>');
                    210:         } else {
                    211:             $r->print('<p class="LC_error">'.
                    212:                       &mt('You are not permitted to take this action.').
                    213:                       '</p>'); 
                    214:         }
                    215:     } elsif ($env{'request.editurl'} =~ m{priv/.+\.\d+\.[^.]+$}) {
                    216:         $r->print('<p class="LC_error">'.
                    217:                   &mt('There is a problem with the filename').' '.
                    218:                   '<span class="LC_filename">'.$env{'request.editurl'}.'</span></p>'.
                    219:                   '<p class="LC_warning">'.
1.17      bisitz    220:                   &mt('You may be attempting to edit a versioned file (files in Authoring Space may not include a version number before the extension).').
1.11      raeburn   221:                   '</p>');
1.1       www       222:     } else {
1.9       bisitz    223:         $r->print('<p class="LC_error">'
1.11      raeburn   224:                  .&mt('You do not have authoring privileges for this resource').' '
                    225:                  .'<span class="LC_filename">'.$env{'request.editurl'}.'</span>'
1.9       bisitz    226:                  .'</p>');
1.11      raeburn   227:         my ($realownerdom,$realownername) =
                    228: 	    ($env{'request.editurl'}=~m{^/priv/($LONCAPA::domain_re)/($LONCAPA::username_re)});
1.1       www       229:         my $realownerhome=
1.11      raeburn   230: 	    &Apache::lonnet::homeserver($realownername,$realownerdom);
1.1       www       231:         unless ($realownerhome eq 'no_host') {
1.11      raeburn   232:             my $plainname=&Apache::loncommon::plainname($realownername,$realownerdom);
                    233:             my $user=$realownername.':'.$realownerdom;
1.8       bisitz    234:             my $userlink=&Apache::loncommon::aboutmewrapper(
                    235:                              $plainname.' ('.$user.')'
                    236:                             ,$realownername
1.11      raeburn   237:                             ,$realownerdom);
1.8       bisitz    238: 	    $r->print('<p>'
                    239:                      .&mt('Contact [_1] for access.',$userlink)
                    240:                      .'</p>');
1.1       www       241:         }
                    242:     }
1.5       albertel  243:     $r->print(&Apache::loncommon::end_page());
1.1       www       244:     return OK;
1.11      raeburn   245: }
                    246: 
                    247: sub get_denied_action_text {
                    248:     my %deniedtext = 
                    249:         &Apache::lonlocal::texthash(
                    250:            cfile      => 'Copying, moving, renaming or creating file not allowed.',
                    251:            publish    => 'Publishing not allowed.',
                    252:            upload     => 'Uploading file not allowed.',
                    253:            testbank   => 'Uploading testbank file not allowed',
                    254:            retrieve   => 'Retrieving version information not allowed.',
                    255:            cleanup    => 'Clean up of file not allowed.',
                    256:            diff       => 'Display of differences between file versions disallowed.',
                    257:            decompress => 'Decompression of archive file disallowed.',
                    258:     );
                    259:     return %deniedtext;
                    260: }
1.1       www       261: 
                    262: 1;
                    263: __END__

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