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 #phase 2: language, time zone, layout, pronto style, send read receipts
114 my $pref_err = $self->communigate_pro_queue( $svc_acct->svcnum,
115 'UpdateAccountPrefs',
116 $self->export_username($svc_acct),
119 warn "WARNING: error queueing UpdateAccountPrefs job: $pref_err"
124 if ( $svc_acct->cgp_aliases ) {
125 my $alias_err = $self->communigate_pro_queue( $svc_acct->svcnum,
127 $self->export_username($svc_acct),
128 [ split(/\s*[,\s]\s*/, $svc_acct->cgp_aliases) ],
130 warn "WARNING: error queueing SetAccountAliases job: $alias_err"
138 sub _export_insert_svc_domain {
139 my( $self, $svc_domain ) = (shift, shift);
141 my $create = $self->option('create_domain') || 'CreateDomain';
144 'DomainAccessModes' => [ split(' ', $svc_domain->cgp_accessmodes ) ],
146 $settings{'AccountsLimit'} = $svc_domain->max_accounts
147 if $svc_domain->max_accounts;
148 $settings{'AdminDomainName'} = $svc_domain->parent_svc_x->domain
149 if $svc_domain->parent_svcnum;
150 $settings{'TrailerText'} = $svc_domain->trailer
151 if $svc_domain->trailer;
153 my @options = ( $create, $svc_domain->domain, \%settings );
155 eval { $self->communigate_pro_runcommand( @options ) };
159 if ( $svc_domain->cgp_aliases ) {
160 my $alias_err = $self->communigate_pro_queue( $svc_domain->svcnum,
163 split(/\s*[,\s]\s*/, $svc_domain->cgp_aliases),
165 warn "WARNING: error queueing SetDomainAliases job: $alias_err"
170 my $def_err = $self->communigate_pro_queue( $svc_domain->svcnum,
171 'SetAccountDefaults',
173 'PWDAllowed' =>($svc_domain->acct_def_password_selfchange ? 'YES':'NO'),
174 'PasswordRecovery' => ($svc_domain->acct_def_password_recover ? 'YES':'NO'),
175 'AccessModes' => $svc_domain->acct_def_cgp_accessmodes,
176 'MaxAccountSize' => $svc_domain->acct_def_quota,
177 'MaxWebSize' => $svc_domain->acct_def_file_quota,
178 'MaxWebFile' => $svc_domain->acct_def_file_maxnum,
179 'MaxFileSize' => $svc_domain->acct_def_file_maxsize,
180 'RulesAllowed' => $svc_domain->acct_def_cgp_rulesallowed,
181 'RPOPAllowed' =>($svc_domain->acct_def_cgp_rpopallowed ?'YES':'NO'),
182 'MailToAll' =>($svc_domain->acct_def_cgp_mailtoall ?'YES':'NO'),
183 'AddMailTrailer' =>($svc_domain->acct_def_cgp_addmailtrailer ?'YES':'NO'),
185 warn "WARNING: error queueing SetAccountDefaults job: $def_err"
188 #account defaults prefs
189 my $pref_err = $self->communigate_pro_queue( $svc_domain->svcnum,
190 'SetAccountDefaultPrefs',
192 'DeleteMode' => $svc_domain->acct_def_cgp_deletemode,
193 'EmptyTrash' => $svc_domain->acct_def_cgp_emptytrash,
195 warn "WARNING: error queueing SetAccountDefaultPrefs job: $pref_err"
202 sub _export_insert_svc_forward {
203 my( $self, $svc_forward ) = (shift, shift);
205 my $src = $svc_forward->src || $svc_forward->srcsvc_acct->email;
206 my $dst = $svc_forward->dst || $svc_forward->dstsvc_acct->email;
208 #real-time here, presuming CGP does some dup detection?
209 eval { $self->communigate_pro_runcommand( 'CreateForwarder', $src, $dst); };
215 sub _export_insert_svc_mailinglist {
216 my( $self, $svc_mlist ) = (shift, shift);
218 my @members = map $_->email_address,
219 $svc_mlist->mailinglist->mailinglistmember;
221 #real-time here, presuming CGP does some dup detection
222 eval { $self->communigate_pro_runcommand(
224 $svc_mlist->username.'@'.$svc_mlist->domain,
225 { 'RealName' => $svc_mlist->listname,
226 'SetReplyTo' => ( $svc_mlist->reply_to ? 'YES' : 'NO' ),
227 'RemoveAuthor' => ( $svc_mlist->remove_from ? 'YES' : 'NO' ),
228 'RejectAuto' => ( $svc_mlist->reject_auto ? 'YES' : 'NO' ),
229 'RemoveToAndCc' => ( $svc_mlist->remove_to_and_cc ? 'YES' : 'NO' ),
230 'Members' => \@members,
240 sub _export_replace {
241 my( $self, $new, $old ) = (shift, shift, shift);
243 my $table = $new->table;
244 my $method = "_export_replace_$table";
245 $self->$method($new, $old, @_);
248 sub _export_replace_svc_acct {
249 my( $self, $new, $old ) = (shift, shift, shift);
251 #let's just do the rename part realtime rather than trying to queue
252 #w/dependencies. we don't want FS winding up out-of-sync with the wrong
253 #username and a queued job anyway. right??
254 if ( $self->export_username($old) ne $self->export_username($new) ) {
255 eval { $self->communigate_pro_runcommand(
257 $self->export_username($old),
258 $self->export_username($new),
263 if ( $new->_password ne $old->_password
264 && '*SUSPENDED* '.$old->_password ne $new->_password
266 $self->communigate_pro_queue( $new->svcnum, 'SetAccountPassword',
267 $self->export_username($new), $new->_password
273 $settings{'RealName'} = $new->finger
274 if $old->finger ne $new->finger;
275 $settings{$quotas{$_}} = $new->$_()
276 foreach grep $old->$_() ne $new->$_(), keys %quotas;
277 $settings{'accountType'} = $new->cgp_type
278 if $old->cgp_type ne $new->cgp_type;
279 $settings{'AccessModes'} = $new->cgp_accessmodes
280 if $old->cgp_accessmodes ne $new->cgp_accessmodes
281 || $old->cgp_type ne $new->cgp_type;
283 $settings{'PasswordRecovery'} = ( $new->password_recover ? 'YES':'NO' )
284 if $old->password_recover ne $new->password_recover;
286 $settings{'RulesAllowed'} = $new->cgp_rulesallowed
287 if $old->cgp_rulesallowed ne $new->cgp_rulesallowed;
288 $settings{'RPOPAllowed'} = ( $new->cgp_rpopallowed ? 'YES':'NO' )
289 if $old->cgp_rpopallowed ne $new->cgp_rpopallowed;
290 $settings{'MailToAll'} = ( $new->cgp_mailtoall ? 'YES':'NO' )
291 if $old->cgp_mailtoall ne $new->cgp_mailtoall;
292 $settings{'AddMailTrailer'} = ( $new->cgp_addmailtrailer ? 'YES':'NO' )
293 if $old->cgp_addmailtrailer ne $new->cgp_addmailtrailer;
295 #XXX phase 3: archive messages, mailing lists
297 if ( keys %settings ) {
298 my $error = $self->communigate_pro_queue(
300 'UpdateAccountSettings',
301 $self->export_username($new),
304 return $error if $error;
309 $prefs{'DeleteMode'} = $new->cgp_deletemode
310 if $old->cgp_deletemode ne $new->cgp_deletemode;
311 $prefs{'EmptyTrash'} = $new->cgp_emptytrash
312 if $old->cgp_emptytrash ne $new->cgp_emptytrash;
313 #phase 2: language, time zone, layout, pronto style, send read receipts
315 my $pref_err = $self->communigate_pro_queue( $new->svcnum,
316 'UpdateAccountPrefs',
317 $self->export_username($new),
320 warn "WARNING: error queueing UpdateAccountPrefs job: $pref_err"
324 if ( $old->cgp_aliases ne $new->cgp_aliases ) {
325 my $error = $self->communigate_pro_queue(
328 $self->export_username($new),
329 [ split(/\s*[,\s]\s*/, $new->cgp_aliases) ],
331 return $error if $error;
338 sub _export_replace_svc_domain {
339 my( $self, $new, $old ) = (shift, shift, shift);
341 if ( $old->domain ne $new->domain ) {
342 my $error = $self->communigate_pro_queue( $new->svcnum, 'RenameDomain',
343 $old->domain, $new->domain,
345 return $error if $error;
348 $settings{'AccountsLimit'} = $new->max_accounts
349 if $old->max_accounts ne $new->max_accounts;
350 $settings{'TrailerText'} = $new->trailer
351 if $old->trailer ne $new->trailer;
352 $settings{'DomainAccessModes'} = $new->cgp_accessmodes
353 if $old->cgp_accessmodes ne $new->cgp_accessmodes;
354 $settings{'AdminDomainName'} =
355 $new->parent_svcnum ? $new->parent_svc_x->domain : ''
356 if $old->parent_svcnum != $new->parent_svcnum;
358 if ( keys %settings ) {
359 my $error = $self->communigate_pro_queue( $new->svcnum,
360 'UpdateDomainSettings',
364 return $error if $error;
367 if ( $old->cgp_aliases ne $new->cgp_aliases ) {
368 my $error = $self->communigate_pro_queue( $new->svcnum,
371 split(/\s*[,\s]\s*/, $new->cgp_aliases),
373 return $error if $error;
376 #below this identical to insert... any value to doing an Update here?
377 #not seeing any big one... i guess it would be nice to avoid the update
378 #when things haven't changed
381 my $def_err = $self->communigate_pro_queue( $new->svcnum,
382 'SetAccountDefaults',
384 'PWDAllowed' => ( $new->acct_def_password_selfchange ? 'YES' : 'NO' ),
385 'PasswordRecovery' => ( $new->acct_def_password_recover ? 'YES' : 'NO' ),
386 'AccessModes' => $new->acct_def_cgp_accessmodes,
387 'MaxAccountSize' => $new->acct_def_quota,
388 'MaxWebSize' => $new->acct_def_file_quota,
389 'MaxWebFile' => $new->acct_def_file_maxnum,
390 'MaxFileSize' => $new->acct_def_file_maxsize,
391 'RulesAllowed' => $new->acct_def_cgp_rulesallowed,
392 'RPOPAllowed' => ( $new->acct_def_cgp_rpopallowed ? 'YES' : 'NO' ),
393 'MailToAll' => ( $new->acct_def_cgp_mailtoall ? 'YES' : 'NO' ),
394 'AddMailTrailer' => ( $new->acct_def_cgp_addmailtrailer ? 'YES' : 'NO' ),
396 warn "WARNING: error queueing SetAccountDefaults job: $def_err"
399 #account defaults prefs
400 my $pref_err = $self->communigate_pro_queue( $new->svcnum,
401 'SetAccountDefaultPrefs',
403 'DeleteMode' => $new->acct_def_cgp_deletemode,
404 'EmptyTrash' => $new->acct_def_cgp_emptytrash,
406 warn "WARNING: error queueing SetAccountDefaultPrefs job: $pref_err"
412 sub _export_replace_svc_forward {
413 my( $self, $new, $old ) = (shift, shift, shift);
415 my $osrc = $old->src || $old->srcsvc_acct->email;
416 my $nsrc = $new->src || $new->srcsvc_acct->email;
417 my $odst = $old->dst || $old->dstsvc_acct->email;
418 my $ndst = $new->dst || $new->dstsvc_acct->email;
420 if ( $odst ne $ndst ) {
422 #no change command, so delete and create (real-time)
423 eval { $self->communigate_pro_runcommand('DeleteForwarder', $osrc) };
425 eval { $self->communigate_pro_runcommand('CreateForwarder', $nsrc, $ndst)};
428 } elsif ( $osrc ne $nsrc ) {
430 #real-time here, presuming CGP does some dup detection?
431 eval { $self->communigate_pro_runcommand( 'RenameForwarder', $osrc, $nsrc)};
435 warn "communigate replace called for svc_forward with no changes\n";#confess
441 sub _export_replace_svc_mailinglist {
442 my( $self, $new, $old ) = (shift, shift, shift);
444 my $oldGroupName = $old->username.'@'.$old->domain;
445 my $newGroupName = $new->username.'@'.$new->domain;
447 if ( $oldGroupName ne $newGroupName ) {
448 eval { $self->communigate_pro_runcommand(
449 'RenameGroup', $oldGroupName, $newGroupName ); };
453 my @members = map $_->email_address,
454 $new->mailinglist->mailinglistmember;
456 #real-time here, presuming CGP does some dup detection
457 eval { $self->communigate_pro_runcommand(
458 'SetGroup', $newGroupName,
459 { 'RealName' => $new->listname,
460 'SetReplyTo' => ( $new->reply_to ? 'YES' : 'NO' ),
461 'RemoveAuthor' => ( $new->remove_from ? 'YES' : 'NO' ),
462 'RejectAuto' => ( $new->reject_auto ? 'YES' : 'NO' ),
463 'RemoveToAndCc' => ( $new->remove_to_and_cc ? 'YES' : 'NO' ),
464 'Members' => \@members,
475 my( $self, $svc_x ) = (shift, shift);
477 my $table = $svc_x->table;
478 my $method = "_export_delete_$table";
479 $self->$method($svc_x, @_);
482 sub _export_delete_svc_acct {
483 my( $self, $svc_acct ) = (shift, shift);
485 $self->communigate_pro_queue( $svc_acct->svcnum, 'DeleteAccount',
486 $self->export_username($svc_acct),
490 sub _export_delete_svc_domain {
491 my( $self, $svc_domain ) = (shift, shift);
493 $self->communigate_pro_queue( $svc_domain->svcnum, 'DeleteDomain',
495 #XXX turn on force option for domain deletion?
499 sub _export_delete_svc_forward {
500 my( $self, $svc_forward ) = (shift, shift);
502 $self->communigate_pro_queue( $svc_forward->svcnum, 'DeleteForwarder',
503 ($svc_forward->src || $svc_forward->srcsvc_acct->email),
507 sub _export_delete_svc_mailinglist {
508 my( $self, $svc_mailinglist ) = (shift, shift);
510 #real-time here, presuming CGP does some dup detection
511 eval { $self->communigate_pro_runcommand(
513 $svc_mailinglist->username.'@'.$svc_mailinglist->domain,
522 sub _export_suspend {
523 my( $self, $svc_x ) = (shift, shift);
525 my $table = $svc_x->table;
526 my $method = "_export_suspend_$table";
527 $self->$method($svc_x, @_);
531 sub _export_suspend_svc_acct {
532 my( $self, $svc_acct ) = (shift, shift);
534 #XXX is this the desired suspnsion action?
536 $self->communigate_pro_queue(
538 'UpdateAccountSettings',
539 $self->export_username($svc_acct),
540 'AccessModes' => 'Mail',
545 sub _export_suspend_svc_domain {
546 my( $self, $svc_domain) = (shift, shift);
548 #XXX domain operations
553 sub _export_unsuspend {
554 my( $self, $svc_x ) = (shift, shift);
556 my $table = $svc_x->table;
557 my $method = "_export_unsuspend_$table";
558 $self->$method($svc_x, @_);
562 sub _export_unsuspend_svc_acct {
563 my( $self, $svc_acct ) = (shift, shift);
565 $self->communigate_pro_queue(
567 'UpdateAccountSettings',
568 $self->export_username($svc_acct),
569 'AccessModes' => ( $svc_acct->cgp_accessmodes
570 || $self->option('AccessModes') ),
575 sub _export_unsuspend_svc_domain {
576 my( $self, $svc_domain) = (shift, shift);
578 #XXX domain operations
583 sub export_mailinglistmember_insert {
584 my( $self, $svc_mailinglist, $mailinglistmember ) = (shift, shift, shift);
585 $svc_mailinglist->replace();
588 sub export_mailinglistmember_replace {
589 my( $self, $svc_mailinglist, $new, $old ) = (shift, shift, shift, shift);
590 die "no way to do this from the UI right now";
593 sub export_mailinglistmember_delete {
594 my( $self, $svc_mailinglist, $mailinglistmember ) = (shift, shift, shift);
595 $svc_mailinglist->replace();
598 sub export_getsettings {
599 my($self, $svc_x) = (shift, shift);
601 my $table = $svc_x->table;
602 my $method = "export_getsettings_$table";
604 $self->can($method) ? $self->$method($svc_x, @_) : '';
608 sub export_getsettings_svc_domain {
609 my($self, $svc_domain, $settingsref, $defaultref ) = @_;
611 my $settings = eval { $self->communigate_pro_runcommand(
617 my $effective_settings = eval { $self->communigate_pro_runcommand(
618 'GetDomainEffectiveSettings',
623 my $acct_defaults = eval { $self->communigate_pro_runcommand(
624 'GetAccountDefaults',
629 my $acct_defaultprefs = eval { $self->communigate_pro_runcommand(
630 'GetAccountDefaultPrefs',
635 %$effective_settings = (
636 %$effective_settings,
637 ( map { ("Acct. Default $_" => $acct_defaults->{$_}); }
638 keys(%$acct_defaults)
640 ( map { ("Acct. Default $_" => $acct_defaultprefs->{$_}); } #diff label??
641 keys(%$acct_defaultprefs)
646 ( map { ("Acct. Default $_" => $acct_defaults->{$_}); }
647 keys(%$acct_defaults)
649 ( map { ("Acct. Default $_" => $acct_defaultprefs->{$_}); } #diff label??
650 keys(%$acct_defaultprefs)
655 my $aliases = eval { $self->communigate_pro_runcommand(
661 $effective_settings->{'Aliases'} = join(', ', @$aliases);
662 $settings->{'Aliases'} = join(', ', @$aliases);
665 #false laziness w/below
667 my %defaults = map { $_ => 1 }
668 grep !exists(${$settings}{$_}), keys %$effective_settings;
670 foreach my $key ( grep ref($effective_settings->{$_}),
671 keys %$effective_settings )
673 my $value = $effective_settings->{$key};
674 if ( ref($value) eq 'ARRAY' ) {
675 $effective_settings->{$key} = join(' ', @$value);
678 warn "serializing ". ref($value). " for table display not yet handled";
682 %{$settingsref} = %$effective_settings;
683 %{$defaultref} = %defaults;
688 sub export_getsettings_svc_acct {
689 my($self, $svc_acct, $settingsref, $defaultref ) = @_;
691 my $settings = eval { $self->communigate_pro_runcommand(
692 'GetAccountSettings',
697 delete($settings->{'Password'});
699 my $effective_settings = eval { $self->communigate_pro_runcommand(
700 'GetAccountEffectiveSettings',
705 delete($effective_settings->{'Password'});
707 #prefs/effectiveprefs too
709 my $prefs = eval { $self->communigate_pro_runcommand(
715 my $effective_prefs = eval { $self->communigate_pro_runcommand(
716 'GetAccountEffectivePrefs',
721 %$effective_settings = ( %$effective_settings,
722 map { ("Pref $_" => $effective_prefs->{$_}); }
723 keys(%$effective_prefs)
725 %$settings = ( %$settings,
726 map { ("Pref $_" => $prefs->{$_}); }
732 my $aliases = eval { $self->communigate_pro_runcommand(
738 $effective_settings->{'Aliases'} = join(', ', @$aliases);
739 $settings->{'Aliases'} = join(', ', @$aliases);
741 #false laziness w/above
743 my %defaults = map { $_ => 1 }
744 grep !exists(${$settings}{$_}), keys %$effective_settings;
746 foreach my $key ( grep ref($effective_settings->{$_}),
747 keys %$effective_settings )
749 my $value = $effective_settings->{$key};
750 if ( ref($value) eq 'ARRAY' ) {
751 $effective_settings->{$key} = join(' ', @$value);
754 warn "serializing ". ref($value). " for table display not yet handled";
758 %{$settingsref} = %$effective_settings;
759 %{$defaultref} = %defaults;
765 sub export_getsettings_svc_mailinglist {
766 my($self, $svc_mailinglist, $settingsref, $defaultref ) = @_;
768 my $settings = eval { $self->communigate_pro_runcommand(
770 $svc_mailinglist->username.'@'.$svc_mailinglist->domain,
774 $settings->{'Members'} = join(', ', @{ $settings->{'Members'} } );
776 %{$settingsref} = %$settings;
781 sub communigate_pro_queue {
782 my( $self, $svcnum, $method ) = (shift, shift, shift);
783 my $jobnum = ''; #don't actually care
784 $self->communigate_pro_queue_dep( \$jobnum, $svcnum, $method, @_);
787 sub communigate_pro_queue_dep {
788 my( $self, $jobnumref, $svcnum, $method ) = splice(@_,0,4);
790 my %kludge_methods = (
791 #'CreateAccount' => 'CreateAccount',
792 'UpdateAccountSettings' => 'UpdateAccountSettings',
793 'UpdateAccountPrefs' => 'cp_Scalar_Hash',
794 #'CreateDomain' => 'cp_Scalar_Hash',
795 #'CreateSharedDomain' => 'cp_Scalar_Hash',
796 'UpdateDomainSettings' => 'cp_Scalar_settingsHash',
797 'SetDomainAliases' => 'cp_Scalar_Array',
798 'SetAccountDefaults' => 'cp_Scalar_settingsHash',
799 'UpdateAccountDefaults' => 'cp_Scalar_settingsHash',
800 'SetAccountDefaultPrefs' => 'cp_Scalar_settingsHash',
801 'UpdateAccountDefaultPrefs' => 'cp_Scalar_settingsHash',
803 my $sub = exists($kludge_methods{$method})
804 ? $kludge_methods{$method}
805 : 'communigate_pro_command';
807 my $queue = new FS::queue {
809 'job' => "FS::part_export::communigate_pro::$sub",
811 my $error = $queue->insert(
813 $self->option('port'),
814 $self->option('login'),
815 $self->option('password'),
819 $$jobnumref = $queue->jobnum unless $error;
824 sub communigate_pro_runcommand {
825 my( $self, $method ) = (shift, shift);
827 communigate_pro_command(
829 $self->option('port'),
830 $self->option('login'),
831 $self->option('password'),
838 #XXX one sub per arg prototype is lame. more magic? i suppose queue needs
839 # to store data strctures properly instead of just an arg list. right.
842 my( $machine, $port, $login, $password, $method, $scalar, %hash ) = @_;
843 my @args = ( $scalar, \%hash );
844 communigate_pro_command( $machine, $port, $login, $password, $method, @args );
847 sub cp_Scalar_Array {
848 my( $machine, $port, $login, $password, $method, $scalar, @array ) = @_;
849 my @args = ( $scalar, \@array );
850 communigate_pro_command( $machine, $port, $login, $password, $method, @args );
854 # my( $machine, $port, $login, $password, $method, %hash ) = @_;
855 # my @args = ( \%hash );
856 # communigate_pro_command( $machine, $port, $login, $password, $method, @args );
859 sub cp_Scalar_settingsHash {
860 my( $machine, $port, $login, $password, $method, $domain, %settings ) = @_;
861 for (qw( AccessModes DomainAccessModes )) {
862 $settings{$_} = [split(' ',$settings{$_})] if $settings{$_};
864 my @args = ( 'domain' => $domain, 'settings' => \%settings );
865 communigate_pro_command( $machine, $port, $login, $password, $method, @args );
869 # my( $machine, $port, $login, $password, $method, %args ) = @_;
870 # my $accountName = delete $args{'accountName'};
871 # my $accountType = delete $args{'accountType'};
872 # my $externalFlag = delete $args{'externalFlag'};
873 # $args{'AccessModes'} = [ split(' ', $args{'AccessModes'}) ];
874 # my @args = ( accountName => $accountName,
875 # accountType => $accountType,
876 # settings => \%args,
878 # #externalFlag => $externalFlag,
879 # push @args, externalFlag => $externalFlag if $externalFlag;
881 # communigate_pro_command( $machine, $port, $login, $password, $method, @args );
885 sub UpdateAccountSettings {
886 my( $machine, $port, $login, $password, $method, $accountName, %args ) = @_;
887 $args{'AccessModes'} = [ split(' ', $args{'AccessModes'}) ];
888 my @args = ( $accountName, \%args );
889 communigate_pro_command( $machine, $port, $login, $password, $method, @args );
892 sub communigate_pro_command { #subroutine, not method
893 my( $machine, $port, $login, $password, $method, @args ) = @_;
898 my $cli = new CGP::CLI( {
899 'PeerAddr' => $machine,
902 'password' => $password,
903 } ) or die "Can't login to CGPro: $CGP::ERR_STRING\n";
905 #warn "$method ". Dumper(@args) if $DEBUG;
907 my $return = $cli->$method(@args)
908 or die "Communigate Pro error: ". $cli->getErrMessage. "\n";
910 $cli->Logout; # or die "Can't logout of CGPro: $CGP::ERR_STRING\n";