mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2025-02-22 06:21:44 +01:00
* Swap bootstrap asset files * Update themes and color definitions * Move general bootstrap customizations * Theme updates Theme updates * Remove BuildBundlerMinifier This lead to an error, because BuildBundlerMinifier and BundlerMinifier.Core seem to conflict here. Details: https://stackoverflow.com/a/61119586 * Rewplace btn-block class with w-100 * Update badge classes * Remove old font family head variable * Update margin classes * Cleanups * Update float classes * Update text classes * Update padding classes * Update border classes * UPdate dropdown classes * Update select classes * Update neutral custom props * Update bootstrap and customizations * Update ChromeDriver; disable smooth scroll https://github.com/SeleniumHQ/selenium/issues/8295 * Improve alert messages * Improve bootstrap customizations * Disable reduced motion See also 7358282f * Update Bootstrap data attributes * Update file inputs * Update input groups * Replace deprecated jumbotron class * Update variables; re-add negative margin util classes * Update cards * Update form labels * Debug alerts * Fix aria-labelledby associations * Dropdown-related test fixes * Fix CanUseWebhooks test * Test fixes * Nav updates * Fix nav usage in wallet send and payouts * Update alert and modal close buttons * Re-add backdrop properties * Upgrade Bootstrap to v5 final * Update screen reader classes * Update font-weight classes * Update monospace font classes * Update accordians * Update close icon usage * Cleanup * Update scripts and style integrations * Update input group texts * Update LN node setup page * Update more form control classes * Update inline forms * Add js specific test * Upgrade Vue.js * Remove unused JS * Upgrade Bootstrap to v5.0.1 * Try container related test updates * Separate jQuery bundle * Remove jQuery from LND seed backup page * Remove unused code * Refactor email autofill js * Refactor camera scanner JS * Re-add tests * Re-add BuildBundlerMinifier * Do not minify bundles containing Bootstrap Details https://github.com/madskristensen/BundlerMinifier/issues/558 * Update bundles * Cleanup JS test * Cleanup tests involving dropdowns * Cleanup tests involving collapses * Cleanup locale additions in ConfigureCore * Cleanup bundles * Remove duplicate status message * Cleanup formatting * Fix missing validation scripts * Remove unused unminified Bootstrap js files * Fix classic theme * Fix Casa theme * Fix PoS validation
155 lines
5.2 KiB
C#
155 lines
5.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
using BTCPayServer.Security;
|
|
using BTCPayServer.Services;
|
|
using BTCPayServer.Services.Apps;
|
|
using Microsoft.AspNetCore.Mvc.Filters;
|
|
|
|
namespace BTCPayServer.HostedServices
|
|
{
|
|
public class CssThemeManager
|
|
{
|
|
public void Update(ThemeSettings data)
|
|
{
|
|
if (String.IsNullOrWhiteSpace(data.ThemeCssUri))
|
|
_themeUri = "/main/themes/default.css";
|
|
else
|
|
_themeUri = data.ThemeCssUri;
|
|
|
|
if (String.IsNullOrWhiteSpace(data.CustomThemeCssUri))
|
|
_customThemeUri = null;
|
|
else
|
|
_customThemeUri = data.CustomThemeCssUri;
|
|
|
|
if (String.IsNullOrWhiteSpace(data.BootstrapCssUri))
|
|
_bootstrapUri = "/main/bootstrap/bootstrap.css";
|
|
else
|
|
_bootstrapUri = data.BootstrapCssUri;
|
|
|
|
if (String.IsNullOrWhiteSpace(data.CreativeStartCssUri))
|
|
_creativeStartUri = "/main/bootstrap/creative.css";
|
|
else
|
|
_creativeStartUri = data.CreativeStartCssUri;
|
|
|
|
FirstRun = data.FirstRun;
|
|
}
|
|
|
|
private string _themeUri;
|
|
public string ThemeUri
|
|
{
|
|
get { return _themeUri; }
|
|
}
|
|
|
|
private string _customThemeUri;
|
|
public string CustomThemeUri
|
|
{
|
|
get { return _customThemeUri; }
|
|
}
|
|
|
|
private string _bootstrapUri;
|
|
public string BootstrapUri
|
|
{
|
|
get { return _bootstrapUri; }
|
|
}
|
|
|
|
private string _creativeStartUri;
|
|
private PoliciesSettings _policies = new PoliciesSettings();
|
|
|
|
public PoliciesSettings Policies { get { return _policies; } }
|
|
public string CreativeStartUri
|
|
{
|
|
get { return _creativeStartUri; }
|
|
}
|
|
|
|
|
|
public bool ShowRegister { get { return !_policies.LockSubscription; } }
|
|
public bool DiscourageSearchEngines { get { return _policies.DiscourageSearchEngines; } }
|
|
public AppType? RootAppType { get { return _policies.RootAppType; } }
|
|
public string RootAppId { get { return _policies.RootAppId; } }
|
|
|
|
public bool FirstRun { get; set; }
|
|
|
|
public List<PoliciesSettings.DomainToAppMappingItem> DomainToAppMapping { get { return _policies.DomainToAppMapping; } }
|
|
|
|
internal void Update(PoliciesSettings data)
|
|
{
|
|
_policies = data;
|
|
|
|
|
|
}
|
|
|
|
public bool AllowLightningInternalNodeForAll { get { return _policies.AllowLightningInternalNodeForAll; } }
|
|
}
|
|
|
|
public class ContentSecurityPolicyCssThemeManager : Attribute, IActionFilter, IOrderedFilter
|
|
{
|
|
public int Order => 1001;
|
|
|
|
public void OnActionExecuted(ActionExecutedContext context)
|
|
{
|
|
|
|
}
|
|
|
|
public void OnActionExecuting(ActionExecutingContext context)
|
|
{
|
|
var manager = context.HttpContext.RequestServices.GetService(typeof(CssThemeManager)) as CssThemeManager;
|
|
var policies = context.HttpContext.RequestServices.GetService(typeof(ContentSecurityPolicies)) as ContentSecurityPolicies;
|
|
if (manager != null && policies != null)
|
|
{
|
|
if (manager.CreativeStartUri != null && Uri.TryCreate(manager.CreativeStartUri, UriKind.Absolute, out var uri))
|
|
{
|
|
policies.Clear();
|
|
}
|
|
if (manager.BootstrapUri != null && Uri.TryCreate(manager.BootstrapUri, UriKind.Absolute, out uri))
|
|
{
|
|
policies.Clear();
|
|
}
|
|
if (manager.ThemeUri != null && Uri.TryCreate(manager.ThemeUri, UriKind.Absolute, out uri))
|
|
{
|
|
policies.Clear();
|
|
}
|
|
if (manager.CustomThemeUri != null && Uri.TryCreate(manager.CustomThemeUri, UriKind.Absolute, out uri))
|
|
{
|
|
policies.Clear();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public class CssThemeManagerHostedService : BaseAsyncService
|
|
{
|
|
private readonly SettingsRepository _SettingsRepository;
|
|
private readonly CssThemeManager _CssThemeManager;
|
|
|
|
public CssThemeManagerHostedService(SettingsRepository settingsRepository, CssThemeManager cssThemeManager)
|
|
{
|
|
_SettingsRepository = settingsRepository;
|
|
_CssThemeManager = cssThemeManager;
|
|
}
|
|
|
|
internal override Task[] InitializeTasks()
|
|
{
|
|
return new[]
|
|
{
|
|
CreateLoopTask(ListenForThemeChanges),
|
|
CreateLoopTask(ListenForPoliciesChanges),
|
|
};
|
|
}
|
|
|
|
async Task ListenForPoliciesChanges()
|
|
{
|
|
var data = (await _SettingsRepository.GetSettingAsync<PoliciesSettings>()) ?? new PoliciesSettings();
|
|
_CssThemeManager.Update(data);
|
|
await _SettingsRepository.WaitSettingsChanged<PoliciesSettings>(Cancellation);
|
|
}
|
|
|
|
async Task ListenForThemeChanges()
|
|
{
|
|
var data = (await _SettingsRepository.GetSettingAsync<ThemeSettings>()) ?? new ThemeSettings();
|
|
_CssThemeManager.Update(data);
|
|
|
|
await _SettingsRepository.WaitSettingsChanged<ThemeSettings>(Cancellation);
|
|
}
|
|
}
|
|
}
|