Problem with login

deimantas1

New member
Joined
Jun 2, 2013
Messages
4
Hello, I'm get problem with login to Directadmin API.

Error:
Array
(
[error] => 1
[error_msg] => CONNECTION ERROR 35: Unknown SSL protocol error in connection to deimis.zjb.lt:2222
)

Code:
Code:
<?php
include 'httpsocket.php';
$sock = new HTTPSocket;
$sock->connect('deimis.zjb.lt',2222);
 $sock->set_login('login','password');

$request = "/CMD_API_POP";
$method = "POST";
$post_content = "action=create&domain=deimis.zjb.lt&user=deimiss&passwd=dFawIj&quota=500";
$host = 'deimis.zjb.lt';
$port = 2222;

 $retval = DA_SSL_Request("login", "password", $request, $method, $post_content, $host, $port); 

echo "<pre>"; 
print_r($retval); 
echo "</pre>"; 

$sock->query('/CMD_API_POP',
    array(
'action' => 'create',
'add' => 'Submit',
'domain' => 'deimis.zjb.lt',
'user' => 'Testas',
'passwd' => 'testas',
'passwd2' => 'testas',
'quota' => '500'
    ));
$result = $sock->fetch_parsed_body();

echo $result['error'];
echo $result['text'];

function DA_SSL_Request($user, $password, $request, $method='GET', $post_content='', $host='localhost', $port=2222) 
{ 
    $headers = ''; 
    $headers[] = "Content-Type: application/x-www-form-urlencoded"; 
    $headers[] = 'Content-length: '.strlen($post_content); 
    $headers[] = 'Authorization: Basic '.base64_encode("$user:$password"); 
     
    $ch = curl_init(); 
    $complete_url = 'https://'.$host.':'.$port; 
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method.' '.$request.' HTTP/1.1'); 
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 
    curl_setopt($ch, CURLOPT_URL,$complete_url); 
    curl_setopt($ch, CURLOPT_FAILONERROR, 1); 
    curl_setopt($ch, CURLOPT_TIMEOUT, 15); // Time out sec. 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); 
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post_content); 
     
    curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE);  
    curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, FALSE);  
     
    $answer = curl_exec($ch); 
     
    if( !$answer ) 
    { 
        $answer['error'] = 1; 
        $answer['error_msg'] = "CONNECTION ERROR ".curl_errno($ch).": ".curl_error($ch); 
    } 
    else 
    { 
        parse_str($answer,$answer); 
    } 
     
    return $answer; 
}  
?>

I want create email account automatized with Directadmin API.
 
Last edited by a moderator:
And I get this error:
Array ( [0] => Can't create socket connection to https://deimis.zjb.lt:2222. )

With code:
Code:
<?php

include 'httpsocket.php';

$sock = new HTTPSocket;

$sock->connect('https://deimis.zjb.lt',2222);
 $sock->set_login('login','password');

$sock->set_method('POST');

$sock->query('/CMD_API_POP',
    array(
'action' => 'create',
'add' => 'Submit',
'domain' => 'deimis.zjb.lt',
'user' => 'Testas',
'passwd' => 'testas',
'passwd2' => 'testas',
'quota' => '500'
    ));

$result = $sock->fetch_result();
print_r($sock->error);
print_r($sock->result);

?>

Data is good.
 
Last edited by a moderator:
Not working, error:
Code:
Array ( [0] => Can't create socket connection to http://deimis.zjb.lt:2222. )

SSL enabled on directadmin, I can't. I haven't admin. I use hosting, not VPS.
 
Try this then

PHP:
$sock->connect('ssl://deimis.zjb.lt',2222);
 $sock->set_login('login','password');

He did not have ssl enabled. I received a PM from the customer and using tcp:// there was the solution.
 
@deimantas1,

Please, consider to change your password in Directadmin, as the fact you posted it here, is very insecure. The forums can be read by those who might abuse it. I've removed your real login and password from your posts.
 
Back
Top