Skip to content

Commit

Permalink
Merge branch 'SLE-15-GA' into merge_SLE-15-GA
Browse files Browse the repository at this point in the history
  • Loading branch information
teclator committed Oct 17, 2018
2 parents 8d4012f + 1f9eb73 commit a780c3e
Show file tree
Hide file tree
Showing 21 changed files with 943 additions and 165 deletions.
31 changes: 31 additions & 0 deletions package/yast2-firewall.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,34 @@
-------------------------------------------------------------------
Tue Oct 16 20:34:32 UTC 2018 - knut.anderssen@suse.com

- Fixed zone_options widget test mocking (fate#324662)
- 4.0.32

-------------------------------------------------------------------
Wed Oct 10 08:17:09 UTC 2018 - knut.anderssen@suse.com

- Small improvements to the widget for modifying the assignation
of interfaces to zones (fate##324662):
- Permits to split the input field entry by any combination of
spaces or commas.
- Initialize the zone selector with the default zone.
- 4.0.31

-------------------------------------------------------------------
Tue Oct 9 08:55:56 UTC 2018 - knut.anderssen@suse.com

- Alert the user about unsaved changes when leaving the zone
services configuration without applying changes (fate#324662)
- 4.0.30

-------------------------------------------------------------------
Fri Oct 5 06:49:03 UTC 2018 - knut.anderssen@suse.com

- AutoYaST configuration: Added support to editing and resetting
the current configuration. Improved the writing process
(fate324662).
- 4.0.29

-------------------------------------------------------------------
Tue Oct 2 11:52:27 UTC 2018 - knut.anderssen@suse.com

Expand Down
10 changes: 5 additions & 5 deletions package/yast2-firewall.spec
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@


Name: yast2-firewall
Version: 4.0.28
Version: 4.0.32
Release: 0

BuildRoot: %{_tmppath}/%{name}-%{version}-build
Expand All @@ -28,13 +28,13 @@ License: GPL-2.0-only
BuildRequires: perl-XML-Writer update-desktop-files yast2-testsuite
BuildRequires: yast2-devtools >= 3.1.10

# Y2Firewall::Firewalld::Interface
BuildRequires: yast2 >= 4.1.17
# Y2Firewall::Firewalld#reset
BuildRequires: yast2 >= 4.1.21
BuildRequires: rubygem(%rb_default_ruby_abi:yast-rake)
BuildRequires: rubygem(%rb_default_ruby_abi:rspec)

# Y2Firewall::Firewalld::Interface
Requires: yast2 >= 4.1.17
# Y2Firewall::Firewalld#reset
Requires: yast2 >= 4.1.21

# ButtonBox widget
Conflicts: yast2-ycp-ui-bindings < 2.17.3
Expand Down
125 changes: 50 additions & 75 deletions src/lib/y2firewall/clients/auto.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,13 @@
require "y2firewall/firewalld"
require "y2firewall/importer"
require "y2firewall/proposal_settings"
require "y2firewall/summary_presenter"
require "y2firewall/dialogs/main"
require "installation/auto_client"

Yast.import "Mode"
Yast.import "AutoInstall"

module Y2Firewall
module Clients
# This is a client for autoinstallation. It takes its arguments,
Expand All @@ -33,9 +38,6 @@ module Clients
class Auto < ::Installation::AutoClient
include Yast::Logger

Yast.import "HTML"
Yast.import "AutoInstall"

class << self
# @return [Boolean] whether the AutoYaST configuration has been
# modified or not
Expand All @@ -51,6 +53,9 @@ class << self
attr_accessor :start
# @return [Hash]
attr_accessor :profile
# @return [Boolean] whether the AutoYaST configuration has been
# modified or not
attr_accessor :ay_config
end

# Constructor
Expand All @@ -62,28 +67,20 @@ def initialize
#
# @return [String]
def summary
return Yast::HTML.Para(_("Firewalld is not available")) if !firewalld.installed?

firewalld.read if !firewalld.read?

# general overview
summary = general_summary

# per zone details
firewalld.zones.each do |zone|
summary << zone_summary(zone)
end
presenter = Y2Firewall::SummaryPresenter.new(firewalld)
return presenter.not_installed if !firewalld.installed?
return presenter.not_configured if !modified?

summary
presenter.create
end

# Import the firewall configuration
#
# @param profile [Hash] firewall profile section to be imported
# @return [Boolean]
def import(profile)
def import(profile, merge = !Yast::Mode.config)
self.class.profile = profile
return false unless read
return false if merge && !read(force: false)

# Obtains the default from the control file (settings) if not present.
enable if profile.fetch("enable_firewall", settings.enable_firewall)
Expand All @@ -104,32 +101,46 @@ def export
#
# @return [Boolean]
def reset
importer.import({})
firewalld.reset
self.class.ay_config = false
self.class.changed = false
end

def change
log.info "#{self.class}#change not implemented yet, returning :next."

:next
self.class.imported = false
result = Dialogs::Main.new.run
case result
when :next, :finish, :ok, :accept
self.class.ay_config = true
end
result
end

# Write the imported configuration to firewalld. If for some reason the
# configuration was not imported from the profile, it tries to import
# it again.
def write
return false if !firewalld.installed?
import(self.class.profile) unless imported?
import_if_needed
return false unless imported?

firewalld.write
activate_service
firewalld.write if firewalld.modified?

if ay_config?
firewalld.reset
firewalld.read(minimal: true)
import(self.class.profile, false)
else
activate_service
end
end

# Read the currnet firewalld configuration
def read
def read(force: true)
return false if !firewalld.installed?
return true if firewalld.read?
return true if firewalld.read? && !force

modified
firewalld.read
end

Expand All @@ -151,6 +162,19 @@ def modified?

private

def import_if_needed
if ay_config?
self.class.profile = firewalld.export
self.class.imported = false
end

import(self.class.profile) if self.class.profile && !imported?
end

def ay_config?
!!self.class.ay_config
end

# Semantic AutoYaST profile check
#
# Problems will be stored in AutoInstall.issues_list.
Expand Down Expand Up @@ -227,55 +251,6 @@ def imported
def imported?
!!self.class.imported
end

# Creates a piece for summary for zone detail
#
# See has_many (@see Y2Firewall::Firewalld::Relations#has_many) in
# Y2Firewall::Firewalld::Zone for known detail / relations
#
# @param [String] relation is name of relation (used as a caption for generated blob)
# @param [Array<String>] names details to be formated
# @return [<String>] A string formated using Yast::HTML methods
def zone_detail_summary(relation, names)
return "" if names.nil? || names.empty?

Yast::HTML.Bold("#{relation.capitalize}:") + Yast::HTML.List(names)
end

# Creates a summary for the given zone
#
# @param [Firewalld::Zone] zone object defining a zone
# @return [String] HTML formated zone description
def zone_summary(zone)
raise ArgumentError, "zone parameter has to be defined" if zone.nil?

desc = zone.relations.map do |relation|
zone_detail_summary(relation, zone.send(relation))
end.delete_if(&:empty?)
return "" if desc.empty?

summary = Yast::HTML.Heading(zone.name)
summary << Yast::HTML.List(desc)
end

# Creates a general summary for firewalld
#
# @return [String] HTML formated firewall description
# rubocop:disable Metrics/AbcSize
def general_summary
html = Yast::HTML
running = " " + (firewalld.running? ? _("yes") : _("no"))
enabled = " " + (firewalld.enabled? ? _("yes") : _("no"))

summary = html.Bold(_("Running:")) + running + html.Newline
summary << html.Bold(_("Enabled:")) + enabled + html.Newline
summary << html.Bold(_("Default zone:")) + " " + firewalld.default_zone + html.Newline
summary << html.Bold(_("Defined zones:"))
summary << html.List(firewalld.zones.map(&:name))

html.Para(summary)
end
# rubocop:enable Metrics/AbcSize
end
end
end
17 changes: 14 additions & 3 deletions src/lib/y2firewall/dialogs/main.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
require "y2firewall/widgets/overview_tree_pager"

Yast.import "Label"
Yast.import "Mode"

module Y2Firewall
module Dialogs
Expand All @@ -34,8 +35,17 @@ def initialize
Yast.import "NetworkInterfaces"
textdomain "firewall"

Yast::NetworkInterfaces.Read
fw.read
if Yast::Mode.config
fw.read(minimal: true) unless fw.read?
else
Yast::NetworkInterfaces.Read
fw.read unless fw.read?
end
end

def should_open_dialog?
return true if Yast::Mode.config
super
end

def title
Expand Down Expand Up @@ -80,7 +90,7 @@ def next_button
end

def abort_button
Yast::Label.AbortButton
Yast::Mode.config ? Yast::Label.CancelButton : Yast::Label.AbortButton
end

# @return [Boolean] it aborts if returns true
Expand Down Expand Up @@ -118,6 +128,7 @@ def swap_api
# Writes down the firewall configuration and the systemd service
# modifications
def apply_changes
return false if Yast::Mode.config
fw.write_only
fw.system_service.save
end
Expand Down
77 changes: 77 additions & 0 deletions src/lib/y2firewall/dialogs/modify_zone_interfaces.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# encoding: utf-8

# Copyright (c) [2018] SUSE LLC
#
# All Rights Reserved.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of version 2 of the GNU General Public License as published
# by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, contact SUSE LLC.
#
# To contact SUSE LLC about this file by physical or electronic mail, you may
# find current contact information at www.suse.com.

require "cwm"
require "cwm/popup"
require "y2firewall/widgets/modify_zone_interfaces"

module Y2Firewall
module Dialogs
# This dialog allows the user to modify the interfaces belonging to a
# specific zone.
class ModifyZoneInterfaces < ::CWM::Popup
# Constructor
def initialize
textdomain "firewall"
end

# @macro seeAbstractWidget
def title
_("Modify Interfaces")
end

# @macro seeCustomWidget
def contents
VBox(
zone_chooser(zone_interfaces),
zone_interfaces
)
end

private

# @return [Array<Yast::Term>] List of buttons to display
def buttons
[ok_button, cancel_button]
end

# Returns a combo box to select the zone
#
# @note The widget is 'memoized'.
#
# @param interfaces_input [CWM::InputField] input field for modifying the
# selected zone interfaces
# @return [Y2Firewall::Widgets::ZoneInterfacesSelector]
def zone_chooser(interfaces_input)
@zone_chooser ||= Y2Firewall::Widgets::ZoneInterfacesSelector.new(interfaces_input)
end

# Returns a input field to modify the zone interfaces
#
# @note The widget is 'memoized'.
#
# @return [Y2Firewall::Widgets::ZoneInterfaces]
def zone_interfaces
@zone_interfaces ||= Y2Firewall::Widgets::ZoneInterfaces.new
end
end
end
end

0 comments on commit a780c3e

Please sign in to comment.