PHP class for communicating with DA

CMD_API_FTP modify account without password

Hello,
I want to change FTP account path, but without changeing password. How to do that?
I tried to send passwd and passwd2 blank and I have error "invalid password" when I don't send this params I have the same error.
 
1/ Thanks for that Onno.

Most functions seem to work for me.... except it still refuses to create a database! Your function reports that it worked OK - when it doesn't!

I get the feeling there is a bug in my system somewhere.

----------------------------------------
2/There are a couple of changes I would suggest to improve the output of some of the functions
eg for

da_list_accounts.php

i would replace

echo $result;

with

foreach ($result['list'] as $key => $value) {
echo "$key : $value<br />\n";
}
author: internet việt nam
Have a nice day.
 
Error when create ftp account with API

Hi all!

When I create ftp account with API, I have error. This is my code:

PHP:
$server_ip = "xxx.xxx.xxx.xxx";
$server_user = "sv_user";
$server_pass = "sv_password";

$domain = "domain.com";
$pass = "password";

$sock = new HTTPSocket;
$sock->connect($server_ip, 2222);
$sock->set_login($server_user, $server_pass);

$sock->query('/CMD_API_FTP',
	array(
	'action' => 'create',
	'domain' => $domain,
	'user' => 'testuser',
	'type' => 'domain',
	'passwd' => $pass,
	'passwd2' => $pass 
));	

$result = $sock->fetch_parsed_body();  
if ($result['error'] != "0")
{
	echo "Error Creating ftp on server $server_ip:<br>\n";
	print_r($result);
}
else
{
	echo "Ftp created on server $server_ip<br>\n";
}

Result is "Error Creating ftp on server ...", but $result is empty!

Please help me! Thanks!
 
Try grabbing the raw body output, rather than the parsed value, eg:
Code:
$output = $sock->fetch_body();
echo $output;
John
 
Try grabbing the raw body output, rather than the parsed value, eg:
Code:
$output = $sock->fetch_body();
echo $output;
John

Thanks John!

I've used your code, the value of $output is empty. It doesn't show anything!

I think the problem is here! But I don't know exactly where:

$sock->query('/CMD_API_FTP',
array(
'action' => 'create',
'domain' => $domain,
'user' => 'testuser',
'type' => 'domain',
'passwd' => $pass,
'passwd2' => $pass
));

Because when I replace it by code create user, it's work!

$username = 'abc';
$domain = 'abc.com';
$email = '[email protected]';
$pass = '123456';
$package = 'UL01-Unlimit5GB';

$sock->query('/CMD_API_ACCOUNT_USER',
array(
'action' => 'create',
'add' => 'Submit',
'username' => $username,
'email' => $email,
'passwd' => $pass,
'passwd2' => $pass,
'domain' => $domain,
'package' => $package,
'ip' => $server_ip,
'notify' => 'yes'
));
 
Last edited:
Hi John!

When I replace code create FTP by code create user, like this:

PHP:
$username = 'abc';
	$domain = 'abc.com';
	$email = '[email protected]';
	$pass = '123654';
	$package = 'UL01-Unlimit5GB';
	
	$sock->query('/CMD_API_ACCOUNT_USER',
		array(
		'action' => 'create',
		'add' => 'Submit',
		'username' => $username,
		'email' => $email,
		'passwd' => $pass,
		'passwd2' => $pass,
		'domain' => $domain,
		'package' => $package,
		'ip' => $server_ip,
		'notify' => 'yes'
     ));

It's work! I think the problem is here, but I don't know exactly where:

PHP:
$sock->query('/CMD_API_FTP',
    array(
    'action' => 'create',
    'domain' => $domain,
    'user' => 'testuser',
    'type' => 'domain',
    'passwd' => $pass,
    'passwd2' => $pass 
));

Thanks for help!
 
Hi all,

We've released the first semi-stable release of our new DirectAdmin PHP client library today, see its dedicated topic. We like to think it's much better already than the previous attempts, feedback is very highly appreciated :)
 
lol, as the original contributor to the initial attempt I can quite categorically state that it won't be difficult to improve on what I wrote as I spent all of 2 hours putting it all together and then giving it as a starting point for people so they can see how to implement the basic principles. It was never meant to be a comprehensive solution although other people could have built it out to that in the meantime... good luck with your solution and I hope you do well with it...

regards,
Resolveit
 
The fact that it was 12 years old was one of the main factors in us deciding it was time to start over again ;)
 
Run script DA show subdomain

After I run script php
include 'httpsocket.php';

$sock = new HTTPSocket;

$sock->connect('192.168.1.200',2222);
$sock->set_login('admin','123456');

$sock->query('/CMD_API_SUBDOMAINS');
$result = $sock->fetch_parsed_body();

print_r($result);

----------------------------------
On webrower error :
Array ( [error] => 1 [text] => Unable to show subdomains [details] => You do not own that domain )
I expect to support from forum. thanks
 
You need to provide a domain you want to list the subdomains of. Based on how another post on this page (I don't use this class) I think this should work:

include 'httpsocket.php';

$sock = new HTTPSocket;

$sock->connect('192.168.1.200',2222);
$sock->set_login('admin','123456');

$sock->query('/CMD_API_SUBDOMAINS', array('domain' => 'yourdomainhere.tld'));
$result = $sock->fetch_parsed_body();

print_r($result);
 
Resolve

Thank for your support Arieh
But I run script of you, It's still error on webrower error :
Array ( [error] => 1 [text] => Unable to show subdomains [details] => You do not own that domain )
 
Create user DA

I have a script to create user in DA:
<?php

include 'httpsocket.php';

$sock = new HTTPSocket;

$sock->connect("192.168.1.200", 2222);
$sock->set_login("admin", "123456");

$sock->query('/CMD_API_ACCOUNT_USER', array(
'action' => "create",
'add' => "Submit",
'username' => 'hau',
'email' => "hau@gmail",
'passwd' => '123456',
'passwd2' => '123456',
'package' => 'hau',
'ip' => "192.168.1.200",
'notify' => "yes"
));

$result = $sock->fetch_parsed_body();

?>

When I run with php, It don't insert user in DA, I hope the help from everyone! thanks many
 
Hi,
I have script:
include_once('libs/DA_api/da.php');

$da = new HTTPSocket;
$da->connect('ssl://ip', 2222);
$da->set_login('admin', '***');

$da->set_method('get');
$da->query('/CMD_API_ALL_USER_SHOW');
$result = $da->fetch_body();
var_dump($result);

And it doesn't work... I don't know why? For any API commands... everytime shows
string(0) ""

So it looks like empty response....when try to go manually in url bar (via user : pass@url) it redirects to login page...

I have CentOS 7, DA 1.5 and PHP 7.0.7, HTTPSOCKET.php 2.7.2


EDIT ---- SOLUTION
Ok i've got solution - in directadmin.conf I had to turn off SSL redirecting...and then it works... why? Why it doesn't work with SSL? ;/
 
Last edited:
Hello ShinJii,

I have similar problem. Response is EMPTY, no errors.
Did you found a better sollution?

I have 2 version of php55 and 56 on my local pc.
With php 55 it WORKS. I have this output:
php -i | grep SSL
SSL => Yes
SSL Version => SecureTransport
core SSL => supported
extended SSL => supported
OpenSSL support => enabled
OpenSSL Library Version => LibreSSL 2.2.6
OpenSSL Header Version => LibreSSL 2.2.6
OpenSSL support => enabled


php5.6 (NOT WORK) shows:
php -i | grep SSL
SSL => Yes
SSL Version => OpenSSL/1.0.2h
core SSL => supported
extended SSL => supported
OpenSSL support => enabled
OpenSSL Library Version => OpenSSL 1.0.2h 3 May 2016
OpenSSL Header Version => OpenSSL 1.0.2h 3 May 2016
OpenSSL support => enabled

I have similar problems with Ubuntu 16.04 (php 7.0.) - it does not work too.

But with PHP 5.5. (where SSL VERSION is: SecureTransport) it does work.
I am not sure if it is connected, but any help is appreaciated. thank you!

Jaroslav
 
Last edited:
I had found one solution to make it work without SSL verification.

Can anyone explain on how to make it work with verify_peer = true?

What I have done, in HTTPSocket.php
changed this:
$socket = @fsockopen( $this->remote_host, $this->remote_port, $sock_errno, $sock_errstr, 10 );

to tthis:
$context = stream_context_create([
'ssl' => [
'verify_peer' => false,
],
]);
$socket = stream_socket_client($this->remote_host.':'.$this->remote_port, $sock_errno, $sock_errstr, 10, STREAM_CLIENT_CONNECT, $context);

But I don't like disabling SSL verification?

Thank you!
 
Back
Top