Return 404 for static web resources when the 'nowebcontent' flag is set

This commit is contained in:
Mark Monteiro 2020-03-15 16:24:04 +01:00
parent 2a01537371
commit 602112fba4

View File

@ -7,12 +7,14 @@ using MediaBrowser.Common.Extensions;
using MediaBrowser.Common.Plugins; using MediaBrowser.Common.Plugins;
using MediaBrowser.Controller; using MediaBrowser.Controller;
using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Extensions;
using MediaBrowser.Controller.Net; using MediaBrowser.Controller.Net;
using MediaBrowser.Controller.Plugins; using MediaBrowser.Controller.Plugins;
using MediaBrowser.Model.IO; using MediaBrowser.Model.IO;
using MediaBrowser.Model.Net; using MediaBrowser.Model.Net;
using MediaBrowser.Model.Plugins; using MediaBrowser.Model.Plugins;
using MediaBrowser.Model.Services; using MediaBrowser.Model.Services;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
namespace MediaBrowser.WebDashboard.Api namespace MediaBrowser.WebDashboard.Api
@ -113,6 +115,7 @@ namespace MediaBrowser.WebDashboard.Api
private readonly IFileSystem _fileSystem; private readonly IFileSystem _fileSystem;
private IResourceFileManager _resourceFileManager; private IResourceFileManager _resourceFileManager;
private readonly IConfiguration _appConfig;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="DashboardService" /> class. /// Initializes a new instance of the <see cref="DashboardService" /> class.
@ -123,7 +126,8 @@ namespace MediaBrowser.WebDashboard.Api
IServerConfigurationManager serverConfigurationManager, IServerConfigurationManager serverConfigurationManager,
IFileSystem fileSystem, IFileSystem fileSystem,
ILogger<DashboardService> logger, ILogger<DashboardService> logger,
IHttpResultFactory resultFactory) IHttpResultFactory resultFactory,
IConfiguration appConfig)
{ {
_appHost = appHost; _appHost = appHost;
_serverConfigurationManager = serverConfigurationManager; _serverConfigurationManager = serverConfigurationManager;
@ -131,16 +135,22 @@ namespace MediaBrowser.WebDashboard.Api
_logger = logger; _logger = logger;
_resultFactory = resultFactory; _resultFactory = resultFactory;
_resourceFileManager = resourceFileManager; _resourceFileManager = resourceFileManager;
_appConfig = appConfig;
} }
/// <summary> /// <summary>
/// Gets the path for the web interface. /// Gets the path of the directory containing the static web interface content, or null if the server is not
/// hosting the static web content.
/// </summary> /// </summary>
/// <value>The path for the web interface.</value>
public string DashboardUIPath public string DashboardUIPath
{ {
get get
{ {
if (_appConfig.NoWebContent())
{
return null;
}
if (!string.IsNullOrEmpty(_serverConfigurationManager.Configuration.DashboardSourcePath)) if (!string.IsNullOrEmpty(_serverConfigurationManager.Configuration.DashboardSourcePath))
{ {
return _serverConfigurationManager.Configuration.DashboardSourcePath; return _serverConfigurationManager.Configuration.DashboardSourcePath;
@ -301,6 +311,11 @@ namespace MediaBrowser.WebDashboard.Api
/// <returns>System.Object.</returns> /// <returns>System.Object.</returns>
public async Task<object> Get(GetDashboardResource request) public async Task<object> Get(GetDashboardResource request)
{ {
if (_appConfig.NoWebContent() || DashboardUIPath == null)
{
throw new ResourceNotFoundException();
}
var path = request.ResourceName; var path = request.ResourceName;
var contentType = MimeTypes.GetMimeType(path); var contentType = MimeTypes.GetMimeType(path);
@ -372,6 +387,11 @@ namespace MediaBrowser.WebDashboard.Api
public async Task<object> Get(GetDashboardPackage request) public async Task<object> Get(GetDashboardPackage request)
{ {
if (_appConfig.NoWebContent() || DashboardUIPath == null)
{
throw new ResourceNotFoundException();
}
var mode = request.Mode; var mode = request.Mode;
var inputPath = string.IsNullOrWhiteSpace(mode) ? var inputPath = string.IsNullOrWhiteSpace(mode) ?