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' },
16 'desc' => 'Real-time export to Cpanel control panel.',
17 'options' => \%options,
19 '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.',
22 sub rebless { shift; }
25 my($self, $svc_acct) = (shift, shift);
26 $err_or_queue = $self->cpanel_queue( $svc_acct->svcnum, 'insert',
30 $svc_acct->cust_svc->part_svc->svc,
32 ref($err_or_queue) ? '' : $err_or_queue;
36 my( $self, $new, $old ) = (shift, shift, shift);
37 return "can't change username with cpanel"
38 if $old->username ne $new->username;
39 return "can't change password with cpanel"
40 if $old->_passsword ne $new->_password;
41 return "can't change domain with cpanel"
42 if $old->domain ne $new->domain;
46 ##return '' unless $old->_password ne $new->_password;
47 #$err_or_queue = $self->cpanel_queue( $new->svcnum,
48 # 'replace', $new->username, $new->_password );
49 #ref($err_or_queue) ? '' : $err_or_queue;
53 my( $self, $svc_acct ) = (shift, shift);
54 $err_or_queue = $self->cpanel_queue( $svc_acct->svcnum,
55 'delete', $svc_acct->username
57 ref($err_or_queue) ? '' : $err_or_queue;
61 my( $self, $svc_acct ) = (shift, shift);
62 $err_or_queue = $self->cpanel_queue( $svc_acct->svcnum,
63 'suspend', $svc_acct->username );
64 ref($err_or_queue) ? '' : $err_or_queue;
67 sub _export_unsuspend {
68 my( $self, $svc_acct ) = (shift, shift);
69 $err_or_queue = $self->cpanel_queue( $svc_acct->svcnum,
70 'unsuspend', $svc_acct->username );
71 ref($err_or_queue) ? '' : $err_or_queue;
76 my( $self, $svcnum, $method ) = (shift, shift, shift);
77 my $queue = new FS::queue {
79 'job' => "FS::part_export::cpanel::cpanel_$method",
83 $self->option('user'),
84 $self->option('accesshash'),
90 sub cpanel_insert { #subroutine, not method
91 my $whm = cpanel_connect(shift, shift, shift);
92 my $response = $whm->createacct(@_);
93 die $whm->{'error'} if $whm->{'error'};
96 #sub cpanel_replace { #subroutine, not method
99 sub cpanel_delete { #subroutine, not method
100 my $whm = cpanel_connect(shift, shift, shift);
101 my $response = $whm->killacct(shift);
102 die $whm->{'error'} if $whm->{'error'};
105 sub cpanel_suspend { #subroutine, not method
106 my $whm = cpanel_connect(shift, shift, shift);
107 my $response = $whm->suspend(shift);
108 die $whm->{'error'} if $whm->{'error'};
111 sub cpanel_unsuspend { #subroutine, not method
112 my $whm = cpanel_connect(shift, shift, shift);
113 my $response = $whm->unsuspend(shift);
114 die $whm->{'error'} if $whm->{'error'};
118 my( $host, $user, $accesshash ) = @_;
120 eval "use Cpanel::Accounting;";
123 my $whm = new Cpanel::Accounting;
124 $whm->{'host'} = $host;
125 $whm->{'user'} = $user;
126 $whm->{'accesshash'} = $accesshash;
127 $whm->{'usessl'} = 1;