summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Changes.1.5.81
-rw-r--r--FS/FS/part_export/cpanel.pm130
-rw-r--r--eg/export_template.pm25
3 files changed, 156 insertions, 0 deletions
diff --git a/Changes.1.5.8 b/Changes.1.5.8
index 77b0b6fb0..efb91ba55 100644
--- a/Changes.1.5.8
+++ b/Changes.1.5.8
@@ -7,3 +7,4 @@
- add native Radiator export
- added agent/taxclass gateway overrides
- re-did billing section of customer edit and added switch/solo support
+- add cpanel export
diff --git a/FS/FS/part_export/cpanel.pm b/FS/FS/part_export/cpanel.pm
new file mode 100644
index 000000000..3bc47e422
--- /dev/null
+++ b/FS/FS/part_export/cpanel.pm
@@ -0,0 +1,130 @@
+package FS::part_export::cpanel;
+
+use vars qw(@ISA %info);
+use Tie::IxHash;
+use FS::part_export;
+
+@ISA = qw(FS::part_export);
+
+tie my %options, 'Tie::IxHash',
+ 'user' => { label=>'Remote access username' },
+ 'accesshash' => { label=>'Remote access key' },
+;
+
+%info = (
+ 'svc' => 'svc_acct',
+ 'desc' => 'Real-time export to Cpanel control panel.',
+ 'options' => \%options,
+ 'nodomain' => 'Y',
+ '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.',
+);
+
+sub rebless { shift; }
+
+sub _export_insert {
+ my($self, $svc_acct) = (shift, shift);
+ $err_or_queue = $self->cpanel_queue( $svc_acct->svcnum, 'insert',
+ $svc_acct->domain,
+ $svc_acct->username,
+ $svc_acct->_password,
+ $svc_acct->cust_svc->part_svc->svc,
+ );
+ ref($err_or_queue) ? '' : $err_or_queue;
+}
+
+sub _export_replace {
+ my( $self, $new, $old ) = (shift, shift, shift);
+ return "can't change username with cpanel"
+ if $old->username ne $new->username;
+ return "can't change password with cpanel"
+ if $old->_passsword ne $new->_password;
+ return "can't change domain with cpanel"
+ if $old->domain ne $new->domain;
+
+ '';
+
+ ##return '' unless $old->_password ne $new->_password;
+ #$err_or_queue = $self->cpanel_queue( $new->svcnum,
+ # 'replace', $new->username, $new->_password );
+ #ref($err_or_queue) ? '' : $err_or_queue;
+}
+
+sub _export_delete {
+ my( $self, $svc_acct ) = (shift, shift);
+ $err_or_queue = $self->cpanel_queue( $svc_acct->svcnum,
+ 'delete', $svc_acct->username
+ );
+ ref($err_or_queue) ? '' : $err_or_queue;
+}
+
+sub _export_suspend {
+ my( $self, $svc_acct ) = (shift, shift);
+ $err_or_queue = $self->cpanel_queue( $svc_acct->svcnum,
+ 'suspend', $svc_acct->username );
+ ref($err_or_queue) ? '' : $err_or_queue;
+}
+
+sub _export_unsuspend {
+ my( $self, $svc_acct ) = (shift, shift);
+ $err_or_queue = $self->cpanel_queue( $svc_acct->svcnum,
+ 'unsuspend', $svc_acct->username );
+ ref($err_or_queue) ? '' : $err_or_queue;
+}
+
+
+sub cpanel_queue {
+ my( $self, $svcnum, $method ) = (shift, shift, shift);
+ my $queue = new FS::queue {
+ 'svcnum' => $svcnum,
+ 'job' => "FS::part_export::cpanel::cpanel_$method",
+ };
+ $queue->insert(
+ $self->machine,
+ $self->option('user'),
+ $self->option('accesshash'),
+ @_
+ ) or $queue;
+}
+
+
+sub cpanel_insert { #subroutine, not method
+ my $whm = cpanel_connect(shift, shift, shift);
+ my $response = $whm->createacct(@_);
+ die $whm->{'error'} if $whm->{'error'};
+}
+
+#sub cpanel_replace { #subroutine, not method
+#}
+
+sub cpanel_delete { #subroutine, not method
+ my $whm = cpanel_connect(shift, shift, shift);
+ my $response = $whm->killacct(shift);
+ die $whm->{'error'} if $whm->{'error'};
+}
+
+sub cpanel_suspend { #subroutine, not method
+ my $whm = cpanel_connect(shift, shift, shift);
+ my $response = $whm->suspend(shift);
+ die $whm->{'error'} if $whm->{'error'};
+}
+
+sub cpanel_unsuspend { #subroutine, not method
+ my $whm = cpanel_connect(shift, shift, shift);
+ my $response = $whm->unsuspend(shift);
+ die $whm->{'error'} if $whm->{'error'};
+}
+
+sub cpanel_connect {
+ my( $host, $user, $accesshash ) = @_;
+
+ eval "use Cpanel::Accounting;";
+ die $@ if $@;
+
+ my $whm = new Cpanel::Accounting;
+ $whm->{'host'} = $host;
+ $whm->{'user'} = $user;
+ $whm->{'accesshash'} = $accesshash;
+ $whm->{'usessl'} = 1;
+
+ $whm;
+}
diff --git a/eg/export_template.pm b/eg/export_template.pm
index 2c199db85..2830ce337 100644
--- a/eg/export_template.pm
+++ b/eg/export_template.pm
@@ -56,6 +56,24 @@ sub _export_delete {
ref($err_or_queue) ? '' : $err_or_queue;
}
+#these two are optional
+# fallback for svc_acct will change and restore password
+sub _export_suspend {
+ my( $self, $svc_something ) = (shift, shift);
+ $err_or_queue = $self->myexport_queue( $svc_something->svcnum,
+ 'suspend', $svc_something->username );
+ ref($err_or_queue) ? '' : $err_or_queue;
+}
+
+sub _export_unsuspend {
+ my( $self, $svc_something ) = (shift, shift);
+ $err_or_queue = $self->myexport_queue( $svc_something->svcnum,
+ 'unsuspend', $svc_something->username );
+ ref($err_or_queue) ? '' : $err_or_queue;
+}
+
+###
+
#a good idea to queue anything that could fail or take any time
sub myexport_queue {
my( $self, $svcnum, $method ) = (shift, shift, shift);
@@ -79,3 +97,10 @@ sub myexport_delete { #subroutine, not method
#do things with $username
}
+sub myexport_suspend { #subroutine, not method
+}
+
+sub myexport_unsuspend { #subroutine, not method
+}
+
+