Tabs are now used to layout the upload, download and fetch forms on the module's main page.
Converted all user interface code to use the new Webmin UI library.
The download from server form can be used to fetch an entire directory, which is then returned as a ZIP file.
+---- Changes since 1.410 ----
+Added fields for sending an email notification when a background download or file upload completes.
}
if (defined($in{'email_def'}) && !$in{'email_def'}) {
# Validate email
- $in{'email'} =~ /\S/ || &error($text{'download_eemail'});
+ $in{'email'} =~ /\S/ || &error($text{'upload_eemail'});
$download{'email'} = $in{'email'};
}
[ 1, $text{'yes'} ],
[ 0, $text{'no'} ] ]));
+ # Email notification
+ print &ui_table_row($text{'index_email2'},
+ &ui_opt_textbox("email", undef, 40,
+ $text{'no'}, $text{'index_emailto'}), 3);
+
print &ui_table_end();
print &ui_form_end([ [ "ok", $text{'index_ok'} ] ]);
$form++;
index_descfetch=This page is for downloading a file from the system running Webmin for display in your browser or saving on the same system.
index_email=Send email when downloads are done?
index_emailto=Yes, to address
+index_email2=Send email when uploads are done?
upload_title=Upload Files
upload_err=Failed to upload files
upload_extracted=, and extracted files ..
upload_deleted=, and extracted files before deleting archive ..
upload_notcomp=Not a ZIP or TAR file
+upload_eemail=Missing email address to notify
download_err=Failed to save download
download_enone=No URLs to download entered
email_downpath=Destination filename: $1
email_downsize=Downloaded size: $1
email_subjectd=Download complete
+email_eextract=Failed : $1
+email_extdone_zip=ZIP file extracted
+email_extdone_tar=TAR file extracted
+email_extdone_tgz=Gzipped TAR file extracted
+email_extdone_tbz2=Bzipped TAR file extracted
+email_upfile=Original filename: $1
+email_uppath=Destination filename: $1
+email_upsize=Uploaded size: $1
+email_upextract=Extraction status: $1
+email_subjectu=Upload complete
+email_upmsg=The following uploads have completed :
# Actually download one or more files, and return undef or any error message
sub do_download
{
-local $i;
+local ($i, $error, $msg);
for($i=0; $_[0]->{"url_$i"}; $i++) {
+ $error = undef;
$progress_callback_url = $_[0]->{"url_$i"};
$progress_callback_count = $i;
- local $error;
local $path;
if (-d $_[0]->{'dir'}) {
if ($_[0]->{"page_$i"} =~ /([^\/]+)$/) {
}
unlink($path) if ($error);
&switch_uid_back();
- if ($down->{'email'}) {
- # Send email when done
- local $msg = $text{'email_downmsg'}."\n\n";
- $msg .= &text('email_downurl', $_[0]->{"url_$i"})."\n";
- if ($error) {
- $msg .= &text('email_downerr', $error)."\n";
- }
- else {
- local @st = stat($path);
- $msg .= &text('email_downpath', $path)."\n";
- $msg .= &text('email_downsize',&nice_size($st[7]))."\n";
- }
- &send_email_notification(
- $down->{'email'}, $text{'email_subjectd'}, $msg);
+
+ # Add to email message
+ $msg .= &text('email_downurl', $_[0]->{"url_$i"})."\n";
+ if ($error) {
+ $msg .= &text('email_downerr', $error)."\n";
+ }
+ else {
+ local @st = stat($path);
+ $msg .= &text('email_downpath', $path)."\n";
+ $msg .= &text('email_downsize',&nice_size($st[7]))."\n";
}
- return $error if ($error);
+ $msg .= "\n";
+
+ last if ($error);
push(@{$_[2]}, $path);
}
-return undef;
+
+# Send status email
+if ($down->{'email'}) {
+ # Send email when done
+ $msg = $text{'email_downmsg'}."\n\n".$msg;
+ &send_email_notification(
+ $down->{'email'}, $text{'email_subjectd'}, $msg);
+ }
+
+return $error;
}
# can_write_file(file)
# Validate inputs
$in{'dir'} || &error($text{'upload_edir'});
+if (defined($in{'email_def'}) && !$in{'email_def'}) {
+ $in{'email'} =~ /\S/ || &error($text{'upload_eemail'});
+ $email = $in{'email'};
+ }
if ($can_mode != 3) {
# User can be entered
defined(@uinfo = getpwnam($in{'user'})) ||
}
# Save the actual files
+$msg = undef;
for($i=0; defined($d = $in{"upload$i"}); $i++) {
$f = $in{"upload${i}_filename"};
next if (!$f);
&print_tempfile(FILE, $d);
&close_tempfile(FILE);
push(@uploads, $path);
+ @st = stat($path);
+ $estatus = undef;
if ($in{'zip'}) {
local ($err, $out);
$path =~ /^(\S*\/)/;
close(OUT);
$err = $out if ($?);
}
+ $fmt = "zip";
}
elsif ($path =~ /\.tar$/i) {
if (!&has_command("tar")) {
close(OUT);
$err = $out if ($?);
}
+ $fmt = "tar";
}
elsif ($path =~ /\.(tar\.gz|tgz|tar\.bz|tbz|tar\.bz2|tbz2)$/i) {
local $zipper = $path =~ /bz(2?)$/i ? "bunzip2"
close(OUT);
$err = $out if ($?);
}
+ $fmt = $zipper eq "gunzip" ? "tgz" : "tbz2";
}
else {
# Doesn't look possible
}
}
else {
- $ext{$path} = &text('upload_eextract', $err);
+ $ext{$path} = &text('email_eextract', $err);
}
+ $estatus = $err ? &text('email_extfailed', $err)
+ : &text('email_extdone_'.$fmt);
+ }
+
+ # Add to email message
+ $msg .= &text('email_upfile', $f)."\n";
+ $msg .= &text('email_uppath', $path)."\n";
+ $msg .= &text('email_upsize', &nice_size($st[7]))."\n";
+ if ($estatus) {
+ $msg .= &text('email_upextract', $estatus)."\n";
}
+ $msg .= "\n";
}
# Switch back to root
&unlock_file("$module_config_directory/config");
}
+# Send email
+if ($email && $msg) {
+ $msg = $text{'email_upmsg'}."\n\n".$msg;
+ &send_email_notification($email, $text{'email_subjectu'}, $msg);
+ }
+
&webmin_log("upload", undef, undef, { 'uploads' => \@uploads });
&ui_print_footer("index.cgi?mode=upload", $text{'index_return'});