autosel_http_proxy 0.0.1 → 0.0.4
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 +5 -0
- data/README.ja.rdoc +116 -0
- data/README.rdoc +27 -0
- data/bin/set_httpproxy +20 -7
- data/lib/autosel_http_proxy.rb +2 -4
- metadata +6 -2
data/ChangeLog
CHANGED
data/README.ja.rdoc
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
= AutoselHttpProxy
|
2
|
+
|
3
|
+
AutoselHttpProxyは設定ファイルを元にして、HTTP proxyを自動的に設定するユーティリティです。
|
4
|
+
設定ファイルを作成した後以下のようにすると、"http_proxy"などの環境変数を設定した状態で任意のコマンドを起動できます。
|
5
|
+
|
6
|
+
$ set_httpproxy 任意のコマンド
|
7
|
+
|
8
|
+
また、rubyのプログラムならば以下のようにすれば、HTTP proxyの設定を検出できます。
|
9
|
+
|
10
|
+
require 'autosel_http_proxy'
|
11
|
+
AutoselHttpProxy::init
|
12
|
+
if AutoselHttpProxy::setting
|
13
|
+
p AutoselHttpProxy::setting[:proxy_host] # => proxyホスト名
|
14
|
+
p AutoselHttpProxy::setting[:proxy_port] # => proxyポート番号
|
15
|
+
p AutoselHttpProxy::setting[:proxy_user] # => proxy認証ユーザ名
|
16
|
+
p AutoselHttpProxy::setting[:proxy_pass] # => proxy認証パスワード
|
17
|
+
end
|
18
|
+
|
19
|
+
ノートPCのようにネットワーク環境が頻繁に変更される場合に、本プログラムを使うことでHTTP proxy設定変更の手間が軽減されます。
|
20
|
+
|
21
|
+
== インストール
|
22
|
+
|
23
|
+
gem install autosel_http_proxyでインストールされます。
|
24
|
+
インストール先のbinディレクトリにPATHを通してください。
|
25
|
+
|
26
|
+
$ export PATH = /var/lib/gems/1.8/bin:$PATH
|
27
|
+
|
28
|
+
== 設定ファイルの作成
|
29
|
+
|
30
|
+
まずはset_httpproxyコマンドを実行すると、設定ファイルのテンプレートが自動生成されます。
|
31
|
+
|
32
|
+
$ set_httpproxy
|
33
|
+
*** "/home/kiwamu/.autosel_http_proxy.conf" created.
|
34
|
+
*** Please config it.
|
35
|
+
|
36
|
+
この設定ファイルを編集します。
|
37
|
+
|
38
|
+
$ cat ~/.autosel_http_proxy.conf
|
39
|
+
PROXY_LIST =
|
40
|
+
[{:if => 'hostname_found? "hostname.example.com"',
|
41
|
+
:proxy_host => 'proxy.example.com',
|
42
|
+
:proxy_port => '8080',
|
43
|
+
:proxy_user => nil,
|
44
|
+
:proxy_pass => nil,},]
|
45
|
+
|
46
|
+
PROXY_LISTは配列になっているので、複数のHTTP proxy設定を列挙することができます。
|
47
|
+
|
48
|
+
=== :if欄
|
49
|
+
|
50
|
+
以下に挙げるHTTP proxyの設定を有効にする条件を設定します。
|
51
|
+
|
52
|
+
:if => 'hostname_found? "hogehoge.hogehoge.com"
|
53
|
+
|
54
|
+
という設定にすると、hogehoge.hogehoge.comをDNSから引き、見つかれば:proxy_*欄に記載したHTTP proxyの設定を有効にします。
|
55
|
+
|
56
|
+
=== :proxy_host欄
|
57
|
+
|
58
|
+
:if欄が真の場合に設定するHTTP proxyのホスト名。
|
59
|
+
|
60
|
+
=== :proxy_port欄
|
61
|
+
|
62
|
+
:if欄が真の場合に設定するHTTP proxyのポート番号。
|
63
|
+
|
64
|
+
=== :proxy_user欄
|
65
|
+
|
66
|
+
:if欄が真の場合に設定するHTTP proxyの認証ユーザ名。HTTP proxy認証が不要な場合にはnilのままでOKです。
|
67
|
+
|
68
|
+
=== :proxy_pass欄
|
69
|
+
|
70
|
+
:if欄が真の場合に設定するHTTP proxyの認証パスワード。HTTP proxy認証が不要な場合にはnilのままでOKです。
|
71
|
+
|
72
|
+
== 使い方
|
73
|
+
|
74
|
+
=== 任意のコマンドをhttp_proxy環境変数付きで起動させる
|
75
|
+
|
76
|
+
設定ファイルが適切に設定されていれば、コマンドの前にset_httpproxyを付けることで、http_proxy環境変数が自動的に設定された状態でコマンドが起動されます。wgetを例にすると以下のようになります。
|
77
|
+
|
78
|
+
$ set_httpproxy wget http://example.com/img/example.jpg
|
79
|
+
|
80
|
+
このようにhttp_proxy環境変数を参照するようなコマンドは何でも上記の方法でHTTP proxy自動設定することができます。例えば以下のコマンド達はhttp_proxy環境変数を見ています。
|
81
|
+
|
82
|
+
* apt-get
|
83
|
+
* aptitude
|
84
|
+
* gem
|
85
|
+
* minitube
|
86
|
+
* w3m
|
87
|
+
* wget
|
88
|
+
|
89
|
+
SHELLの設定ファイルに、aliasを作っておくと楽かもしれません。
|
90
|
+
|
91
|
+
=== rubyアプリケーションに組込む
|
92
|
+
|
93
|
+
例として{termtter}[http://termtter.org/]にHTTP proxy自動設定させる手順を解説します。
|
94
|
+
まず、set_httpproxyが正常に動作するまで設定ファイルを作成しておきます。その後、~/.termtter/configファイルに以下を追記します。
|
95
|
+
|
96
|
+
require 'autosel_http_proxy'
|
97
|
+
AutoselHttpProxy::init
|
98
|
+
if AutoselHttpProxy::setting
|
99
|
+
config.proxy.host = AutoselHttpProxy::setting[:proxy_host]
|
100
|
+
config.proxy.port = AutoselHttpProxy::setting[:proxy_port]
|
101
|
+
config.proxy.user_name = AutoselHttpProxy::setting[:proxy_user]
|
102
|
+
config.proxy.password = AutoselHttpProxy::setting[:proxy_pass]
|
103
|
+
end
|
104
|
+
|
105
|
+
この設定を施すことで、termtterを起動するたびにその時のネットワーク状態から適切なHTTP proxy設定を自動的に検出するようになります。
|
106
|
+
|
107
|
+
== エラーについて
|
108
|
+
|
109
|
+
プログラム内部では、設定ファイルはrubyスクリプトとしてそのまま解釈実行されます。そのため、設定ファイルにruby文法エラーがあった場合にはAutoselHttpProxyは異常終了してしまいます。注意してください。
|
110
|
+
もし、エラーから復帰できないときは設定ファイルを一度消して、set_httpproxyコマンドで自動生成しなおすのも一案です。
|
111
|
+
|
112
|
+
== リンク
|
113
|
+
|
114
|
+
* {プロジェクトサイト}[http://gitorious.org/autosel_http_proxy]
|
115
|
+
* {Gem}[http://gemcutter.org/gems/autosel_http_proxy]
|
116
|
+
* {Twitter}[http://twitter.com/master_q]
|
data/README.rdoc
CHANGED
@@ -0,0 +1,27 @@
|
|
1
|
+
= AutoselHttpProxy
|
2
|
+
|
3
|
+
AutoselHttpProxy sets HTTP proxy settings automatically with a startup file.
|
4
|
+
AutoselHttpProxy allows to execute a COMMAND with "http_proxy" environment variable.
|
5
|
+
|
6
|
+
$ set_httpproxy COMMAND
|
7
|
+
|
8
|
+
If you use ruby's program, then can use the below code, to set HTTP proxy settings.
|
9
|
+
|
10
|
+
require 'autosel_http_proxy'
|
11
|
+
AutoselHttpProxy::init
|
12
|
+
if AutoselHttpProxy::setting
|
13
|
+
p AutoselHttpProxy::setting[:proxy_host] # => proxy hostname
|
14
|
+
p AutoselHttpProxy::setting[:proxy_port] # => proxy port number
|
15
|
+
p AutoselHttpProxy::setting[:proxy_user] # => proxy username
|
16
|
+
p AutoselHttpProxy::setting[:proxy_pass] # => proxy password
|
17
|
+
end
|
18
|
+
|
19
|
+
== Usage and Detail
|
20
|
+
|
21
|
+
Please read README.ja.rdoc file (in Japanese)...
|
22
|
+
|
23
|
+
== Links
|
24
|
+
|
25
|
+
* {Project page}[http://gitorious.org/autosel_http_proxy]
|
26
|
+
* {Gem}[http://gemcutter.org/gems/autosel_http_proxy]
|
27
|
+
* {Twitter}[http://twitter.com/master_q]
|
data/bin/set_httpproxy
CHANGED
@@ -1,12 +1,25 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# -*- coding: utf-8 -*-
|
3
3
|
|
4
|
-
|
4
|
+
self_file =
|
5
|
+
if File.symlink?(__FILE__)
|
6
|
+
require 'pathname'
|
7
|
+
Pathname.new(__FILE__).realpath
|
8
|
+
else
|
9
|
+
__FILE__
|
10
|
+
end
|
11
|
+
$:.unshift(File.dirname(self_file) + "/../lib")
|
5
12
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
13
|
+
begin
|
14
|
+
require 'autosel_http_proxy'
|
15
|
+
AutoselHttpProxy::init
|
16
|
+
ensure
|
17
|
+
### main
|
18
|
+
if ARGV.size == 0
|
19
|
+
puts "Usage: " + File.basename($PROGRAM_NAME) + " COMMAND"
|
20
|
+
puts "Version: " + AutoselHttpProxy::VERSION
|
21
|
+
exit 1
|
22
|
+
end
|
11
23
|
|
12
|
-
system *ARGV
|
24
|
+
system *ARGV
|
25
|
+
end
|
data/lib/autosel_http_proxy.rb
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
require 'resolv'
|
3
3
|
|
4
4
|
module AutoselHttpProxy
|
5
|
+
VERSION = '0.0.4'
|
5
6
|
PROXY_CONFFILE = File.expand_path '~/.autosel_http_proxy.conf'
|
6
7
|
|
7
8
|
class ConfigNotFound < RuntimeError; end
|
@@ -91,9 +92,6 @@ EOF
|
|
91
92
|
class << self
|
92
93
|
def url() Setting.proxy_url end
|
93
94
|
def setting() Setting.proxy_setting end
|
95
|
+
def init() Setting.init end
|
94
96
|
end
|
95
|
-
|
96
|
-
|
97
|
-
### start
|
98
|
-
Setting.init
|
99
97
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: autosel_http_proxy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kiwamu Okabe
|
@@ -21,19 +21,23 @@ extensions: []
|
|
21
21
|
|
22
22
|
extra_rdoc_files:
|
23
23
|
- README.rdoc
|
24
|
+
- README.ja.rdoc
|
24
25
|
files:
|
25
26
|
- lib/autosel_http_proxy.rb
|
26
27
|
- bin/set_httpproxy
|
27
28
|
- README.rdoc
|
29
|
+
- README.ja.rdoc
|
28
30
|
- ChangeLog
|
29
31
|
has_rdoc: true
|
30
|
-
homepage: http://
|
32
|
+
homepage: http://gitorious.org/autosel_http_proxy
|
31
33
|
licenses: []
|
32
34
|
|
33
35
|
post_install_message:
|
34
36
|
rdoc_options:
|
35
37
|
- --main
|
36
38
|
- README.rdoc
|
39
|
+
- --charset
|
40
|
+
- UTF-8
|
37
41
|
require_paths:
|
38
42
|
- lib
|
39
43
|
required_ruby_version: !ruby/object:Gem::Requirement
|