summaryrefslogtreecommitdiff
path: root/FS/FS/part_export/everyone_net.pm
blob: 7386973e492dc6812803ee30a47b76ba4460b798 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
package FS::part_export::everyone_net;

use vars qw(@ISA %info);
use Tie::IxHash;
use FS::part_export;

@ISA = qw(FS::part_export);

tie my %options, 'Tie::IxHash',
  'clientID'  => { label=>'clientID' },
  'password'  => { label=>'Password' },
  #'workgroup' => { label=>'Default Workgroup' },
  'debug'     => { label=>'Enable debugging',
                    type=>'checkbox'          },
;

%info = (
  'svc'    => 'svc_acct',
  'desc'   => 'Real-time export to Everyone.net outsourced mail service',
  'options'=> \%options,
  'no_machine' => 1,
  'default_svc_class' => 'Email',
  'notes'  => <<'END'
Real-time export to
<a href="http://www.everyone.net/">Everyone.net</a> via the XRC Remote API.
Requires installation of
<a href="http://search.cpan.org/dist/Net-XRC">Net::XRC</a>
from CPAN.
END
);

sub rebless { shift; }

# experiement: want the status of these right away (don't want account to
# create or whatever and then get error in the queue from dup username or
# something), so no queueing

sub _export_insert {
  my( $self, $svc_acct ) = (shift, shift);

  eval "use Net::XRC qw(:types);";
  return $@ if $@;

  $self->_xrc_command( 'createUser',
                       $svc_acct->domain,
                       [],
                       string($svc_acct->username),
                       string($svc_acct->_password),
                     );
}

sub _xrc_command {
  my( $self, $method, $domain, @args ) = @_;
  
  eval "use Net::XRC qw(:types);";
  return $@ if $@;

  local($Net::XRC::DEBUG) = 1
    if $self->option('debug');

  my $xrc = new Net::XRC (
    'clientID' => $self->option('clientID'),
    'password' => $self->option('password'),
  );

  my $dresponse = $xrc->lookupMXReadyClientIDByEmailDomain( string($domain) );
  return $dresponse->error unless $dresponse->is_success;
  my $clientID = $dresponse->content;
  return "clientID for domain $domain not found"
    if $clientID == -1;

  my $response = $xrc->$method($clientID, @args);
  return $response->error unless $response->is_success;
  '';

}

sub _export_replace {
  my( $self, $new, $old ) = (shift, shift, shift);

  eval "use Net::XRC qw(:types);";
  return $@ if $@;

  return "can't change domain with Everyone.net"
    if $old->domain ne $new->domain;
  return "can't change username with Everyone.net"
    if $old->username ne $new->username;
  return '' unless $old->_password ne $new->_password;

  $self->_xrc_command( 'setUserPassword',
                       $new->domain,
                       string($new->username),
                       string($new->_password),
                     );
}

sub _export_delete {
  my( $self, $svc_acct ) = (shift, shift);

  eval "use Net::XRC qw(:types);";
  return $@ if $@;

  $self->_xrc_command( 'deleteUser',
                       $svc_acct->domain,
                       string($svc_acct->username),
                     );
}

sub _export_suspend {
  my( $self, $svc_acct ) = (shift, shift);

  eval "use Net::XRC qw(:types);";
  return $@ if $@;

  $self->_xrc_command( 'suspendUser',
                       $svc_acct->domain,
                       string($svc_acct->username),
                     );
}

sub _export_unsuspend {
  my( $self, $svc_acct ) = (shift, shift);

  eval "use Net::XRC qw(:types);";
  return $@ if $@;

  $self->_xrc_command( 'unsuspendUser',
                       $svc_acct->domain,
                       string($svc_acct->username),
                     );
}

1;