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