CMD_MASTER_LOGIN: master access while login-as as User
If you're a creator (Admin or Reseller) and you "Login As" one of your created accounts, you previously only had access to data from this account.
This CMD_MASTER_LOGIN allows queries to certain higher-level data, allowing ease of switching between logins without needing to do a Logout and Login. One can simply switch between accounts with a search.
You must be logged in as another account using the "Login As" function to use this. This makes use of the existing global token:
|LOGIN_AS_MASTER_NAME|
to know if it does not match |USERNAME|
, and you can use it.
SEARCH
The GET search=
value can be any text, and a sub-string search of all available Users/domains will be returned, up to the ajax_list_max=20
limit (directadmin.conf).
SPECIAL SEARCH
search=[all] - returns ALL available Users/domains. If master is an Admin, this is every account on the server, all domains on the sever.
search=[all_users] - same as [all], less any domains.
search=[all_domains] - same as [all], less any accounts.
search=[user]&user=fred - returns data only for user fred.
2
3
4
Using the [all*] methods will most likely be a slower response time for servers with thousands+ of accounts.
When possible, just use the dynamic-autofill style result with a search every time the User stops typing the search value. You could alternatively pre-load the full set, and search from that with JS, as long as you're aware of the possible load delays, making the type-search response time faster since it's all client-side.
LIST ALL USERS
A fast listing of all visible accounts can be done with CMD_MASTER_LOGIN?search=[all_users]
:
[
"admin",
"auser",
"backtest",
...
]
2
3
4
5
6
JSON
CMD_MASTER_LOGIN
method: POST
action=login
user=fred
2
3
4
will produce dynamic output, and if no error occurs, a normal dynamic success will be sent PLUS:
same_skin=0|1
so that you'll know if you need to reload a cache (that's up to the skin coder's discretion). If 0, you'll likely just want to redirect to / to avoid any issues.
JSON
The CMD_MASTER_LOGIN
call will allow for:
method: GET
action=search
search=<your query>
2
3
where it will hunt for Account and Domains accessible.
If you see is_reseller_skin >= 1
, you'll want to refer to the bottom of this guide for details on how to warn them about the potential security risks of logging in: https://www.directadmin.com/features.php?id=2062open in new window
Where is_reseller_skin=2
, it's not a global skin, but you'll be getting an override to the same current skin (safe, uses your current skin).
The is_reseller_skin=1
should add a warning about the danger of logging into a Reseller skin, and only do if you want to (or just set directadmin.conf with: allow_admin_login_as_to_reseller_skin=0
, which returns is_reseller_skin=2
).
ONE USER REQUEST
If you only want the info for one specific User, the most efficient way would be to use:
CMD_MASTER_LOGIN
method: GET
action=search
search=[user]
use=fred
2
3
4
5
where fred is the one and only User you wish to request information for. No "searching" is done as it's a direct access and display of data, and far quicker than hunting through lists.
RETURN
Will be 2 arrays, eg:
GET: CMD_MASTER_LOGIN?action=search&search=test
{
"domains":
{
"backtest.com":
{
"is_reseller_skin": "0",
"user": "backtest"
},
"hacktest.com":
{
"is_reseller_skin": "1",
"reseller_skin": "/home/reseller2/skins/power_foofoo",
"reseller_skin_owner": "reseller2",
"user": "hacktest"
},
},
"users":
{
"backtest":
{
"creator": "admin"
},
"hacktest":
{
"is_reseller_skin": "1",
"reseller_skin": "/home/reseller2/skins/power_foofoo",
"reseller_skin_owner": "reseller2",
"creator": "reseller2"
},
}
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
PAGINATION
As the size of the results can be large, it's highly recommended to use the result pagination. You can specify the number of results on a page, and the desired page number. For example, the first load of the page should request:
pagination_ipp=50&pagination_page=1
As the User scrolls, once the bottom approaches, say when the scroller is a given number of items near the end or some similar logic, then load the next page into the list.
NOTE: there is a global |TABLE_DEFAULT_IPP|=50
token, as per the directadmin.conf table_default_ipp=50
.
When both the pagination_ipp
and pagination_page
are greater than 0, then the pagination will kick in.
When enabled, DirectAdmin will also include output similar to table info, except per-domain list and per-user list, at the top-level of the json output (not in the "domains" array), e.g.,
CMD_MASTER_LOGIN?action=search&search=test&pagination_ipp=5&pagination_page=2
{
"domains":
{
"testrecur.com":
{
"is_reseller_skin": "0",
"user": "testrecur"
},
"testrestwo.com":
{
"is_reseller_skin": "0",
"user": "reseller2"
}
},
"domains_info":
{
"current_page": "2",
"ipp": "5",
"rows": "7",
"total_pages": "2"
},
"users":
{
},
"users_info":
{
"current_page": "2",
"ipp": "5",
"rows": "5",
"total_pages": "1"
}
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
Note how the request is for page 2 (using ipp=5), and this does overlap with the domain list, but not with the User list.
For the User list, the total of 1 page is less than the requested page 2, thus the User result is empty.