Hello,
A problem I have is possibly that not all the API commands support multiline, and think there was even at least one that didn't work with json=1 which is what I am using for everything. I have worked around most of the things but I will mention those anyway.
I am creating a front end to Virtualmin which will work by completely integrating to the Virtualmin API. To do this it automatically generates the PHP code to talk to each of the functions. Therefore it can work with both the GPL or the PRO versions and adapt to any future API changes you make in Virtualmin.
It uses the list-commands API call to Virtualmin and parses this output (which doesn't have multiline) and gets the list of commands. Here is some duplicates list-commands outputs: create-simple-alias, list-simple-aliases
Hopefully the commands and their --help info are up-to-date in list-commands as this would all depend on that to work properly.
I was also wondering how/if it would be possible to use the "virtualmin help create-domain" type CLI commands in the remote API. These are different than the --help (&help=) params and contain more info that's useful in some cases. It seems to be the only part missing to create a complete, automatic, auto-adapting, Virtualmin API documentation reference guide.
I think if I am to have a complete API integration in my app then using the Virtualmin documentation to help users figure out which params are required or optional then info on what they mean and how to use them is necessary. Since Virtualmin can already output this info I guess it makes sense to use it but maybe its not the intended use for it and maybe I am not even allowed to do that?
Much of the documentation online seems outdated as I am sure you know. It doesn't really take much for it to be outdated and its hard to keep up with documentation. Maybe you have a system to output the code for it already. Maybe thats what this is? http://www.virtualmin.com/documentation/developer/cli/import_api_docs
And last of all I hope to maybe also parse each of the required and optional variables for each command so that I can better filter the inputs before sending things through the PHP shell_exec command. I get this help output by issuing a &help= param to the remote API. While these all send back the help, some say there is no --help param which I have to filter out. There are two variations of it: "Unknown parameter --help" and "Unknown option --help". That's ok though because I am also filtering out the Exit status which can be useful in some cases. And I will still be able to parse the options somehow or another. But there are a couple of things I wanted to ask.
First, maybe there is a better way to parse these parameters on output from the API in the first place? If there was a way to use multiline on each param kind of so I could have an array like this:
Array
(
[Backup and restore] => Array
(
[0] => Array
(
[required] => Array
(
)
[optional] => Array
(
[dest] => file]+
[test] =>
[0] => Array
(
[domain] => name
[all-domains] =>
)
[user] =>
[plan] =>
[feature] =>
[ignore-errors] =>
That is the first part of the array which includes the first part of the Backup and restore section.
And second, does it say some place what the + and * and whatnot mean on some of the commands? I thought I saw something some place but I don't remember where. They don't seem to have to do with the required inputs. The required params for each function seem to be without the [] around them. And there are the | to contend with.
Cool stuff! Thanks for making this software so awesome =) Sorry this is so long. I probably forgot some stuff.
Comments
Submitted by JamieCameron on Wed, 02/02/2011 - 13:53 Comment #1
That sounds like an impressive project!
The list-commands output and --help results will always be the most up-to-date source of information, as they are taken from the commands themselves on the system ... and can change over time depending on the Virtualmin version. The docs at www.virtualmin.com on the other hand typically are based on just the latest release.
So, it sounds like you are looking for a way to get the command parameters in a programmatic way?
Would it be useful if there was a remote API call that returned all the help, but in some parsable JSON format? That could certainly be added ..
Submitted by rrhode on Wed, 02/02/2011 - 18:22 Comment #2
Aha, yes, that would certainly make it easier than having to parse them all out which I think could also be quite prone to errors.
So yeah, if there was a way for the remote API to get the output for the params from the "virtualmin command --help" type commands in a more easily parsable format which separated the required and optional commands, and whatever the + and * are for I don't know, that would be really awesome =)
And the extra help from the "virtualmin help command" type command would just be icing on the cake.
I hope you read some of the extra tidbits I sprinkled throughout my long ass post. Like the duplicate commands list-commands outputs. I just mention it since I am told you would be happy to clean up the API =)
Maybe there would be some way to run a front-end in perl but I don't know perl so well so I am just using PHP. But maybe that's better for something like this anyway. Maybe more people would know that language and be able to modify and customize their site.
I hope to allow the ability for plugins and things so hopefully people build stuff for it eventually. Should be an interesting experience alright. Basically it should allow people to have a billing and support type system or whatever else they happen to want to use there to front Virtualmin, and maybe eventually Cloudmin. I think it has its own API anyway.
Oh, and I just remembered another thing I forgot to mention before. I don't know if this is the right page for this or not but the first link has a link to the second one: https://www.virtualmin.com/documentation/developer/cli https://www.virtualmin.com/documentation/developer/cli/script_installers/
Thanks =)
Submitted by JamieCameron on Thu, 02/03/2011 - 00:22 Comment #3
Thanks for the pointer on the duplicate commands .. I'll fix that.
Also, I will add a multiline option to list-commands, so that it produces output in JSON format.
Will update this bug with more details when I've added a way to get help parameters programatically.
Submitted by rrhode on Thu, 02/03/2011 - 07:42 Comment #4
Thanks man! I do appreciate it. Awesome as always. People always tell me "baby steps" but I seem to just run and dive in face first and hope for the best.
I was thinking, the software I am making is free and open source so if you wanted you guys could even use it to make your online API documentation better or more updated if you don't have something for that yet and still have to manually do it all.
If there is any testing or anything you want me to do while I am messing around just let me know =)
Submitted by JamieCameron on Thu, 02/03/2011 - 18:07 Comment #5
I've been looking at this a bit, and it may be more complex than it first appears as the --help output for most commands isn't really in a strictly consistent format.
Could you tell me a bit more about why you need these parameters exactly, and what you need to know about each one?
Submitted by rrhode on Thu, 02/03/2011 - 18:33 Comment #6
I guess I mostly have to know if they are optional or required.
I am not sure what the + and * are for and whatever else there is on some of them, maybe that is important?
Knowing if the command is required or optional is probably the minimal to make it responsive. Knowing how to validate the input before sending it through the shell_exec PHP command is probably useful to keeping things secure but I might have to just go through them all and make custom regex filters or something.
It would be good to know everything possible about them I guess so that I can validate the input as best as possible before sending it through to Virtualmin in order to try and keep things responsive and secure. Perhaps Virtualmin checks them anyway and will send back the help output and an error if they aren't input correctly.
Submitted by JamieCameron on Thu, 02/03/2011 - 18:39 Comment #7
So in the current output, the [ ] means that a command is optional. A * at the end means it can be repeated, and a + means it must be given at least once and possibly more.
Submitted by JamieCameron on Thu, 02/03/2011 - 19:28 Comment #8
In the next Virtualmin release, I will add an API operation called get-command that will provide information on all the parameters of a given command, including if they are optional or not.
That said, any code you write should still do its own validation instead of relying entirely on this, as there is no way for get-command to explain the underlying meaning of each parameter.
Submitted by Issues on Thu, 02/17/2011 - 21:21 Comment #9
Automatically closed -- issue fixed for 2 weeks with no activity.