Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!

cPanel python plugin

Discussion in 'cPanel Developers' started by Havri, May 22, 2018.

Tags:
  1. Havri

    Havri Well-Known Member

    Joined:
    Oct 28, 2013
    Messages:
    81
    Likes Received:
    17
    Trophy Points:
    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.
     

    Attached Files:

    #1 Havri, May 22, 2018
    Last edited by a moderator: May 22, 2018
  2. cPanelMichael

    cPanelMichael Technical Support Community Manager
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    45,423
    Likes Received:
    1,957
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Twitter:
    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.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. Anoop P Alias

    Anoop P Alias Well-Known Member

    Joined:
    Mar 31, 2015
    Messages:
    97
    Likes Received:
    14
    Trophy Points:
    8
    Location:
    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()
    
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
    cPanelMichael likes this.
Loading...

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice