working textradius export
[freeside.git] / FS / FS / part_export / cp.pm
1 package FS::part_export::cp;
2
3 use vars qw(@ISA);
4 use FS::part_export;
5
6 @ISA = qw(FS::part_export);
7
8 sub rebless { shift; }
9
10 sub _export_insert {
11   my( $self, $svc_acct ) = (shift, shift);
12   $self->cp_queue( $svc_acct->svcnum, 'create_mailbox',
13     Mailbox   => $svc_acct->username,
14     Password  => $svc_acct->_password,
15     Workgroup => $self->option('workgroup'),
16     Domain    => $svc_acct->domain,
17   );
18 }
19
20 sub _export_replace {
21   my( $self, $new, $old ) = (shift, shift, shift);
22   return "can't change domain with Critical Path"
23     if $old->domain ne $new->domain;
24   return '' unless $old->username  ne $new->username
25                 || $old->_password ne $new->_password;
26   $self->cp_queue( $new->svcnum, 'replace', $new->domain,
27     $old->username, $new->username, $old->_password, $new->_password );
28 }
29
30 sub _export_delete {
31   my( $self, $svc_acct ) = (shift, shift);
32   $self->cp_queue( $svc_acct->svcnum, 'delete_mailbox',
33     Mailbox   => $svc_acct->username,
34     Domain    => $svc_acct->domain,
35   );
36 }
37
38 sub cp_queue {
39   my( $self, $svcnum, $method ) = (shift, shift, shift);
40   my $queue = new FS::queue {
41     'svcnum' => $svcnum,
42     'job'    => 'FS::part_export::cp::cp_command',
43   };
44   $queue->insert(
45     $self->option('host'),
46     $self->option('port'),
47     $self->option('username'),
48     $self->option('password'),
49     $self->option('domain'),
50     $method,
51     @_,
52   );
53 }
54
55 sub cp_command { #subroutine, not method
56   my($host, $port, $username, $password, $login_domain, $method, @args) = @_;
57
58   #quelle hack
59   if ( $method eq 'replace' ) {
60   
61     my( $domain, $old_username, $new_username, $old_password, $new_password)
62       = @args;
63
64     if ( $old_username ne $new_username ) {
65       cp_command($host, $port, $username, $password, 'rename_mailbox',
66         Domain        => $domain,
67         Old_Mailbox   => $old_username,
68         New_Mailbox   => $new_username,
69       );
70     }
71
72     my $other = 'F';
73     if ( $new_password =~ /^\*SUSPENDED\* (.*)$/ ) {
74       $new_password = $1;
75       $other = 'T';
76     }
77     cp_command($host, $port, $username, $password, 'set_mailbox_status',
78       Domain       => $domain,
79       Mailbox      => $new_username,
80       Other        => $other,
81       Other_Bounce => $other,
82     );
83
84     if ( $old_password ne $new_password ) {
85       cp_command($host, $port, $username, $password, 'change_mailbox',
86         Domain    => $domain,
87         Mailbox   => $new_username,
88         Password  => $new_password,
89       );
90     }
91
92     return;
93   }
94   #eof quelle hack
95
96   eval "use Net::APP;";
97
98   my $app = new Net::APP (
99     "$host:$port",
100     User     => $username,
101     Password => $password,
102     Domain   => $login_domain,
103     Timeout  => 60,
104     #Debug    => 1,
105   ) or die "$@\n";
106
107   $app->$method( @args );
108
109   die $app->message."\n" unless $app->ok;
110
111 }
112