#!/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 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] remaining end def self.run_phantom_proxy(args) puts "Run with #{args}" 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