mirror of
https://git.baguette.netlib.re/Baguette/networkctl
synced 2024-12-18 13:03:30 +00:00
DNS: 'nameserver' and 'search' lines working.
This commit is contained in:
parent
2cf04c331a
commit
2e7d3c8f28
@ -29,7 +29,7 @@ class WirelessAPSetup
|
|||||||
property main_ip_v6 : IPAddress | DHCP | Autoconfiguration | NotSetup
|
property main_ip_v6 : IPAddress | DHCP | Autoconfiguration | NotSetup
|
||||||
property aliasses_v4 : Array(IPAddress)
|
property aliasses_v4 : Array(IPAddress)
|
||||||
property aliasses_v6 : Array(IPAddress)
|
property aliasses_v6 : Array(IPAddress)
|
||||||
property dns : Array(IPAddress)
|
property dns : NetworkCommands::DNS
|
||||||
|
|
||||||
# we currently only support WPA2-PSK wireless security mechanism
|
# we currently only support WPA2-PSK wireless security mechanism
|
||||||
property security : WPA
|
property security : WPA
|
||||||
@ -46,7 +46,7 @@ class WirelessAPSetup
|
|||||||
@aliasses_v4 = Array(IPAddress).new
|
@aliasses_v4 = Array(IPAddress).new
|
||||||
@aliasses_v6 = Array(IPAddress).new
|
@aliasses_v6 = Array(IPAddress).new
|
||||||
@up = true
|
@up = true
|
||||||
@dns = Array(IPAddress).new
|
@dns = NetworkCommands::DNS.new
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@ -80,14 +80,25 @@ class WirelessAPSetup
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
dns.each do |ip|
|
dns.addresses.each do |ip|
|
||||||
str << "\t\tdns: #{ip}\n"
|
str << "\t\tdns: #{ip}\n"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
dns.search.each do |localdomain|
|
||||||
|
str << "\t\tdomain: #{localdomain}\n"
|
||||||
|
end
|
||||||
|
|
||||||
# to improve readability
|
# to improve readability
|
||||||
str << "\n"
|
str << "\n"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def execute
|
||||||
|
puts "TODO: wireless configuration"
|
||||||
|
|
||||||
|
# DNS configuration
|
||||||
|
dns.execute
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@ -107,14 +118,14 @@ class InterfaceConfiguration
|
|||||||
property aliasses_v4 : Array(IPAddress)
|
property aliasses_v4 : Array(IPAddress)
|
||||||
property aliasses_v6 : Array(IPAddress)
|
property aliasses_v6 : Array(IPAddress)
|
||||||
property wireless_networks : Hash(String, WirelessAPSetup)
|
property wireless_networks : Hash(String, WirelessAPSetup)
|
||||||
property dns : Array(IPAddress)
|
property dns : NetworkCommands::DNS
|
||||||
|
|
||||||
def initialize (@name, @up,
|
def initialize (@name, @up,
|
||||||
@description,
|
@description,
|
||||||
@mtu,
|
@mtu,
|
||||||
@main_ip_v4, @main_ip_v6, aliasses,
|
@main_ip_v4, @main_ip_v6, aliasses,
|
||||||
@wireless, @wireless_networks,
|
@wireless, @wireless_networks,
|
||||||
@dns = Array(IPAddress).new
|
@dns
|
||||||
)
|
)
|
||||||
|
|
||||||
@aliasses_v4 = Array(IPAddress).new
|
@aliasses_v4 = Array(IPAddress).new
|
||||||
@ -179,10 +190,12 @@ 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
|
||||||
|
|
||||||
unless dns.empty?
|
dns.addresses.each do |ip|
|
||||||
dns.each do |ip|
|
str << "\tdns: #{ip}\n"
|
||||||
str << "\tdns: #{ip}\n"
|
end
|
||||||
end
|
|
||||||
|
dns.search.each do |localdomain|
|
||||||
|
str << "\t\tdomain: #{localdomain}\n"
|
||||||
end
|
end
|
||||||
|
|
||||||
unless wireless_networks.empty?
|
unless wireless_networks.empty?
|
||||||
@ -270,6 +283,9 @@ class InterfaceConfiguration
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# DNS configuration
|
||||||
|
dns.execute
|
||||||
end
|
end
|
||||||
|
|
||||||
def down
|
def down
|
||||||
|
@ -9,16 +9,32 @@ class NetworkCommands
|
|||||||
class_property cmd_dhcp_client : UDHCPCCommand.class | DHClientCommand.class | NotSetup.class = NotSetup
|
class_property cmd_dhcp_client : UDHCPCCommand.class | DHClientCommand.class | NotSetup.class = NotSetup
|
||||||
|
|
||||||
class DNS
|
class DNS
|
||||||
def initialize(@addresses : Array(String), @search : Array(String))
|
property addresses : Array(String)
|
||||||
|
property search : Array(String)
|
||||||
|
|
||||||
|
def initialize()
|
||||||
|
@addresses = Array(String).new
|
||||||
|
@search = Array(String).new
|
||||||
end
|
end
|
||||||
|
|
||||||
def execute
|
def execute
|
||||||
File.open("#{Context.root}/etc/resolv.conf", "w") do |file|
|
Dir.mkdir_p("#{Context.root}/etc/")
|
||||||
|
|
||||||
|
if Context.simulation
|
||||||
|
puts "simulation, writing in #{Context.root}/etc/resolv.conf:"
|
||||||
@addresses.each do |address|
|
@addresses.each do |address|
|
||||||
file.puts "nameserver #{address}\n"
|
puts "\tnameserver #{address}\n"
|
||||||
end
|
end
|
||||||
|
|
||||||
file.puts "search #{@search.join(" ")}"
|
puts "\tsearch #{@search.join(" ")}" unless search.empty?
|
||||||
|
else
|
||||||
|
File.open("#{Context.root}/etc/resolv.conf", "w+") do |file|
|
||||||
|
@addresses.each do |address|
|
||||||
|
file.puts "nameserver #{address}\n"
|
||||||
|
end
|
||||||
|
|
||||||
|
file.puts "search #{@search.join(" ")}" unless search.empty?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -20,7 +20,7 @@ class NetworkConfigurationParser
|
|||||||
main_ip_v4 = NotSetup.new
|
main_ip_v4 = NotSetup.new
|
||||||
main_ip_v6 = NotSetup.new
|
main_ip_v6 = NotSetup.new
|
||||||
|
|
||||||
dns = Array(IPAddress).new
|
dns = NetworkCommands::DNS.new
|
||||||
|
|
||||||
aliasses = [] of IPAddress
|
aliasses = [] of IPAddress
|
||||||
|
|
||||||
@ -170,7 +170,7 @@ class NetworkConfigurationParser
|
|||||||
|
|
||||||
access_point = wireless_networks[ssid].not_nil!
|
access_point = wireless_networks[ssid].not_nil!
|
||||||
ipaddr = IPAddress.parse ipstr
|
ipaddr = IPAddress.parse ipstr
|
||||||
access_point.dns << ipaddr
|
access_point.dns.addresses << ipaddr.to_s
|
||||||
|
|
||||||
when /^mtu [0-9]+/
|
when /^mtu [0-9]+/
|
||||||
mtu = /^mtu ([0-9]+)/.match(line).try &.[1].to_i
|
mtu = /^mtu ([0-9]+)/.match(line).try &.[1].to_i
|
||||||
@ -188,7 +188,7 @@ class NetworkConfigurationParser
|
|||||||
end
|
end
|
||||||
|
|
||||||
ipaddr = IPAddress.parse ipstr
|
ipaddr = IPAddress.parse ipstr
|
||||||
dns << ipaddr
|
dns.addresses << ipaddr.to_s
|
||||||
|
|
||||||
when /^#.*$/
|
when /^#.*$/
|
||||||
# simple comment
|
# simple comment
|
||||||
|
Loading…
Reference in New Issue
Block a user