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;
176 $settings{'CertificateType'} = $svc_domain->cgp_certificatetype
177 if $svc_domain->cgp_certificatetype;
179 my @options = ( $create, $svc_domain->domain, \%settings );
181 eval { $self->communigate_pro_runcommand( @options ) };
185 if ( $svc_domain->cgp_aliases ) {
186 my $alias_err = $self->communigate_pro_queue( $svc_domain->svcnum,
189 split(/\s*[,\s]\s*/, $svc_domain->cgp_aliases),
191 warn "WARNING: error queueing SetDomainAliases job: $alias_err"
196 my $def_err = $self->communigate_pro_queue( $svc_domain->svcnum,
197 'SetAccountDefaults',
199 'PWDAllowed' =>($svc_domain->acct_def_password_selfchange ? 'YES':'NO'),
200 'PasswordRecovery' => ($svc_domain->acct_def_password_recover ? 'YES':'NO'),
201 'AccessModes' => $svc_domain->acct_def_cgp_accessmodes,
202 'MaxAccountSize' => $svc_domain->acct_def_quota,
203 'MaxWebSize' => $svc_domain->acct_def_file_quota,
204 'MaxWebFile' => $svc_domain->acct_def_file_maxnum,
205 'MaxFileSize' => $svc_domain->acct_def_file_maxsize,
206 'RulesAllowed' => $svc_domain->acct_def_cgp_rulesallowed,
207 'RPOPAllowed' =>($svc_domain->acct_def_cgp_rpopallowed ?'YES':'NO'),
208 'MailToAll' =>($svc_domain->acct_def_cgp_mailtoall ?'YES':'NO'),
209 'AddMailTrailer' =>($svc_domain->acct_def_cgp_addmailtrailer ?'YES':'NO'),
210 'ArchiveMessagesAfter' => $svc_domain->acct_def_cgp_archiveafter,
212 warn "WARNING: error queueing SetAccountDefaults job: $def_err"
215 #account defaults prefs
216 my $pref_err = $self->communigate_pro_queue( $svc_domain->svcnum,
217 'SetAccountDefaultPrefs',
219 'DeleteMode' => $svc_domain->acct_def_cgp_deletemode,
220 'EmptyTrash' => $svc_domain->acct_def_cgp_emptytrash,
221 'Language' => $svc_domain->acct_def_cgp_language,
222 'TimeZone' => $svc_domain->acct_def_cgp_timezone,
223 'SkinName' => $svc_domain->acct_def_cgp_skinname,
224 'ProntoSkinName' => $svc_domain->acct_def_cgp_prontoskinname,
225 'SendMDNMode' => $svc_domain->acct_def_cgp_sendmdnmode,
227 warn "WARNING: error queueing SetAccountDefaultPrefs job: $pref_err"
230 my $rule_error = $self->communigate_pro_queue(
232 'SetDomainMailRules',
234 $svc_domain->cgp_rule_arrayref,
236 warn "WARNING: error queueing SetDomainMailRules job: $rule_error"
243 sub _export_insert_svc_forward {
244 my( $self, $svc_forward ) = (shift, shift);
246 my $src = $svc_forward->src || $svc_forward->srcsvc_acct->email;
247 my $dst = $svc_forward->dst || $svc_forward->dstsvc_acct->email;
249 #real-time here, presuming CGP does some dup detection?
250 eval { $self->communigate_pro_runcommand( 'CreateForwarder', $src, $dst); };
256 sub _export_insert_svc_mailinglist {
257 my( $self, $svc_mlist ) = (shift, shift);
259 my @members = map $_->email_address,
260 $svc_mlist->mailinglist->mailinglistmember;
262 #real-time here, presuming CGP does some dup detection
263 eval { $self->communigate_pro_runcommand(
265 $svc_mlist->username.'@'.$svc_mlist->domain,
266 { 'RealName' => $svc_mlist->listname,
267 'SetReplyTo' => ( $svc_mlist->reply_to ? 'YES' : 'NO' ),
268 'RemoveAuthor' => ( $svc_mlist->remove_from ? 'YES' : 'NO' ),
269 'RejectAuto' => ( $svc_mlist->reject_auto ? 'YES' : 'NO' ),
270 'RemoveToAndCc' => ( $svc_mlist->remove_to_and_cc ? 'YES' : 'NO' ),
271 'Members' => \@members,
281 sub _export_replace {
282 my( $self, $new, $old ) = (shift, shift, shift);
284 my $table = $new->table;
285 my $method = "_export_replace_$table";
286 $self->$method($new, $old, @_);
289 sub _export_replace_svc_acct {
290 my( $self, $new, $old ) = (shift, shift, shift);
292 #let's just do the rename part realtime rather than trying to queue
293 #w/dependencies. we don't want FS winding up out-of-sync with the wrong
294 #username and a queued job anyway. right??
295 if ( $self->export_username($old) ne $self->export_username($new) ) {
296 eval { $self->communigate_pro_runcommand(
298 $self->export_username($old),
299 $self->export_username($new),
304 if ( $new->_password ne $old->_password
305 && '*SUSPENDED* '.$old->_password ne $new->_password
307 $self->communigate_pro_queue( $new->svcnum, 'SetAccountPassword',
308 $self->export_username($new), $new->_password
314 $settings{'RealName'} = $new->finger
315 if $old->finger ne $new->finger;
316 $settings{$quotas{$_}} = $new->$_()
317 foreach grep $old->$_() ne $new->$_(), keys %quotas;
318 $settings{'accountType'} = $new->cgp_type
319 if $old->cgp_type ne $new->cgp_type;
320 $settings{'AccessModes'} = $new->cgp_accessmodes
321 if $old->cgp_accessmodes ne $new->cgp_accessmodes
322 || $old->cgp_type ne $new->cgp_type;
324 $settings{'PasswordRecovery'} = ( $new->password_recover ? 'YES':'NO' )
325 if $old->password_recover ne $new->password_recover;
327 $settings{'RulesAllowed'} = $new->cgp_rulesallowed
328 if $old->cgp_rulesallowed ne $new->cgp_rulesallowed;
329 $settings{'RPOPAllowed'} = ( $new->cgp_rpopallowed ? 'YES':'NO' )
330 if $old->cgp_rpopallowed ne $new->cgp_rpopallowed;
331 $settings{'MailToAll'} = ( $new->cgp_mailtoall ? 'YES':'NO' )
332 if $old->cgp_mailtoall ne $new->cgp_mailtoall;
333 $settings{'AddMailTrailer'} = ( $new->cgp_addmailtrailer ? 'YES':'NO' )
334 if $old->cgp_addmailtrailer ne $new->cgp_addmailtrailer;
335 $settings{'ArchiveMessagesAfter'} = $new->cgp_archiveafter
336 if $old->cgp_archiveafter ne $new->cgp_archiveafter;
338 #XXX phase 3: mailing lists
340 if ( keys %settings ) {
341 my $error = $self->communigate_pro_queue(
343 'UpdateAccountSettings',
344 $self->export_username($new),
347 return $error if $error;
352 $prefs{'DeleteMode'} = $new->cgp_deletemode
353 if $old->cgp_deletemode ne $new->cgp_deletemode;
354 $prefs{'EmptyTrash'} = $new->cgp_emptytrash
355 if $old->cgp_emptytrash ne $new->cgp_emptytrash;
356 $prefs{'Language'} = $new->cgp_language
357 if $old->cgp_language ne $new->cgp_language;
358 $prefs{'TimeZone'} = $new->cgp_timezone
359 if $old->cgp_timezone ne $new->cgp_timezone;
360 $prefs{'SkinName'} = $new->cgp_skinname
361 if $old->cgp_skinname ne $new->cgp_skinname;
362 $prefs{'ProntoSkinName'} = $new->cgp_prontoskinname
363 if $old->cgp_prontoskinname ne $new->cgp_prontoskinname;
364 $prefs{'SendMDNMode'} = $new->cgp_sendmdnmode
365 if $old->cgp_sendmdnmode ne $new->cgp_sendmdnmode;
367 my $pref_err = $self->communigate_pro_queue( $new->svcnum,
368 'UpdateAccountPrefs',
369 $self->export_username($new),
372 warn "WARNING: error queueing UpdateAccountPrefs job: $pref_err"
376 if ( $old->cgp_aliases ne $new->cgp_aliases ) {
377 my $error = $self->communigate_pro_queue(
380 $self->export_username($new),
381 [ split(/\s*[,\s]\s*/, $new->cgp_aliases) ],
383 return $error if $error;
386 my $rule_error = $self->communigate_pro_queue(
388 'SetAccountMailRules',
389 $self->export_username($new),
390 $new->cgp_rule_arrayref,
392 warn "WARNING: error queueing SetAccountMailRules job: $rule_error"
395 my $rpop_error = $self->communigate_pro_queue(
398 $self->export_username($new),
399 $new->cgp_rpop_hashref,
401 warn "WARNING: error queueing SetAccountMailRPOPs job: $rpop_error"
408 sub _export_replace_svc_domain {
409 my( $self, $new, $old ) = (shift, shift, shift);
411 #let's just do the rename part realtime rather than trying to queue
412 #w/dependencies. we don't want FS winding up out-of-sync with the wrong
413 #username and a queued job anyway. right??
414 if ( $old->domain ne $new->domain ) {
415 eval { $self->communigate_pro_runcommand(
416 'RenameDomain', $old->domain, $new->domain,
422 $settings{'AccountsLimit'} = $new->max_accounts
423 if $old->max_accounts ne $new->max_accounts;
424 $settings{'TrailerText'} = $new->trailer
425 if $old->trailer ne $new->trailer;
426 $settings{'DomainAccessModes'} = $new->cgp_accessmodes
427 if $old->cgp_accessmodes ne $new->cgp_accessmodes;
428 $settings{'AdminDomainName'} =
429 $new->parent_svcnum ? $new->parent_svc_x->domain : ''
430 if $old->parent_svcnum != $new->parent_svcnum;
431 $settings{'CertificateType'} = $new->cgp_certificatetype
432 if $old->cgp_certificatetype ne $new->cgp_certificatetype;
434 if ( keys %settings ) {
435 my $error = $self->communigate_pro_queue( $new->svcnum,
436 'UpdateDomainSettings',
440 return $error if $error;
443 if ( $old->cgp_aliases ne $new->cgp_aliases ) {
444 my $error = $self->communigate_pro_queue( $new->svcnum,
447 split(/\s*[,\s]\s*/, $new->cgp_aliases),
449 return $error if $error;
452 #below this identical to insert... any value to doing an Update here?
453 #not seeing any big one... i guess it would be nice to avoid the update
454 #when things haven't changed
457 my $def_err = $self->communigate_pro_queue( $new->svcnum,
458 'SetAccountDefaults',
460 'PWDAllowed' => ( $new->acct_def_password_selfchange ? 'YES' : 'NO' ),
461 'PasswordRecovery' => ( $new->acct_def_password_recover ? 'YES' : 'NO' ),
462 'AccessModes' => $new->acct_def_cgp_accessmodes,
463 'MaxAccountSize' => $new->acct_def_quota,
464 'MaxWebSize' => $new->acct_def_file_quota,
465 'MaxWebFile' => $new->acct_def_file_maxnum,
466 'MaxFileSize' => $new->acct_def_file_maxsize,
467 'RulesAllowed' => $new->acct_def_cgp_rulesallowed,
468 'RPOPAllowed' => ( $new->acct_def_cgp_rpopallowed ? 'YES' : 'NO' ),
469 'MailToAll' => ( $new->acct_def_cgp_mailtoall ? 'YES' : 'NO' ),
470 'AddMailTrailer' => ( $new->acct_def_cgp_addmailtrailer ? 'YES' : 'NO' ),
471 'ArchiveMessagesAfter' => $new->acct_def_cgp_archiveafter,
473 warn "WARNING: error queueing SetAccountDefaults job: $def_err"
476 #account defaults prefs
477 my $pref_err = $self->communigate_pro_queue( $new->svcnum,
478 'SetAccountDefaultPrefs',
480 'DeleteMode' => $new->acct_def_cgp_deletemode,
481 'EmptyTrash' => $new->acct_def_cgp_emptytrash,
482 'Language' => $new->acct_def_cgp_language,
483 'TimeZone' => $new->acct_def_cgp_timezone,
484 'SkinName' => $new->acct_def_cgp_skinname,
485 'ProntoSkinName' => $new->acct_def_cgp_prontoskinname,
486 'SendMDNMode' => $new->acct_def_cgp_sendmdnmode,
488 warn "WARNING: error queueing SetAccountDefaultPrefs job: $pref_err"
491 my $rule_error = $self->communigate_pro_queue(
493 'SetDomainMailRules',
495 $new->cgp_rule_arrayref,
497 warn "WARNING: error queueing SetDomainMailRules job: $rule_error"
503 sub _export_replace_svc_forward {
504 my( $self, $new, $old ) = (shift, shift, shift);
506 my $osrc = $old->src || $old->srcsvc_acct->email;
507 my $nsrc = $new->src || $new->srcsvc_acct->email;
508 my $odst = $old->dst || $old->dstsvc_acct->email;
509 my $ndst = $new->dst || $new->dstsvc_acct->email;
511 if ( $odst ne $ndst ) {
513 #no change command, so delete and create (real-time)
514 eval { $self->communigate_pro_runcommand('DeleteForwarder', $osrc) };
516 eval { $self->communigate_pro_runcommand('CreateForwarder', $nsrc, $ndst)};
519 } elsif ( $osrc ne $nsrc ) {
521 #real-time here, presuming CGP does some dup detection?
522 eval { $self->communigate_pro_runcommand( 'RenameForwarder', $osrc, $nsrc)};
526 warn "communigate replace called for svc_forward with no changes\n";#confess
532 sub _export_replace_svc_mailinglist {
533 my( $self, $new, $old ) = (shift, shift, shift);
535 my $oldGroupName = $old->username.'@'.$old->domain;
536 my $newGroupName = $new->username.'@'.$new->domain;
538 if ( $oldGroupName ne $newGroupName ) {
539 eval { $self->communigate_pro_runcommand(
540 'RenameGroup', $oldGroupName, $newGroupName ); };
544 my @members = map $_->email_address,
545 $new->mailinglist->mailinglistmember;
547 #real-time here, presuming CGP does some dup detection
548 eval { $self->communigate_pro_runcommand(
549 'SetGroup', $newGroupName,
550 { 'RealName' => $new->listname,
551 'SetReplyTo' => ( $new->reply_to ? 'YES' : 'NO' ),
552 'RemoveAuthor' => ( $new->remove_from ? 'YES' : 'NO' ),
553 'RejectAuto' => ( $new->reject_auto ? 'YES' : 'NO' ),
554 'RemoveToAndCc' => ( $new->remove_to_and_cc ? 'YES' : 'NO' ),
555 'Members' => \@members,
566 my( $self, $svc_x ) = (shift, shift);
568 my $table = $svc_x->table;
569 my $method = "_export_delete_$table";
570 $self->$method($svc_x, @_);
573 sub _export_delete_svc_acct {
574 my( $self, $svc_acct ) = (shift, shift);
576 $self->communigate_pro_queue( $svc_acct->svcnum, 'DeleteAccount',
577 $self->export_username($svc_acct),
581 sub _export_delete_svc_domain {
582 my( $self, $svc_domain ) = (shift, shift);
584 $self->communigate_pro_queue( $svc_domain->svcnum, 'DeleteDomain',
586 #XXX turn on force option for domain deletion?
590 sub _export_delete_svc_forward {
591 my( $self, $svc_forward ) = (shift, shift);
593 $self->communigate_pro_queue( $svc_forward->svcnum, 'DeleteForwarder',
594 ($svc_forward->src || $svc_forward->srcsvc_acct->email),
598 sub _export_delete_svc_mailinglist {
599 my( $self, $svc_mailinglist ) = (shift, shift);
601 #real-time here, presuming CGP does some dup detection
602 eval { $self->communigate_pro_runcommand(
604 $svc_mailinglist->username.'@'.$svc_mailinglist->domain,
613 sub _export_suspend {
614 my( $self, $svc_x ) = (shift, shift);
616 my $table = $svc_x->table;
617 my $method = "_export_suspend_$table";
618 $self->$method($svc_x, @_);
622 sub _export_suspend_svc_acct {
623 my( $self, $svc_acct ) = (shift, shift);
625 #XXX is this the desired suspnsion action?
627 $self->communigate_pro_queue(
629 'UpdateAccountSettings',
630 $self->export_username($svc_acct),
631 'AccessModes' => 'Mail',
636 sub _export_suspend_svc_domain {
637 my( $self, $svc_domain) = (shift, shift);
639 #XXX domain operations
644 sub _export_unsuspend {
645 my( $self, $svc_x ) = (shift, shift);
647 my $table = $svc_x->table;
648 my $method = "_export_unsuspend_$table";
649 $self->$method($svc_x, @_);
653 sub _export_unsuspend_svc_acct {
654 my( $self, $svc_acct ) = (shift, shift);
656 $self->communigate_pro_queue(
658 'UpdateAccountSettings',
659 $self->export_username($svc_acct),
660 'AccessModes' => ( $svc_acct->cgp_accessmodes
661 || $self->option('AccessModes') ),
666 sub _export_unsuspend_svc_domain {
667 my( $self, $svc_domain) = (shift, shift);
669 #XXX domain operations
674 sub export_mailinglistmember_insert {
675 my( $self, $svc_mailinglist, $mailinglistmember ) = (shift, shift, shift);
676 $svc_mailinglist->replace();
679 sub export_mailinglistmember_replace {
680 my( $self, $svc_mailinglist, $new, $old ) = (shift, shift, shift, shift);
681 die "no way to do this from the UI right now";
684 sub export_mailinglistmember_delete {
685 my( $self, $svc_mailinglist, $mailinglistmember ) = (shift, shift, shift);
686 $svc_mailinglist->replace();
689 sub export_getsettings {
690 my($self, $svc_x) = (shift, shift);
692 my $table = $svc_x->table;
693 my $method = "export_getsettings_$table";
695 $self->can($method) ? $self->$method($svc_x, @_) : '';
699 sub export_getsettings_svc_domain {
700 my($self, $svc_domain, $settingsref, $defaultref ) = @_;
702 my $settings = eval { $self->communigate_pro_runcommand(
708 my $effective_settings = eval { $self->communigate_pro_runcommand(
709 'GetDomainEffectiveSettings',
714 my $acct_defaults = eval { $self->communigate_pro_runcommand(
715 'GetAccountDefaults',
720 my $acct_defaultprefs = eval { $self->communigate_pro_runcommand(
721 'GetAccountDefaultPrefs',
726 my $rules = eval { $self->communigate_pro_runcommand(
727 'GetDomainMailRules',
733 my $aliases = eval { $self->communigate_pro_runcommand(
740 ( map { ("Acct. Default $_" => $acct_defaults->{$_}); }
741 keys(%$acct_defaults)
743 ( map { ("Acct. Default $_" => $acct_defaultprefs->{$_}); } #diff label??
744 keys(%$acct_defaultprefs)
746 ( map _rule2string($_), @$rules ),
747 'Aliases' => join(', ', @$aliases),
750 %$effective_settings = ( %$effective_settings, %more );
751 %$settings = ( %$settings, %more );
753 #false laziness w/below
755 my %defaults = map { $_ => 1 }
756 grep !exists(${$settings}{$_}), keys %$effective_settings;
758 foreach my $key ( grep ref($effective_settings->{$_}),
759 keys %$effective_settings )
761 $effective_settings->{$key} = _pretty( $effective_settings->{$key} );
764 %{$settingsref} = %$effective_settings;
765 %{$defaultref} = %defaults;
770 sub export_getsettings_svc_acct {
771 my($self, $svc_acct, $settingsref, $defaultref ) = @_;
773 my $settings = eval { $self->communigate_pro_runcommand(
774 'GetAccountSettings',
779 delete($settings->{'Password'});
781 my $effective_settings = eval { $self->communigate_pro_runcommand(
782 'GetAccountEffectiveSettings',
787 delete($effective_settings->{'Password'});
789 #prefs/effectiveprefs too
791 my $prefs = eval { $self->communigate_pro_runcommand(
797 my $effective_prefs = eval { $self->communigate_pro_runcommand(
798 'GetAccountEffectivePrefs',
803 %$effective_settings = ( %$effective_settings,
804 map { ("Pref $_" => $effective_prefs->{$_}); }
805 keys(%$effective_prefs)
807 %$settings = ( %$settings,
808 map { ("Pref $_" => $prefs->{$_}); }
813 my $rules = eval { $self->communigate_pro_runcommand(
814 'GetAccountMailRules',
819 %$effective_settings = ( %$effective_settings,
820 map _rule2string($_), @$rules
822 %$settings = ( %$settings,
823 map _rule2string($_), @$rules
827 # my $rpops = eval { $self->communigate_pro_runcommand(
833 # %$effective_settings = ( %$effective_settings,
834 # map _rpop2string($_), %$rpops
836 # %$settings = ( %$settings,
837 # map _rpop2string($_), %rpops
841 my $aliases = eval { $self->communigate_pro_runcommand(
847 $effective_settings->{'Aliases'} = join(', ', @$aliases);
848 $settings->{'Aliases'} = join(', ', @$aliases);
850 #false laziness w/above
852 my %defaults = map { $_ => 1 }
853 grep !exists(${$settings}{$_}), keys %$effective_settings;
855 foreach my $key ( grep ref($effective_settings->{$_}),
856 keys %$effective_settings )
858 $effective_settings->{$key} = _pretty( $effective_settings->{$key} );
861 %{$settingsref} = %$effective_settings;
862 %{$defaultref} = %defaults;
870 if ( ref($value) eq 'ARRAY' ) {
871 '['. join(' ', map { ref($_) ? _pretty($_) : $_ } @$value ). ']';
872 } elsif ( ref($value) eq 'HASH' ) {
874 map { my $v = $value->{$_};
875 "$_:". ( ref($v) ? _pretty($v) : $v );
880 warn "serializing ". ref($value). " for table display not yet handled";
884 sub export_getsettings_svc_forward {
885 my($self, $svc_forward, $settingsref, $defaultref ) = @_;
887 my $dest = eval { $self->communigate_pro_runcommand(
889 ($svc_forward->src || $svc_forward->srcsvc_acct->email),
893 my $settings = { 'Destination' => $dest };
895 %{$settingsref} = %$settings;
903 my($priority, $name, $conditions, $actions, $comment) = @$rule;
904 $conditions = join(', ', map { my $a = $_; join(' ', @$a); } @$conditions);
905 $actions = join(', ', map { my $a = $_; join(' ', @$a); } @$actions);
906 ("Mail rule $name" => "$priority IF $conditions THEN $actions ($comment)");
911 # my($priority, $name, $conditions, $actions, $comment) = @$rule;
912 # $conditions = join(', ', map { my $a = $_; join(' ', @$a); } @$conditions);
913 # $actions = join(', ', map { my $a = $_; join(' ', @$a); } @$actions);
914 # ("Mail rule $name" => "$priority IF $conditions THEN $actions ($comment)");
917 sub export_getsettings_svc_mailinglist {
918 my($self, $svc_mailinglist, $settingsref, $defaultref ) = @_;
920 my $settings = eval { $self->communigate_pro_runcommand(
922 $svc_mailinglist->username.'@'.$svc_mailinglist->domain,
926 $settings->{'Members'} = join(', ', @{ $settings->{'Members'} } );
928 %{$settingsref} = %$settings;
933 sub communigate_pro_queue {
934 my( $self, $svcnum, $method ) = (shift, shift, shift);
935 my $jobnum = ''; #don't actually care
936 $self->communigate_pro_queue_dep( \$jobnum, $svcnum, $method, @_);
939 sub communigate_pro_queue_dep {
940 my( $self, $jobnumref, $svcnum, $method ) = splice(@_,0,4);
942 my %kludge_methods = (
943 #'CreateAccount' => 'CreateAccount',
944 'UpdateAccountSettings' => 'UpdateAccountSettings',
945 'UpdateAccountPrefs' => 'cp_Scalar_Hash',
946 #'CreateDomain' => 'cp_Scalar_Hash',
947 #'CreateSharedDomain' => 'cp_Scalar_Hash',
948 'UpdateDomainSettings' => 'cp_Scalar_settingsHash',
949 'SetDomainAliases' => 'cp_Scalar_Array',
950 'SetAccountDefaults' => 'cp_Scalar_settingsHash',
951 'UpdateAccountDefaults' => 'cp_Scalar_settingsHash',
952 'SetAccountDefaultPrefs' => 'cp_Scalar_settingsHash',
953 'UpdateAccountDefaultPrefs' => 'cp_Scalar_settingsHash',
954 'SetAccountRPOPs' => 'cp_Scalar_Hash',
956 my $sub = exists($kludge_methods{$method})
957 ? $kludge_methods{$method}
958 : 'communigate_pro_command';
960 my $queue = new FS::queue {
962 'job' => "FS::part_export::communigate_pro::$sub",
964 my $error = $queue->insert(
966 $self->option('port'),
967 $self->option('login'),
968 $self->option('password'),
972 $$jobnumref = $queue->jobnum unless $error;
977 sub communigate_pro_runcommand {
978 my( $self, $method ) = (shift, shift);
980 communigate_pro_command(
982 $self->option('port'),
983 $self->option('login'),
984 $self->option('password'),
991 #XXX one sub per arg prototype is lame. more magic? i suppose queue needs
992 # to store data strctures properly instead of just an arg list. right.
995 my( $machine, $port, $login, $password, $method, $scalar, %hash ) = @_;
996 my @args = ( $scalar, \%hash );
997 communigate_pro_command( $machine, $port, $login, $password, $method, @args );
1000 sub cp_Scalar_Array {
1001 my( $machine, $port, $login, $password, $method, $scalar, @array ) = @_;
1002 my @args = ( $scalar, \@array );
1003 communigate_pro_command( $machine, $port, $login, $password, $method, @args );
1007 # my( $machine, $port, $login, $password, $method, %hash ) = @_;
1008 # my @args = ( \%hash );
1009 # communigate_pro_command( $machine, $port, $login, $password, $method, @args );
1012 sub cp_Scalar_settingsHash {
1013 my( $machine, $port, $login, $password, $method, $domain, %settings ) = @_;
1014 for (qw( AccessModes DomainAccessModes )) {
1015 $settings{$_} = [split(' ',$settings{$_})] if $settings{$_};
1017 my @args = ( 'domain' => $domain, 'settings' => \%settings );
1018 communigate_pro_command( $machine, $port, $login, $password, $method, @args );
1021 #sub CreateAccount {
1022 # my( $machine, $port, $login, $password, $method, %args ) = @_;
1023 # my $accountName = delete $args{'accountName'};
1024 # my $accountType = delete $args{'accountType'};
1025 # my $externalFlag = delete $args{'externalFlag'};
1026 # $args{'AccessModes'} = [ split(' ', $args{'AccessModes'}) ];
1027 # my @args = ( accountName => $accountName,
1028 # accountType => $accountType,
1029 # settings => \%args,
1031 # #externalFlag => $externalFlag,
1032 # push @args, externalFlag => $externalFlag if $externalFlag;
1034 # communigate_pro_command( $machine, $port, $login, $password, $method, @args );
1038 sub UpdateAccountSettings {
1039 my( $machine, $port, $login, $password, $method, $accountName, %args ) = @_;
1040 $args{'AccessModes'} = [ split(' ', $args{'AccessModes'}) ];
1041 my @args = ( $accountName, \%args );
1042 communigate_pro_command( $machine, $port, $login, $password, $method, @args );
1045 sub communigate_pro_command { #subroutine, not method
1046 my( $machine, $port, $login, $password, $method, @args ) = @_;
1048 eval "use CGP::CLI";
1051 my $cli = new CGP::CLI( {
1052 'PeerAddr' => $machine,
1053 'PeerPort' => $port,
1055 'password' => $password,
1056 } ) or die "Can't login to CGPro: $CGP::ERR_STRING\n";
1058 #warn "$method ". Dumper(@args) if $DEBUG;
1060 my $return = $cli->$method(@args)
1061 or die "Communigate Pro error: ". $cli->getErrMessage. "\n";
1063 $cli->Logout; # or die "Can't logout of CGPro: $CGP::ERR_STRING\n";