Skip to content

Instantly share code, notes, and snippets.

@dimacus
Created June 11, 2013 14:59
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dimacus/5757573 to your computer and use it in GitHub Desktop.
Save dimacus/5757573 to your computer and use it in GitHub Desktop.
Blackhole proxy to block all external calls. Add following configs to your browser creation profile["network.proxy.type"] = 1 profile["network.proxy.http"] = "localhost" profile["network.proxy.http_port"] = 9001 no_proxy_list = "localhost, 127.0.0.1" no_proxy_list += ", #{ENV['PROXY_SERVER_WHITELIST']}" if ENV['PROXY_SERVER_WHITELIST'] profile["…
require 'rubygems'
require 'em-proxy'
require 'http_parser.rb'
require 'uuid'
require 'uri'
PROXY_SERVER_HOST = "127.0.0.1"
PROXY_SERVER_PORT = ENV['PROXY_SERVER_PORT'] || 9001
output = "tmp/blocked_external_urls.log"
puts "Starting server #{PROXY_SERVER_HOST}:#{PROXY_SERVER_PORT}"
Proxy.start(:host => PROXY_SERVER_HOST, :port => PROXY_SERVER_PORT) do |conn|
@p = Http::Parser.new
@p.on_headers_complete = proc do |h|
session = UUID.generate
@request_host, request_port = h['Host'].split(':')
File.open(output, 'a') {|f| f.write("#{@request_host}\n")}
@request_host = "127.0.0.1"
conn.server session, :host => @request_host, :port => (request_port || 80)
conn.relay_to_servers @buffer
@buffer = ''
end
@buffer = ''
conn.on_connect do |data,b|
end
conn.on_data do |data|
@buffer << data
@p << data
data
end
conn.on_response do |backend, resp|
resp
end
conn.on_finish do |backend, name|
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment