NAME
API::DirectAdmin - interface to the DirectAdmin Hosting Panel API ( http://www.directadmin.com )
SYNOPSIS
use API::DirectAdmin;
my %auth = (
auth_user => 'admin_name',
auth_passwd => 'admin_passwd',
host => '11.22.33.44',
);
# init
my $da = API::DirectAdmin->new(%auth);
### Get all panel IP
my $ip_list = $da->ip->list();
unless ($ip_list && ref $ip_list eq 'ARRAY' && scalar @$ip_list) {
die 'Cannot get ip list from DirectAdmin';
}
my $ip = $ip_list->[0];
my $dname = 'perlaround.ru';
my $user_name = 'user1';
my $email = 'user1@example.com';
my $package = 'newpackage';
my $client_creation_result = $da->user->create( {
username => $user_name,
passwd => 'user_password',
passwd2 => 'user_password',
domain => $dname,
email => $email,
package => $package,
ip => $ip,
});
# Switch off account:
my $suspend_result = $da->user->disable( {
select0 => $user_name,
} );
if ( $suspend_result->{error} == 1 ) {
die "Cannot suspend account $suspend_result->{text}";
}
# Switch on account
my $resume_result = $da->user->enable( {
select0 => $user_name,
} );
if ( $resume_result->{error} == 1 ) {
die "Cannot Resume account $resume_result->{text}";
}
# Delete account
my $delete_result = $da->user->delete( {
select0 => $user_name,
} );
if ( $delete_result->{error} == 1 ) {
die "Cannot delete account $delete_result->{text}";
}
# Custom request
my %params = (
action => 'package',
package => 'package_name',
user => 'username',
);
my $responce = $da->query(
command => 'CMD_API_MODIFY_USER',
method => 'POST',
params => \%params,
allowed_fields => 'action
package
user',
);
PUBLIC METHODS
API::DirectAdmin::User
- list
-
Return list of users in array ref.
Example:
my $users_list = $da->users->list();
- create
-
Create a new user in DirectAdmin panel.
Example:
my $result = $da->user->create( { username => 'username', passwd => 'user_password', passwd2 => 'user_password', domain => 'example.com', email => 'email@example.com', package => 'package_name', ip => 'IP.ADD.RE.SS', });
- delete
-
Delete DirectAdmin user and all user's data
Note: Some DirectAdmin's API methods required parameter "select0" for choose value from list. Like list of users, databases, ip, etc.
Example:
my $result = $da->user->delete( { select0 => 'username', } );
- disable/enable
-
Two different methods for disable and enable users with same params.
Example:
my $disable_result = $da->user->disable( { select0 => 'username', } ); my $enable_result = $da->user->enable( { select0 => 'username', } );
- change_password
-
Change password for user
Example:
my $result = $da->user->change_password( { username => 'username', passwd => 'new_password', passwd2 => 'new_password', } );
- change_package
-
Change package (tariff plan) for user
Example:
my $result = $da->user->change_package( { username => 'username', package => 'new_package', } );
- show_packages
-
Return list of available packages.
Note: If you created packages through administrator user - you must use admin's login and password for authorisation. Obviously, if packages was created by reseller user - use reseller authorisation.
Example:
my $packages = $da->user->show_packages();
API::DirectAdmin::Domain
- list
-
Return list of domains on server.
Example:
my $domains = $da->domain->list();
- add
-
Add new domain to user through you connect to server.
Note: For adding domains for customers and you don't khow their password use: auth_user = 'admin_name|customer_name' in auth hash.
Example:
my %auth = ( auth_user => 'admin_name|customer_name', auth_passwd => 'admin_passwd', host => '11.22.33.44', ); # init my $da = API::DirectAdmin->new(%auth); $result = $da->domain->add({ domain => 'newdomain.com', php => 'ON', cgi => 'ON', });
API::DirectAdmin::Mysql
Control users mysql databases
- list
-
List of databases from user. Return empty array if databases not found.
Example:
print $da->mysql->list();
- adddb
-
Add database to user. Prefix "username_" will be added to 'name' and 'user';
Example:
my %auth = ( auth_user => 'admin_name|customer', auth_passwd => 'admin_passwd', host => '11.22.33.44', ); # init my $da = API::DirectAdmin->new(%auth); my $result = $da->mysql->adddb( { name => 'default', # will be 'customer_default' user => 'default', # will be 'customer_default' passwd => 'password', passwd2 => 'password', } );
- deldb
-
Delete selected database from user.
Example:
my $result = $da->mysql->deldb({ select0 => 'database_name' });
API::DirectAdmin::Ip
- list
-
Return array reference of list ip adresses;
Example:
my $ip_list = $da->ip->list();
- add
-
Add IP address to server config
Example:
my $result = $da->ip->add({ ip => '123.234.123.234', status => 'server', });
- remove
-
Remove ip from server
Example:
my $result = $da->ip->remove({ select0 => '123.234.123.234', });
API::DirectAdmin::DNS
Show zones, add and remove records.
- dumpzone
-
Return zone structure for domain
Example:
$da->dns->dumpzone( {domain => 'domain.com'} );
- add_record
-
Add zone record to dns for domain. Available types of records: A, AAAA, NS, MX, TXT, PTR, CNAME, SRV
Example:
my $reult = $da->dns->add_record({ domain => 'domain.com', type => 'A', name => 'subdomain', # will be "subdomain.domain.com." in record value => '127.127.127.127', });
- remove_record
-
Remove record from domain zone
Example:
my $result = $da->dns->remove_record({ domain => 'domain.com', type => 'A', name => 'subdomain', value => '127.127.127.127', });
INSTALLATION
To install this module type the following:
perl Makefile.PL
make
make test
make install
DEPENDENCIES
This module requires these other modules and libraries: LWP::UserAgent HTTP::Request URI Carp Data::Dumper
COPYRIGHT AND LICENCE
Put the correct copyright and licence information here.
Copyright (C) 2012 by Andrey "Chips" Kuzmin
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.10.1 or, at your option, any later version of Perl 5 you may have available.