danielati

Active Member
Nov 7, 2011
31
1
58
cPanel Access Level
Website Owner
Hi dear friends!!!

I'm new in php and cPanel Developers.
I downloaded the file xmlapi.php and I'm having doubts.
What steps I can to implement this script on my system?

I'm doing authentication by hash. The user must be 'root' or it may be other?
I tried with root: hash_auth('root','chave');
but return "0 Access denied".
And I tried with other user and return '0 Sorry, that username is reserved.'

I can see this return because I put "echo" in a line of the xmlapi_query function, like below:

// perform simplexml transformation (array relies on this)
if ( ($this->output == 'simplexml') || $this->output == 'array') {

echo $response;//show access denied;

$response = simplexml_load_string($response, null, LIBXML_NOERROR | LIBXML_NOWARNING);

if (!$response){
error_log("Some error message here");
return;
}
if ( $this->debug ) {
error_log("SimpleXML var_dump:\n" . print_r($response, true));
}
}

I'm grateful and I'm sorry because I don't speak English very well.:)
 

cPanelDavidG

Technical Product Specialist
Nov 29, 2006
11,216
13
313
Houston, TX
cPanel Access Level
Root Administrator
I'm doing authentication by hash. The user must be 'root' or it may be other?
I tried with root: hash_auth('root','chave');
but return "0 Access denied".
First, let me address the most glaring issue here - 'chave' is obviously not a hash, the length along gives that away. A Hash in this context refers to the Remote Access Key that is accessible in WHM. You can find this on the Setup Remote Access Key key screen in the Clustering section of WHM.

As for your question, the username can be anyone that has access to WHM. Just be mindful that any API commands would then be executed as if that user was logged into WHM. They'll have the same limitations and capabilities as if they were in WHM and any accounts they create will be owned by them unless you specify otherwise.
 

danielati

Active Member
Nov 7, 2011
31
1
58
cPanel Access Level
Website Owner
I'm sorry, I wrote wrong .... 'chave' is like 'access key' ;)

I'm passing the values ​​as follows:

Code:
<?
include_once "xmlapi.php" ;

//$ip = getenv('REMOTE_HOST');
$ip = 'domain.com';

$xmlapi = new xmlapi($ip);

$xmlapi->hash_auth('user','access_key');

$xmlapi->set_debug(1);

$acct = array( username => "test", password => "#[email protected]", domain => "test.domain.com");
print $xmlapi->createacct($acct);
Why the variable $response return '0 Sorry, that username is reserved.'?
 

cPanelDavidG

Technical Product Specialist
Nov 29, 2006
11,216
13
313
Houston, TX
cPanel Access Level
Root Administrator
I'm sorry, I wrote wrong .... 'chave' is like 'access key' ;)

I'm passing the values ​​as follows:

Code:
<?
include_once "xmlapi.php" ;

//$ip = getenv('REMOTE_HOST');
$ip = 'domain.com';

$xmlapi = new xmlapi($ip);

$xmlapi->hash_auth('user','access_key');

$xmlapi->set_debug(1);

$acct = array( username => "test", password => "#[email protected]", domain => "test.domain.com");
print $xmlapi->createacct($acct);
Why the variable $response return '0 Sorry, that username is reserved.'?
What username are you attempting to utilize?
 

danielati

Active Member
Nov 7, 2011
31
1
58
cPanel Access Level
Website Owner
Hi David,

I managed to solve.
The problem was the amount of characters I put in password. It seems that it must have at least 6 characters.

I executed the script and the account was created, but without e-mail and package type.

Now I also try to put the e-mail and the package type.
Do you know something about it?

Thanks
 

cPanelDavidG

Technical Product Specialist
Nov 29, 2006
11,216
13
313
Houston, TX
cPanel Access Level
Root Administrator
Hi David,

I managed to solve.
The problem was the amount of characters I put in password. It seems that it must have at least 6 characters.

I executed the script and the account was created, but without e-mail and package type.

Now I also try to put the e-mail and the package type.
Do you know something about it?

Thanks
You can set the contactemail and plan (package) in this function call as well. You can refer to the documentation at: CreateAccount < SoftwareDevelopmentKit < TWiki
 

danielati

Active Member
Nov 7, 2011
31
1
58
cPanel Access Level
Website Owner
I'm sorry come back, but I was trying change the Language to use in the account's cPanel interface.
I put like example but the script didn't performed.....Nothing happen

Example: language=>spanish-utf8
 

MrLeN

Active Member
Dec 12, 2010
38
0
56
If this is what you are referring to:

https://github.com/CpanelInc/xmlapi-php/blob/master/Examples/createacct_example.php

It doesn't work,

Or it's incomplete,

Or I don't understand how to add the extra code it needs to make it create an account.

I added xmlapi.php to my server. Then I added This.

Then I looked to see whare I might add root, root pass, account creation details etc -- which is where I became lost, and thus extremely frustrated; because it's my 8th failure with the 8th script tonight (which is 3:42am).

I've had a gut full of scripts that are either old, incomplete, don't work with cPanel anymore, require the 5th force to understand, or are just plain out not what I am looking for (and I don't work that out until I've tried to make it work for 2 hours).

Now, if you'll excuse me, I am going to smash this monitor into a wall and go to bed.

Good night.

P.S. If anyone can show me a script that will allow me to easily create an account with cPanel 11.30.5 - it will be a refreshing surprise apon my awakening.
 
Last edited:

cPanelDavidG

Technical Product Specialist
Nov 29, 2006
11,216
13
313
Houston, TX
cPanel Access Level
Root Administrator
If this is what you are referring to:

https://github.com/CpanelInc/xmlapi-php/blob/master/Examples/createacct_example.php

It doesn't work,

Or it's incomplete,

Or I don't understand how to add the extra code it needs to m,ake it create an account.

I added xmlapi.php to my server. Then I added This.

Then I looked to see whare I might add root, root pass, account creation details etc -- which is where I becam,e lost, and thus extremely frustrated. because it's my 8th failure with the 8th script tonight (which is 3:42am).

Now, if you'll excuse me, I am going to smash this monitor into a wall and go to bed.

Good night.
I would advise sleep after a long coding session as it helps to refresh the mind and let it focus more easily without becoming frustrated.

This example does work, as long as you have the class one directory level up from the example file (like it is on github), assign variables before they are used and, in general, PHP scripts are running well on your server.

The only modifications that would be needed would be either to replace the variables with strings or to assign values to those variables prior to those variables being used.

Variables in PHP typically begin with $ and are to be set before they are used. For more information on how to set variables in PHP, you can reference: PHP: Basics - Manual

If PHP is not a programming language you are comfortable with, you may consider using examples from other programming languages for which we provide examples. You can visit cPanel & WHM's SDK for a more comprehensive list of documentation and code samples.
 

MrLeN

Active Member
Dec 12, 2010
38
0
56
I know what variables are. Admittedly, I'm no Einstein, but I do know what variables are (and have known for quite some time)

What I don't know is how in earth a script is supposed to work when it has no connection with the server, or anywhere to put usernames and passwords.

Basically, you're telling me that I have to be a good enough programmer to write "the other half" of the "incomplete" script (and I am sure there's some kind of inside joke between people who are "gurus"), that they leave just enough information out so they can get it working, but if anyone else tries, they lose the plot, which allows the gurus much anticipated opening to make condescending remarks about how the idiots should go and learn what variables are. These kind of remarks are usually accompanied by links to tutorials about programming.

I have an idea: It's called "write complete scripts"!

Or don't bother writing them at all.

How would you feel of you went to Ford to get a car and they said: Yeah, you don't get the wheels. If you want wheels, you need a diploma in tire manufacturing - YOU IDIOT! And by the way, here's a book about how rubber is made:

*slams the book into your head*

Ok, so maybe I am exaggerating, but that's how programmers make me feel.

Just sayin'..
 
Last edited:

cPanelDavidG

Technical Product Specialist
Nov 29, 2006
11,216
13
313
Houston, TX
cPanel Access Level
Root Administrator
I know what variables are. Admittedly, I'm no Einstein, but I do know what variables are (and have known for quite some time)

What I don't know is how in earth a script is supposed to work when it has no connection with the server, or anywhere to put usernames and passwords.

Basically, you're telling me that I have to be a good enough programmer to write "the other half" of the "incomplete" script (and I am sure there's some kind of inside joke between people who are "gurus"), that they leave just enough information out so they can get it working, but if anyone else tries, they lose the plot, which allows the gurus much anticipated opening to make condescending remarks about how the idiots should go and learn what variables are. These kind of remarks are usually accompanied by links to tutorials about programming.

I have an idea: It's called "write complete scripts"!

Or don't bother writing them at all.

How would you feel of you went to Ford to get a car and they said: Yeah, you don't get the wheels. If you want wheels, you need a diploma in tire manufacturing - YOU IDIOT! And by the way, here's a book about how rubber is made:

*slams the book into your head*

Ok, so maybe I am exaggerating, but that's how programmers make me feel.

Just sayin'..
This forum is open to the general public to individuals of all skill levels. As a professional courtesy, I was merely attempting to assist you by referring you to resources you may not know existed in the event you were not familiar with the concept of variables in PHP. Keep in mind, such a situation is possible given the public nature of this forum and the contexts of the class and example files adhering to common PHP coding paradigms and your prior post.

You mention that the script is "incomplete" - this is true because we do not know your root password. We also do not know your hostname. We do not know the username of the account you want to create, nor its intended password and so forth. That is why these items are stored in variables for you to set and customize as desired. Everything else is provided there for creating an account, you just need to do the proverbial "fill in the labeled blanks."

To further clarify, you will find most of these variables for the class at the top of that PHP file, whereas the variables in the example files are self-evident as you imply. If you attempt to run the script and an error ensues, be sure to let us know the error message as that assists us with trying to help you with this. We want to help.
 

MrLeN

Active Member
Dec 12, 2010
38
0
56
Code:
include_once "../xmlapi.php" ;

$ip = getenv('REMOTE_HOST');
$root_pass = getenv('REMOTE_PASSWORD');

$xmlapi = new xmlapi($ip);
$xmlapi->password_auth("root",$root_pass);

$xmlapi->set_debug(1);

$acct = array( username => "someuser", password => "pass123", domain => "thisdomain.com");
print $xmlapi->createacct($acct);
Here's all I understand:


I have to replace someuser, pass123 and thisdomain.com with what I want. I get that.

But there is nowhere there to put like:

server: localhost
user: root
root password: fordtires

..and doesn't cPanel 11.30.5 need to use a key? Every script I try wont work because I come to find out I need to set up a key.
 

BlaineM.

cPanel QA Analyst
Apr 4, 2011
31
0
56
Houston, TX
cPanel Access Level
Root Administrator
you can put your information into the example script at:

$ip = getenv('REMOTE_HOST');
$root_pass = getenv('REMOTE_PASSWORD');

"getenv('REMOTE_HOST')" can be changed to a remote location such as server name or IP
"getenv('REMOTE_PASSWORD')" can be changed to your root password, "fordtires", or whatever it really is.