PHP class for communicating with DA

Daf said:
Yeah I know there shouldnt be a problem but there is, so I looked for a differnet way to do it.

I only asked because I saw you could do it through the DirectAdmin filemanager and hoped the api would be able to do it too.

Anyways, thanks for the help.


Using this HTTP class you can duplicate anything in DA, just figure out the form variables and the command line + userid & password and you'll be able to set it up.

I think you'll find that this would become totally unmanagable when you have a lot of files in the directories.

Regards,
Onno Vrijburg
 
Could you first tell me what you are trying to achieve with this code? Then I'll have a look at it and tell you where I think it might need some work :)

Regards,
Onno Vrijburg
 
Hello,

it seems can't be connect to my server when i enabled SSL option. Any idea to solve that problem? Thanks all. :)
 
You can not use the CMD_SHOW_ALL_USERS command unless you have sufficient permissions to do so, such as an admin account. Make sure that your script is logging in as the admin.
 
It works now..

But i have another problem:(

PHP:
<?php

include 'httpsocket.php';

$sock = new HTTPSocket;

$sock->connect('mydomain.nl',2222);
$sock->set_login('admin','pass');

$sock->query('/CMD_API_SHOW_USER_USAGE?user=tester');
$result = $sock->fetch_parsed_body();

print_r($result);

?>

How get i only the bandwidth in an variable?
$Bandwidth = "the bandwidth that the users use";

Thnx
 
Hi all!
How I can show result (such as
Processor Name
Processor Speed (MHz)
System Uptime and others) CMD_SYSTEM_INFO at my script.
:o
 
Problem adding multiple email users

Hi guys,

Im trying to write something with your httpsocket that makes it possible to add email users to DA from a flat file. Saves me a lot of work and ofcourse the rest of the world.

The problem is that only the last user is added in DA. Possible due to the socket is open. I have tried something but did not manage to get it working.

Here is how it works. A user.txt is used to put all the names in. It reads in the new_users array. A password is generated by an pass generator(password.php).
When the script is executed the names and password are been listed. So far so good. Only the last user is the list will be added to DA. How can I close the stream ? In otherwords how can I close the connection to DA and open again when the next user in the array is loaded. Or you maybe have an other solution for this problem.

I hope you have time to answer this maybe easy question.

Regards,
Chase


PS: here is the code

<?

include 'httpsocket.php';
include 'password.php';


// Enter the domain name
$domain = "mydomain.net";

// Set quota for mailbox for all users. Size is in MB
$quota = "30";

// Enter the length of the password
$passlen = 6;

$new_users = file ("users.txt");
$number_of_users = count($new_users);
if ($number_of_users == 0){
echo "Enter users into the users.txt file";
exit;}

for ($i=0; $i<$number_of_users; $i++){
$user=$new_users[$i];
echo $user." ";
$password = generatePassword($passlen);
echo $password."<BR>";

$sock = new HTTPSocket;
$sock->connect('myIP',2222);
$sock->set_login('me','myselfandI');
$sock->set_method('GET');

$sock->query('/CMD_API_POP',

array(
'action' => 'create',
'domain' => $domain,
'user' => $user,
'passwd' => $password,
'quota' => $quota

));
$result = $sock->fetch_parsed_body();
// Now Close the connection
}


?>
 
chase
try this:
PHP:
[b]
$sock = new HTTPSocket;
$sock->connect('myIP',2222);
$sock->set_login('me','myselfandI');
$sock->set_method('GET');
[/b]


for ($i=0; $i<$number_of_users; $i++){
$user=$new_users[$i];
echo $user." ";
$password = generatePassword($passlen);
echo $password."<BR>";

$sock->query('/CMD_API_POP',

array(
'action' => 'create',
'domain' => $domain,
'user' => $user,
'passwd' => $password,
'quota' => $quota
));
$result = $sock->fetch_parsed_body();
}
it may be work! A don't try this!
 
Sorry Kolobok,

thatz already what I have tried before. Ain't gonna work. Build the stream and then parse.

I need to shutdown the stream and rebuild when it goes through the loop.

socket_close($sock);
or socket_close($socket);

stream_set_blocking() would do the trick if knew the streams name.

Don't know the name of that stream.

Maybe you can help me with that.

First thought was im going to quick for the DA and build in a sleep, but that is not the problem. Parsing a array doesn't like the httpsocket.php either.

I will dig deeper tommorow....would be nice to add 100 users at once,

Greetz,
Chase
 
chase try this function:
PHP:
/**
 * Close socket
*/
function close_socket()  {
   return $this->socket_close();
}
(you must add this function in you httpsocket.php)
and use it function on you script:
PHP:
$result = $sock->close_socket();
If you have questions I can help you
write email to me: :D
[email protected]
 
CMD_API_ADMIN_STATS

When i try CMD_API_ADMIN_STATS command. I recevies this response


bandwidth=%38%30%37%36%30&disk%31=%2Fdev%2Fhda%36%3A%32%30%31%36%30%34%34 etc.


How to use this information. What is this %38%30%37%36%30 etc...
 
Back
Top