PHP class for communicating with DA

l0rdphi1

Verified User
Joined
Jun 22, 2003
Messages
1,471
I have updated the communication class to version 2.1, which includes support for DA's new skin login key system.

From within a skin, you may now use the following to login as the code-executing (or "current") user:
PHP:
$Socket = new HTTPSocket;
$Socket->connect('127.0.0.1',2222);
$Socket->set_login($_SERVER['USER']);
// $_SERVER['USER'] will always contain the current user's name

$Socket->query('/CMD_API_SHOW_DOMAINS');
$r_ query_result = $Socket->fetch_parsed_body()

print_r($r_query_result);
Remember, this only works within skins.

Enjoy. :)
 

3DPN

New member
Joined
May 11, 2004
Messages
1
Location
Denver, CO
The total example

Hi everybody,

somewhat new to PHP and I am wondering if anybody would be oppossed to showing me a complete example. How this api works with your clients hosting registration form. Or maybe just a clarification of what is really required to make this work.

After reading this thread here is what I think is supposed to be done, someone please let me know if this is correct:


  1. I need to create my form which gathers the user information
    The form action should be add_domain.php or whatever it is I am trying to do
    make sure I include a call to the httpsocket.php from with in the form action script.
    [/list=1]

    Is it that simple?

    I am not sure as I have seen a multitude of different things in the forums. For instance, what about this - (used by some to create new accounts):

    http://www.directadmin.com/forum/showthread.php?s=&threadid=492#post2786 -

    <?php

    $obj->request("/CMD_API_ACCOUNT_USER?username=<username>&email=<email>&passwd=<password>"
    ."&passwd2=<password>&domain=<primary_domain>&bandwidth=<megs_bandwidth>"
    ."&quota=<megs_storage>&uvdomains=ON&unsubdomains=ON&unemails=ON&unemailf=ON"
    ."&unemailml=ON&unemailr=ON&umysql=ON&udomainptr=ON&uftp=ON&aftp=ON&cgi=ON&ssl=ON"
    ."&suspend_at_limit=ON&skin=<skin>&ip=<server_ip>&add=Submit&action=create");

    $result = $obj->array_last_parsed();

    if ($result[error]) {

    echo "Woo. There was an error.<p>$result[details]";

    exit;
    }

    echo $result[text];

    ?>

    How does all this tie together? And what about the wrapper he mentions at the bottom of the post?

    Any help would be appreciated.

    Thanks,
    3DPN
 

ctnchris

Verified User
Joined
Sep 17, 2003
Messages
97
is it possible to log someone in using this by their e-mail name and pass for that? I have a staff only section on my irc net page im working on and it would be easier if they could just have one pass for everything, and that way I wouldnt have to make a whole new system.
 

l0rdphi1

Verified User
Joined
Jun 22, 2003
Messages
1,471
thoroughfare said:
The class doesn't support HTTPS does it?

Matt
Yes, actually it does. PHP's "https" is ssl:// :)
PHP:
$socket = new HTTPSocket;
$socket->connect('ssl://yourserver',2222);

$socket->method('POST'); // this is an optional call; default is GET
$socket->query("/CMD_API_SHOW_USERS",array( 'user'  => 'admin' ));

if ($socket->fetch_parsed_body())
{
     print_r($socket->fetch_parsed_body());
}
 

l0rdphi1

Verified User
Joined
Jun 22, 2003
Messages
1,471
Hello,
ctnchris said:
is it possible to log someone in using this by their e-mail name and pass for that? I have a staff only section on my irc net page im working on and it would be easier if they could just have one pass for everything, and that way I wouldnt have to make a whole new system.
Hmm.. I don't think you can login to DA's API via an email address, but you may be able to at least verify they've got the right email password using PHP's IMAP functions.

http://www.php.net/imap

Phi1.
 

l0rdphi1

Verified User
Joined
Jun 22, 2003
Messages
1,471
Re: The total example

3DPN,
3DPN said:
  1. I need to create my form which gathers the user information
    The form action should be add_domain.php or whatever it is I am trying to do
    make sure I include a call to the httpsocket.php from with in the form action script.
    [/list=1]

    Is it that simple?
  1. I think it is indeed that simple. Here's add_domain.php for you: http://www.l0rdphi1.com/tools/httpsocket/examples/example.add_domain.phps

    3DPN said:
    And what about the wrapper he mentions at the bottom of the post?
    That's useless if you're instancing HTTPSocket (the wrapper only applies to instances of HTTPGetSocket).

    Good luck!

    Phi1.
 

nbhosting

Verified User
Joined
Aug 6, 2004
Messages
25
Why doesn't this work?

Hi i'm trying to get the class running


but i only get empty arrays till now


PHP:
<?php

include "httpsocket.php";

$sock = new HTTPSocket;
$sock->connect('myserverip',2222);

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

$sock->query('/CMD_API_SHOW_USER_USAGE&user=usernameofaccount');
$result = $sock->fetch_body();

print_r(array_values($result));


?>
i also tryed this

PHP:
<?
include 'httpsocket.php';

$sock = new HTTPSocket;

$sock->connect('ssl://myipnumber,'2222');
$sock->set_login('admin','mypasswd');

$sock->query('/CMD_API_SHOW_USER_USAGE?user=ausername');
$result = $sock->fetch_body();


echo $result;

?>
 
Last edited:

l0rdphi1

Verified User
Joined
Jun 22, 2003
Messages
1,471
Hello,

Is your server running over SSL or not? Only use ssl:// when running over SSL.

$sock->query('/CMD_API_SHOW_USER_USAGE&user=usernameofaccount');
That should be:
Code:
$sock->query('/CMD_API_SHOW_USER_USAGE','user=usernameofaccount');
Good luck, Phi1. :)
 

nbhosting

Verified User
Joined
Aug 6, 2004
Messages
25
PHP:
<?

include 'httpsocket.php';

$sock = new HTTPSocket;

$sock->connect('ssl://217.170.21.24',2222);
$sock->set_login('admin','myadminpass');

$sock->query('/CMD_API_SHOW_USER_USAGE','user=project14');
$result = $sock->fetch_result();

echo $result;

?>
still only get blank pages
i got ssl activated on the domain i'm working on
i also tryed to disable ssl and the use only the ipnummer

no succes there also
 
Last edited:

l0rdphi1

Verified User
Joined
Jun 22, 2003
Messages
1,471
The question is: Is DirectAdmin running over SSL?

If it is, use ssl://

If it is not, just put the IP :)

Phi1.
 

nbhosting

Verified User
Joined
Aug 6, 2004
Messages
25
thatway i get promted for login and my ssl warning after that i get the right output
 

l0rdphi1

Verified User
Joined
Jun 22, 2003
Messages
1,471
You do have OpenSSL complied into _PHP_, yes? That's needed to make ssl:// queries.

Phi1.
 
Top