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