PDA

View Full Version : Questions about the new email API


MagnuM
11-25-2003, 01:37 AM
Thanks for the CMD_CHANGE_EMAIL_PASSWORD. It was realy necessary. If for a successful password change we have a redirect, I am asking how can I redirect a user somewhere else if the old password is wrong, or the confirmation of the new password is not good?

And the CMD_API_POP, I don't know how to use it.
Is this one working only if the users are logged into DA?

I try http://mydomain.com:2222/CMD_API_POP?action=list&domain=mydomain.comand it gives me the login form.

l0rdphi1
11-25-2003, 09:44 AM
To use the APIs effectively, you need to use a "gateway", such as the communication class (http://www.directadmin.com/forum/showthread.php?s=&threadid=258).

l0rdphi1
11-25-2003, 09:47 AM
i.e., for CMD_API_POP:<?php

include 'httpsocket.php';

$sock = new HTTPSocket;

$sock->connect('yoursite.com',2222);
$sock->set_login('admin','password');

$sock->query('/CMD_API_POP','action=list&domain=mydomain.com');
$array_result = $sock->fetch_parsed_body();

print_r($array_result);

?>

MagnuM
11-26-2003, 01:36 AM
Thanks man, you've been more than helpful, by sharing your knowledge with us (all people from this forum).

So I just check http://www.directadmin.com/api.html, but there are no explanations about the new available email API's.

Here are some new questions:
1. Do I need your class for using of CMD_CHANGE_EMAIL_PASSWORD? Because I think, it doesn't require to login.
2. How do I handle the possible error types when change an email password (I need only one good ideea).
3. The API used to create email accounts (CMD_API_POP) doesn't specify the quota for the email box, only the email user and password. Is there a default qouta used by DirectAdmin when create an virtual email box?

Thanks again for everything.

l0rdphi1
11-26-2003, 05:55 AM
Originally posted by MagnuM
1. Do I need your class for using of CMD_CHANGE_EMAIL_PASSWORD? Because I think, it doesn't require to login.Ah, I see. Didn't realize that. Pretty cool.

Originally posted by MagnuM
2. How do I handle the possible error types when change an email password (I need only one good ideea).Well, unless you plan on simply forwarding people to http://yorurhostname:2222/CMD_CHANGE_EMAIL_PASSWORD, you will need to make use of the class. DA will include error=1 in its result if there is an error.

Originally posted by MagnuM
3. The API used to create email accounts (CMD_API_POP) doesn't specify the quota for the email box, only the email user and password. Is there a default qouta used by DirectAdmin when create an virtual email box?Not sure. John will have to tell us that (...and explain why there isn't an option in the API to change it). :)

I'll reply with some code in a few minutes.

l0rdphi1
11-26-2003, 06:10 AM
For CMD_CHANGE_EMAIL_PASSWORD, this should work:<?php

include 'httpsocket.php';

$sock = new HTTPSocket;

$sock->connect('yoursite.com',2222);

$sock->query('/CMD_CHANGE_EMAIL_PASSWORD',"api=yes&email={the_email_address}&oldpassword={old_password}&password1={new_password}&password2={new_password_confirm}");
$array_result = $sock->fetch_parsed_body();

if ($array_result['error'])
{
die("An error has occured: {$array_result['text']}");
}

echo "Password of {the_email_address} has been changed. Here's what DA said: {$array_result['text']}";

?>

This is untested but should work.

MagnuM
11-26-2003, 06:13 AM
Thanks, I want to write myself the same thing, but I thought that CMD_CHANGE_EMAIL_PASSWORD works only with POST. This is where I remain blocked, because I don't know how to use your class with the POST protocol.

Thanks anyway.

l0rdphi1
11-26-2003, 06:15 AM
Originally posted by MagnuM
Thanks, I want to write myself the same thing, but I thought that CMD_CHANGE_EMAIL_PASSWORD works only with POST. This is where I remain blocked, because I don't know how to use your class with the POST protocol.

Thanks anyway.
It works via GET, but if you want POST, after $sock->connect('yoursite.com',2222); add $sock->set_method('POST');

MagnuM
11-26-2003, 06:17 AM
One question: why do we need api=yes?

l0rdphi1
11-26-2003, 08:49 AM
note, if you include the form value "api", you will get url encoded results.http://www.directadmin.com/features.php?id=229

DirectAdmin Support
11-26-2003, 12:28 PM
Hello,

Just to clarify:

CMD_CHANGE_EMAIL_PASSWORD

does not require a DirectAdmin login/password. It works externally from all of the sessions and doesn't *need* to be used with the communication class. It does support both GET and POST but if neither are given, it will show the html page for users to change their passwords. If either GET or POST (or both) are provided, it will assume you're trying to change the email password and will do all of the required form checks. If api=yes is passed, the results will be in API form. If api isn't provided, then the results will be in human readable form (used if you are doing it via plain html and a web browser. api=yes is only needed for scripts running that command.



CMD_API_POP

DOES require the DirectAdmin login/password and sesssions etc.. Will work with GET or POST. Quota is supported in that command, I just forgot to add it ("quota") to the versions update. I also didn't get around to adding it to the api.html yet, so I'll try and get on that soon. Errors are straight forward.. if there isn an error, it will return error=1 with "text" and "details" about the errror.

John