2025-05-03 14:58:07 +02:00
|
|
|
// Copyright (C) 2025, The Duplicati Team
|
2024-06-05 11:02:56 +02:00
|
|
|
// https://duplicati.com, hello@duplicati.com
|
|
|
|
|
//
|
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
|
// copy of this software and associated documentation files (the "Software"),
|
|
|
|
|
// to deal in the Software without restriction, including without limitation
|
|
|
|
|
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
|
// and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
|
// Software is furnished to do so, subject to the following conditions:
|
|
|
|
|
//
|
|
|
|
|
// The above copyright notice and this permission notice shall be included in
|
|
|
|
|
// all copies or substantial portions of the Software.
|
|
|
|
|
//
|
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
|
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
|
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
|
// DEALINGS IN THE SOFTWARE.
|
2022-12-30 10:59:29 -08:00
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Security.Cryptography;
|
|
|
|
|
using Duplicati.Library.RestAPI;
|
2024-06-19 13:54:10 +02:00
|
|
|
using System.Text.Json;
|
|
|
|
|
using System.Text;
|
2024-10-29 12:02:42 +01:00
|
|
|
using System.Security.Cryptography.X509Certificates;
|
2024-11-05 21:26:30 +01:00
|
|
|
using Duplicati.Library.Utility;
|
2025-03-25 12:34:54 +01:00
|
|
|
using Duplicati.Library.AutoUpdater;
|
2025-05-03 14:58:07 +02:00
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using Duplicati.WebserverCore.Abstractions;
|
2018-11-02 22:13:25 +01:00
|
|
|
|
2025-01-14 14:03:48 +01:00
|
|
|
#nullable enable
|
|
|
|
|
|
2022-12-30 10:59:29 -08:00
|
|
|
namespace Duplicati.Server.Database
|
|
|
|
|
{
|
|
|
|
|
public class ServerSettings
|
|
|
|
|
{
|
2024-03-15 16:51:01 +01:00
|
|
|
public static class CONST
|
2022-12-30 10:59:29 -08:00
|
|
|
{
|
|
|
|
|
public const string STARTUP_DELAY = "startup-delay";
|
|
|
|
|
public const string DOWNLOAD_SPEED_LIMIT = "max-download-speed";
|
|
|
|
|
public const string UPLOAD_SPEED_LIMIT = "max-upload-speed";
|
|
|
|
|
public const string LAST_WEBSERVER_PORT = "last-webserver-port";
|
|
|
|
|
public const string IS_FIRST_RUN = "is-first-run";
|
|
|
|
|
public const string SERVER_PORT_CHANGED = "server-port-changed";
|
|
|
|
|
public const string SERVER_PASSPHRASE = "server-passphrase";
|
|
|
|
|
public const string SERVER_PASSPHRASE_SALT = "server-passphrase-salt";
|
|
|
|
|
public const string UPDATE_CHECK_LAST = "last-update-check";
|
|
|
|
|
public const string UPDATE_CHECK_INTERVAL = "update-check-interval";
|
|
|
|
|
public const string UPDATE_CHECK_NEW_VERSION = "update-check-latest";
|
|
|
|
|
public const string UNACKED_ERROR = "unacked-error";
|
|
|
|
|
public const string UNACKED_WARNING = "unacked-warning";
|
|
|
|
|
public const string SERVER_LISTEN_INTERFACE = "server-listen-interface";
|
2024-10-29 11:15:06 +01:00
|
|
|
public const string SERVER_DISABLE_HTTPS = "server-disable-https";
|
2022-12-30 10:59:29 -08:00
|
|
|
public const string SERVER_SSL_CERTIFICATE = "server-ssl-certificate";
|
2024-08-06 21:37:35 +02:00
|
|
|
public const string SERVER_SSL_CERTIFICATEPASSWORD = "server-ssl-certificate-password";
|
2022-12-30 10:59:29 -08:00
|
|
|
public const string HAS_FIXED_INVALID_BACKUPID = "has-fixed-invalid-backup-id";
|
|
|
|
|
public const string UPDATE_CHANNEL = "update-channel";
|
2017-08-24 13:55:29 +02:00
|
|
|
public const string USAGE_REPORTER_LEVEL = "usage-reporter-level";
|
2022-12-30 10:59:29 -08:00
|
|
|
public const string DISABLE_TRAY_ICON_LOGIN = "disable-tray-icon-login";
|
|
|
|
|
public const string SERVER_ALLOWED_HOSTNAMES = "allowed-hostnames";
|
2024-06-19 13:54:10 +02:00
|
|
|
public const string JWT_CONFIG = "jwt-config";
|
2024-09-18 11:07:59 +02:00
|
|
|
public const string REMOTE_CONTROL_CONFIG = "remote-control-config";
|
2024-09-27 16:14:40 +02:00
|
|
|
public const string REMOTE_CONTROL_ENABLED = "remote-control-enabled";
|
2024-06-19 13:54:10 +02:00
|
|
|
public const string PBKDF_CONFIG = "pbkdf-config";
|
|
|
|
|
public const string AUTOGENERATED_PASSPHRASE = "autogenerated-passphrase";
|
2024-08-13 13:50:21 +02:00
|
|
|
public const string DISABLE_VISUAL_CAPTCHA = "disable-visual-captcha";
|
2024-09-18 11:07:59 +02:00
|
|
|
public const string DISABLE_SIGNIN_TOKENS = "disable-signin-tokens";
|
2024-08-20 21:10:15 +02:00
|
|
|
public const string ENCRYPTED_FIELDS = "encrypted-fields";
|
2024-08-28 00:18:55 +02:00
|
|
|
public const string PRELOAD_SETTINGS_HASH = "preload-settings-hash";
|
2024-11-05 21:26:30 +01:00
|
|
|
public const string TIMEZONE_OPTION = "server-timezone";
|
2024-12-18 08:27:59 +01:00
|
|
|
public const string PAUSED_UNTIL = "paused-until";
|
2025-01-27 08:52:06 +01:00
|
|
|
public const string LAST_UPDATE_CHECK_VERSION = "last-update-check-version";
|
2025-03-03 17:39:25 +01:00
|
|
|
public const string ADDITIONAL_REPORT_URL = "additional-report-url";
|
2025-03-26 15:58:06 +01:00
|
|
|
public const string BACKUP_LIST_SORT_ORDER = "backup-list-sort-order";
|
2024-06-07 15:56:43 +02:00
|
|
|
}
|
2022-12-30 10:59:29 -08:00
|
|
|
|
2025-01-14 14:03:48 +01:00
|
|
|
private readonly Dictionary<string, string?> settings;
|
2022-12-30 10:59:29 -08:00
|
|
|
private readonly Connection databaseConnection;
|
2025-03-25 12:34:54 +01:00
|
|
|
private UpdateInfo? m_latestUpdate;
|
2022-12-30 10:59:29 -08:00
|
|
|
|
|
|
|
|
internal ServerSettings(Connection con)
|
|
|
|
|
{
|
2025-01-14 14:03:48 +01:00
|
|
|
settings = new Dictionary<string, string?>();
|
2022-12-30 10:59:29 -08:00
|
|
|
databaseConnection = con;
|
|
|
|
|
ReloadSettings();
|
2025-03-25 12:34:54 +01:00
|
|
|
|
|
|
|
|
// Slightly hacky way to set this, but the rest of the code
|
|
|
|
|
// relies on this value, and the database has an override
|
|
|
|
|
// so we sync it here and in the property setter
|
|
|
|
|
if (Enum.TryParse<ReleaseType>(UpdateChannel, true, out var rt))
|
|
|
|
|
UpdaterManager.CurrentChannel = rt;
|
2022-12-30 10:59:29 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ReloadSettings()
|
|
|
|
|
{
|
2024-06-07 15:56:43 +02:00
|
|
|
lock (databaseConnection.m_lock)
|
2022-12-30 10:59:29 -08:00
|
|
|
{
|
|
|
|
|
settings.Clear();
|
2025-01-14 14:03:48 +01:00
|
|
|
foreach (var n in typeof(CONST).GetFields(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.DeclaredOnly | System.Reflection.BindingFlags.Static).Select(x => (string?)x.GetValue(null)))
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(n))
|
|
|
|
|
settings[n] = null;
|
2024-06-07 15:56:43 +02:00
|
|
|
foreach (var n in databaseConnection.GetSettings(Connection.SERVER_SETTINGS_ID))
|
2022-12-30 10:59:29 -08:00
|
|
|
settings[n.Name] = n.Value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-14 14:03:48 +01:00
|
|
|
public void UpdateSettings(Dictionary<string, string?> newsettings, bool clearExisting)
|
2022-12-30 10:59:29 -08:00
|
|
|
{
|
|
|
|
|
if (newsettings == null)
|
2025-01-14 14:03:48 +01:00
|
|
|
throw new ArgumentNullException(nameof(newsettings));
|
2022-12-30 10:59:29 -08:00
|
|
|
|
2024-06-07 15:56:43 +02:00
|
|
|
lock (databaseConnection.m_lock)
|
2022-12-30 10:59:29 -08:00
|
|
|
{
|
|
|
|
|
m_latestUpdate = null;
|
|
|
|
|
if (clearExisting)
|
|
|
|
|
settings.Clear();
|
|
|
|
|
|
2024-06-07 15:56:43 +02:00
|
|
|
foreach (var k in newsettings)
|
2022-12-30 10:59:29 -08:00
|
|
|
if (!clearExisting && newsettings[k.Key] == null && k.Key.StartsWith("--", StringComparison.Ordinal))
|
|
|
|
|
settings.Remove(k.Key);
|
|
|
|
|
else
|
|
|
|
|
settings[k.Key] = newsettings[k.Key];
|
|
|
|
|
|
2024-06-19 13:54:10 +02:00
|
|
|
// Prevent user from logging themselves out, by disabling the login and not knowing the password
|
2024-07-07 10:36:11 +02:00
|
|
|
if (DisableTrayIconLogin && AutogeneratedPassphrase)
|
2024-06-19 13:54:10 +02:00
|
|
|
settings[CONST.DISABLE_TRAY_ICON_LOGIN] = false.ToString();
|
2022-12-30 10:59:29 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SaveSettings();
|
|
|
|
|
}
|
2024-06-07 15:56:43 +02:00
|
|
|
|
2022-12-30 10:59:29 -08:00
|
|
|
private void SaveSettings()
|
|
|
|
|
{
|
|
|
|
|
databaseConnection.SetSettings(
|
|
|
|
|
from n in settings
|
2024-06-07 15:56:43 +02:00
|
|
|
select (Duplicati.Server.Serialization.Interface.ISetting)new Setting()
|
|
|
|
|
{
|
2022-12-30 10:59:29 -08:00
|
|
|
Filter = "",
|
|
|
|
|
Name = n.Key,
|
|
|
|
|
Value = n.Value
|
2024-06-07 15:56:43 +02:00
|
|
|
}, Database.Connection.SERVER_SETTINGS_ID);
|
2022-12-30 10:59:29 -08:00
|
|
|
|
2025-05-03 14:58:07 +02:00
|
|
|
var provider = databaseConnection.ServiceProvider;
|
|
|
|
|
if (provider != null)
|
2024-06-07 15:56:43 +02:00
|
|
|
{
|
2025-05-03 14:58:07 +02:00
|
|
|
provider?.GetRequiredService<INotificationUpdateService>()?.IncrementLastDataUpdateId();
|
|
|
|
|
provider?.GetRequiredService<EventPollNotify>()?.SignalNewEvent();
|
2024-06-07 15:56:43 +02:00
|
|
|
// If throttle options were changed, update now
|
2025-05-03 14:58:07 +02:00
|
|
|
provider?.GetRequiredService<IQueueRunnerService>()?.GetCurrentTask()?.UpdateThrottleSpeeds(UploadSpeedLimit, DownloadSpeedLimit);
|
2024-06-07 15:56:43 +02:00
|
|
|
}
|
2022-12-30 10:59:29 -08:00
|
|
|
|
2024-06-07 15:56:43 +02:00
|
|
|
// In case the usage reporter is enabled or disabled, refresh now
|
2024-06-19 13:54:10 +02:00
|
|
|
if (FIXMEGlobal.StartOrStopUsageReporter != null)
|
|
|
|
|
FIXMEGlobal.StartOrStopUsageReporter();
|
2022-12-30 10:59:29 -08:00
|
|
|
}
|
2024-06-07 15:56:43 +02:00
|
|
|
|
2025-01-14 14:03:48 +01:00
|
|
|
public string? StartupDelayDuration
|
2022-12-30 10:59:29 -08:00
|
|
|
{
|
2024-06-07 15:56:43 +02:00
|
|
|
get
|
2022-12-30 10:59:29 -08:00
|
|
|
{
|
|
|
|
|
return settings[CONST.STARTUP_DELAY];
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
2024-06-07 15:56:43 +02:00
|
|
|
lock (databaseConnection.m_lock)
|
2022-12-30 10:59:29 -08:00
|
|
|
settings[CONST.STARTUP_DELAY] = value;
|
|
|
|
|
SaveSettings();
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-06-07 15:56:43 +02:00
|
|
|
|
2024-12-18 08:27:59 +01:00
|
|
|
public DateTime? PausedUntil
|
2022-12-30 10:59:29 -08:00
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2024-12-18 08:27:59 +01:00
|
|
|
if (long.TryParse(settings[CONST.PAUSED_UNTIL], out var t))
|
|
|
|
|
return new DateTime(t, DateTimeKind.Utc);
|
|
|
|
|
else
|
2022-12-30 10:59:29 -08:00
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
2024-06-07 15:56:43 +02:00
|
|
|
lock (databaseConnection.m_lock)
|
2024-12-18 08:27:59 +01:00
|
|
|
settings[CONST.PAUSED_UNTIL] = value?.ToUniversalTime().Ticks.ToString();
|
|
|
|
|
SaveSettings();
|
2022-12-30 10:59:29 -08:00
|
|
|
}
|
|
|
|
|
}
|
2024-06-07 15:56:43 +02:00
|
|
|
|
2025-01-14 14:03:48 +01:00
|
|
|
public string? DownloadSpeedLimit
|
2022-12-30 10:59:29 -08:00
|
|
|
{
|
2024-06-07 15:56:43 +02:00
|
|
|
get
|
2022-12-30 10:59:29 -08:00
|
|
|
{
|
|
|
|
|
return settings[CONST.DOWNLOAD_SPEED_LIMIT];
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
2024-06-07 15:56:43 +02:00
|
|
|
lock (databaseConnection.m_lock)
|
2022-12-30 10:59:29 -08:00
|
|
|
settings[CONST.DOWNLOAD_SPEED_LIMIT] = value;
|
|
|
|
|
SaveSettings();
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-06-07 15:56:43 +02:00
|
|
|
|
2025-01-14 14:03:48 +01:00
|
|
|
public string? UploadSpeedLimit
|
2022-12-30 10:59:29 -08:00
|
|
|
{
|
2024-06-07 15:56:43 +02:00
|
|
|
get
|
2022-12-30 10:59:29 -08:00
|
|
|
{
|
|
|
|
|
return settings[CONST.UPLOAD_SPEED_LIMIT];
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
2024-06-07 15:56:43 +02:00
|
|
|
lock (databaseConnection.m_lock)
|
2022-12-30 10:59:29 -08:00
|
|
|
settings[CONST.UPLOAD_SPEED_LIMIT] = value;
|
|
|
|
|
SaveSettings();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool IsFirstRun
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2025-03-25 12:34:54 +01:00
|
|
|
return Utility.ParseBoolOption(settings, CONST.IS_FIRST_RUN);
|
2022-12-30 10:59:29 -08:00
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
2024-06-07 15:56:43 +02:00
|
|
|
lock (databaseConnection.m_lock)
|
2022-12-30 10:59:29 -08:00
|
|
|
settings[CONST.IS_FIRST_RUN] = value.ToString();
|
|
|
|
|
SaveSettings();
|
|
|
|
|
}
|
2017-08-24 13:55:29 +02:00
|
|
|
}
|
|
|
|
|
|
2022-12-30 10:59:29 -08:00
|
|
|
public bool UnackedError
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2025-03-25 12:34:54 +01:00
|
|
|
return Utility.ParseBool(settings[CONST.UNACKED_ERROR], false);
|
2022-12-30 10:59:29 -08:00
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
2024-06-07 15:56:43 +02:00
|
|
|
lock (databaseConnection.m_lock)
|
2022-12-30 10:59:29 -08:00
|
|
|
settings[CONST.UNACKED_ERROR] = value.ToString();
|
|
|
|
|
SaveSettings();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool UnackedWarning
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2025-03-25 12:34:54 +01:00
|
|
|
return Utility.ParseBool(settings[CONST.UNACKED_WARNING], false);
|
2022-12-30 10:59:29 -08:00
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
2024-06-07 15:56:43 +02:00
|
|
|
lock (databaseConnection.m_lock)
|
2022-12-30 10:59:29 -08:00
|
|
|
settings[CONST.UNACKED_WARNING] = value.ToString();
|
|
|
|
|
SaveSettings();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool ServerPortChanged
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2025-03-25 12:34:54 +01:00
|
|
|
return Utility.ParseBool(settings[CONST.SERVER_PORT_CHANGED], false);
|
2022-12-30 10:59:29 -08:00
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
2024-06-07 15:56:43 +02:00
|
|
|
lock (databaseConnection.m_lock)
|
2022-12-30 10:59:29 -08:00
|
|
|
settings[CONST.SERVER_PORT_CHANGED] = value.ToString();
|
|
|
|
|
SaveSettings();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool DisableTrayIconLogin
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2025-03-25 12:34:54 +01:00
|
|
|
return Utility.ParseBool(settings[CONST.DISABLE_TRAY_ICON_LOGIN], false);
|
2022-12-30 10:59:29 -08:00
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
lock (databaseConnection.m_lock)
|
|
|
|
|
settings[CONST.DISABLE_TRAY_ICON_LOGIN] = value.ToString();
|
|
|
|
|
SaveSettings();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-07 10:36:11 +02:00
|
|
|
public bool AutogeneratedPassphrase
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2025-03-25 12:34:54 +01:00
|
|
|
return Utility.ParseBool(settings[CONST.AUTOGENERATED_PASSPHRASE], false);
|
2024-07-07 10:36:11 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-13 13:50:21 +02:00
|
|
|
public bool DisableVisualCaptcha
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2025-03-25 12:34:54 +01:00
|
|
|
return Utility.ParseBool(settings[CONST.DISABLE_VISUAL_CAPTCHA], false);
|
2024-08-13 13:50:21 +02:00
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
lock (databaseConnection.m_lock)
|
|
|
|
|
settings[CONST.DISABLE_VISUAL_CAPTCHA] = value.ToString();
|
|
|
|
|
SaveSettings();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-18 11:07:59 +02:00
|
|
|
public bool DisableSigninTokens
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2025-03-25 12:34:54 +01:00
|
|
|
return Utility.ParseBool(settings[CONST.DISABLE_SIGNIN_TOKENS], false);
|
2024-09-18 11:07:59 +02:00
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
lock (databaseConnection.m_lock)
|
|
|
|
|
settings[CONST.DISABLE_SIGNIN_TOKENS] = value.ToString();
|
|
|
|
|
SaveSettings();
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-12-30 10:59:29 -08:00
|
|
|
public int LastWebserverPort
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
var tp = settings[CONST.LAST_WEBSERVER_PORT];
|
|
|
|
|
int p;
|
|
|
|
|
if (string.IsNullOrEmpty(tp) || !int.TryParse(tp, out p))
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
return p;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
2024-06-07 15:56:43 +02:00
|
|
|
lock (databaseConnection.m_lock)
|
2022-12-30 10:59:29 -08:00
|
|
|
settings[CONST.LAST_WEBSERVER_PORT] = value.ToString();
|
|
|
|
|
SaveSettings();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-19 13:54:10 +02:00
|
|
|
/// <summary>
|
|
|
|
|
/// This class is used to store the PBKDF configuration parameters
|
|
|
|
|
/// </summary>
|
|
|
|
|
private record PbkdfConfig(string Algorithm, int Version, string Salt, int Iterations, string HashAlorithm, string Hash)
|
2022-12-30 10:59:29 -08:00
|
|
|
{
|
2024-06-19 13:54:10 +02:00
|
|
|
/// <summary>
|
|
|
|
|
/// The version to embed in the configuration
|
|
|
|
|
/// </summary>
|
|
|
|
|
private const int _Version = 1;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The algorithm to use
|
|
|
|
|
/// </summary>
|
|
|
|
|
private const string _Algorithm = "PBKDF2";
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The hash algorithm to use
|
|
|
|
|
/// </summary>
|
|
|
|
|
private const string _HashAlorithm = "SHA256";
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The number of iterations to use
|
|
|
|
|
/// </summary>
|
|
|
|
|
private const int _Iterations = 10000;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The size of the hash
|
|
|
|
|
/// </summary>
|
|
|
|
|
private const int _HashSize = 32;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Creates a new PBKDF2 configuration with a random salt
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="password">The password to hash</param>
|
|
|
|
|
public static PbkdfConfig CreatePBKDF2(string password)
|
|
|
|
|
{
|
|
|
|
|
var prng = RandomNumberGenerator.Create();
|
|
|
|
|
var buf = new byte[_HashSize];
|
|
|
|
|
prng.GetBytes(buf);
|
|
|
|
|
|
|
|
|
|
var salt = Convert.ToBase64String(buf);
|
|
|
|
|
var pbkdf2 = new Rfc2898DeriveBytes(password, buf, _Iterations, new HashAlgorithmName(_HashAlorithm));
|
|
|
|
|
var pwd = Convert.ToBase64String(pbkdf2.GetBytes(_HashSize));
|
|
|
|
|
|
|
|
|
|
return new PbkdfConfig(_Algorithm, _Version, salt, _Iterations, _HashAlorithm, pwd);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Verifies a password against a PBKDF2 configuration
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="password">The password to verify</param>
|
|
|
|
|
/// <returns>True if the password matches the configuration</returns>
|
|
|
|
|
public bool VerifyPassword(string password)
|
2022-12-30 10:59:29 -08:00
|
|
|
{
|
2024-06-19 13:54:10 +02:00
|
|
|
var pbkdf2 = new Rfc2898DeriveBytes(password, Convert.FromBase64String(Salt), Iterations, new HashAlgorithmName(HashAlorithm));
|
|
|
|
|
var pwd = Convert.ToBase64String(pbkdf2.GetBytes(_HashSize));
|
|
|
|
|
|
|
|
|
|
return pwd == Hash;
|
2022-12-30 10:59:29 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-19 13:54:10 +02:00
|
|
|
/// <summary>
|
|
|
|
|
/// Verifies a password against the stored PBKDF configuration
|
|
|
|
|
/// </summary>
|
|
|
|
|
public bool VerifyWebserverPassword(string password)
|
2022-12-30 10:59:29 -08:00
|
|
|
{
|
2024-06-19 13:54:10 +02:00
|
|
|
var config = settings[CONST.PBKDF_CONFIG];
|
|
|
|
|
if (string.IsNullOrWhiteSpace(password) || string.IsNullOrWhiteSpace(config))
|
|
|
|
|
return false;
|
|
|
|
|
|
2025-01-14 14:03:48 +01:00
|
|
|
var cfg = JsonSerializer.Deserialize<PbkdfConfig>(config)
|
|
|
|
|
?? throw new Exception("Unable to deserialize PBKDF configuration");
|
|
|
|
|
|
|
|
|
|
return cfg.VerifyPassword(LegacyPreparePassword(password));
|
2022-12-30 10:59:29 -08:00
|
|
|
}
|
|
|
|
|
|
2024-06-19 13:54:10 +02:00
|
|
|
/// <summary>
|
|
|
|
|
/// Prepares a password by pre-hashing it with a legacy salt, if needed
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="password">The password to hash</param>
|
|
|
|
|
/// <returns>The hashed password</returns>
|
|
|
|
|
private string LegacyPreparePassword(string password)
|
|
|
|
|
{
|
2025-01-14 14:03:48 +01:00
|
|
|
var salt = settings[CONST.SERVER_PASSPHRASE_SALT];
|
|
|
|
|
if (string.IsNullOrWhiteSpace(salt))
|
2024-06-19 13:54:10 +02:00
|
|
|
return password;
|
|
|
|
|
|
2025-01-14 14:03:48 +01:00
|
|
|
var buf = Convert.FromBase64String(salt);
|
2024-06-19 13:54:10 +02:00
|
|
|
var sha256 = SHA256.Create();
|
|
|
|
|
var str = Encoding.UTF8.GetBytes(password);
|
|
|
|
|
|
|
|
|
|
sha256.TransformBlock(str, 0, str.Length, str, 0);
|
|
|
|
|
sha256.TransformFinalBlock(buf, 0, buf.Length);
|
2025-01-14 14:03:48 +01:00
|
|
|
return Convert.ToBase64String(sha256.Hash ?? throw new CryptographicUnexpectedOperationException("Calculated hash value is null"));
|
2024-06-19 13:54:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Upgrades the password to a PBKDF configuration, if using the legacy password setup
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void UpgradePasswordToKBDF()
|
2022-12-30 10:59:29 -08:00
|
|
|
{
|
2024-06-19 13:54:10 +02:00
|
|
|
if (!string.IsNullOrWhiteSpace(settings[CONST.PBKDF_CONFIG]))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// Generate a random password if one is not set
|
|
|
|
|
var password = settings[CONST.SERVER_PASSPHRASE];
|
|
|
|
|
var autogenerated = false;
|
2022-12-30 10:59:29 -08:00
|
|
|
if (string.IsNullOrWhiteSpace(password))
|
|
|
|
|
{
|
2024-06-19 13:54:10 +02:00
|
|
|
password = Convert.ToBase64String(RandomNumberGenerator.GetBytes(32));
|
|
|
|
|
settings[CONST.SERVER_PASSPHRASE_SALT] = null;
|
|
|
|
|
autogenerated = true;
|
2022-12-30 10:59:29 -08:00
|
|
|
}
|
2024-06-19 13:54:10 +02:00
|
|
|
|
|
|
|
|
// This will create a new PBKDF2 configuration
|
|
|
|
|
// In case the password already exists in the database,
|
|
|
|
|
// it will need use the pre-salted password as the password
|
|
|
|
|
var config = PbkdfConfig.CreatePBKDF2(password);
|
|
|
|
|
lock (databaseConnection.m_lock)
|
2022-12-30 10:59:29 -08:00
|
|
|
{
|
2024-06-19 13:54:10 +02:00
|
|
|
settings[CONST.PBKDF_CONFIG] = JsonSerializer.Serialize(config);
|
|
|
|
|
settings[CONST.SERVER_PASSPHRASE] = null;
|
|
|
|
|
settings[CONST.AUTOGENERATED_PASSPHRASE] = autogenerated.ToString();
|
2024-06-20 12:24:14 +02:00
|
|
|
if (autogenerated)
|
|
|
|
|
settings[CONST.DISABLE_TRAY_ICON_LOGIN] = false.ToString();
|
2024-06-19 13:54:10 +02:00
|
|
|
}
|
2022-12-30 10:59:29 -08:00
|
|
|
|
2024-06-19 13:54:10 +02:00
|
|
|
SaveSettings();
|
|
|
|
|
}
|
2022-12-30 10:59:29 -08:00
|
|
|
|
2024-06-19 13:54:10 +02:00
|
|
|
/// <summary>
|
|
|
|
|
/// Sets the webserver password
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="password">The password to set</param>
|
|
|
|
|
public void SetWebserverPassword(string password)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrWhiteSpace(password))
|
|
|
|
|
throw new Exception("Disabling password protection is not supported");
|
2022-12-30 10:59:29 -08:00
|
|
|
|
2024-06-19 13:54:10 +02:00
|
|
|
var config = PbkdfConfig.CreatePBKDF2(password);
|
|
|
|
|
lock (databaseConnection.m_lock)
|
|
|
|
|
{
|
|
|
|
|
settings[CONST.SERVER_PASSPHRASE] = null;
|
|
|
|
|
settings[CONST.SERVER_PASSPHRASE_SALT] = null;
|
|
|
|
|
settings[CONST.AUTOGENERATED_PASSPHRASE] = false.ToString();
|
|
|
|
|
settings[CONST.PBKDF_CONFIG] = JsonSerializer.Serialize(config);
|
2022-12-30 10:59:29 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SaveSettings();
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-14 14:03:48 +01:00
|
|
|
public void SetAllowedHostnames(string? allowedHostnames)
|
2022-12-30 10:59:29 -08:00
|
|
|
{
|
|
|
|
|
lock (databaseConnection.m_lock)
|
|
|
|
|
settings[CONST.SERVER_ALLOWED_HOSTNAMES] = allowedHostnames;
|
|
|
|
|
|
|
|
|
|
SaveSettings();
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-14 14:03:48 +01:00
|
|
|
public string? AllowedHostnames => settings[CONST.SERVER_ALLOWED_HOSTNAMES];
|
2022-12-30 10:59:29 -08:00
|
|
|
|
2025-01-14 14:03:48 +01:00
|
|
|
public string? JWTConfig
|
2022-12-30 10:59:29 -08:00
|
|
|
{
|
2024-06-19 13:54:10 +02:00
|
|
|
get => settings[CONST.JWT_CONFIG];
|
|
|
|
|
set
|
2022-12-30 10:59:29 -08:00
|
|
|
{
|
2024-06-19 13:54:10 +02:00
|
|
|
lock (databaseConnection.m_lock)
|
|
|
|
|
settings[CONST.JWT_CONFIG] = value;
|
|
|
|
|
SaveSettings();
|
2022-12-30 10:59:29 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-12 11:05:09 +01:00
|
|
|
/// <summary>
|
|
|
|
|
/// The number of forever tokens that can be created.
|
|
|
|
|
/// A value of -1 means that forever tokens are disabled.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The number of forever tokens that can be created.</value>
|
|
|
|
|
/// <remarks>
|
|
|
|
|
/// This setting is not persisted in the database, as it is meant to be a temporary setting.
|
|
|
|
|
/// </remarks>
|
|
|
|
|
private int m_remainingForeverTokens = -1;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Enables forever tokens
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void EnableForeverTokens()
|
|
|
|
|
{
|
|
|
|
|
lock (databaseConnection.m_lock)
|
|
|
|
|
if (m_remainingForeverTokens == -1)
|
|
|
|
|
m_remainingForeverTokens = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Consumes a forever token, if available
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>True if a token was consumed, false if no tokens are available, null if forever tokens are disabled</returns>
|
|
|
|
|
public bool? ConsumeForeverToken()
|
|
|
|
|
{
|
|
|
|
|
lock (databaseConnection.m_lock)
|
|
|
|
|
{
|
|
|
|
|
if (m_remainingForeverTokens == -1)
|
|
|
|
|
return null;
|
|
|
|
|
if (m_remainingForeverTokens == 0)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if (m_remainingForeverTokens > 0)
|
|
|
|
|
m_remainingForeverTokens--;
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-12-12 08:59:59 +01:00
|
|
|
|
2025-01-14 14:03:48 +01:00
|
|
|
public string? RemoteControlConfig
|
2024-09-18 11:07:59 +02:00
|
|
|
{
|
|
|
|
|
get => settings[CONST.REMOTE_CONTROL_CONFIG];
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
lock (databaseConnection.m_lock)
|
|
|
|
|
settings[CONST.REMOTE_CONTROL_CONFIG] = value;
|
|
|
|
|
SaveSettings();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-27 16:14:40 +02:00
|
|
|
public bool RemoteControlEnabled
|
|
|
|
|
{
|
2025-03-25 12:34:54 +01:00
|
|
|
get => Utility.ParseBool(settings[CONST.REMOTE_CONTROL_ENABLED], false);
|
2024-09-27 16:14:40 +02:00
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
lock (databaseConnection.m_lock)
|
|
|
|
|
settings[CONST.REMOTE_CONTROL_ENABLED] = value.ToString();
|
|
|
|
|
SaveSettings();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-30 10:59:29 -08:00
|
|
|
public DateTime LastUpdateCheck
|
|
|
|
|
{
|
2024-06-07 15:56:43 +02:00
|
|
|
get
|
2022-12-30 10:59:29 -08:00
|
|
|
{
|
|
|
|
|
long t;
|
|
|
|
|
if (long.TryParse(settings[CONST.UPDATE_CHECK_LAST], out t))
|
|
|
|
|
return new DateTime(t, DateTimeKind.Utc);
|
|
|
|
|
else
|
|
|
|
|
return new DateTime(0, DateTimeKind.Utc);
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
2024-06-07 15:56:43 +02:00
|
|
|
lock (databaseConnection.m_lock)
|
2022-12-30 10:59:29 -08:00
|
|
|
settings[CONST.UPDATE_CHECK_LAST] = value.ToUniversalTime().Ticks.ToString();
|
|
|
|
|
SaveSettings();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string UpdateCheckInterval
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
var tp = settings[CONST.UPDATE_CHECK_INTERVAL];
|
|
|
|
|
if (string.IsNullOrWhiteSpace(tp))
|
|
|
|
|
tp = "1W";
|
|
|
|
|
|
|
|
|
|
return tp;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
2024-06-07 15:56:43 +02:00
|
|
|
lock (databaseConnection.m_lock)
|
2022-12-30 10:59:29 -08:00
|
|
|
settings[CONST.UPDATE_CHECK_INTERVAL] = value;
|
|
|
|
|
SaveSettings();
|
2025-05-03 14:58:07 +02:00
|
|
|
databaseConnection?.ServiceProvider?.GetRequiredService<UpdatePollThread>()?.Reschedule();
|
2022-12-30 10:59:29 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public DateTime NextUpdateCheck
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2025-03-25 12:34:54 +01:00
|
|
|
return Timeparser.ParseTimeInterval(UpdateCheckInterval, LastUpdateCheck);
|
2022-12-30 10:59:29 -08:00
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
return LastUpdateCheck.AddDays(7);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-14 14:03:48 +01:00
|
|
|
public Library.AutoUpdater.UpdateInfo? UpdatedVersion
|
2022-12-30 10:59:29 -08:00
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2025-01-14 14:03:48 +01:00
|
|
|
var updateNew = settings[CONST.UPDATE_CHECK_NEW_VERSION];
|
|
|
|
|
if (string.IsNullOrWhiteSpace(updateNew))
|
2022-12-30 10:59:29 -08:00
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (m_latestUpdate != null)
|
|
|
|
|
return m_latestUpdate;
|
|
|
|
|
|
2025-01-14 14:03:48 +01:00
|
|
|
using (var tr = new System.IO.StringReader(updateNew))
|
2022-12-30 10:59:29 -08:00
|
|
|
return m_latestUpdate = Server.Serialization.Serializer.Deserialize<Library.AutoUpdater.UpdateInfo>(tr);
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
2025-01-14 14:03:48 +01:00
|
|
|
string? result = null;
|
2022-12-30 10:59:29 -08:00
|
|
|
if (value != null)
|
|
|
|
|
{
|
2025-01-14 14:03:48 +01:00
|
|
|
var sb = new StringBuilder();
|
2024-06-07 15:56:43 +02:00
|
|
|
using (var tw = new System.IO.StringWriter(sb))
|
2022-12-30 10:59:29 -08:00
|
|
|
Server.Serialization.Serializer.SerializeJson(tw, value);
|
|
|
|
|
|
|
|
|
|
result = sb.ToString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_latestUpdate = value;
|
2024-06-07 15:56:43 +02:00
|
|
|
lock (databaseConnection.m_lock)
|
2022-12-30 10:59:29 -08:00
|
|
|
settings[CONST.UPDATE_CHECK_NEW_VERSION] = result;
|
|
|
|
|
|
|
|
|
|
SaveSettings();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-14 14:03:48 +01:00
|
|
|
public string? ServerListenInterface
|
2022-12-30 10:59:29 -08:00
|
|
|
{
|
2024-06-07 15:56:43 +02:00
|
|
|
get
|
2022-12-30 10:59:29 -08:00
|
|
|
{
|
|
|
|
|
return settings[CONST.SERVER_LISTEN_INTERFACE];
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
2024-06-07 15:56:43 +02:00
|
|
|
lock (databaseConnection.m_lock)
|
2022-12-30 10:59:29 -08:00
|
|
|
settings[CONST.SERVER_LISTEN_INTERFACE] = value;
|
|
|
|
|
SaveSettings();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-29 11:15:06 +01:00
|
|
|
public bool DisableHTTPS
|
2024-08-06 21:37:35 +02:00
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2025-03-25 12:34:54 +01:00
|
|
|
return Utility.ParseBool(settings[CONST.SERVER_DISABLE_HTTPS], false);
|
2024-08-06 21:37:35 +02:00
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
lock (databaseConnection.m_lock)
|
2024-10-29 11:15:06 +01:00
|
|
|
settings[CONST.SERVER_DISABLE_HTTPS] = value.ToString();
|
2024-08-06 21:37:35 +02:00
|
|
|
SaveSettings();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-29 11:15:06 +01:00
|
|
|
public bool UseHTTPS
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2024-10-29 13:55:12 +01:00
|
|
|
return !DisableHTTPS && !string.IsNullOrWhiteSpace(settings[CONST.SERVER_SSL_CERTIFICATE]);
|
2024-10-29 11:15:06 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-05 10:34:10 +01:00
|
|
|
public X509Certificate2Collection? ServerSSLCertificate
|
2022-12-30 10:59:29 -08:00
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2025-01-14 14:03:48 +01:00
|
|
|
var certificate = settings[CONST.SERVER_SSL_CERTIFICATE];
|
2025-03-25 12:34:54 +01:00
|
|
|
if (string.IsNullOrEmpty(certificate))
|
2022-12-30 10:59:29 -08:00
|
|
|
return null;
|
|
|
|
|
|
2025-03-25 12:34:54 +01:00
|
|
|
return Utility.LoadPfxCertificate(
|
2025-01-14 14:03:48 +01:00
|
|
|
Convert.FromBase64String(certificate),
|
2024-10-30 10:39:48 +01:00
|
|
|
settings[CONST.SERVER_SSL_CERTIFICATEPASSWORD],
|
|
|
|
|
// Need to allow loading of plain-text certificates for backwards compatibility
|
|
|
|
|
allowUnsafeCertificateLoad: true
|
|
|
|
|
);
|
2022-12-30 10:59:29 -08:00
|
|
|
}
|
2024-10-29 13:55:12 +01:00
|
|
|
set
|
2024-08-06 21:37:35 +02:00
|
|
|
{
|
2024-10-29 13:55:12 +01:00
|
|
|
if (value == null)
|
|
|
|
|
{
|
|
|
|
|
lock (databaseConnection.m_lock)
|
2024-10-29 14:08:11 +01:00
|
|
|
{
|
2024-10-29 13:55:12 +01:00
|
|
|
settings[CONST.SERVER_SSL_CERTIFICATE] = null;
|
2024-10-29 14:08:11 +01:00
|
|
|
settings[CONST.SERVER_SSL_CERTIFICATEPASSWORD] = null;
|
|
|
|
|
}
|
2024-10-29 13:55:12 +01:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2024-12-05 10:34:10 +01:00
|
|
|
if (!value.Any(x => x.HasPrivateKey))
|
|
|
|
|
throw new ArgumentException("The certificate must have a private key");
|
|
|
|
|
|
2024-10-29 13:55:12 +01:00
|
|
|
var password = Convert.ToBase64String(RandomNumberGenerator.GetBytes(32));
|
2025-01-14 14:03:48 +01:00
|
|
|
var certdata = Convert.ToBase64String(value.Export(X509ContentType.Pkcs12, password)
|
|
|
|
|
?? throw new CryptographicUnexpectedOperationException("Exported certificate data is null"));
|
|
|
|
|
|
2024-10-29 13:55:12 +01:00
|
|
|
lock (databaseConnection.m_lock)
|
|
|
|
|
{
|
|
|
|
|
settings[CONST.SERVER_SSL_CERTIFICATE] = certdata;
|
|
|
|
|
settings[CONST.SERVER_SSL_CERTIFICATEPASSWORD] = password;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-08-06 21:37:35 +02:00
|
|
|
|
2024-10-29 13:55:12 +01:00
|
|
|
SaveSettings();
|
2024-08-06 21:37:35 +02:00
|
|
|
}
|
2022-12-30 10:59:29 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool FixedInvalidBackupId
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2025-03-25 12:34:54 +01:00
|
|
|
return Utility.ParseBool(settings[CONST.HAS_FIXED_INVALID_BACKUPID], false);
|
2022-12-30 10:59:29 -08:00
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
2024-06-07 15:56:43 +02:00
|
|
|
lock (databaseConnection.m_lock)
|
2022-12-30 10:59:29 -08:00
|
|
|
settings[CONST.HAS_FIXED_INVALID_BACKUPID] = value.ToString();
|
|
|
|
|
SaveSettings();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-14 14:03:48 +01:00
|
|
|
public string? UpdateChannel
|
2022-12-30 10:59:29 -08:00
|
|
|
{
|
2024-06-07 15:56:43 +02:00
|
|
|
get
|
2022-12-30 10:59:29 -08:00
|
|
|
{
|
|
|
|
|
return settings[CONST.UPDATE_CHANNEL];
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
2024-06-07 15:56:43 +02:00
|
|
|
lock (databaseConnection.m_lock)
|
2022-12-30 10:59:29 -08:00
|
|
|
settings[CONST.UPDATE_CHANNEL] = value;
|
|
|
|
|
SaveSettings();
|
2025-03-25 12:34:54 +01:00
|
|
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(value))
|
|
|
|
|
UpdaterManager.CurrentChannel = AutoUpdateSettings.DefaultUpdateChannel;
|
|
|
|
|
else if (Enum.TryParse<ReleaseType>(value, true, out var rt))
|
|
|
|
|
UpdaterManager.CurrentChannel = rt;
|
2022-12-30 10:59:29 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-14 14:03:48 +01:00
|
|
|
public string? UsageReporterLevel
|
2022-12-30 10:59:29 -08:00
|
|
|
{
|
2024-06-07 15:56:43 +02:00
|
|
|
get
|
2022-12-30 10:59:29 -08:00
|
|
|
{
|
|
|
|
|
return settings[CONST.USAGE_REPORTER_LEVEL];
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
2024-06-07 15:56:43 +02:00
|
|
|
lock (databaseConnection.m_lock)
|
2022-12-30 10:59:29 -08:00
|
|
|
settings[CONST.USAGE_REPORTER_LEVEL] = value;
|
|
|
|
|
SaveSettings();
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-08-20 17:10:34 +02:00
|
|
|
|
2024-08-20 21:10:15 +02:00
|
|
|
public bool EncryptedFields
|
2024-08-20 17:10:34 +02:00
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2025-03-25 12:34:54 +01:00
|
|
|
return Utility.ParseBool(settings[CONST.ENCRYPTED_FIELDS], false);
|
2024-08-20 17:10:34 +02:00
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
lock (databaseConnection.m_lock)
|
2024-08-20 21:10:15 +02:00
|
|
|
settings[CONST.ENCRYPTED_FIELDS] = value.ToString();
|
2024-08-20 17:10:34 +02:00
|
|
|
SaveSettings();
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-08-28 00:18:55 +02:00
|
|
|
|
2025-01-14 14:03:48 +01:00
|
|
|
public string? PreloadSettingsHash
|
2024-08-28 00:18:55 +02:00
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return settings[CONST.PRELOAD_SETTINGS_HASH];
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
lock (databaseConnection.m_lock)
|
|
|
|
|
settings[CONST.PRELOAD_SETTINGS_HASH] = value;
|
|
|
|
|
SaveSettings();
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-11-05 21:26:30 +01:00
|
|
|
|
|
|
|
|
public TimeZoneInfo Timezone
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
var id = settings[CONST.TIMEZONE_OPTION];
|
|
|
|
|
|
|
|
|
|
// All times are stored in UTC in the database, prior to introducing the timezone option
|
|
|
|
|
if (string.IsNullOrEmpty(id))
|
|
|
|
|
return TimeZoneInfo.Utc;
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (!string.IsNullOrEmpty(id))
|
2025-01-14 14:03:48 +01:00
|
|
|
return TimeZoneHelper.GetTimeZoneById(id)
|
|
|
|
|
?? TimeZoneInfo.Local;
|
2024-11-05 21:26:30 +01:00
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
return TimeZoneInfo.Local;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
lock (databaseConnection.m_lock)
|
|
|
|
|
settings[CONST.TIMEZONE_OPTION] = value?.Id;
|
|
|
|
|
SaveSettings();
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-01-27 08:52:06 +01:00
|
|
|
|
|
|
|
|
public string? LastConfigIssueCheckVersion
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return settings[CONST.LAST_UPDATE_CHECK_VERSION];
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
lock (databaseConnection.m_lock)
|
|
|
|
|
settings[CONST.LAST_UPDATE_CHECK_VERSION] = value;
|
|
|
|
|
SaveSettings();
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-03-03 17:39:25 +01:00
|
|
|
|
|
|
|
|
public string? AdditionalReportUrl
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return settings[CONST.ADDITIONAL_REPORT_URL];
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
lock (databaseConnection.m_lock)
|
|
|
|
|
settings[CONST.ADDITIONAL_REPORT_URL] = value;
|
|
|
|
|
SaveSettings();
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-03-26 15:58:06 +01:00
|
|
|
|
|
|
|
|
public string? BackupListSortOrder
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return settings[CONST.BACKUP_LIST_SORT_ORDER];
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
lock (databaseConnection.m_lock)
|
|
|
|
|
settings[CONST.BACKUP_LIST_SORT_ORDER] = value;
|
|
|
|
|
SaveSettings();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-30 10:59:29 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|