X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fpart_export%2Fcpanel.pm;h=6c61e3d2ba86318e798fa57833ee68699621fbed;hb=389b6f1116c3309c2ee57a6c295ed1a793503095;hp=7628ff608fee1116b1de1caebdccdc5c55ee483f;hpb=c3d44e9d01d88fde47d817df4c7d77c16f074e65;p=freeside.git diff --git a/FS/FS/part_export/cpanel.pm b/FS/FS/part_export/cpanel.pm index 7628ff608..6c61e3d2b 100644 --- a/FS/FS/part_export/cpanel.pm +++ b/FS/FS/part_export/cpanel.pm @@ -9,6 +9,7 @@ use FS::part_export; tie my %options, 'Tie::IxHash', 'user' => { label=>'Remote access username' }, 'accesshash' => { label=>'Remote access key', type=>'textarea' }, + 'debug' => { label=>'Enable debugging', type=>'checkbox' }, ; %info = ( @@ -82,44 +83,105 @@ sub cpanel_queue { $self->machine, $self->option('user'), $self->option('accesshash'), + $self->option('debug'), @_ ) 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'}; + my( $machine, $user, $accesshash, $debug ) = splice(@_,0,4); + +# my $whm = cpanel_connect($machine, $user, $accesshash, $debug); +# warn " cpanel->createacct ". join(', ', @_). "\n" +# if $debug; +# my $response = $whm->createacct(@_); +# die $whm->{'error'} if $whm->{'error'}; +# warn " cpanel response: $response\n" +# if $debug; + + warn "cpanel_insert: attempting web interface to add POP" + if $debug; + + my($domain, $username, $password, $svc) = @_; + + use LWP::UserAgent; + use HTTP::Request::Common qw(POST); + + my $url = + "http://$user:$accesshash\@$domain:2082/frontend/x/mail/addpop2.html"; + + my $ua = LWP::UserAgent->new(); + + #$req->authorization_basic($user, $accesshash); + + my $res = $ua->request( + POST( $url, + [ + 'email' => $username, + 'domain' => $domain, + 'password' => $password, + 'quota' => 10, #? + ] + ) + ); + + die "Error submitting data to $url: ". $res->status_line + unless $res->is_success; + + die "Username in use" + if $res->content =~ /exists/; + + die "Account not created: ". $res->content + if $res->content =~ /failure/; + } #sub cpanel_replace { #subroutine, not method #} sub cpanel_delete { #subroutine, not method - my $whm = cpanel_connect(shift, shift, shift); + my( $machine, $user, $accesshash, $debug ) = splice(@_,0,4); + my $whm = cpanel_connect($machine, $user, $accesshash, $debug); + warn " cpanel->killacct ". join(', ', @_). "\n" + if $debug; my $response = $whm->killacct(shift); die $whm->{'error'} if $whm->{'error'}; + warn " cpanel response: $response\n" + if $debug; } sub cpanel_suspend { #subroutine, not method - my $whm = cpanel_connect(shift, shift, shift); + my( $machine, $user, $accesshash, $debug ) = splice(@_,0,4); + my $whm = cpanel_connect($machine, $user, $accesshash, $debug); + warn " cpanel->suspend ". join(', ', @_). "\n" + if $debug; my $response = $whm->suspend(shift); die $whm->{'error'} if $whm->{'error'}; + warn " cpanel response: $response\n" + if $debug; } sub cpanel_unsuspend { #subroutine, not method - my $whm = cpanel_connect(shift, shift, shift); + my( $machine, $user, $accesshash, $debug ) = splice(@_,0,4); + my $whm = cpanel_connect($machine, $user, $accesshash, $debug); + warn " cpanel->unsuspend ". join(', ', @_). "\n" + if $debug; my $response = $whm->unsuspend(shift); die $whm->{'error'} if $whm->{'error'}; + warn " cpanel response: $response\n" + if $debug; } sub cpanel_connect { - my( $host, $user, $accesshash ) = @_; + my( $host, $user, $accesshash, $debug ) = @_; eval "use Cpanel::Accounting;"; die $@ if $@; + warn "creating new Cpanel::Accounting connection to $user@$host\n" + if $debug; + my $whm = new Cpanel::Accounting; $whm->{'host'} = $host; $whm->{'user'} = $user; @@ -128,3 +190,5 @@ sub cpanel_connect { $whm; } + +1;