titech-pubnet-auth 0.2.1 → 0.2.2

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.
@@ -68,7 +68,7 @@ pubnet_auth = TitechPubnetAuth.new
68
68
  retry_count = 0
69
69
  loop do |t|
70
70
  begin
71
- if mputs 'network_available?', pubnet_auth.network_available? and
71
+ if mputs 'network_available?', pubnet_auth.network_available?
72
72
  if not mputs 'is_connected?', pubnet_auth.is_connected?
73
73
  if mputs 'auth', pubnet_auth.auth
74
74
  notifier.call
@@ -1,3 +1,3 @@
1
1
  class TitechPubnetAuth
2
- VERSION = '0.2.1'
2
+ VERSION = '0.2.2'
3
3
  end
@@ -26,10 +26,10 @@ class TitechPubnetAuth
26
26
  @private = YAML.load(File::open(File::expand_path('config/private.yml',BASE_DIR),'r'))
27
27
  end
28
28
 
29
+ #
30
+ # called if network_available? and not is_connected?
31
+ #
29
32
  def auth(sample_uri = SAMPLE_URI.call)
30
- return false if not network_available?
31
- return true if is_connected?
32
-
33
33
  auth_page = @agent.get(sample_uri)
34
34
  return false if auth_page.uri.hostname != 'wlanauth.noc.titech.ac.jp'
35
35
 
@@ -43,12 +43,18 @@ class TitechPubnetAuth
43
43
  return is_connected?
44
44
  end
45
45
 
46
+ #
47
+ # called if network_available?
48
+ #
46
49
  def is_connected?(sample_uri = SAMPLE_URI.call)
47
50
  return @agent_with_proxy.get(sample_uri).uri.hostname == sample_uri.hostname
48
51
  rescue # retry without the proxy
49
52
  return @agent.get(sample_uri).uri.hostname == sample_uri.hostname
50
53
  end
51
-
54
+
55
+ #
56
+ # note: titech-pubnet allows to access portal.titech.ac.jp without authentication.
57
+ #
52
58
  def network_available?
53
59
  @agent.get('http://portal.titech.ac.jp')
54
60
  return true
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: titech-pubnet-auth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-15 00:00:00.000000000 Z
12
+ date: 2012-11-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: colorize
@@ -71,7 +71,6 @@ files:
71
71
  - lib/titech_pubnet_auth/extension.rb
72
72
  - lib/titech_pubnet_auth/version.rb
73
73
  - lib/titech_pubnet_auth.rb
74
- - lib/titech_pubnet_auth.rb.back
75
74
  - bin/titech-pubnet-auth
76
75
  - bin/titech-pubnet-auth-daemon
77
76
  - config/private.yml.example
@@ -1,59 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
-
3
- require 'mechanize'
4
- require 'uri'
5
- require 'yaml'
6
-
7
- $:.unshift File.dirname(__FILE__)
8
- require 'titech_pubnet_auth/extension'
9
-
10
-
11
- class TitechPubnetAuth
12
- BASE_DIR = File.expand_path('..',File.dirname(__FILE__))
13
-
14
- SAMPLE_URI = ->{%w[www.titech.ac.jp github.com twitter.com].map{|uri| URI.parse("http://#{uri}")}[rand(3)]}
15
-
16
- HTTP_PROXY = {ip: '131.112.125.238', port: 3128}
17
-
18
- def initialize(opt = {open_timeout: 3})
19
- @agent, @agent_with_proxy = Mechanize.new, Mechanize.new
20
- [@agent,@agent_with_proxy].each{|agent|
21
- agent.follow_meta_refresh = true
22
- agent.open_timeout = opt[:open_timeout]
23
- }
24
- @agent_with_proxy.set_proxy(HTTP_PROXY[:ip], HTTP_PROXY[:port])
25
-
26
- @private = YAML.load(File::open(File::expand_path('config/private.yml',BASE_DIR),'r'))
27
- end
28
-
29
- def auth(sample_uri = SAMPLE_URI.call)
30
- return false if not network_available?
31
- return true if is_connected?
32
-
33
- auth_page = @agent.get(sample_uri)
34
- return false if auth_page.uri.hostname != 'wlanauth.noc.titech.ac.jp'
35
-
36
- auth_page.form do |form|
37
- form.buttonClicked = 4
38
- form.redirect_url = sample_uri
39
- form.username = @private['username']
40
- form.password = @private['password']
41
- end.submit
42
-
43
- return is_connected?
44
- end
45
-
46
- def is_connected?(sample_uri = SAMPLE_URI.call)
47
- return @agent_with_proxy.get(sample_uri).uri.hostname == sample_uri.hostname
48
- rescue # retry without the proxy
49
- return @agent.get(sample_uri).uri.hostname == sample_uri.hostname
50
- end
51
-
52
- def network_available?
53
- @agent.get('http://portal.titech.ac.jp')
54
- return true
55
- rescue => e
56
- return false
57
- end
58
-
59
- end