Skip to content

Commit

Permalink
Merge 9616059 into 4d10c98
Browse files Browse the repository at this point in the history
  • Loading branch information
mvidner committed Sep 21, 2018
2 parents 4d10c98 + 9616059 commit d9c1daf
Show file tree
Hide file tree
Showing 50 changed files with 2,998 additions and 91 deletions.
9 changes: 9 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# EditorConfig is awesome: https://EditorConfig.org

# top-most EditorConfig file
root = true

# 2 space indentation
[*.rb]
indent_style = space
indent_size = 2
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ script:
# the "yast-travis-ruby" script is included in the base yastdevel/ruby image
# see https://github.com/yast/docker-yast-ruby/blob/master/yast-travis-ruby
- docker run -it -e TRAVIS=1 -e TRAVIS_JOB_ID="$TRAVIS_JOB_ID" yast-firewall-image yast-travis-ruby
- docker run -it -e TRAVIS=1 -e TRAVIS_JOB_ID="$TRAVIS_JOB_ID" yast-firewall-image rake check:doc
7 changes: 7 additions & 0 deletions .yardopts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
--no-private
--protected
--markup markdown
--readme README.md
--output-dir ./doc/autodocs
--files **/*.md
src/**/*.rb
8 changes: 4 additions & 4 deletions package/yast2-firewall.spec
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ License: GPL-2.0
BuildRequires: perl-XML-Writer update-desktop-files yast2-testsuite
BuildRequires: yast2-devtools >= 3.1.10

# Firewalld read?
BuildRequires: yast2 >= 4.0.45
# Y2Firewall::Firewalld::Interface
BuildRequires: yast2 >= 4.0.96
BuildRequires: rubygem(%rb_default_ruby_abi:yast-rake)
BuildRequires: rubygem(%rb_default_ruby_abi:rspec)

# Firewalld - extended API
Requires: yast2 >= 4.0.49
# Y2Firewall::Firewalld::Interface
Requires: yast2 >= 4.0.96

# ButtonBox widget
Conflicts: yast2-ycp-ui-bindings < 2.17.3
Expand Down
22 changes: 11 additions & 11 deletions src/include/firewall/uifunctions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -496,10 +496,10 @@ def HandleFirewallInterfaces(key, event)
# @return [Boolean] whether user accepts the port definition despite the warning.
#
# @example
# // maximum port number is 65535, port range
# boolean accepted = ReportWrongPortDefinition(99999, "5:99999");
# // dtto., single port
# boolean whattodo = ReportWrongPortDefinition(78910, "78910");
# // maximum port number is 65535, port range
# boolean accepted = ReportWrongPortDefinition(99999, "5:99999");
# // dtto., single port
# boolean whattodo = ReportWrongPortDefinition(78910, "78910");
def ReportWrongPortDefinition(port_nr, port_definition)
port_err = ""

Expand Down Expand Up @@ -554,7 +554,7 @@ def CheckPortNameDefinition(port_name)
# Function checks list of ports if they exist (are known).
#
# @param [Object] ui_id for the setfocus
# @param list <string> of ports to be checked
# @param ports [Array<String>] of ports to be checked
def CheckIfTheyAreAllKnownPorts(ui_id, ports)
ui_id = deep_copy(ui_id)
ports = deep_copy(ports)
Expand Down Expand Up @@ -978,7 +978,7 @@ def HandleAllowedServices(key, event)

# Function sets UI for Masquerade Table (and buttons) enabled or disabled
#
# @param boolean enable
# @param usable [Boolean] enable
def SetMasqueradeTableUsable(usable)
UI.ChangeWidget(Id("table_redirect_masq"), :Enabled, usable)
UI.ChangeWidget(Id("add_redirect_to_masquerade"), :Enabled, usable)
Expand Down Expand Up @@ -1069,8 +1069,8 @@ def InitMasquerading(key)
# Validates existency of a value in a referenced UI entry
# and reports error otherwise
#
# @param any UI id
# @report boolean if value exists
# @param ui_id [String] any UI id
# @return [Boolean] true if value exists
def ValidateExistency(ui_id)
ui_id = deep_copy(ui_id)
if UI.QueryWidget(Id(ui_id), :Value) == ""
Expand All @@ -1085,7 +1085,7 @@ def ValidateExistency(ui_id)
# Checks whether the referenced UI entry contains a valid
# port definition and reports an error otherwise
#
# @param any UI id
# @param ui_id [String] any UI id
# @return [Boolean] if entry is valid
def ValidatePortEntry(ui_id)
ui_id = deep_copy(ui_id)
Expand Down Expand Up @@ -1116,7 +1116,7 @@ def ValidatePortEntry(ui_id)
# Function checks port number got as parameter.
# If check fails SetFocus is called and an empty string is returned.
#
# @param any UI id
# @param ui_id [String] any UI id
# @return [Fixnum] port number (or nil)
def GetPortNumber(ui_id)
ui_id = deep_copy(ui_id)
Expand Down Expand Up @@ -1144,7 +1144,7 @@ def GetPortNumber(ui_id)
# Checks whether the referenced UI entry contains a valid IPv4 or v6
# and reports error otherwise.
#
# @param any UI id
# @param ui_id [String] any UI id
# @return [Boolean] whether it's valid IP
def ValidateIPEntry(ui_id)
ui_id = deep_copy(ui_id)
Expand Down
3 changes: 1 addition & 2 deletions src/lib/y2firewall/clients/auto.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,7 @@ def read
# A map with the packages that needs to be installed or removed for
# configuring firewalld properly
#
# @return packages [Hash{String => Array<String>} ] of packages to be
# installed or removed
# @return [Hash{String => Array<String>} ] of packages to be installed or removed
def packages
{ "install" => ["firewalld"], "remove" => [] }
end
Expand Down
27 changes: 12 additions & 15 deletions src/lib/y2firewall/clients/firewall.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
require "yast"
require "yast2/execute"
require "ui/text_helpers"
require "y2firewall/dialogs/main"

Yast.import "UI"
Yast.import "Popup"
Yast.import "PackageSystem"

module Y2Firewall
module Clients
Expand All @@ -34,31 +39,23 @@ class Firewall

# Constructor
def initialize
Yast.import "UI"
Yast.import "Popup"
Yast.import "PackageSystem"

textdomain "firewall"
end

# TRANSLATORS: firewall-config and firewall-cmd are the names of software utilities,
# so they should not be translated.
NOT_SUPPORTED = N_("YaST currently does not have a module for configuring" \
" firewall. Please, either use \"firewall-config\" to configure your firewall" \
" via a user interface or \"firewall-cmd\" for the command line.").freeze
NOT_SUPPORTED = N_("YaST does not support the command line for " \
"configuring the firewall.\nInstead, please use the firewalld " \
"command line clients \"firewalld-cmd\" or \"firewall-offline-cmd\".")

def run
log_and_return do
return :abort unless Yast::PackageSystem.CheckAndInstallPackages(["firewalld"])
if !Yast::WFM.Args.empty?
$stderr.puts wrap_text(_(NOT_SUPPORTED))
false
elsif Yast::UI.TextMode()
Yast::Popup.Error(
wrap_text(_(NOT_SUPPORTED))
)
$stderr.puts _(NOT_SUPPORTED)
false
elsif Yast::PackageSystem.CheckAndInstallPackages(["firewall-config"])
Yast::Execute.locally("/usr/bin/firewall-config")
else
Dialogs::Main.new.run
end
end
end
Expand Down
68 changes: 68 additions & 0 deletions src/lib/y2firewall/dialogs/change_zone.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# 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/popup"
require "y2firewall/widgets/zone_options"

module Y2Firewall
module Dialogs
# This dialog allows the user to select which zone should be an interface assigned to.
class ChangeZone < ::CWM::Popup
# @!attribute [r] interface
# @return [Y2Firewall::Firewalld::Interface] Interface to act on
attr_reader :interface

# Constructor
#
# @param interface [Y2Firewall::Firewalld::Interface] Interface to act on
def initialize(interface)
textdomain "firewall"
@interface = interface
end

# @macro seeAbstractWidget
def title
_("Change Zone")
end

# @macro seeCustomWidget
def contents
VBox(zone_options)
end

private

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

# Returns a combobox to select the zone
#
# @note The widget is 'memoized'.
#
# @return [Y2Firewall::Widgets::ZoneOptions]
def zone_options
@zone_options ||= Y2Firewall::Widgets::ZoneOptions.new(interface)
end
end
end
end
126 changes: 126 additions & 0 deletions src/lib/y2firewall/dialogs/main.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
# encoding: utf-8

# ------------------------------------------------------------------------------
# Copyright (c) 2018 SUSE LLC
#
#
# 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.
#
# To contact SUSE about this file by physical or electronic mail, you may find
# current contact information at www.suse.com.
# ------------------------------------------------------------------------------

require "yast"
require "cwm/dialog"
require "y2firewall/widgets/overview_tree_pager"

Yast.import "Label"

module Y2Firewall
module Dialogs
# Main entry point to Firewall showing tree pager with all content
class Main < CWM::Dialog
# Constructor
def initialize
Yast.import "NetworkInterfaces"
textdomain "firewall"

Yast::NetworkInterfaces.Read
fw.read
end

def title
_("Firewall")
end

def contents
MarginBox(
0.5,
0.5,
Widgets::OverviewTreePager.new
)
end

# Runs the dialog
#
# @return [Symbol] result of the dialog
def run
result = nil

loop do
result = super
swap_api if result == :swap_mode
break unless continue_running?(result)
end

apply_changes if result == :next
result
end

def skip_store_for
[:redraw]
end

def back_button
# do not show back button when running on running system. See CWM::Dialog.back_button
""
end

def next_button
Yast::Label.AcceptButton
end

def abort_button
Yast::Label.AbortButton
end

# @return [Boolean] it aborts if returns true
def abort_handler
true
end

# @return [Boolean] it goes back if returns true
def back_handler
true
end

private

# Whether the dialog run loop should continue or not
#
# @return [Boolean] true in case of a dialog redraw or an api change
def continue_running?(result)
result == :redraw || result == :swap_mode
end

# Convenience method which return an instance of Y2Firewall::Firewalld
#
# @return [Y2Firewall::Firewalld] a firewalld instance
def fw
Y2Firewall::Firewalld.instance
end

# Modify the firewalld API instance in case the systemd service state has
# changed.
def swap_api
fw.api = Y2Firewall::Firewalld::Api.new
end

# Writes down the firewall configuration and the systemd service
# modifications
def apply_changes
fw.write_only
fw.system_service.save
end
end
end
end
8 changes: 4 additions & 4 deletions src/lib/y2firewall/importer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ class Importer
include Yast::Logger
# Import the given configuration
#
# @param [Hash] AutoYaST profile firewall's section
# @param profile [Hash] AutoYaST profile firewall's section
# @return [true,nil] return true if success; return nil if the given
# profile is empty
# profile is empty
def import(profile)
return if profile.empty?

Expand Down Expand Up @@ -61,9 +61,9 @@ def import(profile)
#
# importer.strategy_for(profile) #=> Y2Firewall::ImporterStrategies::Firewalld
#
# @param [Hash] AutoYaST profile firewall's section
# @param profile [Hash] AutoYaST profile firewall's section
# @return [ImporterStrategies::SuseFirewall,ImporterStrategies::Firewalld]
# the importer strategy to be used for importing.
# the importer strategy to be used for importing.
def strategy_for(profile)
return ImporterStrategies::SuseFirewall if profile.any? { |k, _v| k.start_with?("FW_") }

Expand Down

0 comments on commit d9c1daf

Please sign in to comment.