summaryrefslogtreecommitdiff
path: root/FS/FS/part_export/status_shellcommands.pm
blob: c5200ec507b32f61a0176d49e04b509ae2efe280 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package FS::part_export::status_shellcommands;
use base qw( FS::part_export::shellcommands );

use vars qw( %info );
use Tie::IxHash;
use String::ShellQuote;

tie my %options, 'Tie::IxHash',
  'user' => { label=>'Remote username', default=>'root' },

  'spam_enable'     => { label=>'Spam filtering enable command', },
  'spam_disable'    => { label=>'Spam filtering disable command', },
  'spam_tag2_level'  => { label=>'Spam set tag2 level command', },
  'spam_kill_level' => { label=>'Spam set kill level command', },

  'fail_on_output' => {
      label => 'Treat any output from the command as an error',
      type  => 'checkbox',
  },
  'ignore_all_errors' => {
      label => 'Ignore all errors from the command',
      type  => 'checkbox',
  },
;

%info = (
  'svc'      => 'svc_acct',
  'desc'     => 'Set mailbox status via shell commands',
  'options'  => \%options,
  'nodomain' => '',
  'notes'    => <<END
Set mailbox status information (vacation and spam settings) with shell commands.
END
);

#don't want to inherit these from shellcommands
sub _export_insert    {}
sub _export_replace   {}
sub _export_delete    {}
sub _export_suspend   {}
sub _export_unsuspend {}

sub export_setstatus {
  my($self, $svc_acct, $hashref) = @_;

  for (qw( spam_tag2_level spam_kill_level )) {
    $hashref->{$_} =~ /^\d+(\.\d+)?$/ or return "illegal $_";
  }

  my @shellargs = (
    $svc_acct->svcnum,
    user          => $self->option('user') || 'root',
    host          => $self->machine,
    #stdin_string  => $stdin_string,
    fail_on_output    => $self->option('fail_on_output'),
    ignore_all_errors => $self->option('ignore_all_errors'),
    #ignored_errors    => $self->option('ignored_errors') || '',
  );

  $self->shellcommands_queue( @shellargs, 'command' =>
    $self->option('spam_enable'). ' '.
    shell_quote($svc_acct->email)
  )
    || $self->shellcommands_queue( @shellargs, 'command' =>
         $self->option('spam_tag2_level'). ' '.
         shell_quote($svc_acct->email). ' '.
         $hashref->{'spam_tag2_level'}
       )
    || $self->shellcommands_queue( @shellargs, 'command' =>
         $self->option('spam_kill_level'). ' '.
         shell_quote($svc_acct->email). ' '.
         $hashref->{'spam_kill_level'}
       )
  ;

}

1;