Class: Spade::Server::CommandRunner
- Inherits:
-
Object
- Object
- Spade::Server::CommandRunner
- Defined in:
- lib/spade/server.rb
Instance Method Summary collapse
-
#call(env) ⇒ Object
FIXME: This is not very safe, we should have some restrictions.
-
#initialize(app) ⇒ CommandRunner
constructor
A new instance of CommandRunner.
Constructor Details
#initialize(app) ⇒ CommandRunner
Returns a new instance of CommandRunner.
21 22 23 |
# File 'lib/spade/server.rb', line 21 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Object
FIXME: This is not very safe, we should have some restrictions
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/spade/server.rb', line 26 def call(env) if env['PATH_INFO'] == '/_spade/command' rack_input = env["rack.input"].read params = Rack::Utils.parse_query(rack_input, "&") command_path = params['command'] return [500, {}, "command required"] if command_path.nil? || command_path.empty? if ((root = params['pkgRoot']) && !root.nil?) command_path = File.(File.join(command_path), root) end tempfile = Tempfile.new('spade-server') tempfile.write(params['code']) tempfile.close puts "Running: #{command_path}" output = `#{command_path} < #{tempfile.path}` tempfile.delete [200, {}, output] else @app.call(env) end end |