1 package FS::part_export::communigate_pro;
4 use vars qw(@ISA %info %options %quotas $DEBUG);
10 @ISA = qw(FS::part_export);
14 tie %options, 'Tie::IxHash',
15 'port' => { label =>'Port number', default=>'106', },
16 'login' => { label =>'The administrator account name. The name can contain a domain part.', },
17 'password' => { label =>'The administrator account password.', },
18 'accountType' => { label => 'Type for newly-created accounts (default when not specified in service)',
20 options => [qw(MultiMailbox TextMailbox MailDirMailbox AGrade BGrade CGrade)],
21 default => 'MultiMailbox',
23 'externalFlag' => { label => 'Create accounts with an external (visible for legacy mailers) INBOX.',
26 'AccessModes' => { label => 'Access modes (default when not specified in service)',
27 default => 'Mail POP IMAP PWD WebMail WebSite',
29 'create_domain' => { label => 'Domain creation API call',
31 options => [qw( CreateDomain CreateSharedDomain )],
36 'svc' => [qw( svc_acct svc_domain svc_forward svc_mailinglist )],
37 'desc' => 'Real-time export of accounts, domains, mail forwards and mailing lists to a CommuniGate Pro mail server',
38 'options' => \%options,
40 Real time export of accounts, domains, mail forwards and mailing lists to a
41 <a href="http://www.stalker.com/CommuniGatePro/">CommuniGate Pro</a>
43 <a href="http://www.stalker.com/CGPerl/">CommuniGate Pro Perl Interface</a>
44 must be installed as CGP::CLI.
49 'quota' => 'MaxAccountSize',
50 'file_quota' => 'MaxWebSize',
51 'file_maxnum' => 'MaxWebFiles',
52 'file_maxsize' => 'MaxFileSize',
55 sub rebless { shift; }
58 my($self, $svc_acct) = (shift, shift);
63 my( $self, $svc_x ) = (shift, shift);
65 my $table = $svc_x->table;
66 my $method = "_export_insert_$table";
67 $self->$method($svc_x, @_);
70 sub _export_insert_svc_acct {
71 my( $self, $svc_acct ) = (shift, shift);
74 'AccessModes' => [ split(' ', ( $svc_acct->cgp_accessmodes
75 || $self->option('AccessModes') )
78 'RealName' => $svc_acct->finger,
79 'Password' => $svc_acct->_password,
81 'PasswordRecovery' => ($svc_acct->password_recover ? 'YES':'NO'),
83 'RulesAllowed' => $svc_acct->cgp_rulesallowed,
84 'RPOPAllowed' =>($svc_acct->cgp_rpopallowed ?'YES':'NO'),
85 'MailToAll' =>($svc_acct->cgp_mailtoall ?'YES':'NO'),
86 'AddMailTrailer' =>($svc_acct->cgp_addmailtrailer ?'YES':'NO'),
88 map { $quotas{$_} => $svc_acct->$_() }
89 grep $svc_acct->$_(), keys %quotas
91 #XXX phase 3: archive messages, mailing lists
93 my @options = ( 'CreateAccount',
94 'accountName' => $self->export_username($svc_acct),
95 'accountType' => ( $svc_acct->cgp_type
96 || $self->option('accountType') ),
97 'settings' => \%settings
100 push @options, 'externalFlag' => $self->option('externalFlag')
101 if $self->option('externalFlag');
103 #let's do the create realtime too, for much the same reasons, and to avoid
104 #pain of trying to queue w/dep the prefs & aliases
105 eval { $self->communigate_pro_runcommand( @options ) };
110 $prefs{'DeleteMode'} = $svc_acct->cgp_deletemode if $svc_acct->cgp_deletemode;
111 $prefs{'EmptyTrash'} = $svc_acct->cgp_emptytrash if $svc_acct->cgp_emptytrash;
112 $prefs{'Language'} = $svc_acct->cgp_language if $svc_acct->cgp_language;
113 $prefs{'TimeZone'} = $svc_acct->cgp_timezone if $svc_acct->cgp_timezone;
114 $prefs{'SkinName'} = $svc_acct->cgp_skinname if $svc_acct->cgp_skinname;
116 $prefs{'SendMDNMode'} = $svc_acct->cgp_sendmdnmode if $svc_acct->cgp_sendmdnmode;
118 my $pref_err = $self->communigate_pro_queue( $svc_acct->svcnum,
119 'UpdateAccountPrefs',
120 $self->export_username($svc_acct),
123 warn "WARNING: error queueing UpdateAccountPrefs job: $pref_err"
128 if ( $svc_acct->cgp_aliases ) {
129 my $alias_err = $self->communigate_pro_queue( $svc_acct->svcnum,
131 $self->export_username($svc_acct),
132 [ split(/\s*[,\s]\s*/, $svc_acct->cgp_aliases) ],
134 warn "WARNING: error queueing SetAccountAliases job: $alias_err"
142 sub _export_insert_svc_domain {
143 my( $self, $svc_domain ) = (shift, shift);
145 my $create = $self->option('create_domain') || 'CreateDomain';
148 'DomainAccessModes' => [ split(' ', $svc_domain->cgp_accessmodes ) ],
150 $settings{'AccountsLimit'} = $svc_domain->max_accounts
151 if $svc_domain->max_accounts;
152 $settings{'AdminDomainName'} = $svc_domain->parent_svc_x->domain
153 if $svc_domain->parent_svcnum;
154 $settings{'TrailerText'} = $svc_domain->trailer
155 if $svc_domain->trailer;
157 my @options = ( $create, $svc_domain->domain, \%settings );
159 eval { $self->communigate_pro_runcommand( @options ) };
163 if ( $svc_domain->cgp_aliases ) {
164 my $alias_err = $self->communigate_pro_queue( $svc_domain->svcnum,
167 split(/\s*[,\s]\s*/, $svc_domain->cgp_aliases),
169 warn "WARNING: error queueing SetDomainAliases job: $alias_err"
174 my $def_err = $self->communigate_pro_queue( $svc_domain->svcnum,
175 'SetAccountDefaults',
177 'PWDAllowed' =>($svc_domain->acct_def_password_selfchange ? 'YES':'NO'),
178 'PasswordRecovery' => ($svc_domain->acct_def_password_recover ? 'YES':'NO'),
179 'AccessModes' => $svc_domain->acct_def_cgp_accessmodes,
180 'MaxAccountSize' => $svc_domain->acct_def_quota,
181 'MaxWebSize' => $svc_domain->acct_def_file_quota,
182 'MaxWebFile' => $svc_domain->acct_def_file_maxnum,
183 'MaxFileSize' => $svc_domain->acct_def_file_maxsize,
184 'RulesAllowed' => $svc_domain->acct_def_cgp_rulesallowed,
185 'RPOPAllowed' =>($svc_domain->acct_def_cgp_rpopallowed ?'YES':'NO'),
186 'MailToAll' =>($svc_domain->acct_def_cgp_mailtoall ?'YES':'NO'),
187 'AddMailTrailer' =>($svc_domain->acct_def_cgp_addmailtrailer ?'YES':'NO'),
189 warn "WARNING: error queueing SetAccountDefaults job: $def_err"
192 #account defaults prefs
193 my $pref_err = $self->communigate_pro_queue( $svc_domain->svcnum,
194 'SetAccountDefaultPrefs',
196 'DeleteMode' => $svc_domain->acct_def_cgp_deletemode,
197 'EmptyTrash' => $svc_domain->acct_def_cgp_emptytrash,
198 'Language' => $svc_domain->acct_def_cgp_language,
199 'TimeZone' => $svc_domain->acct_def_cgp_timezone,
200 'SkinName' => $svc_domain->acct_def_cgp_skinname,
202 'SendMDNMode' => $svc_domain->acct_def_cgp_sendmdnmode,
204 warn "WARNING: error queueing SetAccountDefaultPrefs job: $pref_err"
211 sub _export_insert_svc_forward {
212 my( $self, $svc_forward ) = (shift, shift);
214 my $src = $svc_forward->src || $svc_forward->srcsvc_acct->email;
215 my $dst = $svc_forward->dst || $svc_forward->dstsvc_acct->email;
217 #real-time here, presuming CGP does some dup detection?
218 eval { $self->communigate_pro_runcommand( 'CreateForwarder', $src, $dst); };
224 sub _export_insert_svc_mailinglist {
225 my( $self, $svc_mlist ) = (shift, shift);
227 my @members = map $_->email_address,
228 $svc_mlist->mailinglist->mailinglistmember;
230 #real-time here, presuming CGP does some dup detection
231 eval { $self->communigate_pro_runcommand(
233 $svc_mlist->username.'@'.$svc_mlist->domain,
234 { 'RealName' => $svc_mlist->listname,
235 'SetReplyTo' => ( $svc_mlist->reply_to ? 'YES' : 'NO' ),
236 'RemoveAuthor' => ( $svc_mlist->remove_from ? 'YES' : 'NO' ),
237 'RejectAuto' => ( $svc_mlist->reject_auto ? 'YES' : 'NO' ),
238 'RemoveToAndCc' => ( $svc_mlist->remove_to_and_cc ? 'YES' : 'NO' ),
239 'Members' => \@members,
249 sub _export_replace {
250 my( $self, $new, $old ) = (shift, shift, shift);
252 my $table = $new->table;
253 my $method = "_export_replace_$table";
254 $self->$method($new, $old, @_);
257 sub _export_replace_svc_acct {
258 my( $self, $new, $old ) = (shift, shift, shift);
260 #let's just do the rename part realtime rather than trying to queue
261 #w/dependencies. we don't want FS winding up out-of-sync with the wrong
262 #username and a queued job anyway. right??
263 if ( $self->export_username($old) ne $self->export_username($new) ) {
264 eval { $self->communigate_pro_runcommand(
266 $self->export_username($old),
267 $self->export_username($new),
272 if ( $new->_password ne $old->_password
273 && '*SUSPENDED* '.$old->_password ne $new->_password
275 $self->communigate_pro_queue( $new->svcnum, 'SetAccountPassword',
276 $self->export_username($new), $new->_password
282 $settings{'RealName'} = $new->finger
283 if $old->finger ne $new->finger;
284 $settings{$quotas{$_}} = $new->$_()
285 foreach grep $old->$_() ne $new->$_(), keys %quotas;
286 $settings{'accountType'} = $new->cgp_type
287 if $old->cgp_type ne $new->cgp_type;
288 $settings{'AccessModes'} = $new->cgp_accessmodes
289 if $old->cgp_accessmodes ne $new->cgp_accessmodes
290 || $old->cgp_type ne $new->cgp_type;
292 $settings{'PasswordRecovery'} = ( $new->password_recover ? 'YES':'NO' )
293 if $old->password_recover ne $new->password_recover;
295 $settings{'RulesAllowed'} = $new->cgp_rulesallowed
296 if $old->cgp_rulesallowed ne $new->cgp_rulesallowed;
297 $settings{'RPOPAllowed'} = ( $new->cgp_rpopallowed ? 'YES':'NO' )
298 if $old->cgp_rpopallowed ne $new->cgp_rpopallowed;
299 $settings{'MailToAll'} = ( $new->cgp_mailtoall ? 'YES':'NO' )
300 if $old->cgp_mailtoall ne $new->cgp_mailtoall;
301 $settings{'AddMailTrailer'} = ( $new->cgp_addmailtrailer ? 'YES':'NO' )
302 if $old->cgp_addmailtrailer ne $new->cgp_addmailtrailer;
304 #XXX phase 3: archive messages, mailing lists
306 if ( keys %settings ) {
307 my $error = $self->communigate_pro_queue(
309 'UpdateAccountSettings',
310 $self->export_username($new),
313 return $error if $error;
318 $prefs{'DeleteMode'} = $new->cgp_deletemode
319 if $old->cgp_deletemode ne $new->cgp_deletemode;
320 $prefs{'EmptyTrash'} = $new->cgp_emptytrash
321 if $old->cgp_emptytrash ne $new->cgp_emptytrash;
322 $prefs{'Language'} = $new->cgp_language
323 if $old->cgp_language ne $new->cgp_language;
324 $prefs{'TimeZone'} = $new->cgp_timezone
325 if $old->cgp_timezone ne $new->cgp_timezone;
326 $prefs{'SkinName'} = $new->cgp_skinname
327 if $old->cgp_skinname ne $new->cgp_skinname;
329 $prefs{'SendMDNMode'} = $new->cgp_sendmdnmode
330 if $old->cgp_sendmdnmode ne $new->cgp_sendmdnmode;
332 my $pref_err = $self->communigate_pro_queue( $new->svcnum,
333 'UpdateAccountPrefs',
334 $self->export_username($new),
337 warn "WARNING: error queueing UpdateAccountPrefs job: $pref_err"
341 if ( $old->cgp_aliases ne $new->cgp_aliases ) {
342 my $error = $self->communigate_pro_queue(
345 $self->export_username($new),
346 [ split(/\s*[,\s]\s*/, $new->cgp_aliases) ],
348 return $error if $error;
355 sub _export_replace_svc_domain {
356 my( $self, $new, $old ) = (shift, shift, shift);
358 if ( $old->domain ne $new->domain ) {
359 my $error = $self->communigate_pro_queue( $new->svcnum, 'RenameDomain',
360 $old->domain, $new->domain,
362 return $error if $error;
365 $settings{'AccountsLimit'} = $new->max_accounts
366 if $old->max_accounts ne $new->max_accounts;
367 $settings{'TrailerText'} = $new->trailer
368 if $old->trailer ne $new->trailer;
369 $settings{'DomainAccessModes'} = $new->cgp_accessmodes
370 if $old->cgp_accessmodes ne $new->cgp_accessmodes;
371 $settings{'AdminDomainName'} =
372 $new->parent_svcnum ? $new->parent_svc_x->domain : ''
373 if $old->parent_svcnum != $new->parent_svcnum;
375 if ( keys %settings ) {
376 my $error = $self->communigate_pro_queue( $new->svcnum,
377 'UpdateDomainSettings',
381 return $error if $error;
384 if ( $old->cgp_aliases ne $new->cgp_aliases ) {
385 my $error = $self->communigate_pro_queue( $new->svcnum,
388 split(/\s*[,\s]\s*/, $new->cgp_aliases),
390 return $error if $error;
393 #below this identical to insert... any value to doing an Update here?
394 #not seeing any big one... i guess it would be nice to avoid the update
395 #when things haven't changed
398 my $def_err = $self->communigate_pro_queue( $new->svcnum,
399 'SetAccountDefaults',
401 'PWDAllowed' => ( $new->acct_def_password_selfchange ? 'YES' : 'NO' ),
402 'PasswordRecovery' => ( $new->acct_def_password_recover ? 'YES' : 'NO' ),
403 'AccessModes' => $new->acct_def_cgp_accessmodes,
404 'MaxAccountSize' => $new->acct_def_quota,
405 'MaxWebSize' => $new->acct_def_file_quota,
406 'MaxWebFile' => $new->acct_def_file_maxnum,
407 'MaxFileSize' => $new->acct_def_file_maxsize,
408 'RulesAllowed' => $new->acct_def_cgp_rulesallowed,
409 'RPOPAllowed' => ( $new->acct_def_cgp_rpopallowed ? 'YES' : 'NO' ),
410 'MailToAll' => ( $new->acct_def_cgp_mailtoall ? 'YES' : 'NO' ),
411 'AddMailTrailer' => ( $new->acct_def_cgp_addmailtrailer ? 'YES' : 'NO' ),
413 warn "WARNING: error queueing SetAccountDefaults job: $def_err"
416 #account defaults prefs
417 my $pref_err = $self->communigate_pro_queue( $new->svcnum,
418 'SetAccountDefaultPrefs',
420 'DeleteMode' => $new->acct_def_cgp_deletemode,
421 'EmptyTrash' => $new->acct_def_cgp_emptytrash,
422 'Language' => $new->acct_def_cgp_language,
423 'TimeZone' => $new->acct_def_cgp_timezone,
424 'SkinName' => $new->acct_def_cgp_skinname,
426 'SendMDNMode' => $new->acct_def_cgp_sendmdnmode,
428 warn "WARNING: error queueing SetAccountDefaultPrefs job: $pref_err"
434 sub _export_replace_svc_forward {
435 my( $self, $new, $old ) = (shift, shift, shift);
437 my $osrc = $old->src || $old->srcsvc_acct->email;
438 my $nsrc = $new->src || $new->srcsvc_acct->email;
439 my $odst = $old->dst || $old->dstsvc_acct->email;
440 my $ndst = $new->dst || $new->dstsvc_acct->email;
442 if ( $odst ne $ndst ) {
444 #no change command, so delete and create (real-time)
445 eval { $self->communigate_pro_runcommand('DeleteForwarder', $osrc) };
447 eval { $self->communigate_pro_runcommand('CreateForwarder', $nsrc, $ndst)};
450 } elsif ( $osrc ne $nsrc ) {
452 #real-time here, presuming CGP does some dup detection?
453 eval { $self->communigate_pro_runcommand( 'RenameForwarder', $osrc, $nsrc)};
457 warn "communigate replace called for svc_forward with no changes\n";#confess
463 sub _export_replace_svc_mailinglist {
464 my( $self, $new, $old ) = (shift, shift, shift);
466 my $oldGroupName = $old->username.'@'.$old->domain;
467 my $newGroupName = $new->username.'@'.$new->domain;
469 if ( $oldGroupName ne $newGroupName ) {
470 eval { $self->communigate_pro_runcommand(
471 'RenameGroup', $oldGroupName, $newGroupName ); };
475 my @members = map $_->email_address,
476 $new->mailinglist->mailinglistmember;
478 #real-time here, presuming CGP does some dup detection
479 eval { $self->communigate_pro_runcommand(
480 'SetGroup', $newGroupName,
481 { 'RealName' => $new->listname,
482 'SetReplyTo' => ( $new->reply_to ? 'YES' : 'NO' ),
483 'RemoveAuthor' => ( $new->remove_from ? 'YES' : 'NO' ),
484 'RejectAuto' => ( $new->reject_auto ? 'YES' : 'NO' ),
485 'RemoveToAndCc' => ( $new->remove_to_and_cc ? 'YES' : 'NO' ),
486 'Members' => \@members,
497 my( $self, $svc_x ) = (shift, shift);
499 my $table = $svc_x->table;
500 my $method = "_export_delete_$table";
501 $self->$method($svc_x, @_);
504 sub _export_delete_svc_acct {
505 my( $self, $svc_acct ) = (shift, shift);
507 $self->communigate_pro_queue( $svc_acct->svcnum, 'DeleteAccount',
508 $self->export_username($svc_acct),
512 sub _export_delete_svc_domain {
513 my( $self, $svc_domain ) = (shift, shift);
515 $self->communigate_pro_queue( $svc_domain->svcnum, 'DeleteDomain',
517 #XXX turn on force option for domain deletion?
521 sub _export_delete_svc_forward {
522 my( $self, $svc_forward ) = (shift, shift);
524 $self->communigate_pro_queue( $svc_forward->svcnum, 'DeleteForwarder',
525 ($svc_forward->src || $svc_forward->srcsvc_acct->email),
529 sub _export_delete_svc_mailinglist {
530 my( $self, $svc_mailinglist ) = (shift, shift);
532 #real-time here, presuming CGP does some dup detection
533 eval { $self->communigate_pro_runcommand(
535 $svc_mailinglist->username.'@'.$svc_mailinglist->domain,
544 sub _export_suspend {
545 my( $self, $svc_x ) = (shift, shift);
547 my $table = $svc_x->table;
548 my $method = "_export_suspend_$table";
549 $self->$method($svc_x, @_);
553 sub _export_suspend_svc_acct {
554 my( $self, $svc_acct ) = (shift, shift);
556 #XXX is this the desired suspnsion action?
558 $self->communigate_pro_queue(
560 'UpdateAccountSettings',
561 $self->export_username($svc_acct),
562 'AccessModes' => 'Mail',
567 sub _export_suspend_svc_domain {
568 my( $self, $svc_domain) = (shift, shift);
570 #XXX domain operations
575 sub _export_unsuspend {
576 my( $self, $svc_x ) = (shift, shift);
578 my $table = $svc_x->table;
579 my $method = "_export_unsuspend_$table";
580 $self->$method($svc_x, @_);
584 sub _export_unsuspend_svc_acct {
585 my( $self, $svc_acct ) = (shift, shift);
587 $self->communigate_pro_queue(
589 'UpdateAccountSettings',
590 $self->export_username($svc_acct),
591 'AccessModes' => ( $svc_acct->cgp_accessmodes
592 || $self->option('AccessModes') ),
597 sub _export_unsuspend_svc_domain {
598 my( $self, $svc_domain) = (shift, shift);
600 #XXX domain operations
605 sub export_mailinglistmember_insert {
606 my( $self, $svc_mailinglist, $mailinglistmember ) = (shift, shift, shift);
607 $svc_mailinglist->replace();
610 sub export_mailinglistmember_replace {
611 my( $self, $svc_mailinglist, $new, $old ) = (shift, shift, shift, shift);
612 die "no way to do this from the UI right now";
615 sub export_mailinglistmember_delete {
616 my( $self, $svc_mailinglist, $mailinglistmember ) = (shift, shift, shift);
617 $svc_mailinglist->replace();
620 sub export_getsettings {
621 my($self, $svc_x) = (shift, shift);
623 my $table = $svc_x->table;
624 my $method = "export_getsettings_$table";
626 $self->can($method) ? $self->$method($svc_x, @_) : '';
630 sub export_getsettings_svc_domain {
631 my($self, $svc_domain, $settingsref, $defaultref ) = @_;
633 my $settings = eval { $self->communigate_pro_runcommand(
639 my $effective_settings = eval { $self->communigate_pro_runcommand(
640 'GetDomainEffectiveSettings',
645 my $acct_defaults = eval { $self->communigate_pro_runcommand(
646 'GetAccountDefaults',
651 my $acct_defaultprefs = eval { $self->communigate_pro_runcommand(
652 'GetAccountDefaultPrefs',
657 %$effective_settings = (
658 %$effective_settings,
659 ( map { ("Acct. Default $_" => $acct_defaults->{$_}); }
660 keys(%$acct_defaults)
662 ( map { ("Acct. Default $_" => $acct_defaultprefs->{$_}); } #diff label??
663 keys(%$acct_defaultprefs)
668 ( map { ("Acct. Default $_" => $acct_defaults->{$_}); }
669 keys(%$acct_defaults)
671 ( map { ("Acct. Default $_" => $acct_defaultprefs->{$_}); } #diff label??
672 keys(%$acct_defaultprefs)
677 my $aliases = eval { $self->communigate_pro_runcommand(
683 $effective_settings->{'Aliases'} = join(', ', @$aliases);
684 $settings->{'Aliases'} = join(', ', @$aliases);
687 #false laziness w/below
689 my %defaults = map { $_ => 1 }
690 grep !exists(${$settings}{$_}), keys %$effective_settings;
692 foreach my $key ( grep ref($effective_settings->{$_}),
693 keys %$effective_settings )
695 my $value = $effective_settings->{$key};
696 if ( ref($value) eq 'ARRAY' ) {
697 $effective_settings->{$key} = join(' ', @$value);
700 warn "serializing ". ref($value). " for table display not yet handled";
704 %{$settingsref} = %$effective_settings;
705 %{$defaultref} = %defaults;
710 sub export_getsettings_svc_acct {
711 my($self, $svc_acct, $settingsref, $defaultref ) = @_;
713 my $settings = eval { $self->communigate_pro_runcommand(
714 'GetAccountSettings',
719 delete($settings->{'Password'});
721 my $effective_settings = eval { $self->communigate_pro_runcommand(
722 'GetAccountEffectiveSettings',
727 delete($effective_settings->{'Password'});
729 #prefs/effectiveprefs too
731 my $prefs = eval { $self->communigate_pro_runcommand(
737 my $effective_prefs = eval { $self->communigate_pro_runcommand(
738 'GetAccountEffectivePrefs',
743 %$effective_settings = ( %$effective_settings,
744 map { ("Pref $_" => $effective_prefs->{$_}); }
745 keys(%$effective_prefs)
747 %$settings = ( %$settings,
748 map { ("Pref $_" => $prefs->{$_}); }
754 my $aliases = eval { $self->communigate_pro_runcommand(
760 $effective_settings->{'Aliases'} = join(', ', @$aliases);
761 $settings->{'Aliases'} = join(', ', @$aliases);
763 #false laziness w/above
765 my %defaults = map { $_ => 1 }
766 grep !exists(${$settings}{$_}), keys %$effective_settings;
768 foreach my $key ( grep ref($effective_settings->{$_}),
769 keys %$effective_settings )
771 my $value = $effective_settings->{$key};
772 if ( ref($value) eq 'ARRAY' ) {
773 $effective_settings->{$key} = join(' ', @$value);
776 warn "serializing ". ref($value). " for table display not yet handled";
780 %{$settingsref} = %$effective_settings;
781 %{$defaultref} = %defaults;
787 sub export_getsettings_svc_mailinglist {
788 my($self, $svc_mailinglist, $settingsref, $defaultref ) = @_;
790 my $settings = eval { $self->communigate_pro_runcommand(
792 $svc_mailinglist->username.'@'.$svc_mailinglist->domain,
796 $settings->{'Members'} = join(', ', @{ $settings->{'Members'} } );
798 %{$settingsref} = %$settings;
803 sub communigate_pro_queue {
804 my( $self, $svcnum, $method ) = (shift, shift, shift);
805 my $jobnum = ''; #don't actually care
806 $self->communigate_pro_queue_dep( \$jobnum, $svcnum, $method, @_);
809 sub communigate_pro_queue_dep {
810 my( $self, $jobnumref, $svcnum, $method ) = splice(@_,0,4);
812 my %kludge_methods = (
813 #'CreateAccount' => 'CreateAccount',
814 'UpdateAccountSettings' => 'UpdateAccountSettings',
815 'UpdateAccountPrefs' => 'cp_Scalar_Hash',
816 #'CreateDomain' => 'cp_Scalar_Hash',
817 #'CreateSharedDomain' => 'cp_Scalar_Hash',
818 'UpdateDomainSettings' => 'cp_Scalar_settingsHash',
819 'SetDomainAliases' => 'cp_Scalar_Array',
820 'SetAccountDefaults' => 'cp_Scalar_settingsHash',
821 'UpdateAccountDefaults' => 'cp_Scalar_settingsHash',
822 'SetAccountDefaultPrefs' => 'cp_Scalar_settingsHash',
823 'UpdateAccountDefaultPrefs' => 'cp_Scalar_settingsHash',
825 my $sub = exists($kludge_methods{$method})
826 ? $kludge_methods{$method}
827 : 'communigate_pro_command';
829 my $queue = new FS::queue {
831 'job' => "FS::part_export::communigate_pro::$sub",
833 my $error = $queue->insert(
835 $self->option('port'),
836 $self->option('login'),
837 $self->option('password'),
841 $$jobnumref = $queue->jobnum unless $error;
846 sub communigate_pro_runcommand {
847 my( $self, $method ) = (shift, shift);
849 communigate_pro_command(
851 $self->option('port'),
852 $self->option('login'),
853 $self->option('password'),
860 #XXX one sub per arg prototype is lame. more magic? i suppose queue needs
861 # to store data strctures properly instead of just an arg list. right.
864 my( $machine, $port, $login, $password, $method, $scalar, %hash ) = @_;
865 my @args = ( $scalar, \%hash );
866 communigate_pro_command( $machine, $port, $login, $password, $method, @args );
869 sub cp_Scalar_Array {
870 my( $machine, $port, $login, $password, $method, $scalar, @array ) = @_;
871 my @args = ( $scalar, \@array );
872 communigate_pro_command( $machine, $port, $login, $password, $method, @args );
876 # my( $machine, $port, $login, $password, $method, %hash ) = @_;
877 # my @args = ( \%hash );
878 # communigate_pro_command( $machine, $port, $login, $password, $method, @args );
881 sub cp_Scalar_settingsHash {
882 my( $machine, $port, $login, $password, $method, $domain, %settings ) = @_;
883 for (qw( AccessModes DomainAccessModes )) {
884 $settings{$_} = [split(' ',$settings{$_})] if $settings{$_};
886 my @args = ( 'domain' => $domain, 'settings' => \%settings );
887 communigate_pro_command( $machine, $port, $login, $password, $method, @args );
891 # my( $machine, $port, $login, $password, $method, %args ) = @_;
892 # my $accountName = delete $args{'accountName'};
893 # my $accountType = delete $args{'accountType'};
894 # my $externalFlag = delete $args{'externalFlag'};
895 # $args{'AccessModes'} = [ split(' ', $args{'AccessModes'}) ];
896 # my @args = ( accountName => $accountName,
897 # accountType => $accountType,
898 # settings => \%args,
900 # #externalFlag => $externalFlag,
901 # push @args, externalFlag => $externalFlag if $externalFlag;
903 # communigate_pro_command( $machine, $port, $login, $password, $method, @args );
907 sub UpdateAccountSettings {
908 my( $machine, $port, $login, $password, $method, $accountName, %args ) = @_;
909 $args{'AccessModes'} = [ split(' ', $args{'AccessModes'}) ];
910 my @args = ( $accountName, \%args );
911 communigate_pro_command( $machine, $port, $login, $password, $method, @args );
914 sub communigate_pro_command { #subroutine, not method
915 my( $machine, $port, $login, $password, $method, @args ) = @_;
920 my $cli = new CGP::CLI( {
921 'PeerAddr' => $machine,
924 'password' => $password,
925 } ) or die "Can't login to CGPro: $CGP::ERR_STRING\n";
927 #warn "$method ". Dumper(@args) if $DEBUG;
929 my $return = $cli->$method(@args)
930 or die "Communigate Pro error: ". $cli->getErrMessage. "\n";
932 $cli->Logout; # or die "Can't logout of CGPro: $CGP::ERR_STRING\n";