autosel_http_proxy 0.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.
- data/ChangeLog +0 -0
- data/README.rdoc +0 -0
- data/bin/set_httpproxy +12 -0
- data/lib/autosel_http_proxy.rb +99 -0
- metadata +59 -0
data/ChangeLog
ADDED
File without changes
|
data/README.rdoc
ADDED
File without changes
|
data/bin/set_httpproxy
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'resolv'
|
3
|
+
|
4
|
+
module AutoselHttpProxy
|
5
|
+
PROXY_CONFFILE = File.expand_path '~/.autosel_http_proxy.conf'
|
6
|
+
|
7
|
+
class ConfigNotFound < RuntimeError; end
|
8
|
+
class ConfigNotConfigured < RuntimeError; end
|
9
|
+
class NeedHostname < RuntimeError; end
|
10
|
+
|
11
|
+
class Setting
|
12
|
+
@@proxy_url = nil
|
13
|
+
@@proxy_setting = nil
|
14
|
+
def self.proxy_url() @@proxy_url end
|
15
|
+
def self.proxy_setting() @@proxy_setting end
|
16
|
+
|
17
|
+
def self.hostname_found?(hostname)
|
18
|
+
begin
|
19
|
+
Resolv.getaddress(hostname)
|
20
|
+
true
|
21
|
+
rescue
|
22
|
+
false
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.init_proxy_setting(list)
|
27
|
+
list.each{|a|
|
28
|
+
return @@proxy_setting = a if eval a[:if]
|
29
|
+
}
|
30
|
+
@@proxy_setting = nil
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.set_proxy_env!
|
34
|
+
return nil unless proxy_setting
|
35
|
+
unless proxy_setting[:proxy_host]
|
36
|
+
puts "*** Need \":proxy_host\" in \"#{PROXY_CONFFILE}\"."
|
37
|
+
raise NeedHostname
|
38
|
+
end
|
39
|
+
|
40
|
+
url = "http://"
|
41
|
+
if proxy_setting[:proxy_user] and proxy_setting[:proxy_pass]
|
42
|
+
url += "#{proxy_setting[:proxy_user]}:#{proxy_setting[:proxy_pass]}@"
|
43
|
+
end
|
44
|
+
url += proxy_setting[:proxy_host] if proxy_setting[:proxy_host]
|
45
|
+
url += ":" + proxy_setting[:proxy_port] if proxy_setting[:proxy_port]
|
46
|
+
|
47
|
+
ENV['http_proxy'] = url
|
48
|
+
ENV['https_proxy'] = url
|
49
|
+
ENV['ftp_proxy'] = url
|
50
|
+
@@proxy_url = url
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.create_conf(filename)
|
54
|
+
File.open(filename, 'w', 0600) {|io|
|
55
|
+
io.puts <<EOF
|
56
|
+
PROXY_LIST =
|
57
|
+
[{:if => 'hostname_found? "hostname.example.com"',
|
58
|
+
:proxy_host => 'proxy.example.com',
|
59
|
+
:proxy_port => '8080',
|
60
|
+
:proxy_user => nil,
|
61
|
+
:proxy_pass => nil,},]
|
62
|
+
EOF
|
63
|
+
}
|
64
|
+
end
|
65
|
+
|
66
|
+
def self.load_conf(filename)
|
67
|
+
unless File.exist?(filename)
|
68
|
+
puts "*** \"#{filename}\" created."
|
69
|
+
puts "*** Please config it."
|
70
|
+
create_conf filename
|
71
|
+
raise ConfigNotFound
|
72
|
+
end
|
73
|
+
|
74
|
+
load filename
|
75
|
+
|
76
|
+
if PROXY_LIST[0][:if] ==
|
77
|
+
'hostname_found? "hostname.example.com"'
|
78
|
+
puts "*** \"#{filename}\" isn't configured."
|
79
|
+
puts "*** Please config it."
|
80
|
+
raise ConfigNotConfigured
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def self.init
|
85
|
+
load_conf PROXY_CONFFILE
|
86
|
+
init_proxy_setting PROXY_LIST
|
87
|
+
set_proxy_env!
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
class << self
|
92
|
+
def url() Setting.proxy_url end
|
93
|
+
def setting() Setting.proxy_setting end
|
94
|
+
end
|
95
|
+
|
96
|
+
|
97
|
+
### start
|
98
|
+
Setting.init
|
99
|
+
end
|
metadata
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: autosel_http_proxy
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kiwamu Okabe
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2010-01-22 00:00:00 +09:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Auto select http_proxy setting with a config file
|
17
|
+
email: kiwamu@debian.or.jp
|
18
|
+
executables:
|
19
|
+
- set_httpproxy
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README.rdoc
|
24
|
+
files:
|
25
|
+
- lib/autosel_http_proxy.rb
|
26
|
+
- bin/set_httpproxy
|
27
|
+
- README.rdoc
|
28
|
+
- ChangeLog
|
29
|
+
has_rdoc: true
|
30
|
+
homepage: http://d.masterq.net/
|
31
|
+
licenses: []
|
32
|
+
|
33
|
+
post_install_message:
|
34
|
+
rdoc_options:
|
35
|
+
- --main
|
36
|
+
- README.rdoc
|
37
|
+
require_paths:
|
38
|
+
- lib
|
39
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: "0"
|
44
|
+
version:
|
45
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: "0"
|
50
|
+
version:
|
51
|
+
requirements: []
|
52
|
+
|
53
|
+
rubyforge_project:
|
54
|
+
rubygems_version: 1.3.5
|
55
|
+
signing_key:
|
56
|
+
specification_version: 3
|
57
|
+
summary: Auto select http_proxy setting with a config file
|
58
|
+
test_files: []
|
59
|
+
|