Skip to content

Commit

Permalink
Read the firewalld configuration offering custom zones selection
Browse files Browse the repository at this point in the history
  • Loading branch information
teclator committed Feb 1, 2019
1 parent 0551f3d commit d66a911
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 34 deletions.
26 changes: 13 additions & 13 deletions src/include/network/lan/address.rb
Expand Up @@ -27,10 +27,11 @@
# Authors: Michal Svec <msvec@suse.cz>
#
require "ui/text_helpers"
require "y2firewall/firewalld"
require "y2firewall/helpers/interfaces"

module Yast
module NetworkLanAddressInclude
include Y2Firewall::Helpers::Interfaces
include Yast::Logger
include ::UI::TextHelpers

Expand Down Expand Up @@ -1053,7 +1054,7 @@ def InitFwZone(_key)
UI.ChangeWidget(
Id("FWZONE"),
:Value,
Ops.get_string(@settings, "FWZONE", "")
current_zone
)
else
UI.ChangeWidget(Id("FWZONE"), :Enabled, false)
Expand All @@ -1062,6 +1063,14 @@ def InitFwZone(_key)
nil
end

def current_zone
ifcfg_zone = NetworkInterfaces.Current["ZONE"]
return ifcfg_zone if ifcfg_zone
zone = interface_zone(LanItems.device)
return if zone.nil?
zone.name
end

# @param [Array<String>] types network card types
# @return their descriptions for CWM
def BuildTypesListCWM(types)
Expand Down Expand Up @@ -1426,7 +1435,7 @@ def initialize_address_settings
"STARTMODE" => LanItems.startmode,
"IFPLUGD_PRIORITY" => LanItems.ifplugd_priority,
# problems when renaming the interface?
"FWZONE" => LanItems.firewall_zone,
"FWZONE" => current_zone,
"MTU" => LanItems.mtu,
# address tab:
"BOOTPROTO" => LanItems.bootproto,
Expand Down Expand Up @@ -1557,21 +1566,12 @@ def initial_hostname(ipaddr)
def firewall_zones
zones = [["", _("Automatically Assigned Zone")]]
if firewalld.installed?
Y2Firewall::Firewalld::Zone.known_zones.map do |name, full_name|
zones << [name, Builtins.dgettext("base", full_name)]
end
firewalld.zones.each { |z| zones << [z.name, z.short] }
else
zones = [["", _("Firewall is not installed.")]]
end

zones
end

# Convenience method which returns an instance of Y2Firewall::Firewalld
#
# @return [Y2Firewall::Firewalld] instance
def firewalld
@firewalld ||= Y2Firewall::Firewalld.instance
end
end
end
58 changes: 38 additions & 20 deletions src/modules/Lan.rb
Expand Up @@ -32,6 +32,7 @@
require "yast"
require "network/confirm_virt_proposal"
require "ui/text_helpers"
require "y2firewall/firewalld"

require "shellwords"

Expand Down Expand Up @@ -226,6 +227,30 @@ def readIPv6
ipv6
end

def read_step_labels
steps = [
# Progress stage 1/8
_("Detect network devices"),
# Progress stage 2/8
_("Read driver information"),
# Progress stage 3/8 - multiple devices may be present, really plural
_("Read device configuration"),
# Progress stage 4/8
_("Read network configuration"),
# Progress stage 5/8
_("Read hostname and DNS configuration"),
# Progress stage 6/8
_("Read installation information"),
# Progress stage 7/8
_("Read routing configuration"),
# Progress stage 8/8
_("Detect current status")
]

steps << _("Read firewall configuration") if firewalld.installed?
steps
end

# Read all network settings from the SCR
# @param cache [Symbol] :cache=use cached data, :nocache=reread from disk TODO pass to submodules
# @return true on success
Expand All @@ -237,7 +262,6 @@ def Read(cache)

# Read dialog caption
caption = _("Initializing Network Configuration")
steps = 9

sl = 0 # 1000; /* TESTING
Builtins.sleep(sl)
Expand All @@ -246,25 +270,8 @@ def Read(cache)
Progress.New(
caption,
" ",
steps,
[
# Progress stage 1/8
_("Detect network devices"),
# Progress stage 2/8
_("Read driver information"),
# Progress stage 3/8 - multiple devices may be present, really plural
_("Read device configuration"),
# Progress stage 4/8
_("Read network configuration"),
# Progress stage 5/8
_("Read hostname and DNS configuration"),
# Progress stage 6/8
_("Read installation information"),
# Progress stage 8/8
_("Read routing configuration"),
# Progress stage 9/8
_("Detect current status")
],
read_step_labels.size,
read_step_labels,
[],
""
)
Expand Down Expand Up @@ -348,6 +355,13 @@ def Read(cache)
NetworkService.Read
Builtins.sleep(sl)

return false if Abort()
if firewalld.installed? && !firewalld.read?
ProgressNextStage(_("Reading firewall configuration...")) if @gui
firewalld.read
Builtins.sleep(sl)
end

return false if Abort()
rescue IOError, SystemCallError, RuntimeError => error
msg = format(_("Network configuration is corrupted.\n"\
Expand Down Expand Up @@ -1061,6 +1075,10 @@ def refresh_lan_items
# cache was edited directly, LanItems is not aware of changes.
LanItems.SetModified
end

def firewalld
Y2Firewall::Firewalld.instance
end
end

Lan = LanClass.new
Expand Down
1 change: 0 additions & 1 deletion src/modules/LanItems.rb
Expand Up @@ -1715,7 +1715,6 @@ def SetDeviceVars(devmap, defaults)
@prefix = d["PREFIXLEN"]
@remoteip = d["REMOTE_IPADDR"]
@netmask = d["NETMASK"]
@firewall_zone = d["ZONE"]
@set_default_route = case d["DHCLIENT_SET_DEFAULT_ROUTE"]
when "yes" then true
when "no" then false
Expand Down

0 comments on commit d66a911

Please sign in to comment.