PHP class for communicating with DA

Problem in Extract Files

hi guyz, i'm creating my own custom class for directadmin api using those class helpers to communicate get easily on the api... now i'm trying to create a function where i can extract file via direct admin api but what the problem is i got an error in return....

here is my script
PHP:
$oDa = new HTTPSocket;
		
$oDa->connect( HOST, PORT);
$oDa->set_login( USER,PASS);
$oDa->set_method( 'GET' );
		
$oDa->query('/CMD_API_FILE_MANAGER',array(
'action'=>'extract',
'path'=>'/public_html/wpbackup.tar.gz',
'page'=>'2'));


and the error is here

Array ( [error] => 1 [text] => An error occured during extraction: [details] => You must enter a valid directory. eg: /dir )

of course i'm base the api comman supply from here

http://www.directadmin.com/features.php?id=652


I also try to excute another way just to list for files using this command and it works fine
PHP:
$oDa->query('/CMD_API_FILE_MANAGER',array(
'path'=>'/public_html'));


Is ther anything i missed up? hope you can help thanks a lot....
 
Using api with asp or asp.net

We need to gather bandwidths from DA with or without api.
But we have to use asp.net. So would it be possible?
Is there any example to gather the info with asp.net?

Otherwise I will to gather it directly from show_all_users.cache.

Any advice? Thanks
 
Hello,

I'm trying to get a list of all existing domains at the server. I've tried to use "CMD_API_SHOW_DOMAINS" without any succes.
Does anybody has this working, I need just a list of all existing domains on the server.

Thanks in advanced
 
i need a function that checks if a domain is already registered to a server or not
could you help me ?


thnx
 
I would like to view all users and that no one here is how my code

PHP:
<?php
$sock = new HTTPSocket;
							
$sock->connect(SITE_WEB,PORT);
$sock->set_login(LOGIN,PASSWORD);
$sock->set_method('GET');
		
$usage = "/CMD_API_ALL_USER_USAGE?username=<username>&bandwidth=<bandwidth>&creator=<creator>"; 
					$username = "";
					
					parse_str($usage);
					echo $username;

?>

Thank you
 
Last edited:
Hello,

I'd like to know how to add and delete individual records from a zone (for any domain/user). I'm using the CMD_API_DNS_ADMIN command, but this command with the "delete" value for the "action" argument, deletes the ENTIRE zone, not only the desired record. I don't want to delete the entire zone, only 1 record. The same for adding 1 record.

Is it possible? Thanks in advance.

PS: DirectAdmin control panel version is 1.33.6
 
Yes, I've read that before, and it is impossible to delete just 1 record. You can add individual records, but not delete them, or you can delete the entire zone, and then create it, but the zone is created with default records and I don't want this.
If individual records cannot be deleted, is it possible to create an empty zone with no records (and then I would add my custom records)?

Anyone can help?
 
Has any body the example of API by PERL ?
Thanks
 
Last edited:
is the php class on the 1st post , can be communicated with all version of DirectAdmin ?
 
Cannot get POST to work

I want to add an IP using the API, this only works with POST.

When I use the following commando the debug of DA still states I am using GET instead of POST:

PHP:
$sock = new HTTPSocket;
$sock->connect($daserverip,$daport);
$sock->set_login($dauser,$dapass);
$sock->set_method('POST');
$sock->query("/CMD_API_IP_MANAGER?action=add&add=Submit&ip=1.2.3.4&netmask=255.255.255.0&status=free");
$result = $sock->fetch_parsed_body();

This is the output of DA in debug mode:
Code:
Command::doCommand(/CMD_API_IP_MANAGER) : finished
Command::run: finished /CMD_API_IP_MANAGER

Sockets::handshake - begin
Sockets::handshake - end

Sockets::handshake - begin
Sockets::handshake - end

/CMD_API_IP_MANAGER
GET string: action=add&add=Submit&ip=1.2.3.4&netmask=255.255.255.0&status=free
 0: Accept: */*

I also edited the following lines:
PHP:
function set_method( $method = 'GET' )

and changed it into

PHP:
function set_method( $method = '' )

and even into

PHP:
function set_method( $method = 'POST' )

Al this does not have any effect, DA still keeps register this as a GET string instead of a POST string.

Can please someone explain to me what I do wrong here?
 
Last edited:
delete domain

Hi,

I have the API working to create a domain, but somehow i cant get it done to delete one. And: I cant find anywere how to do that.

I use now:

//Delete domain in DA
include 'httpsocket.php';

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

$sock->set_login("xxx","xxx");

$sock->set_method('POST');

$sock->query('/CMD_DOMAIN',
array(
'action' => 'delete',
'domain' => 'xxx',
'delete' => 'Delete',
'confirmed' => 'Confirm'

));

$result = $sock->fetch_body();
echo $result;
//END DA

Can somebody help me?

Regards

Alex
 
Will this class work with PHP 5.3x? Does anybody use it on PHP 5.3x?
 
Problem with api

When i go to the link
http://www.xxxxxx.be:2222/CMD_API_SHOW_USER_USAGE?domain=xxxxxx.be
i get
bandwidth=%31%34%31%2E%30&db%5Fquota=%39%38%33%30%34&domainptr=%30&email%5Fquota=%31%34%34%30%36%34%35%31%32&ftp=%31&mysql=%31&nemailf=%33&nemailml=%30&nemailr=%30&nemails=%33&nsubdomains=%32&quota=%30%2E%30%39%33%38&vdomains=%31

The values are not good, can sombody help me ?
DirectAdmin 1.36.2
Php 5.2.15
 
In PHP 5.3.6 there's a little problem with the class. I'm not exactly sure what causes it, but as far as I can tell it only happens with deleting users. It works, but the cwd/pwd (getcwd()) is empty after the query() function.

Code:
getcwd();
require_once ( "httpsocket.php" );
$sock = new HTTPSocket;
$sock->connect ( "ssl://".$server_ip, $server_port );
$sock->set_login ( $server_login,$server_pass );
$sock->set_method ( 'POST' );
$sock->query ('/CMD_API_SELECT_USERS',
			array(
  'confirmed' => 'Confirm',
  'delete' => 'yes',
  'select0' => 'testuser'
     ));
getcwd();
The first getcwd() prints the correct path, something like (/home/<user>/domains/<domainname>/public_html), but the second getcwd(); returns an empty result. Somewhere within the class the cwd is reset. I debugged it and found it's in the query() call. It happens somewhere in a while loop within the function:
Code:
while ( !feof($socket) && !$status['timed_out'] )
{
   $chunk = fgets($socket,1024);
   $length += strlen($chunk);
   $this->result .= $chunk;
   ...
 }
I'm not sure why, but in prior versions (PHP 5.2.17) it worked perfectly.

Anyone a clue on this? I think it has something to do with the fgets 1024, but don't know another way of handling an open socket to test it.
 
Back
Top