[yast-devel] Re: [yast-commit] r64378 - in /trunk/sshd: VERSION package/yast2-sshd.changes src/Sshd.ycp src/dialogs.ycp src/wizards.ycp
On Wed, Jun 15, 2011 at 08:47:50AM -0000, locilka@svn2.opensuse.org wrote:
Author: locilka Date: Wed Jun 15 10:47:50 2011 New Revision: 64378
URL: http://svn.opensuse.org/viewcvs/yast?rev=64378&view=rev Log: Added possibility to manage the sshd service (#556535)
Modified: trunk/sshd/VERSION trunk/sshd/package/yast2-sshd.changes trunk/sshd/src/Sshd.ycp trunk/sshd/src/dialogs.ycp trunk/sshd/src/wizards.ycp
Modified: trunk/sshd/VERSION URL: http://svn.opensuse.org/viewcvs/yast/trunk/sshd/VERSION?rev=64378&r1=64377&r2=64378&view=diff ============================================================================== --- trunk/sshd/VERSION (original) +++ trunk/sshd/VERSION Wed Jun 15 10:47:50 2011 @@ -1 +1 @@ -2.18.0 +2.21.0
Modified: trunk/sshd/package/yast2-sshd.changes URL: http://svn.opensuse.org/viewcvs/yast/trunk/sshd/package/yast2-sshd.changes?rev=64378&r1=64377&r2=64378&view=diff ============================================================================== --- trunk/sshd/package/yast2-sshd.changes (original) +++ trunk/sshd/package/yast2-sshd.changes Wed Jun 15 10:47:50 2011 @@ -1,4 +1,10 @@ ------------------------------------------------------------------- +Wed Jun 15 10:45:10 CEST 2011 - locilka@suse.cz + +- Added possibility to manage the sshd service (#556535).
s/#556535/bnc#556535/
+- 2.21.0 + +------------------------------------------------------------------- Wed Jan 13 18:56:03 CET 2010 - kmachalkova@suse.cz
- Adjusted .desktop file(s) to wrap /sbin/yast2/ calls in xdg-su
Modified: trunk/sshd/src/Sshd.ycp URL: http://svn.opensuse.org/viewcvs/yast/trunk/sshd/src/Sshd.ycp?rev=64378&r1=64377&r2=64378&view=diff ============================================================================== --- trunk/sshd/src/Sshd.ycp (original) +++ trunk/sshd/src/Sshd.ycp Wed Jun 15 10:47:50 2011 @@ -30,7 +30,7 @@ /** * Sleep time between Read or Write steps */ -integer sl = 200; +integer sl = 150;
WTF?
/** * Returns whether the configuration has been modified. @@ -46,6 +46,40 @@ modified = true; }
+string service_name = "sshd"; + +boolean start_service = nil; + +global boolean GetStartService () { + return start_service; +} + +global void SetStartService (boolean new_state) { + if (new_state == nil) { + y2error ("Cannot set 'StartService' to %1", new_state); + return; + } else if (start_service == new_state) { + y2warning ("'StartService' unchanged"); + return; + } + + start_service = new_state; + SetModified(); +} + +/** + * Describes whether the daemon is running + */ +boolean Running () { + return (Service::Status(service_name) == 0); +} + +boolean ReadStartService () { + start_service = Running(); + + return (start_service != nil); +} + /** * map of SSHD settings */ @@ -129,26 +163,6 @@ }
/** - * Describes whether the daemon is running - */ -boolean sshd_is_running = false; - -/** - * Reads current sshd status - */ -boolean ReadSSHDService () { - if (Service::Status("sshd") == 0) { - sshd_is_running = true; - } else { - sshd_is_running = false; - } - - y2milestone((sshd_is_running ? "SSH is running":"SSH is not running")); - - return true; -} - -/** * Exports the current configuration. * * @return map of a current configuration @@ -161,7 +175,7 @@ global map Export () { return $[ "config" : SETTINGS, - "status" : sshd_is_running, + "status" : Running(), ]; }
@@ -170,29 +184,13 @@ */ global boolean Import (map import_map) { SETTINGS = (map <string, list<string> >) import_map["config"]:$[]; - sshd_is_running = (import_map["status"]:false == true); + SetStartService (import_map["status"]:false == true); SetModified(); y2milestone ("Configuration has been imported"); return true; }
/** - * Restarts the sshd when the daemon was running when starting the configuration - */ -boolean WriteSSHDService () { - boolean all_ok = true; - - if (sshd_is_running) { - y2milestone("Restarting sshd daemon"); - all_ok = Service::Restart("sshd"); - } else { - y2milestone("Sshd is not running - leaving..."); - } - - return all_ok; -} - -/** Returns a confirmation popup dialog whether user wants to really abort. */ global boolean Abort() { @@ -225,7 +223,7 @@ /* SSHD read dialog caption */ string caption = _("Initializing the SSHD Configuration");
- integer steps = 3; + integer steps = 4;
aaah, so "integer sl = 600 / steps" above, right? 8-] This Progress stuff is so... er... useful?
Progress::New( caption, " ", steps, [ /* Progress stage 1 */ @@ -233,15 +231,18 @@ /* Progress stage 2 */ _("Read the current SSHD state"), /* Progress stage 3 */ - _("Read firewall settings") + _("Read firewall settings"), + /* Progress stage 4 */ + _("Read service status"), ], [ /* Progress step 1 */ _("Reading the current SSHD configuration..."), /* Progress step 2 */ - _("Reading the current SSHD state..."), + _("Reading the current SSHD state"), /* Progress step 3 */ _("Reading firewall settings..."), - /* Progress finished */ + /* Progress step 4 */ + _("Reading service status..."), Message::Finished() ], "" @@ -251,14 +252,12 @@
if (PollAbort()) return false; Progress::NextStage(); - /* Error message */ if(!ReadSSHDSettings()) Report::Error(Message::CannotReadCurrentSettings()); sleep(sl);
if (PollAbort()) return false; - Progress::NextStep(); - /* Error message */ - if(!ReadSSHDService()) Report::Error(_("Cannot read the current SSHD state.")); + Progress::NextStage(); + if (!ReadStartService()) Report::Error(Message::CannotReadCurrentSettings()); sleep(sl);
if (PollAbort()) return false; @@ -273,10 +272,61 @@ Progress::NextStage (); sleep(sl);
+ if (PollAbort()) return false; + Progress::NextStage (); + start_service = Service::Enabled (service_name); + sleep(sl); + modified = false; return true; }
+boolean AdjustSSHDService () { + boolean enable_and_start = GetStartService(); + boolean enabled = Service::Enabled (service_name); + boolean running = (Service::Status (service_name) == 0); + + if (enable_and_start == nil) { + y2error ("Configuration error: Cannot start/stop service %1", service_name); + return false; + } + + // Service enable/disable + if (enable_and_start == enabled) { + y2milestone ("Service '%1' is already in the desired state", service_name); + } else { + if (enable_and_start && !Service::Enable (service_name)) { + y2error ("Cannot enable service %1", service_name); + return false; + } else if (!enable_and_start && !Service::Disable (service_name)) { + y2error ("Cannot disable service %1", service_name); + return false; + } + } + + // Start / restart service + if (enable_and_start) { + if (Running()) { + if (!Service::Restart(service_name)) { + y2error ("Cannot restart service %1", service_name); + return false; + } + } else { + if (!Service::Start (service_name)) { + y2error ("Cannot start service %1", service_name); + return false; + } + } + // Stop a running service + } else if (Running()) { + if (!Service::Stop (service_name)) { + return false; + } + } + + return true; +} + /** * Write all SSHD settings * @return true on success @@ -286,22 +336,22 @@ /* SSHD read dialog caption */ string caption = _("Saving the SSHD Configuration");
- integer steps = 3; - + integer steps = 4; + Progress::New(caption, " ", steps, [ /* Progress stage 1 */ _("Write the SSHD settings"), /* Progress stage 2 */ - _("Adjust the SSHD service"), + _("Write firewall settings"), /* Progress stage 3 */ - _("Write firewall settings") + _("Adjust SSHD service"), ], [ /* Progress step 1 */ _("Writing the SSHD settings..."), /* Progress step 2 */ - _("Adjusting the SSHD service..."), - /* Progress step 3 */ _("Writing firewall settings..."), + /* Progress step 3 */ + _("Adjusting SSHD service..."), Message::Finished() ], "" @@ -317,16 +367,15 @@
if(PollAbort()) return false; Progress::NextStage (); + boolean progress_state = Progress::set (false); /* Error message */ - if(!WriteSSHDService()) Report::Error (Message::CannotAdjustService("sshd")); + if(!SuSEFirewall::Write()) Report::Error(_("Cannot write firewall settings.")); + Progress::set (progress_state); sleep(sl);
if(PollAbort()) return false; Progress::NextStage (); - boolean progress_state = Progress::set (false); - /* Error message */ - if(!SuSEFirewall::Write()) Report::Error(_("Cannot write firewall settings.")); - Progress::set (progress_state); + AdjustSSHDService(); sleep(sl);
Progress::NextStage ();
Modified: trunk/sshd/src/dialogs.ycp URL: http://svn.opensuse.org/viewcvs/yast/trunk/sshd/src/dialogs.ycp?rev=64378&r1=64377&r2=64378&view=diff ============================================================================== --- trunk/sshd/src/dialogs.ycp (original) +++ trunk/sshd/src/dialogs.ycp Wed Jun 15 10:47:50 2011 @@ -28,6 +28,15 @@ mbox_y = 0; }
+term ServiceConfigurationDialogContent () { + return `VBox ( + "start_stop", + `VSpacing(1), + "auto_start_up", + `VStretch() + ); +} + term ServerConfigurationDialogContent () { return `VBox ( `Left(`Label(_("SSHD TCP Ports"))), @@ -45,7 +54,7 @@ /* a push button */ `PushButton(`id("delete_port"), _("&Delete")) )), - `VSpacing(1), + `VSpacing (1), `Frame ( /* a dialog frame caption */ _("Server Features"),
Modified: trunk/sshd/src/wizards.ycp URL: http://svn.opensuse.org/viewcvs/yast/trunk/sshd/src/wizards.ycp?rev=64378&r1=64377&r2=64378&view=diff ============================================================================== --- trunk/sshd/src/wizards.ycp (original) +++ trunk/sshd/src/wizards.ycp Wed Jun 15 10:47:50 2011 @@ -14,10 +14,20 @@ import "CWM"; import "CWMTab"; import "CWMFirewallInterfaces"; +import "CWMServiceStart"; +import "Sshd";
include "sshd/complex.ycp"; include "sshd/dialogs.ycp";
+void SaveAndRestart () { + Wizard::CreateDialog (); + Wizard::RestoreHelp (HELPS["write"]:""); + Sshd::Write (); + sleep (1000); + UI::CloseDialog (); +} + /** * Main workflow of the sshd configuration * @return sequence result @@ -52,9 +62,49 @@ "services" : [ "service:sshd" ], "display_details" : true, ]), + "start_stop" : CWMServiceStart::CreateStartStopWidget ($[ + "service_id" : "sshd", + // label - service status, informative text + "service_running_label" : _("SSH server is running"), + // label - service status, informative text + "service_not_running_label" : _("SSH server is not running"), + // push button (SSH service handling) + "start_now_button" : _("&Start SSH Server Now"), + // push button (SSH service handling) + "stop_now_button" : _("S&top SSH Server Now"), + "save_now_action" : SaveAndRestart, + // push button (SSH service handling) + "save_now_button" : _("Save Settings and Reload SSH Server &Now"), + "help" : sformat (CWMServiceStart::StartStopHelpTemplate (true), + // part of help text, used to describe pusbuttons (matching SSH service handling but without "&") + _("Start SSH Server Now"), + // part of help text, used to describe pusbuttons (matching SSH service handling but without "&") + _("Stop SSH Server Now"), + // part of help text, used to describe pusbuttons (matching SSH service handling but without "&") + _("Save Settings and Reload SSH Server Now")), + ]), + "auto_start_up" : CWMServiceStart::CreateAutoStartWidget ($[ + "get_service_auto_start" : Sshd::GetStartService, + "set_service_auto_start" : Sshd::SetStartService, + // radio button (starting SSH service - option 1) + "start_auto_button" : _("Now and When &Booting"), + // radio button (starting SSH service - option 2) + "start_manual_button" : _("&Manually"), + "help" : sformat (CWMServiceStart::AutoStartHelpTemplate (), + // part of help text, used to describe radiobuttons (matching starting SSH service but without "&") + _("Now and When Booting"), + // part of help text, used to describe radiobuttons (matching starting SSH service but without "&") + _("Manually") + ), + ]),
Hmm, when I saw 'import "CWMServiceStart"' above, I thought "good, that will save us so much repetitive code" :-/ Overall... God, so much code for a stupid totally standard sysvinit service?! I want a simple declaration to replace this *entire* patch: service :name => _("SSH Server"), :sysvinit => "sshd" We really should make better libraries.
];
map <string, any> tabs = $[ + "service_configuration" : $[ + "header" : _("&Start-Up"), + "widget_names" : ["start_stop", "auto_start_up"], + "contents" : ServiceConfigurationDialogContent(), + ], "server_configuration" : $[ "header" : _("&General"), "widget_names" : ["sc", "fw"], @@ -74,7 +124,7 @@
map <string, any> wd = $[ "tab" : CWMTab::CreateWidget ($[ - "tab_order" : ["server_configuration", "login_settings", "proto_and_cipher"], + "tab_order" : ["service_configuration", "server_configuration", "login_settings", "proto_and_cipher"], "tabs" : tabs, "widget_descr" : widgets, "initial_tab" : "server_configuration",
-- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org
-- Martin Vidner, YaST developer http://en.opensuse.org/User:Mvidner Kuracke oddeleni v restauraci je jako fekalni oddeleni v bazenu
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Dne 15.6.2011 17:00, Martin Vidner napsal(a):
On Wed, Jun 15, 2011 at 08:47:50AM -0000, locilka@svn2.opensuse.org wrote:
Modified: trunk/sshd/package/yast2-sshd.changes URL: http://svn.opensuse.org/viewcvs/yast/trunk/sshd/package/yast2-sshd.changes?rev=64378&r1=64377&r2=64378&view=diff ============================================================================== --- trunk/sshd/package/yast2-sshd.changes (original) +++ trunk/sshd/package/yast2-sshd.changes Wed Jun 15 10:47:50 2011 @@ -1,4 +1,10 @@ ------------------------------------------------------------------- +Wed Jun 15 10:45:10 CEST 2011 - locilka@suse.cz + +- Added possibility to manage the sshd service (#556535).
s/#556535/bnc#556535/
Thx, fixed.
+- 2.21.0 + +------------------------------------------------------------------- Wed Jan 13 18:56:03 CET 2010 - kmachalkova@suse.cz
- Adjusted .desktop file(s) to wrap /sbin/yast2/ calls in xdg-su
Modified: trunk/sshd/src/Sshd.ycp URL: http://svn.opensuse.org/viewcvs/yast/trunk/sshd/src/Sshd.ycp?rev=64378&r1=64377&r2=64378&view=diff ============================================================================== --- trunk/sshd/src/Sshd.ycp (original) +++ trunk/sshd/src/Sshd.ycp Wed Jun 15 10:47:50 2011 @@ -30,7 +30,7 @@ /** * Sleep time between Read or Write steps */ -integer sl = 200; +integer sl = 150;
WTF?
All WTFs have been removed ;)
global boolean Abort() { @@ -225,7 +223,7 @@ /* SSHD read dialog caption */ string caption = _("Initializing the SSHD Configuration");
- integer steps = 3; + integer steps = 4;
aaah, so "integer sl = 600 / steps" above, right? 8-]
This Progress stuff is so... er... useful?
See above. Anyway, good point. The purpose of WTF there was to show "something" to the user/admin as SSHD was a "tutorial" module. A bit for effect, not for efficiency.
/** * Main workflow of the sshd configuration * @return sequence result @@ -52,9 +62,49 @@ "services" : [ "service:sshd" ], "display_details" : true, ]), + "start_stop" : CWMServiceStart::CreateStartStopWidget ($[ + "service_id" : "sshd", + // label - service status, informative text + "service_running_label" : _("SSH server is running"), + // label - service status, informative text + "service_not_running_label" : _("SSH server is not running"), + // push button (SSH service handling) + "start_now_button" : _("&Start SSH Server Now"), + // push button (SSH service handling) + "stop_now_button" : _("S&top SSH Server Now"), + "save_now_action" : SaveAndRestart, + // push button (SSH service handling) + "save_now_button" : _("Save Settings and Reload SSH Server &Now"), + "help" : sformat (CWMServiceStart::StartStopHelpTemplate (true), + // part of help text, used to describe pusbuttons (matching SSH service handling but without "&") + _("Start SSH Server Now"), + // part of help text, used to describe pusbuttons (matching SSH service handling but without "&") + _("Stop SSH Server Now"), + // part of help text, used to describe pusbuttons (matching SSH service handling but without "&") + _("Save Settings and Reload SSH Server Now")), + ]), + "auto_start_up" : CWMServiceStart::CreateAutoStartWidget ($[ + "get_service_auto_start" : Sshd::GetStartService, + "set_service_auto_start" : Sshd::SetStartService, + // radio button (starting SSH service - option 1) + "start_auto_button" : _("Now and When &Booting"), + // radio button (starting SSH service - option 2) + "start_manual_button" : _("&Manually"), + "help" : sformat (CWMServiceStart::AutoStartHelpTemplate (), + // part of help text, used to describe radiobuttons (matching starting SSH service but without "&") + _("Now and When Booting"), + // part of help text, used to describe radiobuttons (matching starting SSH service but without "&") + _("Manually") + ), + ]),
Hmm, when I saw 'import "CWMServiceStart"' above, I thought "good, that will save us so much repetitive code" :-/
Overall... God, so much code for a stupid totally standard sysvinit service?! I want a simple declaration to replace this *entire* patch:
service :name => _("SSH Server"), :sysvinit => "sshd"
We really should make better libraries.
Yes, but this CWM piece comes from medieval times and we've got to the 19th century just recently. Reaching the 20th or even 21st century will take us some more time. Anyway, it's a good point for yast-devel but I'd suggest to open a separate thread. Lukas - -- Lukas Ocilka, Appliances Department, SUSE LINUX s.r.o. MD: Jeff Hawn, Jennifer Guild, Alena Hendrichova -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.16 (GNU/Linux) Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org/ iD8DBQFN/vTwVSqMdRCqTiwRAuFqAJ9aRCwkUa+Cbb/Kb/8H+R2RE81YrACdFwM+ MRlTKYNkf9xSK8ElfG1PlFs= =YBmp -----END PGP SIGNATURE----- -- To unsubscribe, e-mail: yast-devel+unsubscribe@opensuse.org For additional commands, e-mail: yast-devel+help@opensuse.org
participants (2)
-
Lukas Ocilka
-
Martin Vidner