Skip to content

Commit

Permalink
Use CWM::ServiceWidget instead of CWMServiceStart
Browse files Browse the repository at this point in the history
  • Loading branch information
dgdavid committed Aug 9, 2018
1 parent 2cb9ddb commit b257384
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 74 deletions.
7 changes: 2 additions & 5 deletions src/include/http-server/dialogs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
45 changes: 26 additions & 19 deletions src/modules/HttpServer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<string, any> test = (map<string, any>)SCR::Execute(.target.bash_output, "apache2ctl conftest");
#y2internal("test %1", test);
Expand All @@ -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<Hash{String => Object>}] known_modules list< map<string,any> > known modules
Expand Down
66 changes: 16 additions & 50 deletions src/modules/HttpServerWidgets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
#
# $Id$
require "yast"
require "cwm/service_widget"

module Yast
class HttpServerWidgetsClass < Module

def main
Yast.import "UI"

Expand All @@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit b257384

Please sign in to comment.