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.

Create and delete ftp account and subdomains

Discussion in 'cPanel Developers' started by nazoreen, Jun 20, 2009.

  1. nazoreen

    nazoreen Active Member

    Joined:
    May 18, 2003
    Messages:
    34
    Likes Received:
    0
    Trophy Points:
    6
    Hello,

    I would try to create and delete ftp accounts and subdomains throught the API.

    Create in the same time and delete ine the same time all in PHP.

    I read the documentation but it is not very clear :(

    I try to check the mybrandedhost.com website, but it seems doesn't work.

    Have you got any little code snippets to make this ? (API1 or API2 never mind !)

    Thank you,
    Have a nice day.
     
    #1 nazoreen, Jun 20, 2009
    Last edited: Jun 22, 2009
  2. nazoreen

    nazoreen Active Member

    Joined:
    May 18, 2003
    Messages:
    34
    Likes Received:
    0
    Trophy Points:
    6
    Thank you,

    But how to connect, request (input) and get response (output) throught PHP ?

    The documentation is not clear, it could be better have something like this :

    Chapter 1 : getting start
    1.1 Perl
    1.1.0 Connection
    1.1.1 Input
    1.1.2 Output
    1.1.3 Available functions (list)

    1.2 PHP
    1.2.0 Connection
    1.2.1 Input
    1.2.2 Output
    1.2.3 Available functions (list)

    With an example for each of paragraph. It is very easy to make this, and it will be better for developper to find informations.

    Have a nice day.
     
  3. cPanelDavidG

    cPanelDavidG Technical Product Specialist

    Joined:
    Nov 29, 2006
    Messages:
    11,279
    Likes Received:
    8
    Trophy Points:
    38
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    The API receives a URL and outputs information in XML. Hence our documentation references XML rather than any specific language that can be used to process XML.

    If you're looking for an easy to use interface to the XML API, I recommend using Matt's PHP 5 Class: http://forums.cpanel.net/f42/xmlapi-php-class-111897.html
     
  4. nazoreen

    nazoreen Active Member

    Joined:
    May 18, 2003
    Messages:
    34
    Likes Received:
    0
    Trophy Points:
    6
    Well addftp is OK.
    But delftp delete the public_html folder :eek:

    This is because developpers must have a clear documentation with every command and variables (required and optionals) !!! We can't guess.

    Actually I didn't find documentation on your website for addftp, delftp, addsubdomain and delsubdomain ! I tried using your search engine and tried using Google.

    I think it is not very serious !

    This is the minimum we need.

    How to list all functions (and args) for cPanel ?

    Thank you,
    Have a nice day.
     
  5. nazoreen

    nazoreen Active Member

    Joined:
    May 18, 2003
    Messages:
    34
    Likes Received:
    0
    Trophy Points:
    6
    Well I understood why delftp removed public_html folder, this is because I chose / as homedir.

    But where is the information about this ?

    It is not a problem because I used a demo domain, but developpers need this information.

    Thank you.
     
  6. nazoreen

    nazoreen Active Member

    Joined:
    May 18, 2003
    Messages:
    34
    Likes Received:
    0
    Trophy Points:
    6
    Well addsubdomain is OK but there is something "bizarre" !

    The $FORM{'dir'} accept all these type of variable :
    /test
    public_html/test
    /public_html/test

    And all types create the subdomain http://test.domain.ext

    May be it could be interesting to restrict to /test variable only to prevent errors in the future.

    Actually I don't know exactly how to implement :
    Code:
    <?cp SubDomain::delsubdomain(% %,result,reason) domain=$FORM{'domain'} ?>
    in PHP

    I don't understand exactly what are %, result and reason... is there sentences ?

    Thank you.
     
  7. nazoreen

    nazoreen Active Member

    Joined:
    May 18, 2003
    Messages:
    34
    Likes Received:
    0
    Trophy Points:
    6
  8. nazoreen

    nazoreen Active Member

    Joined:
    May 18, 2003
    Messages:
    34
    Likes Received:
    0
    Trophy Points:
    6
    Below the xmlin variable for Cpanel::SubDomain::delsubdomain I try to make :
    Code:
    <cpanelaction><module>SubDomain</module><func>delsubdomain</func><apiversion>2</apiversion><args>...</args></cpanelaction>
    Could you tell me which args i must insert (with little example), please ?

    Thank you,
    Have a nice day.
     
  9. cPanelDavidG

    cPanelDavidG Technical Product Specialist

    Joined:
    Nov 29, 2006
    Messages:
    11,279
    Likes Received:
    8
    Trophy Points:
    38
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    We are currently in the process of finalizing documentation for API1 and API2. In the meantime, you can look at the source code of the X3 theme to find the functions (and their arguments). The X3 theme source can be found at /usr/local/cpanel/base/frontend/x3/

    For example, look at /usr/local/cpanel/base/frontend/x3/ftp/realdodelftp.html to see how to delete a FTP account:

    Code:
    <cpanel Ftp="delftp($FORM{'login'},$FORM{'destroy'})">
    The first parameter is the FTP login and the second parameter is 1 if you want to destroy (delete) the folder associated with that FTP login upon deleting the account.

    If you are uncomfortable looking through the source code, let me know and I'll gladly provide you with the functions and arguments to make up for our lack of documentation at this time.
     
  10. cPanelDavidG

    cPanelDavidG Technical Product Specialist

    Joined:
    Nov 29, 2006
    Messages:
    11,279
    Likes Received:
    8
    Trophy Points:
    38
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    Yeah, that's mostly for output. API2 syntax can get rather confusing. You can review my reference slides for API2 beginning on slide 23 of this presentation from our 2007 cPanel Conference:

    http://twiki.cpanel.net/twiki/pub/A...urces/TrainingSlides07/Customizing_cPanel.pdf

    For the function you pasted, there would only be 1 input parameter, and it would be named domain. In API2, parameters are named. In API1, they're just passed in sequence. This means API2 can have more flexibility regarding required and optional parameters.

    As for your dir parameter, I'm not understanding what you see so abnormal about that. Perhaps I am overlooking something? That parameter can take in any folder within a user's home directory, and the name doesn't need to match the name of the subdomain (e.g. test.example.com could just serve content from ~/example).
     
  11. cPanelDavidG

    cPanelDavidG Technical Product Specialist

    Joined:
    Nov 29, 2006
    Messages:
    11,279
    Likes Received:
    8
    Trophy Points:
    38
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    You are very close... here's what I would use if I was removing subdomain.example.com from my account:

    Code:
    <cpanelaction><module>SubDomain</module><func>delsubdomain</func><apiversion>2</apiversion><args><domain>subdomain.example.com</domain></args></cpanelaction>
     
  12. cPanelDavidG

    cPanelDavidG Technical Product Specialist

    Joined:
    Nov 29, 2006
    Messages:
    11,279
    Likes Received:
    8
    Trophy Points:
    38
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    Thanks for bringing that to my attention. I've had our documentation team fix that link and they are auditing that section of our documentation site to see if there are any other incorrect links.
     
  13. nazoreen

    nazoreen Active Member

    Joined:
    May 18, 2003
    Messages:
    34
    Likes Received:
    0
    Trophy Points:
    6
    Thank you but isn't it subdomain_example.com instead of subdomain.example.com ?

    Have a nice day.

    I will look on the server at /usr/local/cpanel/base/frontend/x3/ for others functions :)

    Byebye
     
  14. nazoreen

    nazoreen Active Member

    Joined:
    May 18, 2003
    Messages:
    34
    Likes Received:
    0
    Trophy Points:
    6
    Thank you davidbon and cPanelDavidG,

    Below the "work fine" code I made :

    Code:
    <?php
    $conn = array ( 'host' => '127.0.0.1'
                  , 'port' => '2083'
                  , 'user' => 'cpanel_user'
                  , 'pass' => 'cpanel_pass'
                  ) ;
    
    function cpanel_api ( $conn , $type , $user , $pass , $domain )
    {
     if ( $conn [ 'port' ] == '2087' || $conn [ 'port' ] == '2083' || $conn [ 'port' ] == '443' )
     {
     	$site = 'https://' . $conn [ 'host' ] . ':' . $conn [ 'port' ] ;
     } else {
     	$site = 'http://' . $conn [ 'host' ] . ':' . $conn [ 'port' ] ;
     }
     
     switch ( $type )
     {
     	case 'add_ftp' :
     	 $xmlin = '<cpanelaction><module>Ftp</module><func>addftp</func><apiversion>1</apiversion><args>' . $user . '</args><args>' . $pass . '</args><args>/' . $user . '</args><args>20</args></cpanelaction>' ;
     	 break ;
     	 
     	case 'del_ftp' :
     	 $xmlin = '<cpanelaction><module>Ftp</module><func>delftp</func><apiversion>1</apiversion><args>' . $user . '</args><args>1</args></cpanelaction>' ;
     	 break ;
     	 
     	case 'add_subdomain' :
     	 $xmlin = '<cpanelaction><module>SubDomain</module><func>addsubdomain</func><apiversion>1</apiversion><args>' . $user . '</args><args>' . $domain . '</args><args>0</args><args>0</args><args>/' . $user . '</args></cpanelaction>' ;
     	 break ;
     	 
     	case 'del_subdomain' :
     	 $xmlin = '<cpanelaction><module>SubDomain</module><func>delsubdomain</func><apiversion>2</apiversion><args><domain>' . $user . $domain . '</domain></args></cpanelaction>' ;
     	 break ;
     	 
     	default :
     	 echo 'Type error' ;
     }
     
     if ( $type == 'add_ftp' || $type == 'del_ftp' || $type == 'add_subdomain' || $type == 'del_subdomain' )
     {
      $query = '/xml-api/cpanel?user=' . $conn [ 'user' ] . '&xmlin=' . $xmlin ;
      
      $curl = curl_init ( ) ;
      curl_setopt ( $curl, CURLOPT_SSL_VERIFYPEER , 0 ) ;
      curl_setopt ( $curl, CURLOPT_RETURNTRANSFER , 1 ) ;
      curl_setopt ( $curl, CURLOPT_SSL_VERIFYHOST , 0 ) ;
      curl_setopt ( $curl, CURLOPT_USERPWD        , $conn [ 'user' ] . ':' . $conn [ 'pass' ] ) ;
      curl_setopt ( $curl, CURLOPT_HEADER         , 0 ) ;
      curl_setopt ( $curl, CURLOPT_URL            , $site . $query ) ;
      $result = curl_exec ( $curl ) ;
      curl_close ( $curl ) ;
     }
    }
    
    /***** ADD Subdomain and FTP Account *****/
    cpanel_api ( $conn , 'add_subdomain' , 'test' , '0123456789' , '.domain.com' ) ;
    cpanel_api ( $conn , 'add_ftp'       , 'test' , '0123456789' , '.domain.com' ) ;
    
    /***** DEL Subdomain and FTP Account *****/
    //cpanel_api ( $conn , 'del_subdomain' , 'test' , '0123456789' , '.domain.com' ) ;
    //cpanel_api ( $conn , 'del_ftp'       , 'test' , '0123456789' , '.domain.com' ) ;
    ?>
    Don't forget to use in your php.ini :
    allow_url_fopen = On

    Have a nice day !
     
    #14 nazoreen, Jun 22, 2009
    Last edited: Jun 22, 2009
  15. cPanelDavidG

    cPanelDavidG Technical Product Specialist

    Joined:
    Nov 29, 2006
    Messages:
    11,279
    Likes Received:
    8
    Trophy Points:
    38
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    You are correct, I always forget that :).
     
  16. nazoreen

    nazoreen Active Member

    Joined:
    May 18, 2003
    Messages:
    34
    Likes Received:
    0
    Trophy Points:
    6
    Never mind the 2 types "subdomain_example.com" and "subdomain.example.com" work fine.

    Byebye
     
Loading...

Share This Page