wifi_login 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/.gitignore +17 -0
- data/Gemfile +14 -0
- data/LICENSE.txt +22 -0
- data/README.md +47 -0
- data/Rakefile +9 -0
- data/bin/wifi_login +39 -0
- data/lib/wifi_login/provider.rb +6 -0
- data/lib/wifi_login/providers/docomo.rb +40 -0
- data/lib/wifi_login/version.rb +3 -0
- data/lib/wifi_login.rb +57 -0
- data/spec/spec_helper.rb +12 -0
- data/spec/wifi_login/providers/docomo_spec.rb +24 -0
- data/spec/wifi_login_spec.rb +59 -0
- data/wifi_login.gemspec +24 -0
- metadata +111 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
gem 'mechanize'
|
4
|
+
gem 'pit'
|
5
|
+
gem 'systemu'
|
6
|
+
|
7
|
+
# Add dependencies to develop your gem here.
|
8
|
+
# Include everything needed to run rake, tests, features, etc.
|
9
|
+
group :development do
|
10
|
+
gem "rspec"
|
11
|
+
gem "bundler"
|
12
|
+
end
|
13
|
+
source "http://rubygems.org"
|
14
|
+
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 MATSUOKA Kohei
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# WifiLogin
|
2
|
+
|
3
|
+
An automatically login tool when connected to a public wireless LAN.
|
4
|
+
|
5
|
+
公衆無線LANに自動でログインするためのツールです。
|
6
|
+
現時点では docomo Wi-Fi サービスのみ対応しています。
|
7
|
+
|
8
|
+
Mac OS X 用です。バージョン 10.7.4 でテストしています。
|
9
|
+
docomo Wi-Fi サービスは 802.1X を使うことで自動ログオンが可能ですが、Mac OS X 10.7 (Lion) 以降では標準ツールで 802.1X の設定ができなくなったためこのツールを作りました。
|
10
|
+
|
11
|
+
|
12
|
+
## Installation
|
13
|
+
|
14
|
+
gem コマンドを用いてインストールできます。
|
15
|
+
|
16
|
+
$ gem install wifi_login
|
17
|
+
|
18
|
+
## Configuration
|
19
|
+
|
20
|
+
公衆無線LANにログインするためのIDとパスワードを、pitコマンドで設定してください。
|
21
|
+
|
22
|
+
```
|
23
|
+
$ pit set docomo
|
24
|
+
---
|
25
|
+
id: tx2ekeu7-spmode@docomo
|
26
|
+
password: u563a8t6
|
27
|
+
```
|
28
|
+
|
29
|
+
## Usage
|
30
|
+
|
31
|
+
無線LANを有効にして `login` コマンドを実行すると、自動的に公衆無線LANにログインします。
|
32
|
+
|
33
|
+
$ wifi_login login
|
34
|
+
|
35
|
+
## TODO
|
36
|
+
|
37
|
+
* launchdを用いた公衆無線LANへの自動接続
|
38
|
+
* Growlによるログオン完了通知
|
39
|
+
* WISPr対応
|
40
|
+
|
41
|
+
## Contributing
|
42
|
+
|
43
|
+
1. Fork it
|
44
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
45
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
46
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
47
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/bin/wifi_login
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'wifi_login'
|
3
|
+
|
4
|
+
if ['--version', '-v'].include?(ARGV.first)
|
5
|
+
puts "wifi_login #{WifiLogin::VERSION}"
|
6
|
+
exit(0)
|
7
|
+
end
|
8
|
+
|
9
|
+
begin
|
10
|
+
case ARGV.first
|
11
|
+
when 'install'
|
12
|
+
puts 'not implemented'
|
13
|
+
when 'login'
|
14
|
+
success = WifiLogin.login
|
15
|
+
puts 'login success' if success
|
16
|
+
when 'logout'
|
17
|
+
puts 'not implemented'
|
18
|
+
when 'ssid'
|
19
|
+
puts "current SSID: #{WifiLogin.ssid}"
|
20
|
+
when 'help'
|
21
|
+
puts <<-"EOS"
|
22
|
+
wifi_login #{WifiLogin::VERSION}
|
23
|
+
usage: wifi_login COMMAND
|
24
|
+
|
25
|
+
install # install trigger to your Mac OS X System (launchd)
|
26
|
+
uninstall # uninstall trigger
|
27
|
+
login # login public wi-fi access point
|
28
|
+
ssid # show current SSID
|
29
|
+
help # show this message
|
30
|
+
|
31
|
+
EOS
|
32
|
+
else
|
33
|
+
STDERR.puts "wifi_login: unknown command #{ARGV.first} (see `wifi_login help`)"
|
34
|
+
exit(1)
|
35
|
+
end
|
36
|
+
rescue WifiLogin::Error => e
|
37
|
+
STDERR.puts "ERROR! #{e.message}"
|
38
|
+
exit(1)
|
39
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'wifi_login'
|
2
|
+
require 'mechanize'
|
3
|
+
|
4
|
+
module WifiLogin
|
5
|
+
module Providers
|
6
|
+
class Docomo
|
7
|
+
WifiLogin.providers['docomo'] = self
|
8
|
+
|
9
|
+
def login(id, password)
|
10
|
+
url = 'https://wlan.m-zone.jp/wlan/portal.jsp'
|
11
|
+
agent = Mechanize.new
|
12
|
+
page = agent.get(url)
|
13
|
+
if status(page) == :success_auth
|
14
|
+
return true
|
15
|
+
end
|
16
|
+
form = page.form
|
17
|
+
form.user = id
|
18
|
+
form.password = password
|
19
|
+
page = agent.submit(form)
|
20
|
+
if status(page) != :success_auth
|
21
|
+
raise WifiLogin::Error.new('Login failure. (incorrect id/password?)')
|
22
|
+
end
|
23
|
+
true
|
24
|
+
end
|
25
|
+
|
26
|
+
def status(page)
|
27
|
+
case page.title
|
28
|
+
when 'Login'
|
29
|
+
:before_auth
|
30
|
+
when 'Top page'
|
31
|
+
:success_auth
|
32
|
+
when /^Login error/
|
33
|
+
:fail_auth
|
34
|
+
else
|
35
|
+
raise WifiLogin::Error.new("cannot parse page: #{page.title}")
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/lib/wifi_login.rb
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
require "wifi_login/version"
|
2
|
+
require "pit"
|
3
|
+
require "systemu"
|
4
|
+
|
5
|
+
module WifiLogin
|
6
|
+
class Error < StandardError; end
|
7
|
+
|
8
|
+
AIRPORT_CMD = '/System/Library/PrivateFrameworks/Apple80211.framework/Versions/A/Resources/airport -I'
|
9
|
+
|
10
|
+
module Providers
|
11
|
+
autoload :Docomo, 'wifi_login/providers/docomo'
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.providers
|
15
|
+
@@providers ||= {}
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.login
|
19
|
+
ssid = self.ssid
|
20
|
+
id, password = credential(ssid)
|
21
|
+
provider(ssid).login(id, password)
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.provider(ssid)
|
25
|
+
provider_name = WifiLogin::Providers.constants.find {|provider|
|
26
|
+
provider.downcase.to_s == ssid.downcase
|
27
|
+
}
|
28
|
+
unless provider_name
|
29
|
+
raise WifiLogin::Error.new("provider is not found for SSID: #{ssid}")
|
30
|
+
end
|
31
|
+
WifiLogin::Providers.const_get(provider_name).new
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.credential(ssid)
|
35
|
+
pit = Pit.get(ssid)
|
36
|
+
id = pit['id']
|
37
|
+
password = pit['password']
|
38
|
+
unless (id && password)
|
39
|
+
raise WifiLogin::Error.new("credential is not found. please run `pit set #{ssid}`.")
|
40
|
+
end
|
41
|
+
[id, password]
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.ssid
|
45
|
+
status, stdout, stderr = systemu AIRPORT_CMD
|
46
|
+
if status.exitstatus != 0
|
47
|
+
raise WifiLogin::Error.new("faild to exec #{cmd}")
|
48
|
+
end
|
49
|
+
|
50
|
+
ssid_line = stdout.each_line.find {|line| line.match(/^\s+SSID:/) }
|
51
|
+
unless ssid_line
|
52
|
+
raise WifiLogin::Error.new("not found SSID (disable wi-fi?)")
|
53
|
+
end
|
54
|
+
ssid_line.chomp.split(': ')[1]
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'wifi_login'
|
5
|
+
|
6
|
+
# Requires supporting files with custom matchers and macros, etc,
|
7
|
+
# in ./support/ and its subdirectories.
|
8
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
|
12
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + './../../spec_helper')
|
3
|
+
require 'wifi_login/providers/docomo'
|
4
|
+
|
5
|
+
describe WifiLogin::Providers::Docomo do
|
6
|
+
before do
|
7
|
+
@provider = WifiLogin::Providers::Docomo.new
|
8
|
+
end
|
9
|
+
|
10
|
+
describe '#login' do
|
11
|
+
context "when successful" do
|
12
|
+
let(:id) { 'id' }
|
13
|
+
let(:password) { 'password' }
|
14
|
+
subject { @provider.login(id, password) }
|
15
|
+
|
16
|
+
it "ログイン成功を返す" do
|
17
|
+
subject.should be true
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
context "when unsuccessful" do
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
3
|
+
require 'wifi_login'
|
4
|
+
|
5
|
+
describe WifiLogin do
|
6
|
+
AIRPORT_CMD = '/System/Library/PrivateFrameworks/Apple80211.framework/Versions/A/Resources/airport -I'
|
7
|
+
|
8
|
+
describe '.providers' do
|
9
|
+
subject { WifiLogin.providers }
|
10
|
+
|
11
|
+
it do
|
12
|
+
subject.should be_kind_of Hash
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe '.ssid' do
|
17
|
+
subject { WifiLogin.ssid }
|
18
|
+
|
19
|
+
context 'when enable wifi' do
|
20
|
+
before do
|
21
|
+
status = double(:status, :exitstatus => 0)
|
22
|
+
stdout = <<-EOL
|
23
|
+
agrCtlRSSI: -70
|
24
|
+
agrExtRSSI: 0
|
25
|
+
agrCtlNoise: -96
|
26
|
+
agrExtNoise: 0
|
27
|
+
state: running
|
28
|
+
op mode: station
|
29
|
+
lastTxRate: 48
|
30
|
+
maxRate: 54
|
31
|
+
lastAssocStatus: 0
|
32
|
+
802.11 auth: open
|
33
|
+
link auth: none
|
34
|
+
BSSID: 00:00:00:00:00:00
|
35
|
+
SSID: docomo
|
36
|
+
MCS: -1
|
37
|
+
channel: 6
|
38
|
+
EOL
|
39
|
+
WifiLogin.stub!(:systemu).with(AIRPORT_CMD).and_return([status, stdout, ''])
|
40
|
+
end
|
41
|
+
|
42
|
+
it "取得したSSIDを返すこと" do
|
43
|
+
subject.should eq 'docomo'
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context 'when disable wifi' do
|
48
|
+
before do
|
49
|
+
status = double(:status, :exitstatus => 0)
|
50
|
+
stdout = "AirPort: Off\n"
|
51
|
+
WifiLogin.stub!(:systemu).with(AIRPORT_CMD).and_return([status, stdout, ''])
|
52
|
+
end
|
53
|
+
|
54
|
+
it "例外を返すこと" do
|
55
|
+
expect { subject }.to raise_error
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
data/wifi_login.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'wifi_login/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "wifi_login"
|
8
|
+
gem.version = WifiLogin::VERSION
|
9
|
+
gem.authors = ["MATSUOKA Kohei"]
|
10
|
+
gem.email = ["kohei@machu.jp"]
|
11
|
+
gem.description = %q{An automatically login tool for a public wireless LAN.}
|
12
|
+
gem.summary = %q{An automatically login tool when connected to a public wireless LAN.}
|
13
|
+
gem.homepage = ""
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_runtime_dependency 'mechanize'
|
21
|
+
gem.add_runtime_dependency 'pit'
|
22
|
+
gem.add_runtime_dependency 'systemu'
|
23
|
+
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: wifi_login
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- MATSUOKA Kohei
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-09-25 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: mechanize
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: pit
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: systemu
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
description: An automatically login tool for a public wireless LAN.
|
63
|
+
email:
|
64
|
+
- kohei@machu.jp
|
65
|
+
executables:
|
66
|
+
- wifi_login
|
67
|
+
extensions: []
|
68
|
+
extra_rdoc_files: []
|
69
|
+
files:
|
70
|
+
- .gitignore
|
71
|
+
- Gemfile
|
72
|
+
- LICENSE.txt
|
73
|
+
- README.md
|
74
|
+
- Rakefile
|
75
|
+
- bin/wifi_login
|
76
|
+
- lib/wifi_login.rb
|
77
|
+
- lib/wifi_login/provider.rb
|
78
|
+
- lib/wifi_login/providers/docomo.rb
|
79
|
+
- lib/wifi_login/version.rb
|
80
|
+
- spec/spec_helper.rb
|
81
|
+
- spec/wifi_login/providers/docomo_spec.rb
|
82
|
+
- spec/wifi_login_spec.rb
|
83
|
+
- wifi_login.gemspec
|
84
|
+
homepage: ''
|
85
|
+
licenses: []
|
86
|
+
post_install_message:
|
87
|
+
rdoc_options: []
|
88
|
+
require_paths:
|
89
|
+
- lib
|
90
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
91
|
+
none: false
|
92
|
+
requirements:
|
93
|
+
- - ! '>='
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
requirements: []
|
103
|
+
rubyforge_project:
|
104
|
+
rubygems_version: 1.8.23
|
105
|
+
signing_key:
|
106
|
+
specification_version: 3
|
107
|
+
summary: An automatically login tool when connected to a public wireless LAN.
|
108
|
+
test_files:
|
109
|
+
- spec/spec_helper.rb
|
110
|
+
- spec/wifi_login/providers/docomo_spec.rb
|
111
|
+
- spec/wifi_login_spec.rb
|