--- loncom/interface/lonsource.pm 2005/07/08 10:39:49 1.15 +++ loncom/interface/lonsource.pm 2011/10/25 19:11:52 1.26 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA -# Souce Code handler +# Source Code handler # -# $Id: lonsource.pm,v 1.15 2005/07/08 10:39:49 www Exp $ +# $Id: lonsource.pm,v 1.26 2011/10/25 19:11:52 www Exp $ # # Copyright Michigan State University Board of Trustees # @@ -40,84 +40,93 @@ use Apache::lonmeta; use Apache::File; use Apache::lonlocal; use HTML::Entities; +use LONCAPA; sub make_link { my ($filename, $listname) = @_; - my $sourcelink = "/adm/source?filename=".$filename."&listname=".$listname; + my $sourcelink = "/adm/source?inhibitmenu=yes&filename=".$filename."&listname=".$listname; return $sourcelink; } sub stage_2 { - my ($r, $filename, $author, $listname) = @_; - $filename = $filename; - &Apache::loncommon::content_type($r,'text/html'); - my ($uname, $udom) = &Apache::loncacc::constructaccess('/~'.$author.'/',$r->dir_config('lonDefDomain')); - $r->send_http_header; - my $html=&Apache::lonxml::xmlbegin(); - $r->print($html.'
' + .&mt('Note: the path is in reference to the root of your construction space,' + .' and new directories will be automatically created.') + .'
'); $r->print(''); return OK; } - -sub copy_stage { - my ($r, $filename, $listname, $newpath) = @_; +sub copy_author { my $role; my $domain; my $author_name; -#Figure out if we are author or co-author - - if($env{'request.role'} =~ m|ca.|) { + if ($env{'request.role'} =~ m{^ca\.}) { ($role, $domain, $author_name) = split(/\//,$env{'request.role'}); } else { $role = "au."; $domain = $env{'user.domain'}; $author_name = $env{'user.name'}; } + return ($role,$author_name,$domain); +} + + +sub copy_stage { + my ($r, $filename, $listname, $newpath) = @_; + +#Figure out if we are author or co-author + my ($role,$author_name,$domain)=©_author(); + +# Construct path to copy and filter out any possibly nasty stuff + my $path_to_new_file = '/home/httpd/html/priv/'.$domain.'/'.$author_name.'/'.$newpath.'/'.$listname; + $path_to_new_file=~s/\.\.//g; + $path_to_new_file=~s/\~//g; + $path_to_new_file=~s/\/+/\//g; - my $path_to_new_file = '/home/'.$author_name.'/public_html/'.$newpath.'/'.$listname; #Just checking again for access as we want to make sure that it is really ok now that we have the real path - my ($uname,$udom)= &Apache::loncacc::constructaccess($path_to_new_file,$domain); - unless (($uname) && ($udom)) { - return HTTP_NOT_ACCEPTABLE; + my ($uname,$udom)= &Apache::loncacc::constructaccess($path_to_new_file); + + if (!$uname || !$udom) { + $r->print(&Apache::loncommon::start_page('Not Allowed')); + $r->print(&mt('Not allowed to create file [_1]', $path_to_new_file)); + $r->print(&Apache::loncommon::end_page()); + return; } - &Apache::loncommon::content_type($r,'text/html'); - $r->send_http_header; - my $html=&Apache::lonxml::xmlbegin(); - $r->print($html.''.&mt('No such file').'
'); return 0; } - ©_file($r, $author_name, $newpath, $filename, $path_to_new_file); + ©_file($r, $newpath, $filename, $path_to_new_file); } } sub copy_file { - my ($r, $author_name, $newpath, $filename, $path_to_new_file) = @_; + my ($r, $newpath, $filename, $path_to_new_file) = @_; $r->print("Creating directories"); - my $path = '/home/'.$author_name.'/public_html/'; + +#Figure out if we are author or co-author + my ($role,$author_name,$domain)=©_author(); + + my $path = '/home/httpd/html/priv/'.$domain.'/'.$author_name.'/'; my @directories = split(/\//,$newpath); + foreach my $now_checking (@directories) { if($now_checking ne '') { $path = $path.'/'.$now_checking; @@ -157,11 +176,11 @@ sub copy_file { else { unless(mkdir($path, 02770)) { - $r->print(''.&mt('Error').': '.$!.''); + $r->print(''.&mt('Error:').' '.$!.'
'); return 0; } unless(chmod(02770, ($path))) { - $r->print(' '.&mt('Error').': '.$!.''); + $r->print(''.&mt('Error:').' '.$!.'
'); return 0; } } @@ -170,21 +189,19 @@ sub copy_file { } $r->print("