Skip to content

Commit

Permalink
Merge pull request #3526 from sbwalker/dev
Browse files Browse the repository at this point in the history
only allow download of assemblies when using WebAssembly
  • Loading branch information
sbwalker authored Dec 1, 2023
2 parents 768066d + e92d34a commit 6ad75d9
Showing 1 changed file with 35 additions and 3 deletions.
38 changes: 35 additions & 3 deletions Oqtane.Server/Controllers/InstallationController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@ public class InstallationController : Controller
private readonly IMemoryCache _cache;
private readonly IHttpContextAccessor _accessor;
private readonly IAliasRepository _aliases;
private readonly ISiteRepository _sites;
private readonly ILogger<InstallationController> _filelogger;
private readonly ITenantManager _tenantManager;
private readonly IServerStateManager _serverState;

public InstallationController(IConfigManager configManager, IInstallationManager installationManager, IDatabaseManager databaseManager, ILocalizationManager localizationManager, IMemoryCache cache, IHttpContextAccessor accessor, IAliasRepository aliases, ILogger<InstallationController> filelogger, ITenantManager tenantManager, IServerStateManager serverState)
public InstallationController(IConfigManager configManager, IInstallationManager installationManager, IDatabaseManager databaseManager, ILocalizationManager localizationManager, IMemoryCache cache, IHttpContextAccessor accessor, IAliasRepository aliases, ISiteRepository sites, ILogger<InstallationController> filelogger, ITenantManager tenantManager, IServerStateManager serverState)
{
_configManager = configManager;
_installationManager = installationManager;
Expand All @@ -43,6 +44,7 @@ public InstallationController(IConfigManager configManager, IInstallationManager
_cache = cache;
_accessor = accessor;
_aliases = aliases;
_sites = sites;
_filelogger = filelogger;
_tenantManager = tenantManager;
_serverState = serverState;
Expand Down Expand Up @@ -105,14 +107,32 @@ public void Restart()
[HttpGet("list")]
public List<string> List()
{
return GetAssemblyList().Select(item => item.HashedName).ToList();
var alias = _tenantManager.GetAlias();
var site = _sites.GetSite(alias.SiteId);
if (site != null && site.Runtime == "WebAssembly")
{
return GetAssemblyList().Select(item => item.HashedName).ToList();
}
else
{
return new List<string>();
}
}

// GET api/<controller>/load?list=x,y
[HttpGet("load")]
public IActionResult Load(string list = "*")
{
return File(GetAssemblies(list), System.Net.Mime.MediaTypeNames.Application.Octet, "oqtane.dll");
var alias = _tenantManager.GetAlias();
var site = _sites.GetSite(alias.SiteId);
if (site != null && site.Runtime == "WebAssembly")
{
return File(GetAssemblies(list), System.Net.Mime.MediaTypeNames.Application.Octet, "oqtane.dll");
}
else
{
return File(GetEmptyZip(), System.Net.Mime.MediaTypeNames.Application.Octet, "oqtane.dll");
}
}

private List<ClientAssembly> GetAssemblyList()
Expand Down Expand Up @@ -238,6 +258,18 @@ private byte[] GetZIP(string list)
}
}

private byte[] GetEmptyZip()
{
using (var stream = new MemoryStream())
{
using (var zip = new ZipArchive(stream, ZipArchiveMode.Create))
{
}

return stream.ToArray();
}
}

private async Task RegisterContact(string email)
{
try
Expand Down

0 comments on commit 6ad75d9

Please sign in to comment.