Initial import start
authorjeff <jeff>
Sat, 14 Oct 2006 21:13:30 +0000 (21:13 +0000)
committerjeff <jeff>
Sat, 14 Oct 2006 21:13:30 +0000 (21:13 +0000)
16 files changed:
MANIFEST [new file with mode: 0644]
Makefile.PL [new file with mode: 0644]
README [new file with mode: 0644]
lib/Net/Plesk.pm [new file with mode: 0644]
lib/Net/Plesk/Method.pm [new file with mode: 0644]
lib/Net/Plesk/Method/client_add.pm [new file with mode: 0644]
lib/Net/Plesk/Method/client_get.pm [new file with mode: 0644]
lib/Net/Plesk/Method/client_ippool_add_ip.pm [new file with mode: 0644]
lib/Net/Plesk/Method/domain_add.pm [new file with mode: 0644]
lib/Net/Plesk/Method/domain_del.pm [new file with mode: 0644]
lib/Net/Plesk/Method/domain_get.pm [new file with mode: 0644]
lib/Net/Plesk/Method/mail_add.pm [new file with mode: 0644]
lib/Net/Plesk/Method/mail_remove.pm [new file with mode: 0644]
lib/Net/Plesk/Method/mail_set.pm [new file with mode: 0644]
lib/Net/Plesk/Response.pm [new file with mode: 0644]
t/Net-Plesk.t [new file with mode: 0644]

diff --git a/MANIFEST b/MANIFEST
new file mode 100644 (file)
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 (file)
index 0000000..44bed2e
--- /dev/null
@@ -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 (file)
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 (file)
index 0000000..2b33c51
--- /dev/null
@@ -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<new> 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<URL>, 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<Net::Plesk::Method> for available methods.
+
+Responses are returned as B<Net::Plesk::Response> objects.  See
+L<Net::Plesk::Response>.
+
+=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(
+          '<?xml version="1.0"?>' .
+         '<packet version="' . $self->{'version'} . '">' .
+         $$packet .
+         '</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 E<lt>jeff@cmh.netE<gt>
+
+=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 (file)
index 0000000..df2acd4
--- /dev/null
@@ -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 = (
+  '&' => '&amp;',
+  '<' => '&lt;',
+  '>' => '&gt;',
+);
+
+=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 E<lt>jeff@cmh.netE<gt>
+
+=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 (file)
index 0000000..6cda065
--- /dev/null
@@ -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<login> and I<password>
+options are required.
+
+=cut
+
+sub init {
+  my ($self, $pname, $login, $passwd, $phone, $fax, $email, $address, $city,
+      $state, $pcode, $country) = @_;
+  $$self = join ( "\n", (
+                   '<client>',
+                   '<add>',
+                   '<gen_info>',
+                   '<pname>',
+                   $self->encode($pname),
+                   '</pname>',
+                   '<login>',
+                   $self->encode($login),
+                   '</login>',
+                   '<passwd>',
+                   $self->encode($passwd),
+                   '</passwd>',
+                   '<phone>',
+                   $self->encode($phone),
+                   '</phone>',
+                   '<fax>',
+                   $self->encode($fax),
+                   '</fax>',
+                   '<email>',
+                   $self->encode($email),
+                   '</email>',
+                   '<address>',
+                   $self->encode($address),
+                   '</address>',
+                   '<city>',
+                   $self->encode($city),
+                   '</city>',
+                   '<state>',
+                   $self->encode($state),
+                   '</state>',
+                   '<pcode>',
+                   $self->encode($pcode),
+                   '</pcode>',
+                   '<country>',
+                   $self->encode($country),
+                   '</country>',
+                   '</gen_info>',
+                   '</add>',
+                   '</client>',
+                 ));
+}
+
+=back
+
+=head1 BUGS
+
+  Creepy crawlies.
+
+=head1 SEE ALSO
+
+SWSOFT Plesk Remote API documentation (1.4.0.0 or later)
+
+=head1 AUTHOR
+
+Jeff Finucane E<lt>jeff@cmh.netE<gt>
+
+=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 (file)
index 0000000..5118ea7
--- /dev/null
@@ -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<login> options is required.
+
+=cut
+
+sub init {
+  my ($self, $login) = (shift, shift);
+  $$self = join ( "\n", (
+                   '<client>',
+                   '<get>',
+                   '<filter>',
+                   '<login>',
+                   $self->encode($login),
+                   '</login>',
+                   '</filter>',
+                   '<dataset>',
+                   '<gen_info/>',
+                   '</dataset>',
+                   '</get>',
+                   '</client>',
+                 ));
+}
+
+=back
+
+=head1 BUGS
+
+  Creepy crawlies.
+
+=head1 SEE ALSO
+
+SWSOFT Plesk Remote API documentation (1.4.0.0 or later)
+
+=head1 AUTHOR
+
+Jeff Finucane E<lt>jeff@cmh.netE<gt>
+
+=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 (file)
index 0000000..bafd5dd
--- /dev/null
@@ -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<clientID> and I<ipaddress>
+options are required.
+
+=cut
+
+sub init {
+  my ($self, $clientid, $ipaddress) = @_;
+  $$self = join ( "\n", (
+                   '<client>',
+                   '<ippool_add_ip>',
+                   '<client_id>',
+                   $self->encode($clientid),
+                   '</client_id>',
+                   '<ip_address>',
+                   $self->encode($ipaddress),
+                   '</ip_address>',
+                   '</ippool_add_ip>',
+                   '</client>',
+                 ));
+}
+
+=back
+
+=head1 BUGS
+
+  Creepy crawlies.
+
+=head1 SEE ALSO
+
+SWSOFT Plesk Remote API documentation (1.4.0.0 or later)
+
+=head1 AUTHOR
+
+Jeff Finucane E<lt>jeff@cmh.netE<gt>
+
+=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 (file)
index 0000000..cfe55be
--- /dev/null
@@ -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<domain>, I<client>, and
+$<ip_address> options are required.
+
+=cut
+
+sub init {
+  my ($self, $domain, $client, $ip) = @_;
+  $$self = join ( "\n", (
+                   '<domain>',
+                   '<add>',
+                   '<gen_setup>',
+                   '<name>',
+                   $self->encode($domain),
+                   '</name>',
+                   '<client_id>',
+                   $self->encode($client),
+                   '</client_id>',
+                   '<ip_address>',
+                   $self->encode($ip),
+                   '</ip_address>',
+                   '</gen_setup>',
+                   '</add>',
+                   '</domain>',
+                 ));
+}
+
+=back
+
+=head1 BUGS
+
+  Creepy crawlies.
+
+=head1 SEE ALSO
+
+SWSOFT Plesk Remote API documentation (1.4.0.0 or later)
+
+=head1 AUTHOR
+
+Jeff Finucane E<lt>jeff@cmh.netE<gt>
+
+=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 (file)
index 0000000..76112f9
--- /dev/null
@@ -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<domain> option is required.
+
+=cut
+
+sub init {
+  my ($self, $domain) = @_;
+  $$self = join ( "\n", (
+                   '<domain>',
+                   '<del>',
+                   '<filter>',
+                   '<domain_name>',
+                   $self->encode($domain),
+                   '</domain_name>',
+                   '</filter>',
+                   '</del>',
+                   '</domain>',
+                 ));
+}
+
+=back
+
+=head1 BUGS
+
+  Creepy crawlies.
+
+=head1 SEE ALSO
+
+SWSOFT Plesk Remote API documentation (1.4.0.0 or later)
+
+=head1 AUTHOR
+
+Jeff Finucane E<lt>jeff@cmh.netE<gt>
+
+=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 (file)
index 0000000..fabfcb2
--- /dev/null
@@ -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<domain> option is required.
+
+=cut
+
+sub init {
+  my ($self, $domain) = @_;
+  $$self = join ( "\n", (
+                   '<domain>',
+                   '<get>',
+                   '<filter>',
+                   '<domain_name>',
+                   $self->encode($domain),
+                   '</domain_name>',
+                   '</filter>',
+                   '<dataset>',
+                   '<gen_info/>',
+                   '</dataset>',
+                   '</get>',
+                   '</domain>',
+                 ));
+}
+
+=back
+
+=head1 BUGS
+
+  Creepy crawlies.
+
+=head1 SEE ALSO
+
+SWSOFT Plesk Remote API documentation (1.4.0.0 or later)
+
+=head1 AUTHOR
+
+Jeff Finucane E<lt>jeff@cmh.netE<gt>
+
+=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 (file)
index 0000000..39e8b6f
--- /dev/null
@@ -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<domainID>, I<mailbox>,
+and I<passwd> options are required.
+
+=cut
+
+sub init {
+  my ($self, $domainid, $mailbox, $password) = @_;
+  $$self = join ( "\n", (
+                   '<mail>',
+                   '<create>',
+                   '<filter>',
+                   '<domain_id>',
+                   $self->encode($domainid),
+                   '</domain_id>',
+                   '<mailname>',
+                   '<name>',
+                   $self->encode($mailbox),
+                   '</name>',
+                   '<password>',
+                   $self->encode($password),
+                   '</password>',
+                   '</mailname>',
+                   '</filter>',
+                   '</create>',
+                   '</mail>',
+                 ));
+}
+
+=back
+
+=head1 BUGS
+
+  Creepy crawlies.
+
+=head1 SEE ALSO
+
+SWSOFT Plesk Remote API documentation (1.4.0.0 or later)
+
+=head1 AUTHOR
+
+Jeff Finucane E<lt>jeff@cmh.netE<gt>
+
+=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 (file)
index 0000000..49804ab
--- /dev/null
@@ -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<domainID> and I<mailbox>
+options are required.
+
+=cut
+
+sub init {
+  my ($self, $domainid, $mailbox ) = @_;
+  $$self = join ( "\n", (
+                   '<mail>',
+                   '<remove>',
+                   '<filter>',
+                   '<domain_id>',
+                   $self->encode($domainid),
+                   '</domain_id>',
+                   '<name>',
+                   $self->encode($mailbox),
+                   '</name>',
+                   '</filter>',
+                   '</remove>',
+                   '</mail>',
+                 ));
+}
+
+=back
+
+=head1 BUGS
+
+  Creepy crawlies.
+
+=head1 SEE ALSO
+
+SWSOFT Plesk Remote API documentation (1.4.0.0 or later)
+
+=head1 AUTHOR
+
+Jeff Finucane E<lt>jeff@cmh.netE<gt>
+
+=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 (file)
index 0000000..df574f8
--- /dev/null
@@ -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<domainID>, I<mailbox>, and
+I<password> options are required.
+
+=cut
+
+sub init {
+  my ($self, $domainid, $mailbox, $password, $enabled) = @_;
+  my $enabledflag = $enabled ? "true" : "false";
+  $$self = join ( "\n", (
+                   '<mail>',
+                   '<update>',
+                   '<set>',
+                   '<filter>',
+                   '<domain_id>',
+                   $self->encode($domainid),
+                   '</domain_id>',
+                   '<mailname>',
+                   '<name>',
+                   $self->encode($mailbox),
+                   '</name>',
+                   '<mailbox>',
+                   '<enabled>',
+                   $self->encode($enabledflag),
+                   '</enabled>',
+                   '</mailbox>',
+                   '<password>',
+                   $self->encode($password),
+                   '</password>',
+                   '</mailname>',
+                   '</filter>',
+                   '</set>',
+                   '</update>',
+                   '</mail>',
+                 ));
+}
+
+=back
+
+=head1 BUGS
+
+  Creepy crawlies.
+
+=head1 SEE ALSO
+
+SWSOFT Plesk Remote API documentation (1.4.0.0 or later)
+
+=head1 AUTHOR
+
+Jeff Finucane E<lt>jeff@cmh.netE<gt>
+
+=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 (file)
index 0000000..58203f7
--- /dev/null
@@ -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<Net::Plesk>,
+
+=head1 AUTHOR
+
+Jeff Finucane E<lt>jeff@cmh.netE<gt>
+
+=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 (file)
index 0000000..906c409
--- /dev/null
@@ -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.
+
+