1 package FS::part_export::communigate_pro;
7 @ISA = qw(FS::part_export);
12 my($self, $svc_acct) = (shift, shift);
17 my( $self, $svc_acct ) = (shift, shift);
18 my @options = ( $svc_acct->svcnum, 'CreateAccount',
19 'accountName' => $self->export_username($svc_acct),
20 'accountType' => $self->option('accountType'),
21 'AccessModes' => $self->option('AccessModes'),
22 'RealName' => $svc_acct->finger,
23 'Password' => $svc_acct->_password,
25 push @options, 'MaxAccountSize' => $svc_acct->quota if $svc_acct->quota;
26 push @options, 'externalFlag' => $self->option('externalFlag')
27 if $self->option('externalFlag');
29 $self->communigate_pro_queue( @options );
33 my( $self, $new, $old ) = (shift, shift, shift);
34 return "can't (yet) change username with CommuniGate Pro"
35 if $old->username ne $new->username;
36 return "can't (yet) change domain with CommuniGate Pro"
37 if $self->export_username($old) ne $self->export_username($new);
38 return "can't (yet) change GECOS with CommuniGate Pro"
39 if $old->finger ne $new->finger;
40 return "can't (yet) change quota with CommuniGate Pro"
41 if $old->quota ne $new->quota;
42 return '' unless $old->username ne $new->username
43 || $old->_password ne $new->_password
44 || $old->finger ne $new->finger
45 || $old->quota ne $new->quota;
47 return '' if '*SUSPENDED* '. $old->_password eq $new->_password;
49 #my $err_or_queue = $self->communigate_pro_queue( $new->svcnum,'RenameAccount',
50 # $old->email, $new->email );
51 #return $err_or_queue unless ref($err_or_queue);
52 #my $jobnum = $err_or_queue->jobnum;
54 $self->communigate_pro_queue( $new->svcnum, 'SetAccountPassword',
55 $self->export_username($new), $new->_password )
56 if $new->_password ne $old->_password;
61 my( $self, $svc_acct ) = (shift, shift);
62 $self->communigate_pro_queue( $svc_acct->svcnum, 'DeleteAccount',
63 $self->export_username($svc_acct),
68 my( $self, $svc_acct ) = (shift, shift);
69 $self->communigate_pro_queue( $svc_acct->svcnum, 'UpdateAccountSettings',
70 'accountName' => $self->export_username($svc_acct),
71 'AccessModes' => 'Mail',
75 sub _export_unsuspend {
76 my( $self, $svc_acct ) = (shift, shift);
77 $self->communigate_pro_queue( $svc_acct->svcnum, 'UpdateAccountSettings',
78 'accountName' => $self->export_username($svc_acct),
79 'AccessModes' => $self->option('AccessModes'),
83 sub communigate_pro_queue {
84 my( $self, $svcnum, $method ) = (shift, shift, shift);
85 my @kludge_methods = qw(CreateAccount UpdateAccountSettings);
86 my $sub = 'communigate_pro_command';
87 $sub = $method if grep { $method eq $_ } @kludge_methods;
88 my $queue = new FS::queue {
90 'job' => "FS::part_export::communigate_pro::$sub",
94 $self->option('port'),
95 $self->option('login'),
96 $self->option('password'),
104 my( $machine, $port, $login, $password, $method, %args ) = @_;
105 my $accountName = delete $args{'accountName'};
106 my $accountType = delete $args{'accountType'};
107 my $externalFlag = delete $args{'externalFlag'};
108 $args{'AccessModes'} = [ split(' ', $args{'AccessModes'}) ];
109 my @args = ( accountName => $accountName,
110 accountType => $accountType,
113 #externalFlag => $externalFlag,
114 push @args, externalFlag => $externalFlag if $externalFlag;
116 communigate_pro_command( $machine, $port, $login, $password, $method, @args );
120 sub UpdateAccountSettings {
121 my( $machine, $port, $login, $password, $method, %args ) = @_;
122 my $accountName = delete $args{'accountName'};
123 $args{'AccessModes'} = [ split(' ', $args{'AccessModes'}) ];
124 @args = ( $accountName, \%args );
125 communigate_pro_command( $machine, $port, $login, $password, $method, @args );
128 sub communigate_pro_command { #subroutine, not method
129 my( $machine, $port, $login, $password, $method, @args ) = @_;
133 my $cli = new CGP::CLI( {
134 'PeerAddr' => $machine,
137 'password' => $password,
138 } ) or die "Can't login to CGPro: $CGP::ERR_STRING\n";
140 $cli->$method(@args) or die "CGPro error: ". $cli->getErrMessage;
142 $cli->Logout or die "Can't logout of CGPro: $CGP::ERR_STRING\n";