Skip to content

Commit

Permalink
Merge 8e21b9b into c7e321c
Browse files Browse the repository at this point in the history
  • Loading branch information
joseivanlopez committed Aug 8, 2018
2 parents c7e321c + 8e21b9b commit 908576a
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 170 deletions.
7 changes: 7 additions & 0 deletions package/yast2-ftp-server.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
-------------------------------------------------------------------
Wed Aug 8 13:35:09 UTC 2018 - jlopez@suse.com

- Use new Yast2::ServiceWidget to manage the service status
(part of fate#319428).
- 4.1.3

-------------------------------------------------------------------
Thu Jun 28 14:53:32 CEST 2018 - schubi@suse.de

Expand Down
2 changes: 1 addition & 1 deletion package/yast2-ftp-server.spec
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@


Name: yast2-ftp-server
Version: 4.1.2
Version: 4.1.3
Release: 0

BuildRoot: %{_tmppath}/%{name}-%{version}-build
Expand Down
159 changes: 18 additions & 141 deletions src/include/ftp-server/dialogs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@
# Authors: Jozef Uhliarik <juhliarik@suse.cz>
#
# $Id: dialogs.ycp 27914 2006-02-13 14:32:08Z juhliarik $

require "cwm/service_widget"

module Yast
module FtpServerDialogsInclude
def initialize_ftp_server_dialogs(include_target)
Yast.import "UI"

textdomain "ftp-server"

Yast.import "CWM"
Yast.import "CWMServiceStart"
Yast.import "DialogTree"
Yast.import "Label"
Yast.import "Wizard"
Expand All @@ -26,15 +27,20 @@ def initialize_ftp_server_dialogs(include_target)
Yast.include include_target, "ftp-server/wid_functions.rb"
end

# Widget to define state and start mode of the service
#
# @return [::CWM::ServiceWidget]
def service_widget
@service_widget ||= ::CWM::ServiceWidget.new(FtpServer.service)
end

# map for description of widget later in CWNTree
# widget_descr (vsftpd)
#
# @return [Hash{String,map<String => Object>}]
def wid_handling_vsftpd
@wid_handling_vsftpd ||= {
"StartMode" => CWMServiceStart.CreateAutoStartWidget(StartMode()),
"StartStop" => CWMServiceStart.CreateStartStopWidget(StartStop()),
"StartStopRestart" => StartStopRestart(),
"service_widget" => service_widget.cwm_definition,
"Banner" => Banner(),
"ChrootEnable" => ChrootEnable(),
"VerboseLogging" => VerboseLogging(),
Expand All @@ -60,9 +66,7 @@ def wid_handling_vsftpd
"TLS" => TLS(),
"CertFile" => CertFile(),
"BrowseCertFile" => BrowseCertFile(),
"Firewall" => CWMFirewallInterfaces.CreateOpenFirewallWidget(
FirewallSettingsVs()
)
"Firewall" => CWMFirewallInterfaces.CreateOpenFirewallWidget(FirewallSettingsVs())
}
end

Expand Down Expand Up @@ -104,111 +108,6 @@ def AbortDialog
end
end

# Init function where are added UI hadle functions
# Start widget (vsftpd)
#
# @return [Hash{String => Object}] map for start-up widget

def StartMode
result = {}
Ops.set(
result,
"get_service_auto_start",
fun_ref(method(:GetEnableService), "boolean ()")
)
Ops.set(
result,
"set_service_auto_start",
fun_ref(method(:SetEnableService), "void (boolean)")
)
Ops.set(
result,
"get_service_start_via_socket",
fun_ref(method(:"started_via_socket?"), "boolean ()")
)
Ops.set(
result,
"set_service_start_via_socket",
fun_ref(method(:"start_via_socket="), "void (boolean)")
)
Ops.set(
result,
"help",
CWMServiceStart.AutoStartSocketHelp
)

deep_copy(result)
end

# Init function where are added UI hadle functions
# Start widget
#
# @return [Hash{String => Object}] map for start-stop widget

def StartStop
result = {}
Ops.set(result, "service_id", "vsftpd")
Ops.set(result, "service_running_label", _("FTP is running"))
Ops.set(result, "service_not_running_label", _("FTP is not running"))
Ops.set(result, "start_now_button", _("&Start FTP Now"))
Ops.set(result, "stop_now_button", _("S&top FTP Now"))
Ops.set(
result,
"save_now_action",
fun_ref(method(:SaveAndRestartVsftpd), "boolean ()")
)
Ops.set(
result,
"save_now_button",
_("Sa&ve Settings and Restart FTP Now")
)
Ops.set(
result,
"start_now_action",
fun_ref(method(:StartNowVsftpd), "boolean ()")
)
Ops.set(
result,
"stop_now_action",
fun_ref(method(:StopNowVsftpd), "boolean ()")
)
Ops.set(
result,
"help",
Builtins.sformat(
CWMServiceStart.StartStopHelpTemplate(true),
# part of help text - push button label, NO SHORTCUT!!!
_("Start FTP Daemon Now"),
# part of help text - push button label, NO SHORTCUT!!!
_("Stop FTP Daemon Now"),
# part of help text - push button label, NO SHORTCUT!!!
_("Save Settings and Restart FTP Daemon Now")
)
)

deep_copy(result)
end

# Init function where are added UI hadle functions
# special hack widget where is handlig Start/Stop button
#
# @return [Hash{String => Object}] map for start-stop widget

def StartStopRestart
result = {}

Ops.set(result, "widget", :custom)
Ops.set(result, "custom_widget", Empty())
Ops.set(
result,
"init",
fun_ref(method(:InitStartStopRestart), "void (string)")
)
Ops.set(result, "help", " ")

deep_copy(result)
end

#-----------================= GENERAL SCREEN =============----------
#

Expand Down Expand Up @@ -1014,38 +913,16 @@ def SSL
end

#-----------================= SCREENS OF FTP_SERVER =============----------
#

# Init function where are added UI hadle functions
# Start widget
# define for tabs_vsftpd necessary later in screens (CWNTree)
# Widgets for "Start-Up" tree item
#
# @return [Hash{String => Object}] map for start_up widget
def start_up
result = {}

Ops.set(
result,
"contents",
VBox(
"StartMode",
VSpacing(1),
# disabling start/stop buttons when it doesn't make sense
Mode.normal ? "StartStop" : Empty(),
VStretch()
)
)
# TRANSLATORS: part of dialog caption
Ops.set(result, "caption", _("FTP Start-up"))
# TRANSLATORS: tree menu item
Ops.set(result, "tree_item_label", _("Start-Up"))
Ops.set(
result,
"widget_names",
["StartMode", "StartStop", "StartStopRestart"]
)

deep_copy(result)
{
"tree_item_label" => _("Start-Up"),
"contents" => VBox("service_widget", VStretch()),
"widget_names" => ["service_widget"]
}
end

# Init function where are added UI hadle functions
Expand Down
32 changes: 8 additions & 24 deletions src/include/ftp-server/wid_functions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ def started_via_socket?
FtpServer.EDIT_SETTINGS["StartDaemon"] == "2"
end

# @deprecated
#
# CWMServiceStart function with one boolean parameter
# returning boolean value that says if the service will be started at boot.
def start_via_socket=(enable_service)
Expand All @@ -83,6 +85,8 @@ def UpdateInfoAboutStartingFTP
nil
end

# @deprecated
#
# Function start vsftpd
def StartNowVsftpd
UpdateInfoAboutStartingFTP()
Expand All @@ -104,6 +108,8 @@ def StartNowVsftpd
true
end

# @deprecated
#
# Function stop vsftpd
def StopNowVsftpd
if FtpServer.start_via_socket?
Expand All @@ -116,6 +122,8 @@ def StopNowVsftpd
true
end

# @deprecated
#
# Function saves configuration and restarts vsftpd
def SaveAndRestartVsftpd
StopNowVsftpd()
Expand All @@ -125,30 +133,6 @@ def SaveAndRestartVsftpd
result
end

# Init function for start-up
#
# init starting via socket and update status
def InitStartStopRestart(_key = nil)
log.info "current status socket: #{FtpServer.start_via_socket?} service: #{Service.active?("vsftpd")}"
if FtpServer.start_via_socket? || Service.active?("vsftpd")
UI.ReplaceWidget(
Id("_cwm_service_status_rp"),
Label(_("FTP is running"))
)
UI.ChangeWidget(Id("_cwm_start_service_now"), :Enabled, false)
UI.ChangeWidget(Id("_cwm_stop_service_now"), :Enabled, true)
else
UI.ReplaceWidget(
Id("_cwm_service_status_rp"),
Label(_("FTP is not running"))
)
UI.ChangeWidget(Id("_cwm_start_service_now"), :Enabled, true)
UI.ChangeWidget(Id("_cwm_stop_service_now"), :Enabled, false)
end

nil
end

#-----------================= GENERAL SCREEN =============----------
#

Expand Down
31 changes: 27 additions & 4 deletions src/modules/FtpServer.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# encoding: utf-8

require "yast"

require "yast2/system_service"
require "y2firewall/firewalld"

module Yast
Expand Down Expand Up @@ -159,6 +159,10 @@ def main
@write_only = false
end

def service
@service ||= Yast2::SystemService.find("vsftpd")
end

def firewalld
@firewalld ||= Y2Firewall::Firewalld.instance
end
Expand Down Expand Up @@ -674,7 +678,8 @@ def Read
end

# Write all FtpServer settings
# @return true on success
#
# @return [Boolean] true on success; false otherwise
def Write
# FtpServer read dialog caption
caption = _("Saving FTP Configuration")
Expand Down Expand Up @@ -717,13 +722,31 @@ def Write
Builtins.sleep(@sl)

return false if PollAbort()
write_daemon

result = save_status

# Progress finished
Progress.NextStage
Builtins.sleep(@sl)

return false if PollAbort()
true

result
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 {#write_daemon}. When the service
# is configured by using the UI, it directly saves the service, see
# {Yast2::SystemService#save}.
def save_status
if Mode.auto || Mode.commandline
write_daemon
true
else
service.save
end
end

# Get all FtpServer settings from the first parameter
Expand Down

0 comments on commit 908576a

Please sign in to comment.