App-cpanel

 view release on metacpan or  search on metacpan

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


use Exporter 'import';

our $VERSION = '0.006';
our @EXPORT_OK = qw(dispatch_cmd_print dispatch_cmd_raw_p dir_walk_p);

=head1 NAME

App::cpanel - CLI for cPanel UAPI and API 2

=begin markdown

# PROJECT STATUS

[![CPAN version](https://badge.fury.io/pl/App-cpanel.svg)](https://metacpan.org/pod/App::cpanel)

=end markdown

=head1 SYNOPSIS

  $ cpanel uapi Notifications get_notifications_count
  $ cpanel uapi ResourceUsage get_usages
  $ 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.

Stores relevant domain name in F<~/.cpanel-domain>.

=head1 FUNCTIONS

Exportable:

=head2 dispatch_cmd_print

Will print the return value, using L<Mojo::Util/dumper> except for
C<download>.

=head2 dispatch_cmd_raw_p

Returns a promise of the decoded JSON value or C<download>ed content.

=head2 dir_walk_p

Takes C<$from_dir>, C<$to_dir>, C<$from_map>, C<$to_map>. Copies the
information in the first directory to the second, using the respective
maps. Assumes UNIX-like semantics in filenames, i.e. C<$dir/$file>.

Returns a promise of completion.

The maps are hash-refs whose values are functions, and the keys are:

=head3 ls

Takes C<$dir>. Returns a promise of two hash-refs, of directories and of
files. Each has keys of relative filename, values are an array-ref
containing a string octal number representing UNIX permissions, and a
number giving the C<mtime>. Must reject if does not exist.

=head3 mkdir

Takes C<$dir>. Returns a promise of having created the directory.

=head3 read

Takes C<$dir>, C<$file>. Returns a promise of the file contents.

=head3 write

Takes C<$dir>, C<$file>. Returns a promise of having written the file
contents.

=head3 chmod

Takes C<$path>, C<$perms>. Returns a promise of having changed the
permissions.

=head1 SEE ALSO

L<https://documentation.cpanel.net/display/DD/Guide+to+UAPI>

L<https://documentation.cpanel.net/display/DD/Guide+to+cPanel+API+2>

=head1 AUTHOR

Ed J

=head1 COPYRIGHT AND LICENSE

This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.

=cut

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



( run in 0.840 second using v1.01-cache-2.11-cpan-7fcb06a456a )