diff --git a/updown/CHANGELOG b/updown/CHANGELOG index 0f09b5c92..c4e6b3251 100644 --- a/updown/CHANGELOG +++ b/updown/CHANGELOG @@ -8,3 +8,5 @@ Added a popup progress window to track large uploads. 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. diff --git a/updown/download.cgi b/updown/download.cgi index 4f6be41ad..4c150a085 100755 --- a/updown/download.cgi +++ b/updown/download.cgi @@ -76,7 +76,7 @@ if ($in{'bg'} && $can_schedule) { } 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'}; } diff --git a/updown/index.cgi b/updown/index.cgi index 92fb08b04..ee1c5d054 100755 --- a/updown/index.cgi +++ b/updown/index.cgi @@ -202,6 +202,11 @@ if ($can_upload) { [ 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++; diff --git a/updown/lang/en b/updown/lang/en index 51caa5088..26163199a 100644 --- a/updown/lang/en +++ b/updown/lang/en @@ -39,6 +39,7 @@ index_descupload=This page allows you to upload one or more files from the PC on 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 @@ -58,6 +59,7 @@ upload_eextract=, which could not be extracted : $1 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 @@ -113,3 +115,14 @@ email_downerr=Error message: $1 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 : diff --git a/updown/updown-lib.pl b/updown/updown-lib.pl index 32323598d..96d98343f 100644 --- a/updown/updown-lib.pl +++ b/updown/updown-lib.pl @@ -118,11 +118,11 @@ unlink("$downloads_dir/$_[0]->{'id'}.down"); # 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"} =~ /([^\/]+)$/) { @@ -159,25 +159,32 @@ for($i=0; $_[0]->{"url_$i"}; $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"; } - return $error if ($error); + else { + local @st = stat($path); + $msg .= &text('email_downpath', $path)."\n"; + $msg .= &text('email_downsize',&nice_size($st[7]))."\n"; + } + $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) diff --git a/updown/upload.cgi b/updown/upload.cgi index e835a64e8..059fc03b1 100755 --- a/updown/upload.cgi +++ b/updown/upload.cgi @@ -11,6 +11,10 @@ $can_upload || &error($text{'upload_ecannot'}); # 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'})) || @@ -45,6 +49,7 @@ if (!-d $in{'dir'} && $in{'mkdir'}) { } # Save the actual files +$msg = undef; for($i=0; defined($d = $in{"upload$i"}); $i++) { $f = $in{"upload${i}_filename"}; next if (!$f); @@ -61,7 +66,9 @@ for($i=0; defined($d = $in{"upload$i"}); $i++) { &print_tempfile(FILE, $d); &close_tempfile(FILE); push(@uploads, $path); + @st = stat($path); + $estatus = undef; if ($in{'zip'}) { local ($err, $out); $path =~ /^(\S*\/)/; @@ -85,6 +92,7 @@ for($i=0; defined($d = $in{"upload$i"}); $i++) { close(OUT); $err = $out if ($?); } + $fmt = "zip"; } elsif ($path =~ /\.tar$/i) { if (!&has_command("tar")) { @@ -101,6 +109,7 @@ for($i=0; defined($d = $in{"upload$i"}); $i++) { 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" @@ -122,6 +131,7 @@ for($i=0; defined($d = $in{"upload$i"}); $i++) { close(OUT); $err = $out if ($?); } + $fmt = $zipper eq "gunzip" ? "tgz" : "tbz2"; } else { # Doesn't look possible @@ -140,9 +150,20 @@ for($i=0; defined($d = $in{"upload$i"}); $i++) { } } 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 @@ -175,6 +196,12 @@ else { &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'});