bin/phantom_proxy in phantom_proxy-1.2.17 vs bin/phantom_proxy in phantom_proxy-1.3.0

- old
+ new

@@ -1,60 +1,53 @@ #!/usr/bin/env ruby -require 'thin' +require "goliath/runner" +require "phantom_proxy" +require 'optparse' -require 'fileutils' -require 'timeout' -require 'stringio' -require 'time' -require 'forwardable' -require 'rack' -require 'daemons' +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) -module PhantomJSProxy - CONFIG = File.expand_path(File.dirname(__FILE__))+"/../lib/phantom_proxy/config.ru" -end + Goliath.env = PhantomProxy.env if PhantomProxy.respond_to?(:env) -require 'phantom_proxy' + runner.api = PhantomProxy::Service.new + runner.app = Goliath::Rack::Builder.build(PhantomProxy::Service, runner.api) -# Become a daemon -options = { - :app_name => "phantom_proxy", - :backtrace => true, - :ontop => true, - :log_output => true -} -#Daemons.daemonize(options) - -PARAMETERS = Array.new - -hmac_key = nil -phantom = false -last_arg = nil -ARGV.each { |arg| - if !/-hmac/.match(arg) && !/-hmac/.match(last_arg) && !/-self/.match(arg) - PARAMETERS << arg + puts "Now starting PhantomProxy #{PhantomProxy::VERSION}...." + runner.run end - phantom = true if /-self/.match(arg) - hmac_key = arg if /-hmac/.match(last_arg) - last_arg = arg -} - -if hmac_key - if !File.directory?("/tmp/phantom_proxy") - Dir.mkdir("/tmp/phantom_proxy") - end - - File.open("/tmp/phantom_proxy/key", 'w+') {|f| f.write(hmac_key) } -else - begin - File.delete("/tmp/phantom_proxy/key") - rescue - end end -if !phantom - startoptions = ["start", "-R", PhantomJSProxy::CONFIG, "-P", "/tmp/pids/phantom_proxy.pid", "--tag", "phantom_proxy"]+PARAMETERS - runner = Thin::Runner.new(startoptions).run! -else - Thin::Server.start(PhantomJSProxy::PhantomJSServer.new, ARGV[0], ARGV[1], ARGV[2]) -end +PhantomProxy.run_phantom_proxy PhantomProxy.load_config \ No newline at end of file