From 1f79f888396d5e6255eab103db6669de172a97d0 Mon Sep 17 00:00:00 2001 From: Kenneth Skovhede Date: Tue, 27 Aug 2024 09:59:12 +0200 Subject: [PATCH] Added a dialog for changing the server passphrase. This fixes #5479 --- Duplicati/Server/webroot/ngax/index.html | 1 + .../ngax/scripts/controllers/AppController.js | 50 ++++++++++++++++--- .../controllers/ChangePasswordController.js | 6 +++ .../scripts/controllers/DialogController.js | 5 +- .../ngax/scripts/services/DialogService.js | 10 ++-- .../ngax/templates/changepassword.html | 26 ++++++++++ 6 files changed, 87 insertions(+), 11 deletions(-) create mode 100644 Duplicati/Server/webroot/ngax/scripts/controllers/ChangePasswordController.js create mode 100644 Duplicati/Server/webroot/ngax/templates/changepassword.html diff --git a/Duplicati/Server/webroot/ngax/index.html b/Duplicati/Server/webroot/ngax/index.html index bc42c5542..9130ead8b 100755 --- a/Duplicati/Server/webroot/ngax/index.html +++ b/Duplicati/Server/webroot/ngax/index.html @@ -103,6 +103,7 @@ + diff --git a/Duplicati/Server/webroot/ngax/scripts/controllers/AppController.js b/Duplicati/Server/webroot/ngax/scripts/controllers/AppController.js index c068b950f..8e8e399f9 100644 --- a/Duplicati/Server/webroot/ngax/scripts/controllers/AppController.js +++ b/Duplicati/Server/webroot/ngax/scripts/controllers/AppController.js @@ -176,17 +176,55 @@ backupApp.controller('AppController', function($scope, $cookies, $location, AppS var dt = data.data['max-download-speed']; $scope.throttle_active = (ut != null && ut.trim().length != 0) || (dt != null && dt.trim().length != 0); - var has_asked = data.data['has-asked-for-password-change']; - var autogen_passphrase = data.data['autogenerated-passphrase']; - if (!has_asked && autogen_passphrase == "True") { + var has_asked = AppUtils.parseBoolString(data.data['has-asked-for-password-change']); + var autogen_passphrase = AppUtils.parseBoolString(data.data['autogenerated-passphrase']); + if (!has_asked && autogen_passphrase) { DialogService.dialog( gettextCatalog.getString('First run setup'), gettextCatalog.getString('Duplicati needs to be secured with a passphrase and a random passphrase has been generated for you.\nIf you open Duplicati from the tray icon, you do not need a passphrase, but if you plan to open it from another location you need to set a passphrase you know.\nDo you want to set a passphrase now?'), - [gettextCatalog.getString('No'), gettextCatalog.getString('Yes')], + [gettextCatalog.getString('Yes'), gettextCatalog.getString('No')], function(btn) { - AppService.patch('/serversettings', { 'has-asked-for-password-change': 'true'}, {'headers': {'Content-Type': 'application/json'}}); if (btn == 1) { - $location.path('/settings'); + // Set the flag so we don't ask again + AppService.patch('/serversettings', { 'has-asked-for-password-change': 'true'}); + } + else + { + DialogService.htmlDialog( + gettextCatalog.getString('Change server password'), + 'templates/changepassword.html', + [gettextCatalog.getString('OK'), gettextCatalog.getString('Cancel')], + function(index, text, cur) { + if (index != 0) + return; + + AppService.patch('/serversettings', + { + 'has-asked-for-password-change': 'true', + 'server-passphrase': cur.remotePassword + }) + .then(function() {}, AppUtils.connectionError); + }, + null, + function(index, text, cur) { + if (index != 0) + return true; + + if (cur.remotePassword == null || cur.remotePassword.length == 0) + { + alert("Please enter a passphrase"); + return false; + } + + if(cur.remotePassword != cur.confirmPassword) + { + alert("Passwords do not match"); + return false; + } + + return true; + } + ); } } ); diff --git a/Duplicati/Server/webroot/ngax/scripts/controllers/ChangePasswordController.js b/Duplicati/Server/webroot/ngax/scripts/controllers/ChangePasswordController.js new file mode 100644 index 000000000..cdd690e06 --- /dev/null +++ b/Duplicati/Server/webroot/ngax/scripts/controllers/ChangePasswordController.js @@ -0,0 +1,6 @@ +backupApp.controller('ChangePasswordController', function($scope, gettextCatalog) { + + $scope.selection = $scope.$parent.state.CurrentItem; + $scope.selection.remotePassword = ''; + $scope.selection.confirmPassword = ''; +}); diff --git a/Duplicati/Server/webroot/ngax/scripts/controllers/DialogController.js b/Duplicati/Server/webroot/ngax/scripts/controllers/DialogController.js index 9b471600d..edc560941 100644 --- a/Duplicati/Server/webroot/ngax/scripts/controllers/DialogController.js +++ b/Duplicati/Server/webroot/ngax/scripts/controllers/DialogController.js @@ -23,8 +23,11 @@ backupApp.controller('DialogController', function($scope, DialogService, gettext $scope.onButtonClick = function(index) { var cur = $scope.state.CurrentItem; var input = cur.textarea; - DialogService.dismissCurrent(); + if (cur.validate && !cur.validate(index, input, cur)) + return; + + DialogService.dismissCurrent(); if (cur.callback) cur.callback(index, input, cur); }; diff --git a/Duplicati/Server/webroot/ngax/scripts/services/DialogService.js b/Duplicati/Server/webroot/ngax/scripts/services/DialogService.js index d5ab6e5d6..efe93cec3 100644 --- a/Duplicati/Server/webroot/ngax/scripts/services/DialogService.js +++ b/Duplicati/Server/webroot/ngax/scripts/services/DialogService.js @@ -69,17 +69,18 @@ backupApp.service('DialogService', function(gettextCatalog) { }); }; - this.htmlDialog = function(title, htmltemplate, buttons, callback, onshow) { + this.htmlDialog = function(title, htmltemplate, buttons, callback, onshow, validate) { return this.enqueueDialog({ 'htmltemplate': htmltemplate, 'title': title, 'callback': callback, 'buttons': buttons, - 'onshow': onshow + 'onshow': onshow, + 'validate': validate }); }; - this.textareaDialog = function(title, message, placeholder, textarea, buttons, buttonTemplate, callback, onshow) { + this.textareaDialog = function(title, message, placeholder, textarea, buttons, buttonTemplate, callback, onshow, validate) { return this.enqueueDialog({ 'enableTextarea': true, 'title': title, @@ -89,7 +90,8 @@ backupApp.service('DialogService', function(gettextCatalog) { 'callback': callback, 'buttons': buttons, 'buttonTemplate': buttonTemplate, - 'onshow': onshow + 'onshow': onshow, + 'validate': validate }); }; diff --git a/Duplicati/Server/webroot/ngax/templates/changepassword.html b/Duplicati/Server/webroot/ngax/templates/changepassword.html new file mode 100644 index 000000000..c6170d218 --- /dev/null +++ b/Duplicati/Server/webroot/ngax/templates/changepassword.html @@ -0,0 +1,26 @@ +
+
+
    +
    +
    + +
    +
    +
    + +
    +
+
+