#1 (permalink)  
Old 06-13-2005, 11:58 AM
Registered User
 
Join Date: May 2003
Posts: 49
MeGaMASTER
Question WHM Auto Script

Quote:
#!/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:

Quote:
#!/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!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 06-13-2005, 12:16 PM
Registered User
 
Join Date: Sep 2004
Location: Cleveland, Ohio
Posts: 378
Blue|Fusion is on a distinguished road
Disable open_basedir protection for the account you're trying to run this as.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 06-14-2005, 02:22 AM
Registered User
 
Join Date: Dec 2001
Posts: 14
ZaireWeb is on a distinguished road
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 06-14-2005, 01:30 PM
Registered User
 
Join Date: May 2003
Posts: 49
MeGaMASTER
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 07-12-2005, 05:20 PM
Registered User
 
Join Date: Oct 2004
Posts: 4
boeing747fp is on a distinguished road
how do u get to the accounting.inc.php file to copy it if open_basedir is in effect?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 07-14-2005, 03:19 AM
Registered User
 
Join Date: May 2003
Posts: 49
MeGaMASTER
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;    
}

?>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 07-14-2005, 05:00 AM
Registered User
 
Join Date: Jul 2005
Posts: 7
davemehta is on a distinguished road
Is there a function for adding subdomains and setting where they redirect to for a specific user account?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 07-16-2005, 09:55 AM
Registered User
 
Join Date: Aug 2004
Posts: 13
thekidscareya is on a distinguished road
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;

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 07-16-2005, 10:14 AM
Registered User
 
Join Date: May 2003
Posts: 49
MeGaMASTER
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 07-16-2005, 11:03 AM
Registered User
 
Join Date: Aug 2004
Posts: 13
thekidscareya is on a distinguished road
cool thanks
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #11 (permalink)  
Old 08-24-2005, 12:05 AM
Registered User
 
Join Date: Sep 2004
Posts: 45
bpmod is on a distinguished road
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #12 (permalink)  
Old 09-01-2005, 03:10 PM
Registered User
 
Join Date: Sep 2005
Posts: 1
diego4ever is on a distinguished road
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}&pas sword=${acctpass}&domain=${acctdomain}&plan=${acct plan}",$host,$user,$accesshash,$usessl);
if ($cpanelaccterr != "") { return; }
return $result;
}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 02:28 PM.


Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
© cPanel Inc