view release on metacpan or search on metacpan
--- #YAML:1.0
name: API-ISPManager
version: 0.07
abstract: interface to the ISPManager Hosting Panel API ( http://ispsystem.com )
author:
- nrg <nrg@cpan.org>
license: unknown
distribution_type: module
configure_requires:
ExtUtils::MakeMaker: 0
build_requires:
ExtUtils::MakeMaker: 0
requires:
Crypt::SSLeay: 0
Exporter::Lite: 0
lib/API/ISPManager.pm view on Meta::CPAN
# VDSManager
use API::ISPManager::vds;
use API::ISPManager::diskpreset;
use API::ISPManager::vdspreset;
# BillManager
use API::ISPManager::software;
use API::ISPManager::order;
our @EXPORT = qw/get_auth_id refs is_success get_data query_abstract is_ok get_error/;
our @EXPORT_OK = qw//;
our $VERSION = 0.07;
our $DEBUG = '';
=head1 NAME
API::ISPManager - interface to the ISPManager Hosting Panel API ( http://ispsystem.com )
=head1 SYNOPSIS
lib/API/ISPManager.pm view on Meta::CPAN
return $new_hash;
}
# Get access key, time to live -- 30 minutes
# STATIC(HASHREF: params_hash)
# params_hash:
# - all elements from mk_full_query_string +
# - username*
# - password*
sub get_auth_id {
my %params_raw = @_;
warn 'get_auth_id params: ' . Dumper(\%params_raw) if $DEBUG;
my $params = filter_hash(
\%params_raw,
[ 'host', 'path', 'allow_http', 'username', 'password' ]
);
# Check this sub params
unless ($params->{username} && $params->{password}) {
return '';
}
my $query_string = mk_full_query_string( {
%$params,
func => 'auth',
out => 'xml',
} );
return '' unless $query_string;
warn $query_string if $DEBUG;
my $xml = process_query( query_string => $query_string);
if ($xml) {
my $error_node = exists $xml->{authfail};
return '' if $error_node;
return $xml->{auth}->{id};
} else {
return '';
}
}
# Wrapper for "ref" on undef value, without warnings :)
# Possible very stupid sub :)
# STATIC(REF: our_ref)
sub refs {
my $ref = shift;
lib/API/ISPManager.pm view on Meta::CPAN
my $data_block = shift;
unless ( is_success($data_block) ) {
return '';
}
return $data_block->{data};
}
# list all users
# all params derived from get_auth_id
sub query_abstract {
my %params = @_;
my $params_raw = $params{params};
my $func_name = $params{func};
my $fake_answer = $params{fake_answer} || '';
warn 'query_abstract ' . Dumper( \%params ) if $DEBUG;
return '' unless $params_raw && $func_name;
my $allowed_fields = $params{allowed_fields} || [ 'host', 'path', 'allow_http' ];
# TODO ÑделаÑÑ ÑÑÐµÐ¿ÐºÑ Ð¼Ð°ÑÑивов ÑÑÑ!!!!
my $xml_parser_params = $params{parser_params};
my $auth_id = $fake_answer ? '112323' : get_auth_id( %$params_raw );
warn "Auth_id: $auth_id\n" if $DEBUG;
if ($auth_id or $func_name eq 'ftp') { # ftp hacked by authinfo
my $params = filter_hash( $params_raw, $allowed_fields);
my $query_string = mk_full_query_string( {
( $func_name eq 'ftp' ? ( ) : ( auth => $auth_id ) ), # for ftp auth not used, only authinfo
func => $func_name,
out => 'xml',
%$params,
} );
warn Dumper $query_string if $DEBUG;
return process_query(
query_string => $query_string,
parser_params => $xml_parser_params,
lib/API/ISPManager.pm view on Meta::CPAN
);
#
# TODO add this check here
# if ( $server_answer && $server_answer->{elem} && ref $server_answer->{elem} eq 'HASH' ) {
# return { data => $server_answer->{elem} };
# }
#
} else {
warn "auth_id not found or func type not ftp" if $DEBUG;
return '';
}
}
1;
lib/API/ISPManager/file.pm view on Meta::CPAN
}
}
# Upload file
sub upload {
my $params = shift;
my $allowed_fields = [ qw( host path allow_http plid ) ];
my $func_name = 'file.upload';
my $auth_id = API::ISPManager::get_auth_id( %$params );
if ($auth_id) {
my $params_raw = API::ISPManager::filter_hash( $params, $allowed_fields );
my $ua = LWP::UserAgent->new;
$ua->agent("Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)");
my $url = 'https://server8.hosting.reg.ru/mancgi/upload';
my $query_string = API::ISPManager::mk_full_query_string( {
( auth => $auth_id ),
func => $func_name,
%$params_raw,
} );
my $response = $ua->post(
'https://' . $params->{host} . '/mancgi/upload',
Content_Type => 'form-data',
Content => [
filename => [$params->{file}],
sok => 'ok',
auth => $auth_id,
plid => $params->{plid},
]
);
if ($response->is_success) {
return 1;
}
else {
return '';
lib/API/ISPManager/ftp.pm view on Meta::CPAN
use warnings;
use API::ISPManager;
sub list {
my $params = shift;
my $result = API::ISPManager::query_abstract(
params => $params,
func => 'ftp',
allowed_fields => [ qw( host path allow_http su authinfo) ], # TODO: hack with authinfo!!!
);
return $result;
}
sub create {
}
lib/API/ISPManager/order.pm view on Meta::CPAN
ref $result eq 'HASH' &&
(
$result->{ok} or
( $result->{error} && ref $result->{error} eq 'HASH' && $result->{error}->{code} eq '2' ) # already exists
)
) {
return 1; # { success => 1 };
} else {
return ''; # { success => '', error => Dumper ($result->{error}) };
}
#https://ultrasam.ru/ispmanager/ispmgr?out=xml&auth=232143511
#&sok=yes&func=user.edit&name=nrgxxx&ip=78.47.76.69&passwd=qwerty&ftplimit=100&disklimit=200
}
1;
lib/API/ISPManager/software.pm view on Meta::CPAN
ref $result eq 'HASH' &&
(
$result->{ok} or
( $result->{error} && ref $result->{error} eq 'HASH' && $result->{error}->{code} eq '2' ) # already exists
)
) {
return 1; # { success => 1 };
} else {
return ''; # { success => '', error => Dumper ($result->{error}) };
}
#https://ultrasam.ru/ispmanager/ispmgr?out=xml&auth=232143511
#&sok=yes&func=user.edit&name=nrgxxx&ip=78.47.76.69&passwd=qwerty&ftplimit=100&disklimit=200
}
1;
lib/API/ISPManager/user.pm view on Meta::CPAN
ref $result eq 'HASH' &&
(
$result->{ok} or
( $result->{error} && ref $result->{error} eq 'HASH' && $result->{error}->{code} eq '2' && $result->{error}->{obj} eq 'user' ) # already exists
)
) {
return 1; # { success => 1 };
} else {
return ''; # { success => '', error => Dumper ($result->{error}) };
}
#https://ultrasam.ru/ispmanager/ispmgr?out=xml&auth=232143511
#&sok=yes&func=user.edit&name=nrgxxx&ip=78.47.76.69&passwd=qwerty&ftplimit=100&disklimit=200
}
# Edit user data
sub edit {
my $params = shift;
my $result = API::ISPManager::query_abstract(
params => $params,
func => 'user.edit',
lib/API/ISPManager/vds.pm view on Meta::CPAN
ref $result eq 'HASH' &&
(
$result->{ok} or
( $result->{error} && ref $result->{error} eq 'HASH' && $result->{error}->{code} eq '2' ) # already exists
)
) {
return 1; # { success => 1 };
} else {
return ''; # { success => '', error => Dumper ($result->{error}) };
}
#https://ultrasam.ru/ispmanager/ispmgr?out=xml&auth=232143511
#&sok=yes&func=user.edit&name=nrgxxx&ip=78.47.76.69&passwd=qwerty&ftplimit=100&disklimit=200
}
# Edit user data
sub edit {
my $params = shift;
my $result = API::ISPManager::query_abstract(
params => $params,
func => 'vds.edit',
t/01-test.t view on Meta::CPAN
#exit;
no warnings 'once';
$API::ISPManager::DEBUG = 0;
### ONLINE TESTS
exit if !$ONLINE;
$a = 'get_auth_id';
is( get_auth_id(
username => 'root',
password => 'qwerty',
host => $test_host,
path => 'manager',
),
'',
"$a with error password"
);
my $auth_id;
like( $auth_id = get_auth_id(
username => $ENV{username} || 'root',
password => $ENV{password},
host => $test_host,
path => 'manager',
),
qr/\d+/,
"$a with correct password ($auth_id)"
);
=head
is(
scalar keys %{ API::ISPManager::user::list( { %correct_params } )->{elem} },
20,
'user::list test'
);
t/01-test.t view on Meta::CPAN
%correct_params,
name => 'nrgxxxxxapi',
passwd => 'qwerty',
ip => $ip,
preset => 'Host-1',
domain => 'nrg.name',
} ) );
diag Dumper( API::ISPManager::ftp::list( {
%correct_params,
authinfo => 'username:password',
su => 'su_as_username',
} ) );
diag Dumper( API::ISPManager::user::disable( {
%correct_params,
elid => 'nrgxxxxxapi',
} ) );