titech-pubnet-auth 1.1.1 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8e611fb6cd90163e6460a3f576118d9b3d479bba
4
+ data.tar.gz: 686255d23b172c56253798ed5ad15cb362ce5591
5
+ SHA512:
6
+ metadata.gz: 1e27367ad4f8a43b46e16366812962daadba3f811b01631023fd9d311da27ccc194bd104fa35ae3e0a59a37b41b8d5835dda0e2685ae2506a927f425e4788dab
7
+ data.tar.gz: 90fc94968d4aa64d993828be20f8c63ab5bfe25eaddf3fd2ad2c178854b26d6b044604cf8618faca4979af06b563771ef171a98027b50ff55571bc6e973a4dac
data/README.md CHANGED
@@ -26,6 +26,7 @@ titech-pubnet に接続すると自動で認証が行われる(デスクトッ
26
26
  gem のインストール [^1]
27
27
 
28
28
  $ gem install titech-pubnet-auth
29
+ $ gem install titech-pubnet-auth -r -p http://131.112.125.238:3128 # titech-pubnetでインストールするなら
29
30
 
30
31
  最初に、ユーザー名、パスワードを設定
31
32
 
@@ -7,7 +7,7 @@ require 'optparse'
7
7
 
8
8
  opt = OptionParser.new
9
9
 
10
- interval = 2
10
+ interval = 3
11
11
  opt.on('-i','--interval=SECONDS',"Specify the polling interval.[#{interval}]"){|v|
12
12
  interval = v.to_i
13
13
  }
@@ -45,7 +45,7 @@ if configure
45
45
  'username' => username,
46
46
  'password' => password
47
47
  }
48
- f = File::open(File.expand_path('../config/private.yml', File.dirname(__FILE__)),'w'){|f|
48
+ File::open(File.expand_path('../config/private.yml', File.dirname(__FILE__)),'w'){|f|
49
49
  f << conf.to_yaml
50
50
  }
51
51
  puts 'configured!'
@@ -61,15 +61,13 @@ end
61
61
  include TitechPubnetAuth::BinRoutines
62
62
 
63
63
  pubnet_auth = TitechPubnetAuth.new
64
- retry_count = 0
65
64
  loop do |t|
66
65
  begin
67
66
  if mputs 'network_available?', pubnet_auth.network_available?
68
67
  if not mputs 'is_connected?', pubnet_auth.is_connected?
69
68
  if mputs 'auth', pubnet_auth.auth
70
69
  notifier
71
- retry_count = 0
72
- pubnet_auth = TitechPubnetAuth.new(open_timeout: 3)
70
+ pubnet_auth = TitechPubnetAuth.new(open_timeout: 5)
73
71
  end
74
72
  end
75
73
  end
@@ -82,11 +80,9 @@ loop do |t|
82
80
  error_notifier(e) if debug
83
81
 
84
82
  pubnet_auth = TitechPubnetAuth.new(open_timeout: 10)
85
- retry_count += 1
86
83
  ensure
87
- print "\n"
88
- $stdout.flush
89
- sleep interval unless retry_count == 1
84
+ print "\n"; $stdout.flush
85
+ sleep interval
90
86
  end
91
87
  break if single
92
88
  end
@@ -4,33 +4,30 @@ require 'mechanize'
4
4
  require 'uri'
5
5
  require 'yaml'
6
6
 
7
- $:.unshift File.dirname(__FILE__)
7
+ $:.unshift(__dir__ || File.dirname(__FILE__))
8
8
  require 'titech_pubnet_auth/bin_routines'
9
9
  require 'titech_pubnet_auth/extensions'
10
10
 
11
11
 
12
12
  class TitechPubnetAuth
13
- BASE_DIR = File.expand_path('..',File.dirname(__FILE__))
14
-
15
- SAMPLE_URI = ->{%w[www.google.com twitter.com www.facebook.com mixi.jp www.amazon.co.jp www.wikipedia.org www.fc2.com www.yahoo.co.jp www.kakaku.com].map{|uri| URI.parse("http://#{uri}")}[rand(3)]}
16
-
13
+ SAMPLE_URI = URI "http://example.org"
17
14
  HTTP_PROXY = {ip: '131.112.125.238', port: 3128}
18
15
 
19
- def initialize(opt = {open_timeout: 3})
16
+ def initialize(opt = {open_timeout: 5})
20
17
  @agent, @agent_with_proxy = Mechanize.new, Mechanize.new
21
- [@agent,@agent_with_proxy].each{|agent|
18
+ [@agent, @agent_with_proxy].each{|agent|
22
19
  agent.follow_meta_refresh = true
23
20
  agent.open_timeout = opt[:open_timeout]
24
21
  }
25
22
  @agent_with_proxy.set_proxy(HTTP_PROXY[:ip], HTTP_PROXY[:port])
26
23
 
27
- @private = YAML.load(File::open(File::expand_path('config/private.yml',BASE_DIR),'r'))
24
+ @private = YAML.load_file((__dir__ || File.dirname(__FILE__)) + '/../config/private.yml')
28
25
  end
29
26
 
30
27
  #
31
28
  # called if network_available? and not is_connected?
32
29
  #
33
- def auth(sample_uri = SAMPLE_URI.call)
30
+ def auth(sample_uri = SAMPLE_URI)
34
31
  auth_page = @agent.get(sample_uri)
35
32
  return false if auth_page.uri.hostname != 'wlanauth.noc.titech.ac.jp'
36
33
 
@@ -43,23 +40,29 @@ class TitechPubnetAuth
43
40
 
44
41
  return is_connected?
45
42
  end
46
-
43
+
47
44
  #
48
45
  # called if network_available?
49
46
  #
50
- def is_connected?(sample_uri = SAMPLE_URI.call)
51
- @agent_with_proxy.get(sample_uri).uri.hostname == sample_uri.hostname
47
+ def is_connected?(sample_uri = SAMPLE_URI)
48
+ compare_uri_by_first_part sample_uri, @agent_with_proxy.get(sample_uri).uri
52
49
  rescue # retry without the proxy
53
- @agent.get(sample_uri).uri.hostname == sample_uri.hostname
50
+ compare_uri_by_first_part sample_uri, @agent.get(sample_uri).uri
54
51
  end
55
52
 
56
53
  #
57
54
  # note: titech-pubnet allows to access portal.titech.ac.jp without authentication.
58
55
  #
59
- def network_available?(sample_uri = SAMPLE_URI.call)
56
+ def network_available?(sample_uri = SAMPLE_URI)
60
57
  @agent.get('http://portal.titech.ac.jp').to_b
61
58
  rescue # check another website just to make sure
62
59
  @agent.get(sample_uri).to_b rescue return false
63
60
  end
64
61
 
62
+ private
63
+
64
+ def compare_uri_by_first_part uri1, uri2
65
+ uri1.hostname.split(".").first == uri2.hostname.split(".").first
66
+ end
67
+
65
68
  end
@@ -8,11 +8,11 @@ class TitechPubnetAuth
8
8
  require 'terminal-notifier'
9
9
 
10
10
  def notifier
11
- TerminalNotifier.notify(nil,:title => 'Titech Punet Auth', :subtitle => 'Connected!')
11
+ TerminalNotifier.notify(nil,:title => 'Titech Pubnet Auth', :subtitle => 'Connected!')
12
12
  end
13
13
 
14
14
  def error_notifier(e)
15
- TerminalNotifier.notify(e.inspect,:title => 'Titech Punet Auth',:subtitle => 'Caught an unexpected error!')
15
+ TerminalNotifier.notify(e.inspect,:title => 'Titech Pubnet Auth',:subtitle => 'Caught an unexpected error!')
16
16
  end
17
17
 
18
18
  else
@@ -1,3 +1,3 @@
1
1
  class TitechPubnetAuth
2
- VERSION = '1.1.1'
2
+ VERSION = '1.2.0'
3
3
  end
@@ -18,7 +18,7 @@ Gem::Specification.new do |gem|
18
18
  gem.version = TitechPubnetAuth::VERSION
19
19
 
20
20
  gem.add_dependency 'colorize'
21
- gem.add_dependency 'mechanize', '~> 2.5'
21
+ gem.add_dependency 'mechanize', '~> 2.7'
22
22
  gem.add_dependency 'terminal-notifier', '~> 1.4'
23
23
 
24
24
  end
metadata CHANGED
@@ -1,52 +1,46 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: titech-pubnet-auth
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
5
- prerelease:
4
+ version: 1.2.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Sohei Takeno
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-05-24 00:00:00.000000000 Z
11
+ date: 2013-07-28 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: colorize
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - '>='
28
25
  - !ruby/object:Gem::Version
29
26
  version: '0'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: mechanize
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
31
  - - ~>
36
32
  - !ruby/object:Gem::Version
37
- version: '2.5'
33
+ version: '2.7'
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
38
  - - ~>
44
39
  - !ruby/object:Gem::Version
45
- version: '2.5'
40
+ version: '2.7'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: terminal-notifier
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
45
  - - ~>
52
46
  - !ruby/object:Gem::Version
@@ -54,7 +48,6 @@ dependencies:
54
48
  type: :runtime
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
52
  - - ~>
60
53
  - !ruby/object:Gem::Version
@@ -68,10 +61,10 @@ executables:
68
61
  extensions: []
69
62
  extra_rdoc_files: []
70
63
  files:
64
+ - lib/titech_pubnet_auth.rb
71
65
  - lib/titech_pubnet_auth/bin_routines.rb
72
66
  - lib/titech_pubnet_auth/extensions.rb
73
67
  - lib/titech_pubnet_auth/version.rb
74
- - lib/titech_pubnet_auth.rb
75
68
  - bin/titech-pubnet-auth
76
69
  - bin/titech-pubnet-auth-daemon
77
70
  - config/private.yml.example
@@ -81,27 +74,26 @@ files:
81
74
  - titech_pubnet_auth.gemspec
82
75
  homepage: http://for-titech.herokuapp.com
83
76
  licenses: []
77
+ metadata: {}
84
78
  post_install_message:
85
79
  rdoc_options: []
86
80
  require_paths:
87
81
  - lib
88
82
  required_ruby_version: !ruby/object:Gem::Requirement
89
- none: false
90
83
  requirements:
91
- - - ! '>='
84
+ - - '>='
92
85
  - !ruby/object:Gem::Version
93
86
  version: '0'
94
87
  required_rubygems_version: !ruby/object:Gem::Requirement
95
- none: false
96
88
  requirements:
97
- - - ! '>='
89
+ - - '>='
98
90
  - !ruby/object:Gem::Version
99
91
  version: '0'
100
92
  requirements: []
101
93
  rubyforge_project:
102
- rubygems_version: 1.8.25
94
+ rubygems_version: 2.0.3
103
95
  signing_key:
104
- specification_version: 3
96
+ specification_version: 4
105
97
  summary: This gem provides automatic authentication for titech-pubnet.
106
98
  test_files: []
107
99
  has_rdoc: