< Summary - Jellyfin

Information
Class: Jellyfin.Server.Migrations.PreStartupRoutines.CreateNetworkConfiguration
Assembly: jellyfin
File(s): /srv/git/jellyfin/Jellyfin.Server/Migrations/PreStartupRoutines/CreateNetworkConfiguration.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 30
Coverable lines: 30
Total lines: 135
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 8
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%210%
get_Id()100%210%
get_Name()100%210%
get_PerformOnNewInstall()100%210%
Perform()0%620%
.ctor()100%210%
get_BaseUrl()100%210%
set_BaseUrl(...)0%4260%

File(s)

/srv/git/jellyfin/Jellyfin.Server/Migrations/PreStartupRoutines/CreateNetworkConfiguration.cs

#LineLine coverage
 1using System;
 2using System.IO;
 3using System.Xml;
 4using System.Xml.Serialization;
 5using Emby.Server.Implementations;
 6using Microsoft.Extensions.Logging;
 7
 8namespace Jellyfin.Server.Migrations.PreStartupRoutines;
 9
 10/// <inheritdoc />
 11public class CreateNetworkConfiguration : IMigrationRoutine
 12{
 13    private readonly ServerApplicationPaths _applicationPaths;
 14    private readonly ILogger<CreateNetworkConfiguration> _logger;
 15
 16    /// <summary>
 17    /// Initializes a new instance of the <see cref="CreateNetworkConfiguration"/> class.
 18    /// </summary>
 19    /// <param name="applicationPaths">An instance of <see cref="ServerApplicationPaths"/>.</param>
 20    /// <param name="loggerFactory">An instance of the <see cref="ILoggerFactory"/> interface.</param>
 21    public CreateNetworkConfiguration(ServerApplicationPaths applicationPaths, ILoggerFactory loggerFactory)
 22    {
 023        _applicationPaths = applicationPaths;
 024        _logger = loggerFactory.CreateLogger<CreateNetworkConfiguration>();
 025    }
 26
 27    /// <inheritdoc />
 028    public Guid Id => Guid.Parse("9B354818-94D5-4B68-AC49-E35CB85F9D84");
 29
 30    /// <inheritdoc />
 031    public string Name => nameof(CreateNetworkConfiguration);
 32
 33    /// <inheritdoc />
 034    public bool PerformOnNewInstall => false;
 35
 36    /// <inheritdoc />
 37    public void Perform()
 38    {
 039        string path = Path.Combine(_applicationPaths.ConfigurationDirectoryPath, "network.xml");
 040        if (File.Exists(path))
 41        {
 042            _logger.LogDebug("Network configuration file already exists, skipping");
 043            return;
 44        }
 45
 046        var serverConfigSerializer = new XmlSerializer(typeof(OldNetworkConfiguration), new XmlRootAttribute("ServerConf
 047        using var xmlReader = XmlReader.Create(_applicationPaths.SystemConfigurationFilePath);
 048        var networkSettings = serverConfigSerializer.Deserialize(xmlReader);
 49
 050        var networkConfigSerializer = new XmlSerializer(typeof(OldNetworkConfiguration), new XmlRootAttribute("NetworkCo
 051        var xmlWriterSettings = new XmlWriterSettings { Indent = true };
 052        using var xmlWriter = XmlWriter.Create(path, xmlWriterSettings);
 053        networkConfigSerializer.Serialize(xmlWriter, networkSettings);
 054    }
 55
 56#pragma warning disable
 57    public sealed class OldNetworkConfiguration
 58    {
 59        public const int DefaultHttpPort = 8096;
 60
 61        public const int DefaultHttpsPort = 8920;
 62
 063        private string _baseUrl = string.Empty;
 64
 65        public bool RequireHttps { get; set; }
 66
 67        public string CertificatePath { get; set; } = string.Empty;
 68
 69        public string CertificatePassword { get; set; } = string.Empty;
 70
 71        public string BaseUrl
 72        {
 073            get => _baseUrl;
 74            set
 75            {
 76                // Normalize the start of the string
 077                if (string.IsNullOrWhiteSpace(value))
 78                {
 79                    // If baseUrl is empty, set an empty prefix string
 080                    _baseUrl = string.Empty;
 081                    return;
 82                }
 83
 084                if (value[0] != '/')
 85                {
 86                    // If baseUrl was not configured with a leading slash, append one for consistency
 087                    value = "/" + value;
 88                }
 89
 90                // Normalize the end of the string
 091                if (value[^1] == '/')
 92                {
 93                    // If baseUrl was configured with a trailing slash, remove it for consistency
 094                    value = value.Remove(value.Length - 1);
 95                }
 96
 097                _baseUrl = value;
 098            }
 99        }
 100
 101        public int PublicHttpsPort { get; set; } = DefaultHttpsPort;
 102
 103        public int HttpServerPortNumber { get; set; } = DefaultHttpPort;
 104
 105        public int HttpsPortNumber { get; set; } = DefaultHttpsPort;
 106
 107        public bool EnableHttps { get; set; }
 108
 109        public int PublicPort { get; set; } = DefaultHttpPort;
 110
 111        public bool EnableIPV6 { get; set; }
 112
 113        public bool EnableIPV4 { get; set; } = true;
 114
 115        public bool IgnoreVirtualInterfaces { get; set; } = true;
 116
 0117        public string[] VirtualInterfaceNames { get; set; } = new string[] { "veth" };
 118
 119        public string[] PublishedServerUriBySubnet { get; set; } = Array.Empty<string>();
 120
 121        public string[] RemoteIPFilter { get; set; } = Array.Empty<string>();
 122
 123        public bool IsRemoteIPFilterBlacklist { get; set; }
 124
 125        public bool EnableUPnP { get; set; }
 126
 127        public bool EnableRemoteAccess { get; set; } = true;
 128
 129        public string[] LocalNetworkSubnets { get; set; } = Array.Empty<string>();
 130
 131        public string[] LocalNetworkAddresses { get; set; } = Array.Empty<string>();
 132
 133        public string[] KnownProxies { get; set; } = Array.Empty<string>();
 134    }
 135}