eliminate some false laziness in FS::Misc::send_email vs. msg_template/email.pm send_...
[freeside.git] / FS / FS / part_export / status_shellcommands.pm
1 package FS::part_export::status_shellcommands;
2 use base qw( FS::part_export::shellcommands );
3
4 use vars qw( %info );
5 use Tie::IxHash;
6 use String::ShellQuote;
7
8 tie my %options, 'Tie::IxHash',
9   'user' => { label=>'Remote username', default=>'root' },
10
11   'spam_enable'     => { label=>'Spam filtering enable command', },
12   'spam_disable'    => { label=>'Spam filtering disable command', },
13   'spam_tag2_level'  => { label=>'Spam set tag2 level command', },
14   'spam_kill_level' => { label=>'Spam set kill level command', },
15
16   'fail_on_output' => {
17       label => 'Treat any output from the command as an error',
18       type  => 'checkbox',
19   },
20   'ignore_all_errors' => {
21       label => 'Ignore all errors from the command',
22       type  => 'checkbox',
23   },
24 ;
25
26 %info = (
27   'svc'      => 'svc_acct',
28   'desc'     => 'Set mailbox status via shell commands',
29   'options'  => \%options,
30   'nodomain' => '',
31   'notes'    => <<END
32 Set mailbox status information (vacation and spam settings) with shell commands.
33 END
34 );
35
36 #don't want to inherit these from shellcommands
37 sub _export_insert    {}
38 sub _export_replace   {}
39 sub _export_delete    {}
40 sub _export_suspend   {}
41 sub _export_unsuspend {}
42
43 sub export_setstatus {
44   my($self, $svc_acct, $hashref) = @_;
45
46   for (qw( spam_tag2_level spam_kill_level )) {
47     $hashref->{$_} =~ /^\d+(\.\d+)?$/ or return "illegal $_";
48   }
49
50   my @shellargs = (
51     $svc_acct->svcnum,
52     user          => $self->option('user') || 'root',
53     host          => $self->machine,
54     #stdin_string  => $stdin_string,
55     fail_on_output    => $self->option('fail_on_output'),
56     ignore_all_errors => $self->option('ignore_all_errors'),
57     #ignored_errors    => $self->option('ignored_errors') || '',
58   );
59
60   $self->shellcommands_queue( @shellargs, 'command' =>
61     $self->option('spam_enable'). ' '.
62     shell_quote($svc_acct->email)
63   )
64     || $self->shellcommands_queue( @shellargs, 'command' =>
65          $self->option('spam_tag2_level'). ' '.
66          shell_quote($svc_acct->email). ' '.
67          $hashref->{'spam_tag2_level'}
68        )
69     || $self->shellcommands_queue( @shellargs, 'command' =>
70          $self->option('spam_kill_level'). ' '.
71          shell_quote($svc_acct->email). ' '.
72          $hashref->{'spam_kill_level'}
73        )
74   ;
75
76 }
77
78 1;