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.

WHM Auto Script

Discussion in 'General Discussion' started by MeGaMASTER, Jun 13, 2005.

  1. MeGaMASTER

    MeGaMASTER Well-Known Member

    Joined:
    May 24, 2003
    Messages:
    49
    Likes Received:
    0
    Trophy Points:
    6
    I have tried the PHP code above which I have found on the cPanel website but after trying it I'm receiving lot of warning and error messages:

    Can someone please help me getting it working? Thanks! :)
     
  2. Blue|Fusion

    Blue|Fusion Well-Known Member

    Joined:
    Sep 12, 2004
    Messages:
    378
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    Cleveland, Ohio
    Disable open_basedir protection for the account you're trying to run this as.
     
  3. ZaireWeb

    ZaireWeb Member

    Joined:
    Dec 28, 2001
    Messages:
    14
    Likes Received:
    0
    Trophy Points:
    1
    Or, change your shebang line to the normal PHP path, and grab a copy of that accounting.inc file to place with your script
     
  4. MeGaMASTER

    MeGaMASTER Well-Known Member

    Joined:
    May 24, 2003
    Messages:
    49
    Likes Received:
    0
    Trophy Points:
    6
    Thank you for your help. I have copied the functions from the Accounting.php.inc file and paste them in my script and it is now working.
     
  5. boeing747fp

    boeing747fp Member

    Joined:
    Oct 3, 2004
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    1
    how do u get to the accounting.inc.php file to copy it if open_basedir is in effect?
     
  6. MeGaMASTER

    MeGaMASTER Well-Known Member

    Joined:
    May 24, 2003
    Messages:
    49
    Likes Received:
    0
    Trophy Points:
    6
    Ok here is the content of the Accounting.php.inc file. Just copy and paste the below codes and save it as Accounting.php.inc.

    PHP:
    <?php
    # cpanel4 - Accounting.php.inc              Copyright(c) 1999-2002 John N. Koston
    #                                 All rights Reserved.
    # nick@cpanel.net              http://cpanel.net         

    # This file is governed by the cPanel license


    global $cpanelaccterr;


    function 
    suspend ($host,$user,$accesshash,$usessl,$suspenduser) {
        
    $result whmreq("/scripts/remote_suspend?user=${suspenduser}",$host,$user,$accesshash,$usessl);
        if (
    $cpanelaccterr != "") { return; }
        return 
    $result;
    }
    function 
    unsuspend ($host,$user,$accesshash,$usessl,$suspenduser) {
        
    $result whmreq("/scripts/remote_unsuspend?user=${suspenduser}",$host,$user,$accesshash,$usessl);
        if (
    $cpanelaccterr != "") { return; }
        return 
    $result;
    }
    function 
    killacct ($host,$user,$accesshash,$usessl,$killuser) {
        
    $result whmreq("/scripts/killacct?user=${killuser}&nohtml=1",$host,$user,$accesshash,$usessl);
        if (
    $cpanelaccterr != "") { return; }
        return 
    $result;
    }
    function 
    showversion ($host,$user,$accesshash,$usessl) {
        
    $result whmreq("/scripts2/showversion",$host,$user,$accesshash,$usessl);
        if (
    $cpanelaccterr != "") { return; }
        return 
    $result;
    }
    function 
    createacct ($host,$user,$accesshash,$usessl,$acctdomain,$acctuser,$acctpass,$acctplan) {
        
    $result whmreq("/scripts/wwwacct?remote=1&nohtml=1&username=${acctuser}&password=${acctpass}&domain=${acctdomain}&plan=${acctplan}",$host,$user,$accesshash,$usessl);
        if (
    $cpanelaccterr != "") { return; }
        return 
    $result;
    }

    function 
    listaccts ($host,$user,$accesshash,$usessl) {
        
    $result whmreq("/scripts2/listaccts?nohtml=1&viewall=1",$host,$user,$accesshash,$usessl);
        if (
    $cpanelaccterr != "") { return; }

            
    $page split("\n",$result);
        foreach (
    $page as $line) {
            list(
    $acct,$contents) = split("="$line);
            if (
    $acct != "") {
                
    $allc split(","$contents);
                
    $accts[$acct] = $allc;
            }
            }
            return(
    $accts);
    }
    function 
    listpkgs ($host,$user,$accesshash,$usessl) {
        
    $result whmreq("/scripts/remote_listpkg",$host,$user,$accesshash,$usessl);
        if (
    $cpanelaccterr != "") { return; }


            
    $page split("\n",$result);
        foreach (
    $page as $line) {
            list(
    $pkg,$contents) = split("="$line);
            if (
    $pkg != "") {
                
    $allc split(","$contents);
                
    $pkgs[$pkg] = $allc;
            }
            }
            return(
    $pkgs);
    }
    function 
    whmreq ($request,$host,$user,$accesshash,$usessl) {


        
    $cleanaccesshash preg_replace("'(\r|\n)'","",$accesshash);
            
    $authstr $user ":" $cleanaccesshash;
        
    $cpanelaccterr "";


        if (
    function_exists("curl_init")) {
            
    $ch curl_init();
            if (
    $usessl) {
                
    curl_setopt($chCURLOPT_SSL_VERIFYPEER,0);                
                
    curl_setopt($chCURLOPT_SSL_VERIFYHOST,0);
                
    curl_setopt($chCURLOPT_URL"https://${host}:2087" $request);
            } else {
                
    curl_setopt($chCURLOPT_URL"http://${host}:2086" $request);
                    }
            
    curl_setopt($chCURLOPT_HEADER0);
            
    curl_setopt($chCURLOPT_RETURNTRANSFER,1);
                
    $curlheaders[0] = "Authorization: WHM $authstr";
                    
    curl_setopt($ch,CURLOPT_HTTPHEADER,$curlheaders);
            
    $data=curl_exec ($ch);
            
    curl_close ($ch);
        } elseif (
    function_exists("socket_create")) {
            if (
    $usessl) {
                
    $cpanelaccterr "SSL Support requires curl";
                return;
            }
            
    $service_port 2086;
            
    $address gethostbyname($host);
            
    $socket socket_create (AF_INETSOCK_STREAM0);
            if (
    $socket 0) {
                    
    $cpanelaccterr "socket_create() failed";
                return;
            }
            
    $result socket_connect ($socket$address$service_port);
            if (
    $result 0) {
                    
    $cpanelaccterr "socket_connect() failed";
                return;
            }
            
    $in "GET $request HTTP/1.0\n";
            
    socket_write($socket,$in,strlen($in));    
            
    $in "Connection: close\n";
            
    socket_write($socket,$in,strlen($in));    
            
    $in "Authorization: WHM $authstr\n\n\n";
            
    socket_write($socket,$in,strlen($in));    
        
            
    $inheader 1;
            while((
    $buf socket_read($socket512)) != false) {
              if (!
    $inheader) {
                  
    $data .= $buf;
                  }
              if(
    preg_match("'\r\n\r\n$'s"$buf)) {
                
    $inheader 0;
              }
              if(
    preg_match("'\n\n$'s"$buf)) {
                
    $inheader 0;
              }
              if(
    preg_match("'\r\n$'s"$buf)) {
                
    $inheader 0;
              }
            }

        } else {
            
    $cpanelaccterr "php not compiled with --enable-sockets OR curl";
            return;
        }

        return 
    $data;    
    }

    ?>
     
  7. davemehta

    davemehta Member

    Joined:
    Jul 13, 2005
    Messages:
    8
    Likes Received:
    0
    Trophy Points:
    1
    Is there a function for adding subdomains and setting where they redirect to for a specific user account?
     
  8. thekidscareya

    thekidscareya Member

    Joined:
    Aug 11, 2004
    Messages:
    13
    Likes Received:
    0
    Trophy Points:
    1
    I have a similar question to that:

    Can we modify Accounting.php.inc and add our own functions (eg...add one that creates a package)?

    Something using the following tempalte:
    PHP:

    function function_name ($arg) {
    // where the script is located....and variables
    $url "";
        
    $result whmreq($url,$host,$user,$accesshash,$usessl);
        if (
    $cpanelaccterr != "") { return; }
        return 
    $result;

     
  9. MeGaMASTER

    MeGaMASTER Well-Known Member

    Joined:
    May 24, 2003
    Messages:
    49
    Likes Received:
    0
    Trophy Points:
    6
    Yes. Anything that can be done in WHM, can be a function in this script. However your code is wrong. The function should look like this one:

    PHP:
    function addpkg ($host,$user,$accesshash,$usessl,$pkgname,$pkgquota,$pkghasshell,$pkgmaxftp,$maxpop,$pkgmaxlst,$pkgmaxsql,$pkgmaxsub,$pkgmaxpark,$pkgmaxaddon,$pkgcgi,$pkgfrontpage,$pkgbwlimit,$pkgcpmod,$pkgfeaturelist) { 
        
    $result whmreq("/scripts2/addpkg?name=${pkgname}&quota=${pkgquota}&hasshell=${pkghasshell}&maxftp=${pkgmaxftp}&maxpop=${pkgmaxpop}&maxlst=${pkgmaxlst}&maxsql=${pkgmaxsql}&maxsub=${pkgmaxsub}&maxpark=${pkgmaxpark}&maxaddon=${pkgmaxaddon}&cgi=${pkgcgi}&frontpage=${pkgfrontpage}&bwlimit=${pkgbwlimit}&cpmod=${pkgcpmod}&featurelist=${pkgfeaturelist}&nohtml=1",$host,$user,$accesshash,$usessl); 
        if (
    $cpanelaccterr != "") { return; } 
        return 
    $result
    }
     
    #9 MeGaMASTER, Jul 16, 2005
    Last edited: Jul 16, 2005
  10. thekidscareya

    thekidscareya Member

    Joined:
    Aug 11, 2004
    Messages:
    13
    Likes Received:
    0
    Trophy Points:
    1
  11. bpmod

    bpmod Well-Known Member

    Joined:
    Sep 23, 2004
    Messages:
    49
    Likes Received:
    0
    Trophy Points:
    6
    OK... could you elaborate?

    I have been trying for months to write scripts that will allow automation of such things as modifying a domain (changing from one package to another), adding sub-domains, add-on domains and parked domains (yes, I know they can do that in their own cPanel, but then I don't get to bill them for it) & adding FP extensions (ugh!).

    Any further help would be greatly appreciated.

    Thanks

    Brian
     
    #11 bpmod, Aug 23, 2005
    Last edited: Aug 24, 2005
  12. diego4ever

    diego4ever Registered

    Joined:
    Sep 1, 2005
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    1
    Parse error: parse error, unexpected T_STRING, expecting ')' in /home/revision/public

    The script above have an error in line 32, I solve it.

    function createacct ($host,$user,$accesshash,$usessl,$acctdomain,$acctuser,$acctpass,$acctplan) {
    $result = whmreq("/scripts/wwwacct?remote=1&nohtml=1&username=${acctuser}&password=${acctpass}&domain=${acctdomain}&plan=${acctplan}",$host,$user,$accesshash,$usessl);
    if ($cpanelaccterr != "") { return; }
    return $result;
    }
     
  13. raonaveed

    raonaveed Member

    Joined:
    Nov 30, 2009
    Messages:
    13
    Likes Received:
    0
    Trophy Points:
    1
    How to load packages of specific Reseller/Owner?

    Can you please explain how i can filter or only catch the packages of a specific reseller? So that less load and easily get specific owner specific packages.Thanks
     
Loading...

Share This Page