Cpanel PHP Accounting functions

andyf

Well-Known Member
Jan 7, 2002
249
0
316
UK
I notice that the Perl version of the accounting has been expanded quite significantly to include a whole list of new integration features.

Any chance the same will be done to the PHP version soon?

Thanks.
 

jimcarter

Well-Known Member
Jun 30, 2002
152
0
166
UK
Hi,
I dont see any extra features with the perl accounting module,
however, if you post the extra features you have found I would be happy to add them into the php accounting module for you,
Thanks
 

jimcarter

Well-Known Member
Jun 30, 2002
152
0
166
UK
By the way, if anyone else would like some extra functions for the accounting module, I heard that some people wanted password modification features etc, I would be happy to add them,
when tested working maybe the cpanel staff will add the new file into the distribution so its easier for everyone :)
 

gic

Well-Known Member
Jun 28, 2002
67
0
156
Yes. Thanks to jimcarter, I too now understand how this stuff works. If you need functions written, let me know. I have upgrade/downgrade, password mod, create, remove, and I am going to setup suspend/unsuspend. They are very easy to understand.

I can also create new functions for you.
 

andyf

Well-Known Member
Jan 7, 2002
249
0
316
UK
Ok, I consider myself fairly proficient in PHP.

Any chance you guys could give us a rundown on how these little babies work? :)
 

gic

Well-Known Member
Jun 28, 2002
67
0
156
Okay. The two parts. First off is how to use the fuctions. That is pretty straight forward. We will use the createacct for an example.

PHP:
<?
require '/usr/local/cpanel/Cpanel/Accounting.php.inc';
    $host = "localhost";
    $user = "root";
    $accesshash = 'ACCESS HASH SHOULD BE PASTED HERE';    
    $usessl = "0";

$do = createacct($host,$user,$accesshash,$usessl,$acctdomain,$acctuser,$acctpass,$acctplan);
if (!eregi("wwwacct creation finished",$do)){
	echo "Oh no.  There was a problem.";
}
else {
	echo "Great, the account $acctuser was created successfully.";
}
?>
For this example, all that you need to give it are:
$host = your hostname (usually localhost)
$user = your WHM username (either root or reseller name)
$accesshash = the access hash pasted directly from WHM
$usessl = 1 means to use cURL, 0 means to use socket_connect
$acctdomain = the domain name of the new account
$acctuser = the username of the new account
$acctpass = the password of the new account
$acctplan = the plan name of the new account. (if the plan name has a space, replace it with a + sign)

Just send those variable to this PHP file and it will create the account. If the account is created, it says "Great, the account $acctuser was created successfully". Otherwise it says "Oh no. There was a problem".

-----------------

Next, we look at functions... This came out of my Accounting.php.inc file.
PHP:
function changepass ($host,$user,$accesshash,$usessl,$acctpass,$acctuser) {
	$result = whmreq("/scripts/passwd?remote=1&nohtml=1&password=${acctpass}&domain=${acctuser}&user=${acctuser}&submit-domain=Change%0D%0A++++++Password",$host,$user,$accesshash,$usessl);
	if ($cpanelaccterr != "") { return; }
	return $result;
}
This is a new function that I made. It allows you to change the password of an account.

The part after result (/scripts/passwd) was taken directly from WHM when you submit the form to change the password. Then I inlclude the variables that the password script needs.

Now, I just have to provide the following in a PHP file:
PHP:
<?
require '/usr/local/cpanel/Cpanel/Accounting.php.inc';
    $host = "localhost";
    $user = "root";
    $accesshash = 'ACCESS HASH GOES HERE';    
    $usessl = "0";

$do = changepass($host,$user,$accesshash,$usessl,$acctpass,$acctuser);
if (eregi("syntax mismatch",$do)){
	echo "OOps, you broke it.  I don't think that the username was correct.";
}
else {
	echo "Great job!  Your password has been changed to $acctpass.";
}
?>
Okay, in the example above, you just provide:

$host = hostname (localhost usually)
$user = your WHM username (root or reseller name)
$accesshash = the access hash directly from WHM
$usessl = 1 means to use cURL, 2 means socket_connect
$acctpass = the new password of the account in cpanel
$acctuser = the username of the account you want to change

If it is successful, it prints "Great job! Your password has been changed to $acctpass". If it isn't, it prints "OOps, you broke it. I don't think that the username was correct".

If you have any other questions, post 'em here.
 

andyf

Well-Known Member
Jan 7, 2002
249
0
316
UK
Simply call to the /scripts or /scripts2 links that WHM uses during normal operations then?

Seems simple, I shall give it a go :)

Thanks!
 

ukhost

Well-Known Member
Jan 8, 2002
222
0
316
Hi,

Id like to see the ability to upgrade/downgrade, password modification and the creation/removal of reseller accounts.

Anyone got these functions setup?

Kind Regards,

Neil
 

r3lic

Registered
Apr 5, 2003
3
0
151
I'm useing this exact same script (minus the code and the user), almost the very same example script that cpanel offers, but this thing doesn't work.

<?php
require '/usr/local/cpanel/Cpanel/Accounting.php.inc';
$host2 = "localhost";
$user2 = "<user here>";
$usessl = "0";
$accesshash = '<access here>';

$pkgs = listpkgs($host2,$user2,$accesshash,0);
print_r($pkgs);

?>

Any thought as to why it might not work?
 

laundryp

Member
Apr 21, 2003
13
0
151
yep

Might be same problem I had.

curl was not installed, and there is a bug with using new PHP and the Accounting scripts sockets part. I fixed the bug myself and tkoweb reported it.
 

s3kk3y

Well-Known Member
Oct 12, 2002
93
0
156
I would greatly appreciate it if someone was able to create a script to auto create reseller accounts. The current way of doing it a bit tedious and long.
 

jimcarter

Well-Known Member
Jun 30, 2002
152
0
166
UK
it is not too hard to do something like this depending on how you want the accounts to be automatically created, i.e. maybe you want them created through your billing system or something,
unfortunately I dont feel like giving all my reseller scripts away :D
thanks
 

Steven_K

Member
Jun 14, 2003
23
0
151
UK
I used the code by gic to create accounts and filled in all the variables etc but the error it returned was 'Please use the this syntax wwwacct'.

Anybody know what I should do to fix this?

cPanel.net Support Ticket Number:
 

rvskin

Well-Known Member
PartnerNOC
Feb 19, 2003
399
1
168
<?
require '/usr/local/cpanel/Cpanel/Accounting.php.inc';
$host = "localhost";
$user = "root";
$accesshash = 'ACCESS HASH GOES HERE';
$usessl = "0";

$do = changepass($host,$user,$accesshash,$usessl,$acctpass,$acctuser);
if (eregi("syntax mismatch",$do)){
echo "OOps, you broke it. I don't think that the username was correct.";
}
else {
echo "Great job! Your password has been changed to $acctpass.";
}
?>
One thing I would like to warning you about this code. You are explosing security issue to your server. The essencial part is $accesshash now on php code which world readable. Any clients on your server could easily find them(if they know about how Cpanel works) and workaround to do with all your accounts.

cPanel.net Support Ticket Number:
 

NetPires

Member
Jul 5, 2003
12
0
151
How can I create a domain forwarding (domainfwd) using PHP remote control?

cPanel.net Support Ticket Number:
 

CoolMike

Well-Known Member
Sep 6, 2001
313
0
316
Re: yep

Originally posted by laundryp
curl was not installed, and there is a bug with using new PHP and the Accounting scripts sockets part. I fixed the bug myself and tkoweb reported it.
Hi, is this problem still existing? Because I have exactly the same problem. How can I fix this bug?

Mike

cPanel.net Support Ticket Number:
 

andyf

Well-Known Member
Jan 7, 2002
249
0
316
UK
Re: Re: yep

Originally posted by CoolMike
Hi, is this problem still existing? Because I have exactly the same problem. How can I fix this bug?

Mike

IIRC this is due to the way it processes headers from apache in the sockets part of the script. You need to edit near line 122 and add a third condition something like:
Code:
                  if(preg_match("'\n$'s", $buf)) {
                        $inheader = 0;
                  }
the exact regexp might be a bit off, I'm recalling it from memory as I dont have access to the script right now. But it's happening because the condition which tests for the end of the header isn't being met, seems apache stopped returning all the control characters the script expects and I think it now just returns a single /n newline as the seperator.

Alternatively (and far far more secure) is to compile php with CURL and CURL SSL and make usessl=1.

HTH

cPanel.net Support Ticket Number:
 

CoolMike

Well-Known Member
Sep 6, 2001
313
0
316
Ok, thanks I will try this. Curl is already installed, but if I would like to use this usessl=1, I'm just getting a empty page. Here is the curl information in phpinfo():

CURL support enabled
CURL Information libcurl/7.10.3 OpenSSL/0.9.6b zlib/1.1.4

Would be really great, if we get this to work.
Thanks
Mike

cPanel.net Support Ticket Number: