2026-06-01 20:49:07 +02:00
|
|
|
using ITNexusAgent;
|
|
|
|
|
using ITNexusAgent.Models;
|
|
|
|
|
using ITNexusAgent.UI;
|
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
using System.ServiceProcess;
|
|
|
|
|
|
|
|
|
|
internal class Program
|
|
|
|
|
{
|
|
|
|
|
[STAThread]
|
|
|
|
|
static void Main(string[] args)
|
|
|
|
|
{
|
|
|
|
|
var exePath = System.Diagnostics.Process.GetCurrentProcess().MainModule!.FileName;
|
|
|
|
|
|
|
|
|
|
if (args.Length > 0)
|
|
|
|
|
{
|
|
|
|
|
switch (args[0])
|
|
|
|
|
{
|
|
|
|
|
case "--notify":
|
|
|
|
|
RunNotification(args.Length > 1 ? args[1] : "");
|
|
|
|
|
return;
|
|
|
|
|
|
2026-06-11 10:19:43 +02:00
|
|
|
case "--rdp-consent":
|
2026-06-26 13:27:17 +02:00
|
|
|
ConsentModeRunner.Run(
|
|
|
|
|
args.Length > 1 ? args[1] : "",
|
|
|
|
|
args.Length > 2 ? args[2] : "");
|
2026-06-11 10:19:43 +02:00
|
|
|
return;
|
|
|
|
|
|
2026-06-11 09:49:26 +02:00
|
|
|
case "--rdp-capture":
|
2026-06-11 10:15:00 +02:00
|
|
|
CaptureModeRunner.Run(
|
|
|
|
|
args.Length > 1 ? args[1] : "",
|
2026-06-26 13:27:17 +02:00
|
|
|
args.Length > 2 && int.TryParse(args[2], out var si) ? si : 0,
|
|
|
|
|
args.Length > 3 ? args[3] : "");
|
2026-06-11 09:49:26 +02:00
|
|
|
return;
|
|
|
|
|
|
2026-06-19 12:06:50 +02:00
|
|
|
case "--rdp-indicator":
|
2026-06-26 13:27:17 +02:00
|
|
|
IndicatorModeRunner.Run(
|
|
|
|
|
args.Length > 1 ? args[1] : "",
|
|
|
|
|
args.Length > 2 ? args[2] : "");
|
2026-06-19 12:06:50 +02:00
|
|
|
return;
|
|
|
|
|
|
2026-06-01 20:49:07 +02:00
|
|
|
case "--dashboard":
|
|
|
|
|
RunDashboard();
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
case "--install":
|
|
|
|
|
AgentService.MigrateFromOldAgent();
|
|
|
|
|
AgentService.Install(exePath);
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
case "--uninstall":
|
|
|
|
|
AgentService.Uninstall();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ServiceBase.Run(new AgentService());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void RunNotification(string base64Json)
|
|
|
|
|
{
|
2026-06-10 13:31:11 +02:00
|
|
|
const string errorLog = @"C:\ProgramData\IT Nexus Agent\notify-error.log";
|
2026-06-01 20:49:07 +02:00
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var json = Encoding.UTF8.GetString(Convert.FromBase64String(base64Json));
|
2026-06-10 13:31:11 +02:00
|
|
|
File.AppendAllText(errorLog, $"{DateTime.Now:yyyy-MM-dd HH:mm:ss} START json={json}\n");
|
|
|
|
|
|
2026-06-01 20:49:07 +02:00
|
|
|
var ann = JsonConvert.DeserializeObject<Announcement>(json);
|
2026-06-10 13:31:11 +02:00
|
|
|
if (ann == null)
|
|
|
|
|
{
|
|
|
|
|
File.AppendAllText(errorLog, $"{DateTime.Now:yyyy-MM-dd HH:mm:ss} ERROR: Deserialization returned null\n");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-01 20:49:07 +02:00
|
|
|
var app = new System.Windows.Application();
|
2026-06-10 13:31:11 +02:00
|
|
|
app.ShutdownMode = System.Windows.ShutdownMode.OnMainWindowClose;
|
|
|
|
|
app.DispatcherUnhandledException += (s, e) =>
|
|
|
|
|
{
|
|
|
|
|
File.AppendAllText(errorLog, $"{DateTime.Now:yyyy-MM-dd HH:mm:ss} DISPATCHER ERROR: {e.Exception}\n");
|
|
|
|
|
e.Handled = true;
|
|
|
|
|
app.Shutdown();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var win = new NotificationWindow(ann);
|
|
|
|
|
win.Topmost = true;
|
|
|
|
|
win.Show();
|
|
|
|
|
win.Activate();
|
|
|
|
|
app.Run();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
File.AppendAllText(errorLog, $"{DateTime.Now:yyyy-MM-dd HH:mm:ss} ERROR: {ex}\n");
|
2026-06-01 20:49:07 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void RunDashboard()
|
|
|
|
|
{
|
|
|
|
|
var app = new System.Windows.Application();
|
|
|
|
|
app.Run(new DashboardWindow());
|
|
|
|
|
}
|
|
|
|
|
}
|