mirror of
https://git.baguette.netlib.re/Baguette/networkctl
synced 2024-12-18 04:53:51 +00:00
meh, stuff around wireless configuration
This commit is contained in:
parent
87bcfde75c
commit
702ca7af63
@ -15,6 +15,8 @@ description: |
|
||||
targets:
|
||||
networkctl:
|
||||
main: src/main.cr
|
||||
tests:
|
||||
main: src/tests.cr
|
||||
|
||||
dependencies:
|
||||
ipaddress:
|
||||
|
@ -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
|
||||
|
@ -2,6 +2,8 @@
|
||||
class Context
|
||||
class_property root : String = "/"
|
||||
|
||||
class_property keydir : String = "/etc/network/keydir"
|
||||
|
||||
class_property simulation = false
|
||||
class_property verbosity = 1
|
||||
|
||||
|
@ -70,6 +70,30 @@ class NetworkCommands
|
||||
end
|
||||
end
|
||||
|
||||
class WPASupplicant
|
||||
# verify if the passphrase already is stored for wpa_supplicant
|
||||
def self.passphrase?(ssid : String)
|
||||
puts "TODO: is the wpa_supplicant passphrase for ssid #{ssid} stored?"
|
||||
end
|
||||
|
||||
# store the AP passphrase in the wpa_supplicant way
|
||||
def self.passphrase(ssid : String, passphrase : String)
|
||||
puts "TODO: storing wpa_supplicant passphrase #{passphrase} for ssid #{ssid}"
|
||||
File.open("#{Context.root}/#{Context.keydir}/#{ssid}.conf") do |file|
|
||||
Do.run("wpa_passphrase", [ ssid, passphrase ]) do |content|
|
||||
file.puts content
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def self.connection(ssid : String, ifname : String)
|
||||
unless Do.run("wpa_supplicant",
|
||||
[ "-B", "-c", "#{Context.root}/#{Context.keydir}/#{ssid}.conf", "-i", ifname ]).success?
|
||||
raise "(wpa_supplicant) cannot connect to the wireless AP #{ssid} via the interface #{ifname}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class UDHCPCCommand
|
||||
def self.run(ifname : String)
|
||||
unless Do.run("udhcpc", [ ifname ]).success?
|
||||
|
Loading…
Reference in New Issue
Block a user