1 package FS::part_export::communigate_pro;
7 @ISA = qw(FS::part_export);
12 my( $self, $svc_acct ) = (shift, shift);
13 my @options = ( $svc_acct->svcnum, 'CreateAccount',
14 'accountName' => $svc_acct->email,
15 'accountType' => $self->option('accountType'),
16 'AccessModes' => $self->option('AccessModes'),
17 'RealName' => $svc_acct->finger,
18 'Password' => $svc_acct->_password,
20 push @options, 'MaxAccountSize' => $svc_acct->quota if $svc_acct->quota;
21 push @options, 'externalFlag' => $self->option('externalFlag')
22 if $self->option('externalFlag');
24 $self->communigate_pro_queue( @options );
28 my( $self, $new, $old ) = (shift, shift, shift);
29 return "can't (yet) change domain with CommuniGate Pro"
30 if $old->domain ne $new->domain;
31 return "can't (yet) change username with CommuniGate Pro"
32 if $old->username ne $new->username;
33 return "can't (yet) change GECOS with CommuniGate Pro"
34 if $old->finger ne $new->finger;
35 return "can't (yet) change quota with CommuniGate Pro"
36 if $old->quota ne $new->quota;
37 return '' unless $old->username ne $new->username
38 || $old->_password ne $new->_password
39 || $old->finger ne $new->finger
40 || $old->quota ne $new->quota;
42 return '' if '*SUSPENDED* '. $old->_password eq $new->_password;
44 #my $err_or_queue = $self->communigate_pro_queue( $new->svcnum,'RenameAccount',
45 # $old->email, $new->email );
46 #return $err_or_queue unless ref($err_or_queue);
47 #my $jobnum = $err_or_queue->jobnum;
49 $self->communigate_pro_queue( $new->svcnum, 'SetAccountPassword',
50 $new->email, $new->_password )
51 if $new->_password ne $old->_password;
56 my( $self, $svc_acct ) = (shift, shift);
57 $self->communigate_pro_queue( $svc_acct->svcnum, 'DeleteAccount',
63 my( $self, $svc_acct ) = (shift, shift);
64 $self->communigate_pro_queue( $svc_acct->svcnum, 'UpdateAccountSettings',
65 'accountName' => $svc_acct->email,
66 'AccessModes' => 'Mail',
70 sub _export_unsuspend {
71 my( $self, $svc_acct ) = (shift, shift);
72 $self->communigate_pro_queue( $svc_acct->svcnum, 'UpdateAccountSettings',
73 'accountName' => $svc_acct->email,
74 'AccessModes' => $self->option('AccessModes'),
78 sub communigate_pro_queue {
79 my( $self, $svcnum, $method ) = (shift, shift, shift);
80 my @kludge_methods = qw(CreateAccount UpdateAccountSettings);
81 my $sub = 'communigate_pro_command';
82 $sub = $method if grep { $method eq $_ } @kludge_methods;
83 my $queue = new FS::queue {
85 'job' => "FS::part_export::communigate_pro::$sub",
89 $self->option('port'),
90 $self->option('login'),
91 $self->option('password'),
99 my( $machine, $port, $login, $password, $method, %args ) = @_;
100 my $accountName = delete $args{'accountName'};
101 my $accountType = delete $args{'accountType'};
102 my $externalFlag = delete $args{'externalFlag'};
103 $args{'AccessModes'} = [ split(' ', $args{'AccessModes'}) ];
104 my @args = ( accountName => $accountName,
105 accountType => $accountType,
108 #externalFlag => $externalFlag,
109 push @args, externalFlag => $externalFlag if $externalFlag;
111 communigate_pro_command( $machine, $port, $login, $password, $method, @args );
115 sub UpdateAccountSettings {
116 my( $machine, $port, $login, $password, $method, %args ) = @_;
117 my $accountName = delete $args{'accountName'};
118 $args{'AccessModes'} = [ split(' ', $args{'AccessModes'}) ];
119 @args = ( $accountName, \%args );
120 communigate_pro_command( $machine, $port, $login, $password, $method, @args );
123 sub communigate_pro_command { #subroutine, not method
124 my( $machine, $port, $login, $password, $method, @args ) = @_;
128 my $cli = new CGP::CLI( {
129 'PeerAddr' => $machine,
132 'password' => $password,
133 } ) or die "Can't login to CGPro: $CGP::ERR_STRING\n";
135 $cli->$method(@args) or die "CGPro error: ". $cli->getErrMessage;
137 $cli->Logout or die "Can't logout of CGPro: $CGP::ERR_STRING\n";