line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Barracuda::Api ; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
14695
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
25
|
|
4
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
23
|
|
5
|
1
|
|
|
1
|
|
503
|
use Data::Dumper; |
|
1
|
|
|
|
|
6482
|
|
|
1
|
|
|
|
|
55
|
|
6
|
1
|
|
|
1
|
|
445
|
use XML::RPC; |
|
1
|
|
|
|
|
7356
|
|
|
1
|
|
|
|
|
27
|
|
7
|
1
|
|
|
1
|
|
6
|
use Carp qw(croak); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
582
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub new { |
12
|
0
|
|
|
0
|
1
|
|
my ( $classe, $ref_args ) = @_; |
13
|
|
|
|
|
|
|
|
14
|
0
|
|
0
|
|
|
|
$classe = ref($classe) || $classe; |
15
|
|
|
|
|
|
|
|
16
|
0
|
|
|
|
|
|
my $self = {}; |
17
|
0
|
|
|
|
|
|
bless( $self, $classe ); |
18
|
|
|
|
|
|
|
|
19
|
0
|
|
|
|
|
|
foreach my $attribut ( qw/domain password/ ) { |
20
|
0
|
0
|
|
|
|
|
croak("Must set $attribut") unless $ref_args->{$attribut} |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
# Default value if some attributes are not set |
24
|
0
|
0
|
|
|
|
|
$ref_args->{port} = 8000 unless defined $ref_args->{port}; |
25
|
0
|
0
|
|
|
|
|
$ref_args->{verbose} = 0 unless defined $ref_args->{verbose}; |
26
|
0
|
0
|
|
|
|
|
$ref_args->{proto} = 'http' unless defined $ref_args->{proto}; |
27
|
|
|
|
|
|
|
|
28
|
0
|
|
|
|
|
|
$self->{_DOMAIN} = $ref_args->{domain}; |
29
|
0
|
|
|
|
|
|
$self->{PORT} = $ref_args->{port}; |
30
|
0
|
|
|
|
|
|
$self->{_PASSWORD} = $ref_args->{password}; |
31
|
0
|
|
|
|
|
|
$self->{VERBOSE} = $ref_args->{verbose}; |
32
|
0
|
|
|
|
|
|
$self->{_PROTO} = $ref_args->{proto}; |
33
|
0
|
|
|
|
|
|
$self->{XMLRPC} = XML::RPC->new("$self->{_PROTO}://$self->{_DOMAIN}:$self->{PORT}/cgi-mod/api.cgi?password=$self->{_PASSWORD}"); |
34
|
|
|
|
|
|
|
|
35
|
0
|
|
|
|
|
|
return $self; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub listAllDomain { |
39
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
40
|
|
|
|
|
|
|
|
41
|
0
|
|
|
|
|
|
$self->{XMLRPC}->call('config.list', { type => 'global', |
42
|
|
|
|
|
|
|
child_type => 'domain' }); |
43
|
|
|
|
|
|
|
|
44
|
0
|
|
|
|
|
|
$self->_parseOutput($self->{XMLRPC}->xml_in()); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub createDomain { |
48
|
0
|
|
|
0
|
1
|
|
my ( $self, $domain, $destination ) = @_; |
49
|
|
|
|
|
|
|
|
50
|
0
|
0
|
0
|
|
|
|
croak('You must define domain and destination') |
51
|
|
|
|
|
|
|
unless ( $domain && $destination); |
52
|
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
|
$self->{XMLRPC}->call('config.create', { parent_type => 'global', |
54
|
|
|
|
|
|
|
parent_path => '', |
55
|
|
|
|
|
|
|
type => 'domain', |
56
|
|
|
|
|
|
|
name => "$domain", |
57
|
|
|
|
|
|
|
mta_relay_advanced_host => "$destination" } ); |
58
|
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
|
$self->_parseOutput($self->{XMLRPC}->xml_in()); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub deleteDomain { |
63
|
0
|
|
|
0
|
1
|
|
my ( $self, $domain ) = @_; |
64
|
|
|
|
|
|
|
|
65
|
0
|
0
|
|
|
|
|
croak('You must define domain') |
66
|
|
|
|
|
|
|
unless ( $domain ); |
67
|
|
|
|
|
|
|
|
68
|
0
|
|
|
|
|
|
$self->{XMLRPC}->call('config.delete', { parent_type => 'global', |
69
|
|
|
|
|
|
|
parent_path => '', |
70
|
|
|
|
|
|
|
type => 'domain', |
71
|
|
|
|
|
|
|
path => "$domain" }); |
72
|
|
|
|
|
|
|
|
73
|
0
|
|
|
|
|
|
$self->_parseOutput($self->{XMLRPC}->xml_in()); |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub createUser { |
77
|
0
|
|
|
0
|
1
|
|
my ( $self, $user ) = @_; |
78
|
|
|
|
|
|
|
|
79
|
0
|
0
|
|
|
|
|
croak('You must define a user') |
80
|
|
|
|
|
|
|
unless ( $user ); |
81
|
|
|
|
|
|
|
|
82
|
0
|
|
|
|
|
|
$self->{XMLRPC}->call('user.create', { |
83
|
|
|
|
|
|
|
user => "$user" }); |
84
|
|
|
|
|
|
|
|
85
|
0
|
|
|
|
|
|
$self->_parseOutput($self->{XMLRPC}->xml_in()); |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub deleteUser { |
89
|
0
|
|
|
0
|
1
|
|
my ( $self, $user ) = @_; |
90
|
|
|
|
|
|
|
|
91
|
0
|
0
|
|
|
|
|
croak('You must define a user') |
92
|
|
|
|
|
|
|
unless ( $user ); |
93
|
|
|
|
|
|
|
|
94
|
0
|
|
|
|
|
|
$self->{XMLRPC}->call('user.remove', { |
95
|
|
|
|
|
|
|
user => "$user" }); |
96
|
|
|
|
|
|
|
|
97
|
0
|
|
|
|
|
|
$self->_parseOutput($self->{XMLRPC}->xml_in()); |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub whitelistSenderForDomain { |
101
|
0
|
|
|
0
|
1
|
|
my ( $self, $domain, $whitelist, $comment ) = @_; |
102
|
|
|
|
|
|
|
|
103
|
0
|
0
|
0
|
|
|
|
croak('You must define domain and whitelist') |
104
|
|
|
|
|
|
|
unless ( $domain && $whitelist); |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
# Do not print anything in comment if not set |
107
|
0
|
0
|
|
|
|
|
$comment = '' unless defined $comment; |
108
|
|
|
|
|
|
|
|
109
|
0
|
|
|
|
|
|
$self->{XMLRPC}->call('config.create', { parent_type => 'domain', |
110
|
|
|
|
|
|
|
parent_path => "$domain", |
111
|
|
|
|
|
|
|
type => 'mta_sender_allow_address', |
112
|
|
|
|
|
|
|
name => "$whitelist", |
113
|
|
|
|
|
|
|
mta_sender_allow_comment => "$comment" }); |
114
|
|
|
|
|
|
|
|
115
|
0
|
|
|
|
|
|
$self->_parseOutput($self->{XMLRPC}->xml_in()); |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
sub blacklistSenderForDomain { |
119
|
0
|
|
|
0
|
1
|
|
my ( $self, $domain, $blacklist, $comment ) = @_; |
120
|
|
|
|
|
|
|
|
121
|
0
|
0
|
0
|
|
|
|
croak('You must define domain and blacklist') |
122
|
|
|
|
|
|
|
unless ( $domain && $blacklist); |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
# Print anything in comment if not set |
125
|
0
|
0
|
|
|
|
|
$comment = '' unless defined $comment; |
126
|
|
|
|
|
|
|
|
127
|
0
|
|
|
|
|
|
$self->{XMLRPC}->call('config.create', { parent_type => 'domain', |
128
|
|
|
|
|
|
|
parent_path => "$domain", |
129
|
|
|
|
|
|
|
type => 'mta_sender_block_address', |
130
|
|
|
|
|
|
|
name => "$blacklist", |
131
|
|
|
|
|
|
|
mta_sender_allow_comment => "$comment" }); |
132
|
|
|
|
|
|
|
|
133
|
0
|
|
|
|
|
|
$self->_parseOutput($self->{XMLRPC}->xml_in()); |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
sub _parseOutput { |
137
|
0
|
|
|
0
|
|
|
my ( $self, $output ) = @_; |
138
|
0
|
|
|
|
|
|
my $result = ''; |
139
|
|
|
|
|
|
|
|
140
|
0
|
0
|
|
|
|
|
if ( $self->{VERBOSE} == 0 ) { |
141
|
0
|
|
|
|
|
|
while ( $output =~ m/CDATA\[(.*)\]\]/g ) { |
142
|
0
|
|
|
|
|
|
$result .= "$1\n"; |
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
} else { |
145
|
0
|
|
|
|
|
|
$result = $output; |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
|
148
|
0
|
|
|
|
|
|
$result |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
1; |
152
|
|
|
|
|
|
|
__END__ |