|
|
|
@ -38,6 +38,10 @@ class WirelessAPSetup |
|
|
|
|
property key : String |
|
|
|
|
def initialize(@key) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def to_s(io : IO) |
|
|
|
|
io << "WPA access point, key #{key}" |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def initialize(@ssid, @security) |
|
|
|
@ -84,6 +88,11 @@ class WirelessAPSetup |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def store_access_point_keys |
|
|
|
|
puts "TODO: store_access_point_keys" |
|
|
|
|
puts "security for #{ssid} = #{security}" |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def execute |
|
|
|
|
puts "TODO: wireless configuration" |
|
|
|
|
|
|
|
|
@ -191,23 +200,50 @@ class InterfaceConfiguration |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def access_point_connection |
|
|
|
|
ssid_list = NetworkCommands.scan name |
|
|
|
|
|
|
|
|
|
if ssid_list.nil? |
|
|
|
|
raise "no ssid scanned" |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
if wireless_networks.empty? |
|
|
|
|
raise "no configured access point for interface #{name}, cannot connect" |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
wireless_networks.each do |k,v| |
|
|
|
|
ssid_list.each do |ssid| |
|
|
|
|
if k == ssid |
|
|
|
|
puts "#{CGREEN}#{k} == #{ssid}#{CRESET}" |
|
|
|
|
v.execute |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
# TODO: sleep for a second before testing the gateway? |
|
|
|
|
# TODO: configuring the interface |
|
|
|
|
|
|
|
|
|
puts "TODO: connectivity check with the gateway" |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def store_access_point_keys |
|
|
|
|
if wireless_networks.empty? |
|
|
|
|
raise "no configured access point for interface #{name}" |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
wireless_networks.each do |ssid, wireless_configuration| |
|
|
|
|
# k = ssid |
|
|
|
|
puts "#{CGREEN}configuring #{ssid}#{CRESET}" |
|
|
|
|
wireless_configuration.store_access_point_keys |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
# configure the interface |
|
|
|
|
def execute |
|
|
|
|
unless NetworkCommands.interface_exists(@name) |
|
|
|
|
raise "The interface #{@name} doesn't exists, yet." |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
# TODO: treat differently wireless and non-wireless interfaces |
|
|
|
|
if @wireless |
|
|
|
|
puts "interface #{name} is wireless" |
|
|
|
|
puts "TODO:" |
|
|
|
|
puts "1. scan for SSID" |
|
|
|
|
puts "2. select configured SSID then try to connect" |
|
|
|
|
puts "3. connectivity check with the gateway" |
|
|
|
|
else |
|
|
|
|
puts "interface #{name} is not wireless" |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
if up |
|
|
|
|
NetworkCommands.up name |
|
|
|
|
else |
|
|
|
@ -223,6 +259,15 @@ class InterfaceConfiguration |
|
|
|
|
NetworkCommands.description name, description.not_nil! |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
# TODO: treat differently wireless and non-wireless interfaces |
|
|
|
|
if @wireless |
|
|
|
|
puts "interface #{name} is wireless: connection to the access point" |
|
|
|
|
store_access_point_keys |
|
|
|
|
access_point_connection |
|
|
|
|
else |
|
|
|
|
puts "interface #{name} is not wireless" |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
# ipv4 configuration |
|
|
|
|
main_ip_v4.tap do |ip| |
|
|
|
|
case ip |
|
|
|
|