Enforce password is filled in if "set user" is checked even when not using SSH

Also fix logic for persisting wheter SSH is enabled.
This commit is contained in:
Floris Bos 2022-02-01 16:02:50 +01:00
parent 9c22346d61
commit 0f6115e3a5

View file

@ -144,8 +144,11 @@ Popup {
if (!radioPasswordAuthentication.checked && !radioPubKeyAuthentication.checked) { if (!radioPasswordAuthentication.checked && !radioPubKeyAuthentication.checked) {
radioPasswordAuthentication.checked = true radioPasswordAuthentication.checked = true
} }
if (radioPasswordAuthentication.checked && !fieldUserPassword.length) { if (radioPasswordAuthentication.checked) {
fieldUserPassword.forceActiveFocus() chkSetUser.checked = true
if (!fieldUserPassword.length) {
fieldUserPassword.forceActiveFocus()
}
} }
} }
} }
@ -394,13 +397,13 @@ Popup {
Button { Button {
text: qsTr("SAVE") text: qsTr("SAVE")
onClicked: { onClicked: {
if (chkSSH.checked && radioPasswordAuthentication.checked && fieldUserPassword.text.length == 0) if (chkSetUser.checked && fieldUserPassword.text.length == 0)
{ {
fieldUserPassword.indicateError = true fieldUserPassword.indicateError = true
fieldUserPassword.forceActiveFocus() fieldUserPassword.forceActiveFocus()
return return
} }
if (chkSSH.checked && fieldUserName.text.length == 0) if (chkSetUser.checked && fieldUserName.text.length == 0)
{ {
fieldUserName.indicateError = true fieldUserName.indicateError = true
fieldUserName.forceActiveFocus() fieldUserName.forceActiveFocus()
@ -463,9 +466,13 @@ Popup {
if ('sshUserPassword' in settings) { if ('sshUserPassword' in settings) {
fieldUserPassword.text = settings.sshUserPassword fieldUserPassword.text = settings.sshUserPassword
fieldUserPassword.alreadyCrypted = true fieldUserPassword.alreadyCrypted = true
chkSSH.checked = true
radioPasswordAuthentication.checked = true
chkSetUser.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) { if ('sshUserName' in settings) {
fieldUserName.text = settings.sshUserName fieldUserName.text = settings.sshUserName
@ -779,14 +786,14 @@ Popup {
if (chkHostname.checked && fieldHostname.length) { if (chkHostname.checked && fieldHostname.length) {
settings.hostname = fieldHostname.text settings.hostname = fieldHostname.text
} }
if (chkSSH.checked) { if (chkSetUser.checked) {
settings.sshUserName = fieldUserName.text settings.sshUserName = fieldUserName.text
if (radioPasswordAuthentication.checked) { settings.sshUserPassword = fieldUserPassword.alreadyCrypted ? fieldUserPassword.text : imageWriter.crypt(fieldUserPassword.text)
settings.sshUserPassword = fieldUserPassword.alreadyCrypted ? fieldUserPassword.text : imageWriter.crypt(fieldUserPassword.text) }
}
if (radioPubKeyAuthentication.checked) { settings.sshEnabled = chkSSH.checked
settings.sshAuthorizedKeys = fieldPublicKey.text if (chkSSH.checked && radioPubKeyAuthentication.checked) {
} settings.sshAuthorizedKeys = fieldPublicKey.text
} }
if (chkWifi.checked) { if (chkWifi.checked) {
settings.wifiSSID = fieldWifiSSID.text settings.wifiSSID = fieldWifiSSID.text