1 # Copyright (c) 2010-2012 Zmanda, Inc. All Rights Reserved.
3 # This program is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU General Public License
5 # as published by the Free Software Foundation; either version 2
6 # of the License, or (at your option) any later version.
8 # This program is distributed in the hope that it will be useful, but
9 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
10 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 # You should have received a copy of the GNU General Public License along
14 # with this program; if not, write to the Free Software Foundation, Inc.,
15 # 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 # Contact information: Zmanda Inc., 465 S. Mathilda Ave., Suite 300
18 # Sunnyvale, CA 94085, USA, or: http://www.zmanda.com
20 package Amanda::Interactivity::email;
24 use POSIX qw( :errno_h );
27 @ISA = qw( Amanda::Interactivity );
31 use Amanda::Debug qw( debug );
32 use Amanda::Config qw( :getconf );
34 use Amanda::MainLoop qw( :GIOCondition );
38 Amanda::Interactivity::email -- Interactivity class to send user request by email
42 Amanda::Interactivity class to write user request by email
48 my $properties = shift;
51 send_email_src => undef,
52 check_file_src => undef,
53 properties => $properties,
56 return bless ($self, $class);
62 if ($self->{'send_email_src'}) {
63 $self->{'send_email_src'}->remove();
65 if ($self->{'check_file_src'}) {
66 $self->{'check_file_src'}->remove();
75 my $message = $params{'message'};
76 my $label = $params{'label'};
77 my $new_volume = $params{'new_volume'};
78 my $err = $params{'err'};
79 my $chg_name = $params{'chg_name'};
82 if (defined $self->{'properties'}->{'resend-delay'}) {
83 $resend_delay = 1000 * $self->{'properties'}->{'resend-delay'}->{'values'}->[0];
86 if (defined $self->{'properties'}->{'check-file'}) {
87 $check_file = $self->{'properties'}->{'check-file'}->{'values'}->[0];
90 my $check_file_delay = 10000;
91 if (defined $self->{'properties'}->{'check-file-delay'}) {
92 $check_file_delay = 1000 * $self->{'properties'}->{'check_file-delay'}->{'values'}->[0];
95 my $mailer = getconf($CNF_MAILER);
98 $subject = "AMANDA VOLUME REQUEST: $label";
100 $subject = "AMANDA VOLUME REQUEST: new volume";
104 if (defined $self->{'properties'}->{'mailto'}) {
105 $mailto = $self->{'properties'}->{'mailto'}->{'values'};
107 my $a = getconf($CNF_MAILTO);
108 my @mailto = split (/ /, getconf($CNF_MAILTO));
111 my @cmd = ("$mailer", "-s", $subject, @{$mailto});
114 $send_email_cb = sub {
115 $self->{'send_email_src'} = undef;
116 debug("cmd: " . join(" ", @cmd) . "\n");
118 $pid = open3($fh, ">&2", ">&2", @cmd);
119 print {$fh} "$err\n";
120 if ($label && $new_volume) {
121 print {$fh} "Insert volume labeled '$label' or a new volume in $chg_name\n";
123 print {$fh} "Insert volume labeled '$label' in $chg_name\n";
125 print {$fh} "Insert a new volume in $chg_name\n";
128 print {$fh} "or write the name of a new changer in '$check_file'\n";
129 print {$fh} "or write 'abort' in the file to abort the scan.\n";
135 $self->{'send_email_src'} = Amanda::MainLoop::call_after($resend_delay, $send_email_cb);
140 $check_file_cb = sub {
141 $self->{'check_file_src'} = undef;
143 if (-f $check_file) {
145 open ($fh, '<' , $check_file);
149 if ($line =~ /^abort$/i) {
150 return $params{'request_cb'}->(
151 Amanda::Changer::Error->new('fatal',
152 message => "Aborted by user"));
154 return $params{'request_cb'}->(undef, $line);
157 $self->{'check_file_src'} = Amanda::MainLoop::call_after($check_file_delay, $check_file_cb);