Community Forums
Connect with us on LinkedIn
Community Notice
+ Reply to Thread
Results 1 to 13 of 13
  1. #1
    Member
    Join Date
    May 2003
    Posts
    49

    Question WHM Auto Script

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


    <?php

    require '/usr/local/cpanel/Cpanel/Accounting.php.inc';
    $host = "localhost";
    $user = "";
    $accesshash = '';

    $accts = listaccts($host,$user,$accesshash,0);
    print_r($accts);
    $pkgs = listpkgs($host,$user,$accesshash,0);
    print_r($pkgs);
    ?>
    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:

    #!/usr/local/cpanel/3rdparty/bin/php
    Warning: main(): open_basedir restriction in effect. File(/usr/local/cpanel/Cpanel/Accounting.php.inc) is not within the allowed path(s): (/home/username/:/usr/lib/php:/usr/local/lib/php:/tmp) in /home/username/public_html/listaccts.php on line 5

    Warning: main(/usr/local/cpanel/Cpanel/Accounting.php.inc): failed to open stream: Operation not permitted in /home/username/public_html/listaccts.php on line 5

    Warning: main(): open_basedir restriction in effect. File(/usr/local/cpanel/Cpanel/Accounting.php.inc) is not within the allowed path(s): (/home/username/:/usr/lib/php:/usr/local/lib/php:/tmp) in /home/username/public_html/listaccts.php on line 5

    Warning: main(/usr/local/cpanel/Cpanel/Accounting.php.inc): failed to open stream: Operation not permitted in /home/username/public_html/listaccts.php on line 5

    Fatal error: main(): Failed opening required '/usr/local/cpanel/Cpanel/Accounting.php.inc' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/username/public_html/listaccts.php on line 5
    Can someone please help me getting it working? Thanks!

  2. #2
    Member
    Join Date
    Sep 2004
    Location
    Cleveland, Ohio
    Posts
    378

    Default

    Disable open_basedir protection for the account you're trying to run this as.

  3. #3
    Member
    Join Date
    Dec 2001
    Posts
    14

    Default

    Or, change your shebang line to the normal PHP path, and grab a copy of that accounting.inc file to place with your script
    Eric Coleman
    eric.coleman@sitemod.net
    http://zaireweb.com

  4. #4
    Member
    Join Date
    May 2003
    Posts
    49

    Default

    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. #5
    Registered User
    Join Date
    Oct 2004
    Posts
    4

    Default

    how do u get to the accounting.inc.php file to copy it if open_basedir is in effect?

  6. #6
    Member
    Join Date
    May 2003
    Posts
    49

    Default

    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 Code:
    <?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. #7
    Member
    Join Date
    Jul 2005
    Posts
    7

    Default

    Is there a function for adding subdomains and setting where they redirect to for a specific user account?

  8. #8
    Member
    Join Date
    Aug 2004
    Posts
    13

    Default

    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 Code:

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

    Default

    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 Code:
    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

    Last edited by MeGaMASTER; 07-16-2005 at 10:37 AM.

  10. #10
    Member
    Join Date
    Aug 2004
    Posts
    13

    Default

    cool thanks

  11. #11
    Member
    Join Date
    Sep 2004
    Posts
    47

    Default

    Quote Originally Posted by MeGaMASTER
    Yes. Anything that can be done in WHM, can be a function in this script.
    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
    Last edited by bpmod; 08-24-2005 at 01:44 AM.

  12. #12
    Registered User
    Join Date
    Sep 2005
    Posts
    1

    Exclamation 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. #13
    Member
    Join Date
    Nov 2009
    Posts
    13

    Lightbulb How to load packages of specific Reseller/Owner?

    Quote Originally Posted by MeGaMASTER View Post
    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 Code:
    <?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;    
    }

    ?>
    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

Similar Threads & Tags
Similar threads

  1. recursive folders /usr/local/cpanel/perl/auto/auto/auto/auto...
    By bigste in forum cPanel and WHM Discussions
    Replies: 1
    Last Post: 10-15-2009, 12:52 AM
  2. Auto Backup Script
    By CJL in forum cPanel Developers
    Replies: 6
    Last Post: 07-03-2009, 01:30 AM
  3. Help! I need script for Auto Backup for SQL
    By jeepj27 in forum Database Discussions
    Replies: 1
    Last Post: 09-12-2006, 07:45 PM
  4. WHM Auto script...
    By *asterisk* in forum cPanel and WHM Discussions
    Replies: 6
    Last Post: 09-23-2005, 12:31 PM
  5. Auto Restart Script
    By Netsender in forum cPanel and WHM Discussions
    Replies: 1
    Last Post: 07-07-2004, 01:18 PM
Linkedin       Facebook       Twitter       RSS       Flickr       YouTube