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;
115 $prefs{'ProntoSkinName'} = $svc_acct->cgp_prontoskinname if $svc_acct->cgp_prontoskinname;
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,
201 'ProntoSkinName' => $svc_domain->acct_def_cgp_prontoskinname,
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;
328 $prefs{'ProntoSkinName'} = $new->cgp_prontoskinname
329 if $old->cgp_prontoskinname ne $new->cgp_prontoskinname;
330 $prefs{'SendMDNMode'} = $new->cgp_sendmdnmode
331 if $old->cgp_sendmdnmode ne $new->cgp_sendmdnmode;
333 my $pref_err = $self->communigate_pro_queue( $new->svcnum,
334 'UpdateAccountPrefs',
335 $self->export_username($new),
338 warn "WARNING: error queueing UpdateAccountPrefs job: $pref_err"
342 if ( $old->cgp_aliases ne $new->cgp_aliases ) {
343 my $error = $self->communigate_pro_queue(
346 $self->export_username($new),
347 [ split(/\s*[,\s]\s*/, $new->cgp_aliases) ],
349 return $error if $error;
356 sub _export_replace_svc_domain {
357 my( $self, $new, $old ) = (shift, shift, shift);
359 if ( $old->domain ne $new->domain ) {
360 my $error = $self->communigate_pro_queue( $new->svcnum, 'RenameDomain',
361 $old->domain, $new->domain,
363 return $error if $error;
366 $settings{'AccountsLimit'} = $new->max_accounts
367 if $old->max_accounts ne $new->max_accounts;
368 $settings{'TrailerText'} = $new->trailer
369 if $old->trailer ne $new->trailer;
370 $settings{'DomainAccessModes'} = $new->cgp_accessmodes
371 if $old->cgp_accessmodes ne $new->cgp_accessmodes;
372 $settings{'AdminDomainName'} =
373 $new->parent_svcnum ? $new->parent_svc_x->domain : ''
374 if $old->parent_svcnum != $new->parent_svcnum;
376 if ( keys %settings ) {
377 my $error = $self->communigate_pro_queue( $new->svcnum,
378 'UpdateDomainSettings',
382 return $error if $error;
385 if ( $old->cgp_aliases ne $new->cgp_aliases ) {
386 my $error = $self->communigate_pro_queue( $new->svcnum,
389 split(/\s*[,\s]\s*/, $new->cgp_aliases),
391 return $error if $error;
394 #below this identical to insert... any value to doing an Update here?
395 #not seeing any big one... i guess it would be nice to avoid the update
396 #when things haven't changed
399 my $def_err = $self->communigate_pro_queue( $new->svcnum,
400 'SetAccountDefaults',
402 'PWDAllowed' => ( $new->acct_def_password_selfchange ? 'YES' : 'NO' ),
403 'PasswordRecovery' => ( $new->acct_def_password_recover ? 'YES' : 'NO' ),
404 'AccessModes' => $new->acct_def_cgp_accessmodes,
405 'MaxAccountSize' => $new->acct_def_quota,
406 'MaxWebSize' => $new->acct_def_file_quota,
407 'MaxWebFile' => $new->acct_def_file_maxnum,
408 'MaxFileSize' => $new->acct_def_file_maxsize,
409 'RulesAllowed' => $new->acct_def_cgp_rulesallowed,
410 'RPOPAllowed' => ( $new->acct_def_cgp_rpopallowed ? 'YES' : 'NO' ),
411 'MailToAll' => ( $new->acct_def_cgp_mailtoall ? 'YES' : 'NO' ),
412 'AddMailTrailer' => ( $new->acct_def_cgp_addmailtrailer ? 'YES' : 'NO' ),
414 warn "WARNING: error queueing SetAccountDefaults job: $def_err"
417 #account defaults prefs
418 my $pref_err = $self->communigate_pro_queue( $new->svcnum,
419 'SetAccountDefaultPrefs',
421 'DeleteMode' => $new->acct_def_cgp_deletemode,
422 'EmptyTrash' => $new->acct_def_cgp_emptytrash,
423 'Language' => $new->acct_def_cgp_language,
424 'TimeZone' => $new->acct_def_cgp_timezone,
425 'SkinName' => $new->acct_def_cgp_skinname,
426 'ProntoSkinName' => $new->acct_def_cgp_prontoskinname,
427 'SendMDNMode' => $new->acct_def_cgp_sendmdnmode,
429 warn "WARNING: error queueing SetAccountDefaultPrefs job: $pref_err"
435 sub _export_replace_svc_forward {
436 my( $self, $new, $old ) = (shift, shift, shift);
438 my $osrc = $old->src || $old->srcsvc_acct->email;
439 my $nsrc = $new->src || $new->srcsvc_acct->email;
440 my $odst = $old->dst || $old->dstsvc_acct->email;
441 my $ndst = $new->dst || $new->dstsvc_acct->email;
443 if ( $odst ne $ndst ) {
445 #no change command, so delete and create (real-time)
446 eval { $self->communigate_pro_runcommand('DeleteForwarder', $osrc) };
448 eval { $self->communigate_pro_runcommand('CreateForwarder', $nsrc, $ndst)};
451 } elsif ( $osrc ne $nsrc ) {
453 #real-time here, presuming CGP does some dup detection?
454 eval { $self->communigate_pro_runcommand( 'RenameForwarder', $osrc, $nsrc)};
458 warn "communigate replace called for svc_forward with no changes\n";#confess
464 sub _export_replace_svc_mailinglist {
465 my( $self, $new, $old ) = (shift, shift, shift);
467 my $oldGroupName = $old->username.'@'.$old->domain;
468 my $newGroupName = $new->username.'@'.$new->domain;
470 if ( $oldGroupName ne $newGroupName ) {
471 eval { $self->communigate_pro_runcommand(
472 'RenameGroup', $oldGroupName, $newGroupName ); };
476 my @members = map $_->email_address,
477 $new->mailinglist->mailinglistmember;
479 #real-time here, presuming CGP does some dup detection
480 eval { $self->communigate_pro_runcommand(
481 'SetGroup', $newGroupName,
482 { 'RealName' => $new->listname,
483 'SetReplyTo' => ( $new->reply_to ? 'YES' : 'NO' ),
484 'RemoveAuthor' => ( $new->remove_from ? 'YES' : 'NO' ),
485 'RejectAuto' => ( $new->reject_auto ? 'YES' : 'NO' ),
486 'RemoveToAndCc' => ( $new->remove_to_and_cc ? 'YES' : 'NO' ),
487 'Members' => \@members,
498 my( $self, $svc_x ) = (shift, shift);
500 my $table = $svc_x->table;
501 my $method = "_export_delete_$table";
502 $self->$method($svc_x, @_);
505 sub _export_delete_svc_acct {
506 my( $self, $svc_acct ) = (shift, shift);
508 $self->communigate_pro_queue( $svc_acct->svcnum, 'DeleteAccount',
509 $self->export_username($svc_acct),
513 sub _export_delete_svc_domain {
514 my( $self, $svc_domain ) = (shift, shift);
516 $self->communigate_pro_queue( $svc_domain->svcnum, 'DeleteDomain',
518 #XXX turn on force option for domain deletion?
522 sub _export_delete_svc_forward {
523 my( $self, $svc_forward ) = (shift, shift);
525 $self->communigate_pro_queue( $svc_forward->svcnum, 'DeleteForwarder',
526 ($svc_forward->src || $svc_forward->srcsvc_acct->email),
530 sub _export_delete_svc_mailinglist {
531 my( $self, $svc_mailinglist ) = (shift, shift);
533 #real-time here, presuming CGP does some dup detection
534 eval { $self->communigate_pro_runcommand(
536 $svc_mailinglist->username.'@'.$svc_mailinglist->domain,
545 sub _export_suspend {
546 my( $self, $svc_x ) = (shift, shift);
548 my $table = $svc_x->table;
549 my $method = "_export_suspend_$table";
550 $self->$method($svc_x, @_);
554 sub _export_suspend_svc_acct {
555 my( $self, $svc_acct ) = (shift, shift);
557 #XXX is this the desired suspnsion action?
559 $self->communigate_pro_queue(
561 'UpdateAccountSettings',
562 $self->export_username($svc_acct),
563 'AccessModes' => 'Mail',
568 sub _export_suspend_svc_domain {
569 my( $self, $svc_domain) = (shift, shift);
571 #XXX domain operations
576 sub _export_unsuspend {
577 my( $self, $svc_x ) = (shift, shift);
579 my $table = $svc_x->table;
580 my $method = "_export_unsuspend_$table";
581 $self->$method($svc_x, @_);
585 sub _export_unsuspend_svc_acct {
586 my( $self, $svc_acct ) = (shift, shift);
588 $self->communigate_pro_queue(
590 'UpdateAccountSettings',
591 $self->export_username($svc_acct),
592 'AccessModes' => ( $svc_acct->cgp_accessmodes
593 || $self->option('AccessModes') ),
598 sub _export_unsuspend_svc_domain {
599 my( $self, $svc_domain) = (shift, shift);
601 #XXX domain operations
606 sub export_mailinglistmember_insert {
607 my( $self, $svc_mailinglist, $mailinglistmember ) = (shift, shift, shift);
608 $svc_mailinglist->replace();
611 sub export_mailinglistmember_replace {
612 my( $self, $svc_mailinglist, $new, $old ) = (shift, shift, shift, shift);
613 die "no way to do this from the UI right now";
616 sub export_mailinglistmember_delete {
617 my( $self, $svc_mailinglist, $mailinglistmember ) = (shift, shift, shift);
618 $svc_mailinglist->replace();
621 sub export_getsettings {
622 my($self, $svc_x) = (shift, shift);
624 my $table = $svc_x->table;
625 my $method = "export_getsettings_$table";
627 $self->can($method) ? $self->$method($svc_x, @_) : '';
631 sub export_getsettings_svc_domain {
632 my($self, $svc_domain, $settingsref, $defaultref ) = @_;
634 my $settings = eval { $self->communigate_pro_runcommand(
640 my $effective_settings = eval { $self->communigate_pro_runcommand(
641 'GetDomainEffectiveSettings',
646 my $acct_defaults = eval { $self->communigate_pro_runcommand(
647 'GetAccountDefaults',
652 my $acct_defaultprefs = eval { $self->communigate_pro_runcommand(
653 'GetAccountDefaultPrefs',
658 %$effective_settings = (
659 %$effective_settings,
660 ( map { ("Acct. Default $_" => $acct_defaults->{$_}); }
661 keys(%$acct_defaults)
663 ( map { ("Acct. Default $_" => $acct_defaultprefs->{$_}); } #diff label??
664 keys(%$acct_defaultprefs)
669 ( map { ("Acct. Default $_" => $acct_defaults->{$_}); }
670 keys(%$acct_defaults)
672 ( map { ("Acct. Default $_" => $acct_defaultprefs->{$_}); } #diff label??
673 keys(%$acct_defaultprefs)
678 my $aliases = eval { $self->communigate_pro_runcommand(
684 $effective_settings->{'Aliases'} = join(', ', @$aliases);
685 $settings->{'Aliases'} = join(', ', @$aliases);
688 #false laziness w/below
690 my %defaults = map { $_ => 1 }
691 grep !exists(${$settings}{$_}), keys %$effective_settings;
693 foreach my $key ( grep ref($effective_settings->{$_}),
694 keys %$effective_settings )
696 my $value = $effective_settings->{$key};
697 if ( ref($value) eq 'ARRAY' ) {
698 $effective_settings->{$key} = join(' ', @$value);
701 warn "serializing ". ref($value). " for table display not yet handled";
705 %{$settingsref} = %$effective_settings;
706 %{$defaultref} = %defaults;
711 sub export_getsettings_svc_acct {
712 my($self, $svc_acct, $settingsref, $defaultref ) = @_;
714 my $settings = eval { $self->communigate_pro_runcommand(
715 'GetAccountSettings',
720 delete($settings->{'Password'});
722 my $effective_settings = eval { $self->communigate_pro_runcommand(
723 'GetAccountEffectiveSettings',
728 delete($effective_settings->{'Password'});
730 #prefs/effectiveprefs too
732 my $prefs = eval { $self->communigate_pro_runcommand(
738 my $effective_prefs = eval { $self->communigate_pro_runcommand(
739 'GetAccountEffectivePrefs',
744 %$effective_settings = ( %$effective_settings,
745 map { ("Pref $_" => $effective_prefs->{$_}); }
746 keys(%$effective_prefs)
748 %$settings = ( %$settings,
749 map { ("Pref $_" => $prefs->{$_}); }
755 my $aliases = eval { $self->communigate_pro_runcommand(
761 $effective_settings->{'Aliases'} = join(', ', @$aliases);
762 $settings->{'Aliases'} = join(', ', @$aliases);
764 #false laziness w/above
766 my %defaults = map { $_ => 1 }
767 grep !exists(${$settings}{$_}), keys %$effective_settings;
769 foreach my $key ( grep ref($effective_settings->{$_}),
770 keys %$effective_settings )
772 my $value = $effective_settings->{$key};
773 if ( ref($value) eq 'ARRAY' ) {
774 $effective_settings->{$key} = join(' ', @$value);
777 warn "serializing ". ref($value). " for table display not yet handled";
781 %{$settingsref} = %$effective_settings;
782 %{$defaultref} = %defaults;
788 sub export_getsettings_svc_mailinglist {
789 my($self, $svc_mailinglist, $settingsref, $defaultref ) = @_;
791 my $settings = eval { $self->communigate_pro_runcommand(
793 $svc_mailinglist->username.'@'.$svc_mailinglist->domain,
797 $settings->{'Members'} = join(', ', @{ $settings->{'Members'} } );
799 %{$settingsref} = %$settings;
804 sub communigate_pro_queue {
805 my( $self, $svcnum, $method ) = (shift, shift, shift);
806 my $jobnum = ''; #don't actually care
807 $self->communigate_pro_queue_dep( \$jobnum, $svcnum, $method, @_);
810 sub communigate_pro_queue_dep {
811 my( $self, $jobnumref, $svcnum, $method ) = splice(@_,0,4);
813 my %kludge_methods = (
814 #'CreateAccount' => 'CreateAccount',
815 'UpdateAccountSettings' => 'UpdateAccountSettings',
816 'UpdateAccountPrefs' => 'cp_Scalar_Hash',
817 #'CreateDomain' => 'cp_Scalar_Hash',
818 #'CreateSharedDomain' => 'cp_Scalar_Hash',
819 'UpdateDomainSettings' => 'cp_Scalar_settingsHash',
820 'SetDomainAliases' => 'cp_Scalar_Array',
821 'SetAccountDefaults' => 'cp_Scalar_settingsHash',
822 'UpdateAccountDefaults' => 'cp_Scalar_settingsHash',
823 'SetAccountDefaultPrefs' => 'cp_Scalar_settingsHash',
824 'UpdateAccountDefaultPrefs' => 'cp_Scalar_settingsHash',
826 my $sub = exists($kludge_methods{$method})
827 ? $kludge_methods{$method}
828 : 'communigate_pro_command';
830 my $queue = new FS::queue {
832 'job' => "FS::part_export::communigate_pro::$sub",
834 my $error = $queue->insert(
836 $self->option('port'),
837 $self->option('login'),
838 $self->option('password'),
842 $$jobnumref = $queue->jobnum unless $error;
847 sub communigate_pro_runcommand {
848 my( $self, $method ) = (shift, shift);
850 communigate_pro_command(
852 $self->option('port'),
853 $self->option('login'),
854 $self->option('password'),
861 #XXX one sub per arg prototype is lame. more magic? i suppose queue needs
862 # to store data strctures properly instead of just an arg list. right.
865 my( $machine, $port, $login, $password, $method, $scalar, %hash ) = @_;
866 my @args = ( $scalar, \%hash );
867 communigate_pro_command( $machine, $port, $login, $password, $method, @args );
870 sub cp_Scalar_Array {
871 my( $machine, $port, $login, $password, $method, $scalar, @array ) = @_;
872 my @args = ( $scalar, \@array );
873 communigate_pro_command( $machine, $port, $login, $password, $method, @args );
877 # my( $machine, $port, $login, $password, $method, %hash ) = @_;
878 # my @args = ( \%hash );
879 # communigate_pro_command( $machine, $port, $login, $password, $method, @args );
882 sub cp_Scalar_settingsHash {
883 my( $machine, $port, $login, $password, $method, $domain, %settings ) = @_;
884 for (qw( AccessModes DomainAccessModes )) {
885 $settings{$_} = [split(' ',$settings{$_})] if $settings{$_};
887 my @args = ( 'domain' => $domain, 'settings' => \%settings );
888 communigate_pro_command( $machine, $port, $login, $password, $method, @args );
892 # my( $machine, $port, $login, $password, $method, %args ) = @_;
893 # my $accountName = delete $args{'accountName'};
894 # my $accountType = delete $args{'accountType'};
895 # my $externalFlag = delete $args{'externalFlag'};
896 # $args{'AccessModes'} = [ split(' ', $args{'AccessModes'}) ];
897 # my @args = ( accountName => $accountName,
898 # accountType => $accountType,
899 # settings => \%args,
901 # #externalFlag => $externalFlag,
902 # push @args, externalFlag => $externalFlag if $externalFlag;
904 # communigate_pro_command( $machine, $port, $login, $password, $method, @args );
908 sub UpdateAccountSettings {
909 my( $machine, $port, $login, $password, $method, $accountName, %args ) = @_;
910 $args{'AccessModes'} = [ split(' ', $args{'AccessModes'}) ];
911 my @args = ( $accountName, \%args );
912 communigate_pro_command( $machine, $port, $login, $password, $method, @args );
915 sub communigate_pro_command { #subroutine, not method
916 my( $machine, $port, $login, $password, $method, @args ) = @_;
921 my $cli = new CGP::CLI( {
922 'PeerAddr' => $machine,
925 'password' => $password,
926 } ) or die "Can't login to CGPro: $CGP::ERR_STRING\n";
928 #warn "$method ". Dumper(@args) if $DEBUG;
930 my $return = $cli->$method(@args)
931 or die "Communigate Pro error: ". $cli->getErrMessage. "\n";
933 $cli->Logout; # or die "Can't logout of CGPro: $CGP::ERR_STRING\n";