Email notification on completion of download
authorJamie Cameron <jcameron@webmin.com>
Sat, 19 Apr 2008 18:17:44 +0000 (18:17 +0000)
committerJamie Cameron <jcameron@webmin.com>
Sat, 19 Apr 2008 18:17:44 +0000 (18:17 +0000)
updown/download.cgi
updown/index.cgi
updown/lang/en
updown/updown-lib.pl

index 54689b3..4f6be41 100755 (executable)
@@ -74,6 +74,11 @@ if ($in{'bg'} && $can_schedule) {
                         $in{'day'}, $in{'month'}, $in{'year'}-1900) };
        $@ && &error($text{'download_edate2'});
        }
+if (defined($in{'email_def'}) && !$in{'email_def'}) {
+       # Validate email
+       $in{'email'} =~ /\S/ || &error($text{'download_eemail'});
+       $download{'email'} = $in{'email'};
+       }
 
 # Create the directory if needed
 if (!-d $download{'dir'} && $in{'mkdir'}) {
@@ -109,7 +114,7 @@ if ($in{'bg'} && $can_background) {
 
        if (!$can_schedule) {
                # Just run this script right now
-               system("$atjob_cmd $download{'id'} >/dev/null 2>&1 </dev/null &");
+               &execute_command("$atjob_cmd $download{'id'} &");
                }
        else {
                # Create an At job to do the download
index 5a7e5e0..92fb08b 100755 (executable)
@@ -78,6 +78,13 @@ if ($can_download) {
                # Download is always right now
                }
 
+       # Email address to notify when done
+       if ($can_schedule || $can_background) {
+               print &ui_table_row($text{'index_email'},
+                       &ui_opt_textbox("email", undef, 40,
+                               $text{'no'}, $text{'index_emailto'}), 3);
+               }
+
        print &ui_table_end();
        print &ui_form_end([ [ undef, $text{'index_down'} ] ]);
        $form++;
index f7b3d01..51caa50 100644 (file)
@@ -37,6 +37,8 @@ index_tabfetch=Download from server
 index_descdownload=This form allows you to download files or web pages from HTTP or FTP URLs to the system running Webmin. The download can be done immediately, or scheduled for some time in the future.
 index_descupload=This page allows you to upload one or more files from the PC on which your web browser runs to the system running Webmin.
 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
 
 upload_title=Upload Files
 upload_err=Failed to upload files
@@ -104,3 +106,10 @@ fetch_eopen=Failed to open file : $1
 fetch_eaccess=You are not allowed to download files from $1
 fetch_ezip=A directory cannot be downloaded unless the <tt>zip</tt> command is installed
 fetch_eroot=The root directory cannot be downloaded!
+
+email_downmsg=The following download has completed :
+email_downurl=URL: $1
+email_downerr=Error message: $1
+email_downpath=Destination filename: $1
+email_downsize=Downloaded size: $1
+email_subjectd=Download complete
index 8cbdf5e..3232359 100644 (file)
@@ -159,6 +159,21 @@ 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);
+               }
        return $error if ($error);
        push(@{$_[2]}, $path);
        }
@@ -230,5 +245,22 @@ if (defined($old_uid)) {
        }
 }
 
+# send_email_notification(address, subject, message)
+# Send email when some download or upload is complete
+sub send_email_notification
+{
+local ($to, $subject, $msg) = @_;
+if ($module_info{'usermin'}) {
+       &foreign_require("mailbox", "mailbox-lib.pl");
+       local $from = &mailbox::get_preferred_from_address();
+       &mailbox::send_text_mail($from, $to, undef, $subject, $msg);
+       }
+else {
+       &foreign_require("mailboxes", "mailboxes-lib.pl");
+       local $from = &mailboxes::get_from_address();
+       &mailboxes::send_text_mail($from, $to, undef, $subject, $msg);
+       }
+}
+
 1;