Skip to content

Commit

Permalink
Merge 2ac788f into b6f4dab
Browse files Browse the repository at this point in the history
  • Loading branch information
jreidinger committed Nov 30, 2018
2 parents b6f4dab + 2ac788f commit 7099cc4
Show file tree
Hide file tree
Showing 10 changed files with 487 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/lib/y2firewall/dialogs/main.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

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

module Y2Firewall
module Dialogs
Expand Down Expand Up @@ -95,7 +96,7 @@ def abort_button

# @return [Boolean] it aborts if returns true
def abort_handler
true
Yast::Popup.ReallyAbort(fw.modified?)
end

# @return [Boolean] it goes back if returns true
Expand Down
69 changes: 69 additions & 0 deletions src/lib/y2firewall/dialogs/zone.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# 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"

module Y2Firewall
module Dialogs
# Dialog for add/modify zone
class Zone < CWM::Popup
# @param zone [Y2Firewall::Firewalld::Zone] holder for configuration or
# existing zone
# @param new_zone [Boolean] if it creates new zone or edit existing
def initialize(zone, new_zone = false)
textdomain "firewall"
@zone = zone
@new_zone = new_zone
end

def title
@new_zone ? _("Adding new zone") : format(_("Editing zone '%s'") % @zone.name)
end

def contents
MinWidth(70,
VBox(
# do not allow to change name for already created zone
Left(NameWidget.new(@zone, disabled: !@new_zone)),
VSpacing(1),
Left(ShortWidget.new(@zone)),
VSpacing(1),
Left(DescriptionWidget.new(@zone)),
VSpacing(1),
Left(TargetWidget.new(@zone)),
VSpacing(1),
Left(MasqueradeWidget.new(@zone))
))
end

def abort_button
Yast::Label.CancelButton
end

private

def min_height
10
end
end
end
end
8 changes: 6 additions & 2 deletions src/lib/y2firewall/widgets/allowed_services.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,14 @@ def help
end

def validate
# check for missed selection in ncurses only as in qt selected entries is basically
# just highlight and after move it is still selected, so more confusing.
return true unless Yast::UI.TextMode

return true if selected_services.empty?
# TRANSLATORS: popup question
msg = _("The selection of services will be lost if you leave without\n" \
"applying the changes.\n\nDo you really want to continue?\n")
msg = _("The selection of services will be lost if you leave the page\n" \
"without moving them with Add/Remove.\n\nDo you really want to continue?\n")

Yast::Popup.YesNo(msg)
end
Expand Down
78 changes: 75 additions & 3 deletions src/lib/y2firewall/widgets/pages/zones.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,15 @@
# ------------------------------------------------------------------------------

require "yast"
require "yast2/popup"
require "cwm/page"
require "y2firewall/firewalld"
require "y2firewall/helpers/interfaces"
require "y2firewall/ui_state"
require "y2firewall/dialogs/zone"
require "y2firewall/widgets/zones_table"
require "y2firewall/widgets/pages/zone"
require "y2firewall/widgets/zone_button"
require "y2firewall/helpers/interfaces"
require "y2firewall/widgets/default_zone_button"

module Y2Firewall
Expand Down Expand Up @@ -51,13 +56,80 @@ def contents
return @contents if @contents
@contents = VBox(
Left(Heading(_("Zones"))),
ZonesTable.new(firewall.zones, known_interfaces, default_zone_button),
firewall.zones.empty? ? Empty() : default_zone_button
zones_table,
Left(
HBox(
AddButton.new(self, zones_table),
EditButton.new(self, zones_table),
RemoveButton.new(self, zones_table),
firewall.zones.empty? ? Empty() : default_zone_button
)
)
)
end

# Add zone button
class AddButton < ZoneButton
def label
_("Add")
end

def handle
zone = Y2Firewall::Firewalld::Zone.new(name: "draft")
result = Dialogs::Zone.run(zone, true)
if result == :ok
zone.relations.map { |r| zone.send("#{r}=", []) }
firewall.zones << zone
UIState.instance.select_row(zone.name)

return :redraw
end

nil
end
end

# Edit zone button
class EditButton < ZoneButton
def label
_("Edit")
end

def handle
zone = firewall.find_zone(@table.value.to_s)
name = zone.name
result = Dialogs::Zone.run(zone)
UIState.instance.select_row(name) if result == :ok

result == :ok ? :redraw : nil
end
end

# Remove zone button
class RemoveButton < ZoneButton
def label
_("Remove")
end

def handle
zone = firewall.find_zone(@table.value.to_s)
if Y2Firewall::Firewalld::Zone.known_zones.key?(zone.name)
Yast2::Popup.show(_("Builtin zone cannot be removed."), headline: :error)
return nil
end

firewall.remove_zone(zone.name)

:redraw
end
end

private

def zones_table
@zones_table ||= ZonesTable.new(firewall.zones, known_interfaces, default_zone_button)
end

def default_zone_button
return nil if firewall.zones.empty?
@default_zone_button ||= DefaultZoneButton.new(firewall.zones.first)
Expand Down
182 changes: 182 additions & 0 deletions src/lib/y2firewall/widgets/zone.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
# encoding: utf-8

# Copyright (c) [2017] 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 "y2firewall/widgets/zone"
require "cwm/widget"

module Y2Firewall
module Dialogs
# Name of zone. Can be disabled for modification
class NameWidget < CWM::InputField
include Yast::I18n

def initialize(zone, disabled: false)
textdomain "textdomain"
@zone = zone
@disabled = disabled
end

def init
self.value = @zone.name
@disabled ? disable : enable
end

def label
_("Name")
end

def validate
return true if value.to_s.match?(/^\w+$/)

Yast::Report.Error(_("Please, provide a valid alphanumeric name for the zone"))
focus
false
end

def store
@zone.name = value
end

# Sets the focus into this widget
def focus
Yast::UI.SetFocus(Id(widget_id))
end
end

# short name of zone.
class ShortWidget < CWM::InputField
include Yast::I18n

def initialize(zone)
textdomain "textdomain"
@zone = zone
end

def init
self.value = @zone.short
end

def label
_("Short")
end

def validate
return true unless value.to_s.empty?

Yast::Report.Error(_("Please, provide a short name for the zone"))
focus
false
end

def store
@zone.short = value
end

# Sets the focus into this widget
# TODO: move to CWM itself
def focus
Yast::UI.SetFocus(Id(widget_id))
end
end

# textual description of widget
# TODO: does not show nicely for long description
class DescriptionWidget < CWM::InputField
include Yast::I18n

def initialize(zone)
textdomain "textdomain"
@zone = zone
end

def init
self.value = @zone.description
end

def label
_("Description")
end

def validate
return true unless value.to_s.empty?

Yast::Report.Error(_("Please, provide a description for the zone"))
focus
false
end

def store
@zone.description = value
end

# Sets the focus into this widget
# TODO: move to CWM itself
def focus
Yast::UI.SetFocus(Id(widget_id))
end
end

# target of zone
class TargetWidget < CWM::ComboBox
def initialize(zone)
@zone = zone
end

def label
_("Target")
end

def init
self.value = @zone.target || "default"
end

def items
["default", "ACCEPT", "%%REJECT%%", "DROP"].map { |s| [s, s] }
end

def store
@zone.target = value
end
end

# enabling masquerade for zone
class MasqueradeWidget < CWM::CheckBox
include Yast::I18n

def initialize(zone)
textdomain "textdomain"
@zone = zone
end

def label
_("Masquerade")
end

def init
self.value = !!@zone.masquerade?
end

def store
@zone.masquerade = value
end
end
end
end

0 comments on commit 7099cc4

Please sign in to comment.