// Copyright (C) 2025, The Duplicati Team // 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. using System.Globalization; using Duplicati.Library.AutoUpdater; using Duplicati.Library.RestAPI; using Duplicati.Server; using Duplicati.Server.Serialization.Interface; using Duplicati.WebserverCore.Abstractions; using Duplicati.WebserverCore.Dto; namespace Duplicati.WebserverCore.Services; /// /// Produces system information. /// public class SystemInfoProvider : ISystemInfoProvider { /// /// System information that does not change during runtime. /// private sealed record StaticSystemInformation { /// /// Gets or sets the API version. /// public required int APIVersion { get; init; } /// /// Gets or sets the password placeholder. /// public required string PasswordPlaceholder { get; init; } /// /// Gets or sets the server version. /// public required string? ServerVersion { get; init; } /// /// Gets or sets the server version name. /// public required string ServerVersionName { get; init; } /// /// Gets or sets the server version type. /// public required string? ServerVersionType { get; init; } /// /// The default URL to present for remote control registration /// public required string RemoteControlRegistrationUrl { get; init; } /// /// Gets or sets the started by. /// public required string StartedBy { get; init; } /// /// Gets or sets the default update channel. /// public required string DefaultUpdateChannel { get; init; } /// /// Gets or sets the default usage report level. /// public required string DefaultUsageReportLevel { get; init; } /// /// Gets or sets the OS type. /// public required string OSType { get; init; } /// /// Gets or sets the OS version. /// public required string OSVersion { get; init; } /// /// Gets or sets the directory separator. /// public required char DirectorySeparator { get; init; } /// /// Gets or sets the path separator. /// public required char PathSeparator { get; init; } /// /// Gets or sets a value indicating whether the filesystem is case sensitive. /// public required bool CaseSensitiveFilesystem { get; init; } /// /// Gets or sets the machine name. /// public required string MachineName { get; init; } /// /// Gets or sets the package type ID. /// public required string PackageTypeId { get; init; } /// /// Gets or sets the user name. /// public required string UserName { get; init; } /// /// Gets or sets the new line character. /// public required string NewLine { get; init; } /// /// Gets or sets the CLR version. /// public required string CLRVersion { get; init; } /// /// Gets or sets the options. /// public required Library.Interface.ICommandLineArgument[] Options { get; init; } /// /// Gets or sets the compression modules. /// public required IDynamicModule[] CompressionModules { get; init; } /// /// Gets or sets the encryption modules. /// public required IDynamicModule[] EncryptionModules { get; init; } /// /// Gets or sets the backend modules. /// public required IDynamicModule[] BackendModules { get; init; } /// /// Gets or sets the generic modules. /// public required IDynamicModule[] GenericModules { get; init; } /// /// Gets or sets the web modules. /// public required IDynamicModule[] WebModules { get; init; } /// /// Gets or sets the connection modules. /// public required IDynamicModule[] ConnectionModules { get; init; } /// /// Gets or sets the server modules. /// public required object[] ServerModules { get; init; } /// /// Gets or sets the secret provider modules. /// public required IDynamicModule[] SecretProviderModules { get; init; } /// /// Gets or sets a value indicating whether alternate update URLs are being used. /// public required bool UsingAlternateUpdateURLs { get; init; } /// /// Gets or sets the log levels. /// public required string[] LogLevels { get; init; } /// /// Gets or sets the special folders. /// public required SystemInfoDto.SpecialFolderDto[] SpecialFolders { get; init; } /// /// Gets or sets the supported locales. /// public required SystemInfoDto.LocaleDto[] SupportedLocales { get; init; } /// /// The timezones available on the system /// public required IEnumerable TimeZones { get; init; } } /// /// Cached static system information. /// private Lazy _systemInfoBase = new(() => new StaticSystemInformation { APIVersion = 1, PasswordPlaceholder = FIXMEGlobal.PASSWORD_PLACEHOLDER, ServerVersion = UpdaterManager.SelfVersion.Version, ServerVersionName = License.VersionNumbers.VERSION_NAME, ServerVersionType = UpdaterManager.SelfVersion.ReleaseType, RemoteControlRegistrationUrl = Library.RemoteControl.RegisterForRemote.DefaultRegisterationUrl, StartedBy = FIXMEGlobal.Origin, DefaultUpdateChannel = AutoUpdateSettings.DefaultUpdateChannel.ToString(), DefaultUsageReportLevel = Library.UsageReporter.Reporter.DefaultReportLevel, OSType = UpdaterManager.OperatingSystemName, OSVersion = Library.UsageReporter.OSInfoHelper.PlatformString, DirectorySeparator = Path.DirectorySeparatorChar, PathSeparator = Path.PathSeparator, CaseSensitiveFilesystem = Library.Utility.Utility.IsFSCaseSensitive, MachineName = Environment.MachineName, PackageTypeId = UpdaterManager.PackageTypeId, UserName = OperatingSystem.IsWindows() ? System.Security.Principal.WindowsIdentity.GetCurrent().Name : Environment.UserName, NewLine = Environment.NewLine, CLRVersion = Environment.Version.ToString(), Options = Server.Serializable.ServerSettings.Options, CompressionModules = Server.Serializable.ServerSettings.CompressionModules, EncryptionModules = Server.Serializable.ServerSettings.EncryptionModules, BackendModules = Server.Serializable.ServerSettings.BackendModules, GenericModules = Server.Serializable.ServerSettings.GenericModules, WebModules = Server.Serializable.ServerSettings.WebModules, ConnectionModules = Server.Serializable.ServerSettings.ConnectionModules, ServerModules = Server.Serializable.ServerSettings.ServerModules, SecretProviderModules = Server.Serializable.ServerSettings.SecretProviderModules, UsingAlternateUpdateURLs = AutoUpdateSettings.UsesAlternateURLs, LogLevels = Enum.GetNames(typeof(Library.Logging.LogMessageType)), SpecialFolders = SpecialFolders.Nodes.Select(n => new Dto.SystemInfoDto.SpecialFolderDto { ID = n.id, Path = n.resolvedpath }).ToArray(), SupportedLocales = Library.Localization.LocalizationService.SupportedCultures .Select(x => new Dto.SystemInfoDto.LocaleDto { Code = x, EnglishName = new CultureInfo(x).EnglishName, DisplayName = new CultureInfo(x).NativeName }).ToArray(), TimeZones = Library.Utility.TimeZoneHelper.GetTimeZones() .Select(x => new Dto.SystemInfoDto.TimeZoneDto { ID = x.Id, DisplayName = x.DisplayName, CurrentUTCOffset = x.CurrentUtcOffset.ToString() }), }); /// public SystemInfoDto GetSystemInfo(CultureInfo? browserlanguage) { browserlanguage ??= CultureInfo.InvariantCulture; var systeminfo = _systemInfoBase.Value; // Return the system information, patch in dynamic values return new SystemInfoDto() { APIVersion = systeminfo.APIVersion, PasswordPlaceholder = systeminfo.PasswordPlaceholder, ServerVersion = systeminfo.ServerVersion, ServerVersionName = systeminfo.ServerVersionName, ServerVersionType = systeminfo.ServerVersionType, RemoteControlRegistrationUrl = systeminfo.RemoteControlRegistrationUrl, StartedBy = systeminfo.StartedBy, DefaultUpdateChannel = systeminfo.DefaultUpdateChannel, DefaultUsageReportLevel = systeminfo.DefaultUsageReportLevel, ServerTime = DateTime.Now, ServerTimeZone = TimeZoneInfo.Local.Id, OSType = systeminfo.OSType, OSVersion = systeminfo.OSVersion, DirectorySeparator = systeminfo.DirectorySeparator, PathSeparator = systeminfo.PathSeparator, CaseSensitiveFilesystem = systeminfo.CaseSensitiveFilesystem, MachineName = systeminfo.MachineName, PackageTypeId = systeminfo.PackageTypeId, UserName = systeminfo.UserName, NewLine = systeminfo.NewLine, CLRVersion = systeminfo.CLRVersion, Options = systeminfo.Options, CompressionModules = systeminfo.CompressionModules, EncryptionModules = systeminfo.EncryptionModules, BackendModules = systeminfo.BackendModules, GenericModules = systeminfo.GenericModules, WebModules = systeminfo.WebModules, ConnectionModules = systeminfo.ConnectionModules, ServerModules = systeminfo.ServerModules, SecretProviderModules = systeminfo.SecretProviderModules, UsingAlternateUpdateURLs = systeminfo.UsingAlternateUpdateURLs, LogLevels = systeminfo.LogLevels, SpecialFolders = systeminfo.SpecialFolders, BrowserLocale = new SystemInfoDto.LocaleDto() { Code = browserlanguage.Name, EnglishName = browserlanguage.EnglishName, DisplayName = browserlanguage.NativeName }, SupportedLocales = systeminfo.SupportedLocales, BrowserLocaleSupported = Library.Localization.LocalizationService.isCultureSupported(browserlanguage), TimeZones = systeminfo.TimeZones, }; } }