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!

problem fetching the env variablecontaining the path to the socket

Discussion in 'cPanel Developers' started by JAB Creations, Dec 27, 2017.

  1. JAB Creations

    JAB Creations Member

    Joined:
    Nov 21, 2009
    Messages:
    17
    Likes Received:
    0
    Trophy Points:
    51
    Using the following:
    PHP:
    <?php
    include('/__fake_path__/cpanel.php');

    try
    {
     
    $cpanel = new CPANEL();
    }
    catch (
    Exception $e)
    {
       echo 
    'Caught exception: ',  $e->getMessage(), "\n";
    }
    ?>
    I received the following error:

    I read this post which did not make sense and tried the command on this page dotcult.com/what-the-hell-is-cpsrvd/ which had no effect.

    I have never actually gotten this cPanel class to work and have only had limited success with $xmlapi->api2_query. My only goal is to simply create an email account via PHP. If there is some higher level knowledge, permissions, etc that someone without a lot of experience using APIs should be made aware of please include those details.
     
    #1 JAB Creations, Dec 27, 2017
    Last edited by a moderator: Dec 27, 2017
  2. cPanelMichael

    cPanelMichael Technical Support Community Manager
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    44,806
    Likes Received:
    1,898
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Twitter:
    Hello,

    Is this for a cPanel plugin you are developing (that will appear for users in the cPanel UI), or is this for a standalone PHP script you are creating? If you are simply wanting to create an email account via a PHP script, there's no need to use the LiveAPI system. You could follow an example like the one referenced in the following thread:

    How to make new email accounts for cPanel user, from PHP script

    Thank you.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. JAB Creations

    JAB Creations Member

    Joined:
    Nov 21, 2009
    Messages:
    17
    Likes Received:
    0
    Trophy Points:
    51
    Thank you for the reply Michael. I'm trying to get this to work via PHP (tried the XML API first though abandoned it because the Github project looks largely abandoned with many pending commits).

    Using this:

    PHP:
    $result $xmlapi->api2_query(
        
    'Email''addpop',
        array(
            
    'domain'          => 'example.com',
            
    'email'           => 'username',
            
    'password'        => 'password',
            
    'quota'           => '0',
        )
    );
    I get the following error:

    I changed email field to user and still received the same error. What do I need to adjust?
     
  4. JAB Creations

    JAB Creations Member

    Joined:
    Nov 21, 2009
    Messages:
    17
    Likes Received:
    0
    Trophy Points:
    51
    I was missing the very first parameter: the user string (the cPanel username).

    PHP:
     $result $xmlapi->api2_query('cpanel_user_name','Email''addpop', array('domain' => 'example.com''email' => 'username''password' => 'password''quota' => '0'));
     
  5. cPanelMichael

    cPanelMichael Technical Support Community Manager
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    44,806
    Likes Received:
    1,898
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Twitter:
    Can you verify if that solved the issue?

    cPanel version 70 will be the last version to support XML-like output of our API. Here's a quote from our March 2017 Development Update:

    Thank you.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  6. JAB Creations

    JAB Creations Member

    Joined:
    Nov 21, 2009
    Messages:
    17
    Likes Received:
    0
    Trophy Points:
    51
    Yes.

    Why did you recommend the XML version if it was not only deprecated though also being outright removed in March?

    How? Is this something I trigger in the code or do I have to upload another file that I am not currently aware of? Where is that JSON equivalent? I highly prefer JSON for handling things on the server any way. Also I do not want to deal with having to run scripts in some highly miscellaneous unrelated directory. The development update did not mention an alternative.
     
  7. cPanelMichael

    cPanelMichael Technical Support Community Manager
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    44,806
    Likes Received:
    1,898
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Twitter:
    Hello,

    I've modified the response so that it no longer reflects the link to the PHP client class for interacting with cPanel's XML-API. It's a useful resource for proof-of-concept examples, but you are correct that it's not a good idea to offer that resource with the impending removal of support for XML-like output of APIs.

    Essentially, if your custom scripts are designed to rely on the XML-like output of our API functions, then you should modify them to instead rely on the JSON output. Here are a couple of threads that offer some insight into the differences:

    SOLVED - Manage Json Result from API
    WHM xmlApi call UAPI functions

    Thank you.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  8. JAB Creations

    JAB Creations Member

    Joined:
    Nov 21, 2009
    Messages:
    17
    Likes Received:
    0
    Trophy Points:
    51
    None of this helps, it's all fragmented and there are no full examples with basic obfuscation.

    Reading the UAPI documentation (which apparently should be called API3) it says to first do the following:

    PHP:
    $cpanel = new CPANEL();
    Which spawns the following error:

    For which there is little to nothing I could find in the search engines using quote operators. It's absolutely buried (four pages minimum to find) but it is listed here:

    Guide to the LiveAPI System - PHP Class - Software Development Kit - cPanel Documentation
    Which spawns the following error:

    So now I'm right back at my first post!

    So I go digging and that line in the file at /usr/local/cpanel/php/cpanel.php refers to
    Code:
    getenv('CPANEL_PHPCONNECT_SOCKET')
    which when I echo that from an example.live.php file located at /usr/local/cpanel/base/frontend is apparently blank.

    A reference here suggests that I can not call the PHP function from a live page (even included?)? Then they suggest to use the JSON version of the XML API. BUT YOU JUST SAID TO USE THE XML API THAT IS GOING TO BE DEPRECATED! This is all a circulatory waste of time!

    So absolutely dead-simple:

    If I have a PHP script located at:

    /home/_user_/public_html/example.php

    How do I have that PHP script create a new mail account when called from the client browser that will not expire after a lousy month or two?
     
  9. cPanelMichael

    cPanelMichael Technical Support Community Manager
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    44,806
    Likes Received:
    1,898
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Twitter:
    Hello,

    The LiveAPI system provides environments for applications in the cPanel interface. Thus, you should not use the LiveAPI system because your script exists within an account, and you are not intending it for use in the cPanel interface (e.g. you are not making a plugin that a user will access within their cPanel interface).

    There's no specific example of a PHP script that utilizes the email creation UAPI function. This will require custom coding and development on your part. That said, you may find user-submitted examples like the one referenced on the following third-party URL helpful:

    Create a new subdomain and MySQL database via WHM or cPanel API with PHP

    Otherwise, consider consulting with a developer or system administrator for help setting up a custom script:

    System Administration Services | cPanel Forums

    Thank you.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
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