fixes password change in hosted tray
This commit is contained in:
@@ -62,15 +62,15 @@ namespace Duplicati.GUI.TrayIcon
|
||||
|
||||
private readonly Dictionary<string, string> m_updateRequest;
|
||||
private readonly Dictionary<string, string> m_options;
|
||||
private readonly bool m_dbPasswordSourceDatabase;
|
||||
private string m_TrayIconHeaderValue => m_dbPasswordSourceDatabase ? "database" : "user";
|
||||
private readonly Program.PasswordSource m_passwordSource;
|
||||
private string m_TrayIconHeaderValue => (m_passwordSource == Program.PasswordSource.Database) ? "database" : "user";
|
||||
|
||||
public IServerStatus Status { get { return m_status; } }
|
||||
|
||||
private object m_lock = new object();
|
||||
private Queue<BackgroundRequest> m_workQueue = new Queue<BackgroundRequest>();
|
||||
|
||||
public HttpServerConnection(Uri server, string password, bool saltedpassword, bool dbPasswordSourceDatabase, Dictionary<string, string> options)
|
||||
public HttpServerConnection(Uri server, string password, bool saltedpassword, Program.PasswordSource passwordSource, Dictionary<string, string> options)
|
||||
{
|
||||
m_baseUri = server.ToString();
|
||||
if (!m_baseUri.EndsWith("/", StringComparison.Ordinal))
|
||||
@@ -83,7 +83,7 @@ namespace Duplicati.GUI.TrayIcon
|
||||
m_password = password;
|
||||
m_saltedpassword = saltedpassword;
|
||||
m_options = options;
|
||||
m_dbPasswordSourceDatabase = dbPasswordSourceDatabase;
|
||||
m_passwordSource = passwordSource;
|
||||
|
||||
m_updateRequest = new Dictionary<string, string>();
|
||||
m_updateRequest["longpoll"] = "false";
|
||||
@@ -364,15 +364,25 @@ namespace Duplicati.GUI.TrayIcon
|
||||
wex.Status == System.Net.WebExceptionStatus.ProtocolError &&
|
||||
httpex.StatusCode == System.Net.HttpStatusCode.Unauthorized)
|
||||
{
|
||||
if (m_dbPasswordSourceDatabase)
|
||||
//Can survive if server password is changed via web ui
|
||||
switch (m_passwordSource)
|
||||
{
|
||||
Program.databaseConnection.ApplicationSettings.ReloadSettings();
|
||||
|
||||
//Can survive if server password is changed via web ui
|
||||
if (Program.databaseConnection.ApplicationSettings.WebserverPasswordTrayIcon != m_password)
|
||||
m_password = Program.databaseConnection.ApplicationSettings.WebserverPasswordTrayIcon;
|
||||
else
|
||||
hasTriedPassword = true;
|
||||
case Program.PasswordSource.Database:
|
||||
Program.databaseConnection.ApplicationSettings.ReloadSettings();
|
||||
|
||||
if (Program.databaseConnection.ApplicationSettings.WebserverPasswordTrayIcon != m_password)
|
||||
m_password = Program.databaseConnection.ApplicationSettings.WebserverPasswordTrayIcon;
|
||||
else
|
||||
hasTriedPassword = true;
|
||||
break;
|
||||
case Program.PasswordSource.HostedServer:
|
||||
if (Server.Program.DataConnection.ApplicationSettings.WebserverPassword != m_password)
|
||||
m_password = Server.Program.DataConnection.ApplicationSettings.WebserverPassword;
|
||||
else
|
||||
hasTriedPassword = true;
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
|
||||
m_authtoken = GetAuthToken();
|
||||
|
||||
@@ -8,6 +8,12 @@ namespace Duplicati.GUI.TrayIcon
|
||||
{
|
||||
public static class Program
|
||||
{
|
||||
public enum PasswordSource
|
||||
{
|
||||
Database,
|
||||
HostedServer
|
||||
}
|
||||
|
||||
public static HttpServerConnection Connection;
|
||||
|
||||
private const string TOOLKIT_OPTION = "toolkit";
|
||||
@@ -150,28 +156,28 @@ namespace Duplicati.GUI.TrayIcon
|
||||
openui = Duplicati.Server.Program.IsFirstRun || Duplicati.Server.Program.ServerPortChanged;
|
||||
password = Duplicati.Server.Program.DataConnection.ApplicationSettings.WebserverPassword;
|
||||
saltedpassword = true;
|
||||
serverURL = (new UriBuilder(serverURL) { Port = Duplicati.Server.Program.ServerPort }).Uri;
|
||||
|
||||
var cert = Duplicati.Server.Program.DataConnection.ApplicationSettings.ServerSSLCertificate;
|
||||
var scheme = "http";
|
||||
|
||||
if (cert != null && cert.HasPrivateKey)
|
||||
scheme = "https";
|
||||
|
||||
serverURL = (new UriBuilder(serverURL)
|
||||
{
|
||||
Port = Duplicati.Server.Program.ServerPort,
|
||||
Scheme = scheme
|
||||
}).Uri;
|
||||
}
|
||||
|
||||
if (Library.Utility.Utility.ParseBoolOption(options, NOHOSTEDSERVER_OPTION) && Library.Utility.Utility.ParseBoolOption(options, READCONFIGFROMDB_OPTION))
|
||||
databaseConnection = Server.Program.GetDatabaseConnection(options);
|
||||
|
||||
string pwd;
|
||||
|
||||
if (options.TryGetValue("webserver-password", out pwd))
|
||||
{
|
||||
password = pwd;
|
||||
saltedpassword = false;
|
||||
}
|
||||
|
||||
if (databaseConnection != null)
|
||||
{
|
||||
password = databaseConnection.ApplicationSettings.WebserverPasswordTrayIcon;
|
||||
saltedpassword = false;
|
||||
}
|
||||
|
||||
if (databaseConnection != null)
|
||||
{
|
||||
var cert = databaseConnection.ApplicationSettings.ServerSSLCertificate;
|
||||
var scheme = "http";
|
||||
|
||||
@@ -185,6 +191,14 @@ namespace Duplicati.GUI.TrayIcon
|
||||
}).Uri;
|
||||
}
|
||||
|
||||
string pwd;
|
||||
|
||||
if (options.TryGetValue("webserver-password", out pwd))
|
||||
{
|
||||
password = pwd;
|
||||
saltedpassword = false;
|
||||
}
|
||||
|
||||
string url;
|
||||
|
||||
if (options.TryGetValue(HOSTURL_OPTION, out url))
|
||||
@@ -200,7 +214,7 @@ namespace Duplicati.GUI.TrayIcon
|
||||
{
|
||||
System.Net.ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
|
||||
|
||||
using (Connection = new HttpServerConnection(serverURL, password, saltedpassword, databaseConnection != null, options))
|
||||
using (Connection = new HttpServerConnection(serverURL, password, saltedpassword, databaseConnection != null ? PasswordSource.Database : PasswordSource.HostedServer, options))
|
||||
{
|
||||
using (var tk = RunTrayIcon(toolkit))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user