PHP class for communicating with DA

login without password

l0rdphi1 said:
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. :)

|$/usr/local/bin/php
<?
$Socket = new HTTPSocket;
$Socket->connect('127.0.0.1',2222);
$Socket->set_login($_SERVER['USER']);
$Socket->query('/CMD_API_SHOW_USER_CONFIG');
$r_query_result = $Socket->fetch_parsed_body();

echo $r_query_result ["quota"];

$tmp=$r_query_result ["quota"];
if ($tmp=='100')
echo 'SUPER, WORKS!!!';
else
echo 'BAD :(';
?>
DONE|

Result - BAD :(
Nothing works without password!

Works only if:

$Socket->set_login($_SERVER['USER'],user_password_here);

Than script inform: SUPER, WORKS!!!

Is any way to decide my task without using password?
 
Last edited:
i tried to use it but i don`t know how to :(

<?php
include"api_class.php";

$DIRECT_ADMIN=new HTTPSocket;
$DIRECT_ADMIN->connect('http://mydomain.com', '2222');
$DIRECT_ADMIN->set_login('apitest', 'passwd');
echo $DIRECT_ADMIN->query('/CMD_ACCOUNT_USER?username=scripttest&email=mail&passwd=12345&passwd2=12345&domain=scripttest.bluehost.pl&package=test&ip=CORRECT_IP&notify=yes');
?>

And it return 0 :( Account isn`t added ;(
 
Ok, I find how-to do that. Now I haver other problem.
Code:
<?php
include"api_class.php";

$DIRECT_ADMIN=new HTTPSocket;
$DIRECT_ADMIN->connect('XXXXXXXX', 2222);
$DIRECT_ADMIN->set_method('POST');
$DIRECT_ADMIN->set_login('apitest', 'XXXXX');
$DIRECT_ADMIN->query('/CMD_ACCOUNT_USER',array(

                'action' => 'create',

                'username' => 'userloginlol',

                'email' => '[email protected]',

                'passwd' => 'passwrdw',

                'passwd2' => 'passwrdw',

                'domain' => 'testtesttest.XXXXX.com',

                'package' => 'dsagfsdg',

                'ip' => 'xx.xxx.xxx.xx',

                'notify' => 'yes')
);

$result = $DIRECT_ADMIN->fetch_body();

?>
All`s ok, but user have no package (all is 0, only ftp and e-mails is 1). This package is exists (i copy name by ctrl+c).
Where`s the problem?
 
html code from DA with typical message:

Unix User created successfully

User's System Quotas set
User's data directory created successfully
Domains directory created successfully
Domains directory created successfully in user's home



Domain Created Successfuly
 
Since DA is reporting success but the account isn't actually created it could be a bug. Make sure you're running the latest version of DirectAdmin and if that doesn't solve the problem, toss an email to support.
 
Hi Guys... Excellent class file... got it working with the code i will post below. I have a few things I need to ask tho...

Want I want is a user to register on the site, this will then create them a folder on my server, and create an FTP account which sets them as a user - so they can only access the folder they created (using their chosen username)....

THe problem is that I cannot find if its possible to set their permissions etc... I dont want them to create new folders etc or upload more than ONE file. Do you think its possible to do this??

heres what I have working....

PHP:
include "classes/HTTPSocket.php";
$sock = new HTTPSocket;
$sock->connect('domain.com',2222);

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

$sock->set_method('POST');

$sock->query('/CMD_API_SUBDOMAINS',
	array(
		'action' => 'create',
		'domain' => 'domain.com',
		'subdomain' => $_POST['username']
	));

$result = $sock->fetch_parsed_body();


if ($result["error"] == 1) {
	echo "Username already exists, please <a href='../register.php'>try another</a>";
} else {

	#sub domain created, so set the same username up
	$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);
	
	if ($result["error"] == 1) {
		echo "Error, something went wrong when adding your FTP account";
	} else {
		echo "All ok, you are now registered<br/><br/>";
	}
	

}
 
I'm looking for a way of creating a customized subdomain ...

basically, the subdomain should have X MB disk space, XGB transfer - that parts not too hard with the API ...

but...

How can I specifiy features, like # of email addresses, # of databases, etc ?

Is that possible thru the API yet? It's not a feature native to DA that I can see (then again it is nearly midnight)

Any help would be appreciated.

Thanks

Joe
 
Thanks dude

l0rdphi1 said:
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. :)

That nice, I was actually searching how to make that current user could query API without providing a password a second time.

Well just my 2 cent to ty for that socket work :)

Best regard,
Steve
 
hostpc.com said:
I'm looking for a way of creating a customized subdomain ...

basically, the subdomain should have X MB disk space, XGB transfer - that parts not too hard with the API ...

but...

How can I specifiy features, like # of email addresses, # of databases, etc ?

Is that possible thru the API yet? It's not a feature native to DA that I can see (then again it is nearly midnight)

Any help would be appreciated.

Thanks

Joe
To specify those kind of limits on a sub-domain I think you will need to create the sub-domain as a regular domain. That is, add sub1.domain.com as a new domain instead of a sub-domain on domain.com. Then you can just use the regular domain APIs.

Hopefully that helps.

Cheers!
 
Thanks for the confirmation phil.... we'll still need to manually modify DNS for domain.com tho (if the subs are spread over multiple servers) correct?
 
Unless the DNS for the subdomains are on the same server as the main domain, you need to create NS records for both sub.example.com and for www.sub.example.com (unless you don't want it to work) pointing to the two nameservers on your DA server hosting the subdomain.

Jeff
 
API authenticate

Hello, in httpsocket.php, there is a line where we specify the login username and password:

$sock->set_login("admin|{username}","{admin_password}");

What should be the value here if i were to make a plugin that is accessed at user level ? if it should be the client's login id and his password, how do i automatically capture this password ?

Please help, thanks!
 
Creating Aliases

I had originally posted this in support, then realized it needs to go here.

I need something that will create a domain alias on the fly -- using the httpsocket.php class I think would be the way to do it.

Basically, the domain foo.com already exists. When the user signs up, they are inputting their domain name, bar.com, in a form field. I need to know where to look to make the backend magic happen.

Rewt
 
Back
Top