line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# DESCRIPTION: |
3
|
|
|
|
|
|
|
# Plesk Expand communicate interface. Static methods for managing Plesk user accounts from Plesk Expand. |
4
|
|
|
|
|
|
|
# AUTHORS: |
5
|
|
|
|
|
|
|
# Pavel Odintsov (nrg) |
6
|
|
|
|
|
|
|
# |
7
|
|
|
|
|
|
|
#======================================================================== |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
package API::PleskExpand::Accounts; |
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
1686
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
36
|
|
12
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
32
|
|
13
|
|
|
|
|
|
|
|
14
|
1
|
|
|
1
|
|
400
|
use API::Plesk::Methods; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
use Data::Dumper; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
our $VERSION = '1.04'; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 NAME |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
API::PleskExpand::Accounts - extension module for the management Plesk user accounts from Plesk Expand. |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head1 SYNOPSIS |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
Directly not used, calls via API::PleskExpand. |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
use API::PleskExpand; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
some code |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head1 DESCRIPTION |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
The module provides full support operations with Plesk accounts from Plesk Expand. |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=head1 EXPORT |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
None by default. |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=cut |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head1 METHODS |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=over 3 |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=item create() |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
Params: |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
'select' => 'optimal', |
50
|
|
|
|
|
|
|
'template-id' => 1, |
51
|
|
|
|
|
|
|
'attach_to_template' => 1, # attach account to a certain template |
52
|
|
|
|
|
|
|
'general_info' => { |
53
|
|
|
|
|
|
|
login => 'plesk_login', |
54
|
|
|
|
|
|
|
pname => 'perldonal name', |
55
|
|
|
|
|
|
|
passwd => 'userpasswd', |
56
|
|
|
|
|
|
|
status => 0, # active |
57
|
|
|
|
|
|
|
cname => '', # company name |
58
|
|
|
|
|
|
|
phone => '', |
59
|
|
|
|
|
|
|
fax => '', |
60
|
|
|
|
|
|
|
email => '', |
61
|
|
|
|
|
|
|
address => '', |
62
|
|
|
|
|
|
|
city => '', |
63
|
|
|
|
|
|
|
state => '', # state, for USA only |
64
|
|
|
|
|
|
|
pcode => '', |
65
|
|
|
|
|
|
|
country => 'RU', |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
You can let Plesk Expand automatically select a Plesk server based on certain filtering parameters (params for 'select' field): |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
'optimal' -- Least Integral Estimate (% used) selects the least loaded server (integrally estimated). |
71
|
|
|
|
|
|
|
'min_domains' -- Least Domains (% used) registers a client on the server with the minimum number of domains. |
72
|
|
|
|
|
|
|
'max_diskspace' -- Least Disk Space (% used) registers a client on the server with the minimum disk space used. |
73
|
|
|
|
|
|
|
'' -- Select manually, Specify the target Plesk server by selecting its name from the list. |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
When choosing a 'manual' (select => '') option you should set server_id! |
76
|
|
|
|
|
|
|
For 'optimal', 'min_domains', 'max_diskspace' you can ask additional server group id ('group_id' params) or server keyword ('server_keyword' param); |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
Return (Data::Dumper output): |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
VAR1 = bless( { |
82
|
|
|
|
|
|
|
'answer_data' => [ { |
83
|
|
|
|
|
|
|
'server_id' => '1', |
84
|
|
|
|
|
|
|
'status' => 'ok', |
85
|
|
|
|
|
|
|
'expiration' => '-1', |
86
|
|
|
|
|
|
|
'tmpl_id' => '1', |
87
|
|
|
|
|
|
|
'id' => '15' |
88
|
|
|
|
|
|
|
} ], |
89
|
|
|
|
|
|
|
'error_codes' => '' |
90
|
|
|
|
|
|
|
}, 'API::Plesk::Response' ); |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=cut |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
# Create element |
95
|
|
|
|
|
|
|
# STATIC |
96
|
|
|
|
|
|
|
sub create { |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
my %params = @_; |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
if (ref $params{'general_info'} eq 'HASH') { |
101
|
|
|
|
|
|
|
my $template = ''; |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
if ($params{'template-id'}) { |
104
|
|
|
|
|
|
|
$template = create_node('tmpl_id', $params{'template-id'}) . |
105
|
|
|
|
|
|
|
( $params{'attach_to_template'} ? create_node('attach_to_template', '') : '' ); |
106
|
|
|
|
|
|
|
} else { |
107
|
|
|
|
|
|
|
return ''; # template required |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
my $select = ''; |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
if ($params{'select'}) { |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
if ( $params{'group_id'} ) { |
115
|
|
|
|
|
|
|
$select = create_node( 'server_auto', create_node( $params{'select'}, '') . |
116
|
|
|
|
|
|
|
create_node( 'group_id', $params{'group_id'} ) |
117
|
|
|
|
|
|
|
); |
118
|
|
|
|
|
|
|
} elsif ( $params{'server_keyword'} ) { |
119
|
|
|
|
|
|
|
$select = create_node( 'server_auto', create_node( $params{'select'}, '') ). |
120
|
|
|
|
|
|
|
create_node( 'server_keyword', $params{'server_keyword'} ); |
121
|
|
|
|
|
|
|
} else { |
122
|
|
|
|
|
|
|
$select = create_node( 'server_auto', create_node( $params{'select'}, '') ); |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
} else { |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
if ( $params{'server_id'} ) { |
127
|
|
|
|
|
|
|
$select = create_node( 'server_id', $params{'server_id'} ); |
128
|
|
|
|
|
|
|
} else { |
129
|
|
|
|
|
|
|
return ''; # server_id required! |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
return create_node( 'add_use_template', |
134
|
|
|
|
|
|
|
generate_info_block('gen_info', %{ $params{'general_info'} } ) . '' . $template . $select); |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
} else { |
137
|
|
|
|
|
|
|
return ''; # not enought data |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
# Parse XML response |
143
|
|
|
|
|
|
|
# STATIC |
144
|
|
|
|
|
|
|
sub create_response_parse { |
145
|
|
|
|
|
|
|
return abstract_parser('add_use_template', +shift, [ ]); |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=item modify(%params) |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
Changes the account params. |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
Params: |
154
|
|
|
|
|
|
|
general_info -- hashref`s with new user details |
155
|
|
|
|
|
|
|
id -- client id |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
Return: |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
$VAR1 = bless( { |
161
|
|
|
|
|
|
|
'answer_data' => [ { |
162
|
|
|
|
|
|
|
'server_id' => '1', |
163
|
|
|
|
|
|
|
'status' => 'ok', |
164
|
|
|
|
|
|
|
'tmpl_id' => '1', |
165
|
|
|
|
|
|
|
'id' => '15', |
166
|
|
|
|
|
|
|
'plesk_client_id' => '384', |
167
|
|
|
|
|
|
|
'login' => 'suxdffffxx' |
168
|
|
|
|
|
|
|
} ], |
169
|
|
|
|
|
|
|
'error_codes' => '' |
170
|
|
|
|
|
|
|
}, 'API::Plesk::Response' ); |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
Example (client deactivation): |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
print Dumper $client->Accounts->modify( |
176
|
|
|
|
|
|
|
id => 10, |
177
|
|
|
|
|
|
|
general_info => { status => 16 } |
178
|
|
|
|
|
|
|
); |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=cut |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
# Modify element |
183
|
|
|
|
|
|
|
# STATIC |
184
|
|
|
|
|
|
|
sub modify { |
185
|
|
|
|
|
|
|
my %params = @_; |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
if (ref $params{'general_info'} eq 'HASH') { |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
my $filter = ''; |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
if ($params{'id'}) { |
192
|
|
|
|
|
|
|
$filter = create_filter(login_field_name => 'id', id => $params{'id'}); |
193
|
|
|
|
|
|
|
} else { |
194
|
|
|
|
|
|
|
return ''; # filter required! |
195
|
|
|
|
|
|
|
} |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
return create_node('set', $filter . '' . create_node('values', |
199
|
|
|
|
|
|
|
generate_info_block('gen_info', %{ $params{'general_info'} } ) ) ); |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
} else { |
202
|
|
|
|
|
|
|
return ''; # general_info field required ! |
203
|
|
|
|
|
|
|
} |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
# выключение клиента |
206
|
|
|
|
|
|
|
my $data=<
|
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
1 |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
16 |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
DOC |
221
|
|
|
|
|
|
|
# включаем клиента |
222
|
|
|
|
|
|
|
my $data1 = <
|
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
1 |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
0 |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
DOC |
237
|
|
|
|
|
|
|
} |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
# SET response handler |
241
|
|
|
|
|
|
|
# STATIC |
242
|
|
|
|
|
|
|
sub modify_response_parse { |
243
|
|
|
|
|
|
|
return abstract_parser('set', +shift, []); |
244
|
|
|
|
|
|
|
} |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
=item delete(%params) |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
Delete accounts. |
250
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
Params: |
252
|
|
|
|
|
|
|
id -- client id in Plesk |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
Return: |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
$VAR1 = bless( { |
257
|
|
|
|
|
|
|
'answer_data' => [ { |
258
|
|
|
|
|
|
|
'server_id' => '1', |
259
|
|
|
|
|
|
|
'status' => 'ok', |
260
|
|
|
|
|
|
|
'id' => '15' |
261
|
|
|
|
|
|
|
} ], |
262
|
|
|
|
|
|
|
'error_codes' => '' |
263
|
|
|
|
|
|
|
}, 'API::Plesk::Response' ); |
264
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
Example: |
267
|
|
|
|
|
|
|
print Dumper $client->Accounts->delete( id => 11 ); |
268
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
=back |
270
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
=cut |
272
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
# Delete element |
275
|
|
|
|
|
|
|
# STATIC( %args ) |
276
|
|
|
|
|
|
|
sub delete { |
277
|
|
|
|
|
|
|
my %params = @_; |
278
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
my $filter = ''; |
280
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
if ($params{'id'}) { |
282
|
|
|
|
|
|
|
$filter = create_filter( id => $params{'id'}); |
283
|
|
|
|
|
|
|
} else { |
284
|
|
|
|
|
|
|
return ''; # id required! |
285
|
|
|
|
|
|
|
} |
286
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
|
288
|
|
|
|
|
|
|
return create_node('del', '' . $filter); |
289
|
|
|
|
|
|
|
} |
290
|
|
|
|
|
|
|
|
291
|
|
|
|
|
|
|
|
292
|
|
|
|
|
|
|
# DEL response handler |
293
|
|
|
|
|
|
|
# STATIC |
294
|
|
|
|
|
|
|
sub delete_response_parse { |
295
|
|
|
|
|
|
|
return abstract_parser('del', +shift, [ ]); |
296
|
|
|
|
|
|
|
} |
297
|
|
|
|
|
|
|
|
298
|
|
|
|
|
|
|
|
299
|
|
|
|
|
|
|
# Get all element data |
300
|
|
|
|
|
|
|
# STATIC |
301
|
|
|
|
|
|
|
sub get { |
302
|
|
|
|
|
|
|
my %params = @_; |
303
|
|
|
|
|
|
|
|
304
|
|
|
|
|
|
|
unless ($params{all}) { |
305
|
|
|
|
|
|
|
return ''; |
306
|
|
|
|
|
|
|
} |
307
|
|
|
|
|
|
|
|
308
|
|
|
|
|
|
|
return create_node( 'get', |
309
|
|
|
|
|
|
|
create_node('filter', '') . create_node( 'dataset', create_node('gen_info') ) |
310
|
|
|
|
|
|
|
) . ''; |
311
|
|
|
|
|
|
|
} |
312
|
|
|
|
|
|
|
|
313
|
|
|
|
|
|
|
|
314
|
|
|
|
|
|
|
# GET response handler |
315
|
|
|
|
|
|
|
# STATIC |
316
|
|
|
|
|
|
|
sub get_response_parse { |
317
|
|
|
|
|
|
|
my $answer = abstract_parser('get', +shift, [ ], 'system_error' ); |
318
|
|
|
|
|
|
|
|
319
|
|
|
|
|
|
|
if (ref $answer eq 'ARRAY') { |
320
|
|
|
|
|
|
|
for my $domain (@$answer) { |
321
|
|
|
|
|
|
|
$domain->{data} = xml_extract_values($domain->{data} =~ m#(.*?)#); |
322
|
|
|
|
|
|
|
} |
323
|
|
|
|
|
|
|
} elsif ($answer) { |
324
|
|
|
|
|
|
|
$answer->{data} = xml_extract_values($answer->{data} =~ m#(.*?)#); |
325
|
|
|
|
|
|
|
} |
326
|
|
|
|
|
|
|
|
327
|
|
|
|
|
|
|
return $answer; |
328
|
|
|
|
|
|
|
} |
329
|
|
|
|
|
|
|
|
330
|
|
|
|
|
|
|
|
331
|
|
|
|
|
|
|
1; |
332
|
|
|
|
|
|
|
|
333
|
|
|
|
|
|
|
__END__ |