Can the Virtualmin command line API output JSON?

Hi guys,

Can the Virtualmin Command Line API output JSON?

I know about multiline and I’m using json=1 when doing API calls using HTTP GET, but I would like to rely on SSH keys rather so wanting to get JSON from the command line.

Is this possible?

Manual: Remote API – Virtualmin,

JSON output is intended for the remote API calls as far as I know, the CLI doesn’t emit JSON.

This would be the ideal command:

virtualmin list-users --domain --multiline --json

I had a look at the code. The JSON library is this file:

The list-users command program is here:

In there command line options are received, and I don’t see json=1 in there.

I supposed if one could include or remotely call the JSON::PP library arbitrarily from the list-users program it might work.

I see one challenge that a remote API might be some kind of HTTP stream and the entry point will have to look different. This maybe be a relevant line:

# convert_remote_format(&output, exit-status, command, &in, [format])
# Converts output from some API command to JSON or XML format
sub convert_remote_format
my ($out, $ex, $cmd, $in, $format) = @_;

Anyhow. Wayyy over my head. @staff

Yeah, I can’t think of any reason we shouldn’t offer JSON on the CLI, too. @Jamie, any thoughts on whether that’s difficult to add?

I suppose adding JSON support to the CLI could be done - perhaps via a wrapper command that calls the same JSON conversion code. is there a reason why using HTTP doesn’t work for you though?

Thanks so much @Jamie for the reply. We’re automating a number of our servers and
one of our automations allows end-user administrators to see how much disk space their mailbox users are using.

This automation reads the output from the list-users program and the extracts home_byte_quota_used.

To do it via the remote API means that we send the URL in this format: with HTTP basic authentication on the HTTP Get commands.

The problem is to get basic Auth to work, we need to store root credentials in our management program in unencrypted format. This seems like a huge security risk. I haven’t figured out if encrypting the credentials is possible on the HTTP Auth calls and I doubt it is.

So what would be a lot more ideal would be to use key based authentication and SSH calls that then remotely executes the programs. The programs currently output a type of text indenting format and it would be hard to rewrite JSON wrappers for those, especially if this has already been accommodated for the remote API.

OK I see … let me figure out if there’s a way to create a simple wrapper that converts the output of shell API commands to JSON.,

Technically you could create another “webmin user” with access to the “Virtualmin Virtual Servers” permission, therefore not exposing your “root” password.

I’ve done this a few times in the past, allowing me to setup a sort of “API Key” type model where the username and password was something like:

Username: 82e7844c-a1b6-4622-b5ef-e637cb0220ba
Password: c144413e-f84d-4879-86cd-fd9f61906a59

This would make it similar to many restful APIs that use this type of format.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.