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.

Remote Account Creation

Discussion in 'General Discussion' started by thekidscareya, Oct 24, 2004.

  1. thekidscareya

    thekidscareya Member

    Joined:
    Aug 11, 2004
    Messages:
    13
    Likes Received:
    0
    Trophy Points:
    1
    How do I create an account using PHP on another server that has cPanel?

    Basically, how do I do it remotely?

    Thanks.
     
  2. dhrx

    dhrx Member

    Joined:
    Jan 22, 2003
    Messages:
    23
    Likes Received:
    0
    Trophy Points:
    1
    Hey

    Use the Cpanel API http://cpanel.net/remoteaccess-php.html

    Do a search around the forums theres code lying around on exactly how to do it, as long as you have the server hash you can create the account
     
  3. thekidscareya

    thekidscareya Member

    Joined:
    Aug 11, 2004
    Messages:
    13
    Likes Received:
    0
    Trophy Points:
    1
    I know how to create accounts when running the script on the server with cPanel...but what about having the script on one server and the cPanel hosting on another server. How would I do that?
     
  4. fwwebs

    fwwebs Well-Known Member

    Joined:
    Feb 16, 2004
    Messages:
    329
    Likes Received:
    0
    Trophy Points:
    16
    If the server running the script has cPanel, then refer to the cPanel documentation in the link. You will need to ensure that port 2086 or 2087 is open for outbound traffic on the server running the script.
     
  5. thekidscareya

    thekidscareya Member

    Joined:
    Aug 11, 2004
    Messages:
    13
    Likes Received:
    0
    Trophy Points:
    1
    I'm confused...the server that the script is running does have cPanel..but I dont want it to create accounts on that.
     
  6. fwwebs

    fwwebs Well-Known Member

    Joined:
    Feb 16, 2004
    Messages:
    329
    Likes Received:
    0
    Trophy Points:
    16
    The host name for the script will be the server name of the server you want to create the account on. You'll just be using the Accounting.inc file on the server hosting the script.
     
  7. dhrx

    dhrx Member

    Joined:
    Jan 22, 2003
    Messages:
    23
    Likes Received:
    0
    Trophy Points:
    1
    Yeah, after looking at my PHP files you should see when you do an API request or whatever you want to call it yhe $host variable I think contains localhost or an IP if you change that IP to the server you wish to setup the accounts for I can't see why that shouldn't work unless theres some sort of protection that stops accounts being setup when requests are being called from an external server

    Taken from the docs..

    PHP:
    #!/usr/local/cpanel/3rdparty/bin/php

    <?php

    require '/usr/local/cpanel/Cpanel/Accounting.php.inc';

    ///Change it here
    $host "localhost";
    /// End changing here

    $user "";
    $accesshash '';

    $accts listaccts($host,$user,$accesshash,0);
    print_r($accts);
    $pkgs listpkgs($host,$user,$accesshash,0);
    print_r($pkgs);
    ?>
    I hope thats what you were looking for...
     
  8. thekidscareya

    thekidscareya Member

    Joined:
    Aug 11, 2004
    Messages:
    13
    Likes Received:
    0
    Trophy Points:
    1
    OK....Let's define some stuff:

    Server A - where i want the accts to be made

    Server 1 - where the script is running

    My Server - my computer; it has php, mysql, apache and all that other good stuff


    ----


    what im trying to get to work
    Code:
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    
    <body>
    <?php
    
    $Hash = "the correct hash";
    
    $host = "the ip of server A";
    require '/usr/local/cpanel/Cpanel/Accounting.php.inc';
    $accts = listaccts($host,username,$hash,1);
    print_r($accts);
    
    ?>
    </body>
    </html>
    
    
    When i run the script on server 1 i get this:

    Code:
    
    Array ( [] => Array ( [0] => ) [] => Array ( [0] => ) [] => Array ( [0] => ) [ Array ( [0] => "Content-Type" content ) [ Array ( [0] => "shortcut icon" href ) [] => Array ( [0] => ) [] => Array ( [0] => ) [] => Array ( [0] => ) [Array ( [0] => "603" border ) [  Array ( [0] => "top"> ) [  ] => Array ( [0] => ) [ Array ( [0] => "100%" border ) [  ] => Array ( [0] => ) [  Array ( [0] => "2" colspan ) [ Array ( [0] => "100%" border ) [  ] => Array ( [0] => ) [   Array ( [0] => "/unprotected/images/bottom_label.gif" width ) [  ] => Array ( [0] => ) [  
    ] => Array ( [0] => ) [  ] => Array ( [0] => ) [  
    ] => Array ( [0] => ) [  ] => Array ( [0] => ) [  Array ( [0] => "right"> Array ( [0] => "135" nowrap align ) [  
    Array ( [0] => "top"> ) [  Array ( [0] => "3"> ) [  
    Array ( [0] => "top"> ) [  ] => Array ( [0] => ) [
    Web Host Manager Login
    Array ( [0] => 2>  Password  Array ( [0] => password name ) [ size] => Array ( [0] => 16> 
    Array ( [0] => "Login"> 
     
    
     
    Array ( [0] => "center"> ) [ ] => Array ( [0] => ) [ ] => Array ( [0] => ) [ ] => Array ( [0] => ) [] => Array ( [0] => ) [] => Array ( [0] => ) [] => Array ( [0] => ) ) 
    
     

    when i run the script on My Server i get this:

    Code:
    Warning: main(/usr/local/cpanel/Cpanel/Accounting.php.inc): failed to open stream: No such file or directory in C:\apache\xampp\htdocs\paid\admin\index.php on line 34
    
    Fatal error: main(): Failed opening required '/usr/local/cpanel/Cpanel/Accounting.php.inc' (include_path='.;c:\apache\xampp\php\pear\') in C:\apache\xampp\htdocs\paid\admin\index.php on line 34
    
    why doesnt the script work for any of the servers? also, why is there a difference when i run it on my server and server 1?
     
  9. fwwebs

    fwwebs Well-Known Member

    Joined:
    Feb 16, 2004
    Messages:
    329
    Likes Received:
    0
    Trophy Points:
    16
    This one actually tries to communicate with Server A, at least it appears to. Do you have the correct user and access hash?

    With the server "My Server", if it doesn't have cPanel, and it seems that it doesn't, it will not work because the file doesn't exist on the server running the script.

    There are several conditions that must be met for this to work:
    1. The server with the script must have cPanel.
    2. The server running the script, must have the permissions set to allow the script access to the Accounting.php.inc file.
    3. Port 2086 must be open to outbound traffic on the server running the script.

    With these conditions met account creation will work.

    Try putting a copy of the Accounting.php.inc file in the same directory as the script and call it with 'include("Accounting.php.inc");'. Then the only condition you must meet is 3.
     
    #9 fwwebs, Oct 28, 2004
    Last edited: Oct 28, 2004
  10. thekidscareya

    thekidscareya Member

    Joined:
    Aug 11, 2004
    Messages:
    13
    Likes Received:
    0
    Trophy Points:
    1
    can anyone post the code for accounting.php.inc here?

    EDIT: I found it in the forums.

    EDIT: I tried that, but I don't see anything...its if the script is totally ignored...nothing happens...why?
     
    #10 thekidscareya, Oct 29, 2004
    Last edited: Oct 29, 2004
  11. thekidscareya

    thekidscareya Member

    Joined:
    Aug 11, 2004
    Messages:
    13
    Likes Received:
    0
    Trophy Points:
    1
    BUMP...Can anyone help me?
     
  12. AntecWork

    AntecWork Registered
    PartnerNOC

    Joined:
    Feb 4, 2004
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    1
    You have to copy the php inc file over to your remote system that will be running the script to add an account to your cpanel machien. Doing this lets php know how to call functions like whmreq or createaccount. I suggest you use whmreq as its the most veristle and powerful function.



    aka

    root@cpanelbox# scp -r /usr/local/cpanel/Cpanel root@servertorunscript:/usr/local/cpanel/Cpanel;


    Then have the following in the script.
    #!/usr/local/cpanel/3rdparty/bin/php

    <?php

    require '/usr/local/cpanel/Cpanel/Accounting.php.inc';

    ///Change it here
    $host = "cpanelserver";
    /// End changing here

    $user = "root";
    $accesshash = 'cpanelservershash';
    $page=whmreq("/scripts/wwwacct?domain=$domain&username=$user&password=$pass&quota=$disklimit&bwlimit=$bandlimit&cgi=1&frontpage=1&maxftp=unlimited&maxpop=unlimited&maxsql=unlimited&maxlists=unlimited&maxsub=unlimited&maxpark=unlimited&maxaddon=unlimited&cpmod=x&contactemail=$email&reseller=0&ownerself=0");

    print $page
    ?>
     
  13. anand

    anand Well-Known Member

    Joined:
    Nov 11, 2002
    Messages:
    1,435
    Likes Received:
    1
    Trophy Points:
    38
    Location:
    India
    cPanel Access Level:
    DataCenter Provider
    Try http://whmapi.cpanelappz.com. It gives you access to most of the whm functions and is very easy to manage.
     
Loading...

Share This Page