cPanel-PublicAPI

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN


2.4 2019-04-23
    Add compatibility logic for cPanel API tokens.
    Print HTTP::Tiny “content” when it gives a 599 error (e.g., TLS error).

2.3  2018-12-28
    Bump version number to be strictly greater than 2.2
    Switch cPanel provided encoder to be the real encoder: Cpanel::Encoder::URI
    Testing commits on Travis now.
    Update README
    Block install/test reports for windows since they require getpwuid to pass.
    
2.2.1 2017-10-09
    Update Changes, MANIFEST and README.

2.2 2017-04-17
    Implement HTTP support via HTTP::Tiny.
    Support two-factor authentication (2FA) workflow.
    Establish session when using user/pass; accesshash still uses Basic Auth.
    Support API tokens via new api_token constructor option.
    Documentation fixes.

Makefile.PL  view on Meta::CPAN

use strict;
use warnings;
use ExtUtils::MakeMaker;

die "OS unsupported\n" if $^O eq 'MSWin32'; # Requires getpwuid to be implemented.

WriteMakefile(
    NAME          => 'cPanel::PublicAPI',
    AUTHOR        => q{cPanel, Inc. <integration@cpanel.net>},
    VERSION_FROM  => 'lib/cPanel/PublicAPI.pm',
    ABSTRACT_FROM => 'lib/cPanel/PublicAPI.pod',
    ( $ExtUtils::MakeMaker::VERSION >= 6.3002
        ? ( 'LICENSE' => 'bsd' )
        : () ),
    PL_FILES  => {},

lib/cPanel/PublicAPI.pm  view on Meta::CPAN

    }
    else {
        $self->{'error_fh'} = \*STDERR;
    }

    if ( $OPTS{'user'} ) {
        $self->{'user'} = $OPTS{'user'};
        $self->debug("Using user param from object creation") if $self->{'debug'};
    }
    else {
        $self->{'user'} = exists $INC{'Cpanel/PwCache.pm'} ? ( Cpanel::PwCache::getpwuid($>) )[0] : ( getpwuid($>) )[0];
        $self->debug("Setting user based on current uid ($>)") if $self->{'debug'};
    }

    if ( exists $OPTS{'api_token'} && exists $OPTS{'accesshash'} ) {
        $self->error('You cannot specify both an accesshash and an API token');
        die $self->{'error'};
    }

    # Allow the user to specify an api_token instead of an accesshash.
    # Though, it will just act as a synonym.
    $OPTS{'accesshash'} = $OPTS{'api_token'} if $OPTS{'api_token'};

    if ( ( !exists( $OPTS{'pass'} ) || $OPTS{'pass'} eq '' ) && ( !exists $OPTS{'accesshash'} || $OPTS{'accesshash'} eq '' ) ) {
        my $homedir = exists $INC{'Cpanel/PwCache.pm'} ? ( Cpanel::PwCache::getpwuid($>) )[7] : ( getpwuid($>) )[7];
        $self->debug("Attempting to detect correct authentication credentials") if $self->{'debug'};

        if ( -e $homedir . '/.accesshash' ) {
            local $/;
            if ( open( my $hash_fh, '<', $homedir . '/.accesshash' ) ) {
                $self->{'accesshash'} = readline($hash_fh);
                $self->{'accesshash'} =~ s/[\r\n]+//g;
                close($hash_fh);
                $self->debug("Got accesshash from $homedir/.accesshash") if $self->{'debug'};
            }

t/02-construct.t  view on Meta::CPAN

# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

use strict;
use warnings;

use Test::More;
use Test::Exception;

use cPanel::PublicAPI ();

my @getpwuid = getpwuid($>);
my $homedir  = $getpwuid[7];
my $user     = $getpwuid[0];

# test default settings
if ( !-e $homedir . '/.accesshash' ) {
    $ENV{'REMOTE_PASSWORD'} = 'b4r!' if !defined $ENV{'REMOTE_PASSWORD'};
    $ENV{'SERVER_SOFTWARE'} = 'cpsrvd fakeout';
}

check_options();
check_options( 'debug' => 1, 'error_log' => '/dev/null' );
check_options( 'timeout'   => 150 );

t/03-api-query.t  view on Meta::CPAN

#!/usr/bin/perl

use strict;
use warnings;

use Test::More;    # last test to print

use cPanel::PublicAPI ();

my @getpwuid = getpwuid($>);
my $homedir  = $getpwuid[7];
my $user     = $getpwuid[0];

if ( !-d '/usr/local/cpanel' ) {
    plan skip_all => 'This test requires that cPanel and WHM are installed on a server';
}

if ( !-e $homedir . '/.accesshash' ) {
    plan skip_all => 'This test requires that an account hash is defined (see "Setup Remote Access Keys" in WHM)';
}

# SSL tests

t/04-tfa-sessions.t  view on Meta::CPAN

# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

use strict;
use warnings;

use Test::More;    # last test to print

use cPanel::PublicAPI ();

my @getpwuid = getpwuid($>);
my $homedir  = $getpwuid[7];
my $user     = $getpwuid[0];

if ( !-d '/usr/local/cpanel' ) {
    plan skip_all => 'This test requires that cPanel and WHM are installed on a server';
}

if ( !-e $homedir . '/.accesshash' ) {
    plan skip_all => 'This test requires that an account hash is defined (see "Setup Remote Access Keys" in WHM)';
}

check_cpanel_version() or plan skip_all => 'This test requires cPanel version 54 or higher';

t/05-api-query_tokens.t  view on Meta::CPAN

# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

use strict;
use warnings;

use Test::More;    # last test to print

use cPanel::PublicAPI ();

my @getpwuid = getpwuid($>);
my $homedir  = $getpwuid[7];
my $user     = $getpwuid[0];

if ( !-d '/usr/local/cpanel' ) {
    plan skip_all => 'This test requires that cPanel and WHM are installed on a server';
}

if ( !-e $homedir . '/.accesshash' ) {
    plan skip_all => 'This test requires that an account hash is defined (see "Setup Remote Access Keys" in WHM)';
}

check_cpanel_version(63) or plan skip_all => 'This test requires cPanel version 64 or higher';



( run in 0.291 second using v1.01-cache-2.11-cpan-8d75d55dd25 )