Page 19 of 19 FirstFirst ... 9171819
Results 361 to 369 of 369

Thread: PHP class for communicating with DA

  1. #361
    Join Date
    Sep 2012
    Location
    Lithuania
    Posts
    22
    Okay, solved this in the 'right' way.
    The class seems to be working without any modifications.

    I had slightly miss-configured the Directadmin.
    SO I restored old line: $socket = @fsockopen( $this->remote_host, $this->remote_port, $sock_errno, $sock_errstr, 10 );


    I copied certificate ROOT BUNDLE (5.58 KB) file from here: https://support.comodo.com/index.php...lidation-sha-2 (since I have comodo certificate).
    to /usr/local/directadmin/conf/carootcert.pem
    and added : carootcert=/usr/local/directadmin/conf/carootcert.pem to directadmin.conf and restart.

  2. #362
    Join Date
    Sep 2016
    Posts
    2

    How to use the API?

    Hi, I am having serious trouble using the API. I am using the same code as used in the examples on https://www.directadmin.com/api.php but all I am getting is the home page of the user I am trying to do something for, instead of a parseable result:
    Code:
    PHP Code:
    require_once('httpsocket.php'); $sock = new HTTPSocket(); $sock->connect("ssl://{$server_name}"$server_port); $sock->set_login("admin|{$user}"$password); $sock->query('CMD_API_DATABASES'); $result $sock->fetch_body(); print $result
    Any help would be appreciated.
    PS: I don't know if this is important, but I am trying to do this locally on the server.

  3. #363
    Join Date
    Nov 2013
    Location
    Belgium
    Posts
    57
    Hi,

    I'm not 100% sure, but shouldn't it be /CMD_API (with the slash)? Besides that you should also get an error value returned that gives you more information.

    Regards, Niels

  4. #364
    Join Date
    May 2013
    Posts
    5

    Question 200 OK, but not OK...

    Hi all,

    First of all: I love how this thread has been going for years and years. It's provided to be a wealth of information!

    I've been working with the DA api class for a while now and managed to get it to work pretty much the way I want to. Until now. Something changed, and I don't have a clue what.

    PHP Code:
    $this->query('/CMD_API_CHANGE_DOMAIN',
                    array(
                        
    'old_domain' => $old_domain,
                        
    'new_domain' => $new_domain
                    
    )
    ); 
    Now, this seems like a good query. Yet, the result of this is this:

    PHP Code:
    //Dumped from Laravel
    "HTTP/1.1 200 OK\r\n" 
    If I remove the set_method('POST') before the query call, this is the result:
    PHP Code:
    """
    HTTP/1.1 200 OK\r\n
    Server: DirectAdmin Daemon v1.50.0 Registered to \r\n
    Set-Cookie: session=; path=/; expires=Fri, 23 Sep 2016 08:43:28 GMT; HttpOnly\r\n
    Connection: close\r\n
    Content-Type: text/plain\r\n
    \r\n
    error=1&text=you forgot to post something&details=
    """ 
    Okay, so it works. Other commands work too and get a proper result. Apart from this one (at the moment, anyway).

    The error Laravel throws at me is

    PHP Code:
    ErrorException in Directadmin.php line 301:
    Undefined offset
    Which is the line where the Query-function parses the result into a header and a body.
    PHP Code:
    list($this->result_header,$this->result_body) = preg_split("/\r\n\r\n/",$this->result,2); 
    And I get why it throws the error, seeing as the result doesn't have a body. But I don't seem to figure out why it only gives me a Status 200 OK in return, while it's most definitely NOT okay.

    Also, as a proof of life from the DA-server itself: I do get the confirmation in the logs that the request has been received and handled:

    PHP Code:
    22/09/2016:10:43:28     ip.add.re.ss GET /CMD_API_CHANGE_DOMAIN HTTP/1.0      admin 
    Anybody have any tips as to how to get DA to return the proper response?

  5. #365
    Join Date
    May 2013
    Posts
    5

    Unhappy Feeling silly...

    Okay, that was stupid. I figured out what I did wrong.

    Instead of sending through the user name and password, I passed through the admin user and password. Which doesn't work for this specific API call. And which explains why other functions did work, just not this one.

    Begs the question: why do I get a HTTP 200 OK response, and not a 'This call does not exist in this userlevel' or something?

  6. #366
    Join Date
    Feb 2013
    Posts
    52
    please add create email example for DA class

  7. #367
    Quote Originally Posted by MaartenS View Post
    Okay, that was stupid. I figured out what I did wrong.

    Instead of sending through the user name and password, I passed through the admin user and password. Which doesn't work for this specific API call. And which explains why other functions did work, just not this one.

    Begs the question: why do I get a HTTP 200 OK response, and not a 'This call does not exist in this userlevel' or something?
    Hi Maaren,
    I've made change for the next release of DA so it generates a 403 insetad of a 200 when invalid CMD_* or CMD_API_* requests are made.
    It will also spit out proper url-encoded API data if CMD_API_ is used:
    https://directadmin.com/features.php?id=1885

    Available in the pre-release binaries in about 20 minutes, if anyone needs them.

    John

  8. #368
    Join Date
    Jun 2018
    Posts
    1

    License

    Hello,
    What are the copyright terms for this class (and the example source code)? Is it licensed under the MIT, BSD or some other license? I have found no such info, and therefore the license seems to default to "forbidden for all uses" (except perhaps some fair use depending on country), which is probably not what the Author(s) intended.
    And who, except from Phi1 Stier, is the Author of this class?

    It would be nice to update the source code with respective copyright information.

    IANAL

    Greetings,
    Mateusz

  9. #369
    Hi Mateusz,

    I cannot speak directly for Phil, but I personally have done the 3.x.x updates to the code, to convert it over to curl for better control of headers, redirect, ssl protocols, etc..
    I can say that the intent of the class is just to fill the gap between your own code and the DirectAdmin API.. and as that's essentially the only use for it, hence there wasn't much need for licensing at that time.
    So if you use it for your DirectAdmin API projects, you won't have issues. If you start to wander copy/pasting the code for non-DA use, I cannot really say, as that wasn't it's intent, but at the end of the day it's Phil's baby

    Regardless, I've just sent him an email to see how he wants to proceed, probably a GNU GPL is sufficient, just to add clarification as to how you can go about using it.
    But as mentioned, for your DirectAdmin API project, yes please use it Beyond that, we'll wait for his reply.

    John

Page 19 of 19 FirstFirst ... 9171819

Similar Threads

  1. DA PHP Class with DA API Functions
    By DJVG in forum Scripting / API
    Replies: 14
    Last Post: 01-17-2012, 03:49 PM
  2. different nameserver for each Class C
    By gtgart in forum DNS
    Replies: 2
    Last Post: 11-20-2008, 04:50 PM
  3. Ruby API Class
    By voxxitdesigns in forum Scripting / API
    Replies: 21
    Last Post: 07-31-2008, 08:52 PM
  4. JAVA class for communicating with DA
    By gpfault in forum Scripting / API
    Replies: 0
    Last Post: 03-31-2005, 07:59 PM
  5. Da+php+da Class
    By fusionictnl in forum General Technical Discussion & Troubleshooting
    Replies: 0
    Last Post: 10-27-2004, 03:23 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •