Sha256: 7dd8dee231cb59cc4aadb4b70bbc8e2041a5297103ab9df29745bc9ba1076cb6

Contents?: true

Size: 1.92 KB

Versions: 1

Compression:

Stored size: 1.92 KB

Contents

#!/usr/bin/env ruby

require "rubygems"
require "em-websocket"
require "json"
require "rack"
require "sinatra/async"
require "optparse"

class FingerPoken < Sinatra::Base
  register Sinatra::Async
  set :haml, :format => :html5
  set :logging, true
  set :public, "#{File.dirname(__FILE__)}/../public"
  set :views, "#{File.dirname(__FILE__)}/../views"

  aget '/' do
    headers "Content-Type" => "text/html"
    body haml :index
  end # GET /

  aget '/style.css' do
    headers "Content-Type" => "text/css; charset=utf8"
    body sass :style
  end # GET /style.css
end

def main(args)
  targets = []
  opts = OptionParser.new do |opts|
    opts.banner = "Usage: #{$0} [options]"

    opts.on("-t TARGET", "--target TARGET",
            "Target a url. Can be given multiple times to target multiple things.") do |url|
      target = URI.parse(url)
      case target.scheme
      when "xdo"
        require "fingerpoken/#{target.scheme}"
        targets << [:Xdo, {}]
      when "vnc"
        require "fingerpoken/#{target.scheme}"
        targets << [:VNC, {}]
      when "tivo"
        require "fingerpoken/#{target.scheme}"
        targets << [:Tivo, { :host => "192.168.0.134" }]
      end
    end
  end
  opts.parse(args)

  puts targets

  EventMachine::run do
    $:.unshift(File.dirname(__FILE__) + "/lib")
    channel = EventMachine::Channel.new

    targets.each do |klass, args|
      args.merge!({ :channel => channel })
      puts FingerPoken::Target.const_get(klass).new(args)
    end

    EventMachine::WebSocket.start(:host => "0.0.0.0", :port => 5001) do |ws|
      ws.onmessage do |message|
        request = JSON.parse(message)
        puts "Request: #{request.inspect}"
        channel.push(request)
      end # ws.onmessage
    end # WebSocket
    
    Rack::Handler::Thin.run(
      Rack::CommonLogger.new( \
          Rack::ShowExceptions.new( \
                FingerPoken.new)), :Port => 5000)
  end # EventMachine::run
end

exit(main(ARGV))

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fingerpoken-0.2.20101216024109 bin/fingerpoken.rb