Class: ConcertoConfig::WirelessConnection

Inherits:
Object
  • Object
show all
Defined in:
lib/concerto_client/netconfig.rb

Overview

802.11* unencrypted wireless connections. These are managed by wpa_supplicant on Debian so we need to create its configuration file and link it to the interfaces file.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ WirelessConnection

Returns a new instance of WirelessConnection.



242
243
244
245
246
# File 'lib/concerto_client/netconfig.rb', line 242

def initialize(args={})
    @ssid = args['ssid'] || ''
    @interface_name = args['interface_name'] if args['interface_name']
    @wpa_config_file = '/tmp/wpa_supplicant.concerto.conf'
end

Instance Attribute Details

#interface_nameObject

Returns the value of attribute interface_name.



248
249
250
# File 'lib/concerto_client/netconfig.rb', line 248

def interface_name
  @interface_name
end

#ssidObject

Returns the value of attribute ssid.



248
249
250
# File 'lib/concerto_client/netconfig.rb', line 248

def ssid
  @ssid
end

Class Method Details

.descriptionObject



297
298
299
# File 'lib/concerto_client/netconfig.rb', line 297

def self.description
    "Wireless connection (no encryption)"
end

.interfacesObject



301
302
303
304
305
# File 'lib/concerto_client/netconfig.rb', line 301

def self.interfaces
    # Again this is not guaranteed to be a catch all.
    devices = Dir.glob('/sys/class/net/{ath,wlan}*')
    devices.map { |d| Interface.new(File.basename(d)) }
end

Instance Method Details

#argsObject



290
291
292
293
294
295
# File 'lib/concerto_client/netconfig.rb', line 290

def args
    {
        'interface_name' => @interface_name,
        'ssid' => @ssid
    }
end

#config_interface_nameObject



250
251
252
253
254
255
256
257
258
259
260
# File 'lib/concerto_client/netconfig.rb', line 250

def config_interface_name
    # If the user has requested a specific interface, use it.
    # Otherwise, just pick the first wlan interface, assuming
    # it works and all wlan interfaces have approximately equal
    # reception. When this assumption is wrong the user must force.
    if @interface_name && @interface_name != ''
        @interface_name
    else
        self.class.interfaces[0].name
    end
end

#interfaces_linesObject



285
286
287
288
# File 'lib/concerto_client/netconfig.rb', line 285

def interfaces_lines
    # This links the wpa config to the interfaces file.
    ["wpa-conf #{@wpa_config_file}"]
end

#safe_assignObject



268
269
270
# File 'lib/concerto_client/netconfig.rb', line 268

def safe_assign
    [ :ssid, :interface_name ]
end

#validateObject



262
263
264
265
266
# File 'lib/concerto_client/netconfig.rb', line 262

def validate
    if @ssid == ''
        fail "Need SSID for wireless connection"
    end
end

#write_configsObject



272
273
274
275
276
277
278
279
280
281
282
283
# File 'lib/concerto_client/netconfig.rb', line 272

def write_configs
    # Write a wpa_supplicant.conf file for an unsecured network.
    File.open(@wpa_config_file, 'w') do |wpaconf|
        # long lines, sorry!
        wpaconf.puts "ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev"
        wpaconf.puts "network={"
        wpaconf.puts "ssid=\"#{@ssid}\""
        wpaconf.puts "scan_ssid=1"
        wpaconf.puts "key_mgmt=NONE"
        wpaconf.puts "}"
    end
end