#!/usr/local/bin/ruby require 'webrick' include WEBrick require 'net/telnet' server = HTTPServer.new( :Port => 2000 ) class ControlServlet < HTTPServlet::AbstractServlet @@connection = Net::Telnet::new("Host" => "192.168.1.6", "Port" =>6546, "Timeout" => 3, # "Output_log" => "output_log", "Prompt" => /[$%#>] \z/n) puts "creating connection" def do_GET(req, res) res['Content-Type'] = "text/html" res.body = %Q[ ] res.body = res.body + %Q[
PAUSEUP-
LEFTENTERRIGHT
BACKDOWN+
] uri = req.request_uri.request_uri() vals = uri.split(/\//) return if vals.size ==0 vals.shift.each{|v| res.body = res.body + "[" + v + "]
" } command_string = vals.join(" ") res.body = res.body + "
sending command string [#{command_string}]
" res.body = res.body + "RESPONSE:
" + @@connection.cmd(command_string) + "\n" + "
" end end server.mount("/", ControlServlet) trap("INT"){ server.shutdown @@connection.close } server.start