wliconfig 1.0.0
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.
- checksums.yaml +7 -0
- data/bin/wliconfig +7 -0
- data/lib/wliconfig.rb +213 -0
- metadata +65 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8da5e6ba17d186876232528519394eec9d22993c
|
4
|
+
data.tar.gz: 62f9409548b74623e8fc30d67903bf3561d7cfb5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b9ad949384deedf7dfa3dfae91c3bff7ac3b74398c1a39966c6cce9a1b1e4f383e90a83d600c63f79faebdfc4a842f6e92363aaa7b8bcfc429592660a3532807
|
7
|
+
data.tar.gz: a0d7b4d946c0123e1e3d64af9521a274c50311a36728d9989cb6a301eb61e6b1d54f1c6646ab039c8190f11ada9db1c9ab4ccbe12546dcdf4a8b6792563037fc
|
data/bin/wliconfig
ADDED
data/lib/wliconfig.rb
ADDED
@@ -0,0 +1,213 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
require 'yaml'
|
3
|
+
require 'mechanize'
|
4
|
+
require 'logger'
|
5
|
+
|
6
|
+
$wlog = Logger.new(STDOUT)
|
7
|
+
|
8
|
+
module WLIConfig
|
9
|
+
#
|
10
|
+
# Product classes
|
11
|
+
#
|
12
|
+
module Product
|
13
|
+
#
|
14
|
+
# Product class for WLI-UTX-AG300
|
15
|
+
#
|
16
|
+
class WLI_UTX_AG300
|
17
|
+
attr_reader :ip_addr, :username, :password
|
18
|
+
|
19
|
+
def initialize(ip_addr, username, password)
|
20
|
+
@ip_addr, @username, @password = ip_addr, username, password
|
21
|
+
@url = "http://#{ip_addr}/"
|
22
|
+
end
|
23
|
+
|
24
|
+
def change_config(config)
|
25
|
+
# print url
|
26
|
+
$wlog.info("Attempt to access to '#{@url}'.")
|
27
|
+
|
28
|
+
agent = create_agent()
|
29
|
+
|
30
|
+
# fetch index page
|
31
|
+
$wlog.info("Begin fetch index page.")
|
32
|
+
page = agent.get(@url)
|
33
|
+
page = fetch_main_iframe(page)
|
34
|
+
page = page.links_with(:href => 'index.html?page=wizard_func_wlan_sta_crypto.html')[0].click
|
35
|
+
$wlog.info("End fetch index page.")
|
36
|
+
|
37
|
+
# fetch config page and submit config
|
38
|
+
$wlog.info("Begin fetch config page and submit config.")
|
39
|
+
page = fetch_main_iframe(page)
|
40
|
+
form = page.forms[0]
|
41
|
+
fill_config_form(form, config)
|
42
|
+
page = form.submit
|
43
|
+
$wlog.info("End fetch ocnfig page and submit config.")
|
44
|
+
|
45
|
+
# fetch finish page
|
46
|
+
$wlog.info("Begin fetch complete page.")
|
47
|
+
page = page.forms[0].submit
|
48
|
+
$wlog.info("End fetch complete page.")
|
49
|
+
end
|
50
|
+
|
51
|
+
def create_agent()
|
52
|
+
agent = Mechanize.new
|
53
|
+
|
54
|
+
# meta refresh enable
|
55
|
+
agent.follow_meta_refresh = true
|
56
|
+
|
57
|
+
# basic auth config for url
|
58
|
+
agent.add_auth(@url, @username, @password)
|
59
|
+
|
60
|
+
agent
|
61
|
+
end
|
62
|
+
|
63
|
+
def fetch_main_iframe(page)
|
64
|
+
# find lower frame and go
|
65
|
+
lower = page.frames_with('lower')[0].click
|
66
|
+
|
67
|
+
# find main iframe and go
|
68
|
+
lower.iframes_with('main')[0].click
|
69
|
+
end
|
70
|
+
|
71
|
+
def fill_config_form(form, config)
|
72
|
+
form.ssid = config.ssid
|
73
|
+
form.authmode = config.mode
|
74
|
+
form.auth_pass = config.pass
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
#
|
80
|
+
# Commandline option container
|
81
|
+
#
|
82
|
+
class Options
|
83
|
+
attr_accessor :product, :addr, :user, :pass, :wlan_ssid, :wlan_mode, :wlan_key
|
84
|
+
|
85
|
+
def update_from_file(fname)
|
86
|
+
return unless fname
|
87
|
+
if FileTest.exist?(fname)
|
88
|
+
$wlog.info("Configuration file #{fname} does exist.")
|
89
|
+
open(fname){|f|
|
90
|
+
yaml = YAML.load(f.read)
|
91
|
+
@addr ||= yaml["addr"]
|
92
|
+
@user ||= yaml["user"]
|
93
|
+
@pass ||= yaml["pass"]
|
94
|
+
@wlan_ssid ||= yaml["wlan-ssid"]
|
95
|
+
@wlan_mode ||= yaml["wlan-mode"]
|
96
|
+
@wlan_key ||= yaml["wlan-key"]
|
97
|
+
}
|
98
|
+
true
|
99
|
+
else
|
100
|
+
$wlog.warn("Configuration file #{fname} does not exist.")
|
101
|
+
false
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
def update_from_map(map)
|
106
|
+
@addr = map[:addr] || @addr
|
107
|
+
@user = map[:user] || @user
|
108
|
+
@pass = map[:pass] || @pass
|
109
|
+
@wlan_ssid = map[:wlan_ssid] || @wlan_ssid
|
110
|
+
@wlan_mode = map[:wlan_mode] || @wlan_mode
|
111
|
+
@wlan_key = map[:wlan_key] || @wlan_key
|
112
|
+
end
|
113
|
+
|
114
|
+
def valid?
|
115
|
+
[@addr, @user, @pass, @wlan_ssid, @wlan_mode, @wlan_key].count(nil) == 0
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
#
|
120
|
+
# WLAN configure
|
121
|
+
#
|
122
|
+
class WLANConfig
|
123
|
+
attr_reader :ssid, :mode, :pass
|
124
|
+
|
125
|
+
def initialize(ssid, mode, pass)
|
126
|
+
@ssid, @mode, @pass = ssid, mode, pass
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
#
|
131
|
+
# Create concrete product instance
|
132
|
+
#
|
133
|
+
class ProductFactory
|
134
|
+
include Product
|
135
|
+
|
136
|
+
@@PRODUCT_MAP = {
|
137
|
+
"WLI-UTX-AG300" => WLI_UTX_AG300
|
138
|
+
}
|
139
|
+
@@PRODUCT_MAP.default = WLI_UTX_AG300
|
140
|
+
|
141
|
+
def self.create(product, *params)
|
142
|
+
@@PRODUCT_MAP[product].new(*params)
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
def create_option_parser(container)
|
147
|
+
op = OptionParser.new
|
148
|
+
|
149
|
+
|
150
|
+
op.banner = "wliconfig -- The 3rd party configuration cli for BUFFALO INC wireless lan adapters are called 'WLI' series.\n\nUsage: wliconfig [options...]"
|
151
|
+
op.version = "1.0.0"
|
152
|
+
|
153
|
+
op.on('-f FILE', 'Read options from specified YAML file.'){|v| container[:fname] = v}
|
154
|
+
op.on('-a', '--addr ADDR', 'WLI product\'s ip address. (eg. 192.168.0.1)'){|v| container[:addr] = v}
|
155
|
+
op.on('-u', '--user USERNAME', 'Basic auth username. (eg. admin)'){|v| container[:user] = v}
|
156
|
+
op.on('-p', '--pass PASSWORD', 'Basic auth password. (eg. password)'){|v| container[:pass] = v}
|
157
|
+
op.on('-s', '--wlan-ssid SSID', 'SSID that to connect wireless lan.'){|v| container[:wlan_ssid] = v}
|
158
|
+
op.on('-m', '--wlan-mode MODE', 'Auth mode that to connect wireless lan. (none, wep_hex, wep_char, tkip, aes, wpa2_tkip or wpa2_aes is valid.)'){|v| container[:wlan_mode] = v}
|
159
|
+
op.on('-k', '--wlan-key KEY', 'Key or pass phrase that to connect wireless lan.'){|v| container[:wlan_key] = v}
|
160
|
+
op.on('--debug', 'For developers only. Enabled debug mode.'){|v| $debug = true}
|
161
|
+
|
162
|
+
op
|
163
|
+
end
|
164
|
+
|
165
|
+
def create_options(container)
|
166
|
+
opts = Options.new
|
167
|
+
|
168
|
+
opts.update_from_file("#{ENV['HOME']}/.wliconfig")
|
169
|
+
opts.update_from_file(container[:fname])
|
170
|
+
opts.update_from_map(container)
|
171
|
+
|
172
|
+
opts
|
173
|
+
end
|
174
|
+
|
175
|
+
def main(argv)
|
176
|
+
container = {}
|
177
|
+
parser = create_option_parser(container)
|
178
|
+
parser.parse(argv)
|
179
|
+
|
180
|
+
unless $debug
|
181
|
+
$wlog.level = Logger::INFO
|
182
|
+
$wlog.formatter = proc{|severity, datetime, progname, msg| "#{msg}\n"}
|
183
|
+
end
|
184
|
+
|
185
|
+
$wlog.info("Start processing...")
|
186
|
+
|
187
|
+
$wlog.debug("container:" + container.inspect)
|
188
|
+
|
189
|
+
options = create_options(container)
|
190
|
+
$wlog.debug("options:" + options.inspect)
|
191
|
+
|
192
|
+
unless options.valid?
|
193
|
+
raise "Some options were not specified. Please read usage 'wliconfig --help'."
|
194
|
+
end
|
195
|
+
|
196
|
+
product = ProductFactory.create(options.product, options.addr, options.user, options.pass)
|
197
|
+
$wlog.debug("product:" + product.inspect)
|
198
|
+
|
199
|
+
config = WLANConfig.new(options.wlan_ssid, options.wlan_mode, options.wlan_key)
|
200
|
+
$wlog.debug("config:" + config.inspect)
|
201
|
+
|
202
|
+
product.change_config(config)
|
203
|
+
|
204
|
+
$wlog.info("Complete processing successfully.")
|
205
|
+
|
206
|
+
return 0
|
207
|
+
rescue
|
208
|
+
$wlog.error($!)
|
209
|
+
$wlog.error("Processing failure.")
|
210
|
+
|
211
|
+
return 1
|
212
|
+
end
|
213
|
+
end
|
metadata
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: wliconfig
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- xmisao
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-03-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: mechanize
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.7'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.7'
|
27
|
+
description: |
|
28
|
+
wliconfig is tiny utility that change connect wireless lan network by scraping configuration page of 'WLI' terminal.
|
29
|
+
|
30
|
+
Supported 'WLI' terminals:
|
31
|
+
* WLI-UTX-AG300
|
32
|
+
email: mail@xmisao.com
|
33
|
+
executables:
|
34
|
+
- wliconfig
|
35
|
+
extensions: []
|
36
|
+
extra_rdoc_files: []
|
37
|
+
files:
|
38
|
+
- bin/wliconfig
|
39
|
+
- lib/wliconfig.rb
|
40
|
+
homepage: https://github.com/xmisao/wliconfig
|
41
|
+
licenses:
|
42
|
+
- MIT
|
43
|
+
metadata: {}
|
44
|
+
post_install_message:
|
45
|
+
rdoc_options: []
|
46
|
+
require_paths:
|
47
|
+
- lib
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
requirements: []
|
59
|
+
rubyforge_project:
|
60
|
+
rubygems_version: 2.2.2
|
61
|
+
signing_key:
|
62
|
+
specification_version: 4
|
63
|
+
summary: The 3rd party configuration cli for BUFFALO INC wireless lan adapters are
|
64
|
+
called 'WLI' series.
|
65
|
+
test_files: []
|