Skip to content

Instantly share code, notes, and snippets.

@elia
Created March 16, 2009 16:18
Show Gist options
  • Save elia/79948 to your computer and use it in GitHub Desktop.
Save elia/79948 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'webrick/httpproxy'
require 'webrick/httpauth/digestauth'
require 'webrick/httpauth/userdb'
def ask question
STDOUT.print question
STDOUT.flush
gets.chomp
end
class Authoxy
def initialize local_port, upstream_proxy, user, password
proxy_uri = URI::parse(upstream_proxy) # es: 'http://myproxy.com:8080'
proxy_uri.user = user
proxy_uri.password = password
# Set up the proxy itself
@server = WEBrick::HTTPProxyServer.new(
:LogFile => $stdout,
:Port => local_port.to_i,
:ProxyVia => true,
:ProxyURI => proxy_uri
)
end
def start
@thread = Thread.new do
@server.start
end
end
def stop
@server.shutdown
end
end
trap("INT") {
@server_vimodrone.stop
@server_francia.stop
exit
}
@server = Authoxy.new 8079, 'http://172.24.1.50:8080', 'elia.schito', ask('password: ')
@server.start
sleep
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment