preliminary plesk support
[freeside.git] / FS / FS / part_export / www_plesk.pm
1 package FS::part_export::www_plesk;
2
3 use vars qw(@ISA %info);
4 use Tie::IxHash;
5 use FS::part_export;
6 use Net::Plesk;
7 use Net::Plesk::Response;
8
9 @ISA = qw(FS::part_export);
10
11 tie my %options, 'Tie::IxHash',
12   'URL'       => { label=>'URL' },
13   'login'     => { label=>'Login' },
14   'password'  => { label=>'Password' },
15   'debug'     => { label=>'Enable debugging',
16                     type=>'checkbox'          },
17 ;
18
19 %info = (
20   'svc'    => 'svc_www',
21   'desc'   => 'Real-time export to Plesk managed hosting service',
22   'options'=> \%options,
23   'notes'  => <<'END'
24 Real-time export to
25 <a href="http://www.swsoft.com/">Plesk</a> managed server.
26 Requires installation of
27 <a href="http://search.cpan.org/dist/Net-Plesk">Net::Plesk</a>
28 from CPAN.
29 END
30 );
31
32 sub rebless { shift; }
33
34 # experiment: want the status of these right away (don't want account to
35 # create or whatever and then get error in the queue from dup username or
36 # something), so no queueing
37
38 sub _export_insert {
39   my( $self, $www ) = ( shift, shift );
40   
41   my $plesk = new Net::Plesk (
42     'POST'              => $self->option('URL'),
43     ':HTTP_AUTH_LOGIN'  => $self->option('login'),
44     ':HTTP_AUTH_PASSWD' => $self->option('password'),
45   );
46
47   my $gcresp = $plesk->client_get( $www->svc_acct->username );
48   return $gcresp->errortext
49     unless $gcresp->is_success;
50
51   unless ($gcresp->id) {
52     my $cust_main = $www->cust_svc->cust_pkg->cust_main;
53     $gcresp = $plesk->client_add( $cust_main->name,
54                                   $www->svc_acct->username,
55                                   $www->svc_acct->_password,
56                                   $cust_main->daytime,
57                                   $cust_main->fax,
58                                   $cust_main->invoicing_list->[0],
59                                   $cust_main->address1 . $cust_main->address2,
60                                   $cust_main->city,
61                                   $cust_main->state,
62                                   $cust_main->zip,
63                                   $cust_main->country,
64                                 );
65     return $gcresp->errortext
66       unless $gcresp->is_success;
67   }
68
69   $plesk->client_ippool_add_ip ( $gcresp->id,
70                                  $www->domain_record->recdata,
71                                 );
72
73   $self->_plesk_command( 'domain_add', 
74                          $www->domain_record->svc_domain->domain,
75                          $gcresp->id,
76                          $www->domain_record->recdata,
77                        );
78 }
79
80 sub _plesk_command {
81   my( $self, $method, @args ) = @_;
82   
83   local($Net::Plesk::DEBUG) = 1
84     if $self->option('debug');
85
86   my $plesk = new Net::Plesk (
87     'POST'              => $self->option('URL'),
88     ':HTTP_AUTH_LOGIN'  => $self->option('login'),
89     ':HTTP_AUTH_PASSWD' => $self->option('password'),
90   );
91
92   my $response = $plesk->$method(@args);
93   return $response->errortext unless $response->is_success;
94   '';
95
96 }
97
98 sub _export_replace {
99   my( $self, $new, $old ) = (shift, shift, shift);
100
101   return "can't change domain with Plesk"
102     if $old->domain_record->svc_domain->domain ne
103        $new->domain_record->svc_domain->domain;
104
105   return "can't change client with Plesk"
106     if $old->svc_acct->username ne
107        $new->svc_acct->username;
108
109   return '';
110
111 }
112
113 sub _export_delete {
114   my( $self, $www ) = ( shift, shift );
115   $self->_plesk_command( 'domain_del', $www->domain_record->svc_domain->domain);
116 }
117
118 1;
119