From 3e8bc1837343e34bac7106be458add3982fb77da Mon Sep 17 00:00:00 2001 From: jeff Date: Sat, 14 Oct 2006 21:13:30 +0000 Subject: [PATCH] Initial import --- MANIFEST | 16 ++ Makefile.PL | 9 + README | 32 ++++ lib/Net/Plesk.pm | 246 +++++++++++++++++++++++++++ lib/Net/Plesk/Method.pm | 87 ++++++++++ lib/Net/Plesk/Method/client_add.pm | 108 ++++++++++++ lib/Net/Plesk/Method/client_get.pm | 82 +++++++++ lib/Net/Plesk/Method/client_ippool_add_ip.pm | 79 +++++++++ lib/Net/Plesk/Method/domain_add.pm | 85 +++++++++ lib/Net/Plesk/Method/domain_del.pm | 76 +++++++++ lib/Net/Plesk/Method/domain_get.pm | 80 +++++++++ lib/Net/Plesk/Method/mail_add.pm | 87 ++++++++++ lib/Net/Plesk/Method/mail_remove.pm | 83 +++++++++ lib/Net/Plesk/Method/mail_set.pm | 96 +++++++++++ lib/Net/Plesk/Response.pm | 114 +++++++++++++ t/Net-Plesk.t | 18 ++ 16 files changed, 1298 insertions(+) create mode 100644 MANIFEST create mode 100644 Makefile.PL create mode 100644 README create mode 100644 lib/Net/Plesk.pm create mode 100644 lib/Net/Plesk/Method.pm create mode 100644 lib/Net/Plesk/Method/client_add.pm create mode 100644 lib/Net/Plesk/Method/client_get.pm create mode 100644 lib/Net/Plesk/Method/client_ippool_add_ip.pm create mode 100644 lib/Net/Plesk/Method/domain_add.pm create mode 100644 lib/Net/Plesk/Method/domain_del.pm create mode 100644 lib/Net/Plesk/Method/domain_get.pm create mode 100644 lib/Net/Plesk/Method/mail_add.pm create mode 100644 lib/Net/Plesk/Method/mail_remove.pm create mode 100644 lib/Net/Plesk/Method/mail_set.pm create mode 100644 lib/Net/Plesk/Response.pm create mode 100644 t/Net-Plesk.t diff --git a/MANIFEST b/MANIFEST new file mode 100644 index 0000000..8043637 --- /dev/null +++ b/MANIFEST @@ -0,0 +1,16 @@ +Makefile.PL +MANIFEST +README +lib/Net/Plesk.pm +lib/Net/Plesk/Method.pm +lib/Net/Plesk/Response.pm +lib/Net/Plesk/Method/client_add.pm +lib/Net/Plesk/Method/client_get.pm +lib/Net/Plesk/Method/client_ippool_add_ip.pm +lib/Net/Plesk/Method/domain_add.pm +lib/Net/Plesk/Method/domain_del.pm +lib/Net/Plesk/Method/domain_get.pm +lib/Net/Plesk/Method/mail_add.pm +lib/Net/Plesk/Method/mail_remove.pm +lib/Net/Plesk/Method/mail_set.pm +t/Net-Plesk.t diff --git a/Makefile.PL b/Makefile.PL new file mode 100644 index 0000000..44bed2e --- /dev/null +++ b/Makefile.PL @@ -0,0 +1,9 @@ +use ExtUtils::MakeMaker; +# See lib/ExtUtils/MakeMaker.pm for details of how to influence +# the contents of the Makefile that is written. +WriteMakefile( + 'NAME' => 'Net::Plesk', + 'VERSION_FROM' => 'lib/Net/Plesk.pm', # finds $VERSION + 'PREREQ_PM' => { + }, +); diff --git a/README b/README new file mode 100644 index 0000000..2c145ee --- /dev/null +++ b/README @@ -0,0 +1,32 @@ +Net-Plesk version 0.01 +==================== + +THis module implements a client interface to SWSOFT's Plesk XML RPC, +enabling a perl application to talk to a Plesk server. + +This module is not sponsored or endorsed by SWSOFT. + +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 + Crypt::SSLeay + XML::Simple + XML::XPATH::XMLParser + +COPYRIGHT AND LICENCE + +Copyright (C) 2006 Jeff Finucane + +This library is free software; you can redistribute it and/or modify +it under the same terms as Perl itself. diff --git a/lib/Net/Plesk.pm b/lib/Net/Plesk.pm new file mode 100644 index 0000000..2b33c51 --- /dev/null +++ b/lib/Net/Plesk.pm @@ -0,0 +1,246 @@ +package Net::Plesk; + +use 5.005; +use strict; + +use vars qw( $VERSION @ISA $AUTOLOAD $DEBUG $PROTO_VERSION $POST_URL + @EXPORT_OK %EXPORT_TAGS ); # @EXPORT + +use Exporter; +use LWP; +use Data::Dumper; + +use Net::Plesk::Response; +use Net::Plesk::Method; +use Net::Plesk::Method::domain_add; +use Net::Plesk::Method::domain_del; +use Net::Plesk::Method::domain_get; +use Net::Plesk::Method::mail_add; +use Net::Plesk::Method::mail_remove; +use Net::Plesk::Method::mail_set; +use Net::Plesk::Method::client_add; +use Net::Plesk::Method::client_get; +use Net::Plesk::Method::client_ippool_add_ip; + +@ISA = qw(Exporter); + +$VERSION = '0.01'; + +$PROTO_VERSION = '1.4.0.0'; + +$DEBUG = 1; + +my $ua = LWP::UserAgent->new; +$ua->agent("Net::Plesk/$VERSION"); + +=head1 NAME + +Net::Plesk - Perl extension for Plesk XML Remote API + +=head1 SYNOPSIS + + use Net::Plesk; + + my $plesk = new Net::Plesk ( + 'POST' => 'https://plesk.sample.com:8443/enterprise/control/agent.php', + ':HTTP_AUTH_LOGIN' => '1357948', + ':HTTP_AUTH_PASSWD' => 'password', + ); + + # client_get + + my $clientname = 'tofu_beast'; + my $response = $plesk->client_get( $clientname ); + die $response->errortext unless $response->is_success; + my $clientID = $response->id; + + # client_add + + unless $clientID { + my $clientname = 'Tofu Beast'; + my $login = 'tofu_beast'; + my $password = 'manyninjas'; + my $response = $plesk->client_add( $clientname, + $login, + $password, + $phone, + $fax, + $email, + $address, + $city, + $state, + $postcode, + $country, + ); + die $response->errortext unless $response->is_success; + $clientID = $response->id; + print "$clientname created with ID $clientID\n"; + } + + # client_ippool_add_ip + + my $ipaddress = '192.168.8.45'; + my $response = $plesk->client_ippool_add_ip( $clientID, $ipaddress ); + die $response->errortext unless $response->is_success; + + # domain_get + + my $domain = 'basilisk.jp'; + my $response = $plesk->domain_get( $domain ); + die $response->errortext unless $response->is_success; + my $domainID = $response->id; + + # domain_add + + my $domain = 'basilisk.jp'; + my $clientID = 17; + my $ipaddr = '192.168.8.45'; + my $response = $plesk->domain_add( $domain, $clientID, $ipaddr ); + die $response->errortext unless $response->is_success; + my $domainID = $response->id; + + # domain_del + + my $domain = 'basilisk.jp'; + my $response = $plesk->domain_add( $domain ); + die $response->errortext unless $response->is_success; + + # mail_add + + my $username = 'tofu_beast'; + my $response = $plesk->mail_add( $domainID, $username, 'password' ); + die $response->errortext unless $response->is_success; + my $uid = $response->id; + print "$username created: uid $uid\n"; + + # mail_remove + + $response = $plesk->mail_remove( 'username' ); + if ( $response->is_success ) { + print "mailbox removed"; + } else { + print "error removing mailbox: ". $response->errortext; + } + + # mail_set + + my $enabled = ($user_balance <= 0); + $response = $plesk->mail_set( $domainID, 'username', 'password', $enabled ); + die $response->errortext unless $response->is_success; + +=head1 DESCRIPTION + +This module implements a client interface to SWSOFT's Plesk Remote API, +enabling a perl application to talk to a Plesk managed server. +This documentation assumes that you are familiar with the Plesk documentation +available from SWSOFT (API 1.4.0.0 or later). + +A new Net::Plesk object must be created with the I method. Once this has +been done, all Plesk commands are accessed via method calls on the object. + +=head1 METHODS + +=over 4 + +=item new OPTION => VALUE ... + +Creates a new Net::Plesk object. The I, I<:HTTP_AUTH_LOGIN>, and +I<:HTTP_AUTH_PASSWD> options are required. + +=cut + +sub new { + my $proto = shift; + my $class = ref($proto) || $proto; + my $self = { 'version' => $PROTO_VERSION, + @_, + }; + bless($self, $class); +} + +=item AUTOLOADed methods + +Not all Plesk methods are available. See the Plesk documentation for methods, +arguments and return values. See B for available methods. + +Responses are returned as B objects. See +L. + +=cut + +sub AUTOLOAD { + + my $self = shift; + $AUTOLOAD =~ s/.*:://; + return if $AUTOLOAD eq 'DESTROY'; + + $AUTOLOAD =~ /^([[:alpha:]_]\w*)$/; + die "$AUTOLOAD Illegal method: $1" unless $1; + my $autoload = "Net::Plesk::Method::$1"; + + #inherit? + my $req = HTTP::Request->new('POST' => $self->{'POST'}); + $req->content_type('text/xml'); + + for (keys(%$self)) { + next if $_ eq 'POST'; + $req->header( $_ => $self->{$_} ); + } + + my $packet = $autoload->new(@_); + $req->content( + '' . + '' . + $$packet . + '' + ); + + warn $req->as_string. "\n" + if $DEBUG; + + my $res = $ua->request($req); + + # Check the outcome of the response + if ($res->is_success) { + + warn "\nRESPONSE:\n". $res->content + if $DEBUG; + + my $response = new Net::Plesk::Response $res->content; + + warn Dumper( $response ) + if $DEBUG; + + $response; + } + else { + die $res->status_line, "\n"; + } + +} + +=back + +=head1 BUGS + + Multiple request packets not tested. + +=head1 SEE ALSO + +SWSOFT Plesk Remote API documentation (1.4.0.0 or later) + +=head1 AUTHOR + +Jeff Finucane Ejeff@cmh.netE + +=head1 COPYRIGHT AND LICENSE + +Copyright (C) 2006 Jeff Finucane + +This library is free software; you can redistribute it and/or modify +it under the same terms as Perl itself. + +=cut + +1; + diff --git a/lib/Net/Plesk/Method.pm b/lib/Net/Plesk/Method.pm new file mode 100644 index 0000000..df2acd4 --- /dev/null +++ b/lib/Net/Plesk/Method.pm @@ -0,0 +1,87 @@ +package Net::Plesk::Method; + +use strict; + +use vars qw( $VERSION @ISA $AUTOLOAD $DEBUG ); + +$VERSION = '0.01'; + +$DEBUG = 0; + +my %char_entities = ( + '&' => '&', + '<' => '<', + '>' => '>', +); + +=head1 NAME + +Net::Plesk::Method - Perl base class for Plesk XML Remote API Method + +=head1 SYNOPSIS + + use Exporter; + @ISA = qw( Net::Plesk::Method ); + +=head1 DESCRIPTION + +This module implements a base class for constructing requests using SWSOFT's +Plesk. + +=head1 METHODS + +=over 4 + +=item new + +Creates a new Net::Plesk::Method object and initializes it. +=cut + +sub new { + my $proto = shift; + my $class = ref($proto) || $proto; + my $me; + my $self = \$me; + bless($self, $class); + $self->init(@_); + return $self; +} + + +=item encode + +Returns the xml encoded entity + +=cut + +sub encode { + my ($self,$value) = (shift,shift); + $value =~ s/([&<>])/$char_entities{$1}/ge; + return $value; +} + +=back + +=head1 BUGS + + Creepy crawlies. + +=head1 SEE ALSO + +SWSOFT Plesk Remote API documentation (1.4.0.0 or later) + +=head1 AUTHOR + +Jeff Finucane Ejeff@cmh.netE + +=head1 COPYRIGHT AND LICENSE + +Copyright (C) 2006 Jeff Finucane + +This library is free software; you can redistribute it and/or modify +it under the same terms as Perl itself. + +=cut + +1; + diff --git a/lib/Net/Plesk/Method/client_add.pm b/lib/Net/Plesk/Method/client_add.pm new file mode 100644 index 0000000..6cda065 --- /dev/null +++ b/lib/Net/Plesk/Method/client_add.pm @@ -0,0 +1,108 @@ +package Net::Plesk::Method::client_add; + +use strict; + +use vars qw( $VERSION @ISA $AUTOLOAD $DEBUG ); + +@ISA = qw ( Net::Plesk::Method ); +$VERSION = '0.01'; + +$DEBUG = 0; + +=head1 NAME + +Net::Plesk::Method::client_add - Perl extension for Plesk XML Remote API client addition + +=head1 SYNOPSIS + + use Net::Plesk::Method::client_add + + my $p = new Net::Plesk::client_add ( $clientID, 'client.com' ); + +=head1 DESCRIPTION + +This module implements an interface to construct a request for a client +addition using SWSOFT's Plesk. + +=head1 METHODS + +=over 4 + +=item init args ... + +Initializes a Plesk client_add object. The I and I +options are required. + +=cut + +sub init { + my ($self, $pname, $login, $passwd, $phone, $fax, $email, $address, $city, + $state, $pcode, $country) = @_; + $$self = join ( "\n", ( + '', + '', + '', + '', + $self->encode($pname), + '', + '', + $self->encode($login), + '', + '', + $self->encode($passwd), + '', + '', + $self->encode($phone), + '', + '', + $self->encode($fax), + '', + '', + $self->encode($email), + '', + '
', + $self->encode($address), + '
', + '', + $self->encode($city), + '', + '', + $self->encode($state), + '', + '', + $self->encode($pcode), + '', + '', + $self->encode($country), + '', + '
', + '
', + '
', + )); +} + +=back + +=head1 BUGS + + Creepy crawlies. + +=head1 SEE ALSO + +SWSOFT Plesk Remote API documentation (1.4.0.0 or later) + +=head1 AUTHOR + +Jeff Finucane Ejeff@cmh.netE + +=head1 COPYRIGHT AND LICENSE + +Copyright (C) 2006 Jeff Finucane + +This library is free software; you can redistribute it and/or modify +it under the same terms as Perl itself. + +=cut + +1; + diff --git a/lib/Net/Plesk/Method/client_get.pm b/lib/Net/Plesk/Method/client_get.pm new file mode 100644 index 0000000..5118ea7 --- /dev/null +++ b/lib/Net/Plesk/Method/client_get.pm @@ -0,0 +1,82 @@ +package Net::Plesk::Method::client_get; + +use strict; + +use vars qw( $VERSION @ISA $AUTOLOAD $DEBUG ); + +@ISA = qw( Net::Plesk::Method ); +$VERSION = '0.01'; + +$DEBUG = 0; + +=head1 NAME + +Net::Plesk::Method::client_get - Perl extension for Plesk XML Remote API client + retrieval + +=head1 SYNOPSIS + + use Net::Plesk::Method::client_get + + my $p = new Net::Plesk::Method::client_get ( $login ); + + $request = $p->endcode; + +=head1 DESCRIPTION + +This module implements an interface to construct a request for a client +retrieval using SWSOFT's Plesk. + +=head1 METHODS + +=over 4 + +=item init args ... + +Initializes a Plesk client_get object. The I options is required. + +=cut + +sub init { + my ($self, $login) = (shift, shift); + $$self = join ( "\n", ( + '', + '', + '', + '', + $self->encode($login), + '', + '', + '', + '', + '', + '', + '', + )); +} + +=back + +=head1 BUGS + + Creepy crawlies. + +=head1 SEE ALSO + +SWSOFT Plesk Remote API documentation (1.4.0.0 or later) + +=head1 AUTHOR + +Jeff Finucane Ejeff@cmh.netE + +=head1 COPYRIGHT AND LICENSE + +Copyright (C) 2006 Jeff Finucane + +This library is free software; you can redistribute it and/or modify +it under the same terms as Perl itself. + +=cut + +1; + diff --git a/lib/Net/Plesk/Method/client_ippool_add_ip.pm b/lib/Net/Plesk/Method/client_ippool_add_ip.pm new file mode 100644 index 0000000..bafd5dd --- /dev/null +++ b/lib/Net/Plesk/Method/client_ippool_add_ip.pm @@ -0,0 +1,79 @@ +package Net::Plesk::Method::client_ippool_add_ip; + +use strict; + +use vars qw( $VERSION @ISA $AUTOLOAD $DEBUG ); + +@ISA = qw( Net::Plesk::Method ); +$VERSION = '0.01'; + +$DEBUG = 0; + +=head1 NAME + +Net::Plesk::Method::client_ippool_add_ip - Perl extension for Plesk XML +Remote API client ippool addition + +=head1 SYNOPSIS + + use Net::Plesk::Method::client_ippool_add_ip + + my $p = new Net::Plesk::Method::client_ippool_add_ip ( $clientID, $ipaddress ); + +=head1 DESCRIPTION + +This module implements an interface to construct a request for a ippool +addition to a client using SWSOFT's Plesk. + +=head1 METHODS + +=over 4 + +=item init args ... + +Initializes a Plesk client ippool_add_ip. The I and I +options are required. + +=cut + +sub init { + my ($self, $clientid, $ipaddress) = @_; + $$self = join ( "\n", ( + '', + '', + '', + $self->encode($clientid), + '', + '', + $self->encode($ipaddress), + '', + '', + '', + )); +} + +=back + +=head1 BUGS + + Creepy crawlies. + +=head1 SEE ALSO + +SWSOFT Plesk Remote API documentation (1.4.0.0 or later) + +=head1 AUTHOR + +Jeff Finucane Ejeff@cmh.netE + +=head1 COPYRIGHT AND LICENSE + +Copyright (C) 2006 Jeff Finucane + +This library is free software; you can redistribute it and/or modify +it under the same terms as Perl itself. + +=cut + +1; + diff --git a/lib/Net/Plesk/Method/domain_add.pm b/lib/Net/Plesk/Method/domain_add.pm new file mode 100644 index 0000000..cfe55be --- /dev/null +++ b/lib/Net/Plesk/Method/domain_add.pm @@ -0,0 +1,85 @@ +package Net::Plesk::Method::domain_add; + +use strict; + +use vars qw( $VERSION @ISA $AUTOLOAD $DEBUG ); + +@ISA = qw( Net::Plesk::Method ); +$VERSION = '0.01'; + +$DEBUG = 0; + +=head1 NAME + +Net::Plesk::Method::domain_add - Perl extension for Plesk XML Remote API domain addition + +=head1 SYNOPSIS + + use Net::Plesk::Method::domain_add + + my $p = new Net::Plesk::Method::domain_add ( $clientID, 'domain.com' ); + + $request = $p->endcode; + +=head1 DESCRIPTION + +This module implements an interface to construct a request for a domain +addition using SWSOFT's Plesk. + +=head1 METHODS + +=over 4 + +=item init args ... + +Initializes a Plesk domain_add object. The I, I, and +$ options are required. + +=cut + +sub init { + my ($self, $domain, $client, $ip) = @_; + $$self = join ( "\n", ( + '', + '', + '', + '', + $self->encode($domain), + '', + '', + $self->encode($client), + '', + '', + $self->encode($ip), + '', + '', + '', + '', + )); +} + +=back + +=head1 BUGS + + Creepy crawlies. + +=head1 SEE ALSO + +SWSOFT Plesk Remote API documentation (1.4.0.0 or later) + +=head1 AUTHOR + +Jeff Finucane Ejeff@cmh.netE + +=head1 COPYRIGHT AND LICENSE + +Copyright (C) 2006 Jeff Finucane + +This library is free software; you can redistribute it and/or modify +it under the same terms as Perl itself. + +=cut + +1; + diff --git a/lib/Net/Plesk/Method/domain_del.pm b/lib/Net/Plesk/Method/domain_del.pm new file mode 100644 index 0000000..76112f9 --- /dev/null +++ b/lib/Net/Plesk/Method/domain_del.pm @@ -0,0 +1,76 @@ +package Net::Plesk::Method::domain_del; + +use strict; + +use vars qw( $VERSION @ISA $AUTOLOAD $DEBUG ); + +@ISA = qw( Net::Plesk::Method ); +$VERSION = '0.01'; + +$DEBUG = 0; + +=head1 NAME + +Net::Plesk::Method::domain_del - Perl extension for Plesk XML Remote API domain deletion + +=head1 SYNOPSIS + + use Net::Plesk::Method::domain_del + + my $p = new Net::Plesk::Method::domain_del ( 'domain.com' ); + +=head1 DESCRIPTION + +This module implements an interface to construct a request for a domain +addition using SWSOFT's Plesk. + +=head1 METHODS + +=over 4 + +=item init args ... + +Initializes a Plesk domain_del object. The I option is required. + +=cut + +sub init { + my ($self, $domain) = @_; + $$self = join ( "\n", ( + '', + '', + '', + '', + $self->encode($domain), + '', + '', + '', + '', + )); +} + +=back + +=head1 BUGS + + Creepy crawlies. + +=head1 SEE ALSO + +SWSOFT Plesk Remote API documentation (1.4.0.0 or later) + +=head1 AUTHOR + +Jeff Finucane Ejeff@cmh.netE + +=head1 COPYRIGHT AND LICENSE + +Copyright (C) 2006 Jeff Finucane + +This library is free software; you can redistribute it and/or modify +it under the same terms as Perl itself. + +=cut + +1; + diff --git a/lib/Net/Plesk/Method/domain_get.pm b/lib/Net/Plesk/Method/domain_get.pm new file mode 100644 index 0000000..fabfcb2 --- /dev/null +++ b/lib/Net/Plesk/Method/domain_get.pm @@ -0,0 +1,80 @@ +package Net::Plesk::Method::domain_get; + +use strict; + +use vars qw( $VERSION @ISA $AUTOLOAD $DEBUG ); + +@ISA = qw( Net::Plesk::Method ); +$VERSION = '0.01'; + +$DEBUG = 0; + +=head1 NAME + +Net::Plesk::Method::domain_get - Perl extension for Plesk XML Remote API domain + information retreival + +=head1 SYNOPSIS + + use Net::Plesk::Method::domain_get + + my $p = new Net::Plesk::Method::domain_get ( 'domain.com' ); + +=head1 DESCRIPTION + +This module implements an interface to construct a request for domain +information retreival using SWSOFT's Plesk. + +=head1 METHODS + +=over 4 + +=item init args ... + +Initializes a Plesk domain_get object. The I option is required. + +=cut + +sub init { + my ($self, $domain) = @_; + $$self = join ( "\n", ( + '', + '', + '', + '', + $self->encode($domain), + '', + '', + '', + '', + '', + '', + '', + )); +} + +=back + +=head1 BUGS + + Creepy crawlies. + +=head1 SEE ALSO + +SWSOFT Plesk Remote API documentation (1.4.0.0 or later) + +=head1 AUTHOR + +Jeff Finucane Ejeff@cmh.netE + +=head1 COPYRIGHT AND LICENSE + +Copyright (C) 2006 Jeff Finucane + +This library is free software; you can redistribute it and/or modify +it under the same terms as Perl itself. + +=cut + +1; + diff --git a/lib/Net/Plesk/Method/mail_add.pm b/lib/Net/Plesk/Method/mail_add.pm new file mode 100644 index 0000000..39e8b6f --- /dev/null +++ b/lib/Net/Plesk/Method/mail_add.pm @@ -0,0 +1,87 @@ +package Net::Plesk::Method::mail_add; + +use strict; + +use vars qw( $VERSION @ISA $AUTOLOAD $DEBUG ); + +@ISA = qw( Net::Plesk::Method ); +$VERSION = '0.01'; + +$DEBUG = 0; + +=head1 NAME + +Net::Plesk::Method::mail_add - Perl extension for Plesk XML Remote API mail addition + +=head1 SYNOPSIS + + use Net::Plesk::Method::mail_add + + my $p = new Net::Plesk::Method::mail_add ( $domainID, $mailbox, $passwd ); + + $request = $p->endcode; + +=head1 DESCRIPTION + +This module implements an interface to construct a request for a mailbox +addition using SWSOFT's Plesk. + +=head1 METHODS + +=over 4 + +=item init args ... + +Initializes a Plesk mail_add object. The I, I, +and I options are required. + +=cut + +sub init { + my ($self, $domainid, $mailbox, $password) = @_; + $$self = join ( "\n", ( + '', + '', + '', + '', + $self->encode($domainid), + '', + '', + '', + $self->encode($mailbox), + '', + '', + $self->encode($password), + '', + '', + '', + '', + '', + )); +} + +=back + +=head1 BUGS + + Creepy crawlies. + +=head1 SEE ALSO + +SWSOFT Plesk Remote API documentation (1.4.0.0 or later) + +=head1 AUTHOR + +Jeff Finucane Ejeff@cmh.netE + +=head1 COPYRIGHT AND LICENSE + +Copyright (C) 2006 Jeff Finucane + +This library is free software; you can redistribute it and/or modify +it under the same terms as Perl itself. + +=cut + +1; + diff --git a/lib/Net/Plesk/Method/mail_remove.pm b/lib/Net/Plesk/Method/mail_remove.pm new file mode 100644 index 0000000..49804ab --- /dev/null +++ b/lib/Net/Plesk/Method/mail_remove.pm @@ -0,0 +1,83 @@ +package Net::Plesk::Method::mail_remove; + +use strict; + +use vars qw( $VERSION @ISA $AUTOLOAD $DEBUG ); + +@ISA = qw( Net::Plesk::Method ); +$VERSION = '0.01'; + +$DEBUG = 0; + +=head1 NAME + +Net::Plesk::Method::mail_remove - Perl extension for Plesk XML Remote API mail removal + +=head1 SYNOPSIS + + use Net::Plesk::Method::mail_remove + + my $p = + new Net::Plesk::Method::mail_remove ( $domainID, $mailbox ); + + $request = $p->endcode; + +=head1 DESCRIPTION + +This module implements an interface to construct a request for a mailbox +removal using SWSOFT's Plesk. + +=head1 METHODS + +=over 4 + +=item init args ... + +Initializes a Plesk mail_remove object. The I and I +options are required. + +=cut + +sub init { + my ($self, $domainid, $mailbox ) = @_; + $$self = join ( "\n", ( + '', + '', + '', + '', + $self->encode($domainid), + '', + '', + $self->encode($mailbox), + '', + '', + '', + '', + )); +} + +=back + +=head1 BUGS + + Creepy crawlies. + +=head1 SEE ALSO + +SWSOFT Plesk Remote API documentation (1.4.0.0 or later) + +=head1 AUTHOR + +Jeff Finucane Ejeff@cmh.netE + +=head1 COPYRIGHT AND LICENSE + +Copyright (C) 2006 Jeff Finucane + +This library is free software; you can redistribute it and/or modify +it under the same terms as Perl itself. + +=cut + +1; + diff --git a/lib/Net/Plesk/Method/mail_set.pm b/lib/Net/Plesk/Method/mail_set.pm new file mode 100644 index 0000000..df574f8 --- /dev/null +++ b/lib/Net/Plesk/Method/mail_set.pm @@ -0,0 +1,96 @@ +package Net::Plesk::Method::mail_set; + +use strict; + +use vars qw( $VERSION @ISA $AUTOLOAD $DEBUG ); + +@ISA = qw( Net::Plesk::Method ); +$VERSION = '0.01'; + +$DEBUG = 0; + +=head1 NAME + +Net::Plesk::Method::mail_set - Perl extension for Plesk XML Remote API mailbox setting + +=head1 SYNOPSIS + + use Net::Plesk::Method::mail_set + + my $p = new Net::Plesk::Method::mail_set + ( $domainID, $mailbox, $passwd, $enabled ); + + $request = $p->endcode; + +=head1 DESCRIPTION + +This module implements an interface to construct a request for setting a +mailbox using SWSOFT's Plesk. + +=head1 METHODS + +=over 4 + +=item init args ... + +Initializes a Plesk mail_set object. The I, I, and +I options are required. + +=cut + +sub init { + my ($self, $domainid, $mailbox, $password, $enabled) = @_; + my $enabledflag = $enabled ? "true" : "false"; + $$self = join ( "\n", ( + '', + '', + '', + '', + '', + $self->encode($domainid), + '', + '', + '', + $self->encode($mailbox), + '', + '', + '', + $self->encode($enabledflag), + '', + '', + '', + $self->encode($password), + '', + '', + '', + '', + '', + '', + )); +} + +=back + +=head1 BUGS + + Creepy crawlies. + +=head1 SEE ALSO + +SWSOFT Plesk Remote API documentation (1.4.0.0 or later) + +=head1 AUTHOR + +Jeff Finucane Ejeff@cmh.netE + +=head1 COPYRIGHT AND LICENSE + +Copyright (C) 2006 Jeff Finucane + +This library is free software; you can redistribute it and/or modify +it under the same terms as Perl itself. + +=cut + +1; + diff --git a/lib/Net/Plesk/Response.pm b/lib/Net/Plesk/Response.pm new file mode 100644 index 0000000..58203f7 --- /dev/null +++ b/lib/Net/Plesk/Response.pm @@ -0,0 +1,114 @@ +package Net::Plesk::Response; + +use strict; +use XML::Simple; +use XML::XPath; +use XML::XPath::XMLParser; + +=head1 NAME + +Net::Plesk::Response - Plesk response object + +=head1 SYNOPSIS + + my $response = $plesk->some_method( $and, $args ); + + if ( $response->is_success ) { + + my $id = $response->id; + #... + + } else { + + my $error = $response->error; #error code + my $errortext = $response->errortext; #error message + #... + } + +=head1 DESCRIPTION + +The "Net::Plesk::Response" class represents Plesk responses. + +=cut + +sub new { + my $proto = shift; + my $class = ref($proto) || $proto; + my $self = {}; + bless($self, $class); + + my $data = shift; + $data =~ /^\<\?xml version=\"1.0\"\?\>(.*)$/s; + + my $xp = XML::XPath->new(xml => $1); + my $nodeset = $xp->find('//result'); + foreach my $node ($nodeset->get_nodelist) { + push @{$self->{'results'}}, XML::XPath::XMLParser::as_string($node); + } + + $self; +} + +sub is_success { + my $self = shift; + my $status = 1; + foreach my $result (@{$self->{'results'}}) { + $status = (XMLin($result)->{'status'} eq 'ok'); + last unless $status; + } + $status; +} + +sub error { + my $self = shift; + my @errcode; + foreach my $result (@{$self->{'results'}}) { + my $errcode = XMLin($result)->{'errcode'}; + push @errcode, $errcode if $errcode; + } + return wantarray ? @errcode : $errcode[0]; +} + +sub errortext { + my $self = shift; + my @errtext; + foreach my $result (@{$self->{'results'}}) { + my $errtext = XMLin($result)->{'errtext'}; + push @errtext, $errtext if $errtext; + } + return wantarray ? @errtext : $errtext[0]; +} + +sub id { + my $self = shift; + my @id; + foreach my $result (@{$self->{'results'}}) { + my $id = XMLin($result)->{'id'}; + push @id, $id if $id; + } + return wantarray ? @id : $id[0]; +} + + +=head1 BUGS + +Needs better documentation. + +=head1 SEE ALSO + +L, + +=head1 AUTHOR + +Jeff Finucane Ejeff@cmh.netE + +=head1 COPYRIGHT AND LICENSE + +Copyright (C) 2006 Jeff Finucane + +This library is free software; you can redistribute it and/or modify +it under the same terms as Perl itself. + +=cut + +1; diff --git a/t/Net-Plesk.t b/t/Net-Plesk.t new file mode 100644 index 0000000..906c409 --- /dev/null +++ b/t/Net-Plesk.t @@ -0,0 +1,18 @@ +# Before `make install' is performed this script should be runnable with +# `make test'. After `make install' it should work as `perl Net-Plesk.t' + +######################### + +# change 'tests => 1' to 'tests => last_test_to_print'; + +use Test; +BEGIN { plan tests => 1 }; +use Net::Plesk; +ok(1); # If we made it this far, we're ok. + +######################### + +# Insert your test code below, the Test module is use()ed here so read +# its man page ( perldoc Test ) for help writing this test script. + + -- 2.11.0