PHP class for communicating with DA

Now, I have this script:

PHP:
function DACreatePackage($da_packagename,$da_bandwith,$da_quota,$da_vdomains,$da_nemails) {
$socket = new HTTPSocket; 

$socket->connect($c_da_ip,2222); 
$socket->set_login($c_da_username,$c_da_password); 

$socket->set_method('POST');
if($da_nemails == "0") {
$socket->query('/CMD_API_MANAGE_USER_PACKAGES',
    array(
		'packagename' => $da_packagename, 
		'bandwith' => $da_bandwith,
		'quota' => $da_quota,
		'vdomains' => $da_vdomains, 
		'nsubdomainschecked' => 'checked', 
		'nemailschecked' => 'checked', 	
		'nemailfchecked' => 'checked',
		'nemailmlchecked' => 'checked',
		'nemailrchecked' => 'checked',
		'mysqlchecked' => 'checked',
		'domainptr' => '5',
		'ftpchecked' => 'checked',
		'aftpchecked' => '',
		'cgichecked' => 'checked',
		'sslchecked' => 'checked',
		'sshchecked' => '',
		'dnscontrolchecked' => 'checked',
		'suspendatlimitchecked' => 'checked',
		'add' => 'Save'
    ));} 
	$result = $socket->fetch_body();
	return $result;
	}

If I run this script the error result is 0, but there's no package created in DA.
What's wrong with this script?
 
Don't you need to have something like
global $c_da_ip, $c_da_username, $c_da_password;
in there somewhere?
 
They were already load from the database like this:

PHP:
$settings = mysql_query("SELECT * FROM settings");
$s = mysql_fetch_assoc($settings);

$c_da_username = $s["c_da_username"];
$c_da_password = $s["c_da_password"];
$c_da_ip = $s["c_da_ip"];

So that's not the problem.
 
That's not what I mean. It's not a matter of whether or not these variables have valid values or not. What I'm referring to is the 'scope' of these three variables. You have to declare them 'global' inside 'DACreatePackage', otherwise they won't be 'known' inside that function.

PHP Variable scope: http://us2.php.net/variables.scope
 
Last edited:
I believe you can for FTP



My question is : Using the "Create User" script given to us by the good guys of DA, how can i get the output info returned to me to print, instead of the whole web page. I need to know this as im including pages, and this messes things up

Cheers people ;)
 
You can use the $result

sample:
PHP:
echo $result['error'];

I've got also a problem. I cant create resellers (the resellers will not be created in DA) with the following script:

PHP:
//DirectAdmin create reseller
function DACreateReseller($da_user,$da_email,$da_password,$da_domein,$da_package,$da_ipadres,$da_ip,$da_username,$da_password) {
//Connectie opzetten
$socket = new HTTPSocket; 

//Inloggen 
$socket->connect($da_ip,2222); 
$socket->set_login($da_username,$da_password); 

$socket->set_method('POST');

$socket->query('/CMD_API_ACCOUNT_RESELLER',
    array(
	    'action' => 'create',
        'username' => $da_user, // The User's username. 4-8 characters, alphanumeric
        'email' => $da_email, // A valid email address
        'passwd' => $da_password, // The User's password. 5+ characters, ascii
        'passwd2' => $da_password, // Password double check. 5+ characters, ascii
        'domain' => $da_domein, // A valid domain name in the form: domain.com
        'package' => $da_package, // One of the User packages created by the Reseller
        'ip' => $da_ipadres, // One of the ips which is available for user creation. Only free or shared ips are allowed.
        'notify' => 'no', // yes or no. If yes, an email will be sent to email
        'add' => 'Submit' //Submit
    ));
	$result = $socket->fetch_body();
	return $result;
	}

What's wrong in this script?
 
If i create an user with the api, i can't choose if spamassasin is enabled? Also suspend at limit, cron jobs and system info are off..
I want to choose if they are on?

How to fix that?
 
Hey, im new here :)

I'm not using your class, its just to much overkill for me and i rather write my own functions. However I do got some API questions.

Customers can order more than one domain with a package, so I need to create a domainpointer by api after i add the package.

The package with the standard domain is no problem, however, when I'm trying to add the domainpointer it says:

Code:
error=1&text=Could not excute your request&details=You do not own that domain

The url/api im using:

"CMD_API_DOMAIN_POINTER?domain=".$huidige."&action=add&from=".$nieuwe."alias=yes";

Where $huidige is the domain that comes with tha package and the $nieuwe is the domain that should be add as a domainpointer.

So is this possible to do with admin login or should i use user login?
 
add user and reseller

Would you happen to have a post script written to add
Resellers?
An then another for resellers to add users?
 
resolveit said:
Here is what I have so far. I am making this available as open source and would appreciate it if other people woud contribute by building some of the classes or by fixing bugs in the code.

I am fully aware that the code is not 100% and some results are not shown (could use help on this) but at least most of the completed classes work well.


Content of the ZIP file
/code - classes for the API
/config - Configuration file (admin userID, password ...)
/forms - Forms for entering data (links 1-1 to API classes)
/protocol - httpsocket Class


Kind Regards,
Onno Vrijburg

When I'm trying to use this code, for examples those files:
da_reseller_ipinfo.php
da_list_resellers.php
da_list_admins.php

I'm gettin' a blank page.
And yes, I changed the config file.
How can I fix it ?
 
I am trying to obtain a listing of the directory of the present user of skin with the following php code (without success):
PHP:
|$/usr/local/bin/php
<?php
include 'httpsocket.inc';
$Socket = new HTTPSocket;
$Socket->connect('127.0.0.1',2222);
$Socket->set_login($_SERVER['USER']);
$Socket->query('/CMD_API_FILE_MANAGER', array('path' => '/'));
$result = $Socket->fetch_parsed_body();
if($result) {
    parse_str($result, $x);
    print_r($x);
} else { echo "result = false"; }
echo "<br />Done...";
?>
DONE|
I only obtain the following result:

Array ( [Array] => )
Done...

But when I execute the command 'http://example.com:2222/CMD_API_FILE_MANAGER?path=/' directly on the browser I obtain the correct string:

%2F%2Ebash%5Flogout=date%3D%31%31%35%34%38%33%31....

Somebody can say to me that I am making bad?

Any help will be welcome, I am becoming crazy !

Ramon
 
change:
PHP:
$Socket->set_login($_SERVER['USER']);
to:
PHP:
$Socket->set_login("|USERNAME|");
As this is DA, not apache, so the $_SERVER array isn't filled (I don't think)

John
 
Thanks for the reply John,

Same wrong result, I have proven with "|USERNAME|", "$_SERVER['REMOTE_USER']", "$_SERVER['USER']", without 'set_login', changing the API call, with GET, with POST,... I don't know that to prove more.

All the times the same result:

Array ( [Array] => )

One array with 4 void elements and 401 http code, I am beginning to suspect that the class 'HTTPSocket' don't work from within of skin or that 'DA' prevents that it works.

The only way to get the result is including the 'password' field in 'set_login', but this is not a solution when you wish to add some new feature to the skin.

Somebody has been able to extract some result from within of any skin, calling any function of the API without password field in 'set_login'?

Can you post any working example?
 
Last edited:
After some more tests, I found the problem. The script run without password but only in one new folder not in 'filemanager' folder.

John, is there any restriction in the 'filemanager' folder that prevent the API call run?
 
Yes, the filemanager is chrooted before the skins are processed. This means that when you access /usr/local/bin/php, the chroot makes it /home/username/usr/local/bin/php.

John
 
Back
Top