From 0f6115e3a5ef2f8291c761b8043eb494fb2c8973 Mon Sep 17 00:00:00 2001 From: Floris Bos Date: Tue, 1 Feb 2022 16:02:50 +0100 Subject: [PATCH] Enforce password is filled in if "set user" is checked even when not using SSH Also fix logic for persisting wheter SSH is enabled. --- OptionsPopup.qml | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/OptionsPopup.qml b/OptionsPopup.qml index 41939fc..c7677ec 100644 --- a/OptionsPopup.qml +++ b/OptionsPopup.qml @@ -144,8 +144,11 @@ Popup { if (!radioPasswordAuthentication.checked && !radioPubKeyAuthentication.checked) { radioPasswordAuthentication.checked = true } - if (radioPasswordAuthentication.checked && !fieldUserPassword.length) { - fieldUserPassword.forceActiveFocus() + if (radioPasswordAuthentication.checked) { + chkSetUser.checked = true + if (!fieldUserPassword.length) { + fieldUserPassword.forceActiveFocus() + } } } } @@ -394,13 +397,13 @@ Popup { Button { text: qsTr("SAVE") onClicked: { - if (chkSSH.checked && radioPasswordAuthentication.checked && fieldUserPassword.text.length == 0) + if (chkSetUser.checked && fieldUserPassword.text.length == 0) { fieldUserPassword.indicateError = true fieldUserPassword.forceActiveFocus() return } - if (chkSSH.checked && fieldUserName.text.length == 0) + if (chkSetUser.checked && fieldUserName.text.length == 0) { fieldUserName.indicateError = true fieldUserName.forceActiveFocus() @@ -463,9 +466,13 @@ Popup { if ('sshUserPassword' in settings) { fieldUserPassword.text = settings.sshUserPassword fieldUserPassword.alreadyCrypted = true - chkSSH.checked = true - radioPasswordAuthentication.checked = true chkSetUser.checked = true + /* Older imager versions did not have a sshEnabled setting. + Assume it is true if it does not exists and sshUserPassword is set */ + if (!('sshEnabled' in settings) || settings.sshEnabled === "true") { + chkSSH.checked = true + radioPasswordAuthentication.checked = true + } } if ('sshUserName' in settings) { fieldUserName.text = settings.sshUserName @@ -779,14 +786,14 @@ Popup { if (chkHostname.checked && fieldHostname.length) { settings.hostname = fieldHostname.text } - if (chkSSH.checked) { + if (chkSetUser.checked) { settings.sshUserName = fieldUserName.text - if (radioPasswordAuthentication.checked) { - settings.sshUserPassword = fieldUserPassword.alreadyCrypted ? fieldUserPassword.text : imageWriter.crypt(fieldUserPassword.text) - } - if (radioPubKeyAuthentication.checked) { - settings.sshAuthorizedKeys = fieldPublicKey.text - } + settings.sshUserPassword = fieldUserPassword.alreadyCrypted ? fieldUserPassword.text : imageWriter.crypt(fieldUserPassword.text) + } + + settings.sshEnabled = chkSSH.checked + if (chkSSH.checked && radioPubKeyAuthentication.checked) { + settings.sshAuthorizedKeys = fieldPublicKey.text } if (chkWifi.checked) { settings.wifiSSID = fieldWifiSSID.text