1 package FS::part_export::cpanel;
3 use vars qw(@ISA %info);
7 @ISA = qw(FS::part_export);
9 tie my %options, 'Tie::IxHash',
10 'user' => { label=>'Remote access username' },
11 'accesshash' => { label=>'Remote access key', type=>'textarea' },
12 'debug' => { label=>'Enable debugging', type=>'checkbox' },
17 'desc' => 'Real-time export to Cpanel control panel.',
18 'options' => \%options,
20 'notes' => 'Real time export to a the <a href="http://www.cpanel.net/">Cpanel</a> control panel software. Service definition names are exported as Cpanel packages. Requires installation of the Cpanel::Accounting perl module distributed with Cpanel.',
23 sub rebless { shift; }
26 my($self, $svc_acct) = (shift, shift);
27 $err_or_queue = $self->cpanel_queue( $svc_acct->svcnum, 'insert',
31 $svc_acct->cust_svc->part_svc->svc,
33 ref($err_or_queue) ? '' : $err_or_queue;
37 my( $self, $new, $old ) = (shift, shift, shift);
38 return "can't change username with cpanel"
39 if $old->username ne $new->username;
40 return "can't change password with cpanel"
41 if $old->_passsword ne $new->_password;
42 return "can't change domain with cpanel"
43 if $old->domain ne $new->domain;
47 ##return '' unless $old->_password ne $new->_password;
48 #$err_or_queue = $self->cpanel_queue( $new->svcnum,
49 # 'replace', $new->username, $new->_password );
50 #ref($err_or_queue) ? '' : $err_or_queue;
54 my( $self, $svc_acct ) = (shift, shift);
55 $err_or_queue = $self->cpanel_queue( $svc_acct->svcnum,
56 'delete', $svc_acct->username
58 ref($err_or_queue) ? '' : $err_or_queue;
62 my( $self, $svc_acct ) = (shift, shift);
63 $err_or_queue = $self->cpanel_queue( $svc_acct->svcnum,
64 'suspend', $svc_acct->username );
65 ref($err_or_queue) ? '' : $err_or_queue;
68 sub _export_unsuspend {
69 my( $self, $svc_acct ) = (shift, shift);
70 $err_or_queue = $self->cpanel_queue( $svc_acct->svcnum,
71 'unsuspend', $svc_acct->username );
72 ref($err_or_queue) ? '' : $err_or_queue;
77 my( $self, $svcnum, $method ) = (shift, shift, shift);
78 my $queue = new FS::queue {
80 'job' => "FS::part_export::cpanel::cpanel_$method",
84 $self->option('user'),
85 $self->option('accesshash'),
86 $self->option('debug'),
92 sub cpanel_insert { #subroutine, not method
93 my( $machine, $user, $accesshash, $debug ) = splice(@_,0,4);
94 my $whm = cpanel_connect($machine, $user, $accesshash, $debug);
95 warn " cpanel->createacct ". join(', ', @_). "\n"
97 my $response = $whm->createacct(@_);
98 die $whm->{'error'} if $whm->{'error'};
99 warn " cpanel response: $response\n"
103 #sub cpanel_replace { #subroutine, not method
106 sub cpanel_delete { #subroutine, not method
107 my( $machine, $user, $accesshash, $debug ) = splice(@_,0,4);
108 my $whm = cpanel_connect($machine, $user, $accesshash, $debug);
109 warn " cpanel->killacct ". join(', ', @_). "\n"
111 my $response = $whm->killacct(shift);
112 die $whm->{'error'} if $whm->{'error'};
113 warn " cpanel response: $response\n"
117 sub cpanel_suspend { #subroutine, not method
118 my( $machine, $user, $accesshash, $debug ) = splice(@_,0,4);
119 my $whm = cpanel_connect($machine, $user, $accesshash, $debug);
120 warn " cpanel->suspend ". join(', ', @_). "\n"
122 my $response = $whm->suspend(shift);
123 die $whm->{'error'} if $whm->{'error'};
124 warn " cpanel response: $response\n"
128 sub cpanel_unsuspend { #subroutine, not method
129 my( $machine, $user, $accesshash, $debug ) = splice(@_,0,4);
130 my $whm = cpanel_connect($machine, $user, $accesshash, $debug);
131 warn " cpanel->unsuspend ". join(', ', @_). "\n"
133 my $response = $whm->unsuspend(shift);
134 die $whm->{'error'} if $whm->{'error'};
135 warn " cpanel response: $response\n"
140 my( $host, $user, $accesshash, $debug ) = @_;
142 eval "use Cpanel::Accounting;";
145 warn "creating new Cpanel::Accounting connection to $user@$host\n"
148 my $whm = new Cpanel::Accounting;
149 $whm->{'host'} = $host;
150 $whm->{'user'} = $user;
151 $whm->{'accesshash'} = $accesshash;
152 $whm->{'usessl'} = 1;