Annotation of loncom/publisher/lonupload.pm, revision 1.52

1.12      foxr        1: 
1.1       www         2: # The LearningOnline Network with CAPA
                      3: # Handler to upload files into construction space
                      4: #
1.52    ! www         5: # $Id: lonupload.pm,v 1.51 2010/11/28 00:04:10 raeburn Exp $
1.8       matthew     6: #
                      7: # Copyright Michigan State University Board of Trustees
                      8: #
                      9: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
                     10: #
                     11: # LON-CAPA is free software; you can redistribute it and/or modify
                     12: # it under the terms of the GNU General Public License as published by
                     13: # the Free Software Foundation; either version 2 of the License, or
                     14: # (at your option) any later version.
                     15: #
                     16: # LON-CAPA is distributed in the hope that it will be useful,
                     17: # but WITHOUT ANY WARRANTY; without even the implied warranty of
                     18: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     19: # GNU General Public License for more details.
                     20: #
                     21: # You should have received a copy of the GNU General Public License
                     22: # along with LON-CAPA; if not, write to the Free Software
                     23: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
                     24: #
                     25: # /home/httpd/html/adm/gpl.txt
                     26: #
                     27: # http://www.lon-capa.org/
                     28: #
1.10      harris41   29: ###
1.1       www        30: 
1.39      jms        31: =head1 NAME
                     32: 
                     33: Apache::lonupload - upload files into construction space
                     34: 
                     35: =head1 SYNOPSIS
                     36: 
                     37: Invoked by /etc/httpd/conf/srm.conf:
                     38: 
                     39:  <Location /adm/upload>
                     40:  PerlAccessHandler       Apache::lonacc
                     41:  SetHandler perl-script
                     42:  PerlHandler Apache::lonupload
                     43:  ErrorDocument     403 /adm/login
                     44:  ErrorDocument     404 /adm/notfound.html
                     45:  ErrorDocument     406 /adm/unauthorized.html
                     46:  ErrorDocument	  500 /adm/errorhandler
                     47:  </Location>
                     48: 
                     49: =head1 INTRODUCTION
                     50: 
                     51: This module uploads a file sitting on a client computer into 
                     52: library server construction space.
                     53: 
                     54: This is part of the LearningOnline Network with CAPA project
                     55: described at http://www.lon-capa.org.
                     56: 
                     57: =head1 HANDLER SUBROUTINE
                     58: 
                     59: This routine is called by Apache and mod_perl.
                     60: 
                     61: =over 4
                     62: 
                     63: =item *
                     64: 
                     65: Initialize variables
                     66: 
                     67: =item *
                     68: 
                     69: Start page output
                     70: 
                     71: =item *
                     72: 
1.51      raeburn    73: output relevant interface phase (phaseone, phasetwo, phasethree or phasefour)
1.39      jms        74: 
                     75: =item *
                     76: 
                     77: (phase one is to specify upload file; phase two is to handle conditions
                     78: subsequent to specification--like overwriting an existing file; phase three
                     79: is to handle processing of secondary uploads - of embedded objects in an
                     80: html file).
                     81: 
                     82: =back
                     83: 
                     84: =head1 OTHER SUBROUTINES
                     85: 
1.40      jms        86: =over
1.39      jms        87: 
1.40      jms        88: =item phaseone()
1.39      jms        89: 
1.40      jms        90: Interface for specifying file to upload.
1.39      jms        91: 
1.40      jms        92: =item phasetwo()
1.39      jms        93: 
1.40      jms        94: Interface for handling post-conditions about uploading (such
1.39      jms        95: as overwriting an existing file).
                     96: 
1.40      jms        97: =item phasethree()
1.39      jms        98: 
1.40      jms        99: Interface for handling secondary uploads of embedded objects
1.39      jms       100: in an html file.
                    101: 
1.51      raeburn   102: =item phasefour()
                    103: 
                    104: Interface for handling optional renaming of links to embedded
                    105: objects. 
                    106: 
1.40      jms       107: =item upfile_store()
1.39      jms       108: 
1.40      jms       109: Store contents of uploaded file into temporary space.  Invoked
1.39      jms       110: by phaseone subroutine.
                    111: 
1.40      jms       112: =item check_extension()
1.39      jms       113: 
1.40      jms       114: Checks if filename extension is permitted and checks type
1.39      jms       115:  of file - if html file, calls parser to check for embedded objects.
                    116:  Invoked by phasetwo subroutine.
                    117: 
                    118: =back
                    119: 
                    120: =cut
                    121: 
1.1       www       122: package Apache::lonupload;
                    123: 
                    124: use strict;
                    125: use Apache::File;
                    126: use File::Copy;
1.13      foxr      127: use File::Basename;
1.1       www       128: use Apache::Constants qw(:common :http :methods);
1.3       www       129: use Apache::loncacc;
1.10      harris41  130: use Apache::loncommon();
1.13      foxr      131: use Apache::lonnet;
1.14      foxr      132: use HTML::Entities();
1.20      www       133: use Apache::lonlocal;
1.29      albertel  134: use Apache::lonnet;
1.34      albertel  135: use LONCAPA();
1.12      foxr      136: 
                    137: my $DEBUG=0;
                    138: 
                    139: sub Debug {
1.30      albertel  140:     # Put out the indicated message but only if DEBUG is true.
1.22      albertel  141:     if ($DEBUG) {
1.30      albertel  142: 	my ($r,$message) = @_;
                    143: 	$r->log_reason($message);
1.22      albertel  144:     }
1.12      foxr      145: }
1.1       www       146: 
1.2       www       147: sub upfile_store {
                    148:     my $r=shift;
                    149: 	
1.29      albertel  150:     my $fname=$env{'form.upfile.filename'};
1.2       www       151:     $fname=~s/\W//g;
                    152:     
1.29      albertel  153:     chomp($env{'form.upfile'});
1.1       www       154:   
1.29      albertel  155:     my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
1.2       www       156: 		  '_upload_'.$fname.'_'.time.'_'.$$;
                    157:     {
                    158:        my $fh=Apache::File->new('>'.$r->dir_config('lonDaemons').
                    159:                                    '/tmp/'.$datatoken.'.tmp');
1.29      albertel  160:        print $fh $env{'form.upfile'};
1.1       www       161:     }
1.2       www       162:     return $datatoken;
                    163: }
                    164: 
                    165: sub phaseone {
1.25      raeburn   166:     my ($r,$fn,$uname,$udom,$mode)=@_;
                    167:     my $action = '/adm/upload';
                    168:     if ($mode eq 'testbank') {
                    169:         $action = '/adm/testbank';
                    170:     } elsif ($mode eq 'imsimport') {
                    171:         $action = '/adm/imsimport';
                    172:     }
1.49      bisitz    173: 
                    174:     # Check for file to be uploaded
1.29      albertel  175:     $env{'form.upfile.filename'}=~s/\\/\//g;
                    176:     $env{'form.upfile.filename'}=~s/^.*\/([^\/]+)$/$1/;
1.49      bisitz    177:     if (!$env{'form.upfile.filename'}) {
                    178:         $r->print('<p class="LC_warning">'.&mt('No upload file specified.').'</p>');
                    179:         return;
                    180:     }
                    181: 
                    182:     $fn=~s/\/[^\/]+$//;
                    183:     $fn=~s/([^\/])$/$1\//;
                    184:     $fn.=$env{'form.upfile.filename'};
                    185:     $fn=~s/^\///;
                    186:     $fn=~s/(\/)+/\//g;
                    187:     #    Fn is the full path to the destination filename.
                    188: 
                    189:     # Check for illegal filename
                    190:     &Debug($r, "Filename for upload: $fn");
                    191:     if (!(($fn) && ($fn!~/\/$/))) {
                    192:         $r->print('<p class="LC_warning">'.&mt('Illegal filename.').'</p>');
                    193:         return;
                    194:     }
                    195: 
                    196:     # Display additional options for upload
                    197:     # and upload button
                    198:     $r->print(
                    199:         '<form action="'.$action.'" method="post" name="fileupload">'
                    200:        .'<input type="hidden" name="phase" value="two" />'
                    201:        .'<input type="hidden" name="datatoken" value="'.&upfile_store.'" />'
                    202:        .'<input type="hidden" name="uploaduname" value="'.$uname.'" />'
                    203:     );
                    204:     $r->print(
                    205:         &Apache::lonhtmlcommon::start_pick_box()
                    206:        .&Apache::lonhtmlcommon::row_title(&mt('Save uploaded file as'))
                    207:        .'<span class="LC_filename">/priv/'.$uname.'/</span>'
                    208:        .'<input type="text" size="50" name="filename" value="'.$fn.'" />'
                    209:        .&Apache::lonhtmlcommon::row_closure()
                    210:        .&Apache::lonhtmlcommon::row_title(&mt('File Type'))
                    211:        .'<select name="filetype">'
                    212:        .'<option value="standard" selected="selected">'.&mt('Regular file').'</option>'
                    213:        .'<option value="testbank">'.&mt('Testbank file').'</option>'
                    214:        .'<option value="imsimport">'.&mt('IMS package').'</option>'
                    215:        .'</select>'.&Apache::loncommon::help_open_topic("Uploading_File_Options")
                    216:        .&Apache::lonhtmlcommon::row_closure(1)
                    217:        .&Apache::lonhtmlcommon::end_pick_box()
                    218:     );
                    219:     $r->print(
                    220:         '<p>'
                    221:        .'<input type="button" value="'.&mt('Upload').'" onclick="javascript:verifyForm()"/>'
                    222:        .'</p>'
                    223:        .'</form>'
                    224:     );
1.13      foxr      225: 
1.49      bisitz    226:    # Check for bad extension and warn user
                    227:     if ($fn=~/\.(\w+)$/ && 
                    228:         (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.41      bisitz    229:                 $r->print('<p class="LC_error">'
1.49      bisitz    230:                           .&mt('The extension on this file, [_1], is reserved internally by LON-CAPA.',
                    231:                                '<span class="LC_filename">'.$1.'</span>')
1.41      bisitz    232:                           .' <br />'.&mt('Please change the extension.')
                    233:                           .'</p>');
1.49      bisitz    234:     } elsif($fn=~/\.(\w+)$/ && 
                    235:                     !defined(&Apache::loncommon::fileembstyle($1))) {
1.41      bisitz    236:                 $r->print('<p class="LC_error">'
1.49      bisitz    237:                          .&mt('The extension on this file, [_1], is not recognized by LON-CAPA.',
                    238:                               '<span class="LC_filename">'.$1.'</span>')
1.41      bisitz    239:                          .' <br />'.&mt('Please change the extension.')
                    240:                          .'</p>');
1.22      albertel  241:     }
1.1       www       242: }
                    243: 
                    244: sub phasetwo {
1.25      raeburn   245:     my ($r,$tfn,$uname,$udom,$mode)=@_;
1.37      raeburn   246:     my $output;
1.25      raeburn   247:     my $action = '/adm/upload';
                    248:     my $returnflag = '';
                    249:     if ($mode eq 'testbank') {
                    250:         $action = '/adm/testbank';
                    251:     } elsif ($mode eq 'imsimport') {
                    252:         $action = '/adm/imsimport';
                    253:     }
1.22      albertel  254:     my $fn='/priv/'.$uname.'/'.$tfn;
                    255:     $fn=~s/\/+/\//g;
                    256:     &Debug($r, "Filename is ".$tfn);
                    257:     if ($tfn) {
                    258: 	&Debug($r, "Filename for tfn = ".$tfn);
                    259: 	my $target='/home/'.$uname.'/public_html'.$tfn;
                    260: 	&Debug($r, "target -> ".$target);
1.13      foxr      261: #     target is the full filesystem path of the destination file.
1.22      albertel  262: 	my $base = &File::Basename::basename($fn);
                    263: 	my $path = &File::Basename::dirname($fn);
1.26      albertel  264: 	$base    = &HTML::Entities::encode($base,'<>&"');
1.22      albertel  265: 	my $url  = $path."/".$base; 
                    266: 	&Debug($r, "URL is now ".$url);
1.29      albertel  267: 	my $datatoken=$env{'form.datatoken'};
1.22      albertel  268: 	if (($fn) && ($datatoken)) {
1.36      www       269:             if ($env{'form.cancel'}) {
                    270:                 my $source=$r->dir_config('lonDaemons').'/tmp/'.$datatoken.'.tmp';
                    271:                 my $dirpath=$path.'/';
                    272:                 $dirpath=~s/\/+/\//g;
1.49      bisitz    273:                 $output .= '<p class="LC_warning">'.&mt('Upload cancelled.').'</p>'
                    274:                           .'<p><a href="'.$dirpath.'">'.
                    275:                           &mt('Back to Directory').'</a></p>';
                    276:             } elsif ((-e $target) && (!$env{'form.override'})) {
                    277:                 $output .= '<form action="'.$action.'" method="post">'
                    278:                           .'<p class="LC_warning">'
                    279:                           .&mt('File [_1] already exists.',
                    280:                                '<span class="LC_filename">'.$fn.'</span>')
                    281:                          .'<input type="hidden" name="phase" value="two" />'
                    282:                          .'<input type="hidden" name="filename" value="'.$url.'" />'
                    283:                          .'<input type="hidden" name="datatoken" value="'.$datatoken.'" />'
                    284:                          .'<p>'
                    285:                          .'<input type="submit" name="cancel" value="'.&mt('Cancel').'" />'
                    286:                          .' <input type="submit" name="override" value="'.&mt('Overwrite').'" />'
                    287:                          .'</p>'
                    288:                          .'</form>';
1.36      www       289:             } else {
1.22      albertel  290: 		my $source=$r->dir_config('lonDaemons').'/tmp/'.$datatoken.'.tmp';
1.27      www       291: 		my $dirpath=$path.'/';
                    292: 		$dirpath=~s/\/+/\//g;
1.22      albertel  293: 		# Check for bad extension and disallow upload
1.37      raeburn   294:                 my $result;
                    295:                 ($result,$returnflag) = &check_extension($fn,$mode,$source,$target,$action,$dirpath,$url);
                    296:                 $output .= $result;
1.22      albertel  297: 	    }
                    298: 	} else {
1.37      raeburn   299: 	    $output .= '<span class="LC_error">'.
1.22      albertel  300: 		      &mt('Please use browser "Back" button and pick a filename').
1.37      raeburn   301: 		      '</span><br />';
1.22      albertel  302: 	}
1.1       www       303:     } else {
1.37      raeburn   304: 	$output .= '<span class="LC_error">'.
                    305: 		   &mt('Please use browser "Back" button and pick a filename').
                    306: 		   '</span><br />';
                    307:     }
                    308:     return ($output,$returnflag);
                    309: }
                    310: 
                    311: sub check_extension {
                    312:     my ($fn,$mode,$source,$target,$action,$dirpath,$url) = @_;
                    313:     my ($result,$returnflag);
                    314:     # Check for bad extension and disallow upload
                    315:     if ($fn=~/\.(\w+)$/ &&
                    316:         (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.49      bisitz    317:         $result .= '<p class="LC_warning">'.
                    318:                    &mt('File [_1] could not be copied.',
                    319:                        '<span class="LC_filename">'.$fn.'</span> ').
                    320:                    '<br />'.
                    321:                    &mt('The extension on this file is reserved internally by LON-CAPA.').
                    322:                    '</p>';
1.37      raeburn   323:     } elsif ($fn=~/\.(\w+)$/ &&
                    324:              !defined(&Apache::loncommon::fileembstyle($1))) {
1.49      bisitz    325:         $result .= '<p class="LC_warning">'.
                    326:                    &mt('File [_1] could not be copied.',
                    327:                        '<span class="LC_filename">'.$fn.'</span> ').
                    328:                    '<br />'.
                    329:                    &mt('The extension on this file is not recognized by LON-CAPA.').
                    330:                    '</p>';
1.37      raeburn   331:     } elsif (-d $target) {
1.49      bisitz    332:         $result .= '<p class="LC_warning">'.
                    333:                    &mt('File [_1] could not be copied.',
                    334:                        '<span class="LC_filename">'.$fn.'</span>').
                    335:                    '<br />'.
                    336:                    &mt('The target is an existing directory.').
                    337:                    '</p>';
1.37      raeburn   338:     } elsif (copy($source,$target)) {
                    339:         chmod(0660, $target); # Set permissions to rw-rw---.
                    340:         if ($mode eq 'testbank' || $mode eq 'imsimport') {
                    341:             $returnflag = 'ok';
1.49      bisitz    342:             $result .= '<p class="LC_success">'
                    343:                       .&mt('Your file - [_1] - was uploaded successfully.',
                    344:                            '<span class="LC_filename">'.$fn.'<span>')
                    345:                       .'</p>';
1.37      raeburn   346:         } else {
1.49      bisitz    347:             $result .= '<p class="LC_success">'
                    348:                       .&mt('File copied.')  
                    349:                       .'</p>';
1.37      raeburn   350:         }
                    351:         # Check for embedded objects.
                    352:         my (%allfiles,%codebase);
                    353:         my ($text,$header,$css,$js);
                    354:         if (($mode ne 'imsimport') && ($target =~ /\.(htm|html|shtml)$/i)) {
                    355:             my (%allfiles,%codebase);
                    356:             &Apache::lonnet::extract_embedded_items($target,\%allfiles,\%codebase);
                    357:             if (keys(%allfiles) > 0) {
1.50      raeburn   358:                 my ($currentpath) = ($url =~ m{^(.+)/[^/]+$});
1.51      raeburn   359:                 my $state = &embedded_form_elems('upload_embedded',$url,$mode);
                    360:                 my ($embedded,$num,$pathchg) = 
                    361:                     &Apache::loncommon::ask_for_embedded_content($action,$state,\%allfiles,
                    362:                                                                  \%codebase,
                    363:                                                                  {'error_on_invalid_names'   => 1,
                    364:                                                                   'ignore_remote_references' => 1,
                    365:                                                                   'current_path'             => $currentpath});
1.50      raeburn   366:                 if ($embedded) {
1.51      raeburn   367:                     $result .= '<h3>'.&mt('Reference Warning').'</h3>';
                    368:                     if ($num) {
                    369:                         $result .= '<p>'.&mt('Completed upload of the file.').' '.&mt('This file contained references to other files.').'</p>'.
                    370:                                    '<p>'.&mt('Please select the locations from which the referenced files are to be uploaded.').'</p>'.
                    371:                                    $embedded;
                    372:                         if ($mode eq 'testbank') {
                    373:                             $returnflag = 'embedded';
                    374:                             $result .=  '<p>'.&mt('Or [_1]continue[_2] the testbank import without these files.','<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
                    375:                         }
                    376:                     } else {
                    377:                         $result .= '<p>'.&mt('Completed upload of the file.').'</p>'.$embedded;
                    378:                         if ($pathchg) {
                    379:                             if ($mode eq 'testbank') {
                    380:                                 $returnflag = 'embedded';
                    381:                                 $result .=  '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the references(s).','<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
                    382:                             }
                    383:                         }
                    384:                     }
1.37      raeburn   385:                 }
                    386:             }
                    387:         }
                    388:         if (($mode ne 'imsimport') && ($mode ne 'testbank')) {
1.49      bisitz    389:             $result .= '<br /><a href="'.$url.'">'.
                    390:                         &mt('View file').'</a>';
1.37      raeburn   391:         }
                    392:     } else {
                    393:         $result .= &mt('Failed to copy: [_1].',$!);
                    394:     }
                    395:     if ($mode ne 'imsimport' && $mode ne 'testbank') {
1.49      bisitz    396:         $result .= '<br /><a href="'.$dirpath.'">'.
                    397:                    &mt('Back to Directory').'</a><br />';
1.37      raeburn   398:     }
                    399:     return ($result,$returnflag);
                    400: }
                    401: 
                    402: sub phasethree {
                    403:     my ($r,$fn,$uname,$udom,$mode) = @_;
1.51      raeburn   404:     my $action = '/adm/upload'; 
                    405:     if ($mode eq 'testbank') {
                    406:         $action = '/adm/testbank';
                    407:     } elsif ($mode eq 'imsimport') {
                    408:         $action = '/adm/imsimport';
                    409:     }
                    410:     my $dir_root = '/home/'.$uname.'/public_html';
                    411:     my $url_root = '/priv/'.$uname;
                    412:     my $path = &File::Basename::dirname($fn);
                    413:     my $filename = &HTML::Entities::encode($env{'form.filename'},'<>&"');
                    414:     my $state = &embedded_form_elems('modify_orightml',$filename,$mode).
                    415:                 '<input type="hidden" name="phase" value="four" />';
                    416:     my ($result,$returnflag) = 
                    417:         &Apache::loncommon::upload_embedded($mode,$path,$uname,$udom,
                    418:                                             $dir_root,$url_root,undef,
                    419:                                             undef,undef,$state,$action);
                    420:     if ($mode ne 'imsimport' && $mode ne 'testbank') {
                    421:         $result .= '<br /><h3><a href="'.$url_root.$fn.'">'.
                    422:                   &mt('View main file').'</a></h3>'.
                    423:                   '<h3><a href="'.$url_root.$path.'">'.
                    424:                   &mt('Back to Directory').'</a></h3><br />';
                    425:     }
                    426:     return ($result,$returnflag);
                    427: }
                    428: 
                    429: sub embedded_form_elems {
                    430:     my ($action,$filename,$mode) = @_;
                    431:     return <<STATE;
                    432:     <input type="hidden" name="action" value="$action" />
                    433:     <input type="hidden" name="mode" value="$mode" />
                    434:     <input type="hidden" name="filename" value="$filename" />
                    435: STATE
                    436: }
                    437: 
                    438: sub phasefour {
                    439:     my ($r,$fn,$uname,$udom,$mode) = @_;
                    440:     my $action = '/adm/upload';
                    441:     if ($mode eq 'testbank') {
                    442:         $action = '/adm/testbank';
                    443:     } elsif ($mode eq 'imsimport') {
                    444:         $action = '/adm/imsimport';
                    445:     }
1.37      raeburn   446:     my $result;
                    447:     my $dir_root = '/home/'.$uname.'/public_html';
                    448:     my $url_root = '/priv/'.$uname;
                    449:     my $path = &File::Basename::dirname($fn);
1.51      raeburn   450:     $result .= &Apache::loncommon::modify_html_refs($mode,$path,
                    451:                               $uname,$udom,$dir_root);
1.37      raeburn   452:     if ($mode ne 'imsimport' && $mode ne 'testbank') {
1.51      raeburn   453:         $result .= '<br /><h3><a href="'.$url_root.$fn.'">'.
                    454:                   &mt('View main file').'</a></h3>'.
                    455:                   '<h3><a href="'.$url_root.$path.'">'.
                    456:                   &mt('Back to Directory').'</a></h3><br />';
1.1       www       457:     }
1.37      raeburn   458:     return $result;
1.1       www       459: }
                    460: 
1.10      harris41  461: # ---------------------------------------------------------------- Main Handler
1.1       www       462: sub handler {
                    463: 
1.22      albertel  464:     my $r=shift;
1.1       www       465: 
1.22      albertel  466:     my $uname;
                    467:     my $udom;
1.25      raeburn   468:     my $javascript = '';
1.18      www       469: #
                    470: # phase two: re-attach user
                    471: #
1.29      albertel  472:     if ($env{'form.uploaduname'}) {
                    473: 	$env{'form.filename'}='/priv/'.$env{'form.uploaduname'}.'/'.
                    474: 	    $env{'form.filename'};
1.22      albertel  475:     }
                    476: 
1.29      albertel  477:     unless ($env{'form.phase'} eq 'two') {
1.25      raeburn   478:         $javascript = qq|
                    479: function verifyForm() {
1.28      raeburn   480:     var mode = document.fileupload.filetype.options[document.fileupload.filetype.selectedIndex].value
1.25      raeburn   481:     if (mode == "testbank") {
1.28      raeburn   482:         document.fileupload.action = "/adm/testbank";
1.25      raeburn   483:     }
                    484:     if (mode == "imsimport") {
1.28      raeburn   485:         document.fileupload.action = "/adm/imsimport";
1.25      raeburn   486:     }
                    487:     if (mode == "standard") {
1.28      raeburn   488:         document.fileupload.action = "/adm/upload";
1.25      raeburn   489:     }
1.28      raeburn   490:     document.fileupload.submit();
1.25      raeburn   491: }
1.33      albertel  492: 	|;
1.25      raeburn   493:     }
1.22      albertel  494:     ($uname,$udom)=
1.29      albertel  495: 	&Apache::loncacc::constructaccess($env{'form.filename'},
1.22      albertel  496: 					  $r->dir_config('lonDefDomain'));
1.37      raeburn   497: 
1.22      albertel  498:     unless (($uname) && ($udom)) {
                    499: 	$r->log_reason($uname.' at '.$udom.
1.29      albertel  500: 		       ' trying to publish file '.$env{'form.filename'}.
1.22      albertel  501: 		       ' - not authorized', 
                    502: 		       $r->filename); 
                    503: 	return HTTP_NOT_ACCEPTABLE;
                    504:     }
                    505:     
                    506:     my $fn;
1.29      albertel  507:     if ($env{'form.filename'}) {
                    508: 	$fn=$env{'form.filename'};
1.43      raeburn   509: 	$fn=~s/^https?\:\/\/[^\/]+\///;
1.22      albertel  510: 	$fn=~s/^\///;
1.34      albertel  511: 	$fn=~s{(~|priv/)($LONCAPA::username_re)}{};
1.22      albertel  512: 	$fn=~s/\/+/\//g;
                    513:     } else {
1.29      albertel  514: 	$r->log_reason($env{'user.name'}.' at '.$env{'user.domain'}.
1.22      albertel  515: 		       ' unspecified filename for upload', $r->filename); 
                    516: 	return HTTP_NOT_FOUND;
                    517:     }
1.1       www       518: 
                    519: # ----------------------------------------------------------- Start page output
                    520: 
                    521: 
1.22      albertel  522:     &Apache::loncommon::content_type($r,'text/html');
                    523:     $r->send_http_header;
1.1       www       524: 
1.31      albertel  525:    $javascript = "<script type=\"text/javascript\">\n//<!--\n".
                    526: 	$javascript."\n// --></script>\n";
1.1       www       527: 
1.47      bisitz    528:     # Breadcrumbs
                    529:     my $brcrum = [{'href' => &Apache::loncommon::authorspace(),
                    530:                    'text' => 'Construction Space'},
                    531:                   {'href' => '/adm/upload',
                    532:                    'text' => 'Upload file to Construction Space'}];
1.31      albertel  533:     $r->print(&Apache::loncommon::start_page('Upload file to Construction Space',
1.47      bisitz    534:                                              $javascript,
                    535:                                              {'bread_crumbs' => $brcrum,})
                    536:              .&Apache::loncommon::head_subbox(
                    537:                 &Apache::loncommon::CSTR_pageheader())
                    538:     );
1.3       www       539:   
1.29      albertel  540:     if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
1.52    ! www       541:         $r->print('<p class="LC_info">'
1.46      bisitz    542:                  .&mt('Co-Author [_1]',$uname.':'.$udom)
1.44      bisitz    543:                  .'</p>'
                    544:         );
1.22      albertel  545:     }
1.51      raeburn   546:     if ($env{'form.phase'} eq 'four') {
                    547:         my $output = &phasefour($r,$fn,$uname,$udom,'author');
                    548:         $r->print($output);
                    549:     } elsif ($env{'form.phase'} eq 'three') {
1.37      raeburn   550:         my $output = &phasethree($r,$fn,$uname,$udom,'author');
                    551:         $r->print($output);
                    552:     } elsif ($env{'form.phase'} eq 'two') {
                    553: 	my ($output,$returnflag) = &phasetwo($r,$fn,$uname,$udom);
                    554:         $r->print($output);
1.22      albertel  555:     } else {
                    556: 	&phaseone($r,$fn,$uname,$udom);
                    557:     }
1.1       www       558: 
1.31      albertel  559:     $r->print(&Apache::loncommon::end_page());
1.22      albertel  560:     return OK;  
1.1       www       561: }
1.7       www       562: 
                    563: 1;
                    564: __END__
1.10      harris41  565: 
                    566: 

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