Community Forums
Connect with us on LinkedIn
Community Notice
+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 15 of 16
  1. #1
    Member
    Join Date
    May 2003
    Posts
    34

    Default Create and delete ftp account and subdomains

    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.
    Last edited by nazoreen; 06-22-2009 at 05:31 PM.

  2. #2
    Member
    Join Date
    May 2003
    Posts
    34

    Default

    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. #3
    Technical Product Specialist cPanelDavidG's Avatar
    Join Date
    Nov 2006
    Location
    Houston, TX
    Posts
    10,720
    cPanel/Enkompass Access Level

    Root Administrator

    Default

    Quote Originally Posted by nazoreen View Post
    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.
    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-...ss-111897.html

  4. #4
    Member
    Join Date
    May 2003
    Posts
    34

    Default

    Well addftp is OK.
    But delftp delete the public_html folder

    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. #5
    Member
    Join Date
    May 2003
    Posts
    34

    Default

    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. #6
    Member
    Join Date
    May 2003
    Posts
    34

    Default

    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. #7
    Member
    Join Date
    May 2003
    Posts
    34

    Default

    Just to report a broken link or no content link at this page :
    ApiTwo < AllDocumentation/AutomationIntegration < TWiki

    The chapter : Subdomains

    The link : Api2DeleteSubdomain < AllDocumentation/AutomationIntegration < TWiki

    It redirect to Cpanel::StatsBar::stat page.

    Thank you.

  8. #8
    Member
    Join Date
    May 2003
    Posts
    34

    Default

    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. #9
    Technical Product Specialist cPanelDavidG's Avatar
    Join Date
    Nov 2006
    Location
    Houston, TX
    Posts
    10,720
    cPanel/Enkompass Access Level

    Root Administrator

    Default

    Quote Originally Posted by nazoreen View Post
    Well addftp is OK.
    But delftp delete the public_html folder

    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.
    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. #10
    Technical Product Specialist cPanelDavidG's Avatar
    Join Date
    Nov 2006
    Location
    Houston, TX
    Posts
    10,720
    cPanel/Enkompass Access Level

    Root Administrator

    Default

    Quote Originally Posted by nazoreen View Post
    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.
    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/Al...ing_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. #11
    Technical Product Specialist cPanelDavidG's Avatar
    Join Date
    Nov 2006
    Location
    Houston, TX
    Posts
    10,720
    cPanel/Enkompass Access Level

    Root Administrator

    Default

    Quote Originally Posted by nazoreen View Post
    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.
    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. #12
    Technical Product Specialist cPanelDavidG's Avatar
    Join Date
    Nov 2006
    Location
    Houston, TX
    Posts
    10,720
    cPanel/Enkompass Access Level

    Root Administrator

    Default

    Quote Originally Posted by nazoreen View Post
    Just to report a broken link or no content link at this page :
    ApiTwo < AllDocumentation/AutomationIntegration < TWiki

    The chapter : Subdomains

    The link : Api2DeleteSubdomain < AllDocumentation/AutomationIntegration < TWiki

    It redirect to Cpanel::StatsBar::stat page.

    Thank you.
    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. #13
    Member
    Join Date
    May 2003
    Posts
    34

    Default

    Quote Originally Posted by cPanelDavidG View Post
    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>
    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. #14
    Member
    Join Date
    May 2003
    Posts
    34

    Default

    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 !
    Last edited by nazoreen; 06-22-2009 at 05:29 PM.

  15. #15
    Technical Product Specialist cPanelDavidG's Avatar
    Join Date
    Nov 2006
    Location
    Houston, TX
    Posts
    10,720
    cPanel/Enkompass Access Level

    Root Administrator

    Default

    Quote Originally Posted by nazoreen View Post
    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
    You are correct, I always forget that .

Similar Threads & Tags
Similar threads

  1. Can create, but not delete account?!
    By mstuebner in forum cPanel Developers
    Replies: 6
    Last Post: 01-08-2009, 02:49 PM
  2. FTP - No delete account?
    By Boriskag in forum cPanel and WHM Discussions
    Replies: 2
    Last Post: 09-26-2007, 03:37 PM
  3. Can I Create FTP Without Delete Permission?
    By aryapsh in forum cPanel and WHM Discussions
    Replies: 1
    Last Post: 08-07-2007, 01:01 PM
  4. I Can´t Create ou delete account
    By audisat in forum cPanel and WHM Discussions
    Replies: 8
    Last Post: 06-09-2007, 12:48 AM
  5. script to create subdomains and ftp account
    By theBassTender in forum cPanel and WHM Discussions
    Replies: 3
    Last Post: 08-04-2005, 09:48 PM
Linkedin       Facebook       Twitter       RSS       Flickr       YouTube