We’ve got a number of perl and python scripts we want to expose to some of our teammates for casual usage; and we really don’t want ot deal with getting them setup with git, perl, python, dependencies, etc.
One idea we had was to write a descriptor for each script as to what arguments it needed; and then let a simple HTML page call a CGI script with the appropriate arguments, wait and return stdout to the user.
This seems such a simple need that I’m amazed that I can’t find anything like it existing out there. No framework that renders out the form, that puts out a virtual console screen…
There are, of course, major security concerns. Can anyone recommend a solution that does the above, or something else similar?
I think you’re looking at the problem the wrong way.
No generic framework for running scripts would be likely to help type-checking the arguments to an arbitrary perl or python script, since they’re just strings (whether passed to
sys.argv/$ARGVor as CGI environment variables).But if you split this into parts, they’re all pretty easy, and mostly orthogonal.
First, how do you do type-checking on the fields? Well, if you’re willing to require HTML 5, just put the appropriate type and other parameters on the fields:
If you need to support older browsers, google “HTML form validation” or “JS form validation” and you’ll find hundreds of libraries that do things, either by simplifying the JS you’d have to write, or by letting you attach stock validators by name or CSS style, e.g.:
As usual jQuery is tremendously helpful. There are some solutions that let you write something identical to HTML 5; articles like this one show how easy it is to build one from scratch. Or, even simpler, just use the Validation plugin, so you only need one line of JS.
For setting up the form to trigger your scripts, any stock CGI framework will do this out of the box.
For making the scripts return their stdout to the user, that’s built-in to CGI too. However, make sure to configure your server to send content-type text/plain instead of text/html (for the directory the scripts are in, or for *.cgi or *.py/*.pl, or whatever’s appropriate).
So, what’s left? Do you want to generate the forms automatically from, say, some database mapping script names to type validation strings? Again, nobody’s going to have a generic library that builds forms out of your type string format. But it’s pretty easy to write with jQuery. Just create a form with an empty fieldset and action. In
#(document).ready(or on selecting from an option menu, or whatever), add fields with the appropriate validation attributes to the empty fieldset. (Or, alternatively, if you’re using a simple script-based validation library, just modify the library code to use your type descriptors directly instead of using some other format.) You can also set the action attribute here (if you’re using HTML 5 or the Validation plugin, so you don’t need a custom submit script), or just hit the URL from your custom submit script (if you’re doing validation in a way that already needs it).So, yes, there’s some code to be written here. But any solution is going to require some code—you have to feed the types into it somehow, right?—and using popular general-purpose libraries (e.g., jQuery with the Validation plugin) is probably going to require no more code than any more special-purpose framework would have. As well as being a lot more customizable, and maintainable (it’s a lot easier to find people who have jQuery experience than people who have experience with some narrow-purpose library).