API-PleskExpand

 view release on metacpan or  search on metacpan

lib/API/PleskExpand.pm  view on Meta::CPAN


=over 3

=item new(%params)

Create new class instance.

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__;

lib/API/PleskExpand.pm  view on Meta::CPAN

        $xml_request =~ m/modify_client/is or 
        $xml_request =~ m/get_client/is
    ) {
        $operator = 'exp_plesk_client';
    } elsif ($xml_request =~ m/create_domain/is) {
        $operator = 'exp_plesk_domain';
    }

    my $headers = {
        ':HTTP_AUTH_LOGIN'  => $self->{'username'},
        ':HTTP_AUTH_PASSWD' => $self->{'password'},
        ':HTTP_AUTH_OP'     => $operator
    };

    return $headers if $self->{'dump_headers'};

    return API::Plesk::xml_http_req(
        $self->{'url'},
        $xml_packet_struct,
        headers => $headers 
    );

lib/API/PleskExpand/Domains.pm  view on Meta::CPAN

=over 3

=item create()

Params:

  dname              => 'yandex.ru',   # domain name
  client_id          => 9,             # add domain to client with certain id
  'template-id'      => 1,             # domain template id
  ftp_login          => 'nrgsdasd',    # username for ftp 
  ftp_password       => 'dasdasd',     # password for ftp account
  attach_to_template => 1,             # attach domain to template ? 1 -- yes, 0 -- no

Return:

  $VAR1 = bless( {
    'answer_data' => [ {
        'server_id'     => '1',
        'status'        => 'ok',
        'expiration'    => '-1',
        'tmpl_id'       => '1',

lib/API/PleskExpand/Domains.pm  view on Meta::CPAN

# 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'};

    $params{'attach_to_template'} ||= '';

    my $hosting_block = create_node('hosting',
        generate_info_block(
            'vrt_hst',
            'ftp_login'    => $params{'ftp_login'},
            'ftp_password' => $params{'ftp_password'},
        )
    );
    my $template_block =  create_node('tmpl_id', $params{'template-id'}) .
        ( $params{'attach_to_template'} ? create_node('attach_to_template', '') : '' );

    return create_node( 'add_use_template',
        create_node( 
            'gen_setup',
            create_node( 'name', $params{dname} ) .
            create_node( 'client_id', $params{client_id} ) .

t/TestData.pm  view on Meta::CPAN

package TestData;

use strict;
use warnings;

my $online_expand_url = 'https://your.true.host.ru:8442/webgate.php';

our %online_expand_valid_params = (
    api_version   => $ENV{'expand_api_version'}  || '2.2.4.1',
    username      => $ENV{'expand_username'}     || 'root',
    password      => $ENV{'expand_password'}     || 'qwerty',
    url           => $ENV{'expand_url'}          || $online_expand_url,
    debug         => '',
    request_debug => '',
);

t/expand.t  view on Meta::CPAN


is_string( $modify_query_alter, $_, 'modify account test') for 
'<set><filter><id>5</id></filter><!-- modify_client --><values>' .
'<gen_info><status>0</status></gen_info></values></set>';

my %new_domain_data = (
    dname               => 'y2a1ddsdfandex.ru',
    client_id           => 16,
    'template-id'       => 1,
    ftp_login           => 'nrddgddsdasd',
    ftp_password        => 'dadsdasd',
);

my $create_domain = API::PleskExpand::Domains::create( %new_domain_data );


is_string( $create_domain, $_, 'modify account test') for 
'<add_use_template><gen_setup><name>y2a1ddsdfandex.ru</name>'  .
'<client_id>16</client_id><status>0</status></gen_setup>'      .
'<hosting><vrt_hst><ftp_login>nrddgddsdasd</ftp_login>'        .
'<ftp_password>dadsdasd</ftp_password></vrt_hst></hosting>'    .
'<!-- create_domain --><tmpl_id>1</tmpl_id></add_use_template>';

$create_domain = API::PleskExpand::Domains::create( %new_domain_data, attach_to_template  => 1 );

is_string( $create_domain, $_, 'modify account test') for
'<add_use_template><gen_setup><name>y2a1ddsdfandex.ru</name>' .
'<client_id>16</client_id><status>0</status></gen_setup>'     .
'<hosting><vrt_hst><ftp_login>nrddgddsdasd</ftp_login>'       .
'<ftp_password>dadsdasd</ftp_password></vrt_hst></hosting>'   .
'<!-- create_domain --><tmpl_id>1</tmpl_id>'                  .
'<attach_to_template></attach_to_template></add_use_template>';

$expand_client->{dump_headers} = 1; # debugg =)

is_deeply(
    $expand_client->_execute_query('<add_use_template><!-- create_domain --></add_use_template>'),
    {
        ':HTTP_AUTH_LOGIN'  => $TestData::online_expand_valid_params{'username'},
        ':HTTP_AUTH_PASSWD' => $TestData::online_expand_valid_params{'password'},
        ':HTTP_AUTH_OP'     => 'exp_plesk_domain'
    },
    'test request headers'
);

is_deeply(
    $expand_client->_execute_query('<add_use_template><!-- create_client --></add_use_template>'),
    {
        ':HTTP_AUTH_LOGIN'  => $TestData::online_expand_valid_params{'username'},
        ':HTTP_AUTH_PASSWD' => $TestData::online_expand_valid_params{'password'},
        ':HTTP_AUTH_OP'     => 'exp_plesk_client'
    },
    'exp_plesk_client'
);

$expand_client->{dump_headers} = 0;


my $req_answer1 = {
    errtext     => "[Operator] Client already exists. Plesk client 'hello_medved' is exist.",

t/expand.t  view on Meta::CPAN

        if ($activate_result->is_success) {
            pass "Activation success!";

            
            my $create_domain = $expand_client->Domains->create(
                dname                => $login . '.ru',
                client_id            => $client_id,
                'template-id'        => $domain_template_id,
                'attach_to_template' => 1,
                ftp_login            => $login,
                ftp_password         => 'afsfsaf',
            );

        
            if ($create_domain->is_success) {
   
                pass "Create domain successful";

                my $nop_result = $expand_client->Accounts->modify(
                    general_info => { },         # blank operation
                    id           => $client_id,



( run in 0.582 second using v1.01-cache-2.11-cpan-49f99fa48dc )