CGI and NET::SSH in the same script problems


#1

I’m perplexed as to why I can run the following just fine from a command
line, but when I try to execute from a web browser it crashes.

From the command line it prints out…

FlyBOB Control

Panel

cmd=>[echo ‘THIS IS A TEST FROM THE REMOTE SHELL’] got
stdout:
THIS IS A TEST FROM THE REMOTE SHELL
cmd=>[echo ‘THIS IS A TEST FROM THE REMOTE SHELL’]
closing!

Which means if this text is rendered in a web environment it should
print
THIS IS A TEST FROM THE REMOTE SHELL

Does anyone know why you can’t call net/ssh from a CGI or how to debug
this in a browser environment?

----------------------------- ruby cgi script

require ‘cgi’
require ‘rubygems’
require ‘net/ssh’

def do_sync_cmd( session, command )
session.open_channel do |channel|
channel.env(“PATH”, “/usr/pbs/bin:/acct/uzer/test/bin”)
channel.exec("#{command}") do |ch, success|
abort @myString.concat(“could not execute #{command}”) unless
success

  channel.on_data do |ch, data|
    @myString.concat("cmd=>[#{command}] got stdout: \n#{data}")
    channel.send_data "something for stdin\n"
  end

  channel.on_extended_data do |ch, type, data|
    @myString.concat("cmd=>[#{command}] stderr: \n#{data}")
  end

  channel.on_close do |ch|
    @myString.concat("cmd=>[#{command}] closing!\n\n")
  end
end

end
session.loop
end

@myString = “XXX”

Net::SSH.start(‘myserver.com’, ‘uzer’) do |session|
do_sync_cmd session, “cd /acct/uzer/test/bin && ls -l”
end

cgi = CGI.new(‘html4’)
params = cgi.params

cgi.out {
cgi.html {
cgi.head { cgi.title {‘Test Control Panel v0.1’}}
cgi.body {
cgi.h3 {‘Test Control Panel’} +
cgi.p {"#{@myString}"}
}
}
}