mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2026-01-06 15:44:26 +01:00
Can configure an internallightningnode to make things easier
This commit is contained in:
@@ -79,8 +79,11 @@ namespace BTCPayServer.Configuration
|
||||
|
||||
PostgresConnectionString = conf.GetOrDefault<string>("postgres", null);
|
||||
ExternalUrl = conf.GetOrDefault<Uri>("externalurl", null);
|
||||
InternalLightningNode = conf.GetOrDefault<Uri>("internallightningnode", null);
|
||||
}
|
||||
|
||||
public Uri InternalLightningNode { get; set; }
|
||||
|
||||
public BTCPayNetworkProvider NetworkProvider { get; set; }
|
||||
public string PostgresConnectionString
|
||||
{
|
||||
|
||||
@@ -27,7 +27,14 @@ namespace BTCPayServer.Configuration
|
||||
throw new FormatException();
|
||||
}
|
||||
else if (typeof(T) == typeof(Uri))
|
||||
return (T)(object)new Uri(str, UriKind.Absolute);
|
||||
if (string.IsNullOrEmpty(str))
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
return (T)(object)new Uri(str, UriKind.Absolute);
|
||||
}
|
||||
else if (typeof(T) == typeof(string))
|
||||
return (T)(object)str;
|
||||
else if (typeof(T) == typeof(IPEndPoint))
|
||||
|
||||
@@ -38,6 +38,7 @@ namespace BTCPayServer.Configuration
|
||||
app.Option($"--{crypto}explorercookiefile", $"Path to the cookie file (default: {network.NBXplorerNetwork.DefaultSettings.DefaultCookieFile})", CommandOptionType.SingleValue);
|
||||
}
|
||||
app.Option("--externalurl", $"The expected external url of this service, to use if BTCPay is behind a reverse proxy (default: empty, use the incoming HTTP request to figure out)", CommandOptionType.SingleValue);
|
||||
app.Option("--internallightningnode", $"An internal lightning node which can be used without https requirement and easily configured by the admin (default: empty)", CommandOptionType.SingleValue);
|
||||
return app;
|
||||
}
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ namespace BTCPayServer.Controllers
|
||||
return NotFound();
|
||||
LightningNodeViewModel vm = new LightningNodeViewModel();
|
||||
vm.SetCryptoCurrencies(_NetworkProvider, selectedCrypto);
|
||||
vm.InternalLightningNode = GetInternalLightningNodeIfAuthorized();
|
||||
return View(vm);
|
||||
}
|
||||
|
||||
@@ -35,6 +36,7 @@ namespace BTCPayServer.Controllers
|
||||
return NotFound();
|
||||
var network = vm.CryptoCurrency == null ? null : _ExplorerProvider.GetNetwork(vm.CryptoCurrency);
|
||||
vm.SetCryptoCurrencies(_NetworkProvider, vm.CryptoCurrency);
|
||||
vm.InternalLightningNode = GetInternalLightningNodeIfAuthorized();
|
||||
if (network == null || network.CLightningNetworkName == null)
|
||||
{
|
||||
ModelState.AddModelError(nameof(vm.CryptoCurrency), "Invalid network");
|
||||
@@ -51,14 +53,23 @@ namespace BTCPayServer.Controllers
|
||||
ModelState.AddModelError(nameof(vm.Url), "Invalid URL");
|
||||
return View(vm);
|
||||
}
|
||||
if (_NetworkProvider.ChainType == NBXplorer.ChainType.Main)
|
||||
|
||||
if (uri.Scheme != "https")
|
||||
{
|
||||
if (uri.Scheme != "https")
|
||||
var internalNode = GetInternalLightningNodeIfAuthorized();
|
||||
if (internalNode == null || GetDomain(internalNode) != GetDomain(uri.AbsoluteUri))
|
||||
{
|
||||
ModelState.AddModelError(nameof(vm.Url), "The url must be HTTPS");
|
||||
return View(vm);
|
||||
}
|
||||
}
|
||||
|
||||
if (!CanUseInternalLightning() && GetDomain(_BtcpayServerOptions.InternalLightningNode.AbsoluteUri) == GetDomain(uri.AbsoluteUri))
|
||||
{
|
||||
ModelState.AddModelError(nameof(vm.Url), "Unauthorized url");
|
||||
return View(vm);
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(uri.UserInfo) || uri.UserInfo.Split(':').Length != 2)
|
||||
{
|
||||
ModelState.AddModelError(nameof(vm.Url), "The url is missing user and password");
|
||||
@@ -99,5 +110,25 @@ namespace BTCPayServer.Controllers
|
||||
return View(vm);
|
||||
}
|
||||
}
|
||||
|
||||
private string GetInternalLightningNodeIfAuthorized()
|
||||
{
|
||||
if (_BtcpayServerOptions.InternalLightningNode != null &&
|
||||
CanUseInternalLightning())
|
||||
{
|
||||
return _BtcpayServerOptions.InternalLightningNode.AbsoluteUri;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private bool CanUseInternalLightning()
|
||||
{
|
||||
return (_BTCPayEnv.IsDevelopping || User.IsInRole(Roles.ServerAdmin));
|
||||
}
|
||||
|
||||
string GetDomain(string uri)
|
||||
{
|
||||
return new UriBuilder(uri).Host;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using BTCPayServer.Authentication;
|
||||
using BTCPayServer.Configuration;
|
||||
using BTCPayServer.Data;
|
||||
using BTCPayServer.Models;
|
||||
using BTCPayServer.Models.StoreViewModels;
|
||||
@@ -31,6 +32,8 @@ namespace BTCPayServer.Controllers
|
||||
{
|
||||
public StoresController(
|
||||
IServiceProvider serviceProvider,
|
||||
BTCPayServerOptions btcpayServerOptions,
|
||||
BTCPayServerEnvironment btcpayEnv,
|
||||
IOptions<MvcJsonOptions> mvcJsonOptions,
|
||||
StoreRepository repo,
|
||||
TokenRepository tokenRepo,
|
||||
@@ -53,7 +56,11 @@ namespace BTCPayServer.Controllers
|
||||
_MvcJsonOptions = mvcJsonOptions.Value;
|
||||
_FeeRateProvider = feeRateProvider;
|
||||
_ServiceProvider = serviceProvider;
|
||||
_BtcpayServerOptions = btcpayServerOptions;
|
||||
_BTCPayEnv = btcpayEnv;
|
||||
}
|
||||
BTCPayServerOptions _BtcpayServerOptions;
|
||||
BTCPayServerEnvironment _BTCPayEnv;
|
||||
IServiceProvider _ServiceProvider;
|
||||
BTCPayNetworkProvider _NetworkProvider;
|
||||
private ExplorerClientProvider _ExplorerProvider;
|
||||
|
||||
@@ -29,6 +29,7 @@ namespace BTCPayServer.Models.StoreViewModels
|
||||
}
|
||||
public SelectList CryptoCurrencies { get; set; }
|
||||
public string StatusMessage { get; set; }
|
||||
public string InternalLightningNode { get; internal set; }
|
||||
|
||||
public void SetCryptoCurrencies(BTCPayNetworkProvider networkProvider, string selectedScheme)
|
||||
{
|
||||
|
||||
@@ -15,15 +15,16 @@
|
||||
"Docker-Regtest": {
|
||||
"commandName": "Project",
|
||||
"launchBrowser": true,
|
||||
"environmentVariables": {
|
||||
"BTCPAY_NETWORK": "regtest",
|
||||
"BTCPAY_LTCEXPLORERURL": "http://127.0.0.1:32838/",
|
||||
"BTCPAY_BTCEXPLORERURL": "http://127.0.0.1:32838/",
|
||||
"ASPNETCORE_ENVIRONMENT": "Development",
|
||||
"BTCPAY_CHAINS": "btc,ltc",
|
||||
"BTCPAY_POSTGRES": "User ID=postgres;Host=127.0.0.1;Port=39372;Database=btcpayserver"
|
||||
},
|
||||
"environmentVariables": {
|
||||
"BTCPAY_NETWORK": "regtest",
|
||||
"BTCPAY_LTCEXPLORERURL": "http://127.0.0.1:32838/",
|
||||
"BTCPAY_BTCEXPLORERURL": "http://127.0.0.1:32838/",
|
||||
"ASPNETCORE_ENVIRONMENT": "Development",
|
||||
"BTCPAY_CHAINS": "btc,ltc",
|
||||
"BTCPAY_POSTGRES": "User ID=postgres;Host=127.0.0.1;Port=39372;Database=btcpayserver",
|
||||
"BTCPAY_INTERNALLIGHTNINGNODE": "http://api-token:foiewnccewuify@127.0.0.1:54938/"
|
||||
},
|
||||
"applicationUrl": "http://localhost:14142/"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
@inject BTCPayServer.Services.BTCPayServerEnvironment env
|
||||
@model LightningNodeViewModel
|
||||
@model LightningNodeViewModel
|
||||
@{
|
||||
Layout = "../Shared/_NavLayout.cshtml";
|
||||
ViewData["Title"] = "Add lightning node (Experimental)";
|
||||
@@ -13,12 +12,6 @@
|
||||
<div asp-validation-summary="All" class="text-danger"></div>
|
||||
</div>
|
||||
</div>
|
||||
@if(env.IsDevelopping) {
|
||||
<div class="alert alert-info alert-dismissible" role="alert">
|
||||
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
|
||||
<span>To test during development, please use http://api-token:foiewnccewuify@127.0.0.1:54938/ </span>
|
||||
</div>
|
||||
}
|
||||
|
||||
<div class="alert alert-warning alert-dismissible" role="alert">
|
||||
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
|
||||
@@ -49,8 +42,14 @@
|
||||
|
||||
<div class="form-group">
|
||||
<label asp-for="Url"></label>
|
||||
<input asp-for="Url" class="form-control" />
|
||||
<input id="lightningurl" asp-for="Url" class="form-control" />
|
||||
<span asp-validation-for="Url" class="text-danger"></span>
|
||||
@if(Model.InternalLightningNode != null)
|
||||
{
|
||||
<p class="form-text text-muted">
|
||||
You can use the internal lightning node by <a href="#" onclick="$('#lightningurl').val('@Model.InternalLightningNode'); return false;">clicking here</a>
|
||||
</p>
|
||||
}
|
||||
</div>
|
||||
<button name="command" type="submit" value="save" class="btn btn-success">Submit</button>
|
||||
<button name="command" type="submit" value="test" class="btn btn-info">Test connection</button>
|
||||
|
||||
Reference in New Issue
Block a user