--- loncom/publisher/loncfile.pm 2009/04/13 21:29:26 1.96 +++ loncom/publisher/loncfile.pm 2011/03/01 01:36:55 1.106 @@ -9,7 +9,7 @@ # and displays a page showing the results of the action. # # -# $Id: loncfile.pm,v 1.96 2009/04/13 21:29:26 raeburn Exp $ +# $Id: loncfile.pm,v 1.106 2011/03/01 01:36:55 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -348,6 +348,7 @@ sub cleanDest { my ($request,$dest,$subdir,$fn,$uname)=@_; #remove bad characters my $foundbad=0; + my $error=''; if ($subdir && $dest =~/\./) { $foundbad=1; $dest=~s/\.//g; @@ -359,33 +360,37 @@ sub cleanDest { } if ($dest=~m|/|) { my ($newpath)=($dest=~m|(.*)/|); - $newpath=&relativeDest($fn,$newpath,$uname); + ($newpath,$error)=&relativeDest($fn,$newpath,$uname); if (! -d "$newpath") { - $request->print('

' + $request->print('

' .&mt("You have requested to create file in directory [_1] which doesn't exist. The requested directory path has been removed from the requested file name." - ,'"'.&display($newpath).'"') + ,&display($newpath)) .'

'); $dest=~s|.*/||; } } if ($dest =~ /\.(\d+)\.(\w+)$/){ - $request->print('' - .&mt('Bad filename [_1]',''.&display($dest).'') + $request->print('

' + .&mt('Bad filename [_1]',&display($dest)) .'
' .&mt('[_1](name).(number).(extension)[_2] not allowed.','','') .'
' .&mt('Removing the [_1].number.[_2] from requested filename.','','') - .'
'); + .'

'); $dest =~ s/\.(\d+)(\.\w+)$/$2/; } if ($foundbad) { - $request->print("

".&mt('Invalid characters in requested name have been removed.')."

"); + $request->print('

' + .&mt('Invalid characters in requested name have been removed.') + .'

' + ); } - return $dest; + return ($dest,$error); } sub relativeDest { my ($fn,$newfilename,$uname)=@_; + my $error = ''; if ($newfilename=~/^\//) { # absolute, simply add path $newfilename='/home/'.$uname.'/public_html/'; @@ -398,7 +403,18 @@ sub relativeDest { while ($newfilename=~m:/\.\./:) { $newfilename=~ s:/[^/]+/\.\./:/:g; #remove dir/.. } - return $newfilename; + if ($newfilename =~ m{^/home/($match_username)/(?:public\_html|priv)/}) { + my $otheruname = $1; + unless ($otheruname eq $uname) { + my ($authorname,$authordom)= + &Apache::loncacc::constructaccess($newfilename,$env{'request.role.domain'}); + unless (($authorname eq $otheruname) && ($authordom ne '')) { + my $otherdir = &display($newfilename); + $error = &mt('Access denied to [_1]',$otherdir); + } + } + } + return ($newfilename,$error); } =pod @@ -423,7 +439,7 @@ sub CloseForm1 { my ($request, $fn) = @_; $request->print('

'); $request->print('

'); + '" method="post">

'); } @@ -514,10 +530,10 @@ sub Rename1 { if (-d $fn) { $newfilename=~/\.(\w+)$/; if (&Apache::loncommon::fileembstyle($1) eq 'ssi') { - $request->print('
'. - &mt('Cannot change MIME type of a directory'). + $request->print('

'. + &mt('Cannot change MIME type of a directory.'). ''. - '
'.&mt('Cancel').''); + '
'.&mt('Cancel').'

'); return; } $newfilename=~s/\/[^\/]+\/([^\/]+)$/\/$1/; @@ -533,27 +549,38 @@ sub Rename1 { return; } unless (&obsolete_unpub($user,$domain,$fn)) { - $request->print('

'.&mt('Cannot rename or move non-obsolete published file').'

'. - '
'.&mt('Cancel').''); + $request->print('

' + .&mt('Cannot rename or move non-obsolete published file.') + .'
' + .''.&mt('Cancel').'

' + ); return; } my $action; if ($style eq 'rename') { - $action=&mt('Rename'); + $action='Rename'; } else { - $action=&mt('Move'); + $action='Move'; } - $request->print('

'.$action.' '.&display($fn). - '


to '.&display($newfilename).'?

'); + $request->print('' + .'

' + .&mt($action.' [_1] to [_2]?', + &display($fn), + &display($newfilename)) + .'

' + ); &CloseForm1($request, $fn); } else { - $request->print('

'.&mt('No new filename specified.').'

'); + $request->print('

'.&mt('No new filename specified.').'

'); return; } } else { - $request->print('

'.&mt('No such file').': '.&display($fn).'

'); + $request->print('

' + .&mt('No such file: [_1]', + &display($fn)) + .'

' + ); return; } @@ -591,22 +618,38 @@ sub Delete1 { $fn.'" />'); if (-d $fn) { unless (&empty_directory($fn,'Delete1')) { - $request->print('

'.&mt('Only empty directories may be deleted.').'

'. - 'You must delete the contents of the directory first.
'. - '
'.&mt('Cancel').''); + $request->print('

' + .'' + .&mt('Only empty directories may be deleted.') + .'
' + .&mt('You must delete the contents of the directory first.') + .'

' + .'

'.&mt('Cancel').'

' + ); return; } } else { unless (&obsolete_unpub($user,$domain,$fn)) { - $request->print('

'.&mt('Cannot delete non-obsolete published file').'

'. - '
'.&mt('Cancel').''); + $request->print('

' + .&mt('Cannot delete non-obsolete published file.') + .'
' + .''.&mt('Cancel').'

' + ); return; } } - $request->print('

'.&mt('Delete').' '.&display($fn).'?

'); + $request->print('

' + .&mt('Delete [_1]?', + &display($fn)) + .'

' + ); &CloseForm1($request, $fn); } else { - $request->print('

'.&mt('No such file').': '.&display($fn).'

'); + $request->print('

' + .&mt('No such file: [_1]', + &display($fn)) + .'

' + ); } } @@ -660,13 +703,22 @@ sub Copy1 { $request->print('
'.&mt('Cancel').''); return; } - $request->print('

'.&mt('Copy').' '.&display($fn).'
to '. - &display($newfilename).'?

'); + $request->print( + '' + .'

' + .&mt('Copy [_1] to [_2]?', + &display($fn), + &display($newfilename)) + .'

' + ); &CloseForm1($request, $fn); } else { - $request->print('

'.&mt('No such file').': '.&display($fn).'

'); + $request->print('

' + .&mt('No such file: [_1]', + &display($fn)) + .'

' + ); } } @@ -717,14 +769,17 @@ sub NewDir1 { if ($type eq 'error') { $request->print(''); } else { - if ($mode eq 'testbank') { - $request->print(''); - } elsif ($mode eq 'imsimport') { - $request->print(''); - } - $request->print('

'.&mt('Make new directory').' '. - &display($newfilename).'?

'); + if (($mode eq 'testbank') || ($mode eq 'imsimport')) { + $request->print(''."\n". + ''); + } + $request->print('' + .'

' + .&mt('Make new directory [_1]?', + &display($newfilename)) + .'

' + ); &CloseForm1($request, $fn); } } @@ -734,10 +789,18 @@ sub Decompress1 { my ($request, $user, $domain, $fn) = @_; if( -e $fn) { $request->print(''); - $request->print('

'.&mt('Decompress').' '.&display($fn).'?

'); + $request->print('

' + .&mt('Decompress [_1]?', + &display($fn)) + .'

' + ); &CloseForm1($request, $fn); } else { - $request->print('

'.&mt('No such file').': '.&display($fn).'

'); + $request->print('

' + .&mt('No such file: [_1]', + &display($fn)) + .'

' + ); } } @@ -806,7 +869,7 @@ sub NewFile1 { $extension = $1; } - my @okexts = qw(xml html xhtml htm xhtm problem page sequence rights sty library js css txt); + my @okexts = qw(xml html xhtml htm xhtm problem page sequence rights sty task library js css txt); if (($extension eq '') || (!grep(/^\Q$extension\E/,@okexts))) { my $validexts = '.'.join(', .',@okexts); $request->print('

'. @@ -820,7 +883,7 @@ sub NewFile1 { ''.&mt('Enter a file name: ').' '. '

'. '

'); + '" method="post">

'); return; } @@ -828,9 +891,9 @@ sub NewFile1 { $request->print(''); $request->print('

'); + '" method="post">

'); $request->print('

'); + '" method="post">

'); } return; } @@ -886,8 +949,23 @@ sub phaseone { my $doingdir=0; if ($env{'form.action'} eq 'newdir') { $doingdir=1; } - my $newfilename=&cleanDest($r,$env{'form.newfilename'},$doingdir,$fn,$uname); - $newfilename=&relativeDest($fn,$newfilename,$uname); + my ($newfilename,$error) = + &cleanDest($r,$env{'form.newfilename'},$doingdir,$fn,$uname); + unless ($error) { + ($newfilename,$error)=&relativeDest($fn,$newfilename,$uname); + } + if ($error) { + my $dirlist; + if ($fn=~m{^(.*/)[^/]+$}) { + $dirlist=$1; + } else { + $dirlist=$fn; + } + $r->print('
'.$error.'
'. + '

'.&mt('Return to Directory'). + '

'); + return; + } $r->print('
'. ''. ''. @@ -905,7 +983,10 @@ sub phaseone { if($newfilename) { &Copy1($r, $uname, $udom, $fn, $newfilename); } else { - $r->print('

'.&mt('No new filename specified.').'

'); + $r->print('

' + .&mt('No new filename specified.') + .'

' + ); } } elsif ($env{'form.action'} eq 'newdir') { my $mode = ''; @@ -927,7 +1008,10 @@ sub phaseone { if (($newfilename!~/\/$/) && ($newfilename!~/$empty$/)) { &NewFile1($r, $uname, $udom, $fn, $newfilename); } else { - $r->print('

'.&mt('No new filename specified.').'

'); + $r->print('

' + .&mt('No new filename specified.') + .'

' + ); } } } @@ -1014,7 +1098,12 @@ sub Rename2 { unlink $tmp2; } } else { - $request->print("

".&mt('No such file').": ".&display($oldfile).'

'); + $request->print( + '

' + .&mt('No such file: [_1]', + &display($oldfile)) + .'

' + ); return 0; } return 1; @@ -1062,7 +1151,7 @@ sub Delete2 { return 0; } } else { - $request->print('

'.&mt('No such file').'.

'); + $request->print('

'.&mt('No such file').'

'); return 0; } } @@ -1073,7 +1162,7 @@ sub Delete2 { return 0; } } else { - $request->print('

'.&mt('No such file').'.

'); + $request->print('

'.&mt('No such file').'

'); return 0; } } @@ -1132,7 +1221,7 @@ sub Copy2 { return 1; } } else { - $request->print('

'.&mt('No such file').'

'); + $request->print('

'.&mt('No such file').'

'); return 0; } return 1; @@ -1286,7 +1375,7 @@ sub phasetwo { } $dest = $env{'form.newfilename'}; } else { - $r->print('

'.&mt('No New filename specified').'

'); + $r->print('

'.&mt('No New filename specified').'

'); return; } @@ -1387,15 +1476,31 @@ function writeDone() { $loaditem{'onload'} = "writeDone()"; } + # Breadcrumbs + &Apache::lonhtmlcommon::clear_breadcrumbs(); + &Apache::lonhtmlcommon::add_breadcrumb({ + 'text' => 'Construction Space', + 'href' => &Apache::loncommon::authorspace(), + }); + &Apache::lonhtmlcommon::add_breadcrumb({ + 'text' => 'File Operation', + 'title' => 'Construction Space File Operation', + 'href' => '', + }); + $r->print(&Apache::loncommon::start_page('Construction Space File Operation', $js, - {'add_entries' => \%loaditem,})); + {'add_entries' => \%loaditem,}) + .&Apache::lonhtmlcommon::breadcrumbs() + .&Apache::loncommon::head_subbox( + &Apache::loncommon::CSTR_pageheader()) + ); $r->print('

'.&mt('Location').': '.&display($fn).'

'); if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) { - $r->print('

' - .&mt('Co-Author [_1]:[_2]',$uname,$udom) + $r->print('

' + .&mt('Co-Author [_1]',$uname.':'.$udom) .'

' ); } @@ -1426,8 +1531,11 @@ function writeDone() { $env{'form.action'} eq 'Select Action' ) { $r->print('

'.&mt('New Resource').'

'); } else { - $r->print('

'.&mt('Unknown Action').' '.$env{'form.action'}.'

'. - &Apache::loncommon::end_page()); + $r->print('

' + .&mt('Unknown Action').' '.$env{'form.action'} + .'

' + .&Apache::loncommon::end_page() + ); return OK; } if ($env{'form.phase'} eq 'two') {