elia-ruby-authoxy 1.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubygems'
3
+ require 'authoxy'
4
+
5
+ default_path = File.expand_path('~/.authoxy.yml')
6
+ path = (ARGV.first and File.exist?(ARGV.first)) ? ARGV.first : nil
7
+ path ||= default_path if File.exist?(default_path)
8
+
9
+ if path
10
+ Authoxy.load path
11
+ else
12
+ puts "Usage: #{$0} <file-path> # <file-path> is the path of the YML configuration"
13
+ puts "Usage: #{$0} # If no path is provided Authoxy will look in #{default_path}"
14
+ exit 1
15
+ end
@@ -0,0 +1,11 @@
1
+ laben:
2
+ local_port: 8079
3
+ upstream_proxy: http://172.24.1.50:8080
4
+ password:
5
+ user:
6
+
7
+ thales:
8
+ local_port: 8081
9
+ upstream_proxy: http://localhost:8079
10
+ password:
11
+ user:
@@ -0,0 +1,81 @@
1
+ #!/usr/bin/env ruby
2
+ require 'webrick/httpproxy'
3
+ require 'webrick/httpauth/digestauth'
4
+ require 'webrick/httpauth/userdb'
5
+ require 'yaml'
6
+ require 'pp'
7
+
8
+ def ask question
9
+ STDOUT.print question
10
+ STDOUT.flush
11
+ gets.chomp
12
+ end
13
+
14
+ class Authoxy
15
+ attr_reader :name
16
+
17
+ # Prepares a new Authoxy:
18
+ #
19
+ # <code> my_proxy = Authoxy.new 'office', 8080, 'http://my.office.proxy.com:8080' </code>
20
+ #
21
+ def initialize name, local_port, upstream_proxy, user, password
22
+ @name = name
23
+ proxy_uri = URI::parse(upstream_proxy)
24
+ proxy_uri.user = user
25
+ proxy_uri.password = password
26
+
27
+ # Set up the proxy itself
28
+ @server = WEBrick::HTTPProxyServer.new(
29
+ :LogFile => false,
30
+ :Port => local_port.to_i,
31
+ :ProxyVia => true,
32
+ :ProxyURI => proxy_uri
33
+ )
34
+ end
35
+
36
+ # Starts the proxy
37
+ def start
38
+ @thread = Thread.new do
39
+ puts "Starting #{name} proxy..."
40
+ @server.start
41
+ end
42
+ end
43
+
44
+ # Stops the proxy
45
+ def stop
46
+ puts "Stopping #{name} proxy..."
47
+ @server.shutdown
48
+ end
49
+
50
+ # Starts Authoxy loading the configuration from a YAML file like this:
51
+ #
52
+ # office_proxy:
53
+ # local_port: 8080
54
+ # upstream_proxy: http://my.office.proxy:8080
55
+ # password: very_secret_word
56
+ # user: elia.schito
57
+ #
58
+ # other_office_proxy:
59
+ # local_port: 8081
60
+ # upstream_proxy: http://other.proxy.com:8080
61
+ # user: elia
62
+ # password: other_very_secret_word
63
+ #
64
+ def self.load path
65
+ proxy_definitions = YAML.load_file(path)
66
+
67
+ @proxies ||= []
68
+ proxy_definitions.each do |(name, proxy)|
69
+ @proxies << Authoxy.new( name, proxy['local_port'].to_i, proxy['upstream_proxy'], proxy['user'], proxy['password'] || ask("password (#{name}): ") )
70
+ end
71
+
72
+ trap('INT') {
73
+ @proxies.each { |proxy| proxy.stop }
74
+ exit
75
+ }
76
+ @proxies.each { |proxy| proxy.start }
77
+ sleep
78
+ end
79
+ end
80
+
81
+ Authoxy.load(File.dirname(__FILE__) + '/authoxy.yml') if $0 == __FILE__
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elia-ruby-authoxy
3
3
  version: !ruby/object:Gem::Version
4
- version: "1.0"
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elia Schito
@@ -9,20 +9,21 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-03-21 00:00:00 -07:00
12
+ date: 2009-03-29 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
16
16
  description: A Ruby version of the popular Authoxy program by Heath Raftery (http://www.hrsoftworks.net/Products.php#authoxy)
17
17
  email: perlelia@gmail.com
18
- executables: []
19
-
18
+ executables:
19
+ - authoxy
20
20
  extensions: []
21
21
 
22
22
  extra_rdoc_files: []
23
23
 
24
24
  files:
25
- - lib/authoxy.rb lib/authoxy.example.yml
25
+ - lib/authoxy.rb
26
+ - lib/authoxy.example.yml
26
27
  has_rdoc: true
27
28
  homepage:
28
29
  post_install_message: