oikonomopo
oikonomopo

Reputation: 4065

Can this be done? Bash script in a web application

I have a bash script (supports linux/unix), that installs an application. Instead of executing the script in the terminal, I want to deploy it as a web application.

I want to make a web graphical interface for this script, so that the user can give the necessary inputs in the web forms and when ready,then pass these variables into the bash script to be executed.

This script obvious needs root privileges.

I plan to make it with with tomcat 7 / servlet / jsp. I want to deploy it as .war file.

First, can this be done? Is it possible?

Second, is there any example? I didn't find anything.

Third, any alternative method/better idea?

Upvotes: 0

Views: 1454

Answers (3)

DigitalRoss
DigitalRoss

Reputation: 146141

Err, but you want this to run on the client side, right?

So you don't really run it as bash on your system, you just template it within your web framework.

If the browser can then display this, it won't just d/l as a file, so you will need to set up a Content-Disposition: attachment header in the response to force a d/l.

You will naturally need the user's cooperation to run this as root on his or her system...

Upvotes: 0

Roland Bouman
Roland Bouman

Reputation: 31981

I'd try tomcat's own CGI support.

http://tomcat.apache.org/tomcat-6.0-doc/cgi-howto.html

Upvotes: 1

Oscar Del Ben
Oscar Del Ben

Reputation: 4515

Well, it's possible, but keep in mind that sanitizing user input is hard.

What you want to do is use a scripting language or framework (I recommend sinatra), and use a html form to pass arguments to the backend. In the backend, you call your script by passing whatever arguments you want.

Example with sinatra:

post '/whatever' do
  # This is dangerous!
  `myscript #{params[...]}`
end

Upvotes: 0

Related Questions