summaryrefslogtreecommitdiffstats
path: root/src/main.lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.lib')
-rw-r--r--src/main.lib/Services/Interfaces/ISettingsService.cs23
-rw-r--r--src/main.lib/Services/Legacy/LegacySettingsService.cs5
-rw-r--r--src/main.lib/Services/LogService.cs2
-rw-r--r--src/main.lib/Services/PluginService.cs2
-rw-r--r--src/main.lib/Services/SettingsService.cs3
-rw-r--r--src/main.lib/Services/TaskSchedulerService.cs26
6 files changed, 35 insertions, 26 deletions
diff --git a/src/main.lib/Services/Interfaces/ISettingsService.cs b/src/main.lib/Services/Interfaces/ISettingsService.cs
index a3d0fcc..dfdad4c 100644
--- a/src/main.lib/Services/Interfaces/ISettingsService.cs
+++ b/src/main.lib/Services/Interfaces/ISettingsService.cs
@@ -4,17 +4,18 @@ using static PKISharp.WACS.Services.SettingsService;
namespace PKISharp.WACS.Services
{
public interface ISettingsService
- {
+ {
+ string ExePath { get; }
Uri BaseUri { get; }
- public UiSettings UI { get; }
- public AcmeSettings Acme { get; }
- public ProxySettings Proxy { get; }
- public CacheSettings Cache { get; }
- public ScheduledTaskSettings ScheduledTask { get; }
- public NotificationSettings Notification { get; }
- public SecuritySettings Security { get; }
- public ClientSettings Client { get; }
- public ValidationSettings Validation { get; }
- public StoreSettings Store { get; }
+ UiSettings UI { get; }
+ AcmeSettings Acme { get; }
+ ProxySettings Proxy { get; }
+ CacheSettings Cache { get; }
+ ScheduledTaskSettings ScheduledTask { get; }
+ NotificationSettings Notification { get; }
+ SecuritySettings Security { get; }
+ ClientSettings Client { get; }
+ ValidationSettings Validation { get; }
+ StoreSettings Store { get; }
}
}
diff --git a/src/main.lib/Services/Legacy/LegacySettingsService.cs b/src/main.lib/Services/Legacy/LegacySettingsService.cs
index 6cdfca5..6718882 100644
--- a/src/main.lib/Services/Legacy/LegacySettingsService.cs
+++ b/src/main.lib/Services/Legacy/LegacySettingsService.cs
@@ -26,7 +26,7 @@ namespace PKISharp.WACS.Host.Services.Legacy
public ClientSettings Client { get; private set; }
public ValidationSettings Validation { get; private set; }
public StoreSettings Store { get; private set; }
-
+ public string ExePath { get; private set; }
public LegacySettingsService(ILogService log, MainArguments main, ISettingsService settings)
{
_log = log;
@@ -39,6 +39,7 @@ namespace PKISharp.WACS.Host.Services.Legacy
Client = settings.Client;
Validation = settings.Validation;
Store = settings.Store;
+ ExePath = settings.ExePath;
_clientNames = new List<string>() {
settings.Client.ClientName,
@@ -47,7 +48,7 @@ namespace PKISharp.WACS.Host.Services.Legacy
};
// Read legacy configuration file
- var installDir = new FileInfo(Process.GetCurrentProcess().MainModule.FileName).DirectoryName;
+ var installDir = new FileInfo(ExePath).DirectoryName;
var legacyConfig = new FileInfo(Path.Combine(installDir, "settings.config"));
var userRoot = default(string);
if (legacyConfig.Exists)
diff --git a/src/main.lib/Services/LogService.cs b/src/main.lib/Services/LogService.cs
index 4691cb0..84404f8 100644
--- a/src/main.lib/Services/LogService.cs
+++ b/src/main.lib/Services/LogService.cs
@@ -21,7 +21,7 @@ namespace PKISharp.WACS.Services
public LogService()
{
// Custom configuration support
- var installDir = new FileInfo(Process.GetCurrentProcess().MainModule.FileName).DirectoryName;
+ var installDir = new FileInfo(ExePath).DirectoryName;
ConfigurationRoot = new ConfigurationBuilder()
.AddJsonFile(Path.Combine(installDir, "serilog.json"), true, true)
.Build();
diff --git a/src/main.lib/Services/PluginService.cs b/src/main.lib/Services/PluginService.cs
index 0ebe54c..62cc0c8 100644
--- a/src/main.lib/Services/PluginService.cs
+++ b/src/main.lib/Services/PluginService.cs
@@ -179,7 +179,7 @@ namespace PKISharp.WACS.Services
scanned.Add(assembly);
}
- var installDir = new FileInfo(Process.GetCurrentProcess().MainModule.FileName).Directory;
+ var installDir = new FileInfo(ExePath).Directory;
var dllFiles = installDir.GetFiles("*.dll", SearchOption.AllDirectories);
#if PLUGGABLE
var allAssemblies = new List<Assembly>();
diff --git a/src/main.lib/Services/SettingsService.cs b/src/main.lib/Services/SettingsService.cs
index 11b57f0..400d42b 100644
--- a/src/main.lib/Services/SettingsService.cs
+++ b/src/main.lib/Services/SettingsService.cs
@@ -24,13 +24,14 @@ namespace PKISharp.WACS.Services
public SecuritySettings Security { get; private set; } = new SecuritySettings();
public ValidationSettings Validation { get; private set; } = new ValidationSettings();
public StoreSettings Store { get; private set; } = new StoreSettings();
+ public string ExePath { get; private set; } = Process.GetCurrentProcess().MainModule.FileName;
public SettingsService(ILogService log, IArgumentsService arguments)
{
_log = log;
_arguments = arguments;
- var installDir = new FileInfo(Process.GetCurrentProcess().MainModule.FileName).DirectoryName;
+ var installDir = new FileInfo(ExePath).DirectoryName;
_log.Verbose($"Looking for settings.json in {installDir}");
var settings = new FileInfo(Path.Combine(installDir, "settings.json"));
var settingsTemplate = new FileInfo(Path.Combine(installDir, "settings_default.json"));
diff --git a/src/main.lib/Services/TaskSchedulerService.cs b/src/main.lib/Services/TaskSchedulerService.cs
index 069d0a0..b17bd8c 100644
--- a/src/main.lib/Services/TaskSchedulerService.cs
+++ b/src/main.lib/Services/TaskSchedulerService.cs
@@ -2,8 +2,8 @@
using PKISharp.WACS.Configuration;
using PKISharp.WACS.Extensions;
using System;
+using System.IO;
using System.Linq;
-using System.Reflection;
using System.Runtime.InteropServices;
namespace PKISharp.WACS.Services
@@ -27,12 +27,8 @@ namespace PKISharp.WACS.Services
_log = log;
}
private string TaskName(string clientName) => $"{clientName} renew ({_settings.BaseUri.ToString().CleanBaseUri()})";
-
- private string Path => Assembly.GetEntryAssembly().Location;
-
- private string WorkingDirectory => System.IO.Path.GetDirectoryName(Path);
-
- private string ExecutingFile => System.IO.Path.GetFileName(Path);
+ private string WorkingDirectory => Path.GetDirectoryName(_settings.ExePath);
+ private string ExecutingFile => Path.GetFileName(_settings.ExePath);
private Task ExistingTask
{
@@ -68,8 +64,18 @@ namespace PKISharp.WACS.Services
private bool IsHealthy(Task task)
{
var healthy = true;
- healthy = healthy && task.Definition.Actions.OfType<ExecAction>().Any(action => action.Path == Path && action.WorkingDirectory == WorkingDirectory);
- healthy = healthy && task.Enabled;
+ if (!task.Definition.Actions.OfType<ExecAction>().Any(action =>
+ action.Path == _settings.ExePath &&
+ action.WorkingDirectory == WorkingDirectory))
+ {
+ healthy = false;
+ _log.Warning("Scheduled task points to different location");
+ }
+ if (!task.Enabled)
+ {
+ healthy = false;
+ _log.Warning("Scheduled task is disabled");
+ }
if (healthy)
{
_log.Information("Scheduled task looks healthy");
@@ -146,7 +152,7 @@ namespace PKISharp.WACS.Services
task.Settings.StartWhenAvailable = true;
// Create an action that will launch the app with the renew parameters whenever the trigger fires
- task.Actions.Add(new ExecAction(Path, actionString, WorkingDirectory));
+ task.Actions.Add(new ExecAction(_settings.ExePath, actionString, WorkingDirectory));
task.Principal.RunLevel = TaskRunLevel.Highest;
while (true)