The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Accessing delpop function via PHP

Discussion in 'cPanel Developers' started by devendradb, May 11, 2010.

  1. devendradb

    devendradb Member

    Joined:
    May 8, 2010
    Messages:
    18
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Mumbai, India
    on my web server delpop function is not working but I tried php code for addpop, passwdpop and editquota these functions are working. Can anybody tell me thye solution.
    Thanks.
     
  2. thewebhostingdi

    thewebhostingdi Well-Known Member

    Joined:
    Jan 10, 2008
    Messages:
    141
    Likes Received:
    0
    Trophy Points:
    16
    Kindly check the apache error logs for the exact error message when accessing your php page. You can check it from /usr/local/apache/logs/error_log.
     
  3. cPanelDon

    cPanelDon cPanel Quality Assurance Analyst
    Staff Member

    Joined:
    Nov 5, 2008
    Messages:
    2,557
    Likes Received:
    7
    Trophy Points:
    38
    Location:
    Houston, Texas, U.S.A.
    cPanel Access Level:
    DataCenter Provider
    Twitter:
    Please let us know greater detail so that the issue can be more accurately diagnosed:
    1.) What is the specific PHP code being used?
    2.) When using the PHP script, are there any errors logged? Look in both the PHP error_log (if one exists, perhaps in the same directory as the PHP script being executed) as well as looking in the cPanel error_log in "/usr/local/cpanel/logs/".
    3.) What method is being used to authenticate via the PHP script? Are you using a cPanel username and password, or a hash generated via WHM at the following menu path? ( WHM: Main >> Cluster/Remote Access >> Setup Remote Access Key )

    I recommend referring to our official documentation, as noted below:
     
    #3 cPanelDon, May 18, 2010
    Last edited: May 18, 2010
  4. devendradb

    devendradb Member

    Joined:
    May 8, 2010
    Messages:
    18
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Mumbai, India
    Delpop code

    Hi, I am using following code for using delpop function
    http://$cpuser:$cppass@$cpdomain:2082/frontend/$cpskin/mail/dodelpop.html?&email=$email&domain=$cpdomain

    instead of dodelpop I tried delpop also but both codes did not return any errors.
    thanks.
     
  5. cPanelDavidN

    cPanelDavidN Integration Developer
    Staff Member

    Joined:
    Dec 17, 2009
    Messages:
    571
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    Hi devendradb,

    I suppose that the sample URL that you provided *might* work, however that is not the recommended way.

    Like Donald suggested, you should make you requests using an API call. One way we recommend doing this is by using the XML-API binary and passing the API1 or API2 call to it. It's easy, you can do it remotely or on the localhost.

    One of the most convenient ways to make send requests to the XML-API binary is by using the XML-API PHP client class.
    http://sdk.cpanel.net/lib/xmlapi/php/cp_xmlapi_php_v1.0.5.tar.gz

    Once you have that, you can do something like this:
    Code:
    <?php
    include("xmlapi.php");
    
    $ip = "10.1.1.1";
    
    $xmlapi = new xmlapi($ip);
    $xmlapi->set_port('2083');
    
    $cpuser = "someone";
    $cppass = "pass123";
    $xmlapi->password_auth($cpuser,$cppass);
    
    //$xmlapi->set_debug(1);
    
    // to add a pop email //
    $add = array( 'email' => "testname", 'password' => "testpass123", 'domain' => "thisdomain.com", 'quota'=>0);
    $xmlapi->api2_query('someone','Email','addpop',$add);
    
    // to delete a pop email //
    $del = array( 'email' => "testname", "domain" => "thisdomain.com");
    $xmlapi->api2_query('someone','Email','delpop',$del);
    
    ?>
    
    By using the PHP class, you can easily handle the authentication. If you don't use the PHP class, then you could make the same URL requests -- just make sure to send the proper authentication headers.

    An example URL of delpop: (conveniently generated from debug mode in the PHP client class)
    Code:
    URL: https://10.1.1.1:2083/xml-api/cpanel
    
    DATA: email=testname&domain=thisdomain.com&user=someone&cpanel_xmlapi_module=Email&cpanel_xmlapi_func=delpop&cpanel_xmlapi_apiversion=2
    
    Authentication Header: Authorization: Basic c29tZW9uZZpmYXNzMTIz
    
    Regards,
    -David
     
  6. devendradb

    devendradb Member

    Joined:
    May 8, 2010
    Messages:
    18
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Mumbai, India
    Delpop

    Thanks David. This api worked fine thank you very much.
    - Devendra
     
  7. devendradb

    devendradb Member

    Joined:
    May 8, 2010
    Messages:
    18
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Mumbai, India
    Display data returned by API

    Hi David,
    Now I am trying new API functions but I am not able to extract correct data out of response.
    example: I am using listpopswithdisk API but I am not able to seperate each user or email id out of returned simpleXMLElement Object.
    I can just display whole string. (print_r($r))
    thanks in advance.
     
  8. MattDees

    MattDees cPanel Product Owner
    Staff Member

    Joined:
    Apr 29, 2005
    Messages:
    417
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    please see:

    PHP: SimpleXML Basic usage - Manual

    so, if you wanted to list out all of the usernames, you would want to do something like:

    PHP:
    include("xmlapi.php");

    $ip "127.0.0.1";
    $root_pass "testpassword";

    $account "someuser";

    $xmlapi = new xmlapi($ip);
    $xmlapi->password_auth("root",$root_pass);
    $xmlapi->set_output("simplexml");

    $resp $xmlapi->api2_query($account"Email""listpopswithdisk" );
    foreach ( 
    $resp->data as $email_user ) {
        print 
    $email_user->email "\n";
    }
     
  9. devendradb

    devendradb Member

    Joined:
    May 8, 2010
    Messages:
    18
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Mumbai, India
    Hi Matt,
    Thanks for the help. I tried the code, now I got the correct result. i can now able to put each user in <select> drop down menu.
    Thanks.
     
Loading...

Share This Page