#!/usr/bin/env ruby require "goliath/runner" require "phantom_proxy" require 'optparse' module PhantomProxy def self.load_config options = {} optparse = OptionParser.new do|opts| opts.banner = "Usage: " opts.on( '-l [FILE]', '--logfile [FILE]', 'Write log to FILE' ) do |file| # PhantomProxy2.logger = Logger.new(file) options[:log_file] = file end opts.on('--hmac [STRING]', 'Use a hmac key to secure the connection' ) do |hmac| # PhantomProxy2.hmac_key = hmac options[:hmac_key] = hmac end opts.on('--threadpool_size [INTEGER]', 'Specify this value to use a specific threadpool_size' ) do |threadpool_size| options[:threadpool_size] = threadpool_size end end args = ARGV.dup remaining = [] while !args.empty? begin head = args.shift remaining.concat(optparse.parse([head, args].flatten)) rescue OptionParser::InvalidOption remaining << head retry end end PhantomProxy.logger = Logger.new(options[:log_file]) if options[:log_file] PhantomProxy.hmac_key = options[:hmac_key] if options[:hmac_key] && options[:hmac_key] != "none" PhantomProxy.threadpool_size = options[:threadpool_size] if options[:threadpool_size] remaining end def self.run_phantom_proxy(args) puts "Run with #{args}" EM.threadpool_size = PhantomProxy.threadpool_size if PhantomProxy.threadpool_size runner = Goliath::Runner.new(args, nil) runner.logger=PhantomProxy.logger runner.port = PhantomProxy.port if PhantomProxy.respond_to?(:port) runner.address = PhantomProxy.address if PhantomProxy.respond_to?(:address) Goliath.env = PhantomProxy.env if PhantomProxy.respond_to?(:env) runner.api = PhantomProxy::Service.new runner.app = Goliath::Rack::Builder.build(PhantomProxy::Service, runner.api) puts "Now starting PhantomProxy #{PhantomProxy::VERSION}...." runner.run end end PhantomProxy.run_phantom_proxy PhantomProxy.load_config