export host selection per service, RT#17914
[freeside.git] / FS / FS / part_export / everyone_net.pm
1 package FS::part_export::everyone_net;
2
3 use vars qw(@ISA %info);
4 use Tie::IxHash;
5 use FS::part_export;
6
7 @ISA = qw(FS::part_export);
8
9 tie my %options, 'Tie::IxHash',
10   'clientID'  => { label=>'clientID' },
11   'password'  => { label=>'Password' },
12   #'workgroup' => { label=>'Default Workgroup' },
13   'debug'     => { label=>'Enable debugging',
14                     type=>'checkbox'          },
15 ;
16
17 %info = (
18   'svc'    => 'svc_acct',
19   'desc'   => 'Real-time export to Everyone.net outsourced mail service',
20   'options'=> \%options,
21   'no_machine' => 1,
22   'default_svc_class' => 'Email',
23   'notes'  => <<'END'
24 Real-time export to
25 <a href="http://www.everyone.net/">Everyone.net</a> via the XRC Remote API.
26 Requires installation of
27 <a href="http://search.cpan.org/dist/Net-XRC">Net::XRC</a>
28 from CPAN.
29 END
30 );
31
32 sub rebless { shift; }
33
34 # experiement: want the status of these right away (don't want account to
35 # create or whatever and then get error in the queue from dup username or
36 # something), so no queueing
37
38 sub _export_insert {
39   my( $self, $svc_acct ) = (shift, shift);
40
41   eval "use Net::XRC qw(:types);";
42   return $@ if $@;
43
44   $self->_xrc_command( 'createUser',
45                        $svc_acct->domain,
46                        [],
47                        string($svc_acct->username),
48                        string($svc_acct->_password),
49                      );
50 }
51
52 sub _xrc_command {
53   my( $self, $method, $domain, @args ) = @_;
54   
55   eval "use Net::XRC qw(:types);";
56   return $@ if $@;
57
58   local($Net::XRC::DEBUG) = 1
59     if $self->option('debug');
60
61   my $xrc = new Net::XRC (
62     'clientID' => $self->option('clientID'),
63     'password' => $self->option('password'),
64   );
65
66   my $dresponse = $xrc->lookupMXReadyClientIDByEmailDomain( string($domain) );
67   return $dresponse->error unless $dresponse->is_success;
68   my $clientID = $dresponse->content;
69   return "clientID for domain $domain not found"
70     if $clientID == -1;
71
72   my $response = $xrc->$method($clientID, @args);
73   return $response->error unless $response->is_success;
74   '';
75
76 }
77
78 sub _export_replace {
79   my( $self, $new, $old ) = (shift, shift, shift);
80
81   eval "use Net::XRC qw(:types);";
82   return $@ if $@;
83
84   return "can't change domain with Everyone.net"
85     if $old->domain ne $new->domain;
86   return "can't change username with Everyone.net"
87     if $old->username ne $new->username;
88   return '' unless $old->_password ne $new->_password;
89
90   $self->_xrc_command( 'setUserPassword',
91                        $new->domain,
92                        string($new->username),
93                        string($new->_password),
94                      );
95 }
96
97 sub _export_delete {
98   my( $self, $svc_acct ) = (shift, shift);
99
100   eval "use Net::XRC qw(:types);";
101   return $@ if $@;
102
103   $self->_xrc_command( 'deleteUser',
104                        $svc_acct->domain,
105                        string($svc_acct->username),
106                      );
107 }
108
109 sub _export_suspend {
110   my( $self, $svc_acct ) = (shift, shift);
111
112   eval "use Net::XRC qw(:types);";
113   return $@ if $@;
114
115   $self->_xrc_command( 'suspendUser',
116                        $svc_acct->domain,
117                        string($svc_acct->username),
118                      );
119 }
120
121 sub _export_unsuspend {
122   my( $self, $svc_acct ) = (shift, shift);
123
124   eval "use Net::XRC qw(:types);";
125   return $@ if $@;
126
127   $self->_xrc_command( 'unsuspendUser',
128                        $svc_acct->domain,
129                        string($svc_acct->username),
130                      );
131 }
132
133 1;
134