PHP class for communicating with DA

I found this intermitent problem on version 2.4 and upgraded to 2.6, but it still happens

I couldn't track when it happens, but it's happening pretty often (ie, 20% of times I try to use the API, it happens for around 10~15 minutes and then stops)

I tracked this down to line 174 (v2.6):
$socket = @fsockopen( $this->remote_host, $this->remote_port, $sock_errno, $sock_errstr, 10 );

debugging it I got:
$this->remote_host = "ssl://127.0.0.1"
$this->remote_port = 2222

I just get this error:
Server Error
The following error occurred:

Code:
 The server closed the connection while reading the response. Contact your system administrator.
Please contact the administrator.[/quote]

so this must be crashing very hard for some reason...
I though it may not recognize "ssl://", but it does (otherwise, why would it work many times and just not a few?)

I also tried telnet 127.0.0.1 2222 and got with no problems

NOTHING after this 174 line is executed
this fsockopen function is just crashing everything

any hints?
 
It works fine with localhost: $sock->connect('ssl://localhost', 2222);

If you don't want to use localhost check your firewall settings and make sure it passes port 2222 and 443.
 
Using:

$sock->query('/CMD_API_FTP',

array(

'action' => 'create',

'domain' => 'domain.com',

'user' => $_POST['username'],

'type' => 'user',

'passwd' => $_POST['password'],

'passwd2' => $_POST['password']

));

$result = $sock->fetch_parsed_body();

print_r($result);

I get :

Array ( )

And no account created. Any ideas?
 
Hello.

Could somebody tell me how to delete ns? I used this function to add ns and it works fine:

PHP:
$sock->query("/CMD_DNS_CONTROL?action=add&domain=easy3235.domain.pl&ptr_val=&type=NS&name=".$rzad['dns2'].".&value=".$rzad['domena'].".domain.pl.&add");

I am asking for help;)
 
API class: suggestion

Hello l0rdphi1,

Thanks for writing the API class, I find it very useful.
A suggestion for the next version: when PHP error reporting is set to E_ALL (as on my server) line number 306 throws a warning. I solved this by changing the line
PHP:
// from:
if ($headers['location'])

// to:
if (!empty($headers['location']))
Hope this is helpful.
Thanks again
 
Hi guys,
Can somone please help me?

From my other topic:
"I want to give some people the possibility to create a subdomain and password so they can use my online application. Is there a possibility to create some kind of form which automatically creates a subdomain, password, database and uploads the php-script?"

Iam not realy good at php, so if anyone could tell if this is possibly please let me know, so i can ask somone else to make it.
 
admin password verify

Hi guys,

I am using CMD_API_VERIFY_PASSWORD to check against user password without a problem.

Now I have new clients who have purchased a vps from us, and I want to check against the vps admin password, but I am not getting the desired results.

PHP:
$sock = new HTTPSocket;
$sock->connect($serverip,2222);

$sock->set_login("admin",$dapassword);

$sock->set_method('POST');

$sock->query('/CMD_API_VERIFY_PASSWORD',
    array(
        'user' => $loginname,
        'passwd' => $_SESSION['clave']
    ));
$result = $sock->fetch_body();

The result I get is blank (unset)

I am using his vps ip in serverip, and his admin password in $dapassword.

$loginname = "admin"

and $_SESSION['clave'] = same admin password

My thought process is

1- Login as admin
2- Verify against amin (user) password.

The only reason I can think of for it not working is becuase admin is not owner of admin user (becuase they are at the same level??)

Does this make any sense to anyone ?

Thanks !
 
Last edited:
l0rdphi1 said:
RosT,

You can do the following:
  1. login through the API as test's owner
  2. grab the array returned by CMD_API_SHOW_USERS
  3. use in_array to test if test exists within the above array[/list=1]
    Phi1.


  1. How can I grab the array ?
 
problem spanish server

Hello guys,

I use the API communication class without any problems on a few servers, but now that I have a new server in spain, which is a debian box with DA 1.281 , it is not responding to my API commands.

For example, when I check for password match :

$sock->query('/CMD_API_VERIFY_PASSWORD',
array(
'user' => $_SESSION['usernm'],
'passwd' => $_SESSION['userpw']
));

I always get "valid=0" as a response code, when usually I should be getting "valid=1"

Is there a certain port that needs to be open in order for the commands to work?

Thanks !
 
Last edited:
Sorry,

I am actually getting no response. I wish I was getting valid=0, cuase that would mean I am connecting at least.

But I get nothing, null.


port 2222 is open. I checked with nmap..

Any ideas ?

It works great with my other servers,. and the admin password is that same.
 
Ok,

I've tested other API commands and they are working correctly, so I am connecting. But for some reason CMD_API_VERIFY_PASSWORD does not want to give me a result, nor error nor valid result,... nothing. Just an empty array.

My OS is Debian,. incase that helps.
 
Ok,

I am getting these entries in my directadmin error log:

Code:
2006:12:22-11:25:16: Socket write error: fd is connected to a pipe or socket whose reading end is closed.  When this  happens the writing process will also receive a SIG_PIPE signal.  (Thus, the write return value is seen only if  the program catches, blocks or ignores this signal.)
2006:12:22-11:25:16: Error reading from 83.59.69.134:

83.59.69.134 is my IP at the moment.

Anyone ?
 
Nevermind guys,..

The server from where my script was being launched, was using APF firewall. We added the server's IP to the /etc/apf/allow_hosts.rules file and it works :)

BUT ONLY using GET

Does not work using post,......

Any risk of using GET at this point ?

Thanks
 
kolobok said:
chase try this function:
PHP:
/**
 * Close socket
*/
function close_socket()  {
   return $this->socket_close();
}
(you must add this function in you httpsocket.php)
and use it function on you script:
PHP:
$result = $sock->close_socket();
If you have questions I can help you
write email to me: :D
[email protected]

When I'm doing that, I get:
PHP:
Fatal error: Call to undefined function: socket_close() in /serveradress/httpsocket.php on line 316
 
I have a problem!
I have make one plugins who suspend automatic users after pay time has end!
But i have a problem!

When i run the php appear the theme and i don't want and say this

Code:
Cannot Execute Command

Details

Empty post

But the user are suspended!What cand make to remove the skin and the error?

Sorry for my language,i don't speek very much....

Thank You
 
Hello, just for say, i had modify PHP class because i have this error in apache log:
[Wed Jan 24 02:00:09 2007] [error] [client 127.0.0.1] PHP Notice: Undefined index: location in xxxxxxxxxxxxxxxxxxx\httpsocket.php on line 306

so for resolve this i make this change:
line 306:
if (isset($headers['location']))
{
$this->redirectURL = $headers['location'];
$this->query($headers['location']);
}

modify by:
if (isset($headers['location']))
{
if ($headers['location'])
{
$this->redirectURL = $headers['location'];
$this->query($headers['location']);
}
}

and now, no error logs ;)
good luck and thanks for this class :D
 
I want to create a script that create a pop account.

what's wrong?
Code:
<?php

include 'httpsocket.php';

$sock = new HTTPSocket;
$sock->connect('xxxxxx.org', 2222); 

$sock->set_login("USERNAME","PASSWORD");
$sock->set_method('POST');

$sock->query('CMD_API_POP',
    array(
        'action' => 'create',
        'domain' => 'xxxxxxx.org',
        'user' => 'stermi_prova', 
        'passwd' => 'stermi_prova',
        'quota' => '10'
    ));
$result = $sock->fetch_body();

echo $result;

?>
 
Back
Top