1 package FS::part_export::communigate_pro;
3 use vars qw(@ISA %info %options);
8 @ISA = qw(FS::part_export);
10 tie %options, 'Tie::IxHash',
11 'port' => { label=>'Port number', default=>'106', },
12 'login' => { label=>'The administrator account name. The name can contain a domain part.', },
13 'password' => { label=>'The administrator account password.', },
14 'accountType' => { label=>'Type for newly-created accounts',
16 options=>[qw( MultiMailbox TextMailbox MailDirMailbox )],
17 default=>'MultiMailbox',
19 'externalFlag' => { label=> 'Create accounts with an external (visible for legacy mailers) INBOX.',
22 'AccessModes' => { label=>'Access modes',
23 default=>'Mail POP IMAP PWD WebMail WebSite',
29 'desc' => 'Real-time export to a CommuniGate Pro mail server',
30 'options' => \%options,
33 <a href="http://www.stalker.com/CommuniGatePro/">CommuniGate Pro</a>
35 <a href="http://www.stalker.com/CGPerl/">CommuniGate Pro Perl Interface</a>
36 must be installed as CGP::CLI.
40 sub rebless { shift; }
43 my($self, $svc_acct) = (shift, shift);
48 my( $self, $svc_acct ) = (shift, shift);
49 my @options = ( $svc_acct->svcnum, 'CreateAccount',
50 'accountName' => $self->export_username($svc_acct),
51 'accountType' => $self->option('accountType'),
52 'AccessModes' => $self->option('AccessModes'),
53 'RealName' => $svc_acct->finger,
54 'Password' => $svc_acct->_password,
56 push @options, 'MaxAccountSize' => $svc_acct->quota if $svc_acct->quota;
57 push @options, 'externalFlag' => $self->option('externalFlag')
58 if $self->option('externalFlag');
60 $self->communigate_pro_queue( @options );
64 my( $self, $new, $old ) = (shift, shift, shift);
65 return "can't (yet) change username with CommuniGate Pro"
66 if $old->username ne $new->username;
67 return "can't (yet) change domain with CommuniGate Pro"
68 if $self->export_username($old) ne $self->export_username($new);
69 return "can't (yet) change GECOS with CommuniGate Pro"
70 if $old->finger ne $new->finger;
71 return "can't (yet) change quota with CommuniGate Pro"
72 if $old->quota ne $new->quota;
73 return '' unless $old->username ne $new->username
74 || $old->_password ne $new->_password
75 || $old->finger ne $new->finger
76 || $old->quota ne $new->quota;
78 return '' if '*SUSPENDED* '. $old->_password eq $new->_password;
80 #my $err_or_queue = $self->communigate_pro_queue( $new->svcnum,'RenameAccount',
81 # $old->email, $new->email );
82 #return $err_or_queue unless ref($err_or_queue);
83 #my $jobnum = $err_or_queue->jobnum;
85 $self->communigate_pro_queue( $new->svcnum, 'SetAccountPassword',
86 $self->export_username($new), $new->_password )
87 if $new->_password ne $old->_password;
92 my( $self, $svc_acct ) = (shift, shift);
93 $self->communigate_pro_queue( $svc_acct->svcnum, 'DeleteAccount',
94 $self->export_username($svc_acct),
99 my( $self, $svc_acct ) = (shift, shift);
100 $self->communigate_pro_queue( $svc_acct->svcnum, 'UpdateAccountSettings',
101 'accountName' => $self->export_username($svc_acct),
102 'AccessModes' => 'Mail',
106 sub _export_unsuspend {
107 my( $self, $svc_acct ) = (shift, shift);
108 $self->communigate_pro_queue( $svc_acct->svcnum, 'UpdateAccountSettings',
109 'accountName' => $self->export_username($svc_acct),
110 'AccessModes' => $self->option('AccessModes'),
114 sub communigate_pro_queue {
115 my( $self, $svcnum, $method ) = (shift, shift, shift);
116 my @kludge_methods = qw(CreateAccount UpdateAccountSettings);
117 my $sub = 'communigate_pro_command';
118 $sub = $method if grep { $method eq $_ } @kludge_methods;
119 my $queue = new FS::queue {
121 'job' => "FS::part_export::communigate_pro::$sub",
125 $self->option('port'),
126 $self->option('login'),
127 $self->option('password'),
135 my( $machine, $port, $login, $password, $method, %args ) = @_;
136 my $accountName = delete $args{'accountName'};
137 my $accountType = delete $args{'accountType'};
138 my $externalFlag = delete $args{'externalFlag'};
139 $args{'AccessModes'} = [ split(' ', $args{'AccessModes'}) ];
140 my @args = ( accountName => $accountName,
141 accountType => $accountType,
144 #externalFlag => $externalFlag,
145 push @args, externalFlag => $externalFlag if $externalFlag;
147 communigate_pro_command( $machine, $port, $login, $password, $method, @args );
151 sub UpdateAccountSettings {
152 my( $machine, $port, $login, $password, $method, %args ) = @_;
153 my $accountName = delete $args{'accountName'};
154 $args{'AccessModes'} = [ split(' ', $args{'AccessModes'}) ];
155 @args = ( $accountName, \%args );
156 communigate_pro_command( $machine, $port, $login, $password, $method, @args );
159 sub communigate_pro_command { #subroutine, not method
160 my( $machine, $port, $login, $password, $method, @args ) = @_;
164 my $cli = new CGP::CLI( {
165 'PeerAddr' => $machine,
168 'password' => $password,
169 } ) or die "Can't login to CGPro: $CGP::ERR_STRING\n";
171 $cli->$method(@args) or die "CGPro error: ". $cli->getErrMessage;
173 $cli->Logout; # or die "Can't logout of CGPro: $CGP::ERR_STRING\n";