Do I need to turn on API call for DirectAdmin?

thunn

Verified User
Joined
Mar 13, 2012
Messages
166
Dear Supporters,
I'm using this example to check API but it stop (keep loading) when I call:
http://files.directadmin.com/services/all/httpsocket/examples/example.suspend_user.php

It keeps loading at this line:
Code:
$sock->query('/CMD_SELECT_USERS',
	array(
		'location' => 'CMD_SELECT_USERS',
		'suspend' => 'Suspend', // note - this can also be 'Unsuspend'
		'select0' => '{user}'
    ));


So is there a place to turn on the API call or how can I correct and make it works?

Thank you.
 
Yes, I have tried with this:
$sock->query('/CMD_SELECT_USERS',
array(
'location' => 'CMD_SELECT_USERS',
'suspend' => 'Suspend', // note - this can also be 'Unsuspend'
'select0' => 'joomla'
));

Joomla is one of the user in my system. but it keep loading.
Is there a way that I can see error log or something like that? I don't have any info now to move foward with it :(


PS: When I print_r($socket) object before execute $socket->query() then I get this:
Code:
HTTPSocket Object ( [version] => 2.7 [method] => GET [remote_host] => xxx.xxx.xxx.xxx [remote_port] => 2222 [remote_uname] => admin [remote_passwd] => xxxxxxxxx [result] => [result_header] => [result_body] => [result_status_code] => [lastTransferSpeed] => 
[bind_host] => [error] => Array ( ) [warn] => Array ( ) [query_cache] => Array ( ) [doFollowLocationHeader] => 1 [redirectURL] => [extra_headers] => Array ( ) )
 
Last edited:
It still does not work :(

$sock->query('/CMD_API_SELECT_USERS',
array(
'location' => 'CMD_API_SELECT_USERS',
'suspend' => 'Suspend', // note - this can also be 'Unsuspend'
'select0' => 'joomla' //{user}
));

When I check the log file, it only show this:
Code:
2012:08:28-05:02:42: -> A failure in the SSL library occurred, usually a protocol error.
2012:08:28-05:02:42: -> error:00000001:lib(0):func(0):reason(1)
2012:08:28-05:02:42: Can't connect to ssl!
2012:08:28-05:02:42: -> A failure in the SSL library occurred, usually a protocol error.
2012:08:28-05:02:42: -> error:00000001:lib(0):func(0):reason(1)

When I change the URL to have https and print error, not sure this is correct for ssl connection or not:
$sock->connect('https://xxx.xxx.xxx.xxxx',2222);
Can't create socket connection to https://xxx.xxx.xxx.xxxx:2222
 
Ahhhhhhhhhh zEitEr, it worked
Thank you very much :)

The key problem is ssl:// method

This is the full code, hope it help someone when view this thread:

Code:
<?php

include 'httpsocket.php';
echo "START";

$sock = new HTTPSocket();

$sock->connect('ssl://111.111.111.111',2222);
$sock->set_login('admin','admin_password_here');
$sock->set_method('POST');

$sock->query('/CMD_API_SELECT_USERS',
        array(
                'location' => 'CMD_API_SELECT_USERS',
                'suspend' => 'Suspend', // note - this can also be 'Unsuspend'
                'select0' => 'direct_admin_username_being_suspend_here'
    ));

$result = $sock->fetch_body();

echo $result . "<b>{user}</b>";

?>
 
Back
Top