API-PleskExpand
view release on metacpan or search on metacpan
API-PleskExpand version 1.00
=======================
The given module is intended for interaction with the XML API of the Plesk Expand centralized hosting panel. API is realized not completely, but there is a full support of operations with Account and Domains.
API::PleskExpand module gives the convenient interface for addition of new functions. Extensions represent modules in a folder Expand with definitions of demanded functions. Each demanded operation is described by two functions: op and op_response_pa...
INSTALLATION
To install this module type the following:
perl Makefile.PL
make
make test
make install
lib/API/PleskExpand.pm view on Meta::CPAN
my $res = $expand_client->Func_Module->operation_type(%params);
if ($res->is_success) {
$res->get_data; # return arr ref of answer blocks
}
=head1 DESCRIPTION
At present the module provides interaction with Plesk Expand 2.2.4 (API 2.2.4.1). Complete support of operations with Accounts, partial support of work with domains. Support of addition of domains to user Accounts.
API::PleskExpand module gives the convenient interface for addition of new functions. Extensions represent modules in a folder Plesk with definitions of demanded functions. Each demanded operation is described by two functions: op and op_response_par...
For example, here the set of subs in the Accounts module is those.
create / create_response_parse
modify / modify_response_parse
delete / delete_response_parse
get / get_response_parse
=head1 EXPORT
lib/API/PleskExpand.pm view on Meta::CPAN
Required params:
api_version -- default: 2.2.4.1
username -- Expand user name (root as default).
password -- Expand password.
url -- full url to Expand XML RPC gate (https://ip.ad.dr.ess::8442/webgate.php').
=cut
sub new {
(undef) = shift @_;
my $self = __PACKAGE__->SUPER::new(@_);
$self->{package_name} = __PACKAGE__;
unless ($self->{api_version}) {
$self->{api_version} = '2.2.4.1';
}
return $self;
}
lib/API/PleskExpand.pm view on Meta::CPAN
=item AUTOLOADed methods
All other methods are loaded by Autoload from corresponding modules.
Execute some operations (see API::PleskExpand::* modules documentation).
Example:
my $res = $expand_client->Func_Module->operation_type(%params);
# Func_Module -- module in API/PleskExpand folder
# operation_type -- sub which defined in Func_Module.
# params hash used as @_ for operation_type sub.
=back
=cut
# OVERRIDE, INSTANCE(xml_request)
sub _execute_query {
my ($self, $xml_request) = @_;
# packet version override for
my $packet_version = $self->{'api_version'};
return unless $xml_request;
my $xml_packet_struct = <<" DOC";
<?xml version="1.0" encoding="UTF-8"?>
<packet version="$packet_version">
$xml_request
lib/API/PleskExpand/Accounts.pm view on Meta::CPAN
'tmpl_id' => '1',
'id' => '15'
} ],
'error_codes' => ''
}, 'API::Plesk::Response' );
=cut
# Create element
# STATIC
sub create {
my %params = @_;
if (ref $params{'general_info'} eq 'HASH') {
my $template = '';
if ($params{'template-id'}) {
$template = create_node('tmpl_id', $params{'template-id'}) .
( $params{'attach_to_template'} ? create_node('attach_to_template', '') : '' );
} else {
lib/API/PleskExpand/Accounts.pm view on Meta::CPAN
generate_info_block('gen_info', %{ $params{'general_info'} } ) . '<!-- create_client -->' . $template . $select);
} else {
return ''; # not enought data
}
}
# Parse XML response
# STATIC
sub create_response_parse {
return abstract_parser('add_use_template', +shift, [ ]);
}
=item modify(%params)
Changes the account params.
Params:
general_info -- hashref`s with new user details
lib/API/PleskExpand/Accounts.pm view on Meta::CPAN
print Dumper $client->Accounts->modify(
id => 10,
general_info => { status => 16 }
);
=cut
# Modify element
# STATIC
sub modify {
my %params = @_;
if (ref $params{'general_info'} eq 'HASH') {
my $filter = '';
if ($params{'id'}) {
$filter = create_filter(login_field_name => 'id', id => $params{'id'});
} else {
return ''; # filter required!
lib/API/PleskExpand/Accounts.pm view on Meta::CPAN
</gen_info>
</values>
</set>
</packet>
DOC
}
# SET response handler
# STATIC
sub modify_response_parse {
return abstract_parser('set', +shift, []);
}
=item delete(%params)
Delete accounts.
Params:
id -- client id in Plesk
lib/API/PleskExpand/Accounts.pm view on Meta::CPAN
Example:
print Dumper $client->Accounts->delete( id => 11 );
=back
=cut
# Delete element
# STATIC( %args )
sub delete {
my %params = @_;
my $filter = '';
if ($params{'id'}) {
$filter = create_filter( id => $params{'id'});
} else {
return ''; # id required!
}
return create_node('del', '<!-- del_client -->' . $filter);
}
# DEL response handler
# STATIC
sub delete_response_parse {
return abstract_parser('del', +shift, [ ]);
}
# Get all element data
# STATIC
sub get {
my %params = @_;
unless ($params{all}) {
return '';
}
return create_node( 'get',
create_node('filter', '') . create_node( 'dataset', create_node('gen_info') )
) . '<!-- get_client -->';
}
# GET response handler
# STATIC
sub get_response_parse {
my $answer = abstract_parser('get', +shift, [ ], 'system_error' );
if (ref $answer eq 'ARRAY') {
for my $domain (@$answer) {
$domain->{data} = xml_extract_values($domain->{data} =~ m#<gen_info>(.*?)</gen_info>#);
}
} elsif ($answer) {
$answer->{data} = xml_extract_values($answer->{data} =~ m#<gen_info>(.*?)</gen_info>#);
}
lib/API/PleskExpand/Domains.pm view on Meta::CPAN
=back
=head1 EXPORT
None.
=cut
# Create element
# STATIC
sub create {
my %params = @_;
return '' unless $params{'dname'} &&
#$params{'ip'} &&
$params{'client_id'} &&
$params{'ftp_login'} &&
$params{'ftp_password'} &&
$params{'template-id'};
lib/API/PleskExpand/Domains.pm view on Meta::CPAN
create_node( 'name', $params{dname} ) .
create_node( 'client_id', $params{client_id} ) .
create_node( 'status', 0)
) . $hosting_block . '<!-- create_domain -->' . $template_block
);
}
# Parse XML response
# STATIC
sub create_response_parse {
return abstract_parser('add_use_template', +shift, [ ], 'system_error' );
}
# Modify element
# STATIC
sub modify {
# stub
}
# SET response handler
# STATIC
sub modify_response_parse {
# stub
}
# Delete element
# STATIC( %args )
sub delete {
# stub
}
# DEL response handler
# STATIC
sub delete_response_parse {
# stub
}
# Get all element data
# STATIC
sub get {
my %params = @_;
unless ($params{all}) {
return '';
}
#return '<get><filter></filter><dataset><gen_info/></dataset></get><!-- create_domain -->';
return create_node( 'get',
create_node('filter', '') . create_node( 'dataset', create_node('gen_info') )
) . '<!-- create_domain -->';
}
# GET response handler
# STATIC
sub get_response_parse {
my $answer = abstract_parser('get', +shift, [ ], 'system_error' );
if (ref $answer eq 'ARRAY') {
for my $domain (@$answer) {
$domain->{data} = xml_extract_values($domain->{data} =~ m#<gen_info>(.*?)</gen_info>#);
}
} elsif ($answer) {
$answer->{data} = xml_extract_values($answer->{data} =~ m#<gen_info>(.*?)</gen_info>#);
}
}
my $expand_client = API::PleskExpand->new( %TestData::online_expand_valid_params);
isa_ok( $expand_client, 'API::PleskExpand', 'STATIC call new' );
# Calling undefined method from Plesk.pm
{
our $our_warning;
local $SIG{__DIE__} = sub { $our_warning = shift; }; # confess <=> die
eval { API::PleskExpand->new(%TestData::online_expand_valid_params)->aaa__bbbccc() };
like($our_warning, qr/aaa__bbbccc/,
'Checking AUTOLOAD by calling undefined method.');
}
my %create_account_data = (
'select' => 'optimal',
'template-id' => 1,
'general_info' => {
( run in 0.253 second using v1.01-cache-2.11-cpan-4d50c553e7e )