From b257384b99d18b93fcbf877d1b804476ae9c2a1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20D=C3=ADaz?= Date: Wed, 8 Aug 2018 12:05:39 +0100 Subject: [PATCH] Use CWM::ServiceWidget instead of CWMServiceStart --- src/include/http-server/dialogs.rb | 7 +--- src/modules/HttpServer.rb | 45 +++++++++++--------- src/modules/HttpServerWidgets.rb | 66 ++++++++---------------------- 3 files changed, 44 insertions(+), 74 deletions(-) diff --git a/src/include/http-server/dialogs.rb b/src/include/http-server/dialogs.rb index c6256e4..82ba0b2 100644 --- a/src/include/http-server/dialogs.rb +++ b/src/include/http-server/dialogs.rb @@ -34,19 +34,16 @@ def initialize_http_server_dialogs(include_target) HStretch(), HSpacing(1), VBox( - "server_enable", #, - # `VSpacing(1) - # `VSpacing (1), + "service_widget", "LISTEN", - # `VSpacing (1), "firewall_adapt", - # `VSpacing (1), "logs" ), # `HSpacing (1), HStretch() ), "widget_names" => [ + "service_widget", "server_enable", "LISTEN", "firewall_adapt", diff --git a/src/modules/HttpServer.rb b/src/modules/HttpServer.rb index 588d5b0..4c1ee00 100644 --- a/src/modules/HttpServer.rb +++ b/src/modules/HttpServer.rb @@ -10,6 +10,7 @@ # Representation of the configuration of http-server. # Input and output routines. require "yast" +require "yast2/system_service" require "y2firewall/firewalld" module Yast @@ -37,6 +38,7 @@ def main Yast.import "Confirm" Yast.import "FileChanges" Yast.import "Label" + Yast.import "Mode" # Abort function # return boolean return true if abort @@ -79,6 +81,13 @@ def main IGNORED_FILES = ["vhost.template", "vhost-ssl.template"] APACHE_VHOSTS_DIR = "/etc/apache2/vhosts.d" + # Returns the apache2 service + # + # @return [Yast2::SystemService] + def service + @service ||= Yast2::SystemService.find("apache2") + end + def firewalld Y2Firewall::Firewalld.instance end @@ -480,34 +489,17 @@ def Write log.info("The apache2 service is not defined in firewalld") end - DnsServerAPI.Write if @configured_dns Progress.set(old_progress) YaST::HTTPDData.WriteModuleList - # in autoyast, quit here - # Wrong, service still has to be enabled... - # if( write_only ) return true; - Progress.NextStage - if !YaST::HTTPDData.WriteService(@write_only) + if !save_status # translators: error message - Report.Error(Message.CannotAdjustService("apache2")) + Report.Error(Message.CannotAdjustService(service.name)) end - if YaST::HTTPDData.GetService - # this will reload the configuration and start httpd - if !Service.Restart("apache2") - # translators: error message - Report.Error(Message.CannotAdjustService("apache2")) - end - else - if !Service.Stop("apache2") - # translators: error message - Report.Error(Message.CannotAdjustService("apache2")) - end - end # configuration test # map test = (map)SCR::Execute(.target.bash_output, "apache2ctl conftest"); #y2internal("test %1", test); @@ -522,6 +514,21 @@ def Write true end + # Saves service status (start mode and starts/stops the service) + # + # @note For AutoYaST and for command line actions, it uses the old way for + # backward compatibility, see {Yast::HTTPDData#WriteService}. When the + # service is configured by using the UI, it directly saves the service, see + # {Yast2::SystemService#save}. + # + # @return [Boolean] true if service status is saved; false otherwise. + def save_status + if Mode.auto || Mode.commandline + Yast::HTTPDData.WriteService(@write_only) + else + service.save + end + end # For module name find description map in known_modules # @param [Array Object>}] known_modules list< map > known modules diff --git a/src/modules/HttpServerWidgets.rb b/src/modules/HttpServerWidgets.rb index 7d48cd5..f71d8ca 100644 --- a/src/modules/HttpServerWidgets.rb +++ b/src/modules/HttpServerWidgets.rb @@ -9,9 +9,11 @@ # # $Id$ require "yast" +require "cwm/service_widget" module Yast class HttpServerWidgetsClass < Module + def main Yast.import "UI" @@ -23,14 +25,12 @@ def main Yast.import "Label" Yast.import "Popup" Yast.import "Report" - Yast.import "Service" Yast.import "String" Yast.import "LogView" Yast.import "TablePopup" Yast.import "HttpServer" Yast.import "YaST::HTTPDData" Yast.import "Confirm" - Yast.import "CWMServiceStart" Yast.import "CWMFirewallInterfaces" Yast.import "Punycode" Yast.import "Package" @@ -344,6 +344,7 @@ def main @option_counter = 0 @deleted_options = [] +<<<<<<< HEAD # these are for future use: # error message - the entered ip address is not found @@ -355,34 +356,7 @@ def main # Map of widgets for CWM def widgets @widgets ||= { - "server_enable" => { - "widget" => :radio_buttons, - # translator: server enable/disable radio button group - "label" => _( - "HTTP &Service" - ), - "items" => [ - # translators: service status radio button label - ["disabled", _("Disabled")], - # translators: service status radio button label - ["enabled", _("Enabled")] - ], - "init" => fun_ref( - method(:initServiceStatus), - "void (string)" - ), - "handle" => fun_ref( - method(:handleServiceStatus), - "symbol (string, map)" - ), - "store" => fun_ref( - method(:storeServiceStatus), - "void (string, map)" - ), - "handle_events" => ["enabled", "disabled"], - "opt" => [:notify], - "help" => @HELPS["server_enable"] - }, + "service_widget" => service_widget.cwm_definition, "firewall_adapt" => CWMFirewallInterfaces.CreateOpenFirewallWidget( { # Firewalld already defines the http and https services. This @@ -596,26 +570,7 @@ def widgets ), "help" => Ops.get_string(@HELPS, "listen_interfaces", "") }, - "booting" => CWMServiceStart.CreateAutoStartWidget( - { - "get_service_auto_start" => fun_ref( - method(:getServiceAutoStart), - "boolean ()" - ), - "set_service_auto_start" => fun_ref( - method(:setServiceAutoStart), - "void (boolean)" - ), - #translators: radiobutton - to start Apache2 service automatically - "start_auto_button" => _( - "Start Apache2 Server When Booting" - ), - #translators: radiobutton - to don't start Apache2 service - "start_manual_button" => _( - "Start Apache2 Server Manually" - ) - } - ), + "booting" => service_widget.cwm_definition, "expert_conf" => { "widget" => :push_button, #translators: button to enter expert configuration @@ -804,6 +759,13 @@ def widgets } end + # Rerturns a service widget + # + # @return [::CWM::ServiceWidget] + def service_widget + @service_widget ||= ::CWM::ServiceWidget.new(HttpServer.service) + end + # Validate certificate # @return [Boolean] certificate valid def CheckCommonServerCertificate @@ -3363,6 +3325,7 @@ def handleListenSettings(key, event) # ************************************ server status *********************** + # @deprecated Service status is now managed by Yast2::ServiceWidget # Initialize function of a widget # @param [String] key any widget key of widget that is processed def initServiceStatus(key) @@ -3375,6 +3338,7 @@ def initServiceStatus(key) nil end + # @deprecated Service status is now managed by Yast2::ServiceWidget # Store function of a widget # @param [String] key any widget key of widget that is processed # @param [Hash] event map event that occured @@ -3387,6 +3351,8 @@ def storeServiceStatus(key, event) nil end + + # @deprecated Service status is now managed by Yast2::ServiceWidget # Handling service status # @param [String] key string # @param [Hash] event map