Community Forums
Connect with us on LinkedIn
+ Reply to Thread
Results 1 to 4 of 4
  1. #1
    Registered User
    Join Date
    Feb 2008
    Posts
    3

    Default API not working after cpanel upgrade:11.16.0-RELEASE

    hi

    We have the below code working before cpanel upgrade. This code use to fetch us the data through cpanel. Please let us know the changes which needs to be made on our side to fix this code as per new cpanel.

    <?php
    class HTTP
    {
    function HTTP($host, $username, $password, $port = 2082, $ssl = '', $theme = 'sg')
    {
    $this->ssl = $ssl ? 'ssl://' : '';
    $this->username = $username;
    $this->password = $password;
    $this->theme = $theme;
    $this->auth = base64_encode($username . ':' . $password);
    $this->port = $port;
    $this->host = $host;
    $this->path = '/frontend/' . $theme . '/';
    }

    function getData($url, $data = '')
    {
    $url = $this->path . $url;
    if(is_array($data))
    {
    $url = $url . '?';
    foreach($data as $key=>$value)
    {
    $url .= urlencode($key) . '=' . urlencode($value) . '&';
    }
    $url = substr($url, 0, -1);
    }
    $response = '';
    $fp = fsockopen($this->ssl . $this->host, $this->port);
    if(!$fp)
    {
    return false;
    }
    $out = 'GET ' . $url . ' HTTP/1.0' . "\r\n";
    $out .= 'Authorization: Basic ' . $this->auth . "\r\n";
    $out .= 'Connection: Close' . "\r\n\r\n";
    fwrite($fp, $out);
    while (!feof($fp))
    {
    $response .= @fgets($fp);
    }
    fclose($fp);
    return $response;
    }
    }

    /**
    * Functions to manipulate cPanel
    */
    class cPanel
    {
    /**
    * Creates an object to manipulate cPanel
    * @param string $host cPanel host without leading http://
    * @param string $username cPanel username
    * @param string $password cPanel password
    * @param int $port cPanel port, default to 2082. Change to 2083 if using SSL
    * @param bool $ssl False for http (default), true for SSL (requires OpenSSL)
    * @param string $theme cPanel theme, (forward compatibility- 'sg' theme currently required)
    * @return cPanel
    */
    function cPanel($host, $username, $password, $port = 2082, $ssl = false, $theme = 'sg')
    {
    $this->HTTP = new HTTP($host, $username, $password, $port, $ssl, $theme);
    }

    /**
    * Change cPanel's password
    *
    * Returns true on success or false on failure.
    * The cPanel object is no longer usable after changing the password.
    * @param string $password new password
    * @return bool
    */
    function setPassword($password)
    {
    $data['oldpass'] = $this->HTTP->password;
    $data['newpass'] = $password;
    $response = $this->HTTP->getData('passwd/changepass.html', $data);
    if(strpos($response, 'has been') && !strpos($response, 'could not'))
    {
    return true;
    }
    return false;
    }

    /**
    * Retrieve contact email address.
    *
    * Returns the contact email address listed in cPanel.
    * @return string
    */
    function getContactEmail()
    {
    $email = array();
    preg_match('/email" value="(.*)"/', $this->HTTP->getData('contact/index.html'), $email);
    return $email[1];
    }

    /**
    * Modify contact email address
    *
    * Returns true on success or false on failure.
    * @param string new contact email address
    * @return string
    */
    function setContactEmail($email)
    {
    $data['email'] = $email;
    $response = $this->HTTP->getData('contact/saveemail.html', $data);
    if(strpos($response, 'has been'))
    {
    return true;
    }
    return false;
    }

    /**
    * List all domains in the cPanel account
    *
    * Returns a numerically-indexed array on success or false on failure.
    * @return array
    */
    function listDomains()
    {
    $domainList = array();
    preg_match_all('/<option value="([^"]*)/', $this->HTTP->getData('mail/addpop2.html'), $domainList);
    if(count($domainList[1]) > 0)
    {
    return $domainList[1];
    }
    return false;
    }

    /**
    * List all POP3 email accounts
    *
    * Returns a numerically-indexed array on success or false on failure.
    * @return array
    */
    function listMailAccounts()
    {
    $accountList = array();
    preg_match_all('/\?acct=([^"]*)/', $this->HTTP->getData('mail/pops.html'), $accountList);
    if(count($accountList[1]) > 0)
    {
    return $accountList[1];
    }
    return false;
    }

    /**

  2. #2
    Technical Product Specialist cPanelDavidG's Avatar
    Join Date
    Nov 2006
    Location
    Houston, TX
    Posts
    11,189
    cPanel/Enkompass Access Level

    Root Administrator

    Default

    Looks like you're doing a lot of things without using APIs. You may wish to switch over to using APIs so you wont need to worry much about cPanel upgrades breaking your scripts in the future.

    Relevant API function calls you may want to use instead:

    - Change Password: XML API passwd - http://www.cpanel.net/plugins/xmlapi/passwd.html
    - Get Contact Email: XML API listaccts - http://www.cpanel.net/plugins/xmlapi/listaccts.html
    - Set Contact Email: API2 CustInfo::savecontactinfo (1)
    - List all domains for an account: You could use the XML API listaccts function to get the primary domain, then use API2 Park::listaddondomains (2) for addon domains and for parked domains use Park::listparkeddomains http://www.cpanel.net/plugins/api2/C...mains.pod.html
    - List all POP3 accounts: API2 Email::listpopswithdisk - http://www.cpanel.net/plugins/api2/C...hdisk.pod.html

    Note that API2 functions can be called via the XML API. More documentation at: http://www.cPanel.net/plugins/devel

    (1) = Not yet documented. Look at /usr/local/cpanel/base/frontend/x3/contact/savemailinclude.html to see how it is implemented in the X3 theme.

    (2) = Not yet documented. Look at /usr/local/cpanel/base/frontend/x3/addon/index.html to see how it is implemented in the X3 theme.

    Of course, you could always simply look at the contents of the appropriate files in /usr/local/cpanel/base/frontend/x3 to see how things are handled by the X3 theme. However as X3 itself is merely a graphical interface to the APIs, you may wish to interact directly with the APIs rather than using the X3 as an interface to the APIs.

  3. #3
    Registered User
    Join Date
    Apr 2008
    Posts
    1

    Default I have exactly the same problem

    How did you get on with this issue ?

    We have to force upgrade from theme x to x3 since x didn't allow us to do all the the things we wanted to do with mapping domains.

    Like you, most of our code, which is basically identical to yours has broke.

    And as usual we are on tight deadlines to finish off the current project.

    To be blunt, the documentation for PHP use for X3 seems to be a bit hard to locate. We don't really want to use XML. We need a library of simple PHP calls which mainly perform the following functions which fit into our existing framework.

    Find out what email addresses exist on the server. ***
    Find our what domains exist on the server.
    Add a domain
    Add an email address
    Delete a domain
    Delete an email address.

    Hope you can provide me with some feedback. I would appreciate this very much.

    Ed
    Ed Hollingshead
    sales@mediatradingservices.co.uk

  4. #4
    Technical Product Specialist cPanelDavidG's Avatar
    Join Date
    Nov 2006
    Location
    Houston, TX
    Posts
    11,189
    cPanel/Enkompass Access Level

    Root Administrator

    Default

    If you do not desire to use XML, then there are no APIs available for you to use to achieve the functionality you desire outside of cPanel (or a shell environment) itself.

    There are plenty of PHP code samples on how to use the XML-API around the forum, I recommend performing a forum search.

Similar Threads & Tags
Similar threads

  1. cPanel API not working on our iWeb host.
    By dbarbier in forum cPanel Developers
    Replies: 6
    Last Post: 04-19-2010, 03:00 PM
  2. Failed cPanel 11 Upgrade on Release
    By kre8web in forum cPanel and WHM Discussions
    Replies: 7
    Last Post: 08-26-2007, 09:00 PM
  3. New cPanel Upgrade 9.7.7-RELEASE 15 ERRORS !!!
    By gorilla in forum cPanel and WHM Discussions
    Replies: 6
    Last Post: 09-17-2004, 01:55 PM
  4. Replies: 0
    Last Post: 01-31-2004, 01:31 PM
  5. How to upgrade from Edge to Release
    By alecx in forum cPanel and WHM Discussions
    Replies: 6
    Last Post: 08-08-2003, 10:47 PM
Linkedin       Facebook       Twitter       RSS       Flickr       YouTube