2023-01-24 15:29:31 +01:00
|
|
|
|
/* Copyright (c) Cloud Software Group, Inc.
|
2013-06-24 13:41:48 +02:00
|
|
|
|
*
|
|
|
|
|
* Redistribution and use in source and binary forms,
|
|
|
|
|
* with or without modification, are permitted provided
|
|
|
|
|
* that the following conditions are met:
|
|
|
|
|
*
|
|
|
|
|
* * Redistributions of source code must retain the above
|
|
|
|
|
* copyright notice, this list of conditions and the
|
|
|
|
|
* following disclaimer.
|
|
|
|
|
* * Redistributions in binary form must reproduce the above
|
|
|
|
|
* copyright notice, this list of conditions and the
|
|
|
|
|
* following disclaimer in the documentation and/or other
|
|
|
|
|
* materials provided with the distribution.
|
|
|
|
|
*
|
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
|
|
|
|
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
|
|
|
|
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
|
|
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
|
|
|
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
|
|
|
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
|
|
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2022-11-11 14:57:37 +01:00
|
|
|
|
using System.Configuration;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Net;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using XenAdmin.Core;
|
|
|
|
|
using XenAdmin.Dialogs;
|
2019-08-13 10:50:23 +02:00
|
|
|
|
using XenAdmin.Dialogs.RestoreSession;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
using XenAdmin.Network;
|
2022-11-11 14:57:37 +01:00
|
|
|
|
using XenAPI;
|
2017-11-17 02:04:45 +01:00
|
|
|
|
using XenCenterLib;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace XenAdmin
|
|
|
|
|
{
|
|
|
|
|
public static class Settings
|
|
|
|
|
{
|
|
|
|
|
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
|
|
|
|
|
|
2022-11-11 14:57:37 +01:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Module for authenticating with proxy server using the Basic authentication scheme.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private static IAuthenticationModule BasicAuthenticationModule;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Module for authenticating with proxy server using the Digest authentication scheme.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private static IAuthenticationModule DigestAuthenticationModule;
|
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Used in place of the username, to indicate that a record is for a VM's VNC connection, rather
|
|
|
|
|
/// than a connection to a server.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private const string VNC_INDICATOR = "$VNC$";
|
|
|
|
|
|
|
|
|
|
private const char SEPARATOR = '\x202f'; // narrow non-breaking space.
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Anybody who chooses this for their password deserves a crash:
|
|
|
|
|
/// MODIFIER LETTER REVERSED GLOTTAL STOP, NKO SYMBOL GBAKURUNEN, CHAM PUNCTUATION DOUBLE DANDA, BOPOMOFO LETTER INNN
|
|
|
|
|
/// </summary>
|
2022-04-12 16:36:01 +02:00
|
|
|
|
private const string MARKER_VALUE = "\x02c1\x07f7\xaa5e\x31b3";
|
2013-06-24 13:41:48 +02:00
|
|
|
|
private const string DISCONNECTED = "disconnected";
|
|
|
|
|
private const string CONNECTED = "connected";
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// vm_uuid -> password. The password may be null if it's been deleted.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private static Dictionary<string, string> VNCPasswords = new Dictionary<string, string>();
|
|
|
|
|
|
2022-11-11 14:57:37 +01:00
|
|
|
|
|
|
|
|
|
static Settings()
|
|
|
|
|
{
|
|
|
|
|
// Store the Basic and Digest authentication modules, used for proxy server authentication,
|
|
|
|
|
// for later use; this is needed because we cannot create new instances of them and it
|
|
|
|
|
// saves us needing to create our own custom authentication modules.
|
|
|
|
|
|
|
|
|
|
var authModules = AuthenticationManager.RegisteredModules;
|
|
|
|
|
while (authModules.MoveNext())
|
|
|
|
|
{
|
|
|
|
|
if (!(authModules.Current is IAuthenticationModule module))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (module.AuthenticationType == "Basic")
|
|
|
|
|
BasicAuthenticationModule = module;
|
|
|
|
|
else if (module.AuthenticationType == "Digest")
|
|
|
|
|
DigestAuthenticationModule = module;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
/// <summary>
|
2022-01-24 20:55:38 +01:00
|
|
|
|
/// MSDN info regarding the path to the user.config file is somewhat confusing.
|
|
|
|
|
/// It turns out it is not in Application.UserAppDataPath as stated on
|
|
|
|
|
/// http://msdn.microsoft.com/en-us/library/8eyb2ct1.aspx. As described on
|
2013-06-24 13:41:48 +02:00
|
|
|
|
/// http://stackoverflow.com/questions/1075204/when-using-a-settings-settings-file-in-net-where-is-the-config-actually-stored
|
2022-01-24 20:55:38 +01:00
|
|
|
|
/// and on http://msdn.microsoft.com/en-us/library/ms379611.aspx, it is
|
|
|
|
|
/// ProfileDirectory\CompanyName\AppName_EvidenceType_EvidenceHash\Version\user.config
|
|
|
|
|
/// where
|
|
|
|
|
/// - ProfileDirectory: either the roaming profile directory or the local one.
|
|
|
|
|
/// Settings are stored by default in the local user.config file. To store a
|
|
|
|
|
/// setting in the roaming user.config file, you need to mark the setting with
|
|
|
|
|
/// the SettingsManageabilityAttribute with SettingsManageability set to Roaming.
|
|
|
|
|
/// - CompanyName: typically the string specified by the AssemblyCompanyAttribute
|
|
|
|
|
/// (with the caveat that the string is escaped and truncated as necessary, and if
|
|
|
|
|
/// not specified on the assembly, we have a fallback procedure).
|
|
|
|
|
/// - AppName: typically the string specified by the AssemblyProductAttribute
|
|
|
|
|
/// (same caveats as for company name).
|
|
|
|
|
/// - EvidenceType and EvidenceHash: information derived from the app domain evidence
|
|
|
|
|
/// to provide proper app domain and assembly isolation.
|
|
|
|
|
/// - Version: typically the version specified in the AssemblyVersionAttribute.
|
|
|
|
|
/// This is required to isolate different versions of the app deployed side by side.
|
|
|
|
|
/// - The file name is always simply 'user.config
|
|
|
|
|
/// Trying to retrieve the filename at the places where this method's caller caught
|
|
|
|
|
/// the ConfigurationErrorsException returns null, so this one has to be called.
|
2013-06-24 13:41:48 +02:00
|
|
|
|
/// </summary>
|
|
|
|
|
public static string GetUserConfigPath()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoaming);
|
|
|
|
|
return config.FilePath;
|
|
|
|
|
}
|
|
|
|
|
catch (ConfigurationErrorsException exc)
|
|
|
|
|
{
|
|
|
|
|
return exc.Filename;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void RestoreSession()
|
|
|
|
|
{
|
|
|
|
|
if (Program.RunInAutomatedTestMode)
|
|
|
|
|
{
|
|
|
|
|
Program.SkipSessionSave = true;
|
|
|
|
|
Properties.Settings.Default.SaveSession = false;
|
|
|
|
|
return;
|
|
|
|
|
}
|
2020-10-27 03:10:44 +01:00
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
if (!Registry.AllowCredentialSave)
|
|
|
|
|
{
|
|
|
|
|
Program.SkipSessionSave = true;
|
|
|
|
|
Properties.Settings.Default.SaveSession = false;
|
|
|
|
|
Properties.Settings.Default.RequirePass = false;
|
|
|
|
|
RestoreSessionWithPassword(null, false);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2020-10-27 03:10:44 +01:00
|
|
|
|
|
2021-08-31 12:31:16 +02:00
|
|
|
|
Program.MainPassword = null;
|
2020-10-27 03:10:44 +01:00
|
|
|
|
|
|
|
|
|
if (Properties.Settings.Default.SaveSession || Properties.Settings.Default.RequirePass)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2020-10-27 03:10:44 +01:00
|
|
|
|
if (Properties.Settings.Default.ServerList != null && Properties.Settings.Default.ServerList.Length > 0 ||
|
|
|
|
|
Properties.Settings.Default.ServerAddressList != null && Properties.Settings.Default.ServerAddressList.Length > 0)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
if (!Properties.Settings.Default.RequirePass)
|
|
|
|
|
{
|
|
|
|
|
Program.SkipSessionSave = true;
|
|
|
|
|
RestoreSessionWithPassword(null, true);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-08 12:18:35 +01:00
|
|
|
|
Program.MainWindow.CloseSplashScreen();
|
2020-10-27 03:10:44 +01:00
|
|
|
|
|
|
|
|
|
string password = null;
|
|
|
|
|
do
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2020-10-27 03:10:44 +01:00
|
|
|
|
using (var dialog = new LoadSessionDialog(password != null))
|
|
|
|
|
password = dialog.ShowDialog(Program.MainWindow) == DialogResult.OK
|
|
|
|
|
? dialog.Password
|
|
|
|
|
: null;
|
|
|
|
|
} while (password != null && !RestoreSessionWithPassword(password, true));
|
|
|
|
|
|
|
|
|
|
Properties.Settings.Default.SaveSession = password != null;
|
|
|
|
|
Properties.Settings.Default.RequirePass = true;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
Program.SkipSessionSave = true;
|
2020-10-27 03:10:44 +01:00
|
|
|
|
|
|
|
|
|
if (password == null)
|
|
|
|
|
RestoreSessionWithPassword(null, false); //if the user has cancelled start a new session
|
|
|
|
|
else
|
2021-08-31 12:31:16 +02:00
|
|
|
|
Program.MainPassword = EncryptionUtils.ComputeHash(password);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Properties.Settings.Default.RequirePass = false;
|
|
|
|
|
Properties.Settings.Default.SaveSession = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Program.SkipSessionSave = true;
|
|
|
|
|
RestoreSessionWithPassword(null, false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2020-10-27 03:10:44 +01:00
|
|
|
|
/// Tries to restore the session list using the given password as the key.
|
|
|
|
|
/// Returns true if successful, false otherwise (usually due to
|
2013-06-24 13:41:48 +02:00
|
|
|
|
/// a decryption failure, in turn due to a wrong password).
|
|
|
|
|
/// </summary>
|
2020-10-27 03:10:44 +01:00
|
|
|
|
private static bool RestoreSessionWithPassword(string password, bool useOriginalList)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
string[] encServerList;
|
|
|
|
|
|
|
|
|
|
if (useOriginalList)
|
|
|
|
|
{
|
|
|
|
|
// if we are resuming without a password or have a valid password use Settings.ServerList
|
|
|
|
|
encServerList = Properties.Settings.Default.ServerList ?? new string[0];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// user has cancelled, use the ServerAddressList (no usernames or passwords)
|
|
|
|
|
encServerList = Properties.Settings.Default.ServerAddressList ?? new string[0];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string[] decryptedList = new string[encServerList.Length];
|
|
|
|
|
if (!Properties.Settings.Default.RequirePass || !useOriginalList)
|
|
|
|
|
{
|
|
|
|
|
int idx = 0;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
foreach (string encEntry in encServerList)
|
|
|
|
|
{
|
|
|
|
|
decryptedList[idx] = EncryptionUtils.Unprotect(encEntry);
|
|
|
|
|
idx++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception exp)
|
|
|
|
|
{
|
|
|
|
|
log.Warn("Could not unprotect session information", exp);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
int idx = 0;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
foreach (string encEntry in encServerList)
|
|
|
|
|
{
|
2020-10-27 03:10:44 +01:00
|
|
|
|
decryptedList[idx] = EncryptionUtils.DecryptString(encEntry, password);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
idx++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception exp)
|
|
|
|
|
{
|
|
|
|
|
log.Warn("Could not decrypt session information", exp);
|
|
|
|
|
// Problem decrypting -> wrong password entered...
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Validate the decrypted entries - the session entries may
|
|
|
|
|
// have been decrypted to nonsense...
|
|
|
|
|
foreach (string entry in decryptedList)
|
|
|
|
|
{
|
|
|
|
|
string[] entryComps = entry.Split(SEPARATOR);
|
|
|
|
|
if (entryComps.Length < 3 || entryComps.Length > 7)
|
|
|
|
|
{
|
|
|
|
|
log.Warn("Did not decrypt session list to a valid entry...");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (string entry in decryptedList)
|
|
|
|
|
{
|
|
|
|
|
// $VNC$, VM UUID, unused, password
|
|
|
|
|
// username, hostname, port, password
|
|
|
|
|
// username, hostname, port, password, connected
|
|
|
|
|
// username, hostname, port, password, connected, friendly name
|
|
|
|
|
// username, hostname, port, password, connected, friendly name, pool members
|
|
|
|
|
|
|
|
|
|
// If the user cancels the restore dialog, we use the ServerAddressList instead:
|
|
|
|
|
// hostname, port, friendly name
|
|
|
|
|
|
|
|
|
|
string[] entryComps = entry.Split(SEPARATOR);
|
|
|
|
|
|
|
|
|
|
int port;
|
|
|
|
|
if (!int.TryParse(entryComps[2], out port))
|
|
|
|
|
{
|
|
|
|
|
port = ConnectionsManager.DEFAULT_XEN_PORT;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (entryComps[0] == VNC_INDICATOR)
|
|
|
|
|
{
|
|
|
|
|
string vm_uuid = entryComps[1];
|
|
|
|
|
VNCPasswords[vm_uuid] = entryComps[3];
|
|
|
|
|
}
|
|
|
|
|
else if (entryComps.Length == 3)
|
|
|
|
|
{
|
|
|
|
|
if (!int.TryParse(entryComps[1], out port))
|
|
|
|
|
{
|
|
|
|
|
port = ConnectionsManager.DEFAULT_XEN_PORT;
|
|
|
|
|
}
|
|
|
|
|
IXenConnection connection = new XenConnection();
|
|
|
|
|
connection.Hostname = entryComps[0];
|
|
|
|
|
connection.Port = port;
|
|
|
|
|
connection.Password = null;
|
|
|
|
|
connection.SaveDisconnected = true;
|
|
|
|
|
connection.FriendlyName = entryComps[2] != "" ? entryComps[2] : entryComps[0];
|
|
|
|
|
|
|
|
|
|
AddConnection(connection);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
IXenConnection connection = new XenConnection();
|
|
|
|
|
connection.Username = entryComps[0];
|
|
|
|
|
connection.Hostname = entryComps[1];
|
|
|
|
|
connection.Port = port;
|
2022-04-12 16:36:01 +02:00
|
|
|
|
// If password is MARKER_VALUE, this indicates we didn't save a password for this connection
|
|
|
|
|
if (entryComps[3] == MARKER_VALUE)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
connection.Password = null;
|
|
|
|
|
connection.ExpectPasswordIsCorrect = false;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
connection.Password = entryComps[3];
|
|
|
|
|
}
|
|
|
|
|
connection.SaveDisconnected = entryComps.Length > 4 && entryComps[4] == DISCONNECTED;
|
|
|
|
|
connection.FriendlyName = entryComps.Length > 5 ? entryComps[5] : entryComps[1];
|
|
|
|
|
|
2021-08-31 12:31:16 +02:00
|
|
|
|
// We save a comma-separated list of hostnames of each of the supporters.
|
|
|
|
|
// This enables us to connect to a former supporter in the event of coordinator failover while the GUI isn't running.
|
2013-06-24 13:41:48 +02:00
|
|
|
|
if (entryComps.Length == 7 && entryComps[6] != "")
|
|
|
|
|
{
|
|
|
|
|
connection.PoolMembers = new List<string>(entryComps[6].Split(new char[] { ',' }));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
connection.PoolMembers = new List<string>(new string[] { connection.Hostname });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AddConnection(connection);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-29 16:19:05 +01:00
|
|
|
|
public static void ConfigureExternalSshClientSettings()
|
|
|
|
|
{
|
|
|
|
|
var customSshClient = Properties.Settings.Default.CustomSshConsole;
|
|
|
|
|
var puttyLocation = Properties.Settings.Default.PuttyLocation;
|
|
|
|
|
var openSshLocation = Properties.Settings.Default.OpenSSHLocation;
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(puttyLocation) && customSshClient == SshConsole.Putty ||
|
|
|
|
|
string.IsNullOrEmpty(openSshLocation) && customSshClient == SshConsole.OpenSSH)
|
|
|
|
|
{
|
|
|
|
|
customSshClient = SshConsole.None;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// attempt to locate clients in their default locations
|
|
|
|
|
if (string.IsNullOrEmpty(puttyLocation))
|
|
|
|
|
{
|
|
|
|
|
var defaultPaths = new[] {
|
|
|
|
|
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "PuTTY\\putty.exe"),
|
|
|
|
|
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), "PuTTY\\putty.exe")
|
|
|
|
|
};
|
|
|
|
|
puttyLocation = defaultPaths.Where(File.Exists).FirstOrDefault();
|
|
|
|
|
}
|
|
|
|
|
if (string.IsNullOrEmpty(openSshLocation))
|
|
|
|
|
{
|
|
|
|
|
// https://docs.microsoft.com/en-us/windows-server/administration/openssh/openssh_server_configuration
|
|
|
|
|
var defaultPath = Path.Combine(Environment.SystemDirectory, "OpenSSH\\ssh.exe");
|
|
|
|
|
openSshLocation = File.Exists(defaultPath) ? defaultPath : openSshLocation;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// we prioritize PuTTY since that must have been installed by the user
|
|
|
|
|
if (customSshClient == SshConsole.None)
|
|
|
|
|
{
|
|
|
|
|
if (!string.IsNullOrEmpty(puttyLocation))
|
|
|
|
|
{
|
|
|
|
|
customSshClient = SshConsole.Putty;
|
|
|
|
|
}
|
|
|
|
|
else if (!string.IsNullOrEmpty(openSshLocation))
|
|
|
|
|
{
|
|
|
|
|
customSshClient = SshConsole.OpenSSH;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-11 17:33:04 +01:00
|
|
|
|
var needToSave = false;
|
2021-11-29 16:19:05 +01:00
|
|
|
|
// avoid updating settings if they haven't changed
|
|
|
|
|
if (customSshClient != Properties.Settings.Default.CustomSshConsole)
|
|
|
|
|
{
|
|
|
|
|
Properties.Settings.Default.CustomSshConsole = customSshClient;
|
2022-11-11 17:33:04 +01:00
|
|
|
|
needToSave = true;
|
2021-11-29 16:19:05 +01:00
|
|
|
|
}
|
|
|
|
|
if (puttyLocation != null && !puttyLocation.Equals(Properties.Settings.Default.PuttyLocation))
|
|
|
|
|
{
|
|
|
|
|
Properties.Settings.Default.PuttyLocation = puttyLocation;
|
2022-11-11 17:33:04 +01:00
|
|
|
|
needToSave = true;
|
2021-11-29 16:19:05 +01:00
|
|
|
|
}
|
|
|
|
|
if (openSshLocation != null && !openSshLocation.Equals(Properties.Settings.Default.OpenSSHLocation))
|
|
|
|
|
{
|
|
|
|
|
Properties.Settings.Default.OpenSSHLocation = openSshLocation;
|
2022-11-11 17:33:04 +01:00
|
|
|
|
needToSave = true;
|
2021-11-29 16:19:05 +01:00
|
|
|
|
}
|
2022-01-10 12:15:02 +01:00
|
|
|
|
|
2022-11-11 17:33:04 +01:00
|
|
|
|
if (needToSave)
|
|
|
|
|
TrySaveSettings();
|
2021-11-29 16:19:05 +01:00
|
|
|
|
}
|
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
private static void AddConnection(IXenConnection connection)
|
|
|
|
|
{
|
|
|
|
|
if (ConnectionsManager.XenConnectionsContains(connection))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
XenConnection conn = connection as XenConnection;
|
|
|
|
|
conn.LastConnectionFullName =
|
|
|
|
|
string.IsNullOrEmpty(connection.FriendlyName) ?
|
|
|
|
|
connection.Hostname :
|
|
|
|
|
string.Format("{0} ({1})", connection.FriendlyName, connection.Hostname);
|
|
|
|
|
|
|
|
|
|
lock (ConnectionsManager.ConnectionsLock)
|
|
|
|
|
{
|
|
|
|
|
ConnectionsManager.XenConnections.Add(connection);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// If an exception is thrown while saving the list, this method will notify the user
|
|
|
|
|
/// and then call Application.Exit().
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static void SaveServerList()
|
|
|
|
|
{
|
|
|
|
|
Program.AssertOnEventThread();
|
|
|
|
|
|
|
|
|
|
// Check that there is something to do...
|
|
|
|
|
if (ConnectionsManager.XenConnectionsCopy.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
// Ensure the list is empty in the serialized settings file...
|
|
|
|
|
Properties.Settings.Default.ServerList = new string[0];
|
|
|
|
|
Properties.Settings.Default.ServerAddressList = new string[0];
|
|
|
|
|
TrySaveSettings();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!Program.SkipSessionSave && Registry.AllowCredentialSave)
|
|
|
|
|
{
|
|
|
|
|
if (Program.RunInAutomatedTestMode)
|
|
|
|
|
log.Debug("In automated test mode: not showing save session dialog");
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-06-20 12:30:22 +02:00
|
|
|
|
using (var dialog = new SaveAndRestoreDialog())
|
|
|
|
|
dialog.ShowDialog(Program.MainWindow);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
Program.SkipSessionSave = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
EncryptServerList();
|
|
|
|
|
TrySaveSettings();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Attempts to save the settings. On catching an exception will prompt the user and close XC.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static void TrySaveSettings()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
Properties.Settings.Default.Save();
|
|
|
|
|
}
|
2022-11-11 17:33:04 +01:00
|
|
|
|
catch (Exception ex)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2022-11-11 17:33:04 +01:00
|
|
|
|
//catch all as ConfigurationErrorsException does not account for all errors that may happen
|
|
|
|
|
log.Error("Could not save settings. Exiting application.", ex);
|
|
|
|
|
|
|
|
|
|
using (var dlg = new ErrorDialog(string.Format(Messages.MESSAGEBOX_SAVE_CORRUPTED, GetUserConfigPath()))
|
2024-01-01 20:06:36 +01:00
|
|
|
|
{ WindowTitle = Messages.MESSAGEBOX_SAVE_CORRUPTED_TITLE })
|
2016-06-20 11:49:12 +02:00
|
|
|
|
{
|
|
|
|
|
dlg.ShowDialog(Program.MainWindow);
|
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
Application.Exit();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void EncryptServerList()
|
|
|
|
|
{
|
|
|
|
|
List<string> encServerList = new List<string>();
|
|
|
|
|
List<string> encServerAddressList = new List<string>();
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
foreach (IXenConnection connection in ConnectionsManager.XenConnectionsCopy)
|
|
|
|
|
{
|
|
|
|
|
int port = connection.Port;
|
|
|
|
|
if (port <= 0)
|
|
|
|
|
port = ConnectionsManager.DEFAULT_XEN_PORT;
|
|
|
|
|
|
|
|
|
|
if (Properties.Settings.Default.SaveSession)
|
|
|
|
|
{
|
|
|
|
|
encServerList.Add(EncryptCredentials(connection.Hostname, port, connection.Username, connection.Password,
|
|
|
|
|
!connection.IsConnected, connection.FriendlyName, connection.PoolMembers));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Save the address, port and friendly name in case the user clicks cancel on the resume password dialog
|
2020-10-27 03:10:44 +01:00
|
|
|
|
string entryAddress = ProtectCredentials(connection.Hostname, port, connection.FriendlyName);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
encServerAddressList.Add(entryAddress);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Properties.Settings.Default.SaveSession)
|
|
|
|
|
{
|
|
|
|
|
foreach (string vm_uuid in VNCPasswords.Keys)
|
|
|
|
|
{
|
|
|
|
|
string pwd = VNCPasswords[vm_uuid];
|
|
|
|
|
if (pwd != null)
|
|
|
|
|
encServerList.Add(EncryptCredentials(vm_uuid, -1, VNC_INDICATOR, pwd, false, "", null));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Properties.Settings.Default.SaveSession)
|
|
|
|
|
Properties.Settings.Default.ServerList = encServerList.ToArray();
|
|
|
|
|
Properties.Settings.Default.ServerAddressList = encServerAddressList.ToArray();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception exp)
|
|
|
|
|
{
|
|
|
|
|
// Problem encrypting
|
|
|
|
|
log.Error("Could not encrypt session.", exp);
|
|
|
|
|
|
|
|
|
|
// Ugly, but we need to warn the user...
|
|
|
|
|
if (!Program.RunInAutomatedTestMode)
|
2020-04-22 15:47:03 +02:00
|
|
|
|
using (var dlg = new WarningDialog(Messages.MESSAGEBOX_SESSION_SAVE_UNABLE)
|
2024-01-01 20:06:36 +01:00
|
|
|
|
{ WindowTitle = Messages.MESSAGEBOX_SESSION_SAVE_UNABLE_TITLE })
|
2016-06-20 11:49:12 +02:00
|
|
|
|
{
|
|
|
|
|
dlg.ShowDialog();
|
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-27 03:10:44 +01:00
|
|
|
|
private static string ProtectCredentials(String serverName, int port, string friendlyName)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
string entryStr = string.Join(SEPARATOR.ToString(), new string[] { serverName, port.ToString(), friendlyName });
|
|
|
|
|
return EncryptionUtils.Protect(entryStr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static String EncryptCredentials(String serverName, int port, String username, String password, bool saveDisconnected, string friendlyName, List<string> poolMembers)
|
|
|
|
|
{
|
|
|
|
|
if (password == null)
|
|
|
|
|
{
|
|
|
|
|
// We don't have a password saved for this connection: save a special marker value
|
2022-04-12 16:36:01 +02:00
|
|
|
|
password = MARKER_VALUE;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
string entryStr = string.Join(SEPARATOR.ToString(), new string[] { username, serverName, port.ToString(), password, (saveDisconnected ? DISCONNECTED : CONNECTED), friendlyName });
|
|
|
|
|
if (poolMembers != null && poolMembers.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
string members = string.Join(",", poolMembers.ToArray());
|
|
|
|
|
entryStr += SEPARATOR.ToString();
|
|
|
|
|
entryStr += members;
|
|
|
|
|
}
|
2021-08-31 12:31:16 +02:00
|
|
|
|
return Properties.Settings.Default.RequirePass && Program.MainPassword != null ? EncryptionUtils.EncryptString(entryStr, Program.MainPassword) : EncryptionUtils.Protect(entryStr);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2023-03-17 17:11:49 +01:00
|
|
|
|
public static string[] GetServerHistory()
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2018-07-19 20:52:12 +02:00
|
|
|
|
if (Properties.Settings.Default.ServerHistory == null)
|
2023-03-17 17:11:49 +01:00
|
|
|
|
Properties.Settings.Default.ServerHistory = Array.Empty<string>();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2018-07-19 20:52:12 +02:00
|
|
|
|
return Properties.Settings.Default.ServerHistory;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void UpdateServerHistory(string hostnameWithPort)
|
|
|
|
|
{
|
2023-03-17 17:11:49 +01:00
|
|
|
|
var history = new List<string>(GetServerHistory());
|
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
if (!history.Contains(hostnameWithPort))
|
|
|
|
|
{
|
|
|
|
|
while (history.Count >= 20)
|
|
|
|
|
history.RemoveAt(0);
|
|
|
|
|
history.Add(hostnameWithPort);
|
2023-03-17 17:11:49 +01:00
|
|
|
|
Properties.Settings.Default.ServerHistory = history.ToArray();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
TrySaveSettings();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-22 11:47:43 +02:00
|
|
|
|
public static AutoCompleteStringCollection GetVMwareServerHistory()
|
|
|
|
|
{
|
|
|
|
|
if (Properties.Settings.Default.VMwareServerHistory == null)
|
|
|
|
|
Properties.Settings.Default.VMwareServerHistory = new AutoCompleteStringCollection();
|
|
|
|
|
|
|
|
|
|
return Properties.Settings.Default.VMwareServerHistory;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void UpdateVMwareServerHistory(string server)
|
|
|
|
|
{
|
|
|
|
|
var history = GetVMwareServerHistory();
|
|
|
|
|
if (history.Contains(server))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
while (history.Count >= 20)
|
|
|
|
|
history.RemoveAt(0);
|
|
|
|
|
|
|
|
|
|
history.Add(server);
|
|
|
|
|
Properties.Settings.Default.VMwareServerHistory = history;
|
|
|
|
|
TrySaveSettings();
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="vm_uuid"></param>
|
|
|
|
|
/// <returns>The password corresponding to the given VM, or null if no password is stored.</returns>
|
|
|
|
|
public static char[] GetVNCPassword(string vm_uuid)
|
|
|
|
|
{
|
|
|
|
|
return
|
|
|
|
|
VNCPasswords.ContainsKey(vm_uuid) && VNCPasswords[vm_uuid] != null ?
|
|
|
|
|
VNCPasswords[vm_uuid].ToCharArray() :
|
|
|
|
|
null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="vm_uuid"></param>
|
|
|
|
|
/// <param name="password">May be null, to clear the password</param>
|
|
|
|
|
public static void SetVNCPassword(string vm_uuid, char[] password)
|
|
|
|
|
{
|
|
|
|
|
VNCPasswords[vm_uuid] = password == null ? null : new string(password);
|
|
|
|
|
SaveServerList();
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-05 17:26:45 +02:00
|
|
|
|
public static void AddCertificate(string hashString, string hostname)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
Dictionary<string, string> known_servers = KnownServers;
|
2020-04-05 17:26:45 +02:00
|
|
|
|
known_servers.Add(hostname, hashString);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
KnownServers = known_servers;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static Dictionary<string, string> KnownServers
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2018-07-19 20:52:12 +02:00
|
|
|
|
var known = new Dictionary<string, string>();
|
|
|
|
|
|
|
|
|
|
var knownServers = Properties.Settings.Default.KnownServers;
|
|
|
|
|
if (knownServers == null)
|
|
|
|
|
return known;
|
2024-01-01 20:06:36 +01:00
|
|
|
|
|
2018-07-19 20:52:12 +02:00
|
|
|
|
foreach (string knownHost in knownServers)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2018-07-19 20:52:12 +02:00
|
|
|
|
string[] hostCert = knownHost.Split(' ');
|
|
|
|
|
if (hostCert.Length != 2)
|
|
|
|
|
continue;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2018-07-19 20:52:12 +02:00
|
|
|
|
known.Add(hostCert[0], hostCert[1]);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
return known;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
2018-07-19 20:52:12 +02:00
|
|
|
|
Properties.Settings.Default.KnownServers = value == null
|
|
|
|
|
? new string[0]
|
|
|
|
|
: value.Select(kvp => string.Format("{0} {1}", kvp.Key, kvp.Value)).ToArray();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2018-07-19 20:52:12 +02:00
|
|
|
|
TrySaveSettings();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-05 17:26:45 +02:00
|
|
|
|
public static void ReplaceCertificate(string hostname, string hashString)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
Dictionary<string, string> known_servers = KnownServers;
|
2020-04-05 17:26:45 +02:00
|
|
|
|
known_servers[hostname] = hashString;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
KnownServers = known_servers;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void UpdateDisabledPluginsList(List<string> list)
|
|
|
|
|
{
|
|
|
|
|
Properties.Settings.Default.DisabledPlugins = list.ToArray();
|
|
|
|
|
TrySaveSettings();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static bool IsPluginEnabled(string name, string org)
|
|
|
|
|
{
|
2020-06-19 18:31:01 +02:00
|
|
|
|
string id = $"{org}::{name}";
|
|
|
|
|
return Properties.Settings.Default.DisabledPlugins.All(s => s != id);
|
|
|
|
|
//returns true for empty collection, which is correct
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void Log()
|
|
|
|
|
{
|
|
|
|
|
log.Info("Tools Options Settings -");
|
|
|
|
|
|
|
|
|
|
log.Info($"=== ProxySetting: {Properties.Settings.Default.ProxySetting}");
|
|
|
|
|
log.Info($"=== ProxyAddress: {Properties.Settings.Default.ProxyAddress}");
|
|
|
|
|
log.Info($"=== ProxyPort: {Properties.Settings.Default.ProxyPort}");
|
|
|
|
|
log.Info($"=== ByPassProxyForServers: {Properties.Settings.Default.BypassProxyForServers}");
|
|
|
|
|
log.Info($"=== ProvideProxyAuthentication: {Properties.Settings.Default.ProvideProxyAuthentication}");
|
|
|
|
|
log.Info($"=== ProxyAuthenticationMethod: {Properties.Settings.Default.ProxyAuthenticationMethod}");
|
|
|
|
|
log.Info($"=== ConnectionTimeout: {Properties.Settings.Default.ConnectionTimeout}");
|
|
|
|
|
|
|
|
|
|
log.Info($"=== FullScreenShortcutKey: {Properties.Settings.Default.FullScreenShortcutKey}");
|
|
|
|
|
log.Info($"=== DockShortcutKey: {Properties.Settings.Default.DockShortcutKey}");
|
|
|
|
|
log.Info($"=== UncaptureShortcutKey: {Properties.Settings.Default.UncaptureShortcutKey}");
|
|
|
|
|
log.Info($"=== ClipboardAndPrinterRedirection: {Properties.Settings.Default.ClipboardAndPrinterRedirection}");
|
|
|
|
|
log.Info($"=== WindowsShortcuts: {Properties.Settings.Default.WindowsShortcuts}");
|
|
|
|
|
log.Info($"=== ReceiveSoundFromRDP: {Properties.Settings.Default.ReceiveSoundFromRDP}");
|
|
|
|
|
log.Info($"=== AutoSwitchToRDP: {Properties.Settings.Default.AutoSwitchToRDP}");
|
|
|
|
|
log.Info($"=== ConnectToServerConsole: {Properties.Settings.Default.ConnectToServerConsole}");
|
|
|
|
|
log.Info($"=== PreserveScaleWhenUndocked: {Properties.Settings.Default.PreserveScaleWhenUndocked}");
|
|
|
|
|
log.Info($"=== PreserveScaleWhenSwitchBackToVNC: {Properties.Settings.Default.PreserveScaleWhenSwitchBackToVNC}");
|
|
|
|
|
|
|
|
|
|
log.Info($"=== WarnUnrecognizedCertificate: {Properties.Settings.Default.WarnUnrecognizedCertificate}");
|
|
|
|
|
log.Info($"=== WarnChangedCertificate: {Properties.Settings.Default.WarnChangedCertificate}");
|
2020-08-11 14:35:39 +02:00
|
|
|
|
log.Info($"=== RemindChangePassword: {Properties.Settings.Default.RemindChangePassword}");
|
2020-06-19 18:31:01 +02:00
|
|
|
|
|
2024-01-01 20:06:36 +01:00
|
|
|
|
//do not log Fileservice settings
|
|
|
|
|
log.Info($"=== AllowXenCenterUpdates: {Properties.Settings.Default.AllowXenCenterUpdates}");
|
|
|
|
|
log.Info($"=== AllowPatchesUpdates: {Properties.Settings.Default.AllowPatchesUpdates}");
|
|
|
|
|
log.Info($"=== AllowXenServerUpdates: {Properties.Settings.Default.AllowXenServerUpdates}");
|
2022-06-08 16:51:44 +02:00
|
|
|
|
|
2020-06-19 18:31:01 +02:00
|
|
|
|
log.Info($"=== FillAreaUnderGraphs: {Properties.Settings.Default.FillAreaUnderGraphs}");
|
|
|
|
|
log.Info($"=== RememberLastSelectedTab: {Properties.Settings.Default.RememberLastSelectedTab}");
|
|
|
|
|
|
|
|
|
|
log.Info($"=== SaveSession: {Properties.Settings.Default.SaveSession}");
|
|
|
|
|
log.Info($"=== RequirePass: {Properties.Settings.Default.RequirePass}");
|
|
|
|
|
|
|
|
|
|
var disabledPlugins = Properties.Settings.Default.DisabledPlugins.Length == 0
|
|
|
|
|
? "<None>"
|
|
|
|
|
: string.Join(", ", Properties.Settings.Default.DisabledPlugins);
|
|
|
|
|
log.InfoFormat($"=== DisabledPlugins: {disabledPlugins}");
|
|
|
|
|
|
|
|
|
|
log.Info($"=== DoNotConfirmDismissAlerts: {Properties.Settings.Default.DoNotConfirmDismissAlerts}");
|
2024-01-01 20:06:36 +01:00
|
|
|
|
log.Info($"=== DoNotConfirmDismissUpdates: {Properties.Settings.Default.DoNotConfirmDismissUpdates}");
|
|
|
|
|
log.Info($"=== DoNotConfirmDismissEvents: {Properties.Settings.Default.DoNotConfirmDismissEvents}");
|
2020-06-19 18:31:01 +02:00
|
|
|
|
log.Info($"=== IgnoreOvfValidationWarnings: {Properties.Settings.Default.IgnoreOvfValidationWarnings}");
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
2022-01-13 12:04:13 +01:00
|
|
|
|
|
2022-11-11 14:57:37 +01:00
|
|
|
|
public static void Load()
|
|
|
|
|
{
|
|
|
|
|
string appVersionString = Program.Version.ToString();
|
|
|
|
|
log.InfoFormat("Application version of current settings {0}", appVersionString);
|
|
|
|
|
|
2022-11-11 17:33:04 +01:00
|
|
|
|
if (Properties.Settings.Default.ApplicationVersion != appVersionString)
|
2022-11-11 14:57:37 +01:00
|
|
|
|
{
|
2022-11-11 17:33:04 +01:00
|
|
|
|
log.Info("Upgrading settings...");
|
|
|
|
|
Properties.Settings.Default.Upgrade();
|
2022-11-11 14:57:37 +01:00
|
|
|
|
|
2022-11-11 17:33:04 +01:00
|
|
|
|
// if program's hash has changed (e.g. by upgrading to .NET 4.0), then Upgrade() doesn't import the previous application settings
|
|
|
|
|
// because it cannot locate a previous user.config file. In this case a new user.config file is created with the default settings.
|
|
|
|
|
// We will try and find a config file from a previous installation and update the settings from it
|
2022-11-11 14:57:37 +01:00
|
|
|
|
|
2022-11-11 17:33:04 +01:00
|
|
|
|
if (Properties.Settings.Default.ApplicationVersion == "" && Properties.Settings.Default.DoUpgrade)
|
|
|
|
|
UpgradeFromPreviousInstallation();
|
2022-11-11 14:57:37 +01:00
|
|
|
|
|
2022-11-11 17:33:04 +01:00
|
|
|
|
log.InfoFormat("Settings upgraded from '{0}' to '{1}'", Properties.Settings.Default.ApplicationVersion, appVersionString);
|
|
|
|
|
Properties.Settings.Default.ApplicationVersion = appVersionString;
|
|
|
|
|
TrySaveSettings();
|
2022-11-11 14:57:37 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-13 12:04:13 +01:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Looks for a config file from a previous installation of the application and updates the settings from it.
|
|
|
|
|
/// </summary>
|
2022-11-11 14:57:37 +01:00
|
|
|
|
private static void UpgradeFromPreviousInstallation()
|
2022-01-13 12:04:13 +01:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
// The path of the user.config files looks something like this:
|
|
|
|
|
// <Profile Directory>\<Company Name>\<App Name>_<Evidence Type>_<Evidence Hash>\<Version>\user.config
|
|
|
|
|
// Get a previous user.config file by enumerating through all the folders in <Profile Directory>\<Company Name>
|
|
|
|
|
|
2022-01-24 20:55:38 +01:00
|
|
|
|
var currentConfigFolder = new DirectoryInfo(GetUserConfigPath()).Parent;
|
2022-01-13 12:04:13 +01:00
|
|
|
|
|
|
|
|
|
var companyFolder = currentConfigFolder?.Parent?.Parent;
|
|
|
|
|
if (companyFolder == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
FileInfo previousConfig = null;
|
|
|
|
|
Version previousVersion = null;
|
|
|
|
|
Version currentVersion = Program.Version;
|
|
|
|
|
|
2023-09-06 16:48:12 +02:00
|
|
|
|
var directories = companyFolder.GetDirectories($"{BrandManager.BrandConsole}*");
|
2022-01-24 20:55:38 +01:00
|
|
|
|
|
|
|
|
|
foreach (var dir in directories)
|
2022-01-13 12:04:13 +01:00
|
|
|
|
{
|
2022-01-24 20:55:38 +01:00
|
|
|
|
var configFiles = dir.GetFiles("user.config", SearchOption.AllDirectories);
|
|
|
|
|
|
|
|
|
|
foreach (var file in configFiles)
|
2022-01-13 12:04:13 +01:00
|
|
|
|
{
|
|
|
|
|
var configFolderName = Path.GetFileName(Path.GetDirectoryName(file.FullName));
|
|
|
|
|
if (configFolderName != null)
|
|
|
|
|
{
|
|
|
|
|
var configVersion = new Version(configFolderName);
|
|
|
|
|
|
|
|
|
|
if (configVersion <= currentVersion && (previousVersion == null || configVersion > previousVersion))
|
|
|
|
|
{
|
|
|
|
|
previousVersion = configVersion;
|
|
|
|
|
previousConfig = file;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (previousConfig != null)
|
|
|
|
|
{
|
|
|
|
|
// copy previous config file to current config location
|
|
|
|
|
var destinationFile = Path.GetDirectoryName(currentConfigFolder.FullName);
|
|
|
|
|
|
|
|
|
|
destinationFile = Path.Combine(destinationFile, previousVersion.ToString());
|
|
|
|
|
|
|
|
|
|
if (!Directory.Exists(destinationFile))
|
|
|
|
|
Directory.CreateDirectory(destinationFile);
|
|
|
|
|
|
|
|
|
|
destinationFile = Path.Combine(destinationFile, previousConfig.Name);
|
|
|
|
|
|
|
|
|
|
File.Copy(previousConfig.FullName, destinationFile);
|
|
|
|
|
|
|
|
|
|
// upgrade settings
|
|
|
|
|
XenAdmin.Properties.Settings.Default.Upgrade();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
log.Debug("Exception while updating settings.", ex);
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-11-11 14:57:37 +01:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Configures .NET's AuthenticationManager to only use the authentication module that is
|
|
|
|
|
/// specified in the ProxyAuthenticationMethod setting. Also sets XenAPI's HTTP class to
|
|
|
|
|
/// use the same authentication method.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static void ReconfigureProxyAuthenticationSettings()
|
|
|
|
|
{
|
|
|
|
|
var authModules = AuthenticationManager.RegisteredModules;
|
|
|
|
|
var modulesToUnregister = new List<IAuthenticationModule>();
|
|
|
|
|
|
|
|
|
|
while (authModules.MoveNext())
|
|
|
|
|
{
|
|
|
|
|
var module = (IAuthenticationModule)authModules.Current;
|
|
|
|
|
modulesToUnregister.Add(module);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (var module in modulesToUnregister)
|
|
|
|
|
AuthenticationManager.Unregister(module);
|
|
|
|
|
|
|
|
|
|
var authSetting = (HTTP.ProxyAuthenticationMethod)Properties.Settings.Default.ProxyAuthenticationMethod;
|
|
|
|
|
if (authSetting == HTTP.ProxyAuthenticationMethod.Basic)
|
|
|
|
|
AuthenticationManager.Register(BasicAuthenticationModule);
|
|
|
|
|
else
|
|
|
|
|
AuthenticationManager.Register(DigestAuthenticationModule);
|
|
|
|
|
|
|
|
|
|
HTTP.CurrentProxyAuthenticationMethod = authSetting;
|
|
|
|
|
Session.Proxy = XenAdminConfigManager.Provider.GetProxyFromSettings(null);
|
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|