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 #phase 2: allowed mail rules, RPOP modifications, accepts mail to all, add trailer to sent mail
82 'RulesAllowed' => $svc_acct->cgp_rulesallowed,
83 'RPOPAllowed' =>($svc_acct->cgp_rpopallowed ?'YES':'NO'),
84 'MailToAll' =>($svc_acct->cgp_mailtoall ?'YES':'NO'),
85 'AddMailTrailer' =>($svc_acct->cgp_addmailtrailer ?'YES':'NO'),
87 map { $quotas{$_} => $svc_acct->$_() }
88 grep $svc_acct->$_(), keys %quotas
90 #XXX phase 2: pwdallowed, passwordrecovery
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 #phase 2: allowed mail rules, RPOP modifications, accepts mail to all, add trailer to sent mail
284 $settings{'RulesAllowed'} = $new->cgp_rulesallowed
285 if $old->cgp_rulesallowed ne $new->cgp_rulesallowed;
286 $settings{'RPOPAllowed'} = $new->cgp_rpopallowed
287 if $old->cgp_rpopallowed ne $new->cgp_rpopallowed;
288 $settings{'MailToAll'} = $new->cgp_mailtoall
289 if $old->cgp_mailtoall ne $new->cgp_mailtoall;
290 $settings{'AddMailTrailer'} = $new->cgp_addmailtrailer
291 if $old->cgp_addmailtrailer ne $new->cgp_addmailtrailer;
293 #XXX phase 2: pwdallowed, passwordrecovery
294 #XXX phase 3: archive messages, mailing lists
296 if ( keys %settings ) {
297 my $error = $self->communigate_pro_queue(
299 'UpdateAccountSettings',
300 $self->export_username($new),
303 return $error if $error;
308 $prefs{'DeleteMode'} = $new->cgp_deletemode
309 if $old->cgp_deletemode ne $new->cgp_deletemode;
310 $prefs{'EmptyTrash'} = $new->cgp_emptytrash
311 if $old->cgp_emptytrash ne $new->cgp_emptytrash;
312 #phase 2: language, time zone, layout, pronto style, send read receipts
314 my $pref_err = $self->communigate_pro_queue( $new->svcnum,
315 'UpdateAccountPrefs',
316 $self->export_username($new),
319 warn "WARNING: error queueing UpdateAccountPrefs job: $pref_err"
323 if ( $old->cgp_aliases ne $new->cgp_aliases ) {
324 my $error = $self->communigate_pro_queue(
327 $self->export_username($new),
328 [ split(/\s*[,\s]\s*/, $new->cgp_aliases) ],
330 return $error if $error;
337 sub _export_replace_svc_domain {
338 my( $self, $new, $old ) = (shift, shift, shift);
340 if ( $old->domain ne $new->domain ) {
341 my $error = $self->communigate_pro_queue( $new->svcnum, 'RenameDomain',
342 $old->domain, $new->domain,
344 return $error if $error;
347 $settings{'AccountsLimit'} = $new->max_accounts
348 if $old->max_accounts ne $new->max_accounts;
349 $settings{'TrailerText'} = $new->trailer
350 if $old->trailer ne $new->trailer;
351 $settings{'DomainAccessModes'} = $new->cgp_accessmodes
352 if $old->cgp_accessmodes ne $new->cgp_accessmodes;
353 $settings{'AdminDomainName'} =
354 $new->parent_svcnum ? $new->parent_svc_x->domain : ''
355 if $old->parent_svcnum != $new->parent_svcnum;
357 if ( keys %settings ) {
358 my $error = $self->communigate_pro_queue( $new->svcnum,
359 'UpdateDomainSettings',
363 return $error if $error;
366 if ( $old->cgp_aliases ne $new->cgp_aliases ) {
367 my $error = $self->communigate_pro_queue( $new->svcnum,
370 split(/\s*[,\s]\s*/, $new->cgp_aliases),
372 return $error if $error;
375 #below this identical to insert... any value to doing an Update here?
376 #not seeing any big one... i guess it would be nice to avoid the update
377 #when things haven't changed
380 my $def_err = $self->communigate_pro_queue( $new->svcnum,
381 'SetAccountDefaults',
383 'PWDAllowed' => ( $new->acct_def_password_selfchange ? 'YES' : 'NO' ),
384 'PasswordRecovery' => ( $new->acct_def_password_recover ? 'YES' : 'NO' ),
385 'AccessModes' => $new->acct_def_cgp_accessmodes,
386 'MaxAccountSize' => $new->acct_def_quota,
387 'MaxWebSize' => $new->acct_def_file_quota,
388 'MaxWebFile' => $new->acct_def_file_maxnum,
389 'MaxFileSize' => $new->acct_def_file_maxsize,
390 'RulesAllowed' => $new->acct_def_cgp_rulesallowed,
391 'RPOPAllowed' => ( $new->acct_def_cgp_rpopallowed ? 'YES' : 'NO' ),
392 'MailToAll' => ( $new->acct_def_cgp_mailtoall ? 'YES' : 'NO' ),
393 'AddMailTrailer' => ( $new->acct_def_cgp_addmailtrailer ? 'YES' : 'NO' ),
395 warn "WARNING: error queueing SetAccountDefaults job: $def_err"
398 #account defaults prefs
399 my $pref_err = $self->communigate_pro_queue( $new->svcnum,
400 'SetAccountDefaultPrefs',
402 'DeleteMode' => $new->acct_def_cgp_deletemode,
403 'EmptyTrash' => $new->acct_def_cgp_emptytrash,
405 warn "WARNING: error queueing SetAccountDefaultPrefs job: $pref_err"
411 sub _export_replace_svc_forward {
412 my( $self, $new, $old ) = (shift, shift, shift);
414 my $osrc = $old->src || $old->srcsvc_acct->email;
415 my $nsrc = $new->src || $new->srcsvc_acct->email;
416 my $odst = $old->dst || $old->dstsvc_acct->email;
417 my $ndst = $new->dst || $new->dstsvc_acct->email;
419 if ( $odst ne $ndst ) {
421 #no change command, so delete and create (real-time)
422 eval { $self->communigate_pro_runcommand('DeleteForwarder', $osrc) };
424 eval { $self->communigate_pro_runcommand('CreateForwarder', $nsrc, $ndst)};
427 } elsif ( $osrc ne $nsrc ) {
429 #real-time here, presuming CGP does some dup detection?
430 eval { $self->communigate_pro_runcommand( 'RenameForwarder', $osrc, $nsrc)};
434 warn "communigate replace called for svc_forward with no changes\n";#confess
440 sub _export_replace_svc_mailinglist {
441 my( $self, $new, $old ) = (shift, shift, shift);
443 my $oldGroupName = $old->username.'@'.$old->domain;
444 my $newGroupName = $new->username.'@'.$new->domain;
446 if ( $oldGroupName ne $newGroupName ) {
447 eval { $self->communigate_pro_runcommand(
448 'RenameGroup', $oldGroupName, $newGroupName ); };
452 my @members = map $_->email_address,
453 $new->mailinglist->mailinglistmember;
455 #real-time here, presuming CGP does some dup detection
456 eval { $self->communigate_pro_runcommand(
457 'SetGroup', $newGroupName,
458 { 'RealName' => $new->listname,
459 'SetReplyTo' => ( $new->reply_to ? 'YES' : 'NO' ),
460 'RemoveAuthor' => ( $new->remove_from ? 'YES' : 'NO' ),
461 'RejectAuto' => ( $new->reject_auto ? 'YES' : 'NO' ),
462 'RemoveToAndCc' => ( $new->remove_to_and_cc ? 'YES' : 'NO' ),
463 'Members' => \@members,
474 my( $self, $svc_x ) = (shift, shift);
476 my $table = $svc_x->table;
477 my $method = "_export_delete_$table";
478 $self->$method($svc_x, @_);
481 sub _export_delete_svc_acct {
482 my( $self, $svc_acct ) = (shift, shift);
484 $self->communigate_pro_queue( $svc_acct->svcnum, 'DeleteAccount',
485 $self->export_username($svc_acct),
489 sub _export_delete_svc_domain {
490 my( $self, $svc_domain ) = (shift, shift);
492 $self->communigate_pro_queue( $svc_domain->svcnum, 'DeleteDomain',
494 #XXX turn on force option for domain deletion?
498 sub _export_delete_svc_forward {
499 my( $self, $svc_forward ) = (shift, shift);
501 $self->communigate_pro_queue( $svc_forward->svcnum, 'DeleteForwarder',
502 ($svc_forward->src || $svc_forward->srcsvc_acct->email),
506 sub _export_delete_svc_mailinglist {
507 my( $self, $svc_mailinglist ) = (shift, shift);
509 #real-time here, presuming CGP does some dup detection
510 eval { $self->communigate_pro_runcommand(
512 $svc_mailinglist->username.'@'.$svc_mailinglist->domain,
521 sub _export_suspend {
522 my( $self, $svc_x ) = (shift, shift);
524 my $table = $svc_x->table;
525 my $method = "_export_suspend_$table";
526 $self->$method($svc_x, @_);
530 sub _export_suspend_svc_acct {
531 my( $self, $svc_acct ) = (shift, shift);
533 #XXX is this the desired suspnsion action?
535 $self->communigate_pro_queue(
537 'UpdateAccountSettings',
538 $self->export_username($svc_acct),
539 'AccessModes' => 'Mail',
544 sub _export_suspend_svc_domain {
545 my( $self, $svc_domain) = (shift, shift);
547 #XXX domain operations
552 sub _export_unsuspend {
553 my( $self, $svc_x ) = (shift, shift);
555 my $table = $svc_x->table;
556 my $method = "_export_unsuspend_$table";
557 $self->$method($svc_x, @_);
561 sub _export_unsuspend_svc_acct {
562 my( $self, $svc_acct ) = (shift, shift);
564 $self->communigate_pro_queue(
566 'UpdateAccountSettings',
567 $self->export_username($svc_acct),
568 'AccessModes' => ( $svc_acct->cgp_accessmodes
569 || $self->option('AccessModes') ),
574 sub _export_unsuspend_svc_domain {
575 my( $self, $svc_domain) = (shift, shift);
577 #XXX domain operations
582 sub export_mailinglistmember_insert {
583 my( $self, $svc_mailinglist, $mailinglistmember ) = (shift, shift, shift);
584 $svc_mailinglist->replace();
587 sub export_mailinglistmember_replace {
588 my( $self, $svc_mailinglist, $new, $old ) = (shift, shift, shift, shift);
589 die "no way to do this from the UI right now";
592 sub export_mailinglistmember_delete {
593 my( $self, $svc_mailinglist, $mailinglistmember ) = (shift, shift, shift);
594 $svc_mailinglist->replace();
597 sub export_getsettings {
598 my($self, $svc_x) = (shift, shift);
600 my $table = $svc_x->table;
601 my $method = "export_getsettings_$table";
603 $self->can($method) ? $self->$method($svc_x, @_) : '';
607 sub export_getsettings_svc_domain {
608 my($self, $svc_domain, $settingsref, $defaultref ) = @_;
610 my $settings = eval { $self->communigate_pro_runcommand(
616 my $effective_settings = eval { $self->communigate_pro_runcommand(
617 'GetDomainEffectiveSettings',
622 my $acct_defaults = eval { $self->communigate_pro_runcommand(
623 'GetAccountDefaults',
628 my $acct_defaultprefs = eval { $self->communigate_pro_runcommand(
629 'GetAccountDefaultPrefs',
634 %$effective_settings = (
635 %$effective_settings,
636 ( map { ("Acct. Default $_" => $acct_defaults->{$_}); }
637 keys(%$acct_defaults)
639 ( map { ("Acct. Default $_" => $acct_defaultprefs->{$_}); } #diff label??
640 keys(%$acct_defaultprefs)
645 ( map { ("Acct. Default $_" => $acct_defaults->{$_}); }
646 keys(%$acct_defaults)
648 ( map { ("Acct. Default $_" => $acct_defaultprefs->{$_}); } #diff label??
649 keys(%$acct_defaultprefs)
654 my $aliases = eval { $self->communigate_pro_runcommand(
660 $effective_settings->{'Aliases'} = join(', ', @$aliases);
661 $settings->{'Aliases'} = join(', ', @$aliases);
664 #false laziness w/below
666 my %defaults = map { $_ => 1 }
667 grep !exists(${$settings}{$_}), keys %$effective_settings;
669 foreach my $key ( grep ref($effective_settings->{$_}),
670 keys %$effective_settings )
672 my $value = $effective_settings->{$key};
673 if ( ref($value) eq 'ARRAY' ) {
674 $effective_settings->{$key} = join(' ', @$value);
677 warn "serializing ". ref($value). " for table display not yet handled";
681 %{$settingsref} = %$effective_settings;
682 %{$defaultref} = %defaults;
687 sub export_getsettings_svc_acct {
688 my($self, $svc_acct, $settingsref, $defaultref ) = @_;
690 my $settings = eval { $self->communigate_pro_runcommand(
691 'GetAccountSettings',
696 delete($settings->{'Password'});
698 my $effective_settings = eval { $self->communigate_pro_runcommand(
699 'GetAccountEffectiveSettings',
704 delete($effective_settings->{'Password'});
706 #prefs/effectiveprefs too
708 my $prefs = eval { $self->communigate_pro_runcommand(
714 my $effective_prefs = eval { $self->communigate_pro_runcommand(
715 'GetAccountEffectivePrefs',
720 %$effective_settings = ( %$effective_settings,
721 map { ("Pref $_" => $effective_prefs->{$_}); }
722 keys(%$effective_prefs)
724 %$settings = ( %$settings,
725 map { ("Pref $_" => $prefs->{$_}); }
731 my $aliases = eval { $self->communigate_pro_runcommand(
737 $effective_settings->{'Aliases'} = join(', ', @$aliases);
738 $settings->{'Aliases'} = join(', ', @$aliases);
740 #false laziness w/above
742 my %defaults = map { $_ => 1 }
743 grep !exists(${$settings}{$_}), keys %$effective_settings;
745 foreach my $key ( grep ref($effective_settings->{$_}),
746 keys %$effective_settings )
748 my $value = $effective_settings->{$key};
749 if ( ref($value) eq 'ARRAY' ) {
750 $effective_settings->{$key} = join(' ', @$value);
753 warn "serializing ". ref($value). " for table display not yet handled";
757 %{$settingsref} = %$effective_settings;
758 %{$defaultref} = %defaults;
764 sub export_getsettings_svc_mailinglist {
765 my($self, $svc_mailinglist, $settingsref, $defaultref ) = @_;
767 my $settings = eval { $self->communigate_pro_runcommand(
769 $svc_mailinglist->username.'@'.$svc_mailinglist->domain,
773 $settings->{'Members'} = join(', ', @{ $settings->{'Members'} } );
775 %{$settingsref} = %$settings;
780 sub communigate_pro_queue {
781 my( $self, $svcnum, $method ) = (shift, shift, shift);
782 my $jobnum = ''; #don't actually care
783 $self->communigate_pro_queue_dep( \$jobnum, $svcnum, $method, @_);
786 sub communigate_pro_queue_dep {
787 my( $self, $jobnumref, $svcnum, $method ) = splice(@_,0,4);
789 my %kludge_methods = (
790 #'CreateAccount' => 'CreateAccount',
791 'UpdateAccountSettings' => 'UpdateAccountSettings',
792 'UpdateAccountPrefs' => 'cp_Scalar_Hash',
793 #'CreateDomain' => 'cp_Scalar_Hash',
794 #'CreateSharedDomain' => 'cp_Scalar_Hash',
795 'UpdateDomainSettings' => 'cp_Scalar_settingsHash',
796 'SetDomainAliases' => 'cp_Scalar_Array',
797 'SetAccountDefaults' => 'cp_Scalar_settingsHash',
798 'UpdateAccountDefaults' => 'cp_Scalar_settingsHash',
799 'SetAccountDefaultPrefs' => 'cp_Scalar_settingsHash',
800 'UpdateAccountDefaultPrefs' => 'cp_Scalar_settingsHash',
802 my $sub = exists($kludge_methods{$method})
803 ? $kludge_methods{$method}
804 : 'communigate_pro_command';
806 my $queue = new FS::queue {
808 'job' => "FS::part_export::communigate_pro::$sub",
810 my $error = $queue->insert(
812 $self->option('port'),
813 $self->option('login'),
814 $self->option('password'),
818 $$jobnumref = $queue->jobnum unless $error;
823 sub communigate_pro_runcommand {
824 my( $self, $method ) = (shift, shift);
826 communigate_pro_command(
828 $self->option('port'),
829 $self->option('login'),
830 $self->option('password'),
837 #XXX one sub per arg prototype is lame. more magic? i suppose queue needs
838 # to store data strctures properly instead of just an arg list. right.
841 my( $machine, $port, $login, $password, $method, $scalar, %hash ) = @_;
842 my @args = ( $scalar, \%hash );
843 communigate_pro_command( $machine, $port, $login, $password, $method, @args );
846 sub cp_Scalar_Array {
847 my( $machine, $port, $login, $password, $method, $scalar, @array ) = @_;
848 my @args = ( $scalar, \@array );
849 communigate_pro_command( $machine, $port, $login, $password, $method, @args );
853 # my( $machine, $port, $login, $password, $method, %hash ) = @_;
854 # my @args = ( \%hash );
855 # communigate_pro_command( $machine, $port, $login, $password, $method, @args );
858 sub cp_Scalar_settingsHash {
859 my( $machine, $port, $login, $password, $method, $domain, %settings ) = @_;
860 for (qw( AccessModes DomainAccessModes )) {
861 $settings{$_} = [split(' ',$settings{$_})] if $settings{$_};
863 my @args = ( 'domain' => $domain, 'settings' => \%settings );
864 communigate_pro_command( $machine, $port, $login, $password, $method, @args );
868 # my( $machine, $port, $login, $password, $method, %args ) = @_;
869 # my $accountName = delete $args{'accountName'};
870 # my $accountType = delete $args{'accountType'};
871 # my $externalFlag = delete $args{'externalFlag'};
872 # $args{'AccessModes'} = [ split(' ', $args{'AccessModes'}) ];
873 # my @args = ( accountName => $accountName,
874 # accountType => $accountType,
875 # settings => \%args,
877 # #externalFlag => $externalFlag,
878 # push @args, externalFlag => $externalFlag if $externalFlag;
880 # communigate_pro_command( $machine, $port, $login, $password, $method, @args );
884 sub UpdateAccountSettings {
885 my( $machine, $port, $login, $password, $method, $accountName, %args ) = @_;
886 $args{'AccessModes'} = [ split(' ', $args{'AccessModes'}) ];
887 my @args = ( $accountName, \%args );
888 communigate_pro_command( $machine, $port, $login, $password, $method, @args );
891 sub communigate_pro_command { #subroutine, not method
892 my( $machine, $port, $login, $password, $method, @args ) = @_;
897 my $cli = new CGP::CLI( {
898 'PeerAddr' => $machine,
901 'password' => $password,
902 } ) or die "Can't login to CGPro: $CGP::ERR_STRING\n";
904 #warn "$method ". Dumper(@args) if $DEBUG;
906 my $return = $cli->$method(@args)
907 or die "Communigate Pro error: ". $cli->getErrMessage. "\n";
909 $cli->Logout; # or die "Can't logout of CGPro: $CGP::ERR_STRING\n";