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"
138 my $rule_error = $self->communigate_pro_queue(
140 'SetAccountMailRules',
141 $self->export_username($svc_acct),
142 $svc_acct->cgp_rule_arrayref,
144 warn "WARNING: error queueing SetAccountMailRules job: $rule_error"
151 sub _export_insert_svc_domain {
152 my( $self, $svc_domain ) = (shift, shift);
154 my $create = $self->option('create_domain') || 'CreateDomain';
157 'DomainAccessModes' => [ split(' ', $svc_domain->cgp_accessmodes ) ],
159 $settings{'AccountsLimit'} = $svc_domain->max_accounts
160 if $svc_domain->max_accounts;
161 $settings{'AdminDomainName'} = $svc_domain->parent_svc_x->domain
162 if $svc_domain->parent_svcnum;
163 $settings{'TrailerText'} = $svc_domain->trailer
164 if $svc_domain->trailer;
166 my @options = ( $create, $svc_domain->domain, \%settings );
168 eval { $self->communigate_pro_runcommand( @options ) };
172 if ( $svc_domain->cgp_aliases ) {
173 my $alias_err = $self->communigate_pro_queue( $svc_domain->svcnum,
176 split(/\s*[,\s]\s*/, $svc_domain->cgp_aliases),
178 warn "WARNING: error queueing SetDomainAliases job: $alias_err"
183 my $def_err = $self->communigate_pro_queue( $svc_domain->svcnum,
184 'SetAccountDefaults',
186 'PWDAllowed' =>($svc_domain->acct_def_password_selfchange ? 'YES':'NO'),
187 'PasswordRecovery' => ($svc_domain->acct_def_password_recover ? 'YES':'NO'),
188 'AccessModes' => $svc_domain->acct_def_cgp_accessmodes,
189 'MaxAccountSize' => $svc_domain->acct_def_quota,
190 'MaxWebSize' => $svc_domain->acct_def_file_quota,
191 'MaxWebFile' => $svc_domain->acct_def_file_maxnum,
192 'MaxFileSize' => $svc_domain->acct_def_file_maxsize,
193 'RulesAllowed' => $svc_domain->acct_def_cgp_rulesallowed,
194 'RPOPAllowed' =>($svc_domain->acct_def_cgp_rpopallowed ?'YES':'NO'),
195 'MailToAll' =>($svc_domain->acct_def_cgp_mailtoall ?'YES':'NO'),
196 'AddMailTrailer' =>($svc_domain->acct_def_cgp_addmailtrailer ?'YES':'NO'),
198 warn "WARNING: error queueing SetAccountDefaults job: $def_err"
201 #account defaults prefs
202 my $pref_err = $self->communigate_pro_queue( $svc_domain->svcnum,
203 'SetAccountDefaultPrefs',
205 'DeleteMode' => $svc_domain->acct_def_cgp_deletemode,
206 'EmptyTrash' => $svc_domain->acct_def_cgp_emptytrash,
207 'Language' => $svc_domain->acct_def_cgp_language,
208 'TimeZone' => $svc_domain->acct_def_cgp_timezone,
209 'SkinName' => $svc_domain->acct_def_cgp_skinname,
210 'ProntoSkinName' => $svc_domain->acct_def_cgp_prontoskinname,
211 'SendMDNMode' => $svc_domain->acct_def_cgp_sendmdnmode,
213 warn "WARNING: error queueing SetAccountDefaultPrefs job: $pref_err"
216 my $rule_error = $self->communigate_pro_queue(
218 'SetDomainMailRules',
220 $svc_domain->cgp_rule_arrayref,
222 warn "WARNING: error queueing SetDomainMailRules job: $rule_error"
229 sub _export_insert_svc_forward {
230 my( $self, $svc_forward ) = (shift, shift);
232 my $src = $svc_forward->src || $svc_forward->srcsvc_acct->email;
233 my $dst = $svc_forward->dst || $svc_forward->dstsvc_acct->email;
235 #real-time here, presuming CGP does some dup detection?
236 eval { $self->communigate_pro_runcommand( 'CreateForwarder', $src, $dst); };
242 sub _export_insert_svc_mailinglist {
243 my( $self, $svc_mlist ) = (shift, shift);
245 my @members = map $_->email_address,
246 $svc_mlist->mailinglist->mailinglistmember;
248 #real-time here, presuming CGP does some dup detection
249 eval { $self->communigate_pro_runcommand(
251 $svc_mlist->username.'@'.$svc_mlist->domain,
252 { 'RealName' => $svc_mlist->listname,
253 'SetReplyTo' => ( $svc_mlist->reply_to ? 'YES' : 'NO' ),
254 'RemoveAuthor' => ( $svc_mlist->remove_from ? 'YES' : 'NO' ),
255 'RejectAuto' => ( $svc_mlist->reject_auto ? 'YES' : 'NO' ),
256 'RemoveToAndCc' => ( $svc_mlist->remove_to_and_cc ? 'YES' : 'NO' ),
257 'Members' => \@members,
267 sub _export_replace {
268 my( $self, $new, $old ) = (shift, shift, shift);
270 my $table = $new->table;
271 my $method = "_export_replace_$table";
272 $self->$method($new, $old, @_);
275 sub _export_replace_svc_acct {
276 my( $self, $new, $old ) = (shift, shift, shift);
278 #let's just do the rename part realtime rather than trying to queue
279 #w/dependencies. we don't want FS winding up out-of-sync with the wrong
280 #username and a queued job anyway. right??
281 if ( $self->export_username($old) ne $self->export_username($new) ) {
282 eval { $self->communigate_pro_runcommand(
284 $self->export_username($old),
285 $self->export_username($new),
290 if ( $new->_password ne $old->_password
291 && '*SUSPENDED* '.$old->_password ne $new->_password
293 $self->communigate_pro_queue( $new->svcnum, 'SetAccountPassword',
294 $self->export_username($new), $new->_password
300 $settings{'RealName'} = $new->finger
301 if $old->finger ne $new->finger;
302 $settings{$quotas{$_}} = $new->$_()
303 foreach grep $old->$_() ne $new->$_(), keys %quotas;
304 $settings{'accountType'} = $new->cgp_type
305 if $old->cgp_type ne $new->cgp_type;
306 $settings{'AccessModes'} = $new->cgp_accessmodes
307 if $old->cgp_accessmodes ne $new->cgp_accessmodes
308 || $old->cgp_type ne $new->cgp_type;
310 $settings{'PasswordRecovery'} = ( $new->password_recover ? 'YES':'NO' )
311 if $old->password_recover ne $new->password_recover;
313 $settings{'RulesAllowed'} = $new->cgp_rulesallowed
314 if $old->cgp_rulesallowed ne $new->cgp_rulesallowed;
315 $settings{'RPOPAllowed'} = ( $new->cgp_rpopallowed ? 'YES':'NO' )
316 if $old->cgp_rpopallowed ne $new->cgp_rpopallowed;
317 $settings{'MailToAll'} = ( $new->cgp_mailtoall ? 'YES':'NO' )
318 if $old->cgp_mailtoall ne $new->cgp_mailtoall;
319 $settings{'AddMailTrailer'} = ( $new->cgp_addmailtrailer ? 'YES':'NO' )
320 if $old->cgp_addmailtrailer ne $new->cgp_addmailtrailer;
322 #XXX phase 3: archive messages, mailing lists
324 if ( keys %settings ) {
325 my $error = $self->communigate_pro_queue(
327 'UpdateAccountSettings',
328 $self->export_username($new),
331 return $error if $error;
336 $prefs{'DeleteMode'} = $new->cgp_deletemode
337 if $old->cgp_deletemode ne $new->cgp_deletemode;
338 $prefs{'EmptyTrash'} = $new->cgp_emptytrash
339 if $old->cgp_emptytrash ne $new->cgp_emptytrash;
340 $prefs{'Language'} = $new->cgp_language
341 if $old->cgp_language ne $new->cgp_language;
342 $prefs{'TimeZone'} = $new->cgp_timezone
343 if $old->cgp_timezone ne $new->cgp_timezone;
344 $prefs{'SkinName'} = $new->cgp_skinname
345 if $old->cgp_skinname ne $new->cgp_skinname;
346 $prefs{'ProntoSkinName'} = $new->cgp_prontoskinname
347 if $old->cgp_prontoskinname ne $new->cgp_prontoskinname;
348 $prefs{'SendMDNMode'} = $new->cgp_sendmdnmode
349 if $old->cgp_sendmdnmode ne $new->cgp_sendmdnmode;
351 my $pref_err = $self->communigate_pro_queue( $new->svcnum,
352 'UpdateAccountPrefs',
353 $self->export_username($new),
356 warn "WARNING: error queueing UpdateAccountPrefs job: $pref_err"
360 if ( $old->cgp_aliases ne $new->cgp_aliases ) {
361 my $error = $self->communigate_pro_queue(
364 $self->export_username($new),
365 [ split(/\s*[,\s]\s*/, $new->cgp_aliases) ],
367 return $error if $error;
370 my $rule_error = $self->communigate_pro_queue(
372 'SetAccountMailRules',
373 $self->export_username($new),
374 $new->cgp_rule_arrayref,
376 warn "WARNING: error queueing SetAccountMailRules job: $rule_error"
383 sub _export_replace_svc_domain {
384 my( $self, $new, $old ) = (shift, shift, shift);
386 #let's just do the rename part realtime rather than trying to queue
387 #w/dependencies. we don't want FS winding up out-of-sync with the wrong
388 #username and a queued job anyway. right??
389 if ( $old->domain ne $new->domain ) {
390 eval { $self->communigate_pro_runcommand(
391 'RenameDomain', $old->domain, $new->domain,
397 $settings{'AccountsLimit'} = $new->max_accounts
398 if $old->max_accounts ne $new->max_accounts;
399 $settings{'TrailerText'} = $new->trailer
400 if $old->trailer ne $new->trailer;
401 $settings{'DomainAccessModes'} = $new->cgp_accessmodes
402 if $old->cgp_accessmodes ne $new->cgp_accessmodes;
403 $settings{'AdminDomainName'} =
404 $new->parent_svcnum ? $new->parent_svc_x->domain : ''
405 if $old->parent_svcnum != $new->parent_svcnum;
407 if ( keys %settings ) {
408 my $error = $self->communigate_pro_queue( $new->svcnum,
409 'UpdateDomainSettings',
413 return $error if $error;
416 if ( $old->cgp_aliases ne $new->cgp_aliases ) {
417 my $error = $self->communigate_pro_queue( $new->svcnum,
420 split(/\s*[,\s]\s*/, $new->cgp_aliases),
422 return $error if $error;
425 #below this identical to insert... any value to doing an Update here?
426 #not seeing any big one... i guess it would be nice to avoid the update
427 #when things haven't changed
430 my $def_err = $self->communigate_pro_queue( $new->svcnum,
431 'SetAccountDefaults',
433 'PWDAllowed' => ( $new->acct_def_password_selfchange ? 'YES' : 'NO' ),
434 'PasswordRecovery' => ( $new->acct_def_password_recover ? 'YES' : 'NO' ),
435 'AccessModes' => $new->acct_def_cgp_accessmodes,
436 'MaxAccountSize' => $new->acct_def_quota,
437 'MaxWebSize' => $new->acct_def_file_quota,
438 'MaxWebFile' => $new->acct_def_file_maxnum,
439 'MaxFileSize' => $new->acct_def_file_maxsize,
440 'RulesAllowed' => $new->acct_def_cgp_rulesallowed,
441 'RPOPAllowed' => ( $new->acct_def_cgp_rpopallowed ? 'YES' : 'NO' ),
442 'MailToAll' => ( $new->acct_def_cgp_mailtoall ? 'YES' : 'NO' ),
443 'AddMailTrailer' => ( $new->acct_def_cgp_addmailtrailer ? 'YES' : 'NO' ),
445 warn "WARNING: error queueing SetAccountDefaults job: $def_err"
448 #account defaults prefs
449 my $pref_err = $self->communigate_pro_queue( $new->svcnum,
450 'SetAccountDefaultPrefs',
452 'DeleteMode' => $new->acct_def_cgp_deletemode,
453 'EmptyTrash' => $new->acct_def_cgp_emptytrash,
454 'Language' => $new->acct_def_cgp_language,
455 'TimeZone' => $new->acct_def_cgp_timezone,
456 'SkinName' => $new->acct_def_cgp_skinname,
457 'ProntoSkinName' => $new->acct_def_cgp_prontoskinname,
458 'SendMDNMode' => $new->acct_def_cgp_sendmdnmode,
460 warn "WARNING: error queueing SetAccountDefaultPrefs job: $pref_err"
463 my $rule_error = $self->communigate_pro_queue(
465 'SetDomainMailRules',
467 $new->cgp_rule_arrayref,
469 warn "WARNING: error queueing SetDomainMailRules job: $rule_error"
475 sub _export_replace_svc_forward {
476 my( $self, $new, $old ) = (shift, shift, shift);
478 my $osrc = $old->src || $old->srcsvc_acct->email;
479 my $nsrc = $new->src || $new->srcsvc_acct->email;
480 my $odst = $old->dst || $old->dstsvc_acct->email;
481 my $ndst = $new->dst || $new->dstsvc_acct->email;
483 if ( $odst ne $ndst ) {
485 #no change command, so delete and create (real-time)
486 eval { $self->communigate_pro_runcommand('DeleteForwarder', $osrc) };
488 eval { $self->communigate_pro_runcommand('CreateForwarder', $nsrc, $ndst)};
491 } elsif ( $osrc ne $nsrc ) {
493 #real-time here, presuming CGP does some dup detection?
494 eval { $self->communigate_pro_runcommand( 'RenameForwarder', $osrc, $nsrc)};
498 warn "communigate replace called for svc_forward with no changes\n";#confess
504 sub _export_replace_svc_mailinglist {
505 my( $self, $new, $old ) = (shift, shift, shift);
507 my $oldGroupName = $old->username.'@'.$old->domain;
508 my $newGroupName = $new->username.'@'.$new->domain;
510 if ( $oldGroupName ne $newGroupName ) {
511 eval { $self->communigate_pro_runcommand(
512 'RenameGroup', $oldGroupName, $newGroupName ); };
516 my @members = map $_->email_address,
517 $new->mailinglist->mailinglistmember;
519 #real-time here, presuming CGP does some dup detection
520 eval { $self->communigate_pro_runcommand(
521 'SetGroup', $newGroupName,
522 { 'RealName' => $new->listname,
523 'SetReplyTo' => ( $new->reply_to ? 'YES' : 'NO' ),
524 'RemoveAuthor' => ( $new->remove_from ? 'YES' : 'NO' ),
525 'RejectAuto' => ( $new->reject_auto ? 'YES' : 'NO' ),
526 'RemoveToAndCc' => ( $new->remove_to_and_cc ? 'YES' : 'NO' ),
527 'Members' => \@members,
538 my( $self, $svc_x ) = (shift, shift);
540 my $table = $svc_x->table;
541 my $method = "_export_delete_$table";
542 $self->$method($svc_x, @_);
545 sub _export_delete_svc_acct {
546 my( $self, $svc_acct ) = (shift, shift);
548 $self->communigate_pro_queue( $svc_acct->svcnum, 'DeleteAccount',
549 $self->export_username($svc_acct),
553 sub _export_delete_svc_domain {
554 my( $self, $svc_domain ) = (shift, shift);
556 $self->communigate_pro_queue( $svc_domain->svcnum, 'DeleteDomain',
558 #XXX turn on force option for domain deletion?
562 sub _export_delete_svc_forward {
563 my( $self, $svc_forward ) = (shift, shift);
565 $self->communigate_pro_queue( $svc_forward->svcnum, 'DeleteForwarder',
566 ($svc_forward->src || $svc_forward->srcsvc_acct->email),
570 sub _export_delete_svc_mailinglist {
571 my( $self, $svc_mailinglist ) = (shift, shift);
573 #real-time here, presuming CGP does some dup detection
574 eval { $self->communigate_pro_runcommand(
576 $svc_mailinglist->username.'@'.$svc_mailinglist->domain,
585 sub _export_suspend {
586 my( $self, $svc_x ) = (shift, shift);
588 my $table = $svc_x->table;
589 my $method = "_export_suspend_$table";
590 $self->$method($svc_x, @_);
594 sub _export_suspend_svc_acct {
595 my( $self, $svc_acct ) = (shift, shift);
597 #XXX is this the desired suspnsion action?
599 $self->communigate_pro_queue(
601 'UpdateAccountSettings',
602 $self->export_username($svc_acct),
603 'AccessModes' => 'Mail',
608 sub _export_suspend_svc_domain {
609 my( $self, $svc_domain) = (shift, shift);
611 #XXX domain operations
616 sub _export_unsuspend {
617 my( $self, $svc_x ) = (shift, shift);
619 my $table = $svc_x->table;
620 my $method = "_export_unsuspend_$table";
621 $self->$method($svc_x, @_);
625 sub _export_unsuspend_svc_acct {
626 my( $self, $svc_acct ) = (shift, shift);
628 $self->communigate_pro_queue(
630 'UpdateAccountSettings',
631 $self->export_username($svc_acct),
632 'AccessModes' => ( $svc_acct->cgp_accessmodes
633 || $self->option('AccessModes') ),
638 sub _export_unsuspend_svc_domain {
639 my( $self, $svc_domain) = (shift, shift);
641 #XXX domain operations
646 sub export_mailinglistmember_insert {
647 my( $self, $svc_mailinglist, $mailinglistmember ) = (shift, shift, shift);
648 $svc_mailinglist->replace();
651 sub export_mailinglistmember_replace {
652 my( $self, $svc_mailinglist, $new, $old ) = (shift, shift, shift, shift);
653 die "no way to do this from the UI right now";
656 sub export_mailinglistmember_delete {
657 my( $self, $svc_mailinglist, $mailinglistmember ) = (shift, shift, shift);
658 $svc_mailinglist->replace();
661 sub export_getsettings {
662 my($self, $svc_x) = (shift, shift);
664 my $table = $svc_x->table;
665 my $method = "export_getsettings_$table";
667 $self->can($method) ? $self->$method($svc_x, @_) : '';
671 sub export_getsettings_svc_domain {
672 my($self, $svc_domain, $settingsref, $defaultref ) = @_;
674 my $settings = eval { $self->communigate_pro_runcommand(
680 my $effective_settings = eval { $self->communigate_pro_runcommand(
681 'GetDomainEffectiveSettings',
686 my $acct_defaults = eval { $self->communigate_pro_runcommand(
687 'GetAccountDefaults',
692 my $acct_defaultprefs = eval { $self->communigate_pro_runcommand(
693 'GetAccountDefaultPrefs',
698 my $rules = eval { $self->communigate_pro_runcommand(
699 'GetDomainMailRules',
705 my $aliases = eval { $self->communigate_pro_runcommand(
712 ( map { ("Acct. Default $_" => $acct_defaults->{$_}); }
713 keys(%$acct_defaults)
715 ( map { ("Acct. Default $_" => $acct_defaultprefs->{$_}); } #diff label??
716 keys(%$acct_defaultprefs)
718 ( map _rule2string($_), @$rules ),
719 'Aliases' => join(', ', @$aliases),
722 %$effective_settings = ( %$effective_settings, %more );
723 %$settings = ( %$settings, %more );
725 #false laziness w/below
727 my %defaults = map { $_ => 1 }
728 grep !exists(${$settings}{$_}), keys %$effective_settings;
730 foreach my $key ( grep ref($effective_settings->{$_}),
731 keys %$effective_settings )
733 my $value = $effective_settings->{$key};
734 if ( ref($value) eq 'ARRAY' ) {
735 $effective_settings->{$key} = join(' ', @$value);
738 warn "serializing ". ref($value). " for table display not yet handled";
742 %{$settingsref} = %$effective_settings;
743 %{$defaultref} = %defaults;
748 sub export_getsettings_svc_acct {
749 my($self, $svc_acct, $settingsref, $defaultref ) = @_;
751 my $settings = eval { $self->communigate_pro_runcommand(
752 'GetAccountSettings',
757 delete($settings->{'Password'});
759 my $effective_settings = eval { $self->communigate_pro_runcommand(
760 'GetAccountEffectiveSettings',
765 delete($effective_settings->{'Password'});
767 #prefs/effectiveprefs too
769 my $prefs = eval { $self->communigate_pro_runcommand(
775 my $effective_prefs = eval { $self->communigate_pro_runcommand(
776 'GetAccountEffectivePrefs',
781 %$effective_settings = ( %$effective_settings,
782 map { ("Pref $_" => $effective_prefs->{$_}); }
783 keys(%$effective_prefs)
785 %$settings = ( %$settings,
786 map { ("Pref $_" => $prefs->{$_}); }
791 my $rules = eval { $self->communigate_pro_runcommand(
792 'GetAccountMailRules',
797 %$effective_settings = ( %$effective_settings,
798 map _rule2string($_), @$rules
800 %$settings = ( %$settings,
801 map _rule2string($_), @$rules
805 my $aliases = eval { $self->communigate_pro_runcommand(
811 $effective_settings->{'Aliases'} = join(', ', @$aliases);
812 $settings->{'Aliases'} = join(', ', @$aliases);
814 #false laziness w/above
816 my %defaults = map { $_ => 1 }
817 grep !exists(${$settings}{$_}), keys %$effective_settings;
819 foreach my $key ( grep ref($effective_settings->{$_}),
820 keys %$effective_settings )
822 my $value = $effective_settings->{$key};
823 if ( ref($value) eq 'ARRAY' ) {
824 $effective_settings->{$key} = join(' ', @$value);
827 warn "serializing ". ref($value). " for table display not yet handled";
831 %{$settingsref} = %$effective_settings;
832 %{$defaultref} = %defaults;
838 sub export_getsettings_svc_forward {
839 my($self, $svc_forward, $settingsref, $defaultref ) = @_;
841 my $dest = eval { $self->communigate_pro_runcommand(
843 ($svc_forward->src || $svc_forward->srcsvc_acct->email),
847 my $settings = { 'Destination' => $dest };
849 %{$settingsref} = %$settings;
857 my($priority, $name, $conditions, $actions, $comment) = @$rule;
858 $conditions = join(', ', map { my $a = $_; join(' ', @$a); } @$conditions);
859 $actions = join(', ', map { my $a = $_; join(' ', @$a); } @$actions);
860 ("Mail rule $name" => "$priority IF $conditions THEN $actions ($comment)");
863 sub export_getsettings_svc_mailinglist {
864 my($self, $svc_mailinglist, $settingsref, $defaultref ) = @_;
866 my $settings = eval { $self->communigate_pro_runcommand(
868 $svc_mailinglist->username.'@'.$svc_mailinglist->domain,
872 $settings->{'Members'} = join(', ', @{ $settings->{'Members'} } );
874 %{$settingsref} = %$settings;
879 sub communigate_pro_queue {
880 my( $self, $svcnum, $method ) = (shift, shift, shift);
881 my $jobnum = ''; #don't actually care
882 $self->communigate_pro_queue_dep( \$jobnum, $svcnum, $method, @_);
885 sub communigate_pro_queue_dep {
886 my( $self, $jobnumref, $svcnum, $method ) = splice(@_,0,4);
888 my %kludge_methods = (
889 #'CreateAccount' => 'CreateAccount',
890 'UpdateAccountSettings' => 'UpdateAccountSettings',
891 'UpdateAccountPrefs' => 'cp_Scalar_Hash',
892 #'CreateDomain' => 'cp_Scalar_Hash',
893 #'CreateSharedDomain' => 'cp_Scalar_Hash',
894 'UpdateDomainSettings' => 'cp_Scalar_settingsHash',
895 'SetDomainAliases' => 'cp_Scalar_Array',
896 'SetAccountDefaults' => 'cp_Scalar_settingsHash',
897 'UpdateAccountDefaults' => 'cp_Scalar_settingsHash',
898 'SetAccountDefaultPrefs' => 'cp_Scalar_settingsHash',
899 'UpdateAccountDefaultPrefs' => 'cp_Scalar_settingsHash',
901 my $sub = exists($kludge_methods{$method})
902 ? $kludge_methods{$method}
903 : 'communigate_pro_command';
905 my $queue = new FS::queue {
907 'job' => "FS::part_export::communigate_pro::$sub",
909 my $error = $queue->insert(
911 $self->option('port'),
912 $self->option('login'),
913 $self->option('password'),
917 $$jobnumref = $queue->jobnum unless $error;
922 sub communigate_pro_runcommand {
923 my( $self, $method ) = (shift, shift);
925 communigate_pro_command(
927 $self->option('port'),
928 $self->option('login'),
929 $self->option('password'),
936 #XXX one sub per arg prototype is lame. more magic? i suppose queue needs
937 # to store data strctures properly instead of just an arg list. right.
940 my( $machine, $port, $login, $password, $method, $scalar, %hash ) = @_;
941 my @args = ( $scalar, \%hash );
942 communigate_pro_command( $machine, $port, $login, $password, $method, @args );
945 sub cp_Scalar_Array {
946 my( $machine, $port, $login, $password, $method, $scalar, @array ) = @_;
947 my @args = ( $scalar, \@array );
948 communigate_pro_command( $machine, $port, $login, $password, $method, @args );
952 # my( $machine, $port, $login, $password, $method, %hash ) = @_;
953 # my @args = ( \%hash );
954 # communigate_pro_command( $machine, $port, $login, $password, $method, @args );
957 sub cp_Scalar_settingsHash {
958 my( $machine, $port, $login, $password, $method, $domain, %settings ) = @_;
959 for (qw( AccessModes DomainAccessModes )) {
960 $settings{$_} = [split(' ',$settings{$_})] if $settings{$_};
962 my @args = ( 'domain' => $domain, 'settings' => \%settings );
963 communigate_pro_command( $machine, $port, $login, $password, $method, @args );
967 # my( $machine, $port, $login, $password, $method, %args ) = @_;
968 # my $accountName = delete $args{'accountName'};
969 # my $accountType = delete $args{'accountType'};
970 # my $externalFlag = delete $args{'externalFlag'};
971 # $args{'AccessModes'} = [ split(' ', $args{'AccessModes'}) ];
972 # my @args = ( accountName => $accountName,
973 # accountType => $accountType,
974 # settings => \%args,
976 # #externalFlag => $externalFlag,
977 # push @args, externalFlag => $externalFlag if $externalFlag;
979 # communigate_pro_command( $machine, $port, $login, $password, $method, @args );
983 sub UpdateAccountSettings {
984 my( $machine, $port, $login, $password, $method, $accountName, %args ) = @_;
985 $args{'AccessModes'} = [ split(' ', $args{'AccessModes'}) ];
986 my @args = ( $accountName, \%args );
987 communigate_pro_command( $machine, $port, $login, $password, $method, @args );
990 sub communigate_pro_command { #subroutine, not method
991 my( $machine, $port, $login, $password, $method, @args ) = @_;
996 my $cli = new CGP::CLI( {
997 'PeerAddr' => $machine,
1000 'password' => $password,
1001 } ) or die "Can't login to CGPro: $CGP::ERR_STRING\n";
1003 #warn "$method ". Dumper(@args) if $DEBUG;
1005 my $return = $cli->$method(@args)
1006 or die "Communigate Pro error: ". $cli->getErrMessage. "\n";
1008 $cli->Logout; # or die "Can't logout of CGPro: $CGP::ERR_STRING\n";