view release on metacpan or search on metacpan
lib/API/DirectAdmin.pm view on Meta::CPAN
# init
sub new {
my $class = shift;
$class = ref ($class) || $class;
my $self = {
auth_user => '',
auth_passwd => '',
host => '',
ip => '',
debug => $DEBUG,
allow_https => 1,
fake_answer => $FAKE_ANSWER,
(@_)
};
confess "Required auth_user!" unless $self->{auth_user};
confess "Required auth_passwd!" unless $self->{auth_passwd};
confess "Required host!" unless $self->{host};
return bless $self, $class;
lib/API/DirectAdmin.pm view on Meta::CPAN
}
# all params derived from get_auth_hash
sub query {
my ( $self, %params ) = @_;
my $command = delete $params{command};
my $fields = $params{allowed_fields} || '';
my $allowed_fields;
warn 'query_abstract ' . Dumper( \%params ) if $self->{debug};
confess "Empty command" unless $command;
$fields = "host port auth_user auth_passwd method allow_https command $fields";
@$allowed_fields = split /\s+/, $fields;
my $params = $self->filter_hash( $params{params}, $allowed_fields );
my $query_string = $self->mk_full_query_string( {
command => $command,
%$params,
} );
carp Dumper $query_string if $self->{debug};
my $server_answer = $self->process_query(
method => $params{method} || 'GET',
query_string => $query_string,
params => $params,
);
carp Dumper $server_answer if $self->{debug};
return $server_answer;
}
# Kill slashes at start / end string
# STATIC(STRING:input_string)
sub kill_start_end_slashes {
my ($self ) = @_;
for ( $self->{host} ) {
lib/API/DirectAdmin.pm view on Meta::CPAN
# STATIC(STRING: query_string)
sub process_query {
my ( $self, %params ) = @_;
my $query_string = $params{query_string};
my $method = $params{method};
confess "Empty query string" unless $query_string;
my $answer = $self->{fake_answer} ? $self->{fake_answer} : $self->mk_query_to_server( $method, $query_string, $params{params} );
carp $answer if $self->{debug};
return $answer;
}
# Make request to server and get answer
# STATIC (STRING: query_string)
sub mk_query_to_server {
my ( $self, $method, $url, $params ) = @_;
unless ( $method ~~ [ qw( POST GET ) ] ) {
lib/API/DirectAdmin.pm view on Meta::CPAN
}
else { # Temporary URL for making request
my $temp_uri = URI->new('http:');
$temp_uri->query_form( $params );
$request->content( $temp_uri->query );
$request->content_type('application/x-www-form-urlencoded');
my $response = $ua->request($request);
$content = $response->content;
}
warn "Answer: " . $content if $self->{debug};
return $content if $params->{noparse};
return $self->parse_answer($content);
}
# Parse answer
sub parse_answer {
my ($self, $response) = @_;
return '' unless $response;
lib/API/DirectAdmin/Domain.pm view on Meta::CPAN
params => \%params,
command => 'CMD_API_DOMAIN',
method => 'POST',
allowed_fields =>
'action
domain
php
cgi',
);
warn 'responce ' . Dumper(\$responce) if $self->{debug};
warn "Creating domain: $responce->{text}, $responce->{details}" if $self->{debug};
return $responce;
}
1;
lib/API/DirectAdmin/Mysql.pm view on Meta::CPAN
# INPUT
# name => 'DBNAME',
# passwd => 'DBPASSWD',
# passwd2 => 'DBPASSWD',
# user => 'DBLOGIN',
sub adddb {
my ($self, $params ) = @_;
$params->{action} = 'create';
carp 'params ' . Dumper($params) if $self->{debug};
my $responce = $self->directadmin->query(
command => 'CMD_API_DATABASES',
method => 'POST',
params => $params,
allowed_fields => 'action
name
passwd
passwd2
user',
);
carp '$responce ' . Dumper(\$responce) if $self->{debug};
return $responce if $responce;
return 'FAIL';
}
# Delete database for user
# Connection data MUST BE for user: auth_user => 'admin_login|user_login'
# auth_passwd => 'admin_passwd'
# INPUT
# select0 => 'DBNAME',
# domain => 'DOMAIN.COM',
sub deldb {
my ($self, $params ) = @_;
$params->{action} = 'delete';
carp 'params ' . Dumper($params) if $self->{debug};
my $responce = $self->directadmin->query(
command => 'CMD_API_DATABASES',
method => 'POST',
params => $params,
allowed_fields => 'action
select0',
);
carp '$responce ' . Dumper(\$responce) if $self->{debug};
return $responce if $responce;
return 'FAIL';
}
# Get list of databases for authorized user.
# No params.
sub list {
my ($self ) = @_;
my $responce = $self->directadmin->query(
command => 'CMD_API_DATABASES',
method => 'GET',
);
carp '$responce ' . Dumper($responce) if $self->{debug};
return $responce->{list} if ref $responce eq 'HASH';
return [];
}
1;
lib/API/DirectAdmin/User.pm view on Meta::CPAN
notify
username
domain
passwd
passwd2
package
ip
email',
);
carp "Creating account: $responce->{text}, $responce->{details}" if $self->{debug};
return $responce;
}
# Suspend user
# params: select0
sub disable {
my ($self, $params ) = @_;
my %add_params = (
suspend => 'Suspend',
lib/API/DirectAdmin/User.pm view on Meta::CPAN
my $responce = $self->directadmin->query(
command => 'CMD_API_SELECT_USERS',
method => 'POST',
params => \%params,
allowed_fields => 'location
suspend
select0',
);
carp "Suspend account: $responce->{text}, $responce->{details}" if $self->{debug};
return $responce;
}
# Unsuspend user
# params: select0
sub enable {
my ($self, $params ) = @_;
my %add_params = (
suspend => 'Unsuspend',
lib/API/DirectAdmin/User.pm view on Meta::CPAN
my $responce = $self->directadmin->query(
command => 'CMD_API_SELECT_USERS',
method => 'POST',
params => \%params,
allowed_fields => 'location
suspend
select0',
);
carp "Unsuspend account: $responce->{text}, $responce->{details}" if $self->{debug};
return $responce;
}
# Delete user
# params: select0
sub delete {
my ($self, $params ) = @_;
my %add_params = (
lib/API/DirectAdmin/User.pm view on Meta::CPAN
my $responce = $self->directadmin->query(
command => 'CMD_API_SELECT_USERS',
method => 'POST',
params => \%params,
allowed_fields => 'confirmed
delete
select0',
);
carp "Delete account: $responce->{text}, $responce->{details}" if $self->{debug};
return $responce;
}
# Change passwd
# params: username, passwd, passwd2
sub change_password {
my ($self, $params ) = @_;
my $responce = $self->directadmin->query(
command => 'CMD_API_USER_PASSWD',
method => 'POST',
params => $params,
allowed_fields => 'passwd
passwd2
username',
);
carp "Change passwd account: $responce->{text}, $responce->{details}" if $self->{debug};
return $responce;
}
# Change package for user
# params: user, package
sub change_package {
my ($self, $params ) = @_;
my $package = $params->{package};
lib/API/DirectAdmin/User.pm view on Meta::CPAN
my $responce = $self->directadmin->query(
command => 'CMD_API_MODIFY_USER',
method => 'POST',
params => \%params,
allowed_fields => 'action
package
user',
);
carp "Change package: $responce->{text}, $responce->{details}" if $self->{debug};
return $responce;
}
# Show a list of user packages
# no params
sub show_packages {
my ($self ) = @_;
my $responce = $self->directadmin->query(
command => 'CMD_API_PACKAGES_USER',