From: jeff Date: Sat, 14 Oct 2006 20:47:11 +0000 (+0000) Subject: preliminary plesk support X-Git-Tag: TRIXBOX_2_6~927 X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=commitdiff_plain;h=55ba66c693dcd0f37123476bb4383491514bf41c preliminary plesk support --- diff --git a/FS/FS/part_export/acct_plesk.pm b/FS/FS/part_export/acct_plesk.pm new file mode 100644 index 000000000..e295a01c5 --- /dev/null +++ b/FS/FS/part_export/acct_plesk.pm @@ -0,0 +1,118 @@ +package FS::part_export::acct_plesk; + +use vars qw(@ISA %info); +use Tie::IxHash; +use FS::part_export; + +@ISA = qw(FS::part_export); + +tie my %options, 'Tie::IxHash', + 'URL' => { label=>'URL' }, + 'login' => { label=>'Login' }, + 'password' => { label=>'Password' }, + 'debug' => { label=>'Enable debugging', + type=>'checkbox' }, +; + +%info = ( + 'svc' => 'svc_acct', + 'desc' => 'Real-time export to Plesk managed mail service', + 'options'=> \%options, + 'notes' => <<'END' +Real-time export to +Plesk managed server. +Requires installation of +Net::Plesk +from CPAN. +END +); + +sub rebless { shift; } + +# experiment: want the status of these right away (don't want account to +# create or whatever and then get error in the queue from dup username or +# something), so no queueing + +sub _export_insert { + my( $self, $svc_acct ) = (shift, shift); + + $self->_plesk_command( 'mail_add', + $svc_acct->domain, + $svc_acct->username, + $svc_acct->_password, + ) || + $self->_export_unsuspend($svc_acct); +} + +sub _plesk_command { + my( $self, $method, $domain, @args ) = @_; + + local($Net::Plesk::DEBUG) = 1 + if $self->option('debug'); + + my $plesk = new Net::Plesk ( + 'POST' => $self->option('URL'), + ':HTTP_AUTH_LOGIN' => $self->option('login'), + ':HTTP_AUTH_PASSWD' => $self->option('password'), + ); + + my $dresponse = $plesk->domain_get( $domain ); + return $dresponse->error unless $dresponse->is_success; + my $domainID = $dresponse->id; + + my $response = $plesk->$method($dresponse->id, @args); + return $response->errortext unless $response->is_success; + ''; + +} + +sub _export_replace { + my( $self, $new, $old ) = (shift, shift, shift); + + return "can't change domain with Plesk" + if $old->domain ne $new->domain; + return "can't change username with Plesk" + if $old->username ne $new->username; + return '' unless $old->_password ne $new->_password; + + $self->_plesk_command( 'mail_set', + $new->domain, + $new->username, + $new->_password, + $old->cust_svc->cust_pkg->susp ? 0 : 1, + ); +} + +sub _export_delete { + my( $self, $svc_acct ) = (shift, shift); + + $self->_plesk_command( 'mail_remove', + $svc_acct->domain, + $svc_acct->username, + ); +} + +sub _export_suspend { + my( $self, $svc_acct ) = (shift, shift); + + $self->_plesk_command( 'mail_set', + $svc_acct->domain, + $svc_acct->username, + $svc_acct->_password, + 0, + ); +} + +sub _export_unsuspend { + my( $self, $svc_acct ) = (shift, shift); + + $self->_plesk_command( 'mail_set', + $svc_acct->domain, + $svc_acct->username, + $svc_acct->_password, + 1, + ); +} + +1; + diff --git a/FS/FS/part_export/www_plesk.pm b/FS/FS/part_export/www_plesk.pm new file mode 100644 index 000000000..383959672 --- /dev/null +++ b/FS/FS/part_export/www_plesk.pm @@ -0,0 +1,119 @@ +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); + +tie my %options, 'Tie::IxHash', + 'URL' => { label=>'URL' }, + 'login' => { label=>'Login' }, + 'password' => { label=>'Password' }, + 'debug' => { label=>'Enable debugging', + type=>'checkbox' }, +; + +%info = ( + 'svc' => 'svc_www', + 'desc' => 'Real-time export to Plesk managed hosting service', + 'options'=> \%options, + 'notes' => <<'END' +Real-time export to +Plesk managed server. +Requires installation of +Net::Plesk +from CPAN. +END +); + +sub rebless { shift; } + +# experiment: want the status of these right away (don't want account to +# create or whatever and then get error in the queue from dup username or +# something), so no queueing + +sub _export_insert { + my( $self, $www ) = ( shift, shift ); + + my $plesk = new Net::Plesk ( + 'POST' => $self->option('URL'), + ':HTTP_AUTH_LOGIN' => $self->option('login'), + ':HTTP_AUTH_PASSWD' => $self->option('password'), + ); + + my $gcresp = $plesk->client_get( $www->svc_acct->username ); + return $gcresp->errortext + unless $gcresp->is_success; + + unless ($gcresp->id) { + my $cust_main = $www->cust_svc->cust_pkg->cust_main; + $gcresp = $plesk->client_add( $cust_main->name, + $www->svc_acct->username, + $www->svc_acct->_password, + $cust_main->daytime, + $cust_main->fax, + $cust_main->invoicing_list->[0], + $cust_main->address1 . $cust_main->address2, + $cust_main->city, + $cust_main->state, + $cust_main->zip, + $cust_main->country, + ); + return $gcresp->errortext + unless $gcresp->is_success; + } + + $plesk->client_ippool_add_ip ( $gcresp->id, + $www->domain_record->recdata, + ); + + $self->_plesk_command( 'domain_add', + $www->domain_record->svc_domain->domain, + $gcresp->id, + $www->domain_record->recdata, + ); +} + +sub _plesk_command { + my( $self, $method, @args ) = @_; + + local($Net::Plesk::DEBUG) = 1 + if $self->option('debug'); + + my $plesk = new Net::Plesk ( + 'POST' => $self->option('URL'), + ':HTTP_AUTH_LOGIN' => $self->option('login'), + ':HTTP_AUTH_PASSWD' => $self->option('password'), + ); + + my $response = $plesk->$method(@args); + return $response->errortext unless $response->is_success; + ''; + +} + +sub _export_replace { + my( $self, $new, $old ) = (shift, shift, shift); + + return "can't change domain with Plesk" + if $old->domain_record->svc_domain->domain ne + $new->domain_record->svc_domain->domain; + + return "can't change client with Plesk" + if $old->svc_acct->username ne + $new->svc_acct->username; + + return ''; + +} + +sub _export_delete { + my( $self, $www ) = ( shift, shift ); + $self->_plesk_command( 'domain_del', $www->domain_record->svc_domain->domain); +} + +1; +