Wrapping a bash script for CGI

I hope its ok to start a new thread, I was going to use my existing one but thought a new one would better clarify things and provide better search for future reference.

Well I have my bash program working now, all nice, user input validated, output formatted, everything is looking sexy.

Now the guys tell me that they don't want telnet access to the server, grrrrrrr! I have to make
an idiot proof web interface.

So I need to choose a way to go. As I see it I can either re-write the whole thing in perl or
somehow 'wrap' my bash into a cgi interface.

I've been thinking about the latter option and it seems non-trivial to me at this stage. On the face of it my thinking goes something like this pseudocode:

1) Spawn a copy of my bash script and background it&
while[1] do
2) Take the standard output of the script and redirect it to a little HTML wrapper something like
echo "content-type: text\/html \<html\> <body>
$MYSTDOUTHERE \</html\>\</body\>"
3) process a POST request and send the relevant data to my backgrounded script
done

While I can express the concept clearly enough (I hope) the details are a bit fuzzy and I would welcome any input or comments before getting started. Is such a method possible/reliable/secure?
The web interface would only be used by trusted administrators but I am worried enough about 'command substitution' in any situation where CGIs are involved, its my natural paranoid stance :slight_smile:
all best regards
Andy

I think this is not secure in any case. I don't really understand why your users don't like telnet/ssh. A telnet bash session has completion, history and all goodies a Web-based one won't have. Typing commands in a Web page and a telnet session -- what makes the difference? Moreover, it's slow. manpages doesn't display well, for example.

If they really want it Web-based, consider a Java telnet/ssh client like http://javassh.org/

If they only need to carry out some predefined tasks, I think you may give them a Web interface with some menu options which execute the commands for them. But to have a command line directly attached to the Web is a very dangerous idea I can think of even if the user community is trusted.

Thanks cbkihong. I worked out how to do it but its really very ugly. Your idea of the JavaWeb telnet interface seems like the perfect political compromise and that is the method I am going with.
All good wishes
Andy