6 use vars qw( $VERSION @ISA $AUTOLOAD $DEBUG $PROTO_VERSION $POST_URL );
10 use Net::Plesk::Response;
11 use Net::Plesk::Method;
12 use Net::Plesk::Method::domain_add;
13 use Net::Plesk::Method::domain_del;
14 use Net::Plesk::Method::domain_get;
15 use Net::Plesk::Method::mail_add;
16 use Net::Plesk::Method::mail_remove;
17 use Net::Plesk::Method::mail_set;
18 use Net::Plesk::Method::client_add;
19 use Net::Plesk::Method::client_get;
20 use Net::Plesk::Method::client_ippool_add_ip;
26 $PROTO_VERSION = '1.4.1.0';
30 my $ua = LWP::UserAgent->new;
31 $ua->agent("Net::Plesk/$VERSION");
35 Net::Plesk - Perl extension for Plesk XML Remote API
41 my $plesk = new Net::Plesk (
42 'POST' => 'https://plesk.sample.com:8443/enterprise/control/agent.php',
43 ':HTTP_AUTH_LOGIN' => '1357948',
44 ':HTTP_AUTH_PASSWD' => 'password',
49 my $clientname = 'tofu_beast';
50 my $response = $plesk->client_get( $clientname );
51 die $response->errortext unless $response->is_success;
52 my $clientID = $response->id;
57 my $clientname = 'Tofu Beast';
58 my $login = 'tofu_beast';
59 my $password = 'manyninjas';
60 my $response = $plesk->client_add( $clientname,
72 die $response->errortext unless $response->is_success;
73 $clientID = $response->id;
74 print "$clientname created with ID $clientID\n";
77 # client_ippool_add_ip
79 my $ipaddress = '192.168.8.45';
80 my $response = $plesk->client_ippool_add_ip( $clientID, $ipaddress );
81 die $response->errortext unless $response->is_success;
85 my $domain = 'basilisk.jp';
86 my $response = $plesk->domain_get( $domain );
87 die $response->errortext unless $response->is_success;
88 my $domainID = $response->id;
92 my $domain = 'basilisk.jp';
94 my $ipaddr = '192.168.8.45';
95 my $response = $plesk->domain_add( $domain, $clientID, $ipaddr );
96 die $response->errortext unless $response->is_success;
97 my $domainID = $response->id;
101 my $domain = 'basilisk.jp';
102 my $response = $plesk->domain_add( $domain );
103 die $response->errortext unless $response->is_success;
107 my $username = 'tofu_beast';
108 my $response = $plesk->mail_add( $domainID, $username, 'password' );
109 die $response->errortext unless $response->is_success;
110 my $uid = $response->id;
111 print "$username created: uid $uid\n";
115 $response = $plesk->mail_remove( 'username' );
116 if ( $response->is_success ) {
117 print "mailbox removed";
119 print "error removing mailbox: ". $response->errortext;
124 my $enabled = ($user_balance <= 0);
125 $response = $plesk->mail_set( $domainID, 'username', 'password', $enabled );
126 die $response->errortext unless $response->is_success;
130 This module implements a client interface to SWSOFT's Plesk Remote API,
131 enabling a perl application to talk to a Plesk managed server.
132 This documentation assumes that you are familiar with the Plesk documentation
133 available from SWSOFT (API 1.4.0.0 or later).
135 A new Net::Plesk object must be created with the I<new> method. Once this has
136 been done, all Plesk commands are accessed via method calls on the object.
142 =item new OPTION => VALUE ...
144 Creates a new Net::Plesk object. The I<URL>, I<:HTTP_AUTH_LOGIN>, and
145 I<:HTTP_AUTH_PASSWD> options are required.
151 my $class = ref($proto) || $proto;
152 my $self = { 'version' => $PROTO_VERSION,
155 bless($self, $class);
158 =item AUTOLOADed methods
160 Not all Plesk methods are available. See the Plesk documentation for methods,
161 arguments and return values. See B<Net::Plesk::Method> for available methods.
163 Responses are returned as B<Net::Plesk::Response> objects. See
164 L<Net::Plesk::Response>.
171 $AUTOLOAD =~ s/.*:://;
172 return if $AUTOLOAD eq 'DESTROY';
174 $AUTOLOAD =~ /^([[:alpha:]_]\w*)$/;
175 die "$AUTOLOAD Illegal method: $1" unless $1;
176 my $autoload = "Net::Plesk::Method::$1";
179 my $req = HTTP::Request->new('POST' => $self->{'POST'});
180 $req->content_type('text/xml');
183 next if $_ eq 'POST';
184 $req->header( $_ => $self->{$_} );
187 my $packet = $autoload->new(@_);
189 '<?xml version="1.0"?>' .
190 '<packet version="' . $self->{'version'} . '">' .
195 warn $req->as_string. "\n"
198 my $res = $ua->request($req);
200 # Check the outcome of the response
201 if ($res->is_success) {
203 warn "\nRESPONSE:\n". $res->content
206 my $response = new Net::Plesk::Response $res->content;
214 new Net::Plesk::Response (
215 '<?xml version="1.0" encoding="UTF-8"?>'. #a lie? probably safe
216 '<packet version="' . $self->{'version'} . '">' .
217 "<system><status>error</status><errcode>500</errcode>" .
218 "<errtext>" . $res->status_line . "</errtext></system>" .
229 Multiple request packets not tested.
233 SWSOFT Plesk Remote API documentation (1.4.0.0 or later)
237 Jeff Finucane E<lt>jeff@cmh.netE<gt>
239 =head1 COPYRIGHT AND LICENSE
241 Copyright (C) 2006 Jeff Finucane
243 This library is free software; you can redistribute it and/or modify
244 it under the same terms as Perl itself.