mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2025-01-19 05:33:31 +01:00
Make sure calling monero related controllers can't be done if the shitcoin is not supported
This commit is contained in:
parent
8c8ef9d3ca
commit
639f5d2fc4
@ -13,13 +13,6 @@ namespace BTCPayServer.Altcoins.Monero
|
|||||||
{
|
{
|
||||||
public static class MoneroLikeExtensions
|
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)
|
public static IServiceCollection AddMoneroLike(this IServiceCollection serviceCollection)
|
||||||
{
|
{
|
||||||
serviceCollection.AddSingleton(provider =>
|
serviceCollection.AddSingleton(provider =>
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
|
using BTCPayServer.Filters;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
namespace BTCPayServer.Altcoins.Monero.RPC
|
namespace BTCPayServer.Altcoins.Monero.RPC
|
||||||
{
|
{
|
||||||
[Route("[controller]")]
|
[Route("[controller]")]
|
||||||
|
[OnlyIfSupportAttribute("XMR")]
|
||||||
public class MoneroLikeDaemonCallbackController : Controller
|
public class MoneroLikeDaemonCallbackController : Controller
|
||||||
{
|
{
|
||||||
private readonly EventAggregator _eventAggregator;
|
private readonly EventAggregator _eventAggregator;
|
||||||
|
@ -19,10 +19,12 @@ using Microsoft.AspNetCore.Authorization;
|
|||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.AspNetCore.Mvc.Rendering;
|
using Microsoft.AspNetCore.Mvc.Rendering;
|
||||||
|
using BTCPayServer.Filters;
|
||||||
|
|
||||||
namespace BTCPayServer.Altcoins.Monero.UI
|
namespace BTCPayServer.Altcoins.Monero.UI
|
||||||
{
|
{
|
||||||
[Route("stores/{storeId}/monerolike")]
|
[Route("stores/{storeId}/monerolike")]
|
||||||
|
[OnlyIfSupportAttribute("XMR")]
|
||||||
[Authorize(AuthenticationSchemes = Policies.CookieAuthentication)]
|
[Authorize(AuthenticationSchemes = Policies.CookieAuthentication)]
|
||||||
[Authorize(Policy = Policies.CanModifyStoreSettings.Key, AuthenticationSchemes = Policies.CookieAuthentication)]
|
[Authorize(Policy = Policies.CanModifyStoreSettings.Key, AuthenticationSchemes = Policies.CookieAuthentication)]
|
||||||
[Authorize(Policy = Policies.CanModifyServerSettings.Key, AuthenticationSchemes = Policies.CookieAuthentication)]
|
[Authorize(Policy = Policies.CanModifyServerSettings.Key, AuthenticationSchemes = Policies.CookieAuthentication)]
|
||||||
|
30
BTCPayServer/Filters/OnlyIfSupportAttribute.cs
Normal file
30
BTCPayServer/Filters/OnlyIfSupportAttribute.cs
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,5 @@
|
|||||||
using BTCPayServer.Configuration;
|
using BTCPayServer.Configuration;
|
||||||
|
using BTCPayServer.Altcoins.Monero;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using System;
|
using System;
|
||||||
using System.IdentityModel.Tokens.Jwt;
|
using System.IdentityModel.Tokens.Jwt;
|
||||||
@ -70,6 +71,7 @@ namespace BTCPayServer.Hosting
|
|||||||
{
|
{
|
||||||
httpClient.Timeout = Timeout.InfiniteTimeSpan;
|
httpClient.Timeout = Timeout.InfiniteTimeSpan;
|
||||||
});
|
});
|
||||||
|
services.AddMoneroLike();
|
||||||
services.TryAddSingleton<SettingsRepository>();
|
services.TryAddSingleton<SettingsRepository>();
|
||||||
services.TryAddSingleton<TorServices>();
|
services.TryAddSingleton<TorServices>();
|
||||||
services.TryAddSingleton<SocketFactory>();
|
services.TryAddSingleton<SocketFactory>();
|
||||||
|
@ -21,7 +21,6 @@ using OpenIddict.EntityFrameworkCore.Models;
|
|||||||
using System.Net;
|
using System.Net;
|
||||||
using BTCPayServer.Authentication;
|
using BTCPayServer.Authentication;
|
||||||
using BTCPayServer.Authentication.OpenId;
|
using BTCPayServer.Authentication.OpenId;
|
||||||
using BTCPayServer.Altcoins.Monero;
|
|
||||||
using BTCPayServer.PaymentRequest;
|
using BTCPayServer.PaymentRequest;
|
||||||
using BTCPayServer.Services.Apps;
|
using BTCPayServer.Services.Apps;
|
||||||
using BTCPayServer.Storage;
|
using BTCPayServer.Storage;
|
||||||
@ -49,10 +48,6 @@ namespace BTCPayServer.Hosting
|
|||||||
{
|
{
|
||||||
Logs.Configure(LoggerFactory);
|
Logs.Configure(LoggerFactory);
|
||||||
services.ConfigureBTCPayServer(Configuration);
|
services.ConfigureBTCPayServer(Configuration);
|
||||||
if (Configuration.AnyMoneroLikeCoinsConfigured())
|
|
||||||
{
|
|
||||||
services.AddMoneroLike();
|
|
||||||
}
|
|
||||||
services.AddMemoryCache();
|
services.AddMemoryCache();
|
||||||
services.AddIdentity<ApplicationUser, IdentityRole>()
|
services.AddIdentity<ApplicationUser, IdentityRole>()
|
||||||
.AddEntityFrameworkStores<ApplicationDbContext>()
|
.AddEntityFrameworkStores<ApplicationDbContext>()
|
||||||
|
Loading…
Reference in New Issue
Block a user