PHP class for communicating with DA

Hello,
anybody could make php that will create domains from a file txt, for example i need to add 50domains, is it possible?
cheers.
 
Error when extract file

Hi everyone,
I have trouble when extract file using CMD_API_FILE_MANAGER. Here is my code:
PHP:
	include('httpsocket.php');
	// init
	$username = 'user';
	$domain = 'domain.com';
	$pass = 'password';
	$path = "/domains/".$domain."/public_html/myfile.tar.gz";
	
	$sock = new HTTPSocket;
	
	$sock->connect($domain, 2222);
	$sock->set_login($username, $pass);
	
	$data = array(
		'path' => $path,
		'action' => 'extract',
		'page' => 2
	);
	
	$sock->query('/CMD_API_FILE_MANAGER', $data);
	$result = $sock->fetch_parsed_body();
	print_r($result);

The error is: You must enter a valid directory.
With the same path, i run code to set file permission, and it run ok.
Please help me, thank so much!
 
I guess documentation here http://www.directadmin.com/features.php?id=652 is missing one detail directory where to extract files, so your request should look like the following:

PHP:
    $data = array( 
        'path' => $path, 
        'directory' => '/',
        'action' => 'extract', 
        'page' => 2 
    );

Note, you might need to change directory to whatever you want, so try different values here.

We should bring this to John's attention.
 
Upload file with method "POST"

Hi,
I try to upload file to my host with method POST. As below:
PHP:
	include('httpsocket.php');
	// init
	$username = 'user';
	$domain = 'domain.com';
	$pass = 'password';
	$path = "/domains/".$domain."/public_html/";
	$file = "myfile.zip";
	
	$sock = new HTTPSocket;
	
	$sock->connect($domain, 2222);
	$sock->set_login($username, $pass);
	$sock->set_method('POST');
	
	$data = array(
		'enctype' => "multipart/form-data",
		'action' => 'upload',
		'path' => $path,
		'file1' => $file
	);
	
	$sock->query('/CMD_API_FILE_MANAGER', $data);
	$result = $sock->fetch_parsed_body();
	print_r($result);

When i run this code, the output is (in 'httpsocket.php'):

+ Undefined offset: 1 in list($this->result_header,$this->result_body) = preg_split("/\r\n\r\n/",$this->result,2);
+ Undefined offset: 1 in list($key,$value) = preg_split("/: /",$pair,2);

In 'httpsocket.php', with POST, value of $this->result is only 'HTTP/1.1 200 OK' so $this->result_body is null and print_r($result); return an empty array.
But with GET, $this->result has full value.

What's wrong in this case? Do i make something wrong? Please help me. Thanks!
 
1. To upload file you should use only POST
2. Make sure, your script finds $file, you might need to put here a full path to the file.
3. I guess you need to send in file1 not a path to the file, but it's content:

Upload a file:
method must be POST
enctype="multipart/form-data" .. must encode it properly.
action=upload
path=/path/you're/uploadingto
file1=filename
... this isn't straight forward, you'll need to lookup up how a browser sends/encodes the files to duplicate this.

so read the content of the file, encode it and only then send it.

See this http://www.php.net/manual/en/function.fsockopen.php#62380 as it might help you to attach a file into your request.
 
I've just uploaded a file and here is the debug output from Directadmin, I've got this result:

Code:
Post string: MAX_FILE_SIZE=10485760&action=upload&file1=/home/tmp/my_file1.tar.gzE0ChMS&file2=/home/tmp/my_file2.tar.gz0qS2n0&path=/private

So, anyway you should use full path to the file and locate it in place accessible by directadmin (here it is /home/tmp/).
 
Check port and using SSL for DirectAdmin

I'm create plugin for Direсtаdmin using httpsосket.php.
Can i know port, and use the Secure Sockets Layer (SSL) in Direсtаdmin using API, that does not define clearly.
And not parce direсtаdmin.conf. In advance thanks for the help

P.S. I'm sorry for my English.
 
Hi all!
Some code here:

public function fetchQuotas($domain = null){
$domain = $this->getDomain($domain);

$this->sock->query('/CMD_API_POP', array(
'action' => 'list',
'type' => 'quota',
'domain' => $domain
));
$row = $this->sock->fetch_parsed_body();
if (is_array($row)){
foreach ($row as &$item) parse_str($item, $item);
if (empty($item) || !is_array($item) || !isset($item['quota'])){
$row = array();
}
} else {
$row = array();
}

return $row;
}

/**
* Get the quota and usage for a user
* @param string $user
* @param string $domain
* @return array for example array(usage=>3412,quota=>123543), both are in bytes
*/
public function fetchUserQuota($user, $domain = null){
$limit = $this->fetchLimit($domain);
return (isset($limit[$user]) ? $limit[$user] : array());
}

That is an example of how to get quota and usage for a user.
But how get the limit for a user? (how many letters sent already and limit)
Thank you!
 
API with PHP script now working | user level

Hello

I hope u can help me

i'v try everything google search, forum search and nothing

i have a shred server with Directadmin control panel user level
i want to delete and add or edit a dns A record
i try this:
http://forum.directadmin.com/showthread.php?t=258
http://www.directadmin.com/features.php?id=504

1. do i need to have any port open from my server end?
2. it's possible to do any API connection with an User Level?
3. when i try to run the script, the page is loading for 1 minuet or so an then error couldn't show page.

please help me.

Thank You.
 
1. do i need to have any port open from my server end?

No, if it's already open. I guess you would not access Directadmin in a browser if it were closed. Anyway it's a good idea to doublecheck.

2. it's possible to do any API connection with an User Level?

Yes.

3. when i try to run the script, the page is loading for 1 minuet or so an then error couldn't show page.

You probably need to enable debugging in your PHP script, and see errors; and check of course logs /var/log/directadmin/ for details.
 
@DiSHi:

Do you have your own server? Or a user account from a hosting provider, on which you have only user level? If you only have user level access on a server managed by your provider it's possible they don't allow DNS control; check with them.

@zEitEr:

I'm getting the impression from DiSHi's post that he only has user level. Which would mean he cannot get to the logs.

Jeff
 
Change user’s password API

I sent a request via API with "Post" method and with query('/CMD_API_USER_PASSWD', array( 'username' => “demo1”, 'passwd' => “123456789”, 'passwd2' => “123456789” )), then I received a response result “error=1&text=Unable to change password&details=&#34&#34 is an invalid username”.
I also have try with “CMD_API_SHOW_ALL_USERS” API and it execute successful with response result “list[]=demo1&list[]=demo2&list[]=demo3&list[]=demo4&list[]=demo5&list[]=demo6&list[]=demo7&list[]=demo8&list[]=demo9&list[]=market2”
Please check out and show me to solve my trouble.
Thanks!
 
So does this class still work with the latest DirectAdmin (despite the latest update being in 2005)?

And can I use this to create a backup using the "Create/Restore Backups" option in DA via a cronjob? I was thinking of doing it with cURL but if this can do it that would be easier I guess.

I must note I host a single website in a shared hosting environment and I'm just a user.
 
Figured it out, thanks for the class :).

PHP:
<?php
$domain = "domain";
$user   = "username";
$pass   = "password";

include 'httpsocket.php';

$sock = new HTTPSocket;
$sock->connect($domain,2223);

$sock->set_login($user,$pass);

$sock->set_method('POST');

$sock->query('/CMD_SITE_BACKUP',
	array(
		'domain'  => $domain,
		'action'  => 'backup',
		'select0' => 'domain',
		'select1' => 'subdomain',
		'select2' => 'email',
		'select3' => 'forwarder',
		'select4' => 'autoresponder',
		'select5' => 'vacation',
		'select6' => 'list',
		'select7' => 'emailsettings',
		'select8' => 'ftp',
		'select9' => 'ftpsettings',
		'select10' => 'database'
    ));
$result = $sock->fetch_body();

if (strpos($result,'Backup creation added to queue') !== false) {
    echo 'success';
} else {
	echo 'fail';
}

?>
 
Back
Top