App-cpanel

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

0.006 2020-06-14
- handle empty dirs

0.005 2020-06-13
- localfs.ls must list dotfiles

0.004 2020-06-13
- reject on non-200 response code
- reject on failure
- fixes for mirror so upload works

0.003 2020-06-13
- enable mirroring to and from a cPanel site

0.002 2020-06-07
- make accessible to MetaCPAN

0.001 2020-06-07
 - first version

README.md  view on Meta::CPAN

    $ cpanel uapi Fileman list_files dir=public_html
    $ cpanel uapi Fileman get_file_content dir=public_html file=index.html
    $ cpanel download public_html/index.html
    $ cpanel api2 Fileman fileop op=chmod metadata=0755 sourcefiles=public_html/cgi-bin/hello-world
    $ cpanel api2 Fileman fileop op=unlink sourcefiles=public_html/cgi-bin/hello-world
    $ cpanel api2 Fileman mkdir path= name=new-dir-at-top

    # this one is one at a time but can overwrite files
    $ cpanel api2 Fileman savefile dir=public_html/cgi-bin filename=hello-world content="$(cat public_html/cgi-bin/hello-world)"
    # this is multiple files but refuses to overwrite
    $ cpanel upload public_html/cgi-bin hello-world

    # download
    $ cpanel mirror public_html public_html cpanel localfs
    # upload
    $ cpanel mirror public_html public_html localfs cpanel

# DESCRIPTION

CLI for cPanel UAPI and also API 2, due to missing functionality in UAPI.

Stores session token in `~/.cpanel-token`, a two-line file. First line
is the URL component that goes after `cpsess`. Second is the `cpsession`
cookie, which you can get from your browser's DevTools.

lib/App/cpanel.pm  view on Meta::CPAN

  $ cpanel uapi Fileman list_files dir=public_html
  $ cpanel uapi Fileman get_file_content dir=public_html file=index.html
  $ cpanel download public_html/index.html
  $ cpanel api2 Fileman fileop op=chmod metadata=0755 sourcefiles=public_html/cgi-bin/hello-world
  $ cpanel api2 Fileman fileop op=unlink sourcefiles=public_html/cgi-bin/hello-world
  $ cpanel api2 Fileman mkdir path= name=new-dir-at-top

  # this one is one at a time but can overwrite files
  $ cpanel api2 Fileman savefile dir=public_html/cgi-bin filename=hello-world content="$(cat public_html/cgi-bin/hello-world)"
  # this is multiple files but refuses to overwrite
  $ cpanel upload public_html/cgi-bin hello-world

  # download
  $ cpanel mirror public_html public_html cpanel localfs
  # upload
  $ cpanel mirror public_html public_html localfs cpanel

=head1 DESCRIPTION

CLI for cPanel UAPI and also API 2, due to missing functionality in UAPI.

Stores session token in F<~/.cpanel-token>, a two-line file. First line
is the URL component that goes after C<cpsess>. Second is the C<cpsession>
cookie, which you can get from your browser's DevTools.

lib/App/cpanel.pm  view on Meta::CPAN

use strict;
use warnings;
use Mojo::URL;
use Mojo::UserAgent;
use Mojo::File qw(path);
use Mojo::Util qw(dumper encode);

my %cmd2func = (
  uapi => [ \&uapi_p, 1 ],
  download => [ \&download_p, 0 ],
  upload => [ \&upload_p, 1 ],
  api2 => [ \&api2_p, 1 ],
  mirror => [ \&mirror_p, 1 ],
);
my $token_file = "$ENV{HOME}/.cpanel-token";
my $domain_file = "$ENV{HOME}/.cpanel-domain";
my %localfs_map = (
  ls => \&localfs_ls,
  mkdir => \&localfs_mkdir,
  read => \&localfs_read,
  write => \&localfs_write,

lib/App/cpanel.pm  view on Meta::CPAN

  my $tx_p = api_request 'get_p', $domain, $token,
    [ 'download' ],
    { skipencode => 1, file => $file };
  $tx_p->then(sub {
    my $res = $_[0]->res;
    die $res->code . ": " . $res->message . "\n" if $res->code != 200;
    $res->body;
  });
}

sub make_upload_form {
  my $dir = shift;
  my $counter = 0;
  +{
    dir => $dir,
    map {
      my $p = path $_;
      ('file-' . ++$counter => {
        filename => $p->basename,
        content => $p->slurp,
      });
    } @_,
  };
}

sub upload_p {
  my ($dir, @files) = @_;
  die "No dir\n" unless $dir;
  die "No files\n" unless @files;
  my ($token, $domain) = (read_token(), read_domain());
  my $tx_p = api_request 'post_p', $domain, $token,
    [ 'execute', 'Fileman', 'upload_files' ],
    undef,
    form => make_upload_form($dir, @files),
    ;
  $tx_p->then(\&_error_or_json)->then(\&_uapi_error_or_json);
}

sub _api2_error_or_json {
  my $json = $_[0];
  my $result = $json->{cpanelresult};
  if (!$result or !$result->{event}{result} or $result->{error}) {
    die join '', "Failed:\n",
      map "$_\n",



( run in 3.156 seconds using v1.01-cache-2.11-cpan-b16cb0d3907 )