This commit was generated by cvs2svn to compensate for changes in r3921,
[freeside.git] / FS / FS / part_export / cp.pm
1 package FS::part_export::cp;
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   'port'      => { label=>'Port number' },
11   'username'  => { label=>'Username' },
12   'password'  => { label=>'Password' },
13   'domain'    => { label=>'Domain' },
14   'workgroup' => { label=>'Default Workgroup' },
15 ;
16
17 %info = (
18   'svc'    => 'svc_acct',
19   'desc'   => 'Real-time export to Critical Path Account Provisioning Protocol',
20   'options'=> \%options,
21   'notes'  => <<'END'
22 Real-time export to
23 <a href="http://www.cp.net/">Critial Path Account Provisioning Protocol</a>.
24 Requires installation of
25 <a href="http://search.cpan.org/dist/Net-APP">Net::APP</a>
26 from CPAN.
27 END
28 );
29
30 sub rebless { shift; }
31
32 sub _export_insert {
33   my( $self, $svc_acct ) = (shift, shift);
34   $self->cp_queue( $svc_acct->svcnum, 'create_mailbox',
35     'Mailbox'   => $svc_acct->username,
36     'Password'  => $svc_acct->_password,
37     'Workgroup' => $self->option('workgroup'),
38     'Domain'    => $svc_acct->domain,
39   );
40 }
41
42 sub _export_replace {
43   my( $self, $new, $old ) = (shift, shift, shift);
44   return "can't change domain with Critical Path"
45     if $old->domain ne $new->domain;
46   return '' unless $old->username  ne $new->username
47                 || $old->_password ne $new->_password;
48   $self->cp_queue( $new->svcnum, 'replace', $new->domain,
49     $old->username, $new->username, $old->_password, $new->_password );
50 }
51
52 sub _export_delete {
53   my( $self, $svc_acct ) = (shift, shift);
54   $self->cp_queue( $svc_acct->svcnum, 'delete_mailbox',
55     'Mailbox'   => $svc_acct->username,
56     'Domain'    => $svc_acct->domain,
57   );
58 }
59
60 sub _export_suspend {
61   my( $self, $svc_acct ) = (shift, shift);
62   $self->cp_queue( $svc_acct->svcnum, 'set_mailbox_status',
63     'Mailbox'       => $svc_acct->username,
64     'Domain'        => $svc_acct->domain,
65     'OTHER'         => 'T',
66     'OTHER_SUSPEND' => 'T',
67   );
68 }
69
70 sub _export_unsuspend {
71   my( $self, $svc_acct ) = (shift, shift);
72   $self->cp_queue( $svc_acct->svcnum, 'set_mailbox_status',
73     'Mailbox'       => $svc_acct->username,
74     'Domain'        => $svc_acct->domain,
75     'PAYMENT'       => 'F',
76     'OTHER'         => 'F',
77     'OTHER_SUSPEND' => 'F',
78     'OTHER_BOUNCE'  => 'F',
79   );
80 }
81
82 sub cp_queue {
83   my( $self, $svcnum, $method ) = (shift, shift, shift);
84   my $queue = new FS::queue {
85     'svcnum' => $svcnum,
86     'job'    => 'FS::part_export::cp::cp_command',
87   };
88   $queue->insert(
89     $self->machine,
90     $self->option('port'),
91     $self->option('username'),
92     $self->option('password'),
93     $self->option('domain'),
94     $method,
95     @_,
96   );
97 }
98
99 sub cp_command { #subroutine, not method
100   my($host, $port, $username, $password, $login_domain, $method, @args) = @_;
101
102   #quelle hack
103   if ( $method eq 'replace' ) {
104   
105     my( $domain, $old_username, $new_username, $old_password, $new_password)
106       = @args;
107
108     if ( $old_username ne $new_username ) {
109       cp_command($host, $port, $username, $password, 'rename_mailbox',
110         Domain        => $domain,
111         Old_Mailbox   => $old_username,
112         New_Mailbox   => $new_username,
113       );
114     }
115
116     #my $other = 'F';
117     if ( $new_password =~ /^\*SUSPENDED\* (.*)$/ ) {
118       $new_password = $1;
119     #  $other = 'T';
120     }
121     #cp_command($host, $port, $username, $password, $login_domain,
122     #  'set_mailbox_status',
123     #  Domain       => $domain,
124     #  Mailbox      => $new_username,
125     #  Other        => $other,
126     #  Other_Bounce => $other,
127     #);
128
129     if ( $old_password ne $new_password ) {
130       cp_command($host, $port, $username, $password, $login_domain,
131         'change_mailbox',
132         Domain    => $domain,
133         Mailbox   => $new_username,
134         Password  => $new_password,
135       );
136     }
137
138     return;
139   }
140   #eof quelle hack
141
142   eval "use Net::APP;";
143
144   my $app = new Net::APP (
145     "$host:$port",
146     User     => $username,
147     Password => $password,
148     Domain   => $login_domain,
149     Timeout  => 60,
150     #Debug    => 1,
151   ) or die "$@\n";
152
153   $app->$method( @args );
154
155   die $app->message."\n" unless $app->ok;
156
157 }
158
159 1;
160