[prev in list] [next in list] [prev in thread] [next in thread]
List: proftpd-committers
Subject: [ProFTPD-committers] proftpd/contrib ftpmail,1.6,1.7
From: TJ Saunders <castaglia () users ! sourceforge ! net>
Date: 2013-02-27 5:35:25
Message-ID: E1UAZfs-0003RG-3G () sfs-ml-2 ! v29 ! ch3 ! sourceforge ! com
[Download RAW message or body]
Update of /cvsroot/proftp/proftpd/contrib
In directory sfp-cvs-1.v30.ch3.sourceforge.com:/tmp/cvs-serv15021/contrib
Modified Files:
ftpmail
Log Message:
Bug#3709 - Support download-triggered emails in the ftpmail script.
Index: ftpmail
===================================================================
RCS file: /cvsroot/proftp/proftpd/contrib/ftpmail,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- ftpmail 23 May 2011 21:25:44 -0000 1.6
+++ ftpmail 27 Feb 2013 05:35:23 -0000 1.7
@@ -1,6 +1,6 @@
#!/usr/bin/env perl
# ---------------------------------------------------------------------------
-# Copyright (C) 2008-2011 TJ Saunders <tj@castaglia.org>
+# Copyright (C) 2008-2013 TJ Saunders <tj@castaglia.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -31,8 +31,8 @@
my $opts = {};
GetOptions($opts, 'attach-file', 'fifo=s', 'from=s', 'help', 'ignore-users=s',
- 'log=s', 'recipient=s@', 'sleep=s', 'smtp-server=s', 'subject=s',
- 'watch-users=s', 'auth=s');
+ 'log=s', 'recipient=s@', 'upload-recipient=s@', 'download-recipient=s@',
+ 'sleep=s', 'smtp-server=s', 'subject=s', 'watch-users=s', 'auth=s');
if ($opts->{help}) {
usage();
@@ -51,11 +51,23 @@
}
my $from = $opts->{from};
-unless ($opts->{recipient}) {
- print STDERR "$program: missing required --recipient parameter\n";
+unless ($opts->{recipient} ||
+ $opts->{'upload-recipient'}) {
+ print STDERR "$program: missing required --recipient (or --upload-recipient) parameter\n";
exit 1;
}
-my $recipients = $opts->{recipient};
+my $upload_recipients = $opts->{recipient};
+
+# The --upload-recipient list takes precedence over the (deprecated)
+# --recipient list.
+if (defined($opts->{'upload-recipient'})) {
+ $upload_recipients = $opts->{'upload-recipient'};
+}
+
+my $download_recipients = undef;
+if (defined($opts->{'download-recipient'})) {
+ $download_recipients = $opts->{'download-recipient'};
+}
unless ($opts->{'smtp-server'}) {
print STDERR "$program: missing required --smtp-server parameter\n";
@@ -125,6 +137,14 @@
$send_email = 1;
}
+ if (defined($download_recipients)) {
+ # If we have a list of download email recipients, it means we should
+ # send emails for downloads, too.
+ if ($xfer_direction eq 'o') {
+ $send_email = 1;
+ }
+ }
+
if ($send_email) {
# First, check for any specific --watch-users filter. If configured,
@@ -155,6 +175,7 @@
auth_mode => $access_mode,
user => $user_name,
status => $completion_status,
+ direction => $xfer_direction,
});
}
}
@@ -246,33 +267,38 @@
}
sub send_email {
- my $upload_info = shift;
+ my $transfer_info = shift;
- my $file = $upload_info->{file};
+ my $file = $transfer_info->{file};
my $file_str = basename($file);
- my $subject = "User '$upload_info->{user}' uploaded file '$file_str' via FTP";
+ my $transferred = 'uploaded';
+ if ($transfer_info->{direction} eq 'o') {
+ $transferred = 'downloaded';
+ }
+
+ my $subject = "User '$transfer_info->{user}' $transferred file '$file_str' via FTP";
if ($opts->{subject}) {
$subject = $opts->{subject};
}
my $bytes_str = "bytes";
- if ($upload_info->{size} == 1) {
+ if ($transfer_info->{size} == 1) {
$bytes_str = "byte";
}
my $status = "Completed";
- if ($upload_info->{status} eq 'i') {
+ if ($transfer_info->{status} eq 'i') {
$status = "Incomplete";
}
my $secs_str = "secs";
- if ($upload_info->{duration} == 1) {
+ if ($transfer_info->{duration} == 1) {
$secs_str = "sec";
}
my $type_str = "Binary";
- if ($upload_info->{transfer_type} eq 'a') {
+ if ($transfer_info->{transfer_type} eq 'a') {
$type_str = "ASCII";
}
@@ -285,13 +311,13 @@
my $text = <<EOT;
File just uploaded via FTP:
- User: $upload_info->{user}
- Client: $upload_info->{client}
+ User: $transfer_info->{user}
+ Client: $transfer_info->{client}
File: $file $attached
- Size: $upload_info->{size} $bytes_str
- At: $upload_info->{timestamp}
- Duration: $upload_info->{duration} $secs_str
+ Size: $transfer_info->{size} $bytes_str
+ At: $transfer_info->{timestamp}
+ Duration: $transfer_info->{duration} $secs_str
Status: $status
Transfer type: $type_str
@@ -303,10 +329,16 @@
my $email_info = {
smtp => $smtp_server,
From => $from,
- To => join(', ', @$recipients),
Subject => $subject,
};
+ if ($transfer_info->{direction} eq 'i') {
+ $email_info->{To} = join(', ', @$upload_recipients);
+
+ } elsif ($transfer_info->{direction} eq 'o') {
+ $email_info->{To} = join(', ', @$download_recipients);
+ }
+
if ($opts->{'auth'}) {
$email_info->{'auth'} = $smtp_auth;
}
@@ -340,7 +372,7 @@
$email_info->{Body} .= "$boundary\n";
$email_info->{Body} .= "Content-Disposition: attachment; filename=\"$file\"\n";
- if ($upload_info->{transfer_type} eq 'a') {
+ if ($transfer_info->{transfer_type} eq 'a') {
$email_info->{Body} .= "Content-Type: text/plain; charset=\"iso-8859-1\"\n\n";
$email_info->{Body} .= $attach;
@@ -380,7 +412,8 @@
print <<EOH;
usage: $program [--help] [--fifo \$path] [--from \$addr] [--log \$path]
- [--recipient \$addr] [--subject \$string] [--smtp-server \$addr]
+ [--recipient \$addrs] [--upload-recipient \$addrs]
+ [--download-recipient \$addrs] [--subject \$string] [--smtp-server \$addr]
[--attach-file] [--ignore-users \$regex | --watch-users \$regex]
The purpose of this script is to monitor the TransferLog written by proftpd
@@ -429,6 +462,16 @@
used multiple times to specify multiple recipients.
AT LEAST ONE recipient is REQUIRED.
+ --upload-recipient Same as --recipient.
+
+ --download-recipient \$addr
+ Specifies an email address to which to send an email
+ notification of the B<download>. This option can be
+ used multiple times to specify multiple recipients.
+
+ If this option is specified, then C<ftpmail> will
+ watch for FTP downloads as well as uploads.
+
--smtp-server \$addr Specifies the SMTP server to which to send the email.
This parameter is REQUIRED.
------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_feb
_______________________________________________
ProFTPD Committers Mailing List
proftpd-committers@proftpd.org
https://lists.sourceforge.net/lists/listinfo/proftp-committers
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic