From 1db61c35afc546c51de4931ced48330c19af21eb Mon Sep 17 00:00:00 2001 From: ivan Date: Fri, 5 Sep 2003 13:18:29 +0000 Subject: [PATCH] add communigate pro export --- FS/FS/part_export.pm | 23 +++++++ FS/FS/part_export/communigate_pro.pm | 113 +++++++++++++++++++++++++++++++++++ 2 files changed, 136 insertions(+) create mode 100644 FS/FS/part_export/communigate_pro.pm diff --git a/FS/FS/part_export.pm b/FS/FS/part_export.pm index 234dfa535..d6422fe16 100644 --- a/FS/FS/part_export.pm +++ b/FS/FS/part_export.pm @@ -741,6 +741,23 @@ tie my %vpopmail_options, 'Tie::IxHash', }, ; +tie my %communigate_pro_options, 'Tie::IxHash', + 'port' => { label=>'Port number', default=>'106', }, + 'login' => { label=>'The administrator account name. The name can contain a domain part.', }, + 'password' => { label=>'The administrator account password.', }, + 'accountType' => { label=>'Type for newly-created accounts', + type=>'select', + options=>[qw( MultiMailbox TextMailbox MailDirMailbox )], + default=>'MultiMailbox', + }, + 'externalFlag' => { label=> 'Create accounts with an external (visible for legacy mailers) INBOX.', + type=>'checkbox', + }, + 'AccessModes' => { label=>'Access modes', + default=>'Mail POP IMAP PWD WebMail WebSite', + }, +; + tie my %bind_options, 'Tie::IxHash', #'machine' => { label=>'named machine' }, 'named_conf' => { label => 'named.conf location', @@ -958,6 +975,12 @@ tie my %forward_shellcommands_options, 'Tie::IxHash', 'notes' => 'Real time export to vpopmail text files. File::Rsync must be installed, and you will need to setup SSH for unattended operation to vpopmail@export.host.', }, + 'communigate_pro' => { + 'desc' => 'Real-time export to a CommuniGate Pro mail server', + 'options' => \%communigate_pro_options, + 'notes' => 'Real time export to a mail server. The CommuniGate Pro Perl Interface must be installed as CGP::CLI.', + }, + }, 'svc_domain' => { diff --git a/FS/FS/part_export/communigate_pro.pm b/FS/FS/part_export/communigate_pro.pm new file mode 100644 index 000000000..bce7f301f --- /dev/null +++ b/FS/FS/part_export/communigate_pro.pm @@ -0,0 +1,113 @@ +package FS::part_export::communigate_pro; + +use vars qw(@ISA); +use FS::part_export; +use FS::queue; + +@ISA = qw(FS::part_export); + +sub rebless { shift; } + +sub _export_insert { + my( $self, $svc_acct ) = (shift, shift); + $self->communigate_pro_queue( $svc_acct->svcnum, 'CreateAccount', + 'accountName' => $svc_acct->email, + 'accountType' => $self->option('accountType'), + 'externalFlag' => $self->option('externalFlag'), + 'AccessModes' => $self->option('AccessModes'), + 'RealName' => $svc_acct->finger, + 'MaxAccountSize' => $svc_acct->quota, + ); +} + +sub _export_replace { + my( $self, $new, $old ) = (shift, shift, shift); + return "can't (yet) change domain with CommuniGate Pro" + if $old->domain ne $new->domain; + return "can't (yet) change username with CommuniGate Pro" + if $old->username ne $new->username; + return "can't (yet) change GECOS with CommuniGate Pro" + if $old->finger ne $new->finger; + return "can't (yet) change quota with CommuniGate Pro" + if $old->quota ne $new->quota; + return '' unless $old->username ne $new->username + || $old->_password ne $new->_password + || $old->finger ne $new->finger + || $old->quota ne $new->quota; + + #my $err_or_queue = $self->communigate_pro_queue( $new->svcnum,'RenameAccount', + # $old->email, $new->email ); + #return $err_or_queue unless ref($err_or_queue); + #my $jobnum = $err_or_queue->jobnum; + + $self->communigate_pro_queue( $new->svcnum, 'SetAccountPassword', + $new->email, $new->_password ) + if $new->_password ne $old->_password; + +} + +sub _export_delete { + my( $self, $svc_acct ) = (shift, shift); + $self->communigate_pro_queue( $svc_acct->svcnum, 'DeleteAccount', + $svc_acct->email, + ); +} + +#sub _export_suspend { +#} + +#sub _export_unsuspend { +#} + +sub communigate_pro_queue { + my( $self, $svcnum, $method ) = (shift, shift, shift); + my $sub = $method eq 'CreateAccount' + ? 'CreateAccount' + : 'communigate_pro_command'; + my $queue = new FS::queue { + 'svcnum' => $svcnum, + 'job' => "FS::part_export::communigate_pro::$sub", + }; + $queue->insert( + $self->machine, + $self->option('port'), + $self->option('login'), + $self->option('password'), + $method, + @_, + ); + +} + +sub CreateAccount { + my( $machine, $port, $login, $password, $method, @args ) = @_; + + my %args = @args; + my $accountName = delete $args{'accountName'}; + my $accountType = delete $args{'accountType'}; + my $externalFlag = delete $args{'externalFlag'}; + $args{'AccessModes'} = [ split(' ', $args{'AccessModes'}) ]; + @args = ( accountName => $accountName, [ settings => \%args ], + accountType => $accountType, externalFlag => $externalFlag, ); + + communigate_pro_command( $machine, $port, $login, $password, $method, @args ); + +} + +sub communigate_pro_command { #subroutine, not method + my( $machine, $port, $login, $password, $method, @args ) = @_; + + eval "use CGP::CLI"; + + my $cli = new CGP::CLI( { + 'PeerAddr' => $machine, + 'PeerPort' => $port, + 'login' => $login, + 'password' => $password, + } ) or die "Can't login to CGPro: $CGP::ERR_STRING\n"; + + $cli->$method(@args) or die "CGPro error: ". $cli->getErrMessage; + + $cli->Logout or die "Can't logout of CGPro: $CGP:ERR_STRING\n"; + +} -- 2.11.0