diff --git a/BTCPayServer/BTCPayServer.csproj b/BTCPayServer/BTCPayServer.csproj
index 574e2f7d8..3aed31c4d 100644
--- a/BTCPayServer/BTCPayServer.csproj
+++ b/BTCPayServer/BTCPayServer.csproj
@@ -10,6 +10,8 @@
+
+
diff --git a/BTCPayServer/Hosting/Startup.cs b/BTCPayServer/Hosting/Startup.cs
index b65d8ca50..98e6f8788 100644
--- a/BTCPayServer/Hosting/Startup.cs
+++ b/BTCPayServer/Hosting/Startup.cs
@@ -17,6 +17,8 @@ using BTCPayServer.Models;
using Microsoft.AspNetCore.Identity;
using BTCPayServer.Data;
using Microsoft.Extensions.Logging;
+using Hangfire;
+using Hangfire.SQLite;
using BTCPayServer.Logging;
using Microsoft.AspNetCore.Authorization;
using System.Threading.Tasks;
@@ -24,11 +26,28 @@ using BTCPayServer.Controllers;
using BTCPayServer.Services.Stores;
using BTCPayServer.Services.Mails;
using Microsoft.Extensions.Configuration;
+using Hangfire.AspNetCore;
+using BTCPayServer.Configuration;
+using System.IO;
+using Hangfire.Dashboard;
+using Hangfire.Annotations;
namespace BTCPayServer.Hosting
{
public class Startup
{
+ class NeedRole : IDashboardAuthorizationFilter
+ {
+ string _Role;
+ public NeedRole(string role)
+ {
+ _Role = role;
+ }
+ public bool Authorize([NotNull] DashboardContext context)
+ {
+ return context.GetHttpContext().User.IsInRole(_Role);
+ }
+ }
public Startup(IConfiguration conf)
{
Configuration = conf;
@@ -46,6 +65,13 @@ namespace BTCPayServer.Hosting
.AddEntityFrameworkStores()
.AddDefaultTokenProviders();
+ services.AddHangfire(o =>
+ {
+ var scope = AspNetCoreJobActivator.Current.BeginScope(null);
+ var options = (ApplicationDbContext)scope.Resolve(typeof(ApplicationDbContext));
+ var path = Path.Combine(((BTCPayServerOptions)scope.Resolve(typeof(BTCPayServerOptions))).DataDir, "hangfire.db");
+ o.UseSQLiteStorage("Data Source=" + path + ";");
+ });
services.AddBTCPayServer();
services.AddMvc();
}
@@ -65,7 +91,8 @@ namespace BTCPayServer.Hosting
app.UsePayServer();
app.UseStaticFiles();
app.UseAuthentication();
-
+ app.UseHangfireServer();
+ app.UseHangfireDashboard("/hangfire", new DashboardOptions() { Authorization = new[] { new NeedRole(Roles.ServerAdmin) } });
app.UseMvc(routes =>
{
routes.MapRoute(
diff --git a/BTCPayServer/Views/Server/ServerNavPages.cs b/BTCPayServer/Views/Server/ServerNavPages.cs
index 9885451fa..314d00cf2 100644
--- a/BTCPayServer/Views/Server/ServerNavPages.cs
+++ b/BTCPayServer/Views/Server/ServerNavPages.cs
@@ -14,8 +14,10 @@ namespace BTCPayServer.Views.Server
public static string Users => "Users";
+ public static string Hangfire => "Hangfire";
public static string UsersNavClass(ViewContext viewContext) => PageNavClass(viewContext, Users);
+ public static string HangfireNavClass(ViewContext viewContext) => PageNavClass(viewContext, Hangfire);
public static string IndexNavClass(ViewContext viewContext) => PageNavClass(viewContext, Index);
diff --git a/BTCPayServer/Views/Server/_Nav.cshtml b/BTCPayServer/Views/Server/_Nav.cshtml
index 4bb1ea3af..600af243e 100644
--- a/BTCPayServer/Views/Server/_Nav.cshtml
+++ b/BTCPayServer/Views/Server/_Nav.cshtml
@@ -2,5 +2,6 @@