Creating a Login Key for a user through CMD_API_LOGIN_KEYS

AU_Chris

New member
Joined
Sep 22, 2021
Messages
4
Hi,

I'm trying to automatically create a Login key for users on my server through the API using the examples and the HTTPSocket class.
After a bit of experimenting I've managed to turn the Login keys option on through the API for any given user. Using the login-as method, I was hoping to create these without having to know my users passwords

This should be possible if I'm interpreting this page correctly: https://www.directadmin.com/features.php?id=1298

Reading that I came to the following:

PHP:
$sock = new HTTPSocket;
$sock->connect('mailserver',2222);
$sock->set_login('reseller|user', 'password');

$sock->query('/CMD_API_LOGIN_KEYS', [
    'keyname' => 'akeyname',
    'key' => 'whatever',
    'key2' => 'whatever',
    'never_expires' => 'yes',
    //'expiry_timestamp' => ?,
    'max_uses' => 0,
    'clear_key' => ' no',
    'allow_html' => 'yes',
    'passwd' => 'password',
    'select_allow0' => 'ALL_USER',
]);

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

However all I'm getting in return is some information about a LoginKey my reseller account has and no key is made in my user account.
Can anyone tell me how to generate a key for my user account?
 
Right. Thanks for beeing my rubber duck, DA forum. I decided to take a look at the HTML form for making a login key and found the missing fields

'action' => 'create',
'type' => 'key',

and got it to work.

Code:
$sock->query('/CMD_API_LOGIN_KEYS', [
    'action' => 'create',
    'type' => 'key',
    'keyname' => 'akeyname',
    'key' => 'whatever',
    'key2' => 'whatever',
    'never_expires' => 'yes',
    //'expiry_timestamp' => ?,
    'max_uses' => 0,
    'clear_key' => ' no',
    'allow_html' => 'yes',
    'passwd' => 'password',
    'select_allow0' => 'ALL_USER',
]);
 
Question: if I need to create a login Key with few features disabled, what is the syntax?
'select_allow0' => 'ALL_USER' create a login key with all basic user permissions, but what if I need to disable few of them? What's the syntax to be used?
 
Question: if I need to create a login Key with few features disabled, what is the syntax?
'select_allow0' => 'ALL_USER' create a login key with all basic user permissions, but what if I need to disable few of them? What's the syntax to be used?
Answering myself on my own: it's sufficient to change
'select_allow0' => 'ALL_USER'
with
'select_allow0' => 'CMD_DNS_ADMIN'
'select_allow1' => 'CMD_DNS_CONTROL'
'select_allow2' => 'CMD_DNS_MX'
'select_allow3' => 'CMD_DOMAIN_POINTER'

And so on...
Doing so, I created a login key and was able to log in but...
It's not usable, because the web interface goes on blinking and flashing.

I guess there may be some kind of permission hierarchy, or permission dependency, that I'm missing, and that I should add a few other permissions, but I don't know what else should I add to...

The permissions I allowed are the following:
CMD_DNS_ADMIN
CMD_DNS_CONTROL
CMD_DNS_MX
CMD_DOMAIN_POINTER
CMD_EMAIL_FORWARDER
CMD_EMAIL_FORWARDER_MODIFY
CMD_LOGIN
CMD_REDIRECT
CMD_SSL
CMD_SUBDOMAIN


(What I want is to create a user that is just able to manage DNS, email forwarder and redirect)

Any idea?
 
Doing so, I created a login key and was able to log in but...
It's not usable, because the web interface goes on blinking and flashing.
I just tried login keys for the first time (giving a user permissions for autoresponder and vacation messages for email), and face the same problem. Site is reloading instantly and very fast in a loop, no chance to work with it. Was you able to solve this issue?
 
Back
Top