billguy
27th March 2008, 04:58 PM
If http://download1.swsoft.com/Plesk/Plesk8.1/Doc/plesk-8.1-api-rpc-guide/33181.htm seems like too much of a hassle (it did for me), have a look at Odintsov Pavel's API::Plesk (http://search.cpan.org/~nrg/API-Plesk-1.01/lib/API/Plesk.pm) over on CPAN. Neat and tidy.
Example:
use API::Plesk;
use API::Plesk::Response;
my $plesk_client = API::Plesk->new('api_version'=>'1.5.0.0','username'=>'user','password'=>'pass','url'=>'https://example.com:8443/enterprise/control/agent.php');
my $res = $plesk_client->Accounts->get('login' => 'some_user');
print "User exists \n" if $res->is_success;
print $res->get_error_string, "\n";
The documentation could be friendlier but the software is free. ;)
atomicturtle
28th March 2008, 10:47 AM
Very cool, thanks for the heads up!
billguy
30th March 2008, 02:08 PM
Create a Plesk user account.
use API::Plesk;
use API::Plesk::Response;
#Creates a Plesk user account.
#Usage: perl plesk_create_user.pl username password full_name email plesk_client_template_name
#Set Plesk connect credentials here.
my ($plesk_ver, $plesk_user, $plesk_pass, $plesk_url) = qw(1.5.0.0 admin password https://host.com:8443/enterprise/control/agent.php);
#Plesk vars.
my ($user, $pass, $name, $email, $client_template) = ($ARGV[0], $ARGV[1], $ARGV[2], $ARGV[3], $ARGV[4]);
#Build user data hash ref.
my $user_data = {
#'cname' => , # company name
'pname' => $name,
'login' => $user,
'passwd' => $pass,
'status' => '0',
#'phone' => ,
#'fax' => ,
'email' => $email,
#'address' => ,
#'city' => ,
#'state' => ,
#'pcode' => ,
#'country' => ,
};
#Connect to Plesk.
my $plesk_client = API::Plesk->new('api_version'=>$plesk_ver,'username'=>$plesk_user,'password'=>$plesk_pass,'url'=>$plesk_url);
#Create the user account. Make sure you have a plesk template already created. Use a Plesk client template name.
my $plesk_usercreate_res= $plesk_client->Accounts->create('general_info'=>$user_data, 'template-name'=>$client_template);
#Print the result.
$plesk_usercreate_res->is_success ? print "$user created. \n" : print $plesk_usercreate_res->get_error_string, " \n";
Create a Plesk domain.
use API::Plesk;
use API::Plesk::Response;
#Creates a Plesk domain.
#Usage: perl plesk_create_domain.pl domain_name plesk_owner_username ftp_user ftp_pass ip_address plesk_domain_template_name
#Set Plesk connect credentials here.
my ($plesk_ver, $plesk_user, $plesk_pass, $plesk_url) = qw(1.5.0.0 admin password https://host.com:8443/enterprise/control/agent.php);
#Plesk vars.
my ($domain, $username, $ftp_user, $ftp_pass, $ip, $dom_template) = ($ARGV[0], $ARGV[1], $ARGV[2], $ARGV[3], $ARGV[4], $ARGV[5]);
#Connect to Plesk.
my $plesk_client = API::Plesk->new('api_version'=>$plesk_ver,'username'=>$plesk_user,'password'=>$plesk_pass,'url'=>$plesk_url);
#Fetch the userid from the username. Exit if not exist.
my $plesk_res= $plesk_client->Accounts->get('login' => $username);
$plesk_res->is_success ? my $userid = $plesk_res->get_data->[0]{'id'} : print $plesk_res->get_error_string, " \n";
#create the domain, make sure you have a good plesk template already created. Use a Plesk template name.
my $plesk_domaincreate_res= $plesk_client->Domains->create('dname'=>$domain,
'ip'=>$ip,
'client_id'=>$userid,
'ftp_login'=>$ftp_user,
'ftp_password'=>$ftp_pass,
'template'=>$dom_template);
#Print the result.
$plesk_domaincreate_res->is_success ? print "$domain created. \n" : print $plesk_domaincreate_res->get_error_string, " \n";
Enjoy!
HostingGuy
1st April 2008, 03:02 PM
What I did was built a .Net wrapper available in a web service that sits in a load balanced web server to use as a centralized web service going to all plesk hosting boxes to do these types of things :)
Very smiilar, but unreleased to the public unfortunately
tuzi520
23rd September 2008, 04:42 AM
Thanks billguy!
Would it be possible when a user login Plesk and use API::Plesk to automatically view/get the databases and create one?
vBulletin® v3.6.12, Copyright ©2000-2009, Jelsoft Enterprises Ltd.