Command line key/URL generation for CLI API calls.

Version 1.62.0


IMPORTANT UPDATE / DESIGN CHANGE BELOW the ==== line NO LONGER APPLIES --cli-command will be dropped. Instead, we'll fall back to using our login key system, but with useful tools for cli. If you have a script/tool that needs to use DA, you'll make a binary call to generate a login key. This key will be passed to curl/API, generated on the fly if needed. eg: 2 new calls: 1) ./directadmin --root-auth-url-for=fred which generates output: https://admin|fred:login_key@hostname:2222 where login_key is replace with the key that should be used. 2) ./directadmin --root-auth-url generates: https://admin:login_key@hostname:2222 --- You'd be able to use it like this: curl -k "$(/usr/local/directadmin/directadmin --root-auth-url-for=fred)/CMD_API_SHOW_USERS?json=yes" The geneated key will be temporary (rules to be confirmed) thus the --root-auth-url-for / --root-auth-url calls must be run for each attempt. We may change them to be one-time use, or any other rule, hence the need for repeated calls. =========================== OLD: EVERYTHING BELOW WILL NOT BE USED and dropped from the binaries (was never in production) ---- ./directadmin --cli-command command=CMD_* ALPHA: This code requires testing prior to production use. It's a front-end wrapper to simulate the socket/request parser for port 2222. Not all end-points have been tested. -------------- Root access to run any CMD_ call (GET or POST) via cli. json=yes is always assumed for the input/output, passing it is not required, but you may need to add if the output is not in json (please report any such cases) Eg: ./directadmin --cli-command command=CMD_SYSTEM_INFO user=admin Will dump the CMD_SYSTEM_INFO command, while running as admin. For GET/POST, add: method=GET method=POST the data passed in the GET/POST request will be passed in the data='' value, eg: =========== EXAMPLES ---------------- List all email accounts for this domain: ./directadmin --cli-command command=CMD_EMAIL_POP user=admin method=GET data='{ "GET": "" }' Where the data array will be "GET" and/or "POST", added to the json. The data GET/POST value can be a URL encoded string, or can be json (DA will figure it out and parse as needed). NOTE: shells might not like the & character should you be using it in your GET/POST. DirectAdmin will URL decode normally, so use %26 instead of the ampersand & character, eg: "" You might hit an error like this if you're hitting the issue: "result": "Request::set_cli_request: error parsing json line: String did not find closing '\"' assuming you're using valid json. To keep the data safe, you can use: data=stdin and pass your json {} to stdin, followed by an EOF character (ctrl-d when doing it manually) --------------- CREATE EMAIL ACCOUNT This is a stdin sample, can be piped to DA however you wish. In this example, we'll create a file called: CMD_API_POP.json (name doesn't matter) With contents: { "POST" : { "domain" : "", "action" : "create", "user" : "cliuser", "passwd" : "scretpAss1!", "quota" : "10" } } and make the request to DA as follows: [root@es6-64 directadmin]# ./directadmin --cli-command command=CMD_API_POP user=admin method=GET data=stdin < CMD_API_POP.json { "result": "cliuser", "success": "Email account created" } --------------- COMMAND LINE VALUES IN DATA For added security, you want not want command, user, method on the command line. These values can be included in the stdin/data, instead of the command line, eg: { "method" : "POST", "command" : "CMD_API_POP", "user" : "admin", "POST" : { "domain" : "", "action" : "create", "user" : "cliuser", "passwd" : "scretpAss1!", "quota" : "10" } } [root@es6-64 directadmin]# ./directadmin --cli-command data=stdin < CMD_API_POP.json { "error": "Unable to create email account", "result": "That user already exists\n" } NOTE: command line arguments will override any data/stdin arguments. This may be useful if you --------------- RETURN CODE If the wrapper is able to correctly simulate the input, and all data is parsed and sent to the back-end, exit code 0 will be returned from the directadmin binary. This includes "error" states for the json, eg: the above "That user already exists" returns exit code 0 as the wrapper was successful. Check for "error" in the JSON output, but it may vary based on the CMD call made (see API documentation for the expected json output) However, any wrapper errors, such as json parsing, missing method/command/user, etc.. will exit with code 14. The output there "should" still be in the same json "error" format.

Interested to try DirectAdmin? Get a 30-day Free Trial!