diff --git a/.gitignore b/.gitignore index 35908eca9..fbf55eb42 100644 --- a/.gitignore +++ b/.gitignore @@ -293,3 +293,4 @@ BTCPayServer/wwwroot/bundles/* !BTCPayServer/wwwroot/bundles/.gitignore .vscode +BTCPayServer/testpwd diff --git a/BTCPayServer/Configuration/BTCPayServerOptions.cs b/BTCPayServer/Configuration/BTCPayServerOptions.cs index de189636e..37c4a9d27 100644 --- a/BTCPayServer/Configuration/BTCPayServerOptions.cs +++ b/BTCPayServer/Configuration/BTCPayServerOptions.cs @@ -141,6 +141,7 @@ namespace BTCPayServer.Configuration ExternalServices.Load(net.CryptoCode, conf); } + ExternalServices.LoadNonCryptoServices(conf); Logs.Configuration.LogInformation("Supported chains: " + String.Join(',', supportedChains.ToArray())); var services = conf.GetOrDefault("externalservices", null); diff --git a/BTCPayServer/Configuration/ExternalConnectionString.cs b/BTCPayServer/Configuration/ExternalConnectionString.cs index 24c90411d..2c0114138 100644 --- a/BTCPayServer/Configuration/ExternalConnectionString.cs +++ b/BTCPayServer/Configuration/ExternalConnectionString.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Threading.Tasks; using BTCPayServer.Controllers; @@ -77,7 +78,7 @@ namespace BTCPayServer.Configuration } } - if (serviceType == ExternalServiceTypes.Charge || serviceType == ExternalServiceTypes.RTL || serviceType == ExternalServiceTypes.Spark) + if (new []{ExternalServiceTypes.Charge, ExternalServiceTypes.RTL, ExternalServiceTypes.Spark, ExternalServiceTypes.Configurator}.Contains(serviceType)) { // Read access key from cookie file if (connectionString.CookieFilePath != null) diff --git a/BTCPayServer/Configuration/ExternalService.cs b/BTCPayServer/Configuration/ExternalService.cs index 1fc05215b..ccee3cb34 100644 --- a/BTCPayServer/Configuration/ExternalService.cs +++ b/BTCPayServer/Configuration/ExternalService.cs @@ -41,11 +41,20 @@ namespace BTCPayServer.Configuration $"lightning charge server: 'type=charge;server=https://charge.example.com;cookiefilepath=/root/.charge/.cookie'" + Environment.NewLine + "Error: {1}", "C-Lightning (Charge server)"); + + } + + public void LoadNonCryptoServices(IConfiguration configuration) + { + Load(configuration, null, "configurator", ExternalServiceTypes.Configurator, "Invalid setting {0}, " + Environment.NewLine + + $"configurator: 'passwordfile=/etc/configurator/password'" + Environment.NewLine + + "Error: {1}", + "Configurator"); } void Load(IConfiguration configuration, string cryptoCode, string serviceName, ExternalServiceTypes type, string errorMessage, string displayName) { - var setting = $"{cryptoCode}.external.{serviceName}"; + var setting = $"{(!string.IsNullOrEmpty(cryptoCode)? $"{cryptoCode}.": string.Empty)}external.{serviceName}"; var connStr = configuration.GetOrDefault(setting, string.Empty); if (connStr.Length != 0) { @@ -65,8 +74,11 @@ namespace BTCPayServer.Configuration public ExternalService GetService(string serviceName, string cryptoCode) { - return this.FirstOrDefault(o => o.CryptoCode.Equals(cryptoCode, StringComparison.OrdinalIgnoreCase) && - o.ServiceName.Equals(serviceName, StringComparison.OrdinalIgnoreCase)); + return this.FirstOrDefault(o => + (cryptoCode == null && o.CryptoCode == null) || + (o.CryptoCode != null && o.CryptoCode.Equals(cryptoCode, StringComparison.OrdinalIgnoreCase)) + && + o.ServiceName.Equals(serviceName, StringComparison.OrdinalIgnoreCase)); } } @@ -88,6 +100,7 @@ namespace BTCPayServer.Configuration RTL, Charge, P2P, - RPC + RPC, + Configurator } } diff --git a/BTCPayServer/Controllers/ServerController.cs b/BTCPayServer/Controllers/ServerController.cs index 7455f0d80..ec2d19331 100644 --- a/BTCPayServer/Controllers/ServerController.cs +++ b/BTCPayServer/Controllers/ServerController.cs @@ -528,10 +528,12 @@ namespace BTCPayServer.Controllers return null; } - [Route("server/services/{serviceName}/{cryptoCode}")] + + + [Route("server/services/{serviceName}/{cryptoCode?}")] public async Task Service(string serviceName, string cryptoCode, bool showQR = false, uint? nonce = null) { - if (!_dashBoard.IsFullySynched(cryptoCode, out _)) + if (!string.IsNullOrEmpty(cryptoCode) && !_dashBoard.IsFullySynched(cryptoCode, out _)) { TempData[WellKnownTempData.ErrorMessage] = $"{cryptoCode} is not fully synched"; return RedirectToAction(nameof(Services)); @@ -542,6 +544,7 @@ namespace BTCPayServer.Controllers try { + if (service.Type == ExternalServiceTypes.P2P) { return View("P2PService", new LightningWalletServices() @@ -595,6 +598,14 @@ namespace BTCPayServer.Controllers case ExternalServiceTypes.LNDGRPC: case ExternalServiceTypes.LNDRest: return LndServices(service, connectionString, nonce); + case ExternalServiceTypes.Configurator: + return View("ConfiguratorService", + new LightningWalletServices() + { + ShowQR = showQR, + WalletName = service.ServiceName, + ServiceLink = $"{connectionString.Server}?password={connectionString.AccessKey}" + }); default: throw new NotSupportedException(service.Type.ToString()); } diff --git a/BTCPayServer/Properties/launchSettings.json b/BTCPayServer/Properties/launchSettings.json index b578d2481..2f3db0eaa 100644 --- a/BTCPayServer/Properties/launchSettings.json +++ b/BTCPayServer/Properties/launchSettings.json @@ -40,6 +40,7 @@ "BTCPAY_BTCEXTERNALLNDSEEDBACKUP": "../BTCPayServer.Tests/TestData/LndSeedBackup/walletunlock.json", "BTCPAY_BTCEXTERNALSPARK": "server=/spark/btc/;cookiefile=fake", "BTCPAY_BTCEXTERNALCHARGE": "server=https://127.0.0.1:53280/mycharge/btc/;cookiefilepath=fake", + "BTCPAY_EXTERNALCONFIGURATOR": "passwordfile=testpwd;server=/configurator", "BTCPAY_BTCEXPLORERURL": "http://127.0.0.1:32838/", "BTCPAY_ALLOW-ADMIN-REGISTRATION": "true", "BTCPAY_DISABLE-REGISTRATION": "false", diff --git a/BTCPayServer/Views/Server/ConfiguratorService.cshtml b/BTCPayServer/Views/Server/ConfiguratorService.cshtml new file mode 100644 index 000000000..5106650d1 --- /dev/null +++ b/BTCPayServer/Views/Server/ConfiguratorService.cshtml @@ -0,0 +1,33 @@ +@model LightningWalletServices +@{ + ViewData.SetActivePageAndTitle(ServerNavPages.Services); +} + +

BTCPay Server Configurator

+ + +
+
+
+
+
+ +
+
+
+

+ This page exposes information to use the configured BTCPay Server Configurator to modify this setup. +

+
+ + + + + +
+
+ +@section Scripts { + @await Html.PartialAsync("_ValidationScriptsPartial") + +} diff --git a/BTCPayServer/Views/Server/Services.cshtml b/BTCPayServer/Views/Server/Services.cshtml index 4794610c2..33e18d34e 100644 --- a/BTCPayServer/Views/Server/Services.cshtml +++ b/BTCPayServer/Views/Server/Services.cshtml @@ -29,7 +29,7 @@ - @foreach (var s in Model.ExternalServices) + @foreach (var s in Model.ExternalServices.Where(service => !string.IsNullOrEmpty(service.CryptoCode))) { @s.CryptoCode @@ -52,7 +52,7 @@ -@if (Model.OtherExternalServices.Count != 0) +@if (Model.OtherExternalServices.Count != 0 || Model.ExternalServices.Any(service => string.IsNullOrEmpty(service.CryptoCode))) {
@@ -69,6 +69,15 @@ + @foreach (var s in Model.ExternalServices.Where(service => string.IsNullOrEmpty(service.CryptoCode))) + { + + @s.DisplayName + + See information + + + } @foreach (var s in Model.OtherExternalServices) {