mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-08-19 21:03:17 -07:00
Generate a new security token per install Pt.1, Pt.2 = new Role System
This commit is contained in:
parent
100336b3fc
commit
910fd34445
9 changed files with 42 additions and 32 deletions
15
src/Ombi.Helpers/StartupSingleton.cs
Normal file
15
src/Ombi.Helpers/StartupSingleton.cs
Normal file
|
@ -0,0 +1,15 @@
|
|||
namespace Ombi.Helpers
|
||||
{
|
||||
public class StartupSingleton
|
||||
{
|
||||
private static StartupSingleton instance;
|
||||
|
||||
private StartupSingleton() { }
|
||||
|
||||
public static StartupSingleton Instance => instance ?? (instance = new StartupSingleton());
|
||||
|
||||
public string StoragePath { get; set; }
|
||||
|
||||
public string SecurityKey { get; set; }
|
||||
}
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
namespace Ombi.Helpers
|
||||
{
|
||||
public class StoragePathSingleton
|
||||
{
|
||||
private static StoragePathSingleton instance;
|
||||
|
||||
private StoragePathSingleton() { }
|
||||
|
||||
public static StoragePathSingleton Instance => instance ?? (instance = new StoragePathSingleton());
|
||||
|
||||
public string StoragePath { get; set; }
|
||||
}
|
||||
}
|
|
@ -18,5 +18,6 @@ namespace Ombi.Store.Entities
|
|||
StoragePath = 5,
|
||||
Notification = 6,
|
||||
BaseUrl = 7,
|
||||
SecurityToken = 8
|
||||
}
|
||||
}
|
|
@ -117,7 +117,7 @@ namespace Ombi.Controllers.V1
|
|||
public AboutViewModel About()
|
||||
{
|
||||
var dbConfiguration = DatabaseExtensions.GetDatabaseConfiguration();
|
||||
var storage = StoragePathSingleton.Instance;
|
||||
var storage = StartupSingleton.Instance;
|
||||
var model = new AboutViewModel
|
||||
{
|
||||
FrameworkDescription = RuntimeInformation.FrameworkDescription,
|
||||
|
|
|
@ -62,7 +62,7 @@ namespace Ombi.Extensions
|
|||
|
||||
public static DatabaseConfiguration GetDatabaseConfiguration()
|
||||
{
|
||||
var i = StoragePathSingleton.Instance;
|
||||
var i = StartupSingleton.Instance;
|
||||
if (string.IsNullOrEmpty(i.StoragePath))
|
||||
{
|
||||
i.StoragePath = string.Empty;
|
||||
|
|
|
@ -83,7 +83,7 @@ namespace Ombi
|
|||
var tokenValidationParameters = new TokenValidationParameters
|
||||
{
|
||||
ValidateIssuerSigningKey = true,
|
||||
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(tokenOptions.GetValue("SecretKey", string.Empty))),
|
||||
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(StartupSingleton.Instance.SecurityKey)),
|
||||
|
||||
RequireExpirationTime = true,
|
||||
ValidateLifetime = true,
|
||||
|
|
|
@ -18,7 +18,7 @@ using Ombi.Store.Context.Sqlite;
|
|||
|
||||
namespace Ombi
|
||||
{
|
||||
public class Program
|
||||
public static class Program
|
||||
{
|
||||
private static string UrlArgs { get; set; }
|
||||
|
||||
|
@ -50,13 +50,11 @@ namespace Ombi
|
|||
UrlArgs = host;
|
||||
|
||||
var urlValue = string.Empty;
|
||||
var instance = StoragePathSingleton.Instance;
|
||||
var instance = StartupSingleton.Instance;
|
||||
var demoInstance = DemoSingleton.Instance;
|
||||
demoInstance.Demo = demo;
|
||||
instance.StoragePath = storagePath ?? string.Empty;
|
||||
// Check if we need to migrate the settings
|
||||
DeleteSchedules();
|
||||
//CheckAndMigrate();
|
||||
|
||||
|
||||
var services = new ServiceCollection();
|
||||
services.ConfigureDatabases(null);
|
||||
|
@ -67,6 +65,8 @@ namespace Ombi
|
|||
var config = settingsDb.ApplicationConfigurations.ToList();
|
||||
var url = config.FirstOrDefault(x => x.Type == ConfigurationTypes.Url);
|
||||
var dbBaseUrl = config.FirstOrDefault(x => x.Type == ConfigurationTypes.BaseUrl);
|
||||
var securityToken = config.FirstOrDefault(x => x.Type == ConfigurationTypes.SecurityToken);
|
||||
CheckSecurityToken(securityToken, settingsDb, instance);
|
||||
if (url == null)
|
||||
{
|
||||
url = new ApplicationConfiguration
|
||||
|
@ -136,18 +136,25 @@ namespace Ombi
|
|||
}
|
||||
}
|
||||
|
||||
private static void DeleteSchedules()
|
||||
private static void CheckSecurityToken(ApplicationConfiguration securityToken, SettingsContext ctx, StartupSingleton instance)
|
||||
{
|
||||
try
|
||||
if (securityToken == null || string.IsNullOrEmpty(securityToken.Value))
|
||||
{
|
||||
if (File.Exists("Schedules.db"))
|
||||
securityToken = new ApplicationConfiguration
|
||||
{
|
||||
File.Delete("Schedules.db");
|
||||
Type = ConfigurationTypes.SecurityToken,
|
||||
Value = Guid.NewGuid().ToString("N")
|
||||
};
|
||||
|
||||
using (var tran = ctx.Database.BeginTransaction())
|
||||
{
|
||||
ctx.ApplicationConfigurations.Add(securityToken);
|
||||
ctx.SaveChanges();
|
||||
tran.Commit();
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
|
||||
instance.SecurityKey = securityToken.Value;
|
||||
}
|
||||
|
||||
public static IHostBuilder CreateHostBuilder(string[] args) =>
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
},
|
||||
"Ombi": {
|
||||
"commandName": "Project",
|
||||
"commandLineArgs": "--host http://localhost:3577 --baseurl /ombi",
|
||||
"commandLineArgs": "--host http://localhost:3577 ",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
},
|
||||
|
|
|
@ -35,7 +35,7 @@ namespace Ombi
|
|||
{
|
||||
public class Startup
|
||||
{
|
||||
public static StoragePathSingleton StoragePath => StoragePathSingleton.Instance;
|
||||
public static StartupSingleton StoragePath => StartupSingleton.Instance;
|
||||
|
||||
public Startup(IWebHostEnvironment env)
|
||||
{
|
||||
|
@ -164,7 +164,7 @@ namespace Ombi
|
|||
var baseUrl = appConfig.Get(ConfigurationTypes.BaseUrl);
|
||||
if (baseUrl != null)
|
||||
{
|
||||
if (baseUrl.Value.HasValue() && settings.BaseUrl != baseUrl.Value)
|
||||
if (baseUrl.Value.HasValue())
|
||||
{
|
||||
settings.BaseUrl = baseUrl.Value;
|
||||
ombiService.SaveSettings(settings);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue