Enable cpapi2 in CageFS
Forum
  1. Forums
  2. CloudLinux and Control Panels
  3. CloudLinux and cPanel
  1. Ibra
  2. Tuesday, 28 August 2018
  3.  Subscribe via email
Hi!

I'm trying to enable the cpapi2 command, but I can't get it to work fully.

I created a file, cpapi2.cfg, in /etc/cagefs/conf.d containing the following:


[cpapi2]
comment=cPanel API v2
paths=/usr/bin/cpapi2


and executed:


cagefsctl --force-update


I then ran cpapi2 a regular user and the following was shown:


Utility to execute cPanel API calls

cpapi2 [options] [module] [uri-key=uri-value] [uri-key=uri-value] ....

Additional documentation is available at https://go.cpanel.net/api2docs

IMPORTANT: “uri-key” and “uri-value” represent URI-escaped strings.[*]

OPTIONS:
--output=[json|jsonpretty|xml|yaml]
The serialization format to use for output.

--input=[json|key-value]
The serialization format to use for input.
- key-value (default) - uri-key=uri-value pairs as arguments
- json - Read JSON from stdin (currently only supported for WHM API 1)


--user=USER
The user to run the API call as. REQUIRED when running “bin/apitool.pl” as root.

--help
Prints this help text.
Can't locate Cpanel.pm in @INC (you may need to install the Cpanel module) (@INC contains: /usr/local/cpanel /usr/local/cpanel/3rdparty/perl/526/lib64/perl5/cpanel_lib/x86_64-linux-64int /usr/local/cpanel/3rdparty/perl/526/lib64/perl5/cpanel_lib /usr/local/cpanel/3rdparty/perl/526/lib64/perl5/5.26.0/x86_64-linux-64int /usr/local/cpanel/3rdparty/perl/526/lib64/perl5/5.26.0 /opt/cpanel/perl5/526/site_lib/x86_64-linux-64int /opt/cpanel/perl5/526/site_lib) at /usr/local/cpanel/Cpanel/ApiInfo/UAPI.pm line 13.
BEGIN failed--compilation aborted at /usr/local/cpanel/Cpanel/ApiInfo/UAPI.pm line 13.
Compilation failed in require at /usr/local/cpanel/Cpanel/Template/Plugin/API_Shell.pm line 12.
BEGIN failed--compilation aborted at /usr/local/cpanel/Cpanel/Template/Plugin/API_Shell.pm line 12.
Compilation failed in require at bin/apitool.pl line 462.




Am I doing something wrong here? Any idea on how to get it working?
I'd appreciate some help! : )
Rate this post:
  1. 29.08.2018 16:08:24
  2. # 1
Ibra Accepted Answer
Posts: 0
Joined: 23.08.2019
0
Votes
Undo
@Aleksei Faians

I tried your suggestion, but it didn't work unfortunately.

As a test, I ran cpapi2 Ftp listftp which returned:



[2018-08-29 18:07:00 +0200] warn [cpapi2] Failed to execute /usr/local/cpanel/cpanel: No such file or directory at /usr/local/cpanel/Cpanel/XML.pm line 114.
Cpanel::XML::cpanel_exec_fast(HASH(0x8975b0), HASH(0xfa38e0)) called at bin/apitool.pl line 206
bin::apitool::_run_cpanel_function("yaml", HASH(0x8975b0), HASH(0xf45b50)) called at bin/apitool.pl line 146
bin::apitool::_cpanel_api_handler(__CPANEL_HIDDEN__, HASH(0xf45b50), __CPANEL_HIDDEN__, __CPANEL_HIDDEN__, ARRAY(0x897b20)) called at bin/apitool.pl line 108
bin::apitool::run("Ftp", "listftp") called at bin/apitool.pl line 37
warn [cpapi2] Failed to execute /usr/local/cpanel/cpanel: No such file or directory
Failed to execute /usr/local/cpanel/cpanel: No such file or directory at bin/apitool.pl line 209.


Thanks for replying though!

@Michael

Your solution worked great! Cheers! :)
  1. 29.08.2018 15:08:37
  2. # 2
Michael Accepted Answer
Posts: 4
Joined: 29.08.2018
0
Votes
Undo
Hello @Ibra,

You can grant access to the cpapi2 binary for caged users by adding the full path to the /etc/cagefs/custom.proxy.commands file per the instructions in the following document:

https://docs.cloudlinux.com/index.html?executing_by_proxy.html

For example:


# cat /etc/cagefs/custom.proxy.commands
CPAPI2=/usr/local/cpanel/bin/cpapi2

# cagefsctl --force-update


I tested and confirmed this works as expected:


# cpapi2 Ftp listftp
---
cpanelresult:
apiversion: 2
data:
-
homedir: /home/username
type: main
user: username
-
homedir: /usr/local/apache/domlogs/username
type: logaccess
user: username_logs
event:
result: 1
func: listftp


Let me know if you have any questions.

Thanks!
  1. 29.08.2018 15:08:36
  2. # 3
Aleksei Faians Accepted Answer
Posts: 21
Joined: 02.04.2018
0
Votes
Undo
Hello,

Yes, you can do as Michael suggested. Or you can just add /usr/local/cpanel/Cpanel.pm to paths in cpapi2.cfg, like this:

# cat /etc/cagefs/conf.d/cpapi2.cfg
[cpapi2]
comment=cPanel API v2
paths=/usr/bin/cpapi2,/usr/local/cpanel/Cpanel.pm

And then execute "cagefsctl --force-update".
  1. 29.08.2018 16:08:43
  2. # 4
Aleksei Faians Accepted Answer
Posts: 21
Joined: 02.04.2018
0
Votes
Undo
Hello,

Thank you for update. Indeed, this tool requires more stuff to be added to CageFS, so using proxyexec method (suggested by Michael) is actually better here.
  • Page :
  • 1


There are no replies made for this post yet.
Be one of the first to reply to this post!
Guest
Submit Your Response
Upload files or images for this discussion by clicking on the upload button below. Supports gif,jpg,png,zip,rar,pdf
• Insert • Remove Upload Files (Maximum File Size: 2 MB)
Captcha
To protect the site from bots and unauthorized scripts, we require that you enter the captcha codes below before posting your question.