jubegnx

hey guys i need some help.

im trying to get into cPanel and use the addon domain tool there...

#!/usr/bin/

perl

  -w

use strict;
use WWW::Mechanize;
use MIME::Base64;

    my $mech = WWW::Mechanize->new( autocheck => 1 );
    my @args = (
        Authorization => "Basic " .
            MIME::Base64::encode( 'user' . ':' . 'pass' )
    );

    $mech->credentials( 'http://hosting.com:5555', 'cPanel', 'user', 'pass' );
    $mech->get( 'http://hosting.com:5555', @args );
    $mech->follow_link( text => 'Addon Domains', n=> 1 );


it logs in fine however when i ask it to follow the link it gives me the following error

Error GETing http://hosting.com:5555/addon/index.html: Access Denied Still Working at login.pl line 19

dirk

Just tested the script and got the same error message.

I think that the credentials are not passed to the new link
because there is no get with @args.

Will have a look if there is a solution.

Dirk

perkiset

<hijack>
Nice to see you back a bit Dirk... how is the new place?
</hijack>

Bompa

Are you sure it's logging in fine?  Maybe I'm missing something cuz I dont use mech,
(i think it's buggy), but dont you have to post to log in?

dirk

Did some further debugging with Komodo and displayed
the passed array @args.

For the first get it contains the credentials, for the second get
it's empty. So it seems you can't use follow_link for such links.

You could try the following workaround. I have tested it and it
was working.



$mech->get( 'http://hosting.com:5555', @args );
#$mech->follow_link( text => 'Addon Domains', n=> 1 );

my $link =  $mech->find_link( text => 'Addon Domains' );

my $addon_url = 'http://hosting.com:5555/frontend/x/' . $link->[0];
$mech->get( $addon_url, @args );
...


@Ed: The new place is fine and very quiet. Specially in the middle of the night
when I'm still working.

nop_90

A cpanel class i use


package CPanel;
use strict;
use warnings;
use WWW::Mechanize;

sub new {
    my $class = shift;
    my $self = bless {}, $class;
    $self->{mech} = WWW::Mechanize->new();
    $self->{url} = shift;
    $self->{mech}->credentials(shift,shift);
    return $self;
}

sub add_subdomain {
    my $self =  shift;
    my ($domain,$subdomain) = @_;
    my $mech = $self->{mech};
    my $response = $mech->get($self->{url});
    die "unable to get main page" unless $response->is_success;
    $response = $mech->follow_link(text_

regex

  => qr/Subdomain/ );
    die "unable to get subdomain page" unless $response->is_success;
    my $form = $mech->form_name("domainform");
    die "unable to find form" unless $form;
    $mech->field("rootdomain",$domain);
    $mech->field("domain",$subdomain);
    $mech->submit();
    1;
}

sub add_on_domain {
    my $self = shift;
    my ($domain,$password) = @_;
    my $mech = $self->{mech};
    my $response = $mech->get($self->{url} . "/frontend/x/addon/index.html");
    die "unable to get add_on_domain form" unless $response->is_success;
    my $form = $mech->form_name("mainform");
    die "unable to find form" unless $form;
    my $userdir = $domain; $userdir =~ s/./-/g;
    $mech->field("domain",$domain);
    $mech->field("user",$userdir);
    $mech->field("pass",$password);
    $response = $mech->click();
    die "unable to post add on domain" unless $response->is_success;
    1;
}

sub install_wordpress {
    my $self = shift;
    my ($domain,$username,$password) = @_;
    my $mech = $self->{mech};
    my $response = $mech->get($self->{url} . "/frontend/x/fantastico/autoinstallwordpress.

php

 ");
    die "unable to get wordpress form" unless $response->is_success;
   
    my $form = $mech->form_with_fields("installdirdomain","installdir");
    die "unable to get wordpress form" unless $form;
   
    $mech->field("installdirdomain",$domain);
    $mech->field("adminuser",$username);
    $mech->field("INST_password",$password);
    $mech->field("socketpass",$password);
    $response = $mech->click();
    die "unable to submit form" unless $response->is_success;
   
    $form = $mech->form_with_fields("adminuser","continuepage");
    die "unable to get finish wordpress form" unless $form;
    $response = $mech->click();
    die "unable to submit form" unless $response->is_success;
    1;
}

1;

dirk

Thanks for the CPanel package. Well-timed posting.

I'm just working on some

Perl

  scripts to create domains via cPanel.

BTW, I have tested the cPanel XML API which is easy to use.

Here is an example for a respective URL:


http://$user0:$password0@yourdomain.com:2086/xml-api/createacct?username=$user&plan=$plan&ip=$ip&cpmod=$cpmod&password=$password&contactemail=$contactemail&domain=$domain&useregns=$useregns&reseller=$reseller


You have to define the variables and then submit the URL via
LWP::UserAgent or WWW::Mechanize.

nop_90

CPanel has xmlrpc api  Applause
now u tell me.
if you going to do xmlrpc use the

perl

  lib that does it, i will look into when start doing that shit again

Anyway above script works on hostigator (not sure about others)
you use like this (incase u not familiar with object

perl

 Applause


my $panel = CPanel->new($cpanel_url,$username,$password);
$panel->add_on_domain("mydomain.domain.com",$password);
$panel->install_wordpress("$site.$domain",$blog_username,$blog_password);


you get idea

dirk

Hm, you don't need a

Perl

  module.

Don't think that xml rpc modules, like XMLRPC::Lite
would work.

You only have to submit a customized URL containing
the fields and values in the query string.

The output is XML. Here you could use a module, like
XML:Simple to parse the output.

jubegnx

got it... thanks for the help

nop_90

Your are right about the xmlapi , xml rpc will not work.
Looked at the documentation, an extremely stupid API
Would have made a heck of a lot more sense if the just use xmlrpc

arms

just what i was looking for. thanks.


Perkiset's Place Home   Politics @ Perkiset's