version 1.1287, 2017/08/07 20:22:13
|
version 1.1293, 2017/08/13 23:21:04
|
Line 84 use Crypt::DES;
|
Line 84 use Crypt::DES;
|
use DynaLoader; # for Crypt::DES version |
use DynaLoader; # for Crypt::DES version |
use MIME::Lite; |
use MIME::Lite; |
use MIME::Types; |
use MIME::Types; |
|
use File::Copy(); |
|
use File::Path::Tiny(); |
|
|
# ---------------------------------------------- Designs |
# ---------------------------------------------- Designs |
use vars qw(%defaultdesign); |
use vars qw(%defaultdesign); |
Line 2477 sub create_text_file {
|
Line 2479 sub create_text_file {
|
# ------------------------------------------ |
# ------------------------------------------ |
|
|
sub domain_select { |
sub domain_select { |
my ($name,$value,$multiple)=@_; |
my ($name,$value,$multiple,$incdoms,$excdoms)=@_; |
|
my @possdoms; |
|
if (ref($incdoms) eq 'ARRAY') { |
|
@possdoms = @{$incdoms}; |
|
} else { |
|
@possdoms = &Apache::lonnet::all_domains(); |
|
} |
|
|
my %domains=map { |
my %domains=map { |
$_ => $_.' '. &Apache::lonnet::domain($_,'description') |
$_ => $_.' '. &Apache::lonnet::domain($_,'description') |
} &Apache::lonnet::all_domains(); |
} @possdoms; |
|
|
|
if ((ref($excdoms) eq 'ARRAY') && (@{$excdoms} > 0)) { |
|
foreach my $dom (@{$excdoms}) { |
|
delete($domains{$dom}); |
|
} |
|
} |
|
|
if ($multiple) { |
if ($multiple) { |
$domains{''}=&mt('Any domain'); |
$domains{''}=&mt('Any domain'); |
$domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))]; |
$domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))]; |
Line 10138 sub user_picker {
|
Line 10154 sub user_picker {
|
$domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1,undef,[$currdom]); |
$domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1,undef,[$currdom]); |
} else { |
} else { |
my $defdom = $env{'request.role.domain'}; |
my $defdom = $env{'request.role.domain'}; |
my ($trustedref,$untrustedref); |
my ($trusted,$untrusted); |
if (($context eq 'requestcrs') || ($context eq 'course')) { |
if (($context eq 'requestcrs') || ($context eq 'course')) { |
($trustedref,$untrustedref) = &Apache::lonnet::trusted_domains('enroll',$defdom); |
($trusted,$untrusted) = &Apache::lonnet::trusted_domains('enroll',$defdom); |
} elsif ($context eq 'author') { |
} elsif ($context eq 'author') { |
($trustedref,$untrustedref) = &Apache::lonnet::trusted_domains('othcoau',$defdom); |
($trusted,$untrusted) = &Apache::lonnet::trusted_domains('othcoau',$defdom); |
} elsif ($context eq 'domain') { |
} elsif ($context eq 'domain') { |
($trustedref,$untrustedref) = &Apache::lonnet::trusted_domains('domroles',$defdom); |
($trusted,$untrusted) = &Apache::lonnet::trusted_domains('domroles',$defdom); |
} |
} |
$domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1,undef,$trustedref,$untrustedref); |
$domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1,undef,$trusted,$untrusted); |
} |
} |
my $srchinsel = ' <select name="srchin">'; |
my $srchinsel = ' <select name="srchin">'; |
|
|
Line 12580 sub decompress_uploaded_file {
|
Line 12596 sub decompress_uploaded_file {
|
|
|
sub process_decompression { |
sub process_decompression { |
my ($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem) = @_; |
my ($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem) = @_; |
|
unless (($dir_root eq '/userfiles') && ($destination =~ m{^(docs|supplemental)/(default|\d+)/\d+$})) { |
|
return '<p class="LC_error">'.&mt('Not extracted.').'<br />'. |
|
&mt('Unexpected file path.').'</p>'."\n"; |
|
} |
|
unless (($docudom =~ /^$match_domain$/) && ($docuname =~ /^$match_courseid$/)) { |
|
return '<p class="LC_error">'.&mt('Not extracted.').'<br />'. |
|
&mt('Unexpected course context.').'</p>'."\n"; |
|
} |
|
unless ($file eq &Apache::lonnet::clean_filename($file)) { |
|
return '<p class="LC_error">'.&mt('Not extracted.').'<br />'. |
|
&mt('Filename contained unexpected characters.').'</p>'."\n"; |
|
} |
my ($dir,$error,$warning,$output); |
my ($dir,$error,$warning,$output); |
if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i) { |
if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i) { |
$error = &mt('Filename not a supported archive file type.'). |
$error = &mt('Filename not a supported archive file type.'). |
Line 12614 sub process_decompression {
|
Line 12642 sub process_decompression {
|
} |
} |
} |
} |
my $numskip = scalar(@to_skip); |
my $numskip = scalar(@to_skip); |
if (($numskip > 0) && |
my $numoverwrite = scalar(@to_overwrite); |
($numskip == $env{'form.archive_itemcount'})) { |
if (($numskip) && (!$numoverwrite)) { |
$warning = &mt('All items in the archive file already exist, and no overwriting of existing files has been requested.'); |
$warning = &mt('All items in the archive file already exist, and no overwriting of existing files has been requested.'); |
} elsif ($dir eq '') { |
} elsif ($dir eq '') { |
$error = &mt('Directory containing archive file unavailable.'); |
$error = &mt('Directory containing archive file unavailable.'); |
} elsif (!$error) { |
} elsif (!$error) { |
my ($decompressed,$display); |
my ($decompressed,$display); |
if ($numskip > 0) { |
if (($numskip) || ($numoverwrite)) { |
my $tempdir = time.'_'.$$.int(rand(10000)); |
my $tempdir = time.'_'.$$.int(rand(10000)); |
mkdir("$dir/$tempdir",0755); |
mkdir("$dir/$tempdir",0755); |
system("mv $dir/$file $dir/$tempdir/$file"); |
if (&File::Copy::move("$dir/$file","$dir/$tempdir/$file")) { |
($decompressed,$display) = |
($decompressed,$display) = |
&decompress_uploaded_file($file,"$dir/$tempdir"); |
&decompress_uploaded_file($file,"$dir/$tempdir"); |
foreach my $item (@to_skip) { |
foreach my $item (@to_skip) { |
if (($item ne '') && ($item !~ /\.\./)) { |
if (($item ne '') && ($item !~ /\.\./)) { |
if (-f "$dir/$tempdir/$item") { |
if (-f "$dir/$tempdir/$item") { |
unlink("$dir/$tempdir/$item"); |
unlink("$dir/$tempdir/$item"); |
} elsif (-d "$dir/$tempdir/$item") { |
} elsif (-d "$dir/$tempdir/$item") { |
system("rm -rf $dir/$tempdir/$item"); |
&File::Path::Tiny::rm("$dir/$tempdir/$item"); |
|
} |
|
} |
|
} |
|
foreach my $item (@to_overwrite) { |
|
if ((-e "$dir/$tempdir/$item") && (-e "$dir/$item")) { |
|
if (($item ne '') && ($item !~ /\.\./)) { |
|
if (-f "$dir/$item") { |
|
unlink("$dir/$item"); |
|
} elsif (-d "$dir/$item") { |
|
&File::Path::Tiny::rm("$dir/$item"); |
|
} |
|
&File::Copy::move("$dir/$tempdir/$item","$dir/$item"); |
|
} |
} |
} |
} |
} |
|
if (&File::Copy::move("$dir/$tempdir/$file","$dir/$file")) { |
|
&File::Path::Tiny::rm("$dir/$tempdir"); |
|
} |
} |
} |
system("mv $dir/$tempdir/* $dir"); |
|
rmdir("$dir/$tempdir"); |
|
} else { |
} else { |
($decompressed,$display) = |
($decompressed,$display) = |
&decompress_uploaded_file($file,$dir); |
&decompress_uploaded_file($file,$dir); |
Line 12655 sub process_decompression {
|
Line 12697 sub process_decompression {
|
if (ref($newdirlistref) eq 'ARRAY') { |
if (ref($newdirlistref) eq 'ARRAY') { |
foreach my $dir_line (@{$newdirlistref}) { |
foreach my $dir_line (@{$newdirlistref}) { |
my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5); |
my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5); |
unless (($item =~ /^\.+$/) || ($item eq $file) || |
unless (($item =~ /^\.+$/) || ($item eq $file)) { |
((@to_skip > 0) && (grep(/^\Q$item\E$/,@to_skip)))) { |
|
push(@newitems,$item); |
push(@newitems,$item); |
if ($dirptr&$testdir) { |
if ($dirptr&$testdir) { |
$is_dir{$item} = 1; |
$is_dir{$item} = 1; |
Line 13259 sub process_extracted_files {
|
Line 13300 sub process_extracted_files {
|
mkdir("$prefix$dir/$docstype/$mapinner{$outer}/$newidx"); |
mkdir("$prefix$dir/$docstype/$mapinner{$outer}/$newidx"); |
} |
} |
if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") { |
if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") { |
system("mv $prefix$path $prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title"); |
if (rename("$prefix$path","$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title")) { |
$newdest{$i} = "$prefix$dir/$docstype/$mapinner{$outer}/$newidx"; |
$newdest{$i} = "$prefix$dir/$docstype/$mapinner{$outer}/$newidx"; |
unless ($ishome) { |
unless ($ishome) { |
my $fetch = "$newdest{$i}/$title"; |
my $fetch = "$newdest{$i}/$title"; |
$fetch =~ s/^\Q$prefix$dir\E//; |
$fetch =~ s/^\Q$prefix$dir\E//; |
$prompttofetch{$fetch} = 1; |
$prompttofetch{$fetch} = 1; |
|
} |
} |
} |
} |
} |
$LONCAPA::map::resources[$newidx]= |
$LONCAPA::map::resources[$newidx]= |
Line 13344 sub process_extracted_files {
|
Line 13386 sub process_extracted_files {
|
} |
} |
if ($fullpath ne '') { |
if ($fullpath ne '') { |
if (-e "$prefix$path") { |
if (-e "$prefix$path") { |
system("mv $prefix$path $fullpath/$title"); |
unless (rename("$prefix$path","$fullpath/$title")) { |
|
$warning .= &mt('Failed to rename dependency').'<br />'; |
|
} |
} |
} |
if (-e "$fullpath/$title") { |
if (-e "$fullpath/$title") { |
my $showpath; |
my $showpath; |
Line 13354 sub process_extracted_files {
|
Line 13398 sub process_extracted_files {
|
$showpath = "/$title"; |
$showpath = "/$title"; |
} |
} |
$result .= '<li>'.&mt('[_1] included as a dependency',$showpath).'</li>'."\n"; |
$result .= '<li>'.&mt('[_1] included as a dependency',$showpath).'</li>'."\n"; |
} |
unless ($ishome) { |
unless ($ishome) { |
my $fetch = "$fullpath/$title"; |
my $fetch = "$fullpath/$title"; |
$fetch =~ s/^\Q$prefix$dir\E//; |
$fetch =~ s/^\Q$prefix$dir\E//; |
$prompttofetch{$fetch} = 1; |
$prompttofetch{$fetch} = 1; |
} |
} |
} |
} |
} |
} |
} |
Line 13656 sub upfile_store {
|
Line 13700 sub upfile_store {
|
|
|
=pod |
=pod |
|
|
=item * &load_tmp_file($r) |
=item * &load_tmp_file($r,$datatoken) |
|
|
Load uploaded file from tmp, $r should be the HTTP Request object, |
Load uploaded file from tmp, $r should be the HTTP Request object, |
needs $env{'form.datatoken'}, |
$datatoken is the name to assign to the temporary file. |
sets $env{'form.upfile'} to the contents of the file |
sets $env{'form.upfile'} to the contents of the file |
|
|
=cut |
=cut |
|
|
sub load_tmp_file { |
sub load_tmp_file { |
my $r=shift; |
my ($r,$datatoken) = @_; |
|
return if ($datatoken eq ''); |
my @studentdata=(); |
my @studentdata=(); |
{ |
{ |
my $studentfile = $r->dir_config('lonDaemons'). |
my $studentfile = $r->dir_config('lonDaemons'). |
'/tmp/'.$env{'form.datatoken'}.'.tmp'; |
'/tmp/'.$datatoken.'.tmp'; |
if ( open(my $fh,"<$studentfile") ) { |
if ( open(my $fh,"<$studentfile") ) { |
@studentdata=<$fh>; |
@studentdata=<$fh>; |
close($fh); |
close($fh); |
Line 13678 sub load_tmp_file {
|
Line 13723 sub load_tmp_file {
|
$env{'form.upfile'}=join('',@studentdata); |
$env{'form.upfile'}=join('',@studentdata); |
} |
} |
|
|
|
sub valid_datatoken { |
|
my ($datatoken) = @_; |
|
if ($datatoken =~ /^$match_username\_$match_domain\_enroll_$match_domain\_$match_courseid\_\d+_\d+$/) { |
|
return $datatoken; |
|
} |
|
return; |
|
} |
|
|
=pod |
=pod |
|
|
=item * &upfile_record_sep() |
=item * &upfile_record_sep() |