1 # Copyright (c) 2010-2012 Zmanda, Inc. All Rights Reserved.
3 # This program is free software; you can redistribute it and/or modify it
4 # under the terms of the GNU General Public License version 2 as published
5 # by the Free Software Foundation.
7 # This program is distributed in the hope that it will be useful, but
8 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
9 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 # You should have received a copy of the GNU General Public License along
13 # with this program; if not, write to the Free Software Foundation, Inc.,
14 # 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 # Contact information: Zmanda Inc., 465 S. Mathilda Ave., Suite 300
17 # Sunnyvale, CA 94085, USA, or: http://www.zmanda.com
19 package Amanda::Interactivity::email;
23 use POSIX qw( :errno_h );
26 @ISA = qw( Amanda::Interactivity );
30 use Amanda::Debug qw( debug );
31 use Amanda::Config qw( :getconf );
33 use Amanda::MainLoop qw( :GIOCondition );
37 Amanda::Interactivity::email -- Interactivity class to send user request by email
41 Amanda::Interactivity class to write user request by email
47 my $properties = shift;
50 send_email_src => undef,
51 check_file_src => undef,
52 properties => $properties,
55 return bless ($self, $class);
61 if ($self->{'send_email_src'}) {
62 $self->{'send_email_src'}->remove();
64 if ($self->{'check_file_src'}) {
65 $self->{'check_file_src'}->remove();
74 my $message = $params{'message'};
75 my $label = $params{'label'};
76 my $new_volume = $params{'new_volume'};
77 my $err = $params{'err'};
78 my $chg_name = $params{'chg_name'};
81 if (defined $self->{'properties'}->{'resend-delay'}) {
82 $resend_delay = 1000 * $self->{'properties'}->{'resend-delay'}->{'values'}->[0];
85 if (defined $self->{'properties'}->{'check-file'}) {
86 $check_file = $self->{'properties'}->{'check-file'}->{'values'}->[0];
89 my $check_file_delay = 10000;
90 if (defined $self->{'properties'}->{'check-file-delay'}) {
91 $check_file_delay = 1000 * $self->{'properties'}->{'check_file-delay'}->{'values'}->[0];
94 my $mailer = getconf($CNF_MAILER);
97 $subject = "AMANDA VOLUME REQUEST: $label";
99 $subject = "AMANDA VOLUME REQUEST: new volume";
103 if (defined $self->{'properties'}->{'mailto'}) {
104 $mailto = $self->{'properties'}->{'mailto'}->{'values'};
106 my $a = getconf($CNF_MAILTO);
107 my @mailto = split (/ /, getconf($CNF_MAILTO));
110 my @cmd = ("$mailer", "-s", $subject, @{$mailto});
113 $send_email_cb = sub {
114 $self->{'send_email_src'} = undef;
115 debug("cmd: " . join(" ", @cmd) . "\n");
117 $pid = open3($fh, ">&2", ">&2", @cmd);
118 print {$fh} "$err\n";
119 if ($label && $new_volume) {
120 print {$fh} "Insert volume labeled '$label' or a new volume in $chg_name\n";
122 print {$fh} "Insert volume labeled '$label' in $chg_name\n";
124 print {$fh} "Insert a new volume in $chg_name\n";
127 print {$fh} "or write the name of a new changer in '$check_file'\n";
128 print {$fh} "or write 'abort' in the file to abort the scan.\n";
134 $self->{'send_email_src'} = Amanda::MainLoop::call_after($resend_delay, $send_email_cb);
139 $check_file_cb = sub {
140 $self->{'check_file_src'} = undef;
142 if (-f $check_file) {
144 open ($fh, '<' , $check_file);
148 if ($line =~ /^abort$/i) {
149 return $params{'request_cb'}->(
150 Amanda::Changer::Error->new('fatal',
151 message => "Aborted by user"));
153 return $params{'request_cb'}->(undef, $line);
156 $self->{'check_file_src'} = Amanda::MainLoop::call_after($check_file_delay, $check_file_cb);