Make sure calling monero related controllers can't be done if the shitcoin is not supported

This commit is contained in:
nicolas.dorier 2019-10-01 15:30:27 +09:00
parent 8c8ef9d3ca
commit 639f5d2fc4
No known key found for this signature in database
GPG Key ID: 6618763EF09186FE
6 changed files with 36 additions and 12 deletions

View File

@ -13,13 +13,6 @@ namespace BTCPayServer.Altcoins.Monero
{
public static class MoneroLikeExtensions
{
public static bool AnyMoneroLikeCoinsConfigured(this IConfiguration configuration)
{
return configuration.GetOrDefault<string>("chains", "")
.Split(',', StringSplitOptions.RemoveEmptyEntries)
.Select(t => t.ToUpperInvariant())
.Any(s => s == "XMR");
}
public static IServiceCollection AddMoneroLike(this IServiceCollection serviceCollection)
{
serviceCollection.AddSingleton(provider =>

View File

@ -1,8 +1,10 @@
using BTCPayServer.Filters;
using Microsoft.AspNetCore.Mvc;
namespace BTCPayServer.Altcoins.Monero.RPC
{
[Route("[controller]")]
[OnlyIfSupportAttribute("XMR")]
public class MoneroLikeDaemonCallbackController : Controller
{
private readonly EventAggregator _eventAggregator;

View File

@ -19,10 +19,12 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Rendering;
using BTCPayServer.Filters;
namespace BTCPayServer.Altcoins.Monero.UI
{
[Route("stores/{storeId}/monerolike")]
[OnlyIfSupportAttribute("XMR")]
[Authorize(AuthenticationSchemes = Policies.CookieAuthentication)]
[Authorize(Policy = Policies.CanModifyStoreSettings.Key, AuthenticationSchemes = Policies.CookieAuthentication)]
[Authorize(Policy = Policies.CanModifyServerSettings.Key, AuthenticationSchemes = Policies.CookieAuthentication)]

View File

@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using BTCPayServer.Configuration;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
namespace BTCPayServer.Filters
{
public class OnlyIfSupportAttribute : Attribute, IAsyncActionFilter
{
private readonly string _cryptoCode;
public OnlyIfSupportAttribute(string cryptoCode)
{
_cryptoCode = cryptoCode;
}
public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
{
var options = context.HttpContext.RequestServices.GetService(typeof(BTCPayServerOptions)) as BTCPayServerOptions;
if (options.NetworkProvider.GetNetwork(_cryptoCode) == null)
{
context.Result = new NotFoundResult();
return;
}
await next();
}
}
}

View File

@ -1,4 +1,5 @@
using BTCPayServer.Configuration;
using BTCPayServer.Altcoins.Monero;
using Microsoft.Extensions.Logging;
using System;
using System.IdentityModel.Tokens.Jwt;
@ -70,6 +71,7 @@ namespace BTCPayServer.Hosting
{
httpClient.Timeout = Timeout.InfiniteTimeSpan;
});
services.AddMoneroLike();
services.TryAddSingleton<SettingsRepository>();
services.TryAddSingleton<TorServices>();
services.TryAddSingleton<SocketFactory>();

View File

@ -21,7 +21,6 @@ using OpenIddict.EntityFrameworkCore.Models;
using System.Net;
using BTCPayServer.Authentication;
using BTCPayServer.Authentication.OpenId;
using BTCPayServer.Altcoins.Monero;
using BTCPayServer.PaymentRequest;
using BTCPayServer.Services.Apps;
using BTCPayServer.Storage;
@ -49,10 +48,6 @@ namespace BTCPayServer.Hosting
{
Logs.Configure(LoggerFactory);
services.ConfigureBTCPayServer(Configuration);
if (Configuration.AnyMoneroLikeCoinsConfigured())
{
services.AddMoneroLike();
}
services.AddMemoryCache();
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()