export host selection per service, RT#17914
[freeside.git] / FS / FS / part_export / www_plesk.pm
index 3839596..a247f05 100644 (file)
@@ -3,8 +3,6 @@ package FS::part_export::www_plesk;
 use vars qw(@ISA %info);
 use Tie::IxHash;
 use FS::part_export;
-use Net::Plesk;
-use Net::Plesk::Response;
 
 @ISA = qw(FS::part_export);
 
@@ -12,20 +10,24 @@ tie my %options, 'Tie::IxHash',
   'URL'       => { label=>'URL' },
   'login'     => { label=>'Login' },
   'password'  => { label=>'Password' },
+  'template'  => { label=>'Domain Template' },
+  'web'       => { label=>'Host Website',
+                    type=>'checkbox'          },
   'debug'     => { label=>'Enable debugging',
                     type=>'checkbox'          },
 ;
 
 %info = (
-  'svc'    => 'svc_www',
-  'desc'   => 'Real-time export to Plesk managed hosting service',
-  'options'=> \%options,
-  'notes'  => <<'END'
+  'svc'        => 'svc_www',
+  'desc'       => 'Real-time export to Plesk managed hosting service',
+  'options'    => \%options,
+  'no_machine' => 1,
+  'notes'      => <<'END'
 Real-time export to
 <a href="http://www.swsoft.com/">Plesk</a> managed server.
 Requires installation of
 <a href="http://search.cpan.org/dist/Net-Plesk">Net::Plesk</a>
-from CPAN.
+from CPAN and proper <a href="http://www.freeside.biz/mediawiki/index.php/Freeside:1.7:Documentation:Administration:www_plesk.pm">configuration</a>.
 END
 );
 
@@ -37,7 +39,10 @@ sub rebless { shift; }
 
 sub _export_insert {
   my( $self, $www ) = ( shift, shift );
-  
+
+  eval "use Net::Plesk;";
+  return $@ if $@;
+
   my $plesk = new Net::Plesk (
     'POST'              => $self->option('URL'),
     ':HTTP_AUTH_LOGIN'  => $self->option('login'),
@@ -70,15 +75,30 @@ sub _export_insert {
                                  $www->domain_record->recdata,
                                        );
 
-  $self->_plesk_command( 'domain_add', 
-                         $www->domain_record->svc_domain->domain,
-                        $gcresp->id,
-                        $www->domain_record->recdata,
-                      );
+  if ($self->option('web')) {
+    $self->_plesk_command( 'domain_add', 
+                           $www->domain_record->svc_domain->domain,
+                          $gcresp->id,
+                          $www->domain_record->recdata,
+                           $self->option('template')?$self->option('template'):'',
+                           $www->svc_acct->username,
+                           $www->svc_acct->_password,
+                        );
+  }else{
+    $self->_plesk_command( 'domain_add', 
+                           $www->domain_record->svc_domain->domain,
+                          $gcresp->id,
+                          $www->domain_record->recdata,
+                           $self->option('template')?$self->option('template'):'',
+                        );
+  }
 }
 
 sub _plesk_command {
   my( $self, $method, @args ) = @_;
+
+  eval "use Net::Plesk;";
+  return $@ if $@;
   
   local($Net::Plesk::DEBUG) = 1
     if $self->option('debug');