2 Commits

17 changed files with 688 additions and 119 deletions

View File

@@ -0,0 +1,9 @@
{
"permissions": {
"allow": [
"Bash(dotnet build:*)"
],
"deny": [],
"ask": []
}
}

View File

@@ -1,32 +1,46 @@
<!-- <!--
This file allow for customizing your build process. This file allows for customizing your build process.
See: https://learn.microsoft.com/visualstudio/msbuild/customize-your-build See: https://learn.microsoft.com/visualstudio/msbuild/customize-your-build
--> -->
<Project> <Project>
<!--
Uncomment if you need to enable inclusion of another Directory.Build.props file from a parent directory
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))" />
-->
<PropertyGroup> <PropertyGroup>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<LangVersion>12</LangVersion> <LangVersion>12</LangVersion>
<AccelerateBuildsInVisualStudio>true</AccelerateBuildsInVisualStudio> <AccelerateBuildsInVisualStudio>true</AccelerateBuildsInVisualStudio>
<!--
If you you like to see source generated files saved to disk you can enable the following:
https://learn.microsoft.com/dotnet/csharp/roslyn-sdk/source-generators-overview?WT.mc_id=DT-MVP-5003472
-->
<!--<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>--> <!--<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>-->
</PropertyGroup> </PropertyGroup>
<!--
This allows all projects to share the same user secrets file.
If you want project to have their own, set it to a different GUID on each project.
See: https://learn.microsoft.com/dotnet/architecture/microservices/secure-net-microservices-web-applications/developer-app-secrets-storage
-->
<PropertyGroup Label="User Secrets"> <PropertyGroup Label="User Secrets">
<UserSecretsId>1ef91ee6-7b55-474e-ab2b-2d164b723a56</UserSecretsId> <UserSecretsId>1ef91ee6-7b55-474e-ab2b-2d164b723a56</UserSecretsId>
</PropertyGroup> </PropertyGroup>
<!-- 🔹 Automatically derive version from latest Git tag -->
<Target Name="GetVersionFromGit" BeforeTargets="GetAssemblyVersion">
<!-- Get the most recent tag (like v1.1.1) -->
<Exec Command="git describe --tags --abbrev=0" ConsoleToMSBuild="true" IgnoreExitCode="true">
<Output TaskParameter="ConsoleOutput" PropertyName="GitTag" />
</Exec>
<!-- Strip leading 'v' if present -->
<PropertyGroup>
<GitVersion>$([System.Text.RegularExpressions.Regex]::Replace('$(GitTag)', '^v', ''))</GitVersion>
</PropertyGroup>
<!-- Fallback if no tags exist yet -->
<PropertyGroup Condition="'$(GitVersion)' == ''">
<GitVersion>0.0.0</GitVersion>
</PropertyGroup>
<!-- Apply to assembly and file versions -->
<Message Text="🔖 Using version: $(GitVersion)" Importance="High" />
<PropertyGroup>
<Version>$(GitVersion)</Version>
<FileVersion>$(GitVersion)</FileVersion>
<AssemblyVersion>$(GitVersion)</AssemblyVersion>
</PropertyGroup>
</Target>
</Project> </Project>

View File

@@ -12,6 +12,17 @@
<OutputPath>C:\Users\Sonder\source\repos\psg-oversight-app\BuildDir\bin\Debug\net8.0-windows\</OutputPath> <OutputPath>C:\Users\Sonder\source\repos\psg-oversight-app\BuildDir\bin\Debug\net8.0-windows\</OutputPath>
<IncludeSatelliteAssembliesForPublish>false</IncludeSatelliteAssembliesForPublish> <IncludeSatelliteAssembliesForPublish>false</IncludeSatelliteAssembliesForPublish>
<!-- 🔢 Version Info -->
<AssemblyVersion>1.0.0.0</AssemblyVersion>
<FileVersion>1.0.3.0</FileVersion>
<Version>1.0.3</Version>
<!-- ✅ Enables source metadata and Git info -->
<Deterministic>true</Deterministic>
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
<RepositoryUrl>https://gitea.psg.net.au/your-repo</RepositoryUrl>
<IncludeSourceRevisionInInformationalVersion>true</IncludeSourceRevisionInInformationalVersion>
</PropertyGroup> </PropertyGroup>
<!-- <!--

View File

@@ -172,33 +172,41 @@
</Grid.RowDefinitions> </Grid.RowDefinitions>
<!-- 🔹 Titlebar --> <!-- 🔹 Titlebar -->
<Border Grid.Row="0" <Border Grid.Row="0"
CornerRadius="12,12,0,0" CornerRadius="12,12,0,0"
Background="{DynamicResource BackgroundDarkBrush}"
Margin="0,0,2,2">
<Grid MouseDown="TitleBar_MouseDown">
<StackPanel Orientation="Horizontal" VerticalAlignment="Center" Margin="10,0,0,0">
<TextBlock Text="PSG - Oversight"
FontSize="22"
FontWeight="Bold"
Foreground="{DynamicResource TitleBrush}" />
<TextBlock x:Name="VersionTextBlock"
Text="v0.0.0"
FontSize="12"
VerticalAlignment="Bottom"
Margin="8,0,0,3"
Foreground="{DynamicResource TitleBrush}"
Opacity="0.7" />
</StackPanel>
Background="{DynamicResource BackgroundDarkBrush}" Margin="0,0,2,2"> <StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
<Grid MouseDown="TitleBar_MouseDown"> <Button Width="30" Height="30" Click="MinimizeWindow_Click" Style="{StaticResource WindowButtonStyle}">
<TextBlock Text="PSG - Oversight" <materialDesign:PackIcon Kind="WindowMinimize" Width="20" Height="20" />
VerticalAlignment="Center" </Button>
Margin="10,0,0,0" <Button Width="30" Height="30" Click="MaximizeRestoreWindow_Click" Style="{StaticResource WindowButtonStyle}">
FontSize="22" <materialDesign:PackIcon Kind="WindowMaximize" Width="20" Height="20" />
FontWeight="Bold" </Button>
Foreground="{DynamicResource TitleBrush}"/>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
<Button Width="30" Height="30" Click="MinimizeWindow_Click" Style="{StaticResource WindowButtonStyle}">
<materialDesign:PackIcon Kind="WindowMinimize" Width="20" Height="20" />
</Button>
<Button Width="30" Height="30" Click="MaximizeRestoreWindow_Click" Style="{StaticResource WindowButtonStyle}">
<materialDesign:PackIcon Kind="WindowMaximize" Width="20" Height="20" />
</Button>
<Button Width="30" Height="30" Click="CloseWindow_Click" Style="{StaticResource CloseButtonStyle}"> <Button Width="30" Height="30" Click="CloseWindow_Click" Style="{StaticResource CloseButtonStyle}">
<materialDesign:PackIcon Kind="WindowClose" Width="20" Height="20" /> <materialDesign:PackIcon Kind="WindowClose" Width="20" Height="20" />
</Button> </Button>
</StackPanel> </StackPanel>
</Grid> </Grid>
</Border> </Border>
<!-- 🔹 Tabs + Theme Toggle -->
<!-- 🔹 Tabs + Theme Toggle -->
<Grid Grid.Row="1" Background="{DynamicResource BackgroundDarkBrush}"> <Grid Grid.Row="1" Background="{DynamicResource BackgroundDarkBrush}">
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="10*" /> <ColumnDefinition Width="10*" />

View File

@@ -1,24 +1,33 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Net.Http; using System.Net.Http;
using System.Reflection;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows; using System.Windows;
using Microsoft.Win32;
using System.IO;
using System.Windows.Threading;
using System.Windows.Forms; using System.Windows.Forms;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Threading;
using Hardcodet.Wpf.TaskbarNotification; using Hardcodet.Wpf.TaskbarNotification;
using LD_SysInfo.Models;
using LD_SysInfo.Services; using LD_SysInfo.Services;
using MaterialDesignColors;
using MaterialDesignThemes.Wpf;
using Microsoft.Win32;
using Newtonsoft.Json; using Newtonsoft.Json;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using System.Windows.Media.Animation;
using LD_SysInfo.Models;
using MaterialDesignColors;
using MaterialDesignThemes.Wpf;
using System.Windows.Input;
using Application = System.Windows.Application; using Application = System.Windows.Application;
using System.Windows.Media;
@@ -34,6 +43,7 @@ namespace LD_SysInfo
private readonly DispatcherTimer messageClearTimer; private readonly DispatcherTimer messageClearTimer;
private readonly DispatcherTimer postTimer; private readonly DispatcherTimer postTimer;
private readonly DispatcherTimer keepAliveTimer; private readonly DispatcherTimer keepAliveTimer;
private readonly DispatcherTimer tokenRefreshTimer;
private readonly Uri LightThemeUri = new Uri("pack://application:,,,/Themes/LightTheme.xaml", UriKind.Absolute); private readonly Uri LightThemeUri = new Uri("pack://application:,,,/Themes/LightTheme.xaml", UriKind.Absolute);
private readonly Uri DarkThemeUri = new Uri("pack://application:,,,/Themes/DarkTheme.xaml", UriKind.Absolute); private readonly Uri DarkThemeUri = new Uri("pack://application:,,,/Themes/DarkTheme.xaml", UriKind.Absolute);
private bool isDarkTheme = false; private bool isDarkTheme = false;
@@ -47,6 +57,24 @@ namespace LD_SysInfo
System.Net.ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true; System.Net.ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;
InitializeComponent(); InitializeComponent();
var exePath = Assembly.GetEntryAssembly()?.Location;
if (string.IsNullOrEmpty(exePath))
{
exePath = Process.GetCurrentProcess().MainModule?.FileName;
}
if (!string.IsNullOrEmpty(exePath))
{
var fvi = FileVersionInfo.GetVersionInfo(exePath);
var productVersion = fvi.ProductVersion ?? "0.0.0";
var cleanVersion = productVersion.Split('+')[0];
VersionTextBlock.Text = $"v{cleanVersion}";
}
else
{
VersionTextBlock.Text = "v0.0.0";
}
LoadConfig(); LoadConfig();
DisplaySystemInfo(); DisplaySystemInfo();
AutoLogin(); AutoLogin();
@@ -74,7 +102,12 @@ namespace LD_SysInfo
keepAliveTimer.Tick += KeepAliveTimer_Tick; keepAliveTimer.Tick += KeepAliveTimer_Tick;
keepAliveTimer.Start(); keepAliveTimer.Start();
// 🔄 Initialize the Token Refresh timer to refresh token proactively before expiration
// Tokens expire in 60 minutes, so refresh at 50 minutes to be safe
tokenRefreshTimer = new DispatcherTimer();
tokenRefreshTimer.Interval = TimeSpan.FromMinutes(50);
tokenRefreshTimer.Tick += TokenRefreshTimer_Tick;
tokenRefreshTimer.Start();
} }
@@ -252,6 +285,41 @@ namespace LD_SysInfo
}); });
} }
var formattedUserApplications = new List<object>();
foreach (var app in sysInfo.UserInstalledApplications)
{
formattedUserApplications.Add(new
{
app_name = app.Name,
app_version = app.Version,
publisher = app.Publisher
});
}
var formattedWindowsUpdates = new List<object>();
foreach (var update in sysInfo.WindowsUpdates)
{
formattedWindowsUpdates.Add(new
{
hotFixID = update.HotFixID,
description = update.Description,
installedOn = update.InstalledOn,
installedBy = update.InstalledBy
});
}
var formattedAppXPackages = new List<object>();
foreach (var pkg in sysInfo.AppXPackages)
{
formattedAppXPackages.Add(new
{
name = pkg.Name,
version = pkg.Version,
publisher = pkg.Publisher,
packageFullName = pkg.PackageFullName
});
}
var payload = new var payload = new
{ {
clientIdentifier = _config.ClientIdentifier, clientIdentifier = _config.ClientIdentifier,
@@ -268,7 +336,10 @@ namespace LD_SysInfo
ipAddresses = sysInfo.IpAddresses, ipAddresses = sysInfo.IpAddresses,
lastBootTime = sysInfo.LastBootTime, lastBootTime = sysInfo.LastBootTime,
drives = sysInfo.Drives, drives = sysInfo.Drives,
installedApplications = formattedApplications installedApplications = formattedApplications,
userInstalledApplications = formattedUserApplications,
windowsUpdates = formattedWindowsUpdates,
appXPackages = formattedAppXPackages
}; };
@@ -519,6 +590,41 @@ namespace LD_SysInfo
}); });
} }
var formattedUserApplications = new List<object>();
foreach (var app in sysInfo.UserInstalledApplications)
{
formattedUserApplications.Add(new
{
app_name = app.Name,
app_version = app.Version,
publisher = app.Publisher
});
}
var formattedWindowsUpdates = new List<object>();
foreach (var update in sysInfo.WindowsUpdates)
{
formattedWindowsUpdates.Add(new
{
hotFixID = update.HotFixID,
description = update.Description,
installedOn = update.InstalledOn,
installedBy = update.InstalledBy
});
}
var formattedAppXPackages = new List<object>();
foreach (var pkg in sysInfo.AppXPackages)
{
formattedAppXPackages.Add(new
{
name = pkg.Name,
version = pkg.Version,
publisher = pkg.Publisher,
packageFullName = pkg.PackageFullName
});
}
var payload = new var payload = new
{ {
clientIdentifier = _config.ClientIdentifier, clientIdentifier = _config.ClientIdentifier,
@@ -535,7 +641,10 @@ namespace LD_SysInfo
ipAddresses = sysInfo.IpAddresses, ipAddresses = sysInfo.IpAddresses,
lastBootTime = sysInfo.LastBootTime, lastBootTime = sysInfo.LastBootTime,
drives = sysInfo.Drives, drives = sysInfo.Drives,
installedApplications = formattedApplications installedApplications = formattedApplications,
userInstalledApplications = formattedUserApplications,
windowsUpdates = formattedWindowsUpdates,
appXPackages = formattedAppXPackages
}; };
@@ -590,6 +699,27 @@ namespace LD_SysInfo
FadeOutStatusMessage(); // Trigger the fade-out effect FadeOutStatusMessage(); // Trigger the fade-out effect
} }
private async void TokenRefreshTimer_Tick(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(ApiClient.GetJwtToken()))
{
Console.WriteLine("⚠️ No token to refresh - skipping proactive refresh.");
return;
}
var apiClient = new ApiClient(_config);
bool refreshed = await apiClient.RefreshTokenAsync();
if (refreshed)
{
Console.WriteLine("✅ Proactive token refresh successful.");
}
else
{
Console.WriteLine("⚠️ Proactive token refresh failed - will retry on next request.");
}
}
private void TrayIcon_DoubleClick(object sender, RoutedEventArgs e) private void TrayIcon_DoubleClick(object sender, RoutedEventArgs e)
{ {
ShowWindow(); ShowWindow();

View File

@@ -177,7 +177,54 @@ namespace LD_SysInfo.Services
/// <summary> /// <summary>
/// Sends the collected data to the server. /// Refreshes the current JWT token without requiring username/password.
/// </summary>
public async Task<bool> RefreshTokenAsync()
{
try
{
if (string.IsNullOrEmpty(jwtToken))
{
Console.WriteLine("⚠️ No token to refresh.");
return false;
}
HttpResponseMessage response = await httpClient.PostAsync(BuildUrl("/api/auth/refresh"), null);
string rawResponse = await response.Content.ReadAsStringAsync();
if (!response.IsSuccessStatusCode)
{
Console.WriteLine($"❌ Token refresh failed: {response.StatusCode} - {rawResponse}");
return false;
}
// Parse the response to get the new token if provided in body
// Note: Your server sets it via cookie, but may also return it in response
try
{
var refreshResponse = JsonConvert.DeserializeObject<Dictionary<string, string>>(rawResponse);
if (refreshResponse?.ContainsKey("token") == true)
{
SetJwtToken(refreshResponse["token"]);
}
}
catch
{
// Token might only be in cookie, which is fine
}
Console.WriteLine("✅ Token refreshed successfully.");
return true;
}
catch (Exception ex)
{
Console.WriteLine($"❌ Exception during token refresh: {ex.Message}");
return false;
}
}
/// <summary>
/// Sends the collected data to the server with automatic token refresh and re-auth.
/// </summary> /// </summary>
private async Task<HttpResponseMessage> SendWithAutoReauthAsync(Func<Task<HttpResponseMessage>> requestFunc) private async Task<HttpResponseMessage> SendWithAutoReauthAsync(Func<Task<HttpResponseMessage>> requestFunc)
{ {
@@ -185,8 +232,24 @@ namespace LD_SysInfo.Services
if (response.StatusCode == System.Net.HttpStatusCode.Unauthorized) if (response.StatusCode == System.Net.HttpStatusCode.Unauthorized)
{ {
Console.WriteLine("⚠️ Token expired or invalid. Attempting re-auth..."); Console.WriteLine("⚠️ Token expired or invalid. Attempting token refresh...");
// Try refreshing the token first (faster than full re-auth)
bool refreshed = await RefreshTokenAsync();
if (refreshed)
{
// Retry original request after refresh
response = await requestFunc();
if (response.IsSuccessStatusCode)
{
return response;
}
}
// If refresh failed or didn't work, fall back to full re-authentication
Console.WriteLine("⚠️ Token refresh failed. Attempting full re-auth...");
var loginResponse = await AuthenticateAsync(_config.Auth.Username, _config.Auth.Password); var loginResponse = await AuthenticateAsync(_config.Auth.Username, _config.Auth.Password);
if (loginResponse == null || string.IsNullOrEmpty(loginResponse.Token)) if (loginResponse == null || string.IsNullOrEmpty(loginResponse.Token))
{ {

View File

@@ -68,6 +68,36 @@ namespace LD_SysInfo
public string Publisher { get; set; } public string Publisher { get; set; }
} }
public class WindowsUpdate
{
[JsonProperty("hotFixID")]
public string HotFixID { get; set; }
[JsonProperty("description")]
public string Description { get; set; }
[JsonProperty("installedOn")]
public string InstalledOn { get; set; }
[JsonProperty("installedBy")]
public string InstalledBy { get; set; }
}
public class AppXPackage
{
[JsonProperty("name")]
public string Name { get; set; }
[JsonProperty("version")]
public string Version { get; set; }
[JsonProperty("publisher")]
public string Publisher { get; set; }
[JsonProperty("packageFullName")]
public string PackageFullName { get; set; }
}
public class DriveInfoSummary public class DriveInfoSummary
{ {
[JsonProperty("name")] [JsonProperty("name")]
@@ -134,9 +164,21 @@ namespace LD_SysInfo
[JsonProperty("lastBootTime")] [JsonProperty("lastBootTime")]
public string LastBootTime { get; set; } public string LastBootTime { get; set; }
[JsonProperty("collectedAt")]
public string CollectedAt { get; set; }
[JsonProperty("installedApplications")] [JsonProperty("installedApplications")]
public List<InstalledApplication> InstalledApplications { get; set; } public List<InstalledApplication> InstalledApplications { get; set; }
[JsonProperty("userInstalledApplications")]
public List<InstalledApplication> UserInstalledApplications { get; set; } = new();
[JsonProperty("windowsUpdates")]
public List<WindowsUpdate> WindowsUpdates { get; set; } = new();
[JsonProperty("appXPackages")]
public List<AppXPackage> AppXPackages { get; set; } = new();
[JsonProperty("drives")] [JsonProperty("drives")]
public List<DriveInfoSummary> Drives { get; set; } = new(); public List<DriveInfoSummary> Drives { get; set; } = new();
@@ -149,6 +191,9 @@ namespace LD_SysInfo
try try
{ {
// Capture collection timestamp with timezone info
sysInfo.CollectedAt = DateTimeOffset.Now.ToString("o");
sysInfo.Hostname = Environment.MachineName; sysInfo.Hostname = Environment.MachineName;
sysInfo.OSName = GetOSFriendlyName(); sysInfo.OSName = GetOSFriendlyName();
sysInfo.OSVersion = Environment.OSVersion.Version.ToString(); sysInfo.OSVersion = Environment.OSVersion.Version.ToString();
@@ -166,6 +211,11 @@ namespace LD_SysInfo
sysInfo.LastBootTime = GetLastBootTime(); sysInfo.LastBootTime = GetLastBootTime();
PopulateDriveInfo(sysInfo); PopulateDriveInfo(sysInfo);
// Populate new collections for comprehensive system information
sysInfo.UserInstalledApplications = GetUserInstalledApplications();
sysInfo.WindowsUpdates = GetInstalledPatches();
sysInfo.AppXPackages = GetAppXPackages();
} }
catch (Exception ex) catch (Exception ex)
{ {
@@ -303,7 +353,11 @@ namespace LD_SysInfo
foreach (var obj in searcher.Get()) foreach (var obj in searcher.Get())
{ {
string lastBoot = obj["LastBootUpTime"]?.ToString(); string lastBoot = obj["LastBootUpTime"]?.ToString();
return ManagementDateTimeConverter.ToDateTime(lastBoot).ToString("o"); // Convert to local time and ensure timezone info is preserved
DateTime localBootTime = ManagementDateTimeConverter.ToDateTime(lastBoot);
// Use DateTimeOffset to ensure timezone information is included
DateTimeOffset bootTimeWithZone = new DateTimeOffset(localBootTime, TimeZoneInfo.Local.GetUtcOffset(localBootTime));
return bootTimeWithZone.ToString("o");
} }
} }
catch { } catch { }
@@ -341,5 +395,138 @@ namespace LD_SysInfo
return applications; return applications;
} }
/// <summary>
/// Gets user-context installed applications from HKEY_CURRENT_USER registry.
/// </summary>
public static List<InstalledApplication> GetUserInstalledApplications()
{
var applications = new List<InstalledApplication>();
string registryKey = @"Software\Microsoft\Windows\CurrentVersion\Uninstall";
try
{
using var regKey = Registry.CurrentUser.OpenSubKey(registryKey);
if (regKey == null) return applications;
foreach (string subKeyName in regKey.GetSubKeyNames())
{
using var subKey = regKey.OpenSubKey(subKeyName);
string name = subKey?.GetValue("DisplayName")?.ToString();
if (!string.IsNullOrWhiteSpace(name))
{
applications.Add(new InstalledApplication
{
Name = name,
Version = subKey?.GetValue("DisplayVersion")?.ToString(),
Publisher = subKey?.GetValue("Publisher")?.ToString()
});
}
}
}
catch (Exception ex)
{
Console.WriteLine($"❌ Failed to gather user-installed applications: {ex.Message}");
}
return applications;
}
/// <summary>
/// Gets Windows Updates and patches installed on the system using WMI.
/// </summary>
public static List<WindowsUpdate> GetInstalledPatches()
{
var patches = new List<WindowsUpdate>();
try
{
using var searcher = new ManagementObjectSearcher(
"SELECT HotFixID, Description, InstalledOn, InstalledBy FROM Win32_QuickFixEngineering");
foreach (var obj in searcher.Get())
{
patches.Add(new WindowsUpdate
{
HotFixID = obj["HotFixID"]?.ToString(),
Description = obj["Description"]?.ToString(),
InstalledOn = obj["InstalledOn"]?.ToString(),
InstalledBy = obj["InstalledBy"]?.ToString()
});
}
}
catch (Exception ex)
{
Console.WriteLine($"❌ Failed to gather Windows Updates: {ex.Message}");
}
return patches;
}
/// <summary>
/// Gets Windows Store (AppX) packages installed on the system using WMI.
/// Note: This may require elevated permissions for complete results.
/// </summary>
public static List<AppXPackage> GetAppXPackages()
{
var packages = new List<AppXPackage>();
try
{
// Try using Win32_InstalledStoreProgram (Windows 10+)
using var searcher = new ManagementObjectSearcher(
"SELECT Name, Version, Publisher FROM Win32_InstalledStoreProgram");
foreach (var obj in searcher.Get())
{
var name = obj["Name"]?.ToString();
if (!string.IsNullOrWhiteSpace(name))
{
packages.Add(new AppXPackage
{
Name = name,
Version = obj["Version"]?.ToString(),
Publisher = obj["Publisher"]?.ToString(),
PackageFullName = name // Win32_InstalledStoreProgram doesn't provide PackageFullName
});
}
}
}
catch (Exception ex)
{
Console.WriteLine($"❌ Failed to gather AppX packages: {ex.Message}");
}
return packages;
}
/// <summary>
/// Checks if a specific Windows Update patch is installed on the system.
/// </summary>
/// <param name="kbNumber">The KB number to check (e.g., "KB5034441")</param>
/// <returns>True if the patch is installed, false otherwise</returns>
public static bool IsPatchInstalled(string kbNumber)
{
if (string.IsNullOrWhiteSpace(kbNumber))
return false;
try
{
// Normalize KB number format
string normalizedKB = kbNumber.ToUpper().Trim();
if (!normalizedKB.StartsWith("KB"))
normalizedKB = "KB" + normalizedKB;
using var searcher = new ManagementObjectSearcher(
$"SELECT HotFixID FROM Win32_QuickFixEngineering WHERE HotFixID = '{normalizedKB}'");
return searcher.Get().Count > 0;
}
catch (Exception ex)
{
Console.WriteLine($"❌ Failed to check patch {kbNumber}: {ex.Message}");
return false;
}
}
} }
} }

View File

@@ -1,5 +1,5 @@
{ {
"ServerUrl": "https://sys.psg.net.au:8443", "ServerUrl": "https://sys.psg.net.au:11443",
"EnableLogging": true, "EnableLogging": true,
"KeepAlivePeriod": 30, "KeepAlivePeriod": 30,
"SystemInfoInterval": 600, "SystemInfoInterval": 600,

View File

@@ -28,6 +28,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LD_SysInfo", "LD-SysInfo\LD
EndProject EndProject
Project("{B7DD6F7E-DEF8-4E67-B5B7-07EF123DB6F0}") = "OversightInstaller", "OversightInstaller\OversightInstaller.wixproj", "{99BFBED9-D563-375C-FBD6-E11D0770B009}" Project("{B7DD6F7E-DEF8-4E67-B5B7-07EF123DB6F0}") = "OversightInstaller", "OversightInstaller\OversightInstaller.wixproj", "{99BFBED9-D563-375C-FBD6-E11D0770B009}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OversightService", "OversightService\OversightService.csproj", "{A8149609-CF69-4268-B985-B68444319344}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
@@ -72,6 +74,22 @@ Global
{99BFBED9-D563-375C-FBD6-E11D0770B009}.Release|x64.Build.0 = Release|x64 {99BFBED9-D563-375C-FBD6-E11D0770B009}.Release|x64.Build.0 = Release|x64
{99BFBED9-D563-375C-FBD6-E11D0770B009}.Release|x86.ActiveCfg = Release|x86 {99BFBED9-D563-375C-FBD6-E11D0770B009}.Release|x86.ActiveCfg = Release|x86
{99BFBED9-D563-375C-FBD6-E11D0770B009}.Release|x86.Build.0 = Release|x86 {99BFBED9-D563-375C-FBD6-E11D0770B009}.Release|x86.Build.0 = Release|x86
{A8149609-CF69-4268-B985-B68444319344}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A8149609-CF69-4268-B985-B68444319344}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A8149609-CF69-4268-B985-B68444319344}.Debug|ARM64.ActiveCfg = Debug|Any CPU
{A8149609-CF69-4268-B985-B68444319344}.Debug|ARM64.Build.0 = Debug|Any CPU
{A8149609-CF69-4268-B985-B68444319344}.Debug|x64.ActiveCfg = Debug|Any CPU
{A8149609-CF69-4268-B985-B68444319344}.Debug|x64.Build.0 = Debug|Any CPU
{A8149609-CF69-4268-B985-B68444319344}.Debug|x86.ActiveCfg = Debug|Any CPU
{A8149609-CF69-4268-B985-B68444319344}.Debug|x86.Build.0 = Debug|Any CPU
{A8149609-CF69-4268-B985-B68444319344}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A8149609-CF69-4268-B985-B68444319344}.Release|Any CPU.Build.0 = Release|Any CPU
{A8149609-CF69-4268-B985-B68444319344}.Release|ARM64.ActiveCfg = Release|Any CPU
{A8149609-CF69-4268-B985-B68444319344}.Release|ARM64.Build.0 = Release|Any CPU
{A8149609-CF69-4268-B985-B68444319344}.Release|x64.ActiveCfg = Release|Any CPU
{A8149609-CF69-4268-B985-B68444319344}.Release|x64.Build.0 = Release|Any CPU
{A8149609-CF69-4268-B985-B68444319344}.Release|x86.ActiveCfg = Release|Any CPU
{A8149609-CF69-4268-B985-B68444319344}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

View File

@@ -1,34 +1,56 @@
<Project Sdk="WixToolset.Sdk/6.0.0"> <Project Sdk="WixToolset.Sdk/6.0.0">
<ItemGroup>
<PackageReference Include="WixToolset.UI.wixext" /> <!-- ✅ Defaults -->
</ItemGroup> <PropertyGroup>
<PropertyGroup> <Version>0.0.0</Version>
<!-- Force embedding files into the MSI (no external .cab file) --> <Platform>x64</Platform>
<EmbedCab>true</EmbedCab> <InstallerPlatform>x64</InstallerPlatform>
</PropertyGroup> <EmbedCab>true</EmbedCab>
<PropertyGroup> <WixExtensionInclude>WixToolset.UI.wixext</WixExtensionInclude>
<WixExtensionInclude>WixToolset.UI.wixext</WixExtensionInclude> </PropertyGroup>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> <!-- ✅ STEP 1: Run Git BEFORE WiX compilation -->
<DefineConstants>PublishDir=C:\Users\Sonder\source\repos\psg-oversight-app\PublishDir</DefineConstants> <Target Name="SetVersionFromGit" BeforeTargets="BeforeBuild">
</PropertyGroup> <Exec Command="git describe --tags --abbrev=0" ConsoleToMSBuild="true" IgnoreExitCode="true">
<ItemGroup> <Output TaskParameter="ConsoleOutput" PropertyName="GitTag" />
<Content Include="Assets\DLShortcut.ico"> </Exec>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content> <PropertyGroup Condition="'$(GitTag)' != ''">
<Content Include="Assets\trayicon.ico"> <GitTagTrimmed>$([System.Text.RegularExpressions.Regex]::Replace('$(GitTag)', '\s', ''))</GitTagTrimmed>
<CopyToOutputDirectory>Always</CopyToOutputDirectory> <GitVersion>$([System.Text.RegularExpressions.Regex]::Replace('$(GitTagTrimmed)', '^v', ''))</GitVersion>
</Content> <Version>$(GitVersion)</Version>
</ItemGroup> </PropertyGroup>
<ItemGroup>
<WixSource Include="HarvestedFiles.wxs" /> <PropertyGroup>
</ItemGroup> <DefineConstants>
<ItemGroup> Version=$(Version);
<Content Include="bpl.rtf"> PublishDir=C:\Users\Sonder\source\repos\psg-oversight-app\PublishDir
<CopyToOutputDirectory>Always</CopyToOutputDirectory> </DefineConstants>
</Content> <OutputName>OversightInstaller_$(Version)_$(Platform)</OutputName>
</ItemGroup> </PropertyGroup>
<ItemGroup>
<None Include="Assets\windowsdesktop-runtime-8.0.13-win-x64.exe" /> <Message Text="📦 Building OversightInstaller version $(Version)" Importance="high" />
</ItemGroup> <Message Text="📦 WiX DefineConstants=$(DefineConstants)" Importance="high" />
</Target>
<!-- ✅ STEP 2: Rename the MSI after build -->
<Target Name="RenameMsi" AfterTargets="Build">
<PropertyGroup>
<BuiltMsi>$(OutputPath)OversightInstaller_$(Version)_$(Platform).msi</BuiltMsi>
<ActualMsi>$(OutputPath)OversightInstaller.msi</ActualMsi>
</PropertyGroup>
<Message Text="📦 Renaming $(ActualMsi) → $(BuiltMsi)" Importance="high" />
<Exec Command="move /Y &quot;$(ActualMsi)&quot; &quot;$(BuiltMsi)&quot;" />
</Target>
<ItemGroup>
<PackageReference Include="WixToolset.UI.wixext" />
<WixSource Include="HarvestedFiles.wxs" />
<Content Include="Assets\DLShortcut.ico" CopyToOutputDirectory="Always" />
<Content Include="Assets\trayicon.ico" CopyToOutputDirectory="Always" />
<Content Include="bpl.rtf" CopyToOutputDirectory="Always" />
<None Include="Assets\windowsdesktop-runtime-8.0.13-win-x64.exe" />
</ItemGroup>
</Project> </Project>

View File

@@ -1,39 +1,54 @@
<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs" <Wix xmlns="http://wixtoolset.org/schemas/v4/wxs"
xmlns:ui="http://wixtoolset.org/schemas/v4/wxs/ui"> xmlns:ui="http://wixtoolset.org/schemas/v4/wxs/ui">
<Package Name="Oversight" Manufacturer="Paragon Systems Group" Version="1.0.0.0" UpgradeCode="e0e26d46-ed26-425e-a1bb-9bc76523ae6b"> <!-- ✅ Safe default in case $(var.Version) is undefined -->
<MajorUpgrade DowngradeErrorMessage="A newer version of this application is already installed." /> <?ifndef Version?>
<?define Version="0.0.0"?>
<?endif?>
<WixVariable <Package
Id="WixUILicenseRtf" Name="Oversight"
Value="bpl.rtf" Manufacturer="Paragon Systems Group"
/> Version="$(var.Version)"
<!-- 🔍 Properties --> UpgradeCode="e0e26d46-ed26-425e-a1bb-9bc76523ae6b">
<Property Id="ARPPRODUCTICON" Value="DLShortcutIcon" />
<Property Id="SERVER_URL" Value="http://your-default-server/api/register" /> <Property Id="DisplayVersion" Value="$(var.Version)" />
<!-- 🔁 Automatic major-upgrade behavior -->
<MajorUpgrade DowngradeErrorMessage="A newer version of this application is already installed." />
<!-- ✅ Only define custom ARP metadata that isnt built-in -->
<Property Id="ARPPRODUCTICON" Value="DLShortcutIcon" />
<Property Id="ARPHELPLINK" Value="https://psg.net.au/" />
<Property Id="ARPCONTACT" Value="support@psg.net.au" />
<Property Id="ARPINSTALLLOCATION" Value="[INSTALLFOLDER]" />
<!-- Optional custom properties -->
<Property Id="SERVER_URL" Value="http://your-default-server/api/register" />
<Property Id="APP_EXECUTABLE" Value="PSG-Oversight.exe" /> <Property Id="APP_EXECUTABLE" Value="PSG-Oversight.exe" />
<!-- 💬 EULA -->
<WixVariable Id="WixUILicenseRtf" Value="bpl.rtf" />
<!-- 🔧 UI --> <!-- 🔧 UI -->
<ui:WixUI Id="WixUI_InstallDir" InstallDirectory="INSTALLFOLDER" /> <ui:WixUI Id="WixUI_InstallDir" InstallDirectory="INSTALLFOLDER" />
<!-- 🎨 Icon for Add/Remove Programs --> <!-- 🎨 Icon for Add/Remove Programs -->
<Icon Id="DLShortcutIcon" SourceFile="Assets\DLShortcut.ico" /> <Icon Id="DLShortcutIcon" SourceFile="Assets\DLShortcut.ico" />
<!-- 📂 Installation Directory --> <!-- 📂 Installation Directory -->
<StandardDirectory Id="ProgramFiles64Folder"> <StandardDirectory Id="ProgramFiles64Folder">
<Directory Id="INSTALLFOLDER" Name="Oversight"> <Directory Id="PSGROOT" Name="PSG">
<Directory Id="INSTALLFOLDER" Name="Oversight">
<!-- Your files and harvested components go here -->
</Directory>
</Directory>
</StandardDirectory>
<!-- 📦 Application Files -->
<ComponentGroupRef Id="AppFiles" />
<!-- 📁 Start Menu Shortcut -->
<!-- 📁 Assets Folder -->
</Directory>
</StandardDirectory>
<ComponentGroupRef Id="AppFiles" />
<!-- 📁 Start Menu Shortcut -->
<StandardDirectory Id="ProgramMenuFolder"> <StandardDirectory Id="ProgramMenuFolder">
<Directory Id="ApplicationProgramsFolder" Name="Oversight"> <Directory Id="ApplicationProgramsFolder" Name="Oversight">
<Component Id="StartMenuShortcutComponent" Guid="4C5466A9-CE33-48AE-B80C-08915A864DF2"> <Component Id="StartMenuShortcutComponent" Guid="4C5466A9-CE33-48AE-B80C-08915A864DF2">
@@ -46,19 +61,39 @@
IconIndex="0" /> IconIndex="0" />
<RemoveFile Id="RemoveStartMenuShortcut" Name="Oversight.lnk" On="uninstall" /> <RemoveFile Id="RemoveStartMenuShortcut" Name="Oversight.lnk" On="uninstall" />
<RemoveFolder Id="RemoveStartMenuFolder" On="uninstall" /> <RemoveFolder Id="RemoveStartMenuFolder" On="uninstall" />
<RegistryValue Root="HKCU" Key="Software\Oversight" Name="StartMenuShortcut" Type="integer" Value="1" KeyPath="yes"/> <RegistryValue Root="HKCU" Key="Software\Oversight"
Name="StartMenuShortcut" Type="integer" Value="1" KeyPath="yes"/>
</Component> </Component>
</Directory> </Directory>
</StandardDirectory> </StandardDirectory>
<!-- 📦 Feature References --> <!-- 64-bit component so ARP keys go to HKLM\Software (not Wow6432Node) -->
<Feature Id="Main" Title="DL SysInfo" Level="1"> <Component Id="AppMetadata" Guid="E62354E8-3C7B-4B13-AFE2-A1E65A7F2E77" Bitness="always64">
<ComponentGroupRef Id="AppFiles" /> <RegistryKey
<ComponentRef Id="StartMenuShortcutComponent" /> Root="HKLM"
</Feature> Key="Software\Microsoft\Windows\CurrentVersion\Uninstall\[ProductCode]">
<!-- 💿 Media --> <!-- Nice, branded ARP entry -->
<Media Id="1" Cabinet="embedded.cab" EmbedCab="yes" /> <RegistryValue Name="DisplayName" Value="Oversight" Type="string" />
<RegistryValue Name="Publisher" Value="Paragon Systems Group" Type="string" />
<!-- Make version show in Control Panel; compile-time value from your wixproj -->
<RegistryValue Name="DisplayVersion" Value="$(var.Version)" Type="string" KeyPath="yes" />
</RegistryKey>
</Component>
</Package>
<!-- 🧱 Primary Feature -->
<Feature Id="Main" Title="DL SysInfo" Level="1">
<ComponentGroupRef Id="AppFiles" />
<ComponentRef Id="StartMenuShortcutComponent" />
<ComponentRef Id="AppMetadata" />
</Feature>
<!-- 💿 Media -->
<Media Id="1" Cabinet="embedded.cab" EmbedCab="yes" />
</Package>
</Wix> </Wix>

View File

@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk.Worker">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UserSecretsId>dotnet-OversightService-9352272b-722c-4a12-acc2-8c9b146e5292</UserSecretsId>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,7 @@
using OversightService;
var builder = Host.CreateApplicationBuilder(args);
builder.Services.AddHostedService<Worker>();
var host = builder.Build();
host.Run();

View File

@@ -0,0 +1,12 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"profiles": {
"OversightService": {
"commandName": "Project",
"dotnetRunMessages": true,
"environmentVariables": {
"DOTNET_ENVIRONMENT": "Development"
}
}
}
}

View File

@@ -0,0 +1,24 @@
namespace OversightService
{
public class Worker : BackgroundService
{
private readonly ILogger<Worker> _logger;
public Worker(ILogger<Worker> logger)
{
_logger = logger;
}
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
while (!stoppingToken.IsCancellationRequested)
{
if (_logger.IsEnabled(LogLevel.Information))
{
_logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now);
}
await Task.Delay(1000, stoppingToken);
}
}
}
}

View File

@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.Hosting.Lifetime": "Information"
}
}
}

View File

@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.Hosting.Lifetime": "Information"
}
}
}