Havri

Well-Known Member
Oct 28, 2013
86
19
8
cPanel Access Level
Root Administrator
Hello,

I am trying to write my first cPanel plugin. The language that I'm trying to write it in is Python. I am not an expert pythonist, so any fix, solution or tip is greatly appreciated.

I already created the cPanel plugin and the icon appears in the user's cPanel. I followed the tutorial from this link:

Tutorial - How to create a Plugin (WHM & cPanel)

After digging around a bit, I found that I can use cpanel's LIVE API, but there are no python examples. I also managed to find the example from a github user that created a cPanel LIVE API file, but it doesn't work:

github.com/dimentox/cpanel/tree/master/python

The errors that I'm seeing are the following:

Code:
Traceback (most recent call last):
  File "./frontend/paper_lantern/my_backups/my_backups.live.py", line 8, in <module>
    pprint.pprint(json.loads(form.value))
  File "/usr/lib64/python2.7/json/__init__.py", line 338, in loads
    return _default_decoder.decode(s)
  File "/usr/lib64/python2.7/json/decoder.py", line 366, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
TypeError: expected string or buffer
[2018-05-22 10:25:02 +0300] die [Internal Death while parsing [live engine] 9992] Child failed to make LIVEAPI connection to cPanel from: ./frontend/paper_lantern/my_backups/my_backups.live.py. at cpanel.pl line 4235.
 at cpanel.pl line 4235.
    cpanel::cpanel::setup_external_engine() called at cpanel.pl line 817
    cpanel::cpanel::script("cpanel::cpanel", "./frontend/paper_lantern/my_backups/my_backups.live.py") called at cpanel.pl line 271


Child failed to make LIVEAPI connection to cPanel from: ./frontend/paper_lantern/my_backups/my_backups.live.py. at cpanel.pl line 4235.
[2018-05-22 10:25:02 +0300] warn [cpaneld] The subprocess (cpanel (cpanel)) exited with an error: The subprocess reported error number 255 when it ended. at /usr/local/cpanel/Cpanel/Server/Handlers/SubProcess.pm line 251.
    Cpanel::Server::Handlers::SubProcess::_report_subprocess_errors(Cpanel::Server::Handlers::SubProcess=HASH(0x2dda7c0)) called at /usr/local/cpanel/Cpanel/Server/Handlers/SubProcess.pm line 109
    Cpanel::Server::Handlers::SubProcess::handler(Cpanel::Server::Handlers::SubProcess=HASH(0x2dda7c0), "subprocess_name", "cpanel (cpanel)", "subprocess_read_handle", IO::Handle=GLOB(0x2df4170), "subprocess_write_handle", IO::Handle=GLOB(0x2dbfb70), "subprocess_pid_to_reap", ...) called at cpsrvd.pl line 6816
    cpanel::cpsrvd::cpHandler("app", "cpanel", "document", "./frontend/paper_lantern/my_backups/my_backups.live.py") called at cpsrvd.pl line 2451
    cpanel::cpsrvd::dodoc_cpaneld() called at cpsrvd.pl line 1677
    cpanel::cpsrvd::dodoc(HASH(0x1338520)) called at cpsrvd.pl line 1452
    cpanel::cpsrvd::handle_one_connection(6) called at cpsrvd.pl line 893
    cpanel::cpsrvd::script() called at cpsrvd.pl line 324
warn [cpaneld] The subprocess (cpanel (cpanel)) exited with an error: The subprocess reported error number 255 when it ended.

Basically, what the plugin has to do is to list some files that are outside of the user's home directory (on some NFS mount or other dir on the server).

What I would like is an actual example that uses python, so that I can build from there. The example can be about anything (echo the username, echo homedir through de API, etc.).

Let me know if you need any other info.

Thank you.
 

Attachments

Last edited by a moderator:

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,904
2,218
463
Hello @Havri,

We don't provide a Python class for the LiveAPI system at this time, so that's something you'd need to develop on your own or have developed for you by a company offering development services. I'll leave this thread open for anyone else using a Python class to respond, but note the easier approach is to use PHP or Perl, since we provide classes for them already:

Guide to the LiveAPI System - Developer Documentation - cPanel Documentation
Guide to the LiveAPI System - PHP Class - Developer Documentation - cPanel Documentation
Guide to the LiveAPI System - Perl Module - Developer Documentation - cPanel Documentation

Let me know if you have any additional questions.

Thank you.
 

Anoop P Alias

Well-Known Member
Mar 31, 2015
103
16
18
Kochi,Kerala,India
cPanel Access Level
Root Administrator
I already have a working plugin fully in python -- you can see the code here -- github.com/AnoopAlias/XtendWeb/tree/ndeploy4/nDeploy_cp

the error you get is python code error

TypeError: expected string or buffer

it's not a cPanel issue. The LiveAPI socket being open warning can be overcome if you just close the socket

Code:
def close_cpanel_liveapisock():
    """We close the cpanel LiveAPI socket here as we dont need those"""
    cp_socket = os.environ["CPANEL_CONNECT_SOCKET"]
    sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
    sock.connect(cp_socket)
    sock.sendall('<cpanelxml shutdown="1" />')
    sock.close()


close_cpanel_liveapisock()
 
  • Like
Reactions: cPanelMichael