mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-18 06:24:24 +01:00
Removing LND seed information from walletunlock.json
This commit is contained in:
@@ -666,6 +666,38 @@ namespace BTCPayServer.Controllers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
[Route("server/services/{serviceName}/{cryptoCode}/removelndseed")]
|
||||||
|
public async Task<IActionResult> RemoveLndSeed(string serviceName, string cryptoCode)
|
||||||
|
{
|
||||||
|
var service = GetService(serviceName, cryptoCode);
|
||||||
|
if (service == null)
|
||||||
|
return NotFound();
|
||||||
|
|
||||||
|
var model = LndSeedBackupViewModel.Parse(service.ConnectionString.CookieFilePath);
|
||||||
|
if (!model.IsWalletUnlockPresent)
|
||||||
|
{
|
||||||
|
TempData[WellKnownTempData.ErrorMessage] = $"File with wallet password and seed info not present";
|
||||||
|
return RedirectToAction(nameof(Services));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (model.Seed == null || model.Seed.Count <= 1)
|
||||||
|
{
|
||||||
|
TempData[WellKnownTempData.ErrorMessage] = $"Seed information was already removed";
|
||||||
|
return RedirectToAction(nameof(Services));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (await model.RemoveSeedAndWrite(service.ConnectionString.CookieFilePath))
|
||||||
|
{
|
||||||
|
return RedirectToAction(nameof(Service), new { serviceName, cryptoCode });
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
TempData[WellKnownTempData.ErrorMessage] = $"Seed removal failed";
|
||||||
|
return RedirectToAction(nameof(Services));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private IActionResult LightningChargeServices(ExternalService service, ExternalConnectionString connectionString, bool showQR = false)
|
private IActionResult LightningChargeServices(ExternalService service, ExternalConnectionString connectionString, bool showQR = false)
|
||||||
{
|
{
|
||||||
ChargeServiceViewModel vm = new ChargeServiceViewModel();
|
ChargeServiceViewModel vm = new ChargeServiceViewModel();
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.Globalization;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace BTCPayServer.Models.ServerViewModels
|
namespace BTCPayServer.Models.ServerViewModels
|
||||||
@@ -14,6 +16,29 @@ namespace BTCPayServer.Models.ServerViewModels
|
|||||||
|
|
||||||
public List<string> Seed { get; set; }
|
public List<string> Seed { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
public async Task<bool> RemoveSeedAndWrite(string lndSeedFilePath)
|
||||||
|
{
|
||||||
|
var removedDate = DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ssZ", CultureInfo.InvariantCulture);
|
||||||
|
var seedFile = new LndSeedFile
|
||||||
|
{
|
||||||
|
wallet_password = WalletPassword,
|
||||||
|
cipher_seed_mnemonic = new List<string> { $"Seed removed on {removedDate}" }
|
||||||
|
};
|
||||||
|
var json = JsonConvert.SerializeObject(seedFile);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await File.WriteAllTextAsync(lndSeedFilePath, json);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
// file access exception and such
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public static LndSeedBackupViewModel Parse(string lndSeedFilePath)
|
public static LndSeedBackupViewModel Parse(string lndSeedFilePath)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|||||||
@@ -24,13 +24,20 @@
|
|||||||
<p>
|
<p>
|
||||||
<div><a href="#details" data-toggle="collapse">Reveal Seed Information</a></div>
|
<div><a href="#details" data-toggle="collapse">Reveal Seed Information</a></div>
|
||||||
<div id="details" class="collapse">
|
<div id="details" class="collapse">
|
||||||
@String.Join(", ", Model.Seed)
|
@foreach (var item in Model.Seed)
|
||||||
|
{
|
||||||
|
<span>@item</span>
|
||||||
|
}
|
||||||
|
<br /><br />
|
||||||
|
<form method="post" action="@Context.Request.Path/removelndseed">
|
||||||
|
<button class="btn btn-primary" type="submit" onclick="return confirmSeedDelete();">Remove Seed from server</button>
|
||||||
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</p>
|
</p>
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
<p>Seed information was deleted on <b>@Model.Seed.First()</b></p>
|
<p><b>@Model.Seed.First()</b></p>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
Reference in New Issue
Block a user