concerto / bandshell

A Local Management Utility for the Concerto Player
Other
7 stars 8 forks source link

Set variable for password in netconfig.rb #43

Open apinter opened 9 years ago

apinter commented 9 years ago

Hi Guys,

Started to play around with Concerto a few days ago, it is awesome, but noticed that it can, but out of the box can't connect to encrypted wireless networks (wpa personal) so I added a field in ../application/views/netsettings.erb which is fine and tried to add an instance variable in ../lib/bandshell/netconfig.rb @pwas:

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

attr_accessor :pwas, :ssid, :interface_name

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

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

def safe_assign
  [ :pwas, :ssid, :interface_name ]
end

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=wpa"
    wpaconf.puts "password=#{@pwas}"
    wpaconf.puts "}"
  end
end

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

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

This clearly not working, can you please advise where can I set this variable to make sense?

Thanks in advance!

augustf commented 9 years ago

@asquared Would adding a password field to pass along to wpa_supplicant will be sufficient here? It wouldn't seem to me to be that simple...

asquared commented 9 years ago

It looks like the key_mgmt option needs to be set to WPA-PSK and the option for the password is then called "psk", not "password".

I would also advocate for making this a new class of connection, perhaps a subclass of WirelessConnection, or an object that plugs into WirelessConnection. There are many different kinds of wireless authentication that might be in use in a Concerto deployment, so we want to factor this in a way that allows new methods to be added easily.

asquared commented 9 years ago

For reference, here's the man page for wpa_supplicant.conf: http://manpages.ubuntu.com/manpages/hardy/man5/wpa_supplicant.conf.5.html

apinter commented 9 years ago

Guys, the question is not exactly about wpa_suppilcant, I know how to configure it, was just posting a silly example (was lazy to copy from my vm, sorry). The problem what I have unfortunately is that I'm not able to define a variable to the password field on the GUI which would pass the input to the wpa_supplicant eventually. Think it would be awesome to have a function like that.