PDA

View Full Version : PHP class for communicating with DA



Pages : [1] 2

l0rdphi1
07-23-2003, 04:37 AM
Hey.

This is a small PHP class put together to help communicate with DirectAdmin. It is simple enough, and most anyone can make good use of it.

Current Version: v2.6
Last updated 2005-07-29

Download: php-source (http://files.directadmin.com/services/all/httpsocket/httpsocket.php) or tarball (http://files.directadmin.com/services/all/httpsocket/httpsocket.tar.gz)

Numerous implementation examples are located here (http://files.directadmin.com/services/all/httpsocket/examples/).

Pretty nifty, eh?

loopforever
07-23-2003, 06:11 AM
An additional method is to simply use fopen(), file(), or getfilecontents() on the full URL. For example:



$diskUsage = getfilecontents("http://user:pass@your.server.com:2222/CMD_API_SHOW_USER_USAGE?user=$some_user_name")

echo "Disk Usage is: $diskUsage";


Just another way of doing this... :) Thanks for sharing your method, I might put it to good use...

l0rdphi1
07-23-2003, 12:54 PM
Originally posted by loopforever
An additional method is to simply use fopen(), file(), or getfilecontents() on the full URL. For example:



$diskUsage = getfileco [...] s: $diskUsage";


Just another way of doing this... :) Thanks for sharing your method, I might put it to good use...
That doesn't work with the new sessions sytem. And plus you have to parse_strthe results :)

Pilot
08-28-2003, 09:30 AM
How would you send your information to CMD_ACCOUNT_USER to create an account?
I made all the fields and such, but I'm unsure on how to send the info.

l0rdphi1
08-28-2003, 01:35 PM
John said he'd be adding an API_ACCOUNT_USER soon, but right now I use:
$fsock->request("/CMD_ACCOUNT_USER?username=$client_sql[client_uname]&email=".strtolower($client_sql[client_email])
."&passwd=$client_sql[client_pword]&passwd2=$client_sql[client_pword]&domain=$client_sql[client_domain]"
."&bandwidth=".($client_sql[client_bandwidth]*1024)."&quota=$client_sql[client_storage]&uvdomains=ON&unsubdomains=ON"
."&unemails=ON&unemailf=ON&unemailml=ON&unemailr=ON&umysql=ON&udomainptr=ON&uftp=ON&aftp=ON&cgi=ON&ssl=ON"
."&suspend_at_limit=ON&skin=loopXv1&ip=$server_ip&add=Submit&action=create");

$client_sql is an array of the user's data.

$server_ip the server's shared IP.

*Note: This example uses the version 1.xx of this class; you need the wrapper (http://www.l0rdphi1.com/junk/httpsocket/httpgetsocket.phps) to continue in this fashion*

l0rdphi1
09-15-2003, 01:21 AM
I edited my original post to include version 1.1 of the class.

I hadn't realized PHP's parse_str() function breaks when DA uses '&' characters in the returned string, and thus version 1.1 fixes this.

Additionally, I recently replied to this (http://www.directadmin.com/forum/showthread.php?s=&threadid=492#post2786) thread with the code I use to create DA accounts.

Enjoy,

Phi1.

thoroughfare
09-15-2003, 06:59 PM
Hi,

Looks interesting, what can it do exactly? Is it just for the API commands?

Cheers,
Matt :)

l0rdphi1
09-15-2003, 07:13 PM
Yeah, it's a simple tool for using DA's API. You could use it for other socket connections too though.

thoroughfare
09-15-2003, 07:31 PM
Thanks :)

Gadget
10-02-2003, 12:07 PM
I have one question, when this code is in actual working form, cant someone go "view source" and pull out your username and password for DA Login?

l0rdphi1
10-02-2003, 08:44 PM
Not that I'm aware of. Even if view-source worked for me, shouldn't it only display the HTML source, and not any of the PHP?

And incase you fear someone actually getting the PHP source: you could always encrypt the password making it at least a little harder to figure out.

Phi1.

l0rdphi1
10-15-2003, 07:06 PM
I just updated to 1.2 to fix some problems with url encoded arrays.

Enjoy :D

lidios
10-22-2003, 07:07 PM
How about having visitors create mailboxes?

How do you implement this in the class?

<form action=/CMD_EMAIL_POP method=POST>
action=create
domain=domain.com
user=emailname (do not include @domain.com)
passwd=password
passwd2=password
create=Create

???

l0rdphi1
10-23-2003, 09:09 AM
You won't need a class if you're going to send it via a form, but then again, I'm not sure that will even work. Try it, if you please.

I can modify the class to support POST, but I won't get time enough for that until this weekend.

Phi1.

thoroughfare
10-23-2003, 06:07 PM
Just post the form to your own PHP script, which in turn parses the form and uses the DA communicating class to send the info on to DA ;)

Matt

l0rdphi1
10-24-2003, 09:30 AM
The problem as I take it is that DA's CMD_EMAIL_POP API doesn't take GET data. As I said though, I can add support for POST this weekend :)

FarCry
11-22-2003, 01:38 AM
this needs a little *bump* or a little bit of a sticky?

l0rdphi1
11-22-2003, 12:09 PM
I'm currently in the process of rewriting this by the way. Will support both GET and POST, and fix a bug in the array_last_parsed method.

Feel free to sicky, if you like :)

l0rdphi1
11-22-2003, 02:14 PM
Thanks for the sticky :D

We should see v2.0 today. Yay. ;)

l0rdphi1
11-22-2003, 06:18 PM
Okay, 2.0 is up. There have been a lot of changes.

I put together a wrapper for old versions, so you don't have to recode anything. Check that out here (http://www.l0rdphi1.com/tools/httpsocket/httpgetsocket.phps).

Enjoy :)

dryas
12-05-2003, 02:08 PM
Hello,

there is a big problem with the new html safe characters feature in version 1.203.

The "parse_str" PHP Function will not work together with the unicode html characters.... :-(

Benny

---
Linuworx.de

DirectAdmin Support
12-06-2003, 12:52 PM
Ok, I'll have a look and make sure it works for 1.20.4

John

dryas
12-09-2003, 01:34 PM
Hi,

sorry, but this feature is terrible. :( Nothing against html safe characters, but it blocks any php or perl script.

If you use &#[NUMBER], PHP didn't work, because it misinterprets the GET Variables. If you use %[NUMBER] Perl will make problems...

The %[NUMBER] works with PHP, but this is not HTML safe, isn't it? I must search and replace all the characters all the time...

Out of the frying pan into the fire... :(

Benny

l0rdphi1
12-09-2003, 07:48 PM
Just escape = and & somehow, with some character sequence, or something. Nothing else is needed.

= -> |EQL|
& -> |AMP|

or something. :)

With the class I can easily convert these back to = and &.

DirectAdmin Support
12-10-2003, 10:11 AM
Hello,

The proper version was released 4 days ago :) Just upgrade to 1.20.4. It uses the proper %?? instead of &#??.

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

John

l0rdphi1
12-10-2003, 12:00 PM
Ah, yes. For some reason I was under the impression this still wasn't fixed. Sorry :)

lidios
02-27-2004, 10:28 PM
Hi,

Every time I try to use this, it tells me:

Could not excute your request



Details
You do not own that domain

Would anyone know why that is?

l0rdphi1
02-27-2004, 10:29 PM
Check and make sure you're using the admin|{username} // {admin_password} login format

lidios
02-27-2004, 10:37 PM
I found what was wrong!

In the examples, it showed the domain name to be inside {}, apparently, the {} are not needed. After I took those out, it worked fine.

This is what I'm talking about:


<?php

include 'httpsocket.php';

$sock = new HTTPSocket;

$sock->connect('comain.com',2222);
$sock->set_login('username,'************');

$sock->set_method('POST');

$sock->query('/CMD_EMAIL_POP',
array(
'action' => 'create',
'domain' => 'domain.com', //NOT '{domain.com}'
'user' => 'start',
'passwd' => 'pass',
'passwd2' => 'pass',
'create' => 'Create'
));
$result = $sock->fetch_body();

echo $result;

?>

lidios
02-27-2004, 10:42 PM
I have a Question though...

How can you set it so that after, lets say, the POP account has been created, the default header (Log Out, Change Password, Help, buttons, and on the left, the DA Logo, and the tree) don't show up?

The links are broken anyways, which I guess is good cuz noone wants visitors to be able to do anything after creating their Email account...

l0rdphi1
02-28-2004, 09:53 AM
Originally posted by lidios
In the examples, it showed the domain name to be inside {}, apparently, the {} are not needed. After I took those out, it worked fine.Yeah, sorry, I use them to show you need to insert something. Maybe using $whatever inplace of {whatever} would be better.

Originally posted by lidios
How can you set it so that after, lets say, the POP account has been created, the default header (Log Out, Change Password, Help, buttons, and on the left, the DA Logo, and the tree) don't show up?You're going to have to regex the body result and cut out anything you don't want.

Remember, any CMD_API* token will return a pretty result that this php class can parse. It's the other tokens that end up returning their in-DA HTML values.

Marckus_e
03-08-2004, 05:51 AM
I have just tried to use the finished example of the CMD_DOMAIN script from l0rdphi1.

I change the login and password, servername and what the domain it should create.

Run the script and end up on the login page, nothing seems to be runned.

No errors?

Creating a user works fine but i want to be able to create a second domain with CMD_DOMAIN (which isn't in the API list).

/Best Regards
Marcus

l0rdphi1
03-08-2004, 06:19 AM
Can you reply with the code you're using? (minus your password :))

Marckus_e
03-08-2004, 06:21 AM
<?php

include 'httpsocket.php';

$sock = new HTTPSocket;
$sock->connect('ssl://ipadress',2222);

$sock->set_login("admin|web270","notforyou!");

$sock->set_method('POST');

$sock->query('/CMD_DOMAIN',
array(
'action' => 'create',
'domain' => 'kalletestar.se',
'ubandwidth' => 'unlimited',
'uquota' => 'unlimited',
'ssl' => 'OFF',
'cgi' => 'ON',
'php' => 'ON',
'create' => 'Create'
));
$result = $sock->fetch_body();

echo $result;

?>


There it is!

l0rdphi1
03-08-2004, 06:28 AM
Hmmmm. You are using your 'admin' user password, correct? Besides the SSL connection (which people have been having trouble with), that looks like it should work without any problems. Are you sure your PHP configuration is set up to handle ssl:// includes in PHP? (I'd guess it is, though)

Marckus_e
03-08-2004, 06:31 AM
Solved!

Used the wrong password.

One shall not work on mondays!

/Marcus

guido
03-20-2004, 07:18 AM
OKe,

I'm new with this so bare with me :D

Oke I have a reseller account with a certain hostingcompany... Created a new user with a own domain, where I want to automatically, with the help of PHP, create new subdomains and emailaccounts.

for example:

'mydomain.com' is the account, with 'test' as username and 'rain' as password
And I want to create the next examples:

test.mydomain.com

and

test@mydomain.com


Well the email part worked with me, by using the virtual email commands : /CMD_API_POP

The username + password I used for that command were the username and password of the 'mydomain.com' account (created under 'Your Reseller').

But the listing and creation of subdomains, doesn't work with me. I will c&p an example where I was trying to print a list of already existing subdomains:



$sock = new HTTPSocket;
$sock->connect("<my IP>",<my Port>);
$sock->set_login("test","rain");$sock->query('/CMD_API_SUBDOMAINS', array('domain' => 'mydomain.com'));

$result = $sock->fetch_parsed_body();
print_r($result);




What am I doing wrong :D

guido
03-20-2004, 12:29 PM
A little bit of reading explains a LOT :)

oke they are running 1.21.0 and the commands I try to use are implements in 1.21.2 -> figures...

So I'll just bug those guys, if the want to upgrade...

I'll be back :D

guido
03-21-2004, 04:53 AM
Oke next question... I can do almost everything:

create subdomains
create databases
create emailboxes

and get lists of all the options above.

BUT is it also possible to create FTP accounts (under the subdomain)? I can't find anything about it in the API, but I've to admit, I'm a really bad reader as well as a writer :D

So is FTP control something I overlooked or just not present... and where can I request such a API extention ;) Because if I'm getting it right "l0rdphi1" is the PHP code master, but not the DA developer, that's John isn't it?

Greetz

DirectAdmin Support
03-23-2004, 10:15 AM
Hello,

Anything you can do via webbrowser can be done via the API. The only difference is that you might not get a parseable result, but the command will be executed. Just load the desired page in your web browser, go "view source" and retrieve all form values for the command you want and apply them to your script.

John

guido
03-23-2004, 10:19 AM
Cool, thenx you!

I will go and experiment :D

Greetz

l0rdphi1
04-19-2004, 12:34 PM
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:
$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. :)

YouCMe
04-27-2004, 03:11 AM
Can you please fix the download links? :)

Tnxz! :D

l0rdphi1
04-27-2004, 09:05 AM
Working for me. Give it another go.

YouCMe
04-27-2004, 09:50 AM
hmm http://www.l0rdphi1.com/tools/httpsocket/httpsocket.tar.gz that link and the phps link give me a page cannot be displayed message :(
can you please mail me the .tar.gz at my support@youcme.nl email adres?

weird that i can't see the page :)
tnxz in advance ;)

YouCMe

3DPN
05-11-2004, 03:04 PM
Hi everybody,

somewhat new to PHP and I am wondering if anybody would be oppossed to showing me a complete example. How this api works with your clients hosting registration form. Or maybe just a clarification of what is really required to make this work.

After reading this thread here is what I think is supposed to be done, someone please let me know if this is correct:

[list=1]
I need to create my form which gathers the user information
The form action should be add_domain.php or whatever it is I am trying to do
make sure I include a call to the httpsocket.php from with in the form action script.
[/list=1]

Is it that simple?

I am not sure as I have seen a multitude of different things in the forums. For instance, what about this - (used by some to create new accounts):

http://www.directadmin.com/forum/showthread.php?s=&threadid=492#post2786 -

<?php

$obj->request("/CMD_API_ACCOUNT_USER?username=<username>&email=<email>&passwd=<password>"
."&passwd2=<password>&domain=<primary_domain>&bandwidth=<megs_bandwidth>"
."&quota=<megs_storage>&uvdomains=ON&unsubdomains=ON&unemails=ON&unemailf=ON"
."&unemailml=ON&unemailr=ON&umysql=ON&udomainptr=ON&uftp=ON&aftp=ON&cgi=ON&ssl=ON"
."&suspend_at_limit=ON&skin=<skin>&ip=<server_ip>&add=Submit&action=create");

$result = $obj->array_last_parsed();

if ($result[error]) {

echo "Woo. There was an error.<p>$result[details]";

exit;
}

echo $result[text];

?>

How does all this tie together? And what about the wrapper he mentions at the bottom of the post?

Any help would be appreciated.

Thanks,
3DPN

ctnchris
05-19-2004, 09:02 AM
is it possible to log someone in using this by their e-mail name and pass for that? I have a staff only section on my irc net page im working on and it would be easier if they could just have one pass for everything, and that way I wouldnt have to make a whole new system.

thoroughfare
07-22-2004, 08:51 AM
The class doesn't support HTTPS does it?

Matt

l0rdphi1
07-22-2004, 10:34 AM
Originally posted by thoroughfare
The class doesn't support HTTPS does it?

Matt
Yes, actually it does. PHP's "https" is ssl:// :)

$socket = new HTTPSocket;
$socket->connect('ssl://yourserver',2222);

$socket->method('POST'); // this is an optional call; default is GET
$socket->query("/CMD_API_SHOW_USERS",array( 'user' => 'admin' ));

if ($socket->fetch_parsed_body())
{
print_r($socket->fetch_parsed_body());
}

l0rdphi1
07-22-2004, 10:38 AM
Hello,

Originally posted by ctnchris
is it possible to log someone in using this by their e-mail name and pass for that? I have a staff only section on my irc net page im working on and it would be easier if they could just have one pass for everything, and that way I wouldnt have to make a whole new system. Hmm.. I don't think you can login to DA's API via an email address, but you may be able to at least verify they've got the right email password using PHP's IMAP functions.

http://www.php.net/imap

Phi1.

l0rdphi1
07-22-2004, 10:46 AM
3DPN,

Originally posted by 3DPN
[list=1]I need to create my form which gathers the user information
The form action should be add_domain.php or whatever it is I am trying to do
make sure I include a call to the httpsocket.php from with in the form action script.
[/list=1]

Is it that simple? I think it is indeed that simple. Here's add_domain.php for you: http://www.l0rdphi1.com/tools/httpsocket/examples/example.add_domain.phps


Originally posted by 3DPN
And what about the wrapper he mentions at the bottom of the post?That's useless if you're instancing HTTPSocket (the wrapper only applies to instances of HTTPGetSocket).

Good luck!

Phi1.

nbhosting
08-06-2004, 09:40 AM
Hi i'm trying to get the class running


but i only get empty arrays till now



<?php

include "httpsocket.php";

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

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

$sock->query('/CMD_API_SHOW_USER_USAGE&user=usernameofaccount');
$result = $sock->fetch_body();

print_r(array_values($result));


?>

i also tryed this


<?
include 'httpsocket.php';

$sock = new HTTPSocket;

$sock->connect('ssl://myipnumber,'2222');
$sock->set_login('admin','mypasswd');

$sock->query('/CMD_API_SHOW_USER_USAGE?user=ausername');
$result = $sock->fetch_body();


echo $result;

?>

l0rdphi1
08-06-2004, 05:35 PM
Hello,

Is your server running over SSL or not? Only use ssl:// when running over SSL.


$sock->query('/CMD_API_SHOW_USER_USAGE&user=usernameofaccount');That should be:
$sock->query('/CMD_API_SHOW_USER_USAGE','user=usernameofaccount');
Good luck, Phi1. :)

nbhosting
08-06-2004, 07:13 PM
<?

include 'httpsocket.php';

$sock = new HTTPSocket;

$sock->connect('ssl://217.170.21.24',2222);
$sock->set_login('admin','myadminpass');

$sock->query('/CMD_API_SHOW_USER_USAGE','user=project14');
$result = $sock->fetch_result();

echo $result;

?>


still only get blank pages
i got ssl activated on the domain i'm working on
i also tryed to disable ssl and the use only the ipnummer

no succes there also

l0rdphi1
08-06-2004, 07:20 PM
The question is: Is DirectAdmin running over SSL?

If it is, use ssl://

If it is not, just put the IP :)

Phi1.

nbhosting
08-06-2004, 09:24 PM
i tryed both ways

both return me an empty array

l0rdphi1
08-06-2004, 11:51 PM
And the proper value IS returned from:

https://217.170.21.24:2222/CMD_API_SHOW_USER_USAGE?user=project14

?

Phi1.

nbhosting
08-07-2004, 05:00 AM
thatway i get promted for login and my ssl warning after that i get the right output

l0rdphi1
08-07-2004, 05:44 AM
You do have OpenSSL complied into _PHP_, yes? That's needed to make ssl:// queries.

Phi1.

nbhosting
08-07-2004, 09:01 AM
i will check

RosT
09-04-2004, 06:49 AM
How to create user "testuser" via reseller "testreseller" for example?

l0rdphi1
09-05-2004, 02:25 PM
Refrence: http://directadmin.com/api.html#create


<?php

include 'httpsocket.php';
$Socket = new HTTPSocket;

$Socket->connect('yoursite.com',2222);
$Socket->set_login("{admin_username}","{admin_password}");
// {admin_username} and {admin_password} are not specifically your administrative DA user,
// but rather the user that you want to own this new user.

$Socket->query('/CMD_ACCOUNT_USER',
array(
'username' => '', // The User's username. 4-8 characters, alphanumeric
'email' => '', // A valid email address
'passwd' => '', // The User's password. 5+ characters, ascii
'passwd2' => '', // Password double check. 5+ characters, ascii
'domain' => '', // A valid domain name in the form: domain.com
'package' => '', // One of the User packages created by the Reseller
'ip' => '', // One of the ips which is available for user creation. Only free or shared ips are allowed.
'notify' => 'yes', // yes or no. If yes, an email will be sent to email
'action' => 'create',
'add' => 'Submit'
));
$result = $Socket->fetch_parsed_body();

if ( $Socket->get_status_code() != 200 || !empty($result['error']) )
{
// failure.
echo "Failed to add new user: {$result['error']}<br />{$result['text']}";
}

// new user added.
print_r($result);

?>

RosT
09-10-2004, 07:03 AM
How to check exists user "test" or no?

l0rdphi1
09-10-2004, 02:35 PM
RosT,

You can do the following:[list=1] login through the API as test's owner grab the array returned by CMD_API_SHOW_USERS use in_array (http://php.net/in_array) to test if test exists within the above array[/list=1]
Phi1.

RosT
09-10-2004, 10:12 PM
Thanks.
An how to get list of all domains in the directadmin database? Not for one user - for all.

jmstacey
09-11-2004, 12:22 AM
I don't see any specific comand for this in the api manual.

So what you can do is get the list of all users, store it as an array. Then have it collect the domains that each owner has and display them. Probably using foreach (http://us4.php.net/manual/en/control-structures.foreach.php)

rushost
09-14-2004, 01:06 AM
for exp. I have 2 DA servers
and one database of users (logins, domains and so on)

user on 1 server created mydomain.com

Is it possible by using your php-class disallow user on second server create same domain name? ....DA allow because it is not using same DNS :(

l0rdphi1
09-14-2004, 01:17 AM
This PHP class can only communicate with DA's API: www.directadmin.com/api.html

Can't do what's not there :)

jmstacey
09-15-2004, 01:22 PM
If you are adding domains through a custom script that you made and not through Da then it would be possible, just not automatically through the api.

You would have to have your script gather a domain list from both servers and then compare them to the domain trying to be created and if there are any matches fail because of a duplicate.

Avenueduweb
09-29-2004, 03:09 AM
Hello,

It's very good and very easy to install this system. But i've got a little problem, my users register an account, automatically the user is create in directadmin but he is suspended, when the user pay their account with paypal, the account become "unsuspended" automatically, no problem for that. But, i want to send a "welcome message" after unsuspend an account, how I do that ? Thanks. Bye.

mike_p
10-01-2004, 09:00 AM
Hi

I'm struggling to create a database using the API.

I can get a list of existing databases for the user's account, I can create POP mail boxes (this proves my socket and login work correctly) BUT every time I try to create a database i get


Program Error
Details: A segmentation fault has occurred

If I set it up manually with the same name/user/password it works.

If I attempt to create it when one already exists, it tells me it can't because my quota has been reached (i have max 1 db for this account type).

I have tried both /CMD_DB and /CMD_API_DATABASES

Here's the code for my latest attempt:
<?php

include 'httpsocket.php';

$sock = new HTTPSocket;

$sock->connect('account ip address',2222);

$sock->set_login("bloggs","******");

$sock->set_method('POST');

$mydata = array(
'action' => 'create',
'name' => 'db',
'user' => 'usr',
'passwd' => '******');

$sock->query('/CMD_API_DATABASES',$mydata);

$result = $sock->fetch_body();

echo $result;

?>


Whats going wrong?

resolveit
10-01-2004, 09:04 AM
Originally posted by mike_p
Hi

I'm struggling to create a database using the API.

I can get a list of existing databases for the user's account, I can create POP mail boxes (this proves my socket and login work correctly) BUT every time I try to create a database i get



If I set it up manually with the same name/user/password it works.

If I attempt to create it when one already exists, it tells me it can't because my quota has been reached (i have max 1 db for this account type).

I have tried both /CMD_DB and /CMD_API_POP

Here's the code for my latest attempt:
<?php

include 'httpsocket.php';

$sock = new HTTPSocket;

$sock->connect('account ip address',2222);

$sock->set_login("bloggs","******");

$sock->set_method('POST');

$mydata = array(
'action' => 'create',
'name' => 'db',
'user' => 'usr',
'passwd' => '******',
'passwd2'=> '******');

$sock->query('/CMD_API_POP',$mydata);

$result = $sock->fetch_body();

echo $result;

?>


Whats going wrong?

First I am no expert but I believe you need to use /CMD_API_DATABASES to get this done.

Kind Regards,
Onno Vrijburg

mike_p
10-01-2004, 09:12 AM
Ooops - that was just a typo from my test to create POP boxes instead! [ I will now edit my original post ].

But thanks anyway for a quick response.

resolveit
10-01-2004, 09:17 AM
Can you post the code that gives you the segment fault. From your post I read that when you try to create a database you get a segment fault, is this correct? Or do you get the segment fault when you try to create POP accounts?

Kind Regards,
Onno Vrijburg

mike_p
10-01-2004, 09:26 AM
<?php

include 'httpsocket.inc';

$sock = new HTTPSocket;

$sock->connect('ipaddress',2222);

$sock->set_login("bloggs","bl0ggs");

$sock->set_method('POST');

$mydata = array(
'action' => 'create',
'domain' => 'bloggs.com',
'name' => 'db',
'user' => 'usr',
'passwd' => 'bl0ggs',
'passwd2'=> 'bl0ggs',
'create' => 'Create'
);

$sock->query('/CMD_DB',$mydata);

$result = $sock->fetch_body();

echo $result;

?>


The onlything Ive changed here is the ip address.
Bloggs.com is a dummy account ive set up for testing.
(DNS is handled by my local hosts file)

resolveit
10-01-2004, 09:30 AM
Originally posted by mike_p
<?php

include 'httpsocket.inc';

$sock = new HTTPSocket;

$sock->connect('ipaddress',2222);

$sock->set_login("bloggs","bl0ggs");

$sock->set_method('POST');

$mydata = array(
'action' => 'create',
'domain' => 'bloggs.com',
'name' => 'db',
'user' => 'usr',
'passwd' => 'bl0ggs',
'passwd2'=> 'bl0ggs',
'create' => 'Create'
);

$sock->query('/CMD_DB',$mydata);

$result = $sock->fetch_body();

echo $result;

?>


The onlything Ive changed here is the ip address.
Bloggs.com is a dummy account ive set up for testing.
(DNS is handled by my local hosts file)


If you read the API Documentation it says that you should use /CMD_DATABASES or /CMD_API_DATABASES and not /CMD_DB.

Let me know if this works...

mike_p
10-01-2004, 09:39 AM
Thanks but that doesn't seem to give any improvement.

Could someone who has succeeded please post their code?
(Ive ended up trying so many different ways my heads now spinning!)

For the enthusiasts here's my latest attempt using a different account (I don't mind posting account name etc and the DNS is normal)


<?php

include 'httpsocket.inc';

$sock = new HTTPSocket;

$sock->connect('is-demo.co.uk',2222);

$sock->set_login("isdemo","demo99");

$sock->set_method('POST');

$mydata = array(
'action' => 'create',
// 'domain' => 'is-demo.co.uk',
'name' => 'db',
'user' => 'usr',
'passwd' => 'demo99'
//'passwd2'=> 'demo99',
//'create' => 'Create'
);

$sock->query('/CMD_API_DATABASES',$mydata);

$result = $sock->fetch_body();

echo $result;

?>


Even the password is as-is - but will be changed in a few minutes time.

Thanks for any further help.

resolveit
10-01-2004, 09:42 AM
There is also no mention of "domain" or "create" fields in the API Interface for databases.

Regards,
Onno

resolveit
10-01-2004, 09:43 AM
Ill work on it tonight and post some code later tonight.

Regards,
Onno

mike_p
10-01-2004, 09:44 AM
There is also no mention of "domain" or "create" fields in the API Interface for databases.
They're commented out: when uing the /CMD_DB call they are required. By using the CMD_DB I was able to get the list of existing databases.

Thanks for sticking with it!

mike_p
10-01-2004, 09:45 AM
Originally posted by resolveit
Ill work on it tonight and post some code later tonight.

Regards,
Onno

Thanks - thats very kind of you.

resolveit
10-01-2004, 10:50 AM
Well, I can report that I have it working. I want to complete a couple more API commands and will then release the interface, including forms and calls to the API. I will do this tonight so everybody can use it as they see fit.

Kind Regards,
Onno Vrijburg

mike_p
10-01-2004, 11:48 AM
Thanks

resolveit
10-01-2004, 03:07 PM
Here is what I have so far. I am making this available as open source and would appreciate it if other people woud contribute by building some of the classes or by fixing bugs in the code.

I am fully aware that the code is not 100% and some results are not shown (could use help on this) but at least most of the completed classes work well.


Content of the ZIP file
/code - classes for the API
/config - Configuration file (admin userID, password ...)
/forms - Forms for entering data (links 1-1 to API classes)
/protocol - httpsocket Class


Kind Regards,
Onno Vrijburg

l0rdphi1
10-02-2004, 02:41 AM
Excellent package you have there, Onno. Your open-source package will be a HUGE help to those who are just getting started with DA's API.

Cheers! :)

mike_p
10-02-2004, 02:43 AM
1/ Thanks for that Onno.

Most functions seem to work for me.... except it still refuses to create a database! Your function reports that it worked OK - when it doesn't!

I get the feeling there is a bug in my system somewhere.

----------------------------------------
2/There are a couple of changes I would suggest to improve the output of some of the functions
eg for

da_list_accounts.php

i would replace

echo $result;

with

foreach ($result['list'] as $key => $value) {
echo "$key : $value<br />\n";
}

toothbrush
10-21-2004, 07:16 AM
Hi there.

I'm having the same problem as mike_p, and I'm also using the exact same code that's been posted here (which is correct according to the API definitions here on da.com).

If anyone has any more suggestions they'd be very welcome.

edit: I'm also on DA 1.23

Paul van der Walt

resolveit
10-21-2004, 08:34 AM
This seems to be a problem in DA 1.23. I have just tried it on a box running DA 1.22 and it works, on another box running DA 1.23 it does not work.

DASupport can you confirm that this is a problem in DA 1.23? Or help us solve the problem.

Kind Regards,
Onno Vrijburg

mike_p
10-21-2004, 08:48 AM
I had the problem before I upgraded to v1.23 (as well as after!).

Does the API use the same system to connect to the database as the main DirectAdmin app? I'm wondering whether it may be a MySQL client library version issue.

i.e. the mysql_connect function is deprecated in later versions
and mysql_real_connect function takes different parameters depending on the version.

toothbrush
10-21-2004, 09:48 AM
Not sure, could be. Did minimal research on the 'segmentation fault' error, found this bugreport: http://bugs.php.net/bug.php?id=25400, that doesn't seem to be useful except that it's MySQL's fault. The version mentioned there is 4.0.14, I have version 4.0.16.

I find it very strange, I'm still getting that error even though I'm trying to fake a POST command which is essentially identical to the one used in the DA control panel (i.e. not using the API). Unfortunately I don't have any ideas.

mike_p
10-21-2004, 11:49 AM
Onno -

If you have a box on which it works and one where it doesn't, could you please compare the mysql client libraries in use on each?

Perhaps there is a conflict depending on whether you use the
mysql-shared-compat or the mysql-shared libraries.
On my server I've got the shared-compat libraries. (MySQL-shared-compat-4.0.16)

Mike

toothbrush
10-22-2004, 02:56 PM
Hi. I had a slight problem with the CMD_API_SHOW_USER_DOMAINS api. The problem is this: the api definition says that the return will be in the form of Array(domain.com,domain1.com) etc, and this is true when I open http://adminuser:adminpass@mydomain.com:2222/CMD_API_SHOW_USER_DOMAINS?user=myuser. I then get the following:


userdomain.com=14.6848:unlimited:1.86753:4.5522:0:no:unlimited:ON:ON:ON:

The funny thing is that when I use the http socket library to access the api the same is returned, but with the format "userdomain_com" as the variable name in the array. Very strange. So for example this code:


$listSocket = new HTTPSocket;

$listSocket->connect($siteurl,$siteport);
$listSocket->set_login($adminusername,$adminpassword);

$listSocket->query('/CMD_API_SHOW_USER_DOMAINS',array('user'=>'myuser'));

$listresult = $listSocket->fetch_parsed_body();
print_r($listresult);

...I get the following output:


Array
(
[userdomain_com] => 14.3521:unlimited:1.86654:4.48669:0:no:unlimited:ON:ON:ON:
)

Does anyone have any idea why this is? I have implemented a workaround but would still like to know the reason.

Thanks,

l0rdphi1
10-22-2004, 03:13 PM
I believe PHP's parse_str (http://php.net/parse_str) function replaces periods with underscores.

Phi1.

toothbrush
10-23-2004, 12:07 AM
Originally posted by l0rdphi1
I believe PHP's parse_str (http://php.net/parse_str) function replaces periods with underscores.

Phi1.


PHP.net:
Note that variables cannot contain a DOT (.) in PHP. So, DOT will be replaced by underscore. e.g. variables like "variable.something" will be converted into "variable_something".

Great, a logical explanation :)

ctnchris
10-25-2004, 11:47 AM
I have
<?php

include 'httpsocket.php';

$sock = new HTTPSocket;

$sock->connect('p44.org',2222);
$sock->set_login('admin','passs');

$sock->query('/CMD_API_SHOW_ALL_USERS');
$result = $sock->fetch_parsed_body();

foreach ($result as $user) {
echo "$user <br />";
}

?> and I know I screwed up something, anyone with a spare second wanna help? i want to list all users without the array crap showing.

toothbrush
10-25-2004, 12:53 PM
...
foreach ($result as $user) {
echo "$user <br />";
}
...

I have a feeling the foreach needs the following changes:


foreach ($result['list'] as $key => $user) {
echo "$user <br />";
}

Give that a try and tell me what happens :) HTH

fusionictnl
10-27-2004, 03:02 AM
Problem:

Authentication doesn't work when having special characters like:

< or + or / or -

A lot of passwords on my server have those characters and is accepted by DA.

But when using the DA Class it isn't working at all. Somehow DA or the API translates it the wrong way.

Please can someone verify this by just using a password with a < or a + or something or both :P

Thx!

l0rdphi1
10-27-2004, 03:07 AM
Hello,

Looking at my source, passwords as passed to DA like this:
$array_headers['Authorization'] = 'Basic '.base64_encode("$this->remote_uname:$this->remote_passwd");

That's a pretty standard format, so I'm not sure where the problem is. Perhaps this is a problem with DA? Or you're doing something silly?

I'd confirm right now if I wasn't so busy :(

Phi1.

fusionictnl
10-27-2004, 03:13 AM
I have tested it with curl_exec and it goes exactly the same way wrong.

Edit: I have changed the password without those characters and it goes great!

So there's definitly something wrong with the encoding procedure. Or DA's way of translating the passwords out of the headers!

noose
11-04-2004, 08:52 AM
<pre><?
ob_start();
include 'httpsocket.php';

include 'funkcje.php';

polaczenie();

$da = new HTTPSocket;

$da->connect('thc.net.pl','2222');
$da->set_login('admin','***');
$sql = "SELECT login FROM thc_konta WHERE oplacone = '0' AND powiadomiony = '1'";
$r = zapytanie($sql);
while($w = mysql_fetch_assoc($r))

{
$tab = array ('location' => '/CMD_SELECT_USERS',
'suspend' => 'Suspend',
'select' => "$w[login]");
$da->query('/CMD_SELECT_USERS', $tab);
print_r($da);
$rez = $da->fetch_parsed_body();
$r2 = $da -> fetch_body();
echo $r2;
?>
<br><hr><b> <? echo $w[login];?> </b>
<?
print_r($rez);
if( !empty($rez[error]))
{
echo "User ".$w[login]." nadal ma konto<br>";
}
else
{
echo "User ".$w[login]." ma zablokowane konto :-) <br>";
}
}
echo "<br> Lacznie : ".mysql_num_rows($r);

ob_end_flush();
?>
result is:

httpsocket Object
(
[version] => 2.3
[method] => GET
[remote_host] => thc.net.pl
[remote_port] => 2222
[remote_uname] => admin
[remote_passwd] => ***
[result] => HTTP/1.1 404 Not found
Server: DirectAdmin Daemon v1.23.1 Registered to Piotr Kloc
Content-Type: text/html

Error: document not found

[result_header] => HTTP/1.1 404 Not found
Server: DirectAdmin Daemon v1.23.1 Registered to Piotr Kloc
Content-Type: text/html
[result_body] => Error: document not found

[bind_host] =>
[error] => Array
(
)

[query_cache] => Array
(
[0] => GET /CMD_SELECT_USERS?location=%2FCMD_SELECT_USERS&suspend=Suspend&select=gigi1990 HTTP/1.0
User-Agent: HTTPSocket/2.3
Host: thc.net.pl:2222
Accept: */*
Connection: Keep-Alive
Authorization: Basic YWRtaW46dGdpNUFwZUY=


[1] => GET //CMD_SELECT_USERS HTTP/1.0
User-Agent: HTTPSocket/2.3
Host: thc.net.pl:2222
Accept: */*
Connection: Keep-Alive
Authorization: Basic YWRtaW46dGdpNUFwZUY=


)

[doFollowLocationHeader] => 1
)
Error: document not found

wft? :|

l0rdphi1
11-04-2004, 02:23 PM
Hello,

Looking at this (http://www.l0rdphi1.com/tools/httpsocket/examples/example.suspend_user.phps), the location member of your $tab array should be set to CMD_SELECT_USERS:
'location' => 'CMD_SELECT_USERS',
Good luck.

Phi1.

noose
11-04-2004, 03:27 PM
With your fix output is ( location => 'CMD_SELECT_USERS' ):

Cannot Execute Command



Details

Empty post



with location => '/CMD_SELECT_USERS' output is:

Error: document not found

l0rdphi1
11-04-2004, 03:29 PM
Also, the select key should be select0 in $tab.

Phi1.

noose
11-04-2004, 03:39 PM
i try select and select0.... nothing :(

l0rdphi1
11-04-2004, 03:41 PM
Oh, here we go; CMD_SELECT_USERS is a POST-only form.

You need a
$da->set_method('POST'); somewhere before the query. :)

noose
11-04-2004, 03:45 PM
still nothing :(


Cannot Execute Command



Details

Empty post

l0rdphi1
11-04-2004, 03:52 PM
Post everything you got now. :)

Phi1.

noose
11-04-2004, 03:54 PM
http://thc.net.pl/suspend.phps <- script
http://thc.net.pl/error.txt <- output

l0rdphi1
11-04-2004, 04:07 PM
That looks like it should work now.

One last posibility: Try adding this somewhere before the query:
$da->doFollowLocationHeader = FALSE;
Phi1.

noose
11-04-2004, 11:11 PM
still nothing :( :( :( How to do this ?? :(

fusionictnl
11-05-2004, 10:44 AM
Since update of latest DA 1.23.1 it isn't working anymore :s None of the plugins :s

Getting a bit tired about Da's way of updating things!

noose
11-05-2004, 10:48 AM
So what shoud I do ? I have the newst version of DA....

fusionictnl
11-05-2004, 11:04 AM
Warning: fsockopen(): no SSL support in this build in /usr/local/directadmin/plugins/billing/admin/include/da.api on line 161

It is compiled with php (configure_ap2_php)

Recompiled it Again and it worked. Maybe this should be standard, with-openssl option. (don't know why it didn't take it the first time when upgrading to apache 2)

noose
11-05-2004, 11:09 AM
I don't understand :( could U write it in a simpler way ? Plz.... :P

fusionictnl
11-05-2004, 11:18 AM
Add:

--with-openssl \

to the /usr/local/directadmin/customapache/configure.php_ap2

configuration file --> WITH leading "\"

and do a build ./build php_ap2

l0rdphi1
11-05-2004, 01:54 PM
--with-openssl IS supposed to be standard. Not sure what happened with this release. :(

Phi1.

noose
11-05-2004, 11:14 PM
it isn't this :(

fusionictnl
11-06-2004, 04:21 AM
It never was, the same for IMAP. Once you compiled php again after first install you don't have these functions anymore!

l0rdphi1
11-12-2004, 01:22 PM
Hello,

I assume you mean change file permissions of a file on a remote server? If so, then no; this class can't do that.

Phi1.

jmstacey
11-12-2004, 11:47 PM
You can chmod files through the DirectAdmin filemanager, but you can not do it through the DA api. There is no point to. It should work within your php scripts as long as its configured correctly and you have safemode off.

resolveit
11-13-2004, 02:17 PM
Originally posted by Daf
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

resolveit
11-14-2004, 10:58 AM
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

Curtis
11-15-2004, 02:19 AM
Hello,

it seems can't be connect to my server when i enabled SSL option. Any idea to solve that problem? Thanks all. :)

fusionictnl
11-15-2004, 04:02 AM
Replace the serverip with ssl://serverip

and make sure to have SSL support compiled into PHP

louis
12-04-2004, 01:43 PM
Hi,

i have this as result:

http://www.mywebspace.nl/index.php

i use this: http://www.l0rdphi1.com/tools/httpsocket/httpsocket.phps
as httpsocket.php

and this:
http://www.l0rdphi1.com/tools/httpsocket/examples/example.show_all_users.phps
as index.php

What is here wrong?

Thnx

jmstacey
12-04-2004, 01:47 PM
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.

louis
12-04-2004, 01:58 PM
But i am the admin

jmstacey
12-04-2004, 02:18 PM
What happens if you attempt to run that command in DA but not through your script
i.e. http://yourdomain.com:2222/CMD_SHOW......

louis
12-05-2004, 07:29 AM
It works now..

But i have another problem:(



<?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

FarCry
12-05-2004, 08:05 AM
Try

$result['bandwidth']

louis
12-05-2004, 08:12 AM
Yeah it works :D Thnx guys

FarCry
12-05-2004, 08:17 AM
no problems

kolobok
12-26-2004, 09:32 AM
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

chase
01-04-2005, 04:03 PM
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
}


?>

kolobok
01-05-2005, 02:01 PM
chase
try this:



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



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!

chase
01-06-2005, 11:38 AM
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

kolobok
01-06-2005, 07:37 PM
chase try this function:


/**
* 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:


$result = $sock->close_socket();

If you have questions I can help you
write email to me: :D
support@problem-net.com

cashmere
05-06-2005, 11:03 AM
Great api and script, but how can i list all databases for a user?

jmstacey
05-07-2005, 01:24 AM
CMD_API_DATABASES should do it I think
http://www.directadmin.com/api.html

cizgihost
06-24-2005, 09:29 AM
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...

PeterB
06-24-2005, 11:53 AM
Originally posted by cizgihost
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...

use urldecode :) '%2' is a slash, if you'd put it in the URL, apache might think that you are requesting a file in another map, so the query string (everything behind ?, exactly the response from the class you are getting) is encoded.

Titam
06-29-2005, 09:46 PM
why that doesn't work : http://www.hollinae.com/test1.php

I have just this test


<?php

include 'httpsocket.php';

$sock = new HTTPSocket;

$sock->connect('MY IP',2222);
$sock->set_login('adminlogin','adminpassword');

$sock->query('/CMD_API_SHOW_ALL_USERS');
$result = $sock->fetch_parsed_body();

print_r($result);

?>

Have i missed something ? :^

Titam
07-02-2005, 03:44 AM
if someone can help me, thanks ... :)

PeterB
07-02-2005, 03:47 AM
You should try to replace


$result = $sock->fetch_parsed_body();

print_r($result);

with


$result = $sock->fetch_body();

echo $result;

, that might work.

Titam
07-02-2005, 03:57 AM
Thanks for your reply. I tested and ... white page :\

grr

PeterB
07-02-2005, 04:22 AM
Originally posted by Titam
Thanks for your reply. I tested and ... white page :\

grr

hmm, strange, I will test it on my own server in a few hours, got some work to finish up first :)

Titam
07-02-2005, 06:39 AM
Originally posted by PeterB
hmm, strange, I will test it on my own server in a few hours, got some work to finish up first :)

Ok :) let me know if it's working on your server :)

Titam
07-02-2005, 07:13 AM
Ok, I found why that did'nt work, it was because of my password, containing a а and ... it doesn't like my а :'( now it's working ... I changed my password ...

ryant
07-28-2005, 07:53 AM
Can someone email or PM me with information on how they have implemeneted the suspend/unsuspend commands?

Thanks!

l0rdphi1
07-29-2005, 08:17 PM
I just updated the main post with the latest version of this class.

ryant: There's an example here (http://l0rdphi1.com/tools/httpsocket/examples/example.suspend_user.phps) of how to suspend or unsuspend a user.

Cheers!

kolobok
09-09-2005, 12:22 AM
Originally posted by l0rdphi1
I just updated the main post with the latest version of this class.

ryant: There's an example here (http://l0rdphi1.com/tools/httpsocket/examples/example.suspend_user.phps) of how to suspend or unsuspend a user.

Cheers!

Addon for ssl query


/**
* Query ssl
*
*/
function query_ssl( $request, $content = '', $usessl = 1)
{
if (function_exists("curl_init")) {
$authstr = base64_encode("$this->remote_uname:$this->remote_passwd");
$ch = curl_init();
if ($usessl) {
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,0);
curl_setopt($ch, CURLOPT_URL, "https://$this->remote_host:$this->remote_port" . $request);
} else {
curl_setopt($ch, CURLOPT_URL, "http://$this->remote_host:$this->remote_port" . $request);
}
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
$curlheaders[0] = "Authorization: Basic $authstr";
curl_setopt($ch,CURLOPT_HTTPHEADER,$curlheaders);
$data=curl_exec ($ch);
curl_close ($ch);
$this->result_body = $data;
}
} //ent ssl query


used with httpsocket.php @version 2.0

WildFyre
09-16-2005, 11:21 AM
Is it possible to create/remove user and reseller packages using the DA API??

-Thanks in advance!

l0rdphi1
09-17-2005, 02:01 PM
@kolobok: if PHP is compliled with openssl you could also do this:

$sock = new httpsocket();
$sock->connect("ssl://IP",2222);
$sock->query("/PAGE");

@WildFyre: Yes, that is possible. However, I'm not sure if there are CMD_API functions to do that. You may need to fake POST data to DA's GUI.

Good luck.

kolobok
09-17-2005, 10:56 PM
Originally posted by l0rdphi1
@kolobok: if PHP is compliled with openssl you could also do this:

$sock = new httpsocket();
$sock->connect("ssl://IP",2222);
$sock->query("/PAGE");


Thanks ;)

pettsson
09-20-2005, 01:21 PM
-Edit-
Suddenly it worked, dunno why.

zumo
10-01-2005, 09:47 AM
<?
class DirectAdmin
{
var $s;

function DirectAdmin($host,$auser,$apass)
{
$this->s = new HTTPSocket;

$this->s->connect($host,2222);
$this->s->set_login($auser,$apass);
return $this->check_auth($auser,$apass);

}

function check_auth($user,$pass)
{
$this->s->query('/CMD_API_VERIFY_PASSWORD',
array(
'user' => $user,
'pass' => $pass,

));

$ret=$this->s->fetch_parsed_body();

if(! isset($ret['error']))
return 0;
else
return $ret['details'];

}


function add_user($name,$email,$passwd,$domain,$package,$ip)
{

$this->s->query('/CMD_API_ACCOUNT_USER', array(
'action' => 'create',
'username' => $name,
'email' => $email,
'passwd' => $passwd,
'passwd2' => $passwd,
'domain' => $domain,
'package' => $package,
'ip' => $ip,
'notify' => 'yes'
));


$ret=$this->s->fetch_parsed_body();

if(!isset($ret['error']))
return 0;
else
return $ret['error'].' '.$ret['details'];

}

function get_user_info($name)
{
$this->s->query('/CMD_API_SHOW_USER_CONFIG',
array(
'user' => $name,
));
$ret=$this->s->fetch_parsed_body();
if(!isset($ret['error']))
return $ret;
else
return false;

}

function is_suspended_user($name)
{
$info=$this->get_user_info($name);
return ($info['suspended']=='no')?0:1;
}

function is_active_user($name)
{
return !$this->is_suspended_user($name);
}

function suspend_user($name)
{
if($this->is_suspended_user($name)) return 0;
$this->s->query('/CMD_SELECT_USERS',
array(
'location' => 'CMD_SELECT_USERS',
'suspend' => 'Suspend',
'select0' => $name
));
return $this->s->fetch_body();
}

function activate_user($name)
{
if($this->is_active_user($name)) return 0;
$this->s->query('/CMD_SELECT_USERS',
array(
'location' => 'CMD_SELECT_USERS',
'suspend' => 'Unsuspend',
'select0' => $name
));
return $this->s->fetch_body();
}



function set_package_user($name,$package)
{

$this->s->query('/CMD_API_MODIFY_USER',
array(
'action' => 'package',
'user' => $name,
'package' => $package
));

$ret=$this->s->fetch_parsed_body();


if(!$ret['error'])
return 0;
else
return $ret['error'].' '.$ret['details'];

}

function get_users()
{

$this->s->query('/CMD_API_SHOW_USERS');
$ret=$this->s->fetch_parsed_body();
return $ret['list'];

}

function get_packages()
{

$this->s->query('/CMD_API_PACKAGES_USER');
$r=$this->s->fetch_parsed_body();
return $r['list'];

}

function delete_user($name)
{
$this->s->set_method('post');
$this->s->query('/CMD_SELECT_USERS',
array(
'location' => 'CMD_SELECT_USERS',
'confirmed' => 'Confirm',
'delete' => 'yes',
'select0' => $name
));
return $this->s->fetch_body();


}



}
?>


example using



$DAHOST='81.177.8.125';
$DAADMIN='admin';
$DAPASS='******';
$DAIP='81.177.8.125'; // assign ip for users

include'http.php';
include'daapi.php';
$da=new DirectAdmin($DAHOST,$DAADMIN,$DAPASS);

print_r($da->get_packages()); // get a packeges list




with it class you can simple create own billing for auto accept payments create / delete / suspend users

r3n3gad3
11-04-2005, 07:29 AM
<?

//include the http socket & config file;
include '../httpsocket.php';
include '../config.php';

//end config part, dont touch the stuff below!;

$Socket = new HTTPSocket;
$Socket->connect($site,$port);
$Socket->set_login($user,$password);
$Socket->query('/CMD_API_ADMIN_STATS','');

$result = $Socket->fetch_parsed_body();

if ( $Socket->get_status_code() != 200 || !empty($result['error']) )
{
// failure.
echo "Failed to get serverstats: {$result['text']}<br />{$result['details']}";
}

// results.
echo "{$result['value']}";
?>

Can someone figure out why this doesnt works?

I want to retrieve all the server stats...

Thnx!!!

(using 2.6 by the way.)

r3n3gad3
11-04-2005, 07:33 AM
Also I would like to know if there is an possibility to create a package from a API command....

sspt
11-05-2005, 11:48 AM
Hello,
I'm trying to create a billing system, but i'm having a problem.
When the system try to suspend and already suspended user. DA turns it UNsuspended...

jmstacey
11-05-2005, 03:59 PM
You should get the status of the user first and then suspend or unsuspend if needed.

rocketcity
11-15-2005, 12:52 PM
Hello,

I have never use an API before and know very little about what to do. I have read through this thread but am some what confused on what to do. I have a customer with 750+ email accounts that need to put on the server and have a couple of questions.

I have copied the httpsocket.php file to the server. What I am not sure about is:

1) What is the best way to create a file with this many email addresses? As I do not want to add them 1 by 1.

2) How do I send the cmd_api_pop file to the server. Do I upload the file to the server and then call it from a browser or do I run this from shell or is there some other way of doing it?

Thanks in advance for the help.

rocketcity
11-16-2005, 03:40 PM
Hello, Anybody?

resolveit
11-16-2005, 03:48 PM
The simple answer is you write a program to call the API.

r3n3gad3
11-17-2005, 02:36 AM
anyone has an answer to my question? :confused:

nobaloney
11-17-2005, 02:35 PM
Onno actually did answer you.

If you want to know how to be a PHP programmer, I'm afraid that's well beyond the scope of this forum.

Jeff

suxumi
11-27-2005, 02:14 PM
Hello

I want to get all information about user, that are available,
like mail, ip,.. etc..
that are available like from admin panel..

I cann't fined the api function witch made that..

so plz help...

thanks

Dmitry Zenkov
11-28-2005, 02:14 AM
Hi,

I try to use httpsoket class, but always get meesage
"The request you've made cannot be executed because it does not exist in your authority level" as result

does it mean that I cann`t use DirectAdmin API in my reseller account?

zumo
11-28-2005, 02:41 AM
rus :
да , только для этого юзай соотвественые api команды , тошо я написал - это для админского уровня

Dmitry Zenkov
11-28-2005, 11:04 AM
zumo
Спасибо.


all
How to determine is user authorized or no? i.е. user login into the DirectAdmin and then he follow to my link. That link start my script. How can I determine that user is authorized?

PS: sorry for my english

hehachris
12-03-2005, 12:57 AM
fixed

Barty
12-06-2005, 02:23 PM
When i'm trying to use the API, I always turn up with the DirectAdmin login screen and an empty array on socket error

I would appreciate any suggestions



<?php

include 'httpsocket.php';
$sock = new HTTPSocket;

$sock->connect("myserver", 2222);
$sock->set_login("admin","mypassword");
$sock->set_method('POST');
$sock->query('/CMD_API_VERIFY_PASSWORD',
array(
'user' => 'mytestuser',
'passwd' => 'mytestpassword'
));
$result = $sock->fetch_body();

print_r($result);
print_r($sock->error);

?>

mersco
01-10-2006, 12:48 PM
Hi,

I am trying to get the API to create an FTP account for me but unfortunately it ain't working out the way I want to.
the FTP account does not get created whatever I try.

could you help me out here and point me in the right direction?

version of DA : 1.26.1
version of httpsocket : 2.6

thanks

source code:



<?php
include 'httpsocket.php';

$sock = new HTTPSocket;

$sock->connect('www.domain.com,',2222);
$sock->set_login('user','pass');


$sock->set_method('POST');
$sock->query('/CMD_API_FTP',
array(
'action' => 'create',
'domain' => 'domain.com',
'user' => 'testy',
'type' => 'user',
'passwd' => 'testpas',
'passwd2' => 'testpas',
'create' => 'Create'
));
$result = $sock->fetch_body();

if ( $sock->get_status_code() != 200 || !empty($result['error']) )
{
// failure.
echo "Failed to add new ftp: {$result['error']}<br />{$result['text']}";
}
print_r($result);

mersco
01-10-2006, 12:51 PM
hmm ..

oops ...

found it ... a typo in my connect string

I had 'www.domain.com,' instead of 'www.domain.com'

my apologies for being to hasty ;)

regards

HostPerfect
01-15-2006, 05:33 AM
I want an automatic list of all available domains what are on my servers. Or a list of domains owned by a couple of users.

(want to make an dropdown menu with sites i made automaticly..)

How to do this?

jmstacey
01-15-2006, 12:05 PM
You'll have to collect a list of all users on the server, or just selected users, then foreach user retrieve the domain list and add them to a master array.

resolveit
01-15-2006, 02:14 PM
or you could simply read the /etc/virtual/domains file for a complete list of domain names on the server.

HostPerfect
01-15-2006, 11:22 PM
How can i read that? Can someone give an example?

nobaloney
01-16-2006, 03:30 PM
$ cat /etc/virtual/domains

Jeff

HostPerfect
01-17-2006, 12:55 AM
No, i mean with php :rolleyes:

jmstacey
01-17-2006, 01:49 PM
As in you want code?

Your lucky I'm in a programming mood today ;)

This is the gist of it:


foreach (file('/etc/virtual/domains') as $domain)
{
echo $domain;
}

rushost
02-22-2006, 12:00 AM
Originally posted by l0rdphi1
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:
$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?

xprotect
02-27-2006, 10:58 AM
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 ;(

xprotect
02-27-2006, 11:26 AM
Ok, I find how-to do that. Now I haver other problem.

<?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' => 'my@mail.com',

'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?

jmstacey
02-27-2006, 06:47 PM
What are the results? ($results)

xprotect
02-28-2006, 05:24 AM
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

jmstacey
02-28-2006, 03:03 PM
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.

xprotect
03-03-2006, 01:45 PM
Of course I use newest version.

mfacer
03-17-2006, 08:03 AM
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....



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/>";
}


}

xprotect
03-30-2006, 12:38 PM
My code still doesn`t works :/
DA support wrote me that it isn`t error :[

hostpc.com
04-12-2006, 09:47 PM
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

arbours
04-13-2006, 12:39 AM
Originally posted by l0rdphi1
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:
$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

l0rdphi1
04-14-2006, 06:50 AM
Originally posted by hostpc.com
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!

hostpc.com
04-26-2006, 06:36 AM
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?

nobaloney
04-26-2006, 07:14 PM
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

genexis
05-12-2006, 07:16 AM
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!

Rewt
05-15-2006, 02:10 PM
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

ryant
05-15-2006, 09:39 PM
Are you trying to add a domain pointer?

2-bizzy
05-18-2006, 11:20 AM
Is it possible to create hostingpackages with the API script in reseller level?

Aspegic
05-18-2006, 11:37 AM
Originally posted by 2-bizzy
Is it possible to create hostingpackages with the API script in reseller level?
It seems possible: http://www.directadmin.com/features.php?id=583
(haven't tried it myself though)

2-bizzy
05-18-2006, 11:49 AM
I will try this...
Thnx!

2-bizzy
05-19-2006, 03:16 AM
Now, I have this script:



function DACreatePackage($da_packagename,$da_bandwith,$da_quota,$da_vdomains,$da_nemails) {
$socket = new HTTPSocket;

$socket->connect($c_da_ip,2222);
$socket->set_login($c_da_username,$c_da_password);

$socket->set_method('POST');
if($da_nemails == "0") {
$socket->query('/CMD_API_MANAGE_USER_PACKAGES',
array(
'packagename' => $da_packagename,
'bandwith' => $da_bandwith,
'quota' => $da_quota,
'vdomains' => $da_vdomains,
'nsubdomainschecked' => 'checked',
'nemailschecked' => 'checked',
'nemailfchecked' => 'checked',
'nemailmlchecked' => 'checked',
'nemailrchecked' => 'checked',
'mysqlchecked' => 'checked',
'domainptr' => '5',
'ftpchecked' => 'checked',
'aftpchecked' => '',
'cgichecked' => 'checked',
'sslchecked' => 'checked',
'sshchecked' => '',
'dnscontrolchecked' => 'checked',
'suspendatlimitchecked' => 'checked',
'add' => 'Save'
));}
$result = $socket->fetch_body();
return $result;
}

If I run this script the error result is 0, but there's no package created in DA.
What's wrong with this script?

Aspegic
05-19-2006, 03:40 AM
Don't you need to have something like
global $c_da_ip, $c_da_username, $c_da_password;
in there somewhere?

2-bizzy
05-19-2006, 07:50 AM
They were already load from the database like this:



$settings = mysql_query("SELECT * FROM settings");
$s = mysql_fetch_assoc($settings);

$c_da_username = $s["c_da_username"];
$c_da_password = $s["c_da_password"];
$c_da_ip = $s["c_da_ip"];


So that's not the problem.

Aspegic
05-19-2006, 08:08 AM
That's not what I mean. It's not a matter of whether or not these variables have valid values or not. What I'm referring to is the 'scope' of these three variables. You have to declare them 'global' inside 'DACreatePackage', otherwise they won't be 'known' inside that function.

PHP Variable scope: http://us2.php.net/variables.scope

2-bizzy
05-19-2006, 08:18 AM
Now I have this:


function DACreatePackage($da_packagename,$da_bandwith,$da_quota,$da_vdomains,$da_nemails,$da_ip,$da_username,$da_password)

It's working!
Thnx!

Aspegic
05-19-2006, 08:31 AM
That's another way of getting those variables in there ;)

Rewt
05-30-2006, 07:45 AM
Originally posted by ryant
Are you trying to add a domain pointer?

Yes. That would be correct. Just wanting to add a domain pointer via a form.

Thanks.

kke
05-31-2006, 10:17 PM
Wow, it's Great !

2-bizzy
06-03-2006, 05:47 AM
Is it possible to add a new FTP account with a space and bandwidth limit?

Tom
06-09-2006, 03:05 PM
I believe you can for FTP



My question is : Using the "Create User" script given to us by the good guys of DA, how can i get the output info returned to me to print, instead of the whole web page. I need to know this as im including pages, and this messes things up

Cheers people ;)

2-bizzy
06-15-2006, 11:55 AM
You can use the $result

sample:

echo $result['error'];

I've got also a problem. I cant create resellers (the resellers will not be created in DA) with the following script:



//DirectAdmin create reseller
function DACreateReseller($da_user,$da_email,$da_password,$da_domein,$da_package,$da_ipadres,$da_ip,$da_username,$da_password) {
//Connectie opzetten
$socket = new HTTPSocket;

//Inloggen
$socket->connect($da_ip,2222);
$socket->set_login($da_username,$da_password);

$socket->set_method('POST');

$socket->query('/CMD_API_ACCOUNT_RESELLER',
array(
'action' => 'create',
'username' => $da_user, // The User's username. 4-8 characters, alphanumeric
'email' => $da_email, // A valid email address
'passwd' => $da_password, // The User's password. 5+ characters, ascii
'passwd2' => $da_password, // Password double check. 5+ characters, ascii
'domain' => $da_domein, // A valid domain name in the form: domain.com
'package' => $da_package, // One of the User packages created by the Reseller
'ip' => $da_ipadres, // One of the ips which is available for user creation. Only free or shared ips are allowed.
'notify' => 'no', // yes or no. If yes, an email will be sent to email
'add' => 'Submit' //Submit
));
$result = $socket->fetch_body();
return $result;
}


What's wrong in this script?

HostPerfect
07-05-2006, 12:18 AM
If i create an user with the api, i can't choose if spamassasin is enabled? Also suspend at limit, cron jobs and system info are off..
I want to choose if they are on?

How to fix that?

Scr33x0r
07-24-2006, 08:12 AM
Hey, im new here :)

I'm not using your class, its just to much overkill for me and i rather write my own functions. However I do got some API questions.

Customers can order more than one domain with a package, so I need to create a domainpointer by api after i add the package.

The package with the standard domain is no problem, however, when I'm trying to add the domainpointer it says:


error=1&text=Could not excute your request&details=You do not own that domain

The url/api im using:

"CMD_API_DOMAIN_POINTER?domain=".$huidige."&action=add&from=".$nieuwe."alias=yes";

Where $huidige is the domain that comes with tha package and the $nieuwe is the domain that should be add as a domainpointer.

So is this possible to do with admin login or should i use user login?

kencox
07-25-2006, 04:06 PM
Would you happen to have a post script written to add
Resellers?
An then another for resellers to add users?

Rbv
08-18-2006, 08:29 AM
Originally posted by resolveit
Here is what I have so far. I am making this available as open source and would appreciate it if other people woud contribute by building some of the classes or by fixing bugs in the code.

I am fully aware that the code is not 100% and some results are not shown (could use help on this) but at least most of the completed classes work well.


Content of the ZIP file
/code - classes for the API
/config - Configuration file (admin userID, password ...)
/forms - Forms for entering data (links 1-1 to API classes)
/protocol - httpsocket Class


Kind Regards,
Onno Vrijburg

When I'm trying to use this code, for examples those files:
da_reseller_ipinfo.php
da_list_resellers.php
da_list_admins.php

I'm gettin' a blank page.
And yes, I changed the config file.
How can I fix it ?

redesb
08-29-2006, 01:23 PM
I am trying to obtain a listing of the directory of the present user of skin with the following php code (without success):
|$/usr/local/bin/php
<?php
include 'httpsocket.inc';
$Socket = new HTTPSocket;
$Socket->connect('127.0.0.1',2222);
$Socket->set_login($_SERVER['USER']);
$Socket->query('/CMD_API_FILE_MANAGER', array('path' => '/'));
$result = $Socket->fetch_parsed_body();
if($result) {
parse_str($result, $x);
print_r($x);
} else { echo "result = false"; }
echo "<br />Done...";
?>
DONE|I only obtain the following result:

Array ( [Array] => )
Done...

But when I execute the command 'http://example.com:2222/CMD_API_FILE_MANAGER?path=/' directly on the browser I obtain the correct string:

%2F%2Ebash%5Flogout=date%3D%31%31%35%34%38%33%31....

Somebody can say to me that I am making bad?

Any help will be welcome, I am becoming crazy !

Ramon

DirectAdmin Support
08-30-2006, 01:39 AM
change:
$Socket->set_login($_SERVER['USER']);to:
$Socket->set_login("|USERNAME|");As this is DA, not apache, so the $_SERVER array isn't filled (I don't think)

John

redesb
08-30-2006, 03:50 AM
Thanks for the reply John,

Same wrong result, I have proven with "|USERNAME|", "$_SERVER['REMOTE_USER']", "$_SERVER['USER']", without 'set_login', changing the API call, with GET, with POST,... I don't know that to prove more.

All the times the same result:

Array ( [Array] => )

One array with 4 void elements and 401 http code, I am beginning to suspect that the class 'HTTPSocket' don't work from within of skin or that 'DA' prevents that it works.

The only way to get the result is including the 'password' field in 'set_login', but this is not a solution when you wish to add some new feature to the skin.

Somebody has been able to extract some result from within of any skin, calling any function of the API without password field in 'set_login'?

Can you post any working example?

redesb
08-30-2006, 05:11 AM
After some more tests, I found the problem. The script run without password but only in one new folder not in 'filemanager' folder.

John, is there any restriction in the 'filemanager' folder that prevent the API call run?

DirectAdmin Support
08-30-2006, 10:24 PM
Yes, the filemanager is chrooted before the skins are processed. This means that when you access /usr/local/bin/php, the chroot makes it /home/username/usr/local/bin/php.

John

Lem0nHead
09-21-2006, 10:36 PM
I found this intermitent problem on version 2.4 and upgraded to 2.6, but it still happens

I couldn't track when it happens, but it's happening pretty often (ie, 20% of times I try to use the API, it happens for around 10~15 minutes and then stops)

I tracked this down to line 174 (v2.6):
$socket = @fsockopen( $this->remote_host, $this->remote_port, $sock_errno, $sock_errstr, 10 );

debugging it I got:
$this->remote_host = "ssl://127.0.0.1"
$this->remote_port = 2222

I just get this error:

Server Error
The following error occurred:

[code=SERVER_RESPONSE_CLOSE] The server closed the connection while reading the response. Contact your system administrator.
Please contact the administrator.

so this must be crashing very hard for some reason...
I though it may not recognize "ssl://", but it does (otherwise, why would it work many times and just not a few?)

I also tried telnet 127.0.0.1 2222 and got with no problems

NOTHING after this 174 line is executed
this fsockopen function is just crashing everything

any hints?

fwpeter
09-22-2006, 01:06 AM
It works fine with localhost: $sock->connect('ssl://localhost', 2222);

If you don't want to use localhost check your firewall settings and make sure it passes port 2222 and 443.

ryant
09-27-2006, 11:03 PM
Using:

$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);

I get :

Array ( )

And no account created. Any ideas?

Rebelkk
09-28-2006, 12:19 PM
Hello.

Could somebody tell me how to delete ns? I used this function to add ns and it works fine:



$sock->query("/CMD_DNS_CONTROL?action=add&domain=easy3235.domain.pl&ptr_val=&type=NS&name=".$rzad['dns2'].".&value=".$rzad['domena'].".domain.pl.&add");


I am asking for help;)

mmo
10-22-2006, 08:28 AM
Hello l0rdphi1,

Thanks for writing the API class, I find it very useful.
A suggestion for the next version: when PHP error reporting is set to E_ALL (as on my server) line number 306 throws a warning. I solved this by changing the line
// from:
if ($headers['location'])

// to:
if (!empty($headers['location'])) Hope this is helpful.
Thanks again

Phil123
10-26-2006, 10:22 AM
Hi guys,
Can somone please help me?

From my other topic:
"I want to give some people the possibility to create a subdomain and password so they can use my online application. Is there a possibility to create some kind of form which automatically creates a subdomain, password, database and uploads the php-script?"

Iam not realy good at php, so if anyone could tell if this is possibly please let me know, so i can ask somone else to make it.

cyberneticos
11-26-2006, 06:54 AM
Hi guys,

I am using CMD_API_VERIFY_PASSWORD to check against user password without a problem.

Now I have new clients who have purchased a vps from us, and I want to check against the vps admin password, but I am not getting the desired results.



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

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

$sock->set_method('POST');

$sock->query('/CMD_API_VERIFY_PASSWORD',
array(
'user' => $loginname,
'passwd' => $_SESSION['clave']
));
$result = $sock->fetch_body();


The result I get is blank (unset)

I am using his vps ip in serverip, and his admin password in $dapassword.

$loginname = "admin"

and $_SESSION['clave'] = same admin password

My thought process is

1- Login as admin
2- Verify against amin (user) password.

The only reason I can think of for it not working is becuase admin is not owner of admin user (becuase they are at the same level??)

Does this make any sense to anyone ?

Thanks !

glock44
12-15-2006, 02:05 PM
how can I get DA answer, like that:


Success Returns error=0&text=text&details=details
Failure Returns error=1&text=text&details=details

Rbv
12-16-2006, 05:08 AM
How can I check if the username exist, before opening a new accout ?


Originally posted by glock44
how can I get DA answer, like that:
I need it too.

Rbv
12-18-2006, 02:52 PM
Originally posted by l0rdphi1
RosT,

You can do the following:[list=1] login through the API as test's owner grab the array returned by CMD_API_SHOW_USERS use in_array (http://php.net/in_array) to test if test exists within the above array[/list=1]
Phi1.

How can I grab the array ?

cyberneticos
12-18-2006, 04:37 PM
Hello guys,

I use the API communication class without any problems on a few servers, but now that I have a new server in spain, which is a debian box with DA 1.281 , it is not responding to my API commands.

For example, when I check for password match :

$sock->query('/CMD_API_VERIFY_PASSWORD',
array(
'user' => $_SESSION['usernm'],
'passwd' => $_SESSION['userpw']
));

I always get "valid=0" as a response code, when usually I should be getting "valid=1"

Is there a certain port that needs to be open in order for the commands to work?

Thanks !

cyberneticos
12-21-2006, 02:26 PM
Sorry,

I am actually getting no response. I wish I was getting valid=0, cuase that would mean I am connecting at least.

But I get nothing, null.


port 2222 is open. I checked with nmap..

Any ideas ?

It works great with my other servers,. and the admin password is that same.

cyberneticos
12-21-2006, 05:05 PM
Ok,

I've tested other API commands and they are working correctly, so I am connecting. But for some reason CMD_API_VERIFY_PASSWORD does not want to give me a result, nor error nor valid result,... nothing. Just an empty array.

My OS is Debian,. incase that helps.

cyberneticos
12-22-2006, 02:42 AM
Ok,

I am getting these entries in my directadmin error log:



2006:12:22-11:25:16: Socket write error: fd is connected to a pipe or socket whose reading end is closed. When this happens the writing process will also receive a SIG_PIPE signal. (Thus, the write return value is seen only if the program catches, blocks or ignores this signal.)
2006:12:22-11:25:16: Error reading from 83.59.69.134:


83.59.69.134 is my IP at the moment.

Anyone ?

cyberneticos
12-22-2006, 06:54 AM
Nevermind guys,..

The server from where my script was being launched, was using APF firewall. We added the server's IP to the /etc/apf/allow_hosts.rules file and it works :)

BUT ONLY using GET

Does not work using post,......

Any risk of using GET at this point ?

Thanks

Rbv
12-26-2006, 07:40 AM
Originally posted by kolobok
chase try this function:


/**
* 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:


$result = $sock->close_socket();

If you have questions I can help you
write email to me: :D
support@problem-net.com

When I'm doing that, I get:

Fatal error: Call to undefined function: socket_close() in /serveradress/httpsocket.php on line 316

Tavicu
01-06-2007, 04:53 PM
I have a problem!
I have make one plugins who suspend automatic users after pay time has end!
But i have a problem!

When i run the php appear the theme and i don't want and say this



Cannot Execute Command

Details

Empty post

But the user are suspended!What cand make to remove the skin and the error?

Sorry for my language,i don't speek very much....

Thank You

Mangas23
01-23-2007, 11:15 PM
Hello, just for say, i had modify PHP class because i have this error in apache log:
[Wed Jan 24 02:00:09 2007] [error] [client 127.0.0.1] PHP Notice: Undefined index: location in xxxxxxxxxxxxxxxxxxx\httpsocket.php on line 306

so for resolve this i make this change:
line 306:
if (isset($headers['location']))
{
$this->redirectURL = $headers['location'];
$this->query($headers['location']);
}

modify by:
if (isset($headers['location']))
{
if ($headers['location'])
{
$this->redirectURL = $headers['location'];
$this->query($headers['location']);
}
}

and now, no error logs ;)
good luck and thanks for this class :D

StErMi
01-31-2007, 06:56 PM
What changes between CMD_API_POP and CMD_EMAIL_POP??

thanks

StErMi
02-01-2007, 01:33 PM
I want to create a script that create a pop account.

what's wrong?


<?php

include 'httpsocket.php';

$sock = new HTTPSocket;
$sock->connect('xxxxxx.org', 2222);

$sock->set_login("USERNAME","PASSWORD");
$sock->set_method('POST');

$sock->query('CMD_API_POP',
array(
'action' => 'create',
'domain' => 'xxxxxxx.org',
'user' => 'stermi_prova',
'passwd' => 'stermi_prova',
'quota' => '10'
));
$result = $sock->fetch_body();

echo $result;

?>

Tavicu
02-03-2007, 03:09 PM
Hello


I want to add a new Domain Records type A but the first i want to check if exist!
How can i do this...?


Thank you

cyberneticos
02-12-2007, 05:40 AM
I am trying to change a user's skin using API.

Why is this not possible ? Or what is the correct way of doing it ?


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

$sock->set_login('--user's name----','----password from form ----');

$sock->set_method('POST');

$sock->query('/CMD_API_CHANGE_INFO',
array(
'skin' => 'cambiar',
'skinvalue' => $skintochangeto,
));

$result = $sock->fetch_body();

echo $result;

cizgihost
03-24-2007, 06:32 AM
Hello This is my code


$da_server = server ip
$da_user = da admin username
$da_pass = da admin password
$arr = this is array ...

include ("httpsocket.php");

$Sock = new HTTPSocket;

$Sock->connect($da_server, '2222');
$Sock->set_login($da_user, $da_pass);
//$sock->set_method('POST');

$Sock->query('/CMD_API_ACCOUNT_USER', $arr);
$result = $Sock->fetch_parsed_body();
print_r($result);


But return



Array ( [error] => 1 [text] => Unable to Create User [details] => A valid IP was not provided )


What is this ?

prashantbhushan
04-14-2007, 12:52 AM
Hello,
Is there any API for email quota usage showing allocated and used space.

Thanks,
Prashant.

DirectAdmin Support
04-14-2007, 01:13 AM
Usage:
http://www.directadmin.com/features.php?id=643
CMD_EMAIL_ACCOUNT_QUOTA

and for limit itself:
http://www.directadmin.com/features.php?id=651

John

ah24
04-24-2007, 01:59 PM
Here is what I have so far. I am making this available as open source and would appreciate it if other people woud contribute by building some of the classes or by fixing bugs in the code.

I am fully aware that the code is not 100% and some results are not shown (could use help on this) but at least most of the completed classes work well.


Content of the ZIP file
/code - classes for the API
/config - Configuration file (admin userID, password ...)
/forms - Forms for entering data (links 1-1 to API classes)
/protocol - httpsocket Class


Kind Regards,
Onno Vrijburg

resolveit you are the MAN!! BIG Thanks for this package!!

geforce
06-03-2007, 08:27 AM
Hey all.
I love this class but..

I cant access my admin account because the skin it was using was deleted.

So does anyone have a command which will set the skin of an account?

geforce
06-03-2007, 08:37 AM
Nevermind I got it from a post above.

It works that script.

nzyme
06-15-2007, 07:03 AM
could some1 put together the features of this class? Im guessing its been evolving a lot since the topic started :)

l0rdphi1
06-18-2007, 09:03 PM
could some1 put together the features of this class? Im guessing its been evolving a lot since the topic started :)

Actually, this class has hardly changed since back then; it's designed to be a base class that only queries the DA APIs.

You can find usage for all of the APIs at these URLs:

http://www.directadmin.com/api.html
http://www.directadmin.com/search_versions.php?query=CMD_API

What someone might consider doing is making a library class that extends this class and implements methods that return result sets for each API, but in my mind that's taking it a bit far. :)

Good luck!

Phil