Page 2 of 8 FirstFirst 1234 ... LastLast
Results 16 to 30 of 108

Thread: XML API PHP Class version 1.0

  1. #16
    Member MattDees's Avatar
    Join Date
    Apr 2005
    Location
    Houston, TX
    Posts
    409

    Default

    I've encountered that issue before and have not been able to find a solution other than switching to fopen for handling.

    No clue why curl on some systems fails like that :-/
    Matt Dees

  2. #17
    cPanel Partner NOC cPanel Partner NOC Badge
    Join Date
    Dec 2009
    Posts
    3

    Default

    According to this original curl file ( [curl] Contents of /lib/transfer.c ), the error means, that the size for the read is bigger than the buffersize (it has to do with the upload size?!). I guess you add an curl curl_setopt for 'CURLOPT_BUFFERSIZE' to prevent this problem. Default buffer size is 16384bytes (16KB).

  3. #18
    Member
    Join Date
    Jun 2006
    Posts
    5

    Default

    Hi again, this code don't work with me.

    Code:
    $xmlapi->api1_query($cpuser, "Mysql", "addusertodb" array($newdb, $newuser, 'USAGE'));
    In RAW XML:
    Code:
    RAW API1 CALL:
    <cpanelaction><module>Mysql</module><func>addusertodb</func><apiversion>1</apiversion><args>test</args><args>test</args></cpanelaction>
    QUERY:
    https://...:2087/xml-api/cpanel?user...panelaction%3E
    
    RAW XML:
    
    <?xml version="1.0" ?>
    <cpanelresult><module>Mysql</module><func>addusertodb</func><type>event</type><source>internal</source><apiversion>1</apiversion><data><result></result></data>  <event>
        <result>1</result>
      </event>
    </cpanelresult>
    
    
    object(SimpleXMLElement)#3 (7) {
      ["module"]=>
      string(5) "Mysql"
      ["func"]=>
      string(11) "addusertodb"
      ["type"]=>
      string(5) "event"
      ["source"]=>
      string(8) "internal"
      ["apiversion"]=>
      string(1) "1"
      ["data"]=>
      object(SimpleXMLElement)#4 (1) {
        ["result"]=>
        object(SimpleXMLElement)#6 (0) {
        }
      }
      ["event"]=>
      object(SimpleXMLElement)#5 (1) {
        ["result"]=>
        string(1) "1"
      }
    }
    SIMPLEXML OBJ:
    Last edited by Infopro; 01-04-2010 at 04:26 AM.

  4. #19
    Member MattDees's Avatar
    Join Date
    Apr 2005
    Location
    Houston, TX
    Posts
    409

    Default

    Quote Originally Posted by Smuxinho View Post
    Hi again, this code don't work with me.

    Code:
    $xmlapi->api1_query($cpuser, "Mysql", "addusertodb" array($newdb, $newuser, 'USAGE'));
    it's adduserdb not addusertodb

    see: MysqlRef < DeveloperResources/ApiRef < TWiki
    Matt Dees

  5. #20
    Member
    Join Date
    Nov 2002
    Posts
    1,782
    cPanel/WHM Access Level

    DataCenter Provider

    Default list accounts

    Hi Matt,

    I am trying to use listaccts to get a list of all domains. Can i somehow get only the list of domains and no other information ? Right now all the domain details are being returned which are causing problems to parse for me.

    Any ideas ?
    :: Anand ::

    ssh root@
    who the hell is root ???

    Cpanelappz Support Forums are up now. Register Today
    http://forums.cpanelappz.com

    WHM/cPanel API : http://whmapi.cpanelappz.com
    Cpanel Login Script : www.cpanelappz.com/cpanel-login-script.htm
    Exiscan+Clam+Exim Auto Installer : www.cpanelappz.com

  6. #21
    Member
    Join Date
    Sep 2005
    Posts
    38

    Default

    Hello anand,

    The data should still be properly parseable.
    It's probably nothing that a regular expression or an xml class can't handle.

    Our company has succesfully implemented an advanced Reseller management enviroment with many of the XMLapi's options.

    The data that is returned is XML correct?
    XML can be parsed using PHP's builtin SimpleXML parser.
    (PHP: SimpleXML - Manual)

    Since your question is off-topic I suggest not to post any more comments concerning your issue in this particular thread.
    If you want further help, I offer my assistence,
    simply send me a private message with you contact details (IM would work)

  7. #22
    Member
    Join Date
    Nov 2002
    Posts
    1,782
    cPanel/WHM Access Level

    DataCenter Provider

    Default

    Hi Maever,

    Quote Originally Posted by maever View Post
    Hello anand,

    The data should still be properly parseable.
    It's probably nothing that a regular expression or an xml class can't handle.

    Our company has succesfully implemented an advanced Reseller management enviroment with many of the XMLapi's options.

    The data that is returned is XML correct?
    XML can be parsed using PHP's builtin SimpleXML parser.
    (PHP: SimpleXML - Manual)

    Since your question is off-topic I suggest not to post any more comments concerning your issue in this particular thread.
    If you want further help, I offer my assistence,
    simply send me a private message with you contact details (IM would work)
    Thanks for the pointer to simplexml. All i was trying to find was any parameter to the api which could only return a list of domains. Since we are sending query to many servers and they in turn have many domains hosted on them, hence the time taken to get respective data is very long. Incase the api can cut down and take additional parameters, the time taken to get data would be reduced for us.

    I will contact you via PM if required, thanks
    :: Anand ::

    ssh root@
    who the hell is root ???

    Cpanelappz Support Forums are up now. Register Today
    http://forums.cpanelappz.com

    WHM/cPanel API : http://whmapi.cpanelappz.com
    Cpanel Login Script : www.cpanelappz.com/cpanel-login-script.htm
    Exiscan+Clam+Exim Auto Installer : www.cpanelappz.com

  8. #23
    Registered User
    Join Date
    Oct 2006
    Posts
    4

    Default

    Hi,

    what would the syntax be for "addfwd" in regard to email forwarding?

    $xmlapi->api1_query($account, "Email", "addfwd", array(???) );


    Thanks.

    edit: also, what would the function and syntax be for an auto responder? Thanks again..!
    Last edited by Mr_Butter; 01-04-2010 at 02:36 AM.

  9. #24
    Member MattDees's Avatar
    Join Date
    Apr 2005
    Location
    Houston, TX
    Posts
    409

    Default

    Quote Originally Posted by Mr_Butter View Post
    Hi,

    what would the syntax be for "addfwd" in regard to email forwarding?

    $xmlapi->api1_query($account, "Email", "addfwd", array(???) );


    Thanks.

    edit: also, what would the function and syntax be for an auto responder? Thanks again..!
    API2:
    Code:
    Email::addforward
    
    API Version: 	2
    Description: 	Create an email forwarder for a specified address. You can forward mail to a new address or pipe incoming email to a program.
    Parameters: 	 
      	domain=>string
      	The domain for which you wish to add a forwarder. (e.g. example.com).
      	email=>string
      	The local address you wish to use as a forwarder. (e.g. 'user' if the address was user@example.com).
      	fwdemail=>string
      	The email address to which you want to forward mail..
      	pipefwd=>string (optional)
      	The path to the program to which you wish to pipe email..
    Returns: 	 
      	
    <data>
      <fwdemail> The email address that will receive forwarded mail.</fwdemail>
      <domain> The domain for which the forwarder was configured.</domain>
      <email> The email address that will act as the forwarder. </email>
    </data>
    11.25+ only.

    11:24 (api1) version:

    Email::addforward( $email, $forward, $domain, $return )



    As for addautoresponder, the syntax is (API1 call):
    Email::addautoresponder( $email, $from, $subject, $body, $domain, $html, $charset, $interval )

    Play with that one as you will. (PM me w/ questions)
    Matt Dees

  10. #25
    Member
    Join Date
    Feb 2005
    Posts
    43

    Default Trying to use the XML API PHP

    Hi,

    I'm using cPanel 11.25 and trying to use the xml api php for the first time.

    I am using an account username and password to login (not root). Trying to work on email addresses for that account only (list email addresses, create email address, change password, that kind of stuff).

    I set port to 2082 or 2083, I've tried both.

    If I use curl, I get this error in error_log:

    PHP Fatal error: Uncaught exception 'Exception' with message 'curl_exec threw error "read function returned funny value" .......

    If I switch to fopen, I get this error in error_log:

    PHP Warning: file_get_contents(http://xxx.xxx.xxx.xxx:2082/xml-api/cpanel) [<a href='function.file-get-contents'>function.file-get-contents</a>]: failed to open stream: HTTP request failed! HTTP/1.1 403 Forbidden\r\n in /home/..../xmlapi.php on line 695

    Please advise. This is the code I am using:

    PHP Code:
    include_once 'xmlapi.php';

    $user "account";
    $password "accountpassword";
    $ip "xxx.xxx.xxx.xxx";  //the account IP address

    $xmlapi = new xmlapi($ip);
    $xmlapi->set_port(2082);
    $xmlapi->password_auth($user$password);
    $xmlapi->set_debug(1);
    print 
    $xmlapi->api2_query($user"Email""listpopswithdisk"); 
    Edit:
    Found a solution to the cURL error.

    I had to add this line in the xmlapi.php file, inside the curl_query() function, I put it right before the curl_exec call:

    PHP Code:
    curl_setopt($curlCURLOPT_POSTFIELDS''); 
    Last edited by veronicabend; 01-04-2010 at 12:58 PM. Reason: Found a solution

  11. #26
    Member broncha's Avatar
    Join Date
    Feb 2009
    Location
    Kathmandu,Nepal
    Posts
    32
    cPanel/WHM Access Level

    Root Administrator

    Default nothing working for me

    Hi , this is what I have
    $hash = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
    $hash = str_replace(array("\r", "\n"),"",$hash);
    $xmlapi = new xmlapi($ip);
    $xmlapi->set_port(2086);
    $xmlapi->set_http_client("fopen");//curl throws me some error
    $xmlapi->hash_auth("root",$hash);
    $xmlapi->set_debug(1);
    $xmlapi->listips();


    This gives me nothing on the scree.I get a blank screen.
    I did escape the white spaces in the hash.
    nothing seems to be working.

    Is there something i need to change?

    EDIT:
    I found that it is just not working for one of my servers.
    I regenerated the hash but it is throwing the exception "Login Attempt Failed" . Can this be about the cPanel ? Definitely not the php class as it is working for other servers.
    Last edited by broncha; 01-07-2010 at 10:45 AM.

  12. #27
    Member
    Join Date
    Apr 2009
    Posts
    14

    Default

    This class really makes my work easier. Nice work.

    I have discovered some bugs that I thought of sharing, together with my proposed solutions.
    I'm not a regular poster so please bear with me if I get out of hand. Feedback in that case would be appreciated.

    Bug:
    Function set_auth_type() is broken. It will always return an error.
    Reason:
    PHP Code:
    public function set_auth_type$auth_type ) {
        if ( 
    $auth_type != 'hash' || $auth_type != 'pass') {
            throw new 
    Exception('the only two allowable auth types arehash and path');
        }
        
    $this->auth_type $auth_type;

    Since the if clause returns an error when true, the if statement should return true if $auth_type is neither 'hash' or 'pass'. The current if-statement is always true.
    PHP Code:
    Solution 1: if ( $auth_type != 'hash' && $auth_type != 'pass')
    Solution 2: if ( !($auth_type == 'hash' || $auth_type == 'pass') ) 

    Bug:
    xml data from server is not checked for utf-8 encoding
    Info:
    If xml data from server contains non-utf-8-encoding xmlapi_query() will fail returning an simplexml object (will return False instead) and 3 error messages will be printed on screen.

    This can happen if a cpanel user's language pack uses ISO-8859-1 and the user saves www.domain.ltd/Ö in an Addon Domain redirect.
    Then call $xmlapi->listaddondomains() on that user.

    cPanel has announced that everything (including language packs) should be in utf-8 so this error should be fixed on the server providers end. But it would be nice for the xmlapi class to handle these errors better.

    Proposed fix:
    The error messages are outputted by the simplexml_load_string() function. They can be supressed with 2 extra parameters.
    simplexml_load_string() returns false on error. Check this for error handling.
    PHP Code:
    //$response = simplexml_load_string($response); // Old code
    $response simplexml_load_string($responsenullLIBXML_NOERROR LIBXML_NOWARNING// This will remove the error messages.
    if (!$response){
            
    error_log("Some error message here");
            return;

    Another solution would be to determine which encoding that is used and use iconv() to change the encoding to utf-8, but cpanel has no xml-api function that can be used to fetch the encoding used for the language pack.
    mb_detect_encoding() or mb_check_encoding() may do the trick but they seem to be error prone, at least that's what I understand after reading the comments on php.net .
    PHP Code:
    $encoding = ... get encoding for the language pack
    $response 
    iconv($encoding"UTF-8"$response)
    ... 
    run simplexml_load_string() 
    Telling simplexml_load_string() the encoding of the xml data is also possible.
    Code:
    $encoding = ... get encoding for the language pack
    $response = "<?xml version=\"1.0\" encoding=\"$encoding\"?>\n".$response;
    ... run simplexml_load_string()
    Last edited by Svintoo; 01-12-2010 at 09:16 AM.

  13. #28
    Member MattDees's Avatar
    Join Date
    Apr 2005
    Location
    Houston, TX
    Posts
    409

    Default

    Svintoo, Thanks for the input, I've included your changes into the class and fixed a handful of other issues:

    http://sdk.cpanel.net/lib/xmlapi/php..._v1.0.3.tar.gz

    changelog:

    * Version: 1.0.3
    * Last updated: 13 January 2010
    *
    * Changes
    *
    * 1.0.3:
    * Fixed issue with set_auth_type using incorrect logic for determining acceptable auth types
    * Suppress non-UTF8 encoding error messages when using curl
    *
    * 1.0.2:
    * Increased curl buffer size to 128kb from 16kb
    * Fix double encoding issue in terminateresellers()
    *
    * 1.0.1:
    * Fixed use of wrong variable name in curl error checking
    * adjust park() to use api2 rather than API1
    Last edited by MattDees; 01-13-2010 at 10:48 AM.
    Matt Dees

  14. #29
    Member
    Join Date
    Jan 2010
    Posts
    7

    Exclamation

    Hi Matt,

    Thanks for the great class.

    I have a weird issue. My code:

    Code:
    require './xmlapi.php';
    
    $xmlapi = new xmlapi('xx.xx.xx.xx');
    
    $xmlapi->password_auth('root','pass');
    
    //$xmlapi->set_http_client('fopen');
    
    $xmlapi->set_debug(1);
    
    echo $xmlapi->listaccts()
    Nothing is printed, same problem with fopen.

    Now when I edit curl_query function and I add print $result; before return $result; I'm getting the result just fine.

    Please help. Thanks.
    Last edited by everactive; 01-15-2010 at 02:34 AM. Reason: Found the previous problem

  15. #30
    Member MattDees's Avatar
    Join Date
    Apr 2005
    Location
    Houston, TX
    Posts
    409

    Default

    Quote Originally Posted by everactive View Post
    Hi Matt,

    Thanks for the great class.

    I have a weird issue. My code:

    Code:
    require './xmlapi.php';
    
    $xmlapi = new xmlapi('xx.xx.xx.xx');
    
    $xmlapi->password_auth('root','pass');
    
    //$xmlapi->set_http_client('fopen');
    
    $xmlapi->set_debug(1);
    
    echo $xmlapi->listaccts()
    Nothing is printed, same problem with fopen.

    Now when I edit curl_query function and I add print $result; before return $result; I'm getting the result just fine.

    Please help. Thanks.
    If you could open a ticket along with steps to reproduce I'd be willing to look into this for you.. very very wierd.

    Are you using the latest version of the XML-API PHP class? And is anything coming up in the error_log?
    Matt Dees

Page 2 of 8 FirstFirst 1234 ... LastLast

Similar Threads

  1. Replies: 1
    Last Post: 06-04-2011, 09:52 AM
  2. XML API class works with a WHM cPanel reseller account?
    By bcosmo in forum cPanel Developers
    Replies: 1
    Last Post: 03-17-2010, 09:33 AM
  3. Install wildcard ssl using XML API class
    By tomdchi in forum cPanel Developers
    Replies: 4
    Last Post: 02-21-2010, 07:58 PM
  4. WHM XML API ready to use class
    By arash_hemmat in forum cPanel & WHM Discussions
    Replies: 3
    Last Post: 07-18-2008, 05:03 AM