Update Safe Exam Browser Patch to 3.10.0.826

This commit is contained in:
2025-09-16 16:32:31 +02:00
parent 4827ae1afc
commit dd82d45ed8
320 changed files with 8445 additions and 5295 deletions

View File

@@ -0,0 +1,93 @@
/*
* Copyright (c) 2025 ETH Zürich, IT Services
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
using System;
using SafeExamBrowser.I18n.Contracts;
using SafeExamBrowser.Logging.Contracts;
using SafeExamBrowser.UserInterface.Contracts.MessageBox;
using SafeExamBrowser.UserInterface.Contracts.Windows;
namespace SafeExamBrowser.Runtime.Responsibilities
{
internal class ClientResponsibility : RuntimeResponsibility
{
private readonly IMessageBox messageBox;
private readonly IRuntimeWindow runtimeWindow;
private readonly Action shutdown;
internal ClientResponsibility(
ILogger logger,
IMessageBox messageBox,
RuntimeContext runtimeContext,
IRuntimeWindow runtimeWindow,
Action shutdown) : base(logger, runtimeContext)
{
this.messageBox = messageBox;
this.runtimeWindow = runtimeWindow;
this.shutdown = shutdown;
}
public override void Assume(RuntimeTask task)
{
switch (task)
{
case RuntimeTask.DeregisterSessionEvents:
DeregisterEvents();
break;
case RuntimeTask.RegisterSessionEvents:
RegisterEvents();
break;
}
}
private void DeregisterEvents()
{
if (Context.ClientProcess != default)
{
Context.ClientProcess.Terminated -= ClientProcess_Terminated;
}
if (Context.ClientProxy != default)
{
Context.ClientProxy.ConnectionLost -= ClientProxy_ConnectionLost;
}
}
private void RegisterEvents()
{
Context.ClientProcess.Terminated += ClientProcess_Terminated;
Context.ClientProxy.ConnectionLost += ClientProxy_ConnectionLost;
}
private void ClientProcess_Terminated(int exitCode)
{
Logger.Error($"Client application has unexpectedly terminated with exit code {exitCode}!");
if (SessionIsRunning)
{
Context.Responsibilities.Delegate(RuntimeTask.StopSession);
}
//messageBox.Show(TextKey.MessageBox_ApplicationError, TextKey.MessageBox_ApplicationErrorTitle, icon: MessageBoxIcon.Error, parent: runtimeWindow);
shutdown.Invoke();
}
private void ClientProxy_ConnectionLost()
{
Logger.Error("Lost connection to the client application!");
if (SessionIsRunning)
{
Context.Responsibilities.Delegate(RuntimeTask.StopSession);
}
messageBox.Show(TextKey.MessageBox_ApplicationError, TextKey.MessageBox_ApplicationErrorTitle, icon: MessageBoxIcon.Error, parent: runtimeWindow);
shutdown.Invoke();
}
}
}

View File

@@ -0,0 +1,84 @@
/*
* Copyright (c) 2025 ETH Zürich, IT Services
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
using System;
using SafeExamBrowser.Communication.Contracts.Events;
using SafeExamBrowser.Communication.Contracts.Hosts;
using SafeExamBrowser.Configuration.Contracts;
using SafeExamBrowser.Logging.Contracts;
namespace SafeExamBrowser.Runtime.Responsibilities
{
internal class CommunicationResponsibility : RuntimeResponsibility
{
private readonly IRuntimeHost runtimeHost;
private readonly Action shutdown;
internal CommunicationResponsibility(
ILogger logger,
RuntimeContext runtimeContext,
IRuntimeHost runtimeHost,
Action shutdown) : base(logger, runtimeContext)
{
this.runtimeHost = runtimeHost;
this.shutdown = shutdown;
}
public override void Assume(RuntimeTask task)
{
switch (task)
{
case RuntimeTask.DeregisterEvents:
DeregisterEvents();
break;
case RuntimeTask.RegisterEvents:
RegisterEvents();
break;
}
}
private void RegisterEvents()
{
runtimeHost.ClientConfigurationNeeded += RuntimeHost_ClientConfigurationNeeded;
runtimeHost.ReconfigurationRequested += RuntimeHost_ReconfigurationRequested;
runtimeHost.ShutdownRequested += RuntimeHost_ShutdownRequested;
}
private void DeregisterEvents()
{
runtimeHost.ClientConfigurationNeeded -= RuntimeHost_ClientConfigurationNeeded;
runtimeHost.ReconfigurationRequested -= RuntimeHost_ReconfigurationRequested;
runtimeHost.ShutdownRequested -= RuntimeHost_ShutdownRequested;
}
private void RuntimeHost_ClientConfigurationNeeded(ClientConfigurationEventArgs args)
{
args.ClientConfiguration = new ClientConfiguration
{
AppConfig = Context.Next.AppConfig,
SessionId = Context.Next.SessionId,
Settings = Context.Next.Settings
};
}
private void RuntimeHost_ReconfigurationRequested(ReconfigurationEventArgs args)
{
Logger.Info($"Accepted request for reconfiguration with '{args.ConfigurationPath}'.");
Context.ReconfigurationFilePath = args.ConfigurationPath;
Context.ReconfigurationUrl = args.ResourceUrl;
Context.Responsibilities.Delegate(RuntimeTask.StartSession);
}
private void RuntimeHost_ShutdownRequested()
{
Logger.Info("Received shutdown request from the client application.");
shutdown.Invoke();
}
}
}

View File

@@ -0,0 +1,67 @@
/*
* Copyright (c) 2025 ETH Zürich, IT Services
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
using SafeExamBrowser.Configuration.Contracts;
using SafeExamBrowser.I18n.Contracts;
using SafeExamBrowser.Logging.Contracts;
using SafeExamBrowser.UserInterface.Contracts.MessageBox;
using SafeExamBrowser.UserInterface.Contracts.Windows;
namespace SafeExamBrowser.Runtime.Responsibilities
{
internal class ErrorMessageResponsibility : RuntimeResponsibility
{
private readonly AppConfig appConfig;
private readonly IMessageBox messageBox;
private readonly ISplashScreen splashScreen;
private readonly IText text;
internal ErrorMessageResponsibility(
AppConfig appConfig,
ILogger logger,
IMessageBox messageBox,
RuntimeContext runtimeContext,
ISplashScreen splashScreen,
IText text) : base(logger, runtimeContext)
{
this.appConfig = appConfig;
this.messageBox = messageBox;
this.splashScreen = splashScreen;
this.text = text;
}
public override void Assume(RuntimeTask task)
{
switch (task)
{
case RuntimeTask.ShowShutdownError:
ShowShutdownErrorMessage();
break;
case RuntimeTask.ShowStartupError:
ShowStartupErrorMessage();
break;
}
}
private void ShowShutdownErrorMessage()
{
var message = AppendLogFilePaths(appConfig, text.Get(TextKey.MessageBox_ShutdownError));
var title = text.Get(TextKey.MessageBox_ShutdownErrorTitle);
messageBox.Show(message, title, icon: MessageBoxIcon.Error, parent: splashScreen);
}
private void ShowStartupErrorMessage()
{
var message = AppendLogFilePaths(appConfig, text.Get(TextKey.MessageBox_StartupError));
var title = text.Get(TextKey.MessageBox_StartupErrorTitle);
messageBox.Show(message, title, icon: MessageBoxIcon.Error, parent: splashScreen);
}
}
}

View File

@@ -0,0 +1,58 @@
/*
* Copyright (c) 2025 ETH Zürich, IT Services
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
using System;
using System.IO;
using SafeExamBrowser.Configuration.Contracts;
using SafeExamBrowser.Core.Contracts.ResponsibilityModel;
using SafeExamBrowser.Logging.Contracts;
namespace SafeExamBrowser.Runtime.Responsibilities
{
internal abstract class RuntimeResponsibility : IResponsibility<RuntimeTask>
{
protected RuntimeContext Context { get; private set; }
protected ILogger Logger { get; private set; }
protected SessionConfiguration Session => Context.Current;
protected bool SessionIsRunning => Session != default;
internal RuntimeResponsibility(ILogger logger, RuntimeContext runtimeContext)
{
Logger = logger;
Context = runtimeContext;
}
public abstract void Assume(RuntimeTask task);
protected string AppendLogFilePaths(AppConfig appConfig, string message)
{
if (File.Exists(appConfig.BrowserLogFilePath))
{
message += $"{Environment.NewLine}{Environment.NewLine}{appConfig.BrowserLogFilePath}";
}
if (File.Exists(appConfig.ClientLogFilePath))
{
message += $"{Environment.NewLine}{Environment.NewLine}{appConfig.ClientLogFilePath}";
}
if (File.Exists(appConfig.RuntimeLogFilePath))
{
message += $"{Environment.NewLine}{Environment.NewLine}{appConfig.RuntimeLogFilePath}";
}
if (File.Exists(appConfig.ServiceLogFilePath))
{
message += $"{Environment.NewLine}{Environment.NewLine}{appConfig.ServiceLogFilePath}";
}
return message;
}
}
}

View File

@@ -0,0 +1,56 @@
/*
* Copyright (c) 2025 ETH Zürich, IT Services
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
namespace SafeExamBrowser.Runtime.Responsibilities
{
/// <summary>
/// Defines all tasks assumed by the responsibilities of the runtime application.
/// </summary>
internal enum RuntimeTask
{
/// <summary>
/// Deregisters the respective event handlers during application termination.
/// </summary>
DeregisterEvents,
/// <summary>
/// Deregisters the respective event handlers during session termination.
/// </summary>
DeregisterSessionEvents,
/// <summary>
/// Registers the respective event handlers during application initialization.
/// </summary>
RegisterEvents,
/// <summary>
/// Registers the respective event handlers during session initialization.
/// </summary>
RegisterSessionEvents,
/// <summary>
/// Shows an error message in case the application shutdown fails.
/// </summary>
ShowShutdownError,
/// <summary>
/// Shows an error message in case the application startup fails.
/// </summary>
ShowStartupError,
/// <summary>
/// Attempts to start a new session.
/// </summary>
StartSession,
/// <summary>
/// Stops the currently running session.
/// </summary>
StopSession
}
}

View File

@@ -0,0 +1,80 @@
/*
* Copyright (c) 2025 ETH Zürich, IT Services
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
using System;
using SafeExamBrowser.Communication.Contracts.Proxies;
using SafeExamBrowser.I18n.Contracts;
using SafeExamBrowser.Logging.Contracts;
using SafeExamBrowser.Settings.Service;
using SafeExamBrowser.UserInterface.Contracts.MessageBox;
using SafeExamBrowser.UserInterface.Contracts.Windows;
namespace SafeExamBrowser.Runtime.Responsibilities
{
internal class ServiceResponsibility : RuntimeResponsibility
{
private readonly IMessageBox messageBox;
private readonly IRuntimeWindow runtimeWindow;
private readonly IServiceProxy serviceProxy;
private readonly Action shutdown;
internal ServiceResponsibility(
ILogger logger,
IMessageBox messageBox,
RuntimeContext runtimeContext,
IRuntimeWindow runtimeWindow,
IServiceProxy serviceProxy,
Action shutdown) : base(logger, runtimeContext)
{
this.messageBox = messageBox;
this.runtimeWindow = runtimeWindow;
this.serviceProxy = serviceProxy;
this.shutdown = shutdown;
}
public override void Assume(RuntimeTask task)
{
switch (task)
{
case RuntimeTask.DeregisterSessionEvents:
DeregisterEvents();
break;
case RuntimeTask.RegisterSessionEvents:
RegisterEvents();
break;
}
}
private void DeregisterEvents()
{
serviceProxy.ConnectionLost -= ServiceProxy_ConnectionLost;
}
private void RegisterEvents()
{
serviceProxy.ConnectionLost += ServiceProxy_ConnectionLost;
}
private void ServiceProxy_ConnectionLost()
{
if (SessionIsRunning && Session.Settings.Service.Policy == ServicePolicy.Mandatory)
{
Logger.Error("Lost connection to the service component!");
Context.Responsibilities.Delegate(RuntimeTask.StopSession);
messageBox.Show(TextKey.MessageBox_ApplicationError, TextKey.MessageBox_ApplicationErrorTitle, icon: MessageBoxIcon.Error, parent: runtimeWindow);
shutdown.Invoke();
}
else
{
Logger.Warn("Lost connection to the service component!");
}
}
}
}

View File

@@ -0,0 +1,181 @@
/*
* Copyright (c) 2025 ETH Zürich, IT Services
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
using System;
using SafeExamBrowser.Configuration.Contracts;
using SafeExamBrowser.Core.Contracts.OperationModel;
using SafeExamBrowser.I18n.Contracts;
using SafeExamBrowser.Logging.Contracts;
using SafeExamBrowser.Settings.Security;
using SafeExamBrowser.UserInterface.Contracts.MessageBox;
using SafeExamBrowser.UserInterface.Contracts.Windows;
namespace SafeExamBrowser.Runtime.Responsibilities
{
internal class SessionResponsibility : RuntimeResponsibility
{
private readonly AppConfig appConfig;
private readonly IMessageBox messageBox;
private readonly IRuntimeWindow runtimeWindow;
private readonly IRepeatableOperationSequence sessionSequence;
private readonly Action shutdown;
private readonly IText text;
internal SessionResponsibility(
AppConfig appConfig,
ILogger logger,
IMessageBox messageBox,
RuntimeContext runtimeContext,
IRuntimeWindow runtimeWindow,
IRepeatableOperationSequence sessionSequence,
Action shutdown,
IText text) : base(logger, runtimeContext)
{
this.appConfig = appConfig;
this.messageBox = messageBox;
this.runtimeWindow = runtimeWindow;
this.sessionSequence = sessionSequence;
this.shutdown = shutdown;
this.text = text;
}
public override void Assume(RuntimeTask task)
{
switch (task)
{
case RuntimeTask.StartSession:
StartSession();
break;
case RuntimeTask.StopSession:
StopSession();
break;
}
}
private void StartSession()
{
runtimeWindow.Show();
runtimeWindow.BringToForeground();
runtimeWindow.ShowProgressBar = true;
Logger.Info(AppendDivider("Session Start Procedure"));
if (SessionIsRunning)
{
Context.Responsibilities.Delegate(RuntimeTask.DeregisterSessionEvents);
}
var result = SessionIsRunning ? sessionSequence.TryRepeat() : sessionSequence.TryPerform();
if (result == OperationResult.Success)
{
Logger.Info(AppendDivider("Session Running"));
HandleSessionStartSuccess();
}
else if (result == OperationResult.Failed)
{
Logger.Info(AppendDivider("Session Start Failed"));
HandleSessionStartFailure();
}
else if (result == OperationResult.Aborted)
{
Logger.Info(AppendDivider("Session Start Aborted"));
HandleSessionStartAbortion();
}
}
private void StopSession()
{
runtimeWindow.Show();
runtimeWindow.BringToForeground();
runtimeWindow.ShowProgressBar = true;
Logger.Info(AppendDivider("Session Stop Procedure"));
Context.Responsibilities.Delegate(RuntimeTask.DeregisterSessionEvents);
var success = sessionSequence.TryRevert() == OperationResult.Success;
if (success)
{
Logger.Info(AppendDivider("Session Terminated"));
}
else
{
Logger.Info(AppendDivider("Session Stop Failed"));
}
}
private void HandleSessionStartSuccess()
{
Context.Responsibilities.Delegate(RuntimeTask.RegisterSessionEvents);
runtimeWindow.ShowProgressBar = false;
runtimeWindow.ShowLog = Session.Settings.Security.AllowApplicationLogAccess;
runtimeWindow.TopMost = Session.Settings.Security.KioskMode != KioskMode.None;
runtimeWindow.UpdateStatus(TextKey.RuntimeWindow_ApplicationRunning);
//if (Session.Settings.Security.KioskMode == KioskMode.DisableExplorerShell)
//{
// runtimeWindow.Hide();
//}
runtimeWindow.Hide();
}
private void HandleSessionStartFailure()
{
var message = AppendLogFilePaths(appConfig, text.Get(TextKey.MessageBox_SessionStartError));
var title = text.Get(TextKey.MessageBox_SessionStartErrorTitle);
if (SessionIsRunning)
{
StopSession();
messageBox.Show(message, title, icon: MessageBoxIcon.Error, parent: runtimeWindow);
Logger.Info("Terminating application...");
shutdown.Invoke();
}
else
{
messageBox.Show(message, title, icon: MessageBoxIcon.Error, parent: runtimeWindow);
}
}
private void HandleSessionStartAbortion()
{
if (SessionIsRunning)
{
Context.Responsibilities.Delegate(RuntimeTask.RegisterSessionEvents);
runtimeWindow.ShowProgressBar = false;
runtimeWindow.UpdateStatus(TextKey.RuntimeWindow_ApplicationRunning);
runtimeWindow.TopMost = Session.Settings.Security.KioskMode != KioskMode.None;
//if (Session.Settings.Security.KioskMode == KioskMode.DisableExplorerShell)
//{
// runtimeWindow.Hide();
//}
runtimeWindow.Hide();
Context.ClientProxy.InformReconfigurationAborted();
}
}
private string AppendDivider(string message)
{
var dashesLeft = new string('-', 48 - message.Length / 2 - message.Length % 2);
var dashesRight = new string('-', 48 - message.Length / 2);
return $"### {dashesLeft} {message} {dashesRight} ###";
}
}
}