Exemplo n.º 1
0
        private bool ValidateRequest(string remoteIp, bool isLocal)
        {
            if (isLocal)
            {
                return(true);
            }

            if (_config.Configuration.EnableRemoteAccess)
            {
                var addressFilter = _config.Configuration.RemoteIPFilter.Where(i => !string.IsNullOrWhiteSpace(i)).ToArray();

                if (addressFilter.Length > 0 && !_networkManager.IsInLocalNetwork(remoteIp))
                {
                    if (_config.Configuration.IsRemoteIPFilterBlacklist)
                    {
                        return(!_networkManager.IsAddressInSubnets(remoteIp, addressFilter));
                    }
                    else
                    {
                        return(_networkManager.IsAddressInSubnets(remoteIp, addressFilter));
                    }
                }
            }
            else
            {
                if (!_networkManager.IsInLocalNetwork(remoteIp))
                {
                    return(false);
                }
            }

            return(true);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Executes the middleware action.
        /// </summary>
        /// <param name="httpContext">The current HTTP context.</param>
        /// <param name="networkManager">The network manager.</param>
        /// <param name="serverConfigurationManager">The server configuration manager.</param>
        /// <returns>The async task.</returns>
        public async Task Invoke(HttpContext httpContext, INetworkManager networkManager, IServerConfigurationManager serverConfigurationManager)
        {
            if (httpContext.Request.IsLocal())
            {
                await _next(httpContext).ConfigureAwait(false);

                return;
            }

            var remoteIp = httpContext.Request.RemoteIp();

            if (serverConfigurationManager.Configuration.EnableRemoteAccess)
            {
                var addressFilter = serverConfigurationManager.Configuration.RemoteIPFilter.Where(i => !string.IsNullOrWhiteSpace(i)).ToArray();

                if (addressFilter.Length > 0 && !networkManager.IsInLocalNetwork(remoteIp))
                {
                    if (serverConfigurationManager.Configuration.IsRemoteIPFilterBlacklist)
                    {
                        if (networkManager.IsAddressInSubnets(remoteIp, addressFilter))
                        {
                            return;
                        }
                    }
                    else
                    {
                        if (!networkManager.IsAddressInSubnets(remoteIp, addressFilter))
                        {
                            return;
                        }
                    }
                }
            }
            else
            {
                if (!networkManager.IsInLocalNetwork(remoteIp))
                {
                    return;
                }
            }

            await _next(httpContext).ConfigureAwait(false);
        }
Exemplo n.º 3
0
        private async Task RegisterServerEndpoints()
        {
            var addresses = await _appHost.GetLocalIpAddresses().ConfigureAwait(false);

            var udn           = CreateUuid(_appHost.SystemId);
            var descriptorUri = "/dlna/" + udn + "/description.xml";

            foreach (var address in addresses)
            {
                if (address.AddressFamily == AddressFamily.InterNetworkV6)
                {
                    // Not supporting IPv6 right now
                    continue;
                }

                // Limit to LAN addresses only
                if (!_networkManager.IsAddressInSubnets(address, true, true))
                {
                    continue;
                }

                var fullService = "urn:schemas-upnp-org:device:MediaServer:1";

                _logger.LogInformation("Registering publisher for {0} on {1}", fullService, address);

                var uri = new Uri(_appHost.GetLocalApiUrl(address) + descriptorUri);

                var device = new SsdpRootDevice
                {
                    CacheLifetime = TimeSpan.FromSeconds(1800), // How long SSDP clients can cache this info.
                    Location      = uri,                        // Must point to the URL that serves your devices UPnP description document.
                    Address       = address,
                    SubnetMask    = _networkManager.GetLocalIpSubnetMask(address),
                    FriendlyName  = "Jellyfin",
                    Manufacturer  = "Jellyfin",
                    ModelName     = "Jellyfin Server",
                    Uuid          = udn
                                    // This must be a globally unique value that survives reboots etc. Get from storage or embedded hardware etc.
                };

                SetProperies(device, fullService);
                _publisher.AddDevice(device);

                var embeddedDevices = new[]
                {
                    "urn:schemas-upnp-org:service:ContentDirectory:1",
                    "urn:schemas-upnp-org:service:ConnectionManager:1",
                    // "urn:microsoft.com:service:X_MS_MediaReceiverRegistrar:1"
                };

                foreach (var subDevice in embeddedDevices)
                {
                    var embeddedDevice = new SsdpEmbeddedDevice
                    {
                        FriendlyName = device.FriendlyName,
                        Manufacturer = device.Manufacturer,
                        ModelName    = device.ModelName,
                        Uuid         = udn
                                       // This must be a globally unique value that survives reboots etc. Get from storage or embedded hardware etc.
                    };

                    SetProperies(embeddedDevice, subDevice);
                    device.AddDevice(embeddedDevice);
                }
            }
        }