wifi-wand 2.5.0 → 2.6.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c9c498e8044e8913348ab143847be13dd0e1683d72c0e26448ae63d817a0675d
4
- data.tar.gz: 440847dc2ddc905172a60cf090b863669ec5fef41d5a23f93e7540326d257583
3
+ metadata.gz: 3dcc159a696bb6c5802164faa4364c372d12478c38027cc0cef1b8efcd28f4a8
4
+ data.tar.gz: f6dcd8a61c97e38c6fe1cd35d6e1c46a5112993c9e3d319dbcd6cc6105b6c963
5
5
  SHA512:
6
- metadata.gz: 5ab2bfebaf3c9dd5ad50e8cc7f9aeaa96c1f9799c504153616e920e278419b4f9d004f32083997f1f5c9cc0794557d6b5af093f2b483f519c1d4691b25346772
7
- data.tar.gz: 48cc73787df1b6d8a5cb0aa641047bd7b796c9e2c7cf8b25d112427122c780101d7847d3b380cb704ac2f173eb3e8ba9b294295e26e6cca5ee299b93cc95a449
6
+ metadata.gz: f2e6bf5a8ad731631e464826ec096a5ba10e61111aab1ca66232a5f1453ea98d26c0e3b5a670d754f6ff16d0829b9b4177a5276def708f3fe0be6d9385cbe6f5
7
+ data.tar.gz: aee01f531189ace41937a7722a413873018792e9a2e161b8dd2634e87c1952763c85f7648ed7b7ac0d0d7b0b205955f70143aaa67f9961abd21eed69176647f9
data/README.md CHANGED
@@ -28,11 +28,9 @@ output at the time of this writing:
28
28
  ```
29
29
  $ wifi-wand -h
30
30
 
31
+ Command Line Switches: [wifi-wand version 2.6.0]
31
32
 
32
-
33
- Command Line Switches: [wifi-wand version 2.4.2]
34
-
35
- -o {i,j,p,y} - outputs data in inspect, JSON, puts, or YAML format when not in shell mode
33
+ -o {i,j,k,p,y} - outputs data in inspect, JSON, pretty JSON, puts, or YAML format when not in shell mode
36
34
  -p wifi_port_name - override automatic detection of port name with this name
37
35
  -s - run in shell mode
38
36
  -v - verbose mode (prints OS commands and their outputs)
@@ -47,7 +45,8 @@ d[isconnect] - disconnects from current network, does not turn off
47
45
  h[elp] - prints this help
48
46
  i[nfo] - a hash of wifi-related information
49
47
  l[s_avail_nets] - details about available networks
50
- n[etwork_name] - name (SSID) of currently connected network
48
+ na[meservers] - nameservers: 'show' or no arg to show, 'clear' to clear, or IP addresses to set, e.g. '9.9.9.9 8.8.8.8'
49
+ ne[twork_name] - name (SSID) of currently connected network
51
50
  on - turns wifi on
52
51
  of[f] - turns wifi off
53
52
  pa[ssword] network-name - password for preferred network-name
data/RELEASE_NOTES.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## v2.6.0
2
+
3
+ * Add support for getting and setting DNS nameservers with 'na'/'nameservers' command.
4
+ * Improve error output readability for top level error catching.
5
+
6
+
1
7
  ## v2.5.0
2
8
 
3
9
  * Add limited support for nonstandard wifi devices (https://github.com/keithrbennett/wifiwand/issues/6).
@@ -67,7 +67,8 @@ d[isconnect] - disconnects from current network, does not turn off
67
67
  h[elp] - prints this help
68
68
  i[nfo] - a hash of wifi-related information
69
69
  l[s_avail_nets] - details about available networks
70
- n[etwork_name] - name (SSID) of currently connected network
70
+ na[meservers] - nameservers: 'show' or no arg to show, 'clear' to clear, or IP addresses to set, e.g. '9.9.9.9 8.8.8.8'
71
+ ne[twork_name] - name (SSID) of currently connected network
71
72
  on - turns wifi on
72
73
  of[f] - turns wifi off
73
74
  pa[ssword] network-name - password for preferred network-name
@@ -193,11 +194,10 @@ When in interactive shell mode:
193
194
 
194
195
 
195
196
  # For use by the shell; when typing a command and options, it is passed to process_command_line
196
- def method_missing(method_name, *options)
197
+ def method_missing(method_name, *method_args)
197
198
  method_name = method_name.to_s
198
- method_exists = !! find_command_action(method_name)
199
- if method_exists
200
- process_command_line(method_name, options)
199
+ if find_command_action(method_name)
200
+ process_command_line(method_name, method_args)
201
201
  else
202
202
  puts(%Q{"#{method_name}" is not a valid command or option. If you intend for this to be a string literal, use quotes or %q/Q{}.})
203
203
  end
@@ -210,14 +210,14 @@ When in interactive shell mode:
210
210
  # be in a form that the Ruby interpreter will recognize as a string,
211
211
  # i.e. single or double quotes, %q, %Q, etc.
212
212
  # Otherwise it will assume it's a method name and pass it to method_missing!
213
- def process_command_line(command, options)
213
+ def process_command_line(command, args)
214
214
  action = find_command_action(command)
215
215
  if action
216
- action.(*options)
216
+ action.(*args)
217
217
  else
218
218
  print_help
219
219
  raise BadCommandError.new(
220
- %Q{Unrecognized command. Command was "#{command}" and options were #{options.inspect}.})
220
+ %Q{Unrecognized command. Command was "#{command}" and options were #{args.inspect}.})
221
221
  end
222
222
  end
223
223
 
@@ -306,7 +306,41 @@ When in interactive shell mode:
306
306
  end
307
307
 
308
308
 
309
- def cmd_n
309
+ # Performs nameserver functionality.
310
+ # @param subcommand 'get' or no arg to get, 'clear' to clear, and an array of IP addresses to set
311
+ def cmd_na(*args)
312
+
313
+ subcommand = if [[], ['get']].include?(args)
314
+ :get
315
+ elsif args == ['clear']
316
+ :clear
317
+ else
318
+ :put
319
+ end
320
+
321
+ case(subcommand)
322
+ when :get
323
+ current_nameservers = model.nameservers_using_networksetup
324
+ if interactive_mode
325
+ current_nameservers
326
+ else
327
+ if post_processor
328
+ puts post_processor.(current_nameservers)
329
+ else
330
+ current_nameservers_as_string = current_nameservers.empty? ? "[None]" : current_nameservers.join(', ')
331
+ puts "Nameservers: #{current_nameservers_as_string}"
332
+ end
333
+ end
334
+ when :clear
335
+ model.set_nameservers(:clear)
336
+ when :put
337
+ new_nameservers = args
338
+ model.set_nameservers(new_nameservers)
339
+ end
340
+ end
341
+
342
+
343
+ def cmd_ne
310
344
  name = model.connected_network_name
311
345
  if interactive_mode
312
346
  name
@@ -416,7 +450,8 @@ When in interactive shell mode:
416
450
  Command.new('h', 'help', -> (*_options) { cmd_h }),
417
451
  Command.new('i', 'info', -> (*_options) { cmd_i }),
418
452
  Command.new('l', 'ls_avail_nets', -> (*_options) { cmd_l }),
419
- Command.new('n', 'network_name', -> (*_options) { cmd_n }),
453
+ Command.new('na', 'nameservers', -> (*options) { cmd_na(*options) }),
454
+ Command.new('ne', 'network_name', -> (*_options) { cmd_ne }),
420
455
  Command.new('of', 'off', -> (*_options) { cmd_of }),
421
456
  Command.new('on', 'on', -> (*_options) { cmd_on }),
422
457
  Command.new('ro', 'ropen', -> (*options) { cmd_ro(*options) }),
@@ -457,6 +492,8 @@ When in interactive shell mode:
457
492
  def call
458
493
  validate_command_line
459
494
  begin
495
+ # By this time, the Main class has removed the command line options, and all that is left
496
+ # in ARGV is the commands and their options.
460
497
  process_command_line(ARGV[0], ARGV[1..-1])
461
498
  rescue BadCommandError => error
462
499
  separator_line = "! #{'-' * 75} !\n"
@@ -62,7 +62,8 @@ class Main
62
62
  begin
63
63
  WifiWand::CommandLineInterface.new(options).call
64
64
  rescue => e
65
- puts "Error: #{e.message}"
65
+ # require 'pry'; binding.pry
66
+ puts "Error: #{e.backtrace.join("\n")}\n\n#{e.message}"
66
67
  end
67
68
  end
68
69
  end
@@ -77,7 +77,7 @@ class BaseModel
77
77
 
78
78
  begin
79
79
  start_status_script = -> do
80
- script = "curl --silent --head http://www.google.com/ > /dev/null ; echo $? > #{tempfile.path} &"
80
+ script = "curl --silent --head https://www.google.com/ > /dev/null ; echo $? > #{tempfile.path} &"
81
81
  pid = Process.spawn(script)
82
82
  Process.detach(pid)
83
83
  pid
@@ -246,27 +246,6 @@ class BaseModel
246
246
  end
247
247
 
248
248
 
249
- # @return array of nameserver IP addresses from /etc/resolv.conf, or nil if not found
250
- # Though this is strictly *not* OS-agnostic, it will be used by most OS's,
251
- # and can be overridden by subclasses (e.g. Windows).
252
- def nameservers_using_resolv_conf
253
- begin
254
- File.readlines('/etc/resolv.conf').grep(/^nameserver /).map { |line| line.split.last }
255
- rescue Errno::ENOENT
256
- nil
257
- end
258
- end
259
-
260
-
261
- def nameservers_using_scutil
262
- output = run_os_command('scutil --dns')
263
- nameserver_lines_scoped_and_unscoped = output.split("\n").grep(/^\s*nameserver\[/)
264
- unique_nameserver_lines = nameserver_lines_scoped_and_unscoped.uniq # take the union
265
- nameservers = unique_nameserver_lines.map { |line| line.split(' : ').last.strip }
266
- nameservers
267
- end
268
-
269
-
270
249
  def wifi_port
271
250
  @wifi_port ||= detect_wifi_port
272
251
  end
@@ -1,3 +1,4 @@
1
+ require 'ipaddr'
1
2
  require 'ostruct'
2
3
  require 'shellwords'
3
4
 
@@ -300,6 +301,29 @@ class MacOsModel < BaseModel
300
301
  end
301
302
 
302
303
 
304
+ def set_nameservers(nameservers)
305
+ arg = if nameservers == :clear
306
+ 'empty'
307
+ else
308
+ bad_addresses = nameservers.reject do |ns|
309
+ begin
310
+ IPAddr.new(ns).ipv4?
311
+ true
312
+ rescue => e
313
+ puts e
314
+ false
315
+ end
316
+ end
317
+
318
+ unless bad_addresses.empty?
319
+ raise "Bad IP addresses provided: #{bad_addresses.join(', ')}"
320
+ end
321
+ nameservers.join(' ')
322
+ end
323
+ run_os_command("networksetup -setdnsservers Wi-Fi #{arg}")
324
+ end
325
+
326
+
303
327
  def open_resource(resource_url)
304
328
  run_os_command('open ' + resource_url)
305
329
  end
@@ -319,5 +343,31 @@ class MacOsModel < BaseModel
319
343
  end
320
344
  end
321
345
  private :colon_output_to_hash
346
+
347
+ # @return array of nameserver IP addresses from /etc/resolv.conf, or nil if not found
348
+ # Though this is strictly *not* OS-agnostic, it will be used by most OS's,
349
+ # and can be overridden by subclasses (e.g. Windows).
350
+ def nameservers_using_resolv_conf
351
+ begin
352
+ File.readlines('/etc/resolv.conf').grep(/^nameserver /).map { |line| line.split.last }
353
+ rescue Errno::ENOENT
354
+ nil
355
+ end
356
+ end
357
+
358
+
359
+ def nameservers_using_scutil
360
+ output = run_os_command('scutil --dns')
361
+ nameserver_lines_scoped_and_unscoped = output.split("\n").grep(/^\s*nameserver\[/)
362
+ unique_nameserver_lines = nameserver_lines_scoped_and_unscoped.uniq # take the union
363
+ nameservers = unique_nameserver_lines.map { |line| line.split(' : ').last.strip }
364
+ nameservers
365
+ end
366
+
367
+
368
+ def nameservers_using_networksetup
369
+ output = run_os_command("networksetup -getdnsservers Wi-Fi")
370
+ output.split("\n")
371
+ end
322
372
  end
323
373
  end
@@ -1,5 +1,5 @@
1
1
  module WifiWand
2
2
 
3
- VERSION = '2.5.0'
3
+ VERSION = '2.6.0'
4
4
 
5
5
  end
@@ -1,9 +1,12 @@
1
1
  # The functionality of this software is very difficult to test,
2
- # sinece it relies on external conditions that cannot be faked.
2
+ # since it relies on external conditions that cannot be faked.
3
3
  # These tests merely run the commands and assert that no
4
4
  # error has occurred; they don't make any attempt to verify the data.
5
5
  # Many of them are run once with the wifi on, and once when it's off.
6
-
6
+ #
7
+ # This test is in no way pretending to be thorough or accurate.
8
+ # Furthermore, since it modifies machine-global state and can interfere with
9
+ # other processes running on the host, it should be used with utmost care.
7
10
 
8
11
  require_relative '../../../lib/wifi-wand/models/mac_os_model'
9
12
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wifi-wand
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.5.0
4
+ version: 2.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Keith Bennett
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-03-05 00:00:00.000000000 Z
11
+ date: 2018-03-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler