1

A couple of months ago I created a form in html/php that would be use to enter informations about new Virtual Machine.

I've also been working on a simple ruby script that would find a new IP address for a new Virtual Machine.

Those two projects were not linked, but now I would like it to be.. but I'm having a hard time. What I'd like to do is to run the ruby script with the informations provided in by the user in the web form.

Lets say the user enters the new VM name (vm1) and some other things like its vlan id (1). I'd like to be able to have the form launch the script with the right paramaters (./script.rb --add vm1 --vlanid 1 --...). I tried to find an easy way to do this, but did not manage to. I installed passenger, but I'm kind of lost with it and it seems pretty overkill to install that only to do what I want.

Thank you guys!

4
  • 2
    Might want to be careful with random form input and running a script using some sort of system call... the form input could be anything... like piping something as innocent as an rm call to your system. :( Commented Feb 23, 2012 at 18:08
  • Since this application will stay only inside the company, I think I'll be alright with that. But still, you are right, I did not think about that. Commented Feb 23, 2012 at 18:11
  • Are you using any sort of framework, like Rails or Sinatra? (Just because you are dealing with forms...) Commented Feb 23, 2012 at 18:17
  • Don't think so. I simply installed the ruby libs and some gems on my linux machine. My webform and the script are two different projects, but it would be nice if I could link them without too much trouble :) Commented Feb 23, 2012 at 18:19

2 Answers 2

2

You could do it with exec():

<?php
// TODO: Security checks!
exec("./script.rb --arg1 $arg1 --arg2 $arg2 &");
?>

Another way to do it is add a web interface to your Ruby script. A great gem for very simple web interfaces is Sinatra, you can just define a basic handler:

require 'rubygems'
require 'sinatra'

get "/" do
  # do what you need to do, all the GET arguments are in the params Hash
end
Sign up to request clarification or add additional context in comments.

1 Comment

I'm giving a try to sinitra. I'll try to create a web form with it.
1

As long as you are sure about form input (as mentioned in the comment from earlier:)

You might just want to look into using that form POST data (like in this article: http://biodegradablegeek.com/2008/04/how-to-post-form-data-using-ruby/).

And then try running a system call (like this) (or exec like this,) to your VM script.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.