From: Goldwyn Rodrigues
This is a precursor to use aa-status json profile view.
Please note, "Configure" option is left hanging which will be filled
in the next patch.
Signed-off-by: Goldwyn Rodrigues
---
src/clients/apparmor-settings.rb | 139 ++++++++++++++++++++++++---------------
1 file changed, 85 insertions(+), 54 deletions(-)
diff --git a/src/clients/apparmor-settings.rb b/src/clients/apparmor-settings.rb
index ecea5bc..2b2d3f2 100644
--- a/src/clients/apparmor-settings.rb
+++ b/src/clients/apparmor-settings.rb
@@ -1,8 +1,6 @@
-# encoding: utf-8
-
# ***************************************************************************
#
-# Copyright (c) 2002 - 2012 Novell, Inc.
+# Copyright (c) 2017 SUSE Linux
# All Rights Reserved.
#
# This program is free software; you can redistribute it and/or
@@ -17,71 +15,104 @@
# You should have received a copy of the GNU General Public License
# along with this program; if not, contact Novell, Inc.
#
-# To contact Novell about this file by physical or electronic mail,
-# you may find current contact information at www.novell.com
+# To contact SuSE about this file by physical or electronic mail,
+# you may find current contact information at www.suse.com
#
# ***************************************************************************
-module Yast
- class ApparmorSettingsClient < Client
- def main
- Yast.import "UI"
-
- textdomain "yast2-apparmor"
- # The main ()
- Builtins.y2milestone("----------------------------------------")
- Builtins.y2milestone("AppArmor module started")
+require "yast"
- Yast.import "Label"
- Yast.import "Popup"
- Yast.import "Wizard"
+Yast.import "UI"
+Yast.import "Label"
+Yast.import "Popup"
+Yast.import "Service"
- Yast.include self, "apparmor/apparmor_packages.rb"
- Yast.include self, "apparmor/aa-config.rb"
+module AppArmor
+ class ApparmorSettings
+ include Yast::I18n
+ include Yast::UIShortcuts
- # no command line support #269891
- if Ops.greater_than(Builtins.size(WFM.Args), 0)
- Yast.import "CommandLine"
- CommandLine.Init({}, WFM.Args)
- return
+ def initialize
+ @service_enabled = Yast::Service.Enabled("apparmor")
+ end
+ def run
+ return unless create_dialog
+ begin
+ return event_loop
+ ensure
+ Yast::UI.CloseDialog
end
-
- return if !installAppArmorPackages
-
- @config_steps = [
- { "id" => "apparmor", "label" => _("Enable AppArmor Functions") }
- ]
-
- @steps = Builtins.flatten([@config_steps])
-
- @current_step = 0
- @button = displayPage(@current_step)
-
- # Finish
- Builtins.y2milestone("AppArmor module finished")
- Builtins.y2milestone("----------------------------------------")
-
- # EOF
-
- nil
end
- def displayPage(no)
- current_id = Ops.get_string(Ops.get(@steps, no), "id", "")
- button = nil
-
- UI.WizardCommand(term(:SetCurrentStep, current_id))
-
- if current_id == "apparmor"
- #button = displayAppArmorConfig();
- button = displayAppArmorConfig
+ private
+ def create_dialog
+ Yast::UI.OpenDialog(
+ Opt(:decorated, :defaultsize),
+ VBox(
+ Heading(_("Apparmor Settings")),
+ VSpacing(1),
+ VBox(
+ CheckBox(Id(:aaState), Opt(:notify), _("&Enable Apparmor"), @service_enabled)
+ ),
+ VSpacing(1),
+ Frame(
+ Id(:aaEnableFrame),
+ _("Configure Profiles"),
+ HBox(
+ Label(_("Configure Profile modes")),
+ PushButton(Id(:modeconf), _("Configure")),
+ )
+ ),
+ VSpacing(1),
+ HBox(
+ Right(
+ PushButton(Id(:quit), Yast::Label.QuitButton)
+ )
+ )
+ )
+ )
+ Yast::UI.ChangeWidget(Id(:aaEnableFrame), :Enabled, @service_enabled)
+ end
+ def event_loop
+ loop do
+ case Yast::UI.UserInput
+ when :modeconf
+ break
+ when :quit
+ break
+ end
+ @service_enabled = Yast::UI.QueryWidget(:aaState, :Value)
+ change_state
end
+ end
+ def change_state
+ status = Yast::Service.Enabled("apparmor")
+ # If the service is the same state as our status, return
+ if status == @service_enabled
+ return
+ end
+ # Change the state to what we have
+ if @service_enabled
+ Yast::Service.start("apparmor")
+ Yast::Service.enable("apparmor")
+ else
+ Yast::Service.stop("apparmor")
+ Yast::Service.disable("apparmor")
+ end
- button
+ # Check if the change of service state worked
+ status = Yast::Service.Enabled("apparmor")
+ if status != @service_enabled
+ Yast::Report.Error(_('Failed to change apparmor service. Please use journal (journalctl -n -u apparmor) to diagnose'))
+ else
+ # Enable the configuration frame since everything went well
+ Yast::UI.ChangeWidget(Id(:aaEnableFrame), :Enabled, status)
+ end
end
+
end
end
-Yast::ApparmorSettingsClient.new.main
+AppArmor::ApparmorSettings.new.run
--
2.12.3
--
To unsubscribe, e-mail: yast-devel+unsubscribe@opensuse.org
To contact the owner, e-mail: yast-devel+owner@opensuse.org