--- loncom/cgi/archive.pl 2024/05/13 13:55:51 1.1 +++ loncom/cgi/archive.pl 2024/09/03 10:40:04 1.3 @@ -1,6 +1,6 @@ #!/usr/bin/perl # -# $Id: archive.pl,v 1.1 2024/05/13 13:55:51 raeburn Exp $ +# $Id: archive.pl,v 1.3 2024/09/03 10:40:04 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -28,7 +28,7 @@ # # A CGI script which creates a compressed archive file of the current # directory in Authoring Space, with optional (a) recursion into -# sub-directories, (b) filtering by filetype and (c) encryption. +# sub-directories, and (b) filtering by filetype. # Supported formats are: tar.gz, tar.bz2, tar.xz and zip. #### use strict; @@ -70,10 +70,11 @@ if (!&LONCAPA::loncgi::check_cookie_and_ &Apache::lonlocal::get_language_handle(); my %lt = &Apache::lonlocal::texthash ( indi => 'Invalid directory name', + noau => 'Archive creation only available to Author', outo => 'Output of command:', comp => 'Archive creation complete.', erro => 'An error occurred.', - cctf => 'Cannot create tar file', + cctf => 'Cannot create tar file', dtf => 'Download tar file', ); # Get the identifier and set a lock @@ -82,13 +83,14 @@ if (!&LONCAPA::loncgi::check_cookie_and_ &Apache::lonlocal::get_language_handle(); &Apache::loncommon::content_type(undef,'text/html'); my $identifier = $ENV{'QUERY_STRING'}; - my ($hashref,$dir,$dirurl,$jsdirurl,$auname,$audom,$allowed,$error,$encrypt,$enckey,$format,$compress); + my ($hashref,$dir,$dirurl,$jsdirurl,$auname,$audom,$allowed,$error, + $format,$compress,$fname,$extension,$adload,$url,$mime); my @posstypes = qw(problem library sty sequence page task rights meta xml html xhtml htm xhtm css js tex txt gif jpg jpeg png svg other); - if (($identifier) && (exists($env{'cgi.'.$identifier.'.archive'}))) { + if (($identifier =~ /^\d+_\d+_\d+$/) && (exists($env{'cgi.'.$identifier.'.archive'}))) { $hashref = &Apache::lonnet::thaw_unescape($env{'cgi.'.$identifier.'.archive'}); if (ref($hashref) eq 'HASH') { $dir = $hashref->{'dir'}; - # check for traversal + $dir =~ s{\.+}{.}g; if (-d $dir) { $dirurl = $dir; ($auname,$audom) = &Apache::lonnet::constructaccess($dir); @@ -98,7 +100,7 @@ if (!&LONCAPA::loncgi::check_cookie_and_ $maxdepth = $prefix =~ tr{/}{}; $jsdirurl = &js_escape($dirurl); if (($auname eq $env{'user.name'}) && ($audom eq $env{'user.domain'}) && - ($env{'environment.authorarchive'})) { + ($env{'environment.canarchive'})) { $allowed = 1; if ($hashref->{'recurse'}) { $recurse = 1; @@ -128,10 +130,6 @@ if (!&LONCAPA::loncgi::check_cookie_and_ } } } - if ((exists($hashref->{'encrypt'}) && $hashref->{'encrypt'} ne '')) { - $encrypt = 1; - $enckey = $hashref->{'encrypt'}; - } if ((exists($hashref->{'format'}) && $hashref->{'format'} =~ /^zip$/i)) { $format = lc($hashref->{'format'}); } else { @@ -144,6 +142,17 @@ if (!&LONCAPA::loncgi::check_cookie_and_ $compress = 'gzip'; } } + if ($hashref->{'adload'}) { + $adload = $hashref->{'adload'}; + } + if ($hashref->{'fname'}) { + $fname = $hashref->{'fname'}; + } + if ($hashref->{'extension'}) { + $extension = $hashref->{'extension'}; + } + } else { + $error = 'noau'; } } } else { @@ -152,8 +161,10 @@ if (!&LONCAPA::loncgi::check_cookie_and_ } else { $error = 'nohash'; } -# delete cgi.$identifier.archive from %env - &Apache::lonnet::delenv('cgi.'.$identifier.'.archive'); +# delete cgi.$identifier.archive from %env if error + if ($error) { + &Apache::lonnet::delenv('cgi.'.$identifier.'.archive'); + } } else { $error = 'noid'; } @@ -175,22 +186,16 @@ if (!&LONCAPA::loncgi::check_cookie_and_ {'href' => '', 'text' => $title}]; } - my $js; - print &Apache::loncommon::start_page($title, - $js, - {'bread_crumbs' => $brcrum,})."\n". - '