Results 1 to 4 of 4

Thread: Adding Accounts via script PHP without using root?

  1. #1
    Registered User
    Join Date
    May 2012
    Posts
    2
    cPanel/WHM Access Level

    Root Administrator

    Question Adding Accounts via script PHP without using root?

    Hi there,

    I wrote a script, which adds accounts on my whm-server. The problem is, that I'm using the root-user to gain access to all the information I need...

    I need to count all registered accounts on a server,
    and to add accounts,
    but I don't want to use the root-user (security).

    Is a reseller-account enough to perform this?
    Or is there any other way to create a user with nearly root-privileges?

    For creating accounts on my server, I use the following script:
    PHP Code:
    // Add Account
        
    $script "https://$rootname:$rootpass@$server:2087/scripts/wwwacct";
        
    $params "?plan={$package}&domain={$domain}&username=".$user."&password=".$pass."&contactemail={$mail}&language=de";
        
    $result file_get_contents($script.$params); 

    and for list accounts, i use the following function:

    PHP Code:
        public static function getCntDomains($rootname$rootpass$ip) {

                
    error_reporting(0);
                
    $query "https://".$ip.":2087/xml-api/listaccts";

                
    $curl curl_init();
                
    # Create Curl Object
                
    curl_setopt($curlCURLOPT_SSL_VERIFYPEER,0);
                
    # Allow self-signed certs
                
    curl_setopt($curlCURLOPT_SSL_VERIFYHOST,0);
                
    # Allow certs that do not match the hostname
                
    curl_setopt($curlCURLOPT_HEADER,0);
                
    # Do not include header in output
                
    curl_setopt($curlCURLOPT_RETURNTRANSFER,1);
                
    # Return contents of transfer on curl_exec
                
    $header[0] = "Authorization: Basic " base64_encode($rootname.":".$rootpass) . "\n\r";
                
    curl_setopt($curlCURLOPT_HTTPHEADER$header);
                
    # set the username and password
                
    curl_setopt($curlCURLOPT_URL$query);
                
    # execute the query
                
    $result curl_exec($curl);
                if (
    $result == false) {
                        
    error_log("curl_exec threw error \"" curl_error($curl) . "\" for $query");
                
    # log error if curl exec fails
                
    }
                
    curl_close($curl);

                
    $stripped strip_tags($result);
                
    $count substr_count($result$ip);
                return 
    $count;

        } 
    And as you know, if you havn't the privileges to perform this action, whm throws an error...

    help


    I'm sorry, if this is the wrong place to post, but i used the search-function (maybe not good enough?)
    and didn't find anything.


    Thanks in advance,
    daniel

  2. #2
    Member This forum account has been confirmed by cPanel staff to represent a vendor. KostonConsulting's Avatar
    Join Date
    Jun 2010
    Location
    Austin, TX
    Posts
    148
    cPanel/WHM Access Level

    Root Administrator

    Default Re: Adding Accounts via script PHP without using root?

    You can add accounts via a reseller but they will be added under that reseller user rather than root. Also, when listing accounts as the user, you will only see the accounts owned by the reseller and not all accounts.

    I'd recommend switching to /xml-api/createacct to create the account as cPanel doesn't guarantee that calling :2087/scripts/wwwacct will stay the same like /xml-api/createacct will.
    Dave Koston
    Koston Consulting
    http://www.kostonconsulting.com

  3. #3
    Technical Product Specialist cPanelDavidG's Avatar
    Join Date
    Nov 2006
    Location
    Houston, TX
    Posts
    11,307
    cPanel/WHM Access Level

    Root Administrator

    Default Re: Adding Accounts via script PHP without using root?

    I usually create a reseller account on my server with a bogus domain and give it root access as not to have user root used for terribly much (after all, it's often the target of brute force attacks and thus blocked by cphulkd anyway). A root-level reseller can do this without restrictions about which reseller owns the account.

  4. #4
    Registered User
    Join Date
    May 2012
    Posts
    2
    cPanel/WHM Access Level

    Root Administrator

    Default Re: Adding Accounts via script PHP without using root?

    Hey guys,

    thank you very much for the help. Finally I'm able to finalize this project.
    Thanks again

Similar Threads

  1. Adding rows to stat.html with data gathered by PHP script.
    By bbhsoft in forum cPanel Developers
    Replies: 6
    Last Post: 07-20-2009, 10:13 PM
  2. Help With php auction Script Please - Adding Fees
    By simplysites in forum cPanel & WHM Discussions
    Replies: 1
    Last Post: 07-20-2004, 03:55 AM
  3. Adding Email accounts using an external script, yet again
    By Pedro Monteiro in forum cPanel & WHM Discussions
    Replies: 6
    Last Post: 07-16-2004, 06:20 AM
  4. adding php script to /scripts
    By christi1 in forum cPanel & WHM Discussions
    Replies: 2
    Last Post: 06-29-2004, 09:16 AM
  5. adding email accounts with php script
    By tundra96 in forum cPanel & WHM Discussions
    Replies: 4
    Last Post: 07-15-2003, 05:48 PM