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 'ArchiveMessagesAfter' => $svc_acct->cgp_archiveafter,
90 map { $quotas{$_} => $svc_acct->$_() }
91 grep $svc_acct->$_(), keys %quotas
93 #XXX phase 3: mailing lists
95 my @options = ( 'CreateAccount',
96 'accountName' => $self->export_username($svc_acct),
97 'accountType' => ( $svc_acct->cgp_type
98 || $self->option('accountType') ),
99 'settings' => \%settings
102 push @options, 'externalFlag' => $self->option('externalFlag')
103 if $self->option('externalFlag');
105 #let's do the create realtime too, for much the same reasons, and to avoid
106 #pain of trying to queue w/dep the prefs & aliases
107 eval { $self->communigate_pro_runcommand( @options ) };
112 $prefs{'DeleteMode'} = $svc_acct->cgp_deletemode if $svc_acct->cgp_deletemode;
113 $prefs{'EmptyTrash'} = $svc_acct->cgp_emptytrash if $svc_acct->cgp_emptytrash;
114 $prefs{'Language'} = $svc_acct->cgp_language if $svc_acct->cgp_language;
115 $prefs{'TimeZone'} = $svc_acct->cgp_timezone if $svc_acct->cgp_timezone;
116 $prefs{'SkinName'} = $svc_acct->cgp_skinname if $svc_acct->cgp_skinname;
117 $prefs{'ProntoSkinName'} = $svc_acct->cgp_prontoskinname if $svc_acct->cgp_prontoskinname;
118 $prefs{'SendMDNMode'} = $svc_acct->cgp_sendmdnmode if $svc_acct->cgp_sendmdnmode;
120 my $pref_err = $self->communigate_pro_queue( $svc_acct->svcnum,
121 'UpdateAccountPrefs',
122 $self->export_username($svc_acct),
125 warn "WARNING: error queueing UpdateAccountPrefs job: $pref_err"
130 if ( $svc_acct->cgp_aliases ) {
131 my $alias_err = $self->communigate_pro_queue( $svc_acct->svcnum,
133 $self->export_username($svc_acct),
134 [ split(/\s*[,\s]\s*/, $svc_acct->cgp_aliases) ],
136 warn "WARNING: error queueing SetAccountAliases job: $alias_err"
140 my $rule_error = $self->communigate_pro_queue(
142 'SetAccountMailRules',
143 $self->export_username($svc_acct),
144 $svc_acct->cgp_rule_arrayref,
146 warn "WARNING: error queueing SetAccountMailRules job: $rule_error"
149 my $rpop_error = $self->communigate_pro_queue(
152 $self->export_username($svc_acct),
153 $svc_acct->cgp_rpop_hashref,
155 warn "WARNING: error queueing SetAccountMailRPOPs job: $rpop_error"
162 sub _export_insert_svc_domain {
163 my( $self, $svc_domain ) = (shift, shift);
165 my $create = $self->option('create_domain') || 'CreateDomain';
168 'DomainAccessModes' => [ split(' ', $svc_domain->cgp_accessmodes ) ],
170 $settings{'AccountsLimit'} = $svc_domain->max_accounts
171 if $svc_domain->max_accounts;
172 $settings{'AdminDomainName'} = $svc_domain->parent_svc_x->domain
173 if $svc_domain->parent_svcnum;
174 $settings{'TrailerText'} = $svc_domain->trailer
175 if $svc_domain->trailer;
177 my @options = ( $create, $svc_domain->domain, \%settings );
179 eval { $self->communigate_pro_runcommand( @options ) };
183 if ( $svc_domain->cgp_aliases ) {
184 my $alias_err = $self->communigate_pro_queue( $svc_domain->svcnum,
187 split(/\s*[,\s]\s*/, $svc_domain->cgp_aliases),
189 warn "WARNING: error queueing SetDomainAliases job: $alias_err"
194 my $def_err = $self->communigate_pro_queue( $svc_domain->svcnum,
195 'SetAccountDefaults',
197 'PWDAllowed' =>($svc_domain->acct_def_password_selfchange ? 'YES':'NO'),
198 'PasswordRecovery' => ($svc_domain->acct_def_password_recover ? 'YES':'NO'),
199 'AccessModes' => $svc_domain->acct_def_cgp_accessmodes,
200 'MaxAccountSize' => $svc_domain->acct_def_quota,
201 'MaxWebSize' => $svc_domain->acct_def_file_quota,
202 'MaxWebFile' => $svc_domain->acct_def_file_maxnum,
203 'MaxFileSize' => $svc_domain->acct_def_file_maxsize,
204 'RulesAllowed' => $svc_domain->acct_def_cgp_rulesallowed,
205 'RPOPAllowed' =>($svc_domain->acct_def_cgp_rpopallowed ?'YES':'NO'),
206 'MailToAll' =>($svc_domain->acct_def_cgp_mailtoall ?'YES':'NO'),
207 'AddMailTrailer' =>($svc_domain->acct_def_cgp_addmailtrailer ?'YES':'NO'),
208 'ArchiveMessagesAfter' => $svc_domain->acct_def_cgp_archiveafter,
210 warn "WARNING: error queueing SetAccountDefaults job: $def_err"
213 #account defaults prefs
214 my $pref_err = $self->communigate_pro_queue( $svc_domain->svcnum,
215 'SetAccountDefaultPrefs',
217 'DeleteMode' => $svc_domain->acct_def_cgp_deletemode,
218 'EmptyTrash' => $svc_domain->acct_def_cgp_emptytrash,
219 'Language' => $svc_domain->acct_def_cgp_language,
220 'TimeZone' => $svc_domain->acct_def_cgp_timezone,
221 'SkinName' => $svc_domain->acct_def_cgp_skinname,
222 'ProntoSkinName' => $svc_domain->acct_def_cgp_prontoskinname,
223 'SendMDNMode' => $svc_domain->acct_def_cgp_sendmdnmode,
225 warn "WARNING: error queueing SetAccountDefaultPrefs job: $pref_err"
228 my $rule_error = $self->communigate_pro_queue(
230 'SetDomainMailRules',
232 $svc_domain->cgp_rule_arrayref,
234 warn "WARNING: error queueing SetDomainMailRules job: $rule_error"
241 sub _export_insert_svc_forward {
242 my( $self, $svc_forward ) = (shift, shift);
244 my $src = $svc_forward->src || $svc_forward->srcsvc_acct->email;
245 my $dst = $svc_forward->dst || $svc_forward->dstsvc_acct->email;
247 #real-time here, presuming CGP does some dup detection?
248 eval { $self->communigate_pro_runcommand( 'CreateForwarder', $src, $dst); };
254 sub _export_insert_svc_mailinglist {
255 my( $self, $svc_mlist ) = (shift, shift);
257 my @members = map $_->email_address,
258 $svc_mlist->mailinglist->mailinglistmember;
260 #real-time here, presuming CGP does some dup detection
261 eval { $self->communigate_pro_runcommand(
263 $svc_mlist->username.'@'.$svc_mlist->domain,
264 { 'RealName' => $svc_mlist->listname,
265 'SetReplyTo' => ( $svc_mlist->reply_to ? 'YES' : 'NO' ),
266 'RemoveAuthor' => ( $svc_mlist->remove_from ? 'YES' : 'NO' ),
267 'RejectAuto' => ( $svc_mlist->reject_auto ? 'YES' : 'NO' ),
268 'RemoveToAndCc' => ( $svc_mlist->remove_to_and_cc ? 'YES' : 'NO' ),
269 'Members' => \@members,
279 sub _export_replace {
280 my( $self, $new, $old ) = (shift, shift, shift);
282 my $table = $new->table;
283 my $method = "_export_replace_$table";
284 $self->$method($new, $old, @_);
287 sub _export_replace_svc_acct {
288 my( $self, $new, $old ) = (shift, shift, shift);
290 #let's just do the rename part realtime rather than trying to queue
291 #w/dependencies. we don't want FS winding up out-of-sync with the wrong
292 #username and a queued job anyway. right??
293 if ( $self->export_username($old) ne $self->export_username($new) ) {
294 eval { $self->communigate_pro_runcommand(
296 $self->export_username($old),
297 $self->export_username($new),
302 if ( $new->_password ne $old->_password
303 && '*SUSPENDED* '.$old->_password ne $new->_password
305 $self->communigate_pro_queue( $new->svcnum, 'SetAccountPassword',
306 $self->export_username($new), $new->_password
312 $settings{'RealName'} = $new->finger
313 if $old->finger ne $new->finger;
314 $settings{$quotas{$_}} = $new->$_()
315 foreach grep $old->$_() ne $new->$_(), keys %quotas;
316 $settings{'accountType'} = $new->cgp_type
317 if $old->cgp_type ne $new->cgp_type;
318 $settings{'AccessModes'} = $new->cgp_accessmodes
319 if $old->cgp_accessmodes ne $new->cgp_accessmodes
320 || $old->cgp_type ne $new->cgp_type;
322 $settings{'PasswordRecovery'} = ( $new->password_recover ? 'YES':'NO' )
323 if $old->password_recover ne $new->password_recover;
325 $settings{'RulesAllowed'} = $new->cgp_rulesallowed
326 if $old->cgp_rulesallowed ne $new->cgp_rulesallowed;
327 $settings{'RPOPAllowed'} = ( $new->cgp_rpopallowed ? 'YES':'NO' )
328 if $old->cgp_rpopallowed ne $new->cgp_rpopallowed;
329 $settings{'MailToAll'} = ( $new->cgp_mailtoall ? 'YES':'NO' )
330 if $old->cgp_mailtoall ne $new->cgp_mailtoall;
331 $settings{'AddMailTrailer'} = ( $new->cgp_addmailtrailer ? 'YES':'NO' )
332 if $old->cgp_addmailtrailer ne $new->cgp_addmailtrailer;
333 $settings{'ArchiveMessagesAfter'} = $new->cgp_archiveafter
334 if $old->cgp_archiveafter ne $new->cgp_archiveafter;
336 #XXX phase 3: mailing lists
338 if ( keys %settings ) {
339 my $error = $self->communigate_pro_queue(
341 'UpdateAccountSettings',
342 $self->export_username($new),
345 return $error if $error;
350 $prefs{'DeleteMode'} = $new->cgp_deletemode
351 if $old->cgp_deletemode ne $new->cgp_deletemode;
352 $prefs{'EmptyTrash'} = $new->cgp_emptytrash
353 if $old->cgp_emptytrash ne $new->cgp_emptytrash;
354 $prefs{'Language'} = $new->cgp_language
355 if $old->cgp_language ne $new->cgp_language;
356 $prefs{'TimeZone'} = $new->cgp_timezone
357 if $old->cgp_timezone ne $new->cgp_timezone;
358 $prefs{'SkinName'} = $new->cgp_skinname
359 if $old->cgp_skinname ne $new->cgp_skinname;
360 $prefs{'ProntoSkinName'} = $new->cgp_prontoskinname
361 if $old->cgp_prontoskinname ne $new->cgp_prontoskinname;
362 $prefs{'SendMDNMode'} = $new->cgp_sendmdnmode
363 if $old->cgp_sendmdnmode ne $new->cgp_sendmdnmode;
365 my $pref_err = $self->communigate_pro_queue( $new->svcnum,
366 'UpdateAccountPrefs',
367 $self->export_username($new),
370 warn "WARNING: error queueing UpdateAccountPrefs job: $pref_err"
374 if ( $old->cgp_aliases ne $new->cgp_aliases ) {
375 my $error = $self->communigate_pro_queue(
378 $self->export_username($new),
379 [ split(/\s*[,\s]\s*/, $new->cgp_aliases) ],
381 return $error if $error;
384 my $rule_error = $self->communigate_pro_queue(
386 'SetAccountMailRules',
387 $self->export_username($new),
388 $new->cgp_rule_arrayref,
390 warn "WARNING: error queueing SetAccountMailRules job: $rule_error"
393 my $rpop_error = $self->communigate_pro_queue(
396 $self->export_username($new),
397 $new->cgp_rpop_hashref,
399 warn "WARNING: error queueing SetAccountMailRPOPs job: $rpop_error"
406 sub _export_replace_svc_domain {
407 my( $self, $new, $old ) = (shift, shift, shift);
409 #let's just do the rename part realtime rather than trying to queue
410 #w/dependencies. we don't want FS winding up out-of-sync with the wrong
411 #username and a queued job anyway. right??
412 if ( $old->domain ne $new->domain ) {
413 eval { $self->communigate_pro_runcommand(
414 'RenameDomain', $old->domain, $new->domain,
420 $settings{'AccountsLimit'} = $new->max_accounts
421 if $old->max_accounts ne $new->max_accounts;
422 $settings{'TrailerText'} = $new->trailer
423 if $old->trailer ne $new->trailer;
424 $settings{'DomainAccessModes'} = $new->cgp_accessmodes
425 if $old->cgp_accessmodes ne $new->cgp_accessmodes;
426 $settings{'AdminDomainName'} =
427 $new->parent_svcnum ? $new->parent_svc_x->domain : ''
428 if $old->parent_svcnum != $new->parent_svcnum;
430 if ( keys %settings ) {
431 my $error = $self->communigate_pro_queue( $new->svcnum,
432 'UpdateDomainSettings',
436 return $error if $error;
439 if ( $old->cgp_aliases ne $new->cgp_aliases ) {
440 my $error = $self->communigate_pro_queue( $new->svcnum,
443 split(/\s*[,\s]\s*/, $new->cgp_aliases),
445 return $error if $error;
448 #below this identical to insert... any value to doing an Update here?
449 #not seeing any big one... i guess it would be nice to avoid the update
450 #when things haven't changed
453 my $def_err = $self->communigate_pro_queue( $new->svcnum,
454 'SetAccountDefaults',
456 'PWDAllowed' => ( $new->acct_def_password_selfchange ? 'YES' : 'NO' ),
457 'PasswordRecovery' => ( $new->acct_def_password_recover ? 'YES' : 'NO' ),
458 'AccessModes' => $new->acct_def_cgp_accessmodes,
459 'MaxAccountSize' => $new->acct_def_quota,
460 'MaxWebSize' => $new->acct_def_file_quota,
461 'MaxWebFile' => $new->acct_def_file_maxnum,
462 'MaxFileSize' => $new->acct_def_file_maxsize,
463 'RulesAllowed' => $new->acct_def_cgp_rulesallowed,
464 'RPOPAllowed' => ( $new->acct_def_cgp_rpopallowed ? 'YES' : 'NO' ),
465 'MailToAll' => ( $new->acct_def_cgp_mailtoall ? 'YES' : 'NO' ),
466 'AddMailTrailer' => ( $new->acct_def_cgp_addmailtrailer ? 'YES' : 'NO' ),
467 'ArchiveMessagesAfter' => $new->acct_def_cgp_archiveafter,
469 warn "WARNING: error queueing SetAccountDefaults job: $def_err"
472 #account defaults prefs
473 my $pref_err = $self->communigate_pro_queue( $new->svcnum,
474 'SetAccountDefaultPrefs',
476 'DeleteMode' => $new->acct_def_cgp_deletemode,
477 'EmptyTrash' => $new->acct_def_cgp_emptytrash,
478 'Language' => $new->acct_def_cgp_language,
479 'TimeZone' => $new->acct_def_cgp_timezone,
480 'SkinName' => $new->acct_def_cgp_skinname,
481 'ProntoSkinName' => $new->acct_def_cgp_prontoskinname,
482 'SendMDNMode' => $new->acct_def_cgp_sendmdnmode,
484 warn "WARNING: error queueing SetAccountDefaultPrefs job: $pref_err"
487 my $rule_error = $self->communigate_pro_queue(
489 'SetDomainMailRules',
491 $new->cgp_rule_arrayref,
493 warn "WARNING: error queueing SetDomainMailRules job: $rule_error"
499 sub _export_replace_svc_forward {
500 my( $self, $new, $old ) = (shift, shift, shift);
502 my $osrc = $old->src || $old->srcsvc_acct->email;
503 my $nsrc = $new->src || $new->srcsvc_acct->email;
504 my $odst = $old->dst || $old->dstsvc_acct->email;
505 my $ndst = $new->dst || $new->dstsvc_acct->email;
507 if ( $odst ne $ndst ) {
509 #no change command, so delete and create (real-time)
510 eval { $self->communigate_pro_runcommand('DeleteForwarder', $osrc) };
512 eval { $self->communigate_pro_runcommand('CreateForwarder', $nsrc, $ndst)};
515 } elsif ( $osrc ne $nsrc ) {
517 #real-time here, presuming CGP does some dup detection?
518 eval { $self->communigate_pro_runcommand( 'RenameForwarder', $osrc, $nsrc)};
522 warn "communigate replace called for svc_forward with no changes\n";#confess
528 sub _export_replace_svc_mailinglist {
529 my( $self, $new, $old ) = (shift, shift, shift);
531 my $oldGroupName = $old->username.'@'.$old->domain;
532 my $newGroupName = $new->username.'@'.$new->domain;
534 if ( $oldGroupName ne $newGroupName ) {
535 eval { $self->communigate_pro_runcommand(
536 'RenameGroup', $oldGroupName, $newGroupName ); };
540 my @members = map $_->email_address,
541 $new->mailinglist->mailinglistmember;
543 #real-time here, presuming CGP does some dup detection
544 eval { $self->communigate_pro_runcommand(
545 'SetGroup', $newGroupName,
546 { 'RealName' => $new->listname,
547 'SetReplyTo' => ( $new->reply_to ? 'YES' : 'NO' ),
548 'RemoveAuthor' => ( $new->remove_from ? 'YES' : 'NO' ),
549 'RejectAuto' => ( $new->reject_auto ? 'YES' : 'NO' ),
550 'RemoveToAndCc' => ( $new->remove_to_and_cc ? 'YES' : 'NO' ),
551 'Members' => \@members,
562 my( $self, $svc_x ) = (shift, shift);
564 my $table = $svc_x->table;
565 my $method = "_export_delete_$table";
566 $self->$method($svc_x, @_);
569 sub _export_delete_svc_acct {
570 my( $self, $svc_acct ) = (shift, shift);
572 $self->communigate_pro_queue( $svc_acct->svcnum, 'DeleteAccount',
573 $self->export_username($svc_acct),
577 sub _export_delete_svc_domain {
578 my( $self, $svc_domain ) = (shift, shift);
580 $self->communigate_pro_queue( $svc_domain->svcnum, 'DeleteDomain',
582 #XXX turn on force option for domain deletion?
586 sub _export_delete_svc_forward {
587 my( $self, $svc_forward ) = (shift, shift);
589 $self->communigate_pro_queue( $svc_forward->svcnum, 'DeleteForwarder',
590 ($svc_forward->src || $svc_forward->srcsvc_acct->email),
594 sub _export_delete_svc_mailinglist {
595 my( $self, $svc_mailinglist ) = (shift, shift);
597 #real-time here, presuming CGP does some dup detection
598 eval { $self->communigate_pro_runcommand(
600 $svc_mailinglist->username.'@'.$svc_mailinglist->domain,
609 sub _export_suspend {
610 my( $self, $svc_x ) = (shift, shift);
612 my $table = $svc_x->table;
613 my $method = "_export_suspend_$table";
614 $self->$method($svc_x, @_);
618 sub _export_suspend_svc_acct {
619 my( $self, $svc_acct ) = (shift, shift);
621 #XXX is this the desired suspnsion action?
623 $self->communigate_pro_queue(
625 'UpdateAccountSettings',
626 $self->export_username($svc_acct),
627 'AccessModes' => 'Mail',
632 sub _export_suspend_svc_domain {
633 my( $self, $svc_domain) = (shift, shift);
635 #XXX domain operations
640 sub _export_unsuspend {
641 my( $self, $svc_x ) = (shift, shift);
643 my $table = $svc_x->table;
644 my $method = "_export_unsuspend_$table";
645 $self->$method($svc_x, @_);
649 sub _export_unsuspend_svc_acct {
650 my( $self, $svc_acct ) = (shift, shift);
652 $self->communigate_pro_queue(
654 'UpdateAccountSettings',
655 $self->export_username($svc_acct),
656 'AccessModes' => ( $svc_acct->cgp_accessmodes
657 || $self->option('AccessModes') ),
662 sub _export_unsuspend_svc_domain {
663 my( $self, $svc_domain) = (shift, shift);
665 #XXX domain operations
670 sub export_mailinglistmember_insert {
671 my( $self, $svc_mailinglist, $mailinglistmember ) = (shift, shift, shift);
672 $svc_mailinglist->replace();
675 sub export_mailinglistmember_replace {
676 my( $self, $svc_mailinglist, $new, $old ) = (shift, shift, shift, shift);
677 die "no way to do this from the UI right now";
680 sub export_mailinglistmember_delete {
681 my( $self, $svc_mailinglist, $mailinglistmember ) = (shift, shift, shift);
682 $svc_mailinglist->replace();
685 sub export_getsettings {
686 my($self, $svc_x) = (shift, shift);
688 my $table = $svc_x->table;
689 my $method = "export_getsettings_$table";
691 $self->can($method) ? $self->$method($svc_x, @_) : '';
695 sub export_getsettings_svc_domain {
696 my($self, $svc_domain, $settingsref, $defaultref ) = @_;
698 my $settings = eval { $self->communigate_pro_runcommand(
704 my $effective_settings = eval { $self->communigate_pro_runcommand(
705 'GetDomainEffectiveSettings',
710 my $acct_defaults = eval { $self->communigate_pro_runcommand(
711 'GetAccountDefaults',
716 my $acct_defaultprefs = eval { $self->communigate_pro_runcommand(
717 'GetAccountDefaultPrefs',
722 my $rules = eval { $self->communigate_pro_runcommand(
723 'GetDomainMailRules',
729 my $aliases = eval { $self->communigate_pro_runcommand(
736 ( map { ("Acct. Default $_" => $acct_defaults->{$_}); }
737 keys(%$acct_defaults)
739 ( map { ("Acct. Default $_" => $acct_defaultprefs->{$_}); } #diff label??
740 keys(%$acct_defaultprefs)
742 ( map _rule2string($_), @$rules ),
743 'Aliases' => join(', ', @$aliases),
746 %$effective_settings = ( %$effective_settings, %more );
747 %$settings = ( %$settings, %more );
749 #false laziness w/below
751 my %defaults = map { $_ => 1 }
752 grep !exists(${$settings}{$_}), keys %$effective_settings;
754 foreach my $key ( grep ref($effective_settings->{$_}),
755 keys %$effective_settings )
757 $effective_settings->{$key} = _pretty( $effective_settings->{$key} );
760 %{$settingsref} = %$effective_settings;
761 %{$defaultref} = %defaults;
766 sub export_getsettings_svc_acct {
767 my($self, $svc_acct, $settingsref, $defaultref ) = @_;
769 my $settings = eval { $self->communigate_pro_runcommand(
770 'GetAccountSettings',
775 delete($settings->{'Password'});
777 my $effective_settings = eval { $self->communigate_pro_runcommand(
778 'GetAccountEffectiveSettings',
783 delete($effective_settings->{'Password'});
785 #prefs/effectiveprefs too
787 my $prefs = eval { $self->communigate_pro_runcommand(
793 my $effective_prefs = eval { $self->communigate_pro_runcommand(
794 'GetAccountEffectivePrefs',
799 %$effective_settings = ( %$effective_settings,
800 map { ("Pref $_" => $effective_prefs->{$_}); }
801 keys(%$effective_prefs)
803 %$settings = ( %$settings,
804 map { ("Pref $_" => $prefs->{$_}); }
809 my $rules = eval { $self->communigate_pro_runcommand(
810 'GetAccountMailRules',
815 %$effective_settings = ( %$effective_settings,
816 map _rule2string($_), @$rules
818 %$settings = ( %$settings,
819 map _rule2string($_), @$rules
823 # my $rpops = eval { $self->communigate_pro_runcommand(
829 # %$effective_settings = ( %$effective_settings,
830 # map _rpop2string($_), %$rpops
832 # %$settings = ( %$settings,
833 # map _rpop2string($_), %rpops
837 my $aliases = eval { $self->communigate_pro_runcommand(
843 $effective_settings->{'Aliases'} = join(', ', @$aliases);
844 $settings->{'Aliases'} = join(', ', @$aliases);
846 #false laziness w/above
848 my %defaults = map { $_ => 1 }
849 grep !exists(${$settings}{$_}), keys %$effective_settings;
851 foreach my $key ( grep ref($effective_settings->{$_}),
852 keys %$effective_settings )
854 $effective_settings->{$key} = _pretty( $effective_settings->{$key} );
857 %{$settingsref} = %$effective_settings;
858 %{$defaultref} = %defaults;
866 if ( ref($value) eq 'ARRAY' ) {
867 '['. join(' ', map { ref($_) ? _pretty($_) : $_ } @$value ). ']';
868 } elsif ( ref($value) eq 'HASH' ) {
870 map { my $v = $value->{$_};
871 "$_:". ( ref($v) ? _pretty($v) : $v );
876 warn "serializing ". ref($value). " for table display not yet handled";
880 sub export_getsettings_svc_forward {
881 my($self, $svc_forward, $settingsref, $defaultref ) = @_;
883 my $dest = eval { $self->communigate_pro_runcommand(
885 ($svc_forward->src || $svc_forward->srcsvc_acct->email),
889 my $settings = { 'Destination' => $dest };
891 %{$settingsref} = %$settings;
899 my($priority, $name, $conditions, $actions, $comment) = @$rule;
900 $conditions = join(', ', map { my $a = $_; join(' ', @$a); } @$conditions);
901 $actions = join(', ', map { my $a = $_; join(' ', @$a); } @$actions);
902 ("Mail rule $name" => "$priority IF $conditions THEN $actions ($comment)");
907 # my($priority, $name, $conditions, $actions, $comment) = @$rule;
908 # $conditions = join(', ', map { my $a = $_; join(' ', @$a); } @$conditions);
909 # $actions = join(', ', map { my $a = $_; join(' ', @$a); } @$actions);
910 # ("Mail rule $name" => "$priority IF $conditions THEN $actions ($comment)");
913 sub export_getsettings_svc_mailinglist {
914 my($self, $svc_mailinglist, $settingsref, $defaultref ) = @_;
916 my $settings = eval { $self->communigate_pro_runcommand(
918 $svc_mailinglist->username.'@'.$svc_mailinglist->domain,
922 $settings->{'Members'} = join(', ', @{ $settings->{'Members'} } );
924 %{$settingsref} = %$settings;
929 sub communigate_pro_queue {
930 my( $self, $svcnum, $method ) = (shift, shift, shift);
931 my $jobnum = ''; #don't actually care
932 $self->communigate_pro_queue_dep( \$jobnum, $svcnum, $method, @_);
935 sub communigate_pro_queue_dep {
936 my( $self, $jobnumref, $svcnum, $method ) = splice(@_,0,4);
938 my %kludge_methods = (
939 #'CreateAccount' => 'CreateAccount',
940 'UpdateAccountSettings' => 'UpdateAccountSettings',
941 'UpdateAccountPrefs' => 'cp_Scalar_Hash',
942 #'CreateDomain' => 'cp_Scalar_Hash',
943 #'CreateSharedDomain' => 'cp_Scalar_Hash',
944 'UpdateDomainSettings' => 'cp_Scalar_settingsHash',
945 'SetDomainAliases' => 'cp_Scalar_Array',
946 'SetAccountDefaults' => 'cp_Scalar_settingsHash',
947 'UpdateAccountDefaults' => 'cp_Scalar_settingsHash',
948 'SetAccountDefaultPrefs' => 'cp_Scalar_settingsHash',
949 'UpdateAccountDefaultPrefs' => 'cp_Scalar_settingsHash',
950 'SetAccountRPOPs' => 'cp_Scalar_Hash',
952 my $sub = exists($kludge_methods{$method})
953 ? $kludge_methods{$method}
954 : 'communigate_pro_command';
956 my $queue = new FS::queue {
958 'job' => "FS::part_export::communigate_pro::$sub",
960 my $error = $queue->insert(
962 $self->option('port'),
963 $self->option('login'),
964 $self->option('password'),
968 $$jobnumref = $queue->jobnum unless $error;
973 sub communigate_pro_runcommand {
974 my( $self, $method ) = (shift, shift);
976 communigate_pro_command(
978 $self->option('port'),
979 $self->option('login'),
980 $self->option('password'),
987 #XXX one sub per arg prototype is lame. more magic? i suppose queue needs
988 # to store data strctures properly instead of just an arg list. right.
991 my( $machine, $port, $login, $password, $method, $scalar, %hash ) = @_;
992 my @args = ( $scalar, \%hash );
993 communigate_pro_command( $machine, $port, $login, $password, $method, @args );
996 sub cp_Scalar_Array {
997 my( $machine, $port, $login, $password, $method, $scalar, @array ) = @_;
998 my @args = ( $scalar, \@array );
999 communigate_pro_command( $machine, $port, $login, $password, $method, @args );
1003 # my( $machine, $port, $login, $password, $method, %hash ) = @_;
1004 # my @args = ( \%hash );
1005 # communigate_pro_command( $machine, $port, $login, $password, $method, @args );
1008 sub cp_Scalar_settingsHash {
1009 my( $machine, $port, $login, $password, $method, $domain, %settings ) = @_;
1010 for (qw( AccessModes DomainAccessModes )) {
1011 $settings{$_} = [split(' ',$settings{$_})] if $settings{$_};
1013 my @args = ( 'domain' => $domain, 'settings' => \%settings );
1014 communigate_pro_command( $machine, $port, $login, $password, $method, @args );
1017 #sub CreateAccount {
1018 # my( $machine, $port, $login, $password, $method, %args ) = @_;
1019 # my $accountName = delete $args{'accountName'};
1020 # my $accountType = delete $args{'accountType'};
1021 # my $externalFlag = delete $args{'externalFlag'};
1022 # $args{'AccessModes'} = [ split(' ', $args{'AccessModes'}) ];
1023 # my @args = ( accountName => $accountName,
1024 # accountType => $accountType,
1025 # settings => \%args,
1027 # #externalFlag => $externalFlag,
1028 # push @args, externalFlag => $externalFlag if $externalFlag;
1030 # communigate_pro_command( $machine, $port, $login, $password, $method, @args );
1034 sub UpdateAccountSettings {
1035 my( $machine, $port, $login, $password, $method, $accountName, %args ) = @_;
1036 $args{'AccessModes'} = [ split(' ', $args{'AccessModes'}) ];
1037 my @args = ( $accountName, \%args );
1038 communigate_pro_command( $machine, $port, $login, $password, $method, @args );
1041 sub communigate_pro_command { #subroutine, not method
1042 my( $machine, $port, $login, $password, $method, @args ) = @_;
1044 eval "use CGP::CLI";
1047 my $cli = new CGP::CLI( {
1048 'PeerAddr' => $machine,
1049 'PeerPort' => $port,
1051 'password' => $password,
1052 } ) or die "Can't login to CGPro: $CGP::ERR_STRING\n";
1054 #warn "$method ". Dumper(@args) if $DEBUG;
1056 my $return = $cli->$method(@args)
1057 or die "Communigate Pro error: ". $cli->getErrMessage. "\n";
1059 $cli->Logout; # or die "Can't logout of CGPro: $CGP::ERR_STRING\n";