mirror of
https://git.baguette.netlib.re/Baguette/networkctl
synced 2024-12-18 13:03:30 +00:00
clarity
This commit is contained in:
parent
2e7d3c8f28
commit
717b642fd1
@ -51,45 +51,36 @@ class WirelessAPSetup
|
||||
|
||||
|
||||
def to_s(io : IO)
|
||||
io << to_string
|
||||
io << indent(1, to_string)
|
||||
end
|
||||
|
||||
def to_string
|
||||
String.build do |str|
|
||||
str << "\t#{CBLUE}#{ssid}#{CRESET}\n"
|
||||
str << "#{CBLUE}#{ssid}#{CRESET}\n"
|
||||
|
||||
str << "\t\t#description #{description.not_nil!}\n" unless description.nil?
|
||||
str << "\t\t#{@up? "up" : "down"}\n"
|
||||
str << "\t\tmtu #{mtu}\n" unless mtu.nil?
|
||||
str << "\t#description #{description.not_nil!}\n" unless description.nil?
|
||||
str << "\t#{@up? "up" : "down"}\n"
|
||||
str << "\tmtu #{mtu}\n" unless mtu.nil?
|
||||
|
||||
# ipv4
|
||||
unless main_ip_v4.is_a?(NotSetup)
|
||||
str << "\t\tinet #{main_ip_v4}\n"
|
||||
str << "\tinet #{main_ip_v4}\n"
|
||||
|
||||
aliasses_v4.each do |a|
|
||||
str << "\t\talias #{a}\n"
|
||||
str << "\talias #{a}\n"
|
||||
end
|
||||
end
|
||||
|
||||
# ipv6
|
||||
unless main_ip_v6.is_a?(NotSetup)
|
||||
str << "\t\tinet6 #{main_ip_v6}\n"
|
||||
str << "\tinet6 #{main_ip_v6}\n"
|
||||
|
||||
@aliasses_v6.each do |a|
|
||||
str << "\t\talias6 #{a}\n"
|
||||
str << "\talias6 #{a}\n"
|
||||
end
|
||||
end
|
||||
|
||||
dns.addresses.each do |ip|
|
||||
str << "\t\tdns: #{ip}\n"
|
||||
end
|
||||
|
||||
dns.search.each do |localdomain|
|
||||
str << "\t\tdomain: #{localdomain}\n"
|
||||
end
|
||||
|
||||
# to improve readability
|
||||
str << "\n"
|
||||
str << indent(1, dns.to_s) unless dns.addresses.empty?
|
||||
end
|
||||
end
|
||||
|
||||
@ -190,17 +181,9 @@ class InterfaceConfiguration
|
||||
str << "\t#{CRED}Should main ipv6 be obtained from autoconfiguration? DHCP? Static configuration?#{CRESET}\n"
|
||||
end
|
||||
|
||||
dns.addresses.each do |ip|
|
||||
str << "\tdns: #{ip}\n"
|
||||
end
|
||||
|
||||
dns.search.each do |localdomain|
|
||||
str << "\t\tdomain: #{localdomain}\n"
|
||||
end
|
||||
str << indent(1, dns.to_s) unless dns.addresses.empty?
|
||||
|
||||
unless wireless_networks.empty?
|
||||
# to improve readability
|
||||
str << "\n"
|
||||
wireless_networks.each do |k,v|
|
||||
str << v
|
||||
end
|
||||
|
@ -1,6 +1,7 @@
|
||||
|
||||
require "option_parser"
|
||||
require "ipaddress"
|
||||
require "./indent"
|
||||
require "./colors"
|
||||
require "./context"
|
||||
require "./network_commands"
|
||||
|
@ -17,20 +17,28 @@ class NetworkCommands
|
||||
@search = Array(String).new
|
||||
end
|
||||
|
||||
def execute
|
||||
Dir.mkdir_p("#{Context.root}/etc/")
|
||||
def to_s(io : IO)
|
||||
addresses.each do |ip|
|
||||
io << "nameserver #{ip}"
|
||||
end
|
||||
|
||||
io << "search #{search.join(" ")}" unless search.empty?
|
||||
end
|
||||
|
||||
def execute
|
||||
if Context.simulation
|
||||
puts "simulation, writing in #{Context.root}/etc/resolv.conf:"
|
||||
@addresses.each do |address|
|
||||
puts "\tnameserver #{address}\n"
|
||||
puts "\tnameserver #{address}"
|
||||
end
|
||||
|
||||
puts "\tsearch #{@search.join(" ")}" unless search.empty?
|
||||
else
|
||||
Dir.mkdir_p("#{Context.root}/etc/")
|
||||
|
||||
File.open("#{Context.root}/etc/resolv.conf", "w+") do |file|
|
||||
@addresses.each do |address|
|
||||
file.puts "nameserver #{address}\n"
|
||||
file.puts "nameserver #{address}"
|
||||
end
|
||||
|
||||
file.puts "search #{@search.join(" ")}" unless search.empty?
|
||||
|
@ -61,6 +61,7 @@ class NetworkConfigurationParser
|
||||
else
|
||||
main_ip_v6 = IPAddress.parse ipstr
|
||||
end
|
||||
|
||||
when /^join [^ \t]+ wpakey .*/
|
||||
# WPA2-PSK, other security mechanisms are not supported, yet
|
||||
ssid = /^join ([^ \t]+)/.match(line).try &.[1]
|
||||
@ -76,14 +77,10 @@ class NetworkConfigurationParser
|
||||
next
|
||||
end
|
||||
|
||||
# TODO
|
||||
new_ap = WirelessAPSetup.new ssid, WirelessAPSetup::WPA.new(wpakeystr)
|
||||
wireless_networks[ssid] = new_ap
|
||||
|
||||
|
||||
when /^network [^ \t]+ inet6 autoconf/
|
||||
puts "TODO: network SSID inet6 autoconf"
|
||||
|
||||
ssid = /^network ([^ \t]+)/.match(line).try &.[1]
|
||||
ipstr = /^network [^ \t]+ inet6? ([^ \t]+)/.match(line).try &.[1]
|
||||
|
||||
@ -99,7 +96,6 @@ class NetworkConfigurationParser
|
||||
|
||||
access_point = wireless_networks[ssid].not_nil!
|
||||
access_point.main_ip_v6 = Autoconfiguration.new
|
||||
puts "for SSID: #{ssid} ipv6 configuration = autoconf"
|
||||
|
||||
when /^network [^ \t]+ inet6? .*/
|
||||
ssid = nil
|
||||
|
Loading…
Reference in New Issue
Block a user