6 use vars qw( $VERSION @ISA $AUTOLOAD $DEBUG $PROTO_VERSION $POST_URL
7 @EXPORT_OK %EXPORT_TAGS ); # @EXPORT
13 use Net::Plesk::Response;
14 use Net::Plesk::Method;
15 use Net::Plesk::Method::domain_add;
16 use Net::Plesk::Method::domain_del;
17 use Net::Plesk::Method::domain_get;
18 use Net::Plesk::Method::mail_add;
19 use Net::Plesk::Method::mail_remove;
20 use Net::Plesk::Method::mail_set;
21 use Net::Plesk::Method::client_add;
22 use Net::Plesk::Method::client_get;
23 use Net::Plesk::Method::client_ippool_add_ip;
29 $PROTO_VERSION = '1.4.1.0';
33 my $ua = LWP::UserAgent->new;
34 $ua->agent("Net::Plesk/$VERSION");
38 Net::Plesk - Perl extension for Plesk XML Remote API
44 my $plesk = new Net::Plesk (
45 'POST' => 'https://plesk.sample.com:8443/enterprise/control/agent.php',
46 ':HTTP_AUTH_LOGIN' => '1357948',
47 ':HTTP_AUTH_PASSWD' => 'password',
52 my $clientname = 'tofu_beast';
53 my $response = $plesk->client_get( $clientname );
54 die $response->errortext unless $response->is_success;
55 my $clientID = $response->id;
60 my $clientname = 'Tofu Beast';
61 my $login = 'tofu_beast';
62 my $password = 'manyninjas';
63 my $response = $plesk->client_add( $clientname,
75 die $response->errortext unless $response->is_success;
76 $clientID = $response->id;
77 print "$clientname created with ID $clientID\n";
80 # client_ippool_add_ip
82 my $ipaddress = '192.168.8.45';
83 my $response = $plesk->client_ippool_add_ip( $clientID, $ipaddress );
84 die $response->errortext unless $response->is_success;
88 my $domain = 'basilisk.jp';
89 my $response = $plesk->domain_get( $domain );
90 die $response->errortext unless $response->is_success;
91 my $domainID = $response->id;
95 my $domain = 'basilisk.jp';
97 my $ipaddr = '192.168.8.45';
98 my $response = $plesk->domain_add( $domain, $clientID, $ipaddr );
99 die $response->errortext unless $response->is_success;
100 my $domainID = $response->id;
104 my $domain = 'basilisk.jp';
105 my $response = $plesk->domain_add( $domain );
106 die $response->errortext unless $response->is_success;
110 my $username = 'tofu_beast';
111 my $response = $plesk->mail_add( $domainID, $username, 'password' );
112 die $response->errortext unless $response->is_success;
113 my $uid = $response->id;
114 print "$username created: uid $uid\n";
118 $response = $plesk->mail_remove( 'username' );
119 if ( $response->is_success ) {
120 print "mailbox removed";
122 print "error removing mailbox: ". $response->errortext;
127 my $enabled = ($user_balance <= 0);
128 $response = $plesk->mail_set( $domainID, 'username', 'password', $enabled );
129 die $response->errortext unless $response->is_success;
133 This module implements a client interface to SWSOFT's Plesk Remote API,
134 enabling a perl application to talk to a Plesk managed server.
135 This documentation assumes that you are familiar with the Plesk documentation
136 available from SWSOFT (API 1.4.0.0 or later).
138 A new Net::Plesk object must be created with the I<new> method. Once this has
139 been done, all Plesk commands are accessed via method calls on the object.
145 =item new OPTION => VALUE ...
147 Creates a new Net::Plesk object. The I<URL>, I<:HTTP_AUTH_LOGIN>, and
148 I<:HTTP_AUTH_PASSWD> options are required.
154 my $class = ref($proto) || $proto;
155 my $self = { 'version' => $PROTO_VERSION,
158 bless($self, $class);
161 =item AUTOLOADed methods
163 Not all Plesk methods are available. See the Plesk documentation for methods,
164 arguments and return values. See B<Net::Plesk::Method> for available methods.
166 Responses are returned as B<Net::Plesk::Response> objects. See
167 L<Net::Plesk::Response>.
174 $AUTOLOAD =~ s/.*:://;
175 return if $AUTOLOAD eq 'DESTROY';
177 $AUTOLOAD =~ /^([[:alpha:]_]\w*)$/;
178 die "$AUTOLOAD Illegal method: $1" unless $1;
179 my $autoload = "Net::Plesk::Method::$1";
182 my $req = HTTP::Request->new('POST' => $self->{'POST'});
183 $req->content_type('text/xml');
186 next if $_ eq 'POST';
187 $req->header( $_ => $self->{$_} );
190 my $packet = $autoload->new(@_);
192 '<?xml version="1.0"?>' .
193 '<packet version="' . $self->{'version'} . '">' .
198 warn $req->as_string. "\n"
201 my $res = $ua->request($req);
203 # Check the outcome of the response
204 if ($res->is_success) {
206 warn "\nRESPONSE:\n". $res->content
209 my $response = new Net::Plesk::Response $res->content;
211 warn Dumper( $response )
217 new Net::Plesk::Response (
218 '<?xml version="1.0" encoding="UTF-8"?>'. #a lie? probably safe
219 '<packet version="' . $self->{'version'} . '">' .
220 "<system><status>error</status><errcode>500</errcode>" .
221 "<errtext>" . $res->status_line . "</errtext></system>" .
232 Multiple request packets not tested.
236 SWSOFT Plesk Remote API documentation (1.4.0.0 or later)
240 Jeff Finucane E<lt>jeff@cmh.netE<gt>
242 =head1 COPYRIGHT AND LICENSE
244 Copyright (C) 2006 Jeff Finucane
246 This library is free software; you can redistribute it and/or modify
247 it under the same terms as Perl itself.