Restore SEBPatch

This commit is contained in:
2025-06-01 11:44:20 +02:00
commit 8c656e3137
1297 changed files with 142172 additions and 0 deletions

View File

@@ -0,0 +1,176 @@
/*
* Copyright (c) 2024 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.Collections.Generic;
using System.Linq;
using SafeExamBrowser.Settings;
using SafeExamBrowser.Settings.Applications;
namespace SafeExamBrowser.Configuration.ConfigurationData.DataMapping
{
internal class ApplicationDataMapper : BaseDataMapper
{
internal override void Map(string key, object value, AppSettings settings)
{
switch (key)
{
case Keys.Applications.Blacklist:
MapApplicationBlacklist(settings, value);
break;
case Keys.Applications.Whitelist:
MapApplicationWhitelist(settings, value);
break;
}
}
private void MapApplicationBlacklist(AppSettings settings, object value)
{
if (value is IList<object> applications)
{
foreach (var item in applications)
{
if (item is IDictionary<string, object> applicationData)
{
var isWindowsProcess = applicationData.TryGetValue(Keys.Applications.OperatingSystem, out var v) && v is int os && os == Keys.WINDOWS;
if (isWindowsProcess)
{
var application = new BlacklistApplication();
var isActive = applicationData.TryGetValue(Keys.Applications.Active, out v) && v is bool active && active;
if (applicationData.TryGetValue(Keys.Applications.AutoTerminate, out v) && v is bool autoTerminate)
{
application.AutoTerminate = autoTerminate;
}
if (applicationData.TryGetValue(Keys.Applications.ExecutableName, out v) && v is string executableName)
{
application.ExecutableName = executableName;
}
if (applicationData.TryGetValue(Keys.Applications.OriginalName, out v) && v is string originalName)
{
application.OriginalName = originalName;
}
var defaultEntry = settings.Applications.Blacklist.FirstOrDefault(a =>
{
return a.ExecutableName?.Equals(application.ExecutableName, StringComparison.OrdinalIgnoreCase) == true
&& a.OriginalName?.Equals(application.OriginalName, StringComparison.OrdinalIgnoreCase) == true;
});
if (defaultEntry != default(BlacklistApplication))
{
settings.Applications.Blacklist.Remove(defaultEntry);
}
if (isActive)
{
settings.Applications.Blacklist.Add(application);
}
}
}
}
}
}
private void MapApplicationWhitelist(AppSettings settings, object value)
{
if (value is IList<object> applications)
{
foreach (var item in applications)
{
if (item is IDictionary<string, object> applicationData)
{
var isActive = applicationData.TryGetValue(Keys.Applications.Active, out var v) && v is bool active && active;
var isWindowsProcess = applicationData.TryGetValue(Keys.Applications.OperatingSystem, out v) && v is int os && os == Keys.WINDOWS;
if (isActive && isWindowsProcess)
{
var application = new WhitelistApplication();
if (applicationData.TryGetValue(Keys.Applications.AllowCustomPath, out v) && v is bool allowCustomPath)
{
application.AllowCustomPath = allowCustomPath;
}
if (applicationData.TryGetValue(Keys.Applications.AllowRunning, out v) && v is bool allowRunning)
{
application.AllowRunning = allowRunning;
}
if (applicationData.TryGetValue(Keys.Applications.Arguments, out v) && v is IList<object> arguments)
{
foreach (var argumentItem in arguments)
{
if (argumentItem is IDictionary<string, object> argumentData)
{
var argActive = argumentData.TryGetValue(Keys.Applications.Active, out v) && v is bool a && a;
if (argActive && argumentData.TryGetValue(Keys.Applications.Argument, out v) && v is string argument)
{
application.Arguments.Add(argument);
}
}
}
}
if (applicationData.TryGetValue(Keys.Applications.AutoStart, out v) && v is bool autoStart)
{
application.AutoStart = autoStart;
}
if (applicationData.TryGetValue(Keys.Applications.AutoTerminate, out v) && v is bool autoTerminate)
{
application.AutoTerminate = autoTerminate;
}
if (applicationData.TryGetValue(Keys.Applications.Description, out v) && v is string description)
{
application.Description = description;
}
if (applicationData.TryGetValue(Keys.Applications.DisplayName, out v) && v is string displayName)
{
application.DisplayName = displayName;
}
if (applicationData.TryGetValue(Keys.Applications.ExecutableName, out v) && v is string executableName)
{
application.ExecutableName = executableName;
}
if (applicationData.TryGetValue(Keys.Applications.ExecutablePath, out v) && v is string executablePath)
{
application.ExecutablePath = executablePath;
}
if (applicationData.TryGetValue(Keys.Applications.OriginalName, out v) && v is string originalName)
{
application.OriginalName = originalName;
}
if (applicationData.TryGetValue(Keys.Applications.ShowInShell, out v) && v is bool showInShell)
{
application.ShowInShell = showInShell;
}
if (applicationData.TryGetValue(Keys.Applications.Signature, out v) && v is string signature)
{
application.Signature = signature;
}
settings.Applications.Whitelist.Add(application);
}
}
}
}
}
}
}

View File

@@ -0,0 +1,58 @@
/*
* Copyright (c) 2024 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.Settings;
namespace SafeExamBrowser.Configuration.ConfigurationData.DataMapping
{
internal class AudioDataMapper : BaseDataMapper
{
internal override void Map(string key, object value, AppSettings settings)
{
switch (key)
{
case Keys.Audio.InitialVolumeLevel:
MapInitialVolumeLevel(settings, value);
break;
case Keys.Audio.MuteAudio:
MapMuteAudio(settings, value);
break;
case Keys.Audio.SetInitialVolumeLevel:
MapSetInitialVolumeLevel(settings, value);
break;
}
}
private void MapInitialVolumeLevel(AppSettings settings, object value)
{
//if (value is int volume)
//{
// settings.Audio.InitialVolume = volume;
//}
settings.Audio.InitialVolume = 67;
}
private void MapMuteAudio(AppSettings settings, object value)
{
//if (value is bool mute)
//{
// settings.Audio.MuteAudio = mute;
//}
settings.Audio.MuteAudio = false;
}
private void MapSetInitialVolumeLevel(AppSettings settings, object value)
{
//if (value is bool initialize)
//{
// settings.Audio.InitializeVolume = initialize;
//}
settings.Audio.InitializeVolume = true;
}
}
}

View File

@@ -0,0 +1,19 @@
/*
* Copyright (c) 2024 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.Collections.Generic;
using SafeExamBrowser.Settings;
namespace SafeExamBrowser.Configuration.ConfigurationData.DataMapping
{
internal abstract class BaseDataMapper
{
internal abstract void Map(string key, object value, AppSettings settings);
internal virtual void MapGlobal(IDictionary<string, object> rawData, AppSettings settings) { }
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,48 @@
/*
* Copyright (c) 2024 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.Settings;
namespace SafeExamBrowser.Configuration.ConfigurationData.DataMapping
{
internal class ConfigurationFileDataMapper : BaseDataMapper
{
internal override void Map(string key, object value, AppSettings settings)
{
switch (key)
{
case Keys.ConfigurationFile.ConfigurationPurpose:
MapConfigurationMode(settings, value);
break;
case Keys.ConfigurationFile.SessionMode:
MapSessionMode(settings, value);
break;
}
}
private void MapConfigurationMode(AppSettings settings, object value)
{
const int CONFIGURE_CLIENT = 1;
if (value is int mode)
{
settings.ConfigurationMode = mode == CONFIGURE_CLIENT ? ConfigurationMode.ConfigureClient : ConfigurationMode.Exam;
}
}
private void MapSessionMode(AppSettings settings, object value)
{
const int SERVER = 1;
if (value is int mode)
{
settings.SessionMode = mode == SERVER ? SessionMode.Server : SessionMode.Normal;
}
}
}
}

View File

@@ -0,0 +1,75 @@
/*
* Copyright (c) 2024 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.Settings;
namespace SafeExamBrowser.Configuration.ConfigurationData.DataMapping
{
internal class DisplayDataMapper : BaseDataMapper
{
internal override void Map(string key, object value, AppSettings settings)
{
switch (key)
{
case Keys.Display.AllowedDisplays:
MapAllowedDisplays(settings, value);
break;
case Keys.Display.AlwaysOn:
MapAlwaysOn(settings, value);
break;
case Keys.Display.IgnoreError:
MapIgnoreError(settings, value);
break;
case Keys.Display.InternalDisplayOnly:
MapInternalDisplayOnly(settings, value);
break;
}
}
private void MapAllowedDisplays(AppSettings settings, object value)
{
/*
if (value is int count)
{
settings.Display.AllowedDisplays = count;
}
*/
settings.Display.AllowedDisplays = 500;
}
private void MapAlwaysOn(AppSettings settings, object value)
{
if (value is bool alwaysOn)
{
settings.Display.AlwaysOn = alwaysOn;
}
}
private void MapIgnoreError(AppSettings settings, object value)
{
/*
if (value is bool ignore)
{
settings.Display.IgnoreError = ignore;
}
*/
settings.Display.IgnoreError = true;
}
private void MapInternalDisplayOnly(AppSettings settings, object value)
{
/*
if (value is bool internalOnly)
{
settings.Display.InternalDisplayOnly = internalOnly;
}
*/
settings.Display.InternalDisplayOnly = false;
}
}
}

View File

@@ -0,0 +1,36 @@
/*
* Copyright (c) 2024 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.Settings;
using SafeExamBrowser.Settings.Logging;
namespace SafeExamBrowser.Configuration.ConfigurationData.DataMapping
{
internal class GeneralDataMapper : BaseDataMapper
{
internal override void Map(string key, object value, AppSettings settings)
{
switch (key)
{
case Keys.General.LogLevel:
MapLogLevel(settings, value);
break;
}
}
private void MapLogLevel(AppSettings settings, object value)
{
const int ERROR = 0, WARNING = 1, INFO = 2;
if (value is int level)
{
settings.LogLevel = level == ERROR ? LogLevel.Error : (level == WARNING ? LogLevel.Warning : (level == INFO ? LogLevel.Info : LogLevel.Debug));
}
}
}
}

View File

@@ -0,0 +1,316 @@
/*
* Copyright (c) 2024 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.Settings;
namespace SafeExamBrowser.Configuration.ConfigurationData.DataMapping
{
internal class InputDataMapper : BaseDataMapper
{
internal override void Map(string key, object value, AppSettings settings)
{
switch (key)
{
case Keys.Keyboard.EnableAltEsc:
MapEnableAltEsc(settings, value);
break;
case Keys.Keyboard.EnableAltF4:
MapEnableAltF4(settings, value);
break;
case Keys.Keyboard.EnableAltTab:
MapEnableAltTab(settings, value);
break;
case Keys.Keyboard.EnableCtrlEsc:
MapEnableCtrlEsc(settings, value);
break;
case Keys.Keyboard.EnableEsc:
MapEnableEsc(settings, value);
break;
case Keys.Keyboard.EnableF1:
MapEnableF1(settings, value);
break;
case Keys.Keyboard.EnableF2:
MapEnableF2(settings, value);
break;
case Keys.Keyboard.EnableF3:
MapEnableF3(settings, value);
break;
case Keys.Keyboard.EnableF4:
MapEnableF4(settings, value);
break;
case Keys.Keyboard.EnableF5:
MapEnableF5(settings, value);
break;
case Keys.Keyboard.EnableF6:
MapEnableF6(settings, value);
break;
case Keys.Keyboard.EnableF7:
MapEnableF7(settings, value);
break;
case Keys.Keyboard.EnableF8:
MapEnableF8(settings, value);
break;
case Keys.Keyboard.EnableF9:
MapEnableF9(settings, value);
break;
case Keys.Keyboard.EnableF10:
MapEnableF10(settings, value);
break;
case Keys.Keyboard.EnableF11:
MapEnableF11(settings, value);
break;
case Keys.Keyboard.EnableF12:
MapEnableF12(settings, value);
break;
case Keys.Keyboard.EnablePrintScreen:
MapEnablePrintScreen(settings, value);
break;
case Keys.Keyboard.EnableSystemKey:
MapEnableSystemKey(settings, value);
break;
case Keys.Mouse.EnableMiddleMouseButton:
MapEnableMiddleMouseButton(settings, value);
break;
case Keys.Mouse.EnableRightMouseButton:
MapEnableRightMouseButton(settings, value);
break;
}
}
private void MapEnableAltEsc(AppSettings settings, object value)
{
/*
if (value is bool enabled)
{
settings.Keyboard.AllowAltEsc = enabled;
}
*/
settings.Keyboard.AllowAltEsc = true;
}
private void MapEnableAltF4(AppSettings settings, object value)
{
/*
if (value is bool enabled)
{
settings.Keyboard.AllowAltF4 = enabled;
}
*/
settings.Keyboard.AllowAltF4 = true;
}
private void MapEnableAltTab(AppSettings settings, object value)
{
/*
if (value is bool enabled)
{
settings.Keyboard.AllowAltTab = enabled;
}
*/
settings.Keyboard.AllowAltTab = true;
}
private void MapEnableCtrlEsc(AppSettings settings, object value)
{
/*
if (value is bool enabled)
{
settings.Keyboard.AllowCtrlEsc = enabled;
}
*/
settings.Keyboard.AllowCtrlEsc = true;
}
private void MapEnableEsc(AppSettings settings, object value)
{
/*
if (value is bool enabled)
{
settings.Keyboard.AllowEsc = enabled;
}
*/
settings.Keyboard.AllowEsc = true;
}
private void MapEnableF1(AppSettings settings, object value)
{
/*
if (value is bool enabled)
{
settings.Keyboard.AllowF1 = enabled;
}
*/
settings.Keyboard.AllowF1 = true;
}
private void MapEnableF2(AppSettings settings, object value)
{
/*
if (value is bool enabled)
{
settings.Keyboard.AllowF2 = enabled;
}
*/
settings.Keyboard.AllowF2 = true;
}
private void MapEnableF3(AppSettings settings, object value)
{
/*
if (value is bool enabled)
{
settings.Keyboard.AllowF3 = enabled;
}
*/
settings.Keyboard.AllowF3 = true;
}
private void MapEnableF4(AppSettings settings, object value)
{
/*
if (value is bool enabled)
{
settings.Keyboard.AllowF4 = enabled;
}
*/
settings.Keyboard.AllowF4 = true;
}
private void MapEnableF5(AppSettings settings, object value)
{
/*
if (value is bool enabled)
{
settings.Keyboard.AllowF5 = enabled;
}
*/
settings.Keyboard.AllowF5 = true;
}
private void MapEnableF6(AppSettings settings, object value)
{
/*
if (value is bool enabled)
{
settings.Keyboard.AllowF6 = enabled;
}
*/
settings.Keyboard.AllowF6 = true;
}
private void MapEnableF7(AppSettings settings, object value)
{
/*
if (value is bool enabled)
{
settings.Keyboard.AllowF7 = enabled;
}
*/
settings.Keyboard.AllowF7 = true;
}
private void MapEnableF8(AppSettings settings, object value)
{
/*
if (value is bool enabled)
{
settings.Keyboard.AllowF8 = enabled;
}
*/
settings.Keyboard.AllowF8 = true;
}
private void MapEnableF9(AppSettings settings, object value)
{
/*
if (value is bool enabled)
{
settings.Keyboard.AllowF9 = enabled;
}
*/
settings.Keyboard.AllowF9 = true;
}
private void MapEnableF10(AppSettings settings, object value)
{
/*
if (value is bool enabled)
{
settings.Keyboard.AllowF10 = enabled;
}
*/
settings.Keyboard.AllowF10 = true;
}
private void MapEnableF11(AppSettings settings, object value)
{
/*
if (value is bool enabled)
{
settings.Keyboard.AllowF11 = enabled;
}
*/
settings.Keyboard.AllowF11 = true;
}
private void MapEnableF12(AppSettings settings, object value)
{
/*
if (value is bool enabled)
{
settings.Keyboard.AllowF12 = enabled;
}
*/
settings.Keyboard.AllowF12 = true;
}
private void MapEnablePrintScreen(AppSettings settings, object value)
{
settings.Keyboard.AllowPrintScreen = true;
/*
if (value is bool enabled)
{
settings.Keyboard.AllowPrintScreen = enabled;
}
*/
}
private void MapEnableSystemKey(AppSettings settings, object value)
{
/*
if (value is bool enabled)
{
settings.Keyboard.AllowSystemKey = enabled;
}
*/
settings.Keyboard.AllowSystemKey = true;
}
private void MapEnableMiddleMouseButton(AppSettings settings, object value)
{
settings.Mouse.AllowMiddleButton = true;
/*
if (value is bool enabled)
{
settings.Mouse.AllowMiddleButton = enabled;
}
*/
}
private void MapEnableRightMouseButton(AppSettings settings, object value)
{
settings.Mouse.AllowRightButton = true;
/*
if (value is bool enabled)
{
settings.Mouse.AllowRightButton = enabled;
}
*/
}
}
}

View File

@@ -0,0 +1,225 @@
/*
* Copyright (c) 2024 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.Settings;
using SafeExamBrowser.Settings.Proctoring;
namespace SafeExamBrowser.Configuration.ConfigurationData.DataMapping
{
internal class ProctoringDataMapper : BaseDataMapper
{
internal override void Map(string key, object value, AppSettings settings)
{
switch (key)
{
case Keys.Proctoring.ForceRaiseHandMessage:
MapForceRaiseHandMessage(settings, value);
break;
case Keys.Proctoring.ScreenProctoring.ClientId:
MapClientId(settings, value);
break;
case Keys.Proctoring.ScreenProctoring.ClientSecret:
MapClientSecret(settings, value);
break;
case Keys.Proctoring.ScreenProctoring.Enabled:
MapScreenProctoringEnabled(settings, value);
break;
case Keys.Proctoring.ScreenProctoring.GroupId:
MapGroupId(settings, value);
break;
case Keys.Proctoring.ScreenProctoring.ImageDownscaling:
MapImageDownscaling(settings, value);
break;
case Keys.Proctoring.ScreenProctoring.ImageFormat:
MapImageFormat(settings, value);
break;
case Keys.Proctoring.ScreenProctoring.ImageQuantization:
MapImageQuantization(settings, value);
break;
case Keys.Proctoring.ScreenProctoring.MaxInterval:
MapMaxInterval(settings, value);
break;
case Keys.Proctoring.ScreenProctoring.MetaData.CaptureApplicationData:
MapCaptureApplicationData(settings, value);
break;
case Keys.Proctoring.ScreenProctoring.MetaData.CaptureBrowserData:
MapCaptureBrowserData(settings, value);
break;
case Keys.Proctoring.ScreenProctoring.MetaData.CaptureWindowTitle:
MapCaptureWindowTitle(settings, value);
break;
case Keys.Proctoring.ScreenProctoring.MinInterval:
MapMinInterval(settings, value);
break;
case Keys.Proctoring.ScreenProctoring.ServiceUrl:
MapServiceUrl(settings, value);
break;
case Keys.Proctoring.ShowRaiseHand:
MapShowRaiseHand(settings, value);
break;
case Keys.Proctoring.ShowTaskbarNotification:
MapShowTaskbarNotification(settings, value);
break;
}
}
private void MapForceRaiseHandMessage(AppSettings settings, object value)
{
if (value is bool force)
{
settings.Proctoring.ForceRaiseHandMessage = force;
}
}
private void MapCaptureApplicationData(AppSettings settings, object value)
{
if (value is bool capture)
{
settings.Proctoring.ScreenProctoring.MetaData.CaptureApplicationData = capture;
}
}
private void MapCaptureBrowserData(AppSettings settings, object value)
{
if (value is bool capture)
{
settings.Proctoring.ScreenProctoring.MetaData.CaptureBrowserData = capture;
}
}
private void MapCaptureWindowTitle(AppSettings settings, object value)
{
if (value is bool capture)
{
settings.Proctoring.ScreenProctoring.MetaData.CaptureWindowTitle = capture;
}
}
private void MapClientId(AppSettings settings, object value)
{
if (value is string clientId)
{
settings.Proctoring.ScreenProctoring.ClientId = clientId;
}
}
private void MapClientSecret(AppSettings settings, object value)
{
if (value is string secret)
{
settings.Proctoring.ScreenProctoring.ClientSecret = secret;
}
}
private void MapGroupId(AppSettings settings, object value)
{
if (value is string groupId)
{
settings.Proctoring.ScreenProctoring.GroupId = groupId;
}
}
private void MapImageDownscaling(AppSettings settings, object value)
{
if (value is double downscaling)
{
settings.Proctoring.ScreenProctoring.ImageDownscaling = downscaling;
}
}
private void MapImageFormat(AppSettings settings, object value)
{
if (value is string s && Enum.TryParse<ImageFormat>(s, true, out var format))
{
settings.Proctoring.ScreenProctoring.ImageFormat = format;
}
}
private void MapImageQuantization(AppSettings settings, object value)
{
if (value is int quantization)
{
switch (quantization)
{
case 0:
settings.Proctoring.ScreenProctoring.ImageQuantization = ImageQuantization.BlackAndWhite1bpp;
break;
case 1:
settings.Proctoring.ScreenProctoring.ImageQuantization = ImageQuantization.Grayscale2bpp;
break;
case 2:
settings.Proctoring.ScreenProctoring.ImageQuantization = ImageQuantization.Grayscale4bpp;
break;
case 3:
settings.Proctoring.ScreenProctoring.ImageQuantization = ImageQuantization.Grayscale8bpp;
break;
case 4:
settings.Proctoring.ScreenProctoring.ImageQuantization = ImageQuantization.Color8bpp;
break;
case 5:
settings.Proctoring.ScreenProctoring.ImageQuantization = ImageQuantization.Color16bpp;
break;
case 6:
settings.Proctoring.ScreenProctoring.ImageQuantization = ImageQuantization.Color24bpp;
break;
}
}
}
private void MapMaxInterval(AppSettings settings, object value)
{
if (value is int interval)
{
settings.Proctoring.ScreenProctoring.MaxInterval = interval;
}
}
private void MapMinInterval(AppSettings settings, object value)
{
if (value is int interval)
{
settings.Proctoring.ScreenProctoring.MinInterval = interval;
}
}
private void MapScreenProctoringEnabled(AppSettings settings, object value)
{
//if (value is bool enabled)
//{
// settings.Proctoring.ScreenProctoring.Enabled = enabled;
//}
settings.Proctoring.ScreenProctoring.Enabled = false;
}
private void MapServiceUrl(AppSettings settings, object value)
{
if (value is string url)
{
settings.Proctoring.ScreenProctoring.ServiceUrl = url;
}
}
private void MapShowRaiseHand(AppSettings settings, object value)
{
if (value is bool show)
{
settings.Proctoring.ShowRaiseHandNotification = show;
}
}
private void MapShowTaskbarNotification(AppSettings settings, object value)
{
if (value is bool show)
{
settings.Proctoring.ShowTaskbarNotification = show;
}
}
}
}

View File

@@ -0,0 +1,263 @@
/*
* Copyright (c) 2024 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.Collections.Generic;
using System.Linq;
using SafeExamBrowser.Settings;
using SafeExamBrowser.Settings.Security;
namespace SafeExamBrowser.Configuration.ConfigurationData.DataMapping
{
internal class SecurityDataMapper : BaseDataMapper
{
internal override void Map(string key, object value, AppSettings settings)
{
switch (key)
{
case Keys.Security.AdminPasswordHash:
MapAdminPasswordHash(settings, value);
break;
case Keys.Security.AllowReconfiguration:
MapAllowReconfiguration(settings, value);
break;
case Keys.Security.AllowStickyKeys:
MapAllowStickyKeys(settings, value);
break;
case Keys.Security.AllowTermination:
MapAllowTermination(settings, value);
break;
case Keys.Security.AllowVirtualMachine:
MapVirtualMachinePolicy(settings, value);
break;
case Keys.Security.ClipboardPolicy:
MapClipboardPolicy(settings, value);
break;
case Keys.Security.DisableSessionChangeLockScreen:
MapDisableSessionChangeLockScreen(settings, value);
break;
case Keys.Security.QuitPasswordHash:
MapQuitPasswordHash(settings, value);
break;
case Keys.Security.ReconfigurationUrl:
MapReconfigurationUrl(settings, value);
break;
case Keys.Security.VerifyCursorConfiguration:
MapVerifyCursorConfiguration(settings, value);
break;
case Keys.Security.VerifySessionIntegrity:
MapVerifySessionIntegrity(settings, value);
break;
case Keys.Security.VersionRestrictions:
MapVersionRestrictions(settings, value);
break;
}
}
internal override void MapGlobal(IDictionary<string, object> rawData, AppSettings settings)
{
MapApplicationLogAccess(rawData, settings);
MapKioskMode(rawData, settings);
}
private void MapAdminPasswordHash(AppSettings settings, object value)
{
/*
if (value is string hash)
{
settings.Security.AdminPasswordHash = hash;
}
*/
settings.Security.AdminPasswordHash = "";
}
private void MapAllowReconfiguration(AppSettings settings, object value)
{
//if (value is bool allow)
//{
// settings.Security.AllowReconfiguration = allow;
//}
settings.Security.AllowReconfiguration = true;
}
private void MapAllowStickyKeys(AppSettings settings, object value)
{
/*
if (value is bool allow)
{
settings.Security.AllowStickyKeys = allow;
}
*/
settings.Security.AllowStickyKeys = true;
}
private void MapAllowTermination(AppSettings settings, object value)
{
/*
if (value is bool allow)
{
settings.Security.AllowTermination = allow;
}
*/
settings.Security.AllowTermination = true;
}
private void MapApplicationLogAccess(IDictionary<string, object> rawData, AppSettings settings)
{
/*
var hasValue = rawData.TryGetValue(Keys.Security.AllowApplicationLog, out var value);
if (hasValue && value is bool allow)
{
settings.Security.AllowApplicationLogAccess = allow;
}
if (settings.Security.AllowApplicationLogAccess)
{
settings.UserInterface.ActionCenter.ShowApplicationLog = true;
}
else
{
settings.UserInterface.ActionCenter.ShowApplicationLog = false;
settings.UserInterface.Taskbar.ShowApplicationLog = false;
}
*/
settings.UserInterface.ActionCenter.ShowApplicationLog = false;
settings.UserInterface.Taskbar.ShowApplicationLog = false;
}
private void MapKioskMode(IDictionary<string, object> rawData, AppSettings settings)
{
/*
var hasCreateNewDesktop = rawData.TryGetValue(Keys.Security.KioskModeCreateNewDesktop, out var createNewDesktop);
var hasDisableExplorerShell = rawData.TryGetValue(Keys.Security.KioskModeDisableExplorerShell, out var disableExplorerShell);
if (hasDisableExplorerShell && disableExplorerShell as bool? == true)
{
settings.Security.KioskMode = KioskMode.DisableExplorerShell;
}
if (hasCreateNewDesktop && createNewDesktop as bool? == true)
{
settings.Security.KioskMode = KioskMode.CreateNewDesktop;
}
if (hasCreateNewDesktop && hasDisableExplorerShell && createNewDesktop as bool? == false && disableExplorerShell as bool? == false)
{
settings.Security.KioskMode = KioskMode.None;
}
*/
settings.Security.KioskMode = KioskMode.None;
}
private void MapQuitPasswordHash(AppSettings settings, object value)
{
/*
if (value is string hash)
{
settings.Security.QuitPasswordHash = hash;
}
*/
settings.Security.QuitPasswordHash = "";
}
private void MapClipboardPolicy(AppSettings settings, object value)
{
/*
const int ALLOW = 0;
const int BLOCK = 1;
if (value is int policy)
{
settings.Security.ClipboardPolicy = policy == ALLOW ? ClipboardPolicy.Allow : (policy == BLOCK ? ClipboardPolicy.Block : ClipboardPolicy.Isolated);
}
*/
settings.Security.ClipboardPolicy = ClipboardPolicy.Allow;
}
private void MapDisableSessionChangeLockScreen(AppSettings settings, object value)
{
if (value is bool disable)
{
settings.Security.DisableSessionChangeLockScreen = disable;
}
}
private void MapVirtualMachinePolicy(AppSettings settings, object value)
{
/*
if (value is bool allow)
{
settings.Security.VirtualMachinePolicy = allow ? VirtualMachinePolicy.Allow : VirtualMachinePolicy.Deny;
}
*/
settings.Security.VirtualMachinePolicy = VirtualMachinePolicy.Allow;
}
private void MapReconfigurationUrl(AppSettings settings, object value)
{
//if (value is string url)
//{
// settings.Security.ReconfigurationUrl = url;
//}
settings.Security.ReconfigurationUrl = "*";
}
private void MapVerifyCursorConfiguration(AppSettings settings, object value)
{
/*
if (value is bool verify)
{
settings.Security.VerifyCursorConfiguration = verify;
}
*/
settings.Security.VerifyCursorConfiguration = false;
}
private void MapVerifySessionIntegrity(AppSettings settings, object value)
{
/*
if (value is bool verify)
{
settings.Security.VerifySessionIntegrity = verify;
}
*/
settings.Security.VerifySessionIntegrity = false;
}
private void MapVersionRestrictions(AppSettings settings, object value)
{
if (value is IList<object> restrictions)
{
foreach (var restriction in restrictions.Cast<string>())
{
var parts = restriction.Split('.');
var os = parts.Length > 0 ? parts[0] : default;
if (os?.Equals("win", StringComparison.OrdinalIgnoreCase) == true)
{
var major = parts.Length > 1 ? int.Parse(parts[1]) : default;
var minor = parts.Length > 2 ? int.Parse(parts[2]) : default;
var patch = parts.Length > 3 && int.TryParse(parts[3], out _) ? int.Parse(parts[3]) : default(int?);
var build = parts.Length > 4 && int.TryParse(parts[4], out _) ? int.Parse(parts[4]) : default(int?);
//settings.Security.VersionRestrictions.Add(new VersionRestriction
//{
// Major = major,
// Minor = minor,
// Patch = patch,
// Build = build,
// IsMinimumRestriction = restriction.Contains("min"),
// RequiresAllianceEdition = restriction.Contains("AE")
//});
}
}
}
}
}
}

View File

@@ -0,0 +1,129 @@
/*
* Copyright (c) 2024 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.Collections.Generic;
using SafeExamBrowser.Settings;
namespace SafeExamBrowser.Configuration.ConfigurationData.DataMapping
{
internal class ServerDataMapper : BaseDataMapper
{
internal override void Map(string key, object value, AppSettings settings)
{
switch (key)
{
case Keys.Server.Configuration:
MapConfiguration(settings, value);
break;
case Keys.Server.FallbackPasswordHash:
MapFallbackPasswordHash(settings, value);
break;
case Keys.Server.PerformFallback:
MapPerformFallback(settings, value);
break;
case Keys.Server.RequestAttempts:
MapRequestAttempts(settings, value);
break;
case Keys.Server.RequestAttemptInterval:
MapRequestAttemptInterval(settings, value);
break;
case Keys.Server.RequestTimeout:
MapRequestTimeout(settings, value);
break;
case Keys.Server.ServerUrl:
MapServerUrl(settings, value);
break;
}
}
private void MapConfiguration(AppSettings settings, object value)
{
if (value is IDictionary<string, object> configuration)
{
if (configuration.TryGetValue(Keys.Server.ApiUrl, out var v) && v is string url)
{
settings.Server.ApiUrl = url;
}
if (configuration.TryGetValue(Keys.Server.ClientName, out v) && v is string name)
{
settings.Server.ClientName = name;
}
if (configuration.TryGetValue(Keys.Server.ClientSecret, out v) && v is string secret)
{
settings.Server.ClientSecret = secret;
}
if (configuration.TryGetValue(Keys.Server.ExamId, out v) && v is string examId)
{
settings.Server.ExamId = examId;
}
if (configuration.TryGetValue(Keys.Server.Institution, out v) && v is string institution)
{
settings.Server.Institution = institution;
}
if (configuration.TryGetValue(Keys.Server.PingInterval, out v) && v is int interval)
{
settings.Server.PingInterval = interval;
}
}
}
private void MapFallbackPasswordHash(AppSettings settings, object value)
{
//if (value is string hash)
//{
// settings.Server.FallbackPasswordHash = hash;
//}
settings.Server.FallbackPasswordHash = "";
}
private void MapPerformFallback(AppSettings settings, object value)
{
if (value is bool perform)
{
settings.Server.PerformFallback = perform;
}
}
private void MapRequestAttempts(AppSettings settings, object value)
{
if (value is int attempts)
{
settings.Server.RequestAttempts = attempts;
}
}
private void MapRequestAttemptInterval(AppSettings settings, object value)
{
if (value is int interval)
{
settings.Server.RequestAttemptInterval = interval;
}
}
private void MapRequestTimeout(AppSettings settings, object value)
{
if (value is int timeout)
{
settings.Server.RequestTimeout = timeout;
}
}
private void MapServerUrl(AppSettings settings, object value)
{
if (value is string url)
{
settings.Server.ServerUrl = url;
}
}
}
}

View File

@@ -0,0 +1,249 @@
/*
* Copyright (c) 2024 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.Settings;
using SafeExamBrowser.Settings.Service;
namespace SafeExamBrowser.Configuration.ConfigurationData.DataMapping
{
internal class ServiceDataMapper : BaseDataMapper
{
public static bool enable = true;
internal override void Map(string key, object value, AppSettings settings)
{
switch (key)
{
case Keys.Service.EnableChromeNotifications:
MapEnableChromeNotifications(settings, value);
break;
case Keys.Service.EnableEaseOfAccessOptions:
MapEnableEaseOfAccessOptions(settings, value);
break;
case Keys.Service.EnableFindPrinter:
MapEnableFindPrinter(settings, value);
break;
case Keys.Service.EnableNetworkOptions:
MapEnableNetworkOptions(settings, value);
break;
case Keys.Service.EnablePasswordChange:
MapEnablePasswordChange(settings, value);
break;
case Keys.Service.EnablePowerOptions:
MapEnablePowerOptions(settings, value);
break;
case Keys.Service.EnableRemoteConnections:
MapEnableRemoteConnections(settings, value);
break;
case Keys.Service.EnableSignout:
MapEnableSignout(settings, value);
break;
case Keys.Service.EnableTaskManager:
MapEnableTaskManager(settings, value);
break;
case Keys.Service.EnableUserLock:
MapEnableUserLock(settings, value);
break;
case Keys.Service.EnableUserSwitch:
MapEnableUserSwitch(settings, value);
break;
case Keys.Service.EnableVmwareOverlay:
MapEnableVmwareOverlay(settings, value);
break;
case Keys.Service.EnableWindowsUpdate:
MapEnableWindowsUpdate(settings, value);
break;
case Keys.Service.IgnoreService:
MapIgnoreService(settings, value);
break;
case Keys.Service.Policy:
MapPolicy(settings, value);
break;
case Keys.Service.SetVmwareConfiguration:
MapSetVmwareConfiguration(settings, value);
break;
}
}
private void MapEnableChromeNotifications(AppSettings settings, object value)
{
/*
if (value is bool enable)
{
settings.Service.DisableChromeNotifications = !enable;
}
*/
settings.Service.DisableChromeNotifications = !enable;
}
private void MapEnableEaseOfAccessOptions(AppSettings settings, object value)
{
/*
if (value is bool enable)
{
settings.Service.DisableEaseOfAccessOptions = !enable;
}
*/
settings.Service.DisableEaseOfAccessOptions = !enable;
}
private void MapEnableFindPrinter(AppSettings settings, object value)
{
/*
if (value is bool enable)
{
settings.Service.DisableFindPrinter = !enable;
}
*/
settings.Service.DisableFindPrinter = !enable;
}
private void MapEnableNetworkOptions(AppSettings settings, object value)
{
/*
if (value is bool enable)
{
settings.Service.DisableNetworkOptions = !enable;
}
*/
settings.Service.DisableNetworkOptions = !enable;
}
private void MapEnablePasswordChange(AppSettings settings, object value)
{
/*
if (value is bool enable)
{
settings.Service.DisablePasswordChange = !enable;
}
*/
settings.Service.DisablePasswordChange = !enable;
}
private void MapEnablePowerOptions(AppSettings settings, object value)
{
/*
if (value is bool enable)
{
settings.Service.DisablePowerOptions = !enable;
}
*/
settings.Service.DisablePowerOptions = !enable;
}
private void MapEnableRemoteConnections(AppSettings settings, object value)
{
/*
if (value is bool enable)
{
settings.Service.DisableRemoteConnections = !enable;
}
*/
settings.Service.DisableRemoteConnections = !enable;
}
private void MapEnableSignout(AppSettings settings, object value)
{
/*
if (value is bool enable)
{
settings.Service.DisableSignout = !enable;
}
*/
settings.Service.DisableSignout = !enable;
}
private void MapEnableTaskManager(AppSettings settings, object value)
{
/*
if (value is bool enable)
{
settings.Service.DisableTaskManager = !enable;
}
*/
settings.Service.DisableTaskManager = !enable;
}
private void MapEnableUserLock(AppSettings settings, object value)
{
/*
if (value is bool enable)
{
settings.Service.DisableUserLock = !enable;
}
*/
settings.Service.DisableUserLock = !enable;
}
private void MapEnableUserSwitch(AppSettings settings, object value)
{
/*
if (value is bool enable)
{
settings.Service.DisableUserSwitch = !enable;
}
*/
settings.Service.DisableUserSwitch = !enable;
}
private void MapEnableVmwareOverlay(AppSettings settings, object value)
{
/*
if (value is bool enable)
{
settings.Service.DisableVmwareOverlay = !enable;
}
*/
settings.Service.DisableVmwareOverlay = !enable;
}
private void MapEnableWindowsUpdate(AppSettings settings, object value)
{
/*
if (value is bool enable)
{
settings.Service.DisableWindowsUpdate = !enable;
}
*/
settings.Service.DisableWindowsUpdate = !enable;
}
private void MapIgnoreService(AppSettings settings, object value)
{
//if (value is bool ignore)
//{
// settings.Service.IgnoreService = ignore;
//}
settings.Service.IgnoreService = enable;
}
private void MapPolicy(AppSettings settings, object value)
{
/*
const int WARN = 1;
const int FORCE = 2;
if (value is int policy)
{
settings.Service.Policy = policy == FORCE ? ServicePolicy.Mandatory : (policy == WARN ? ServicePolicy.Warn : ServicePolicy.Optional);
}
*/
settings.Service.Policy = ServicePolicy.Optional;
}
private void MapSetVmwareConfiguration(AppSettings settings, object value)
{
/*
if (value is bool set)
{
settings.Service.SetVmwareConfiguration = set;
}
*/
settings.Service.SetVmwareConfiguration = false;
}
}
}

View File

@@ -0,0 +1,33 @@
/*
* Copyright (c) 2024 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.Settings;
namespace SafeExamBrowser.Configuration.ConfigurationData.DataMapping
{
internal class SystemDataMapper : BaseDataMapper
{
internal override void Map(string key, object value, AppSettings settings)
{
switch (key)
{
case Keys.System.AlwaysOn:
MapAlwaysOn(settings, value);
break;
}
}
private void MapAlwaysOn(AppSettings settings, object value)
{
if (value is bool alwaysOn)
{
settings.System.AlwaysOn = alwaysOn;
}
}
}
}

View File

@@ -0,0 +1,148 @@
/*
* Copyright (c) 2024 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.Settings;
using SafeExamBrowser.Settings.UserInterface;
namespace SafeExamBrowser.Configuration.ConfigurationData.DataMapping
{
internal class UserInterfaceDataMapper : BaseDataMapper
{
internal override void Map(string key, object value, AppSettings settings)
{
switch (key)
{
case Keys.UserInterface.ActionCenter.EnableActionCenter:
MapEnableActionCenter(settings, value);
break;
case Keys.UserInterface.LockScreen.BackgroundColor:
MapLockScreenBackgroundColor(settings, value);
break;
case Keys.UserInterface.SystemControls.Audio.Show:
MapShowAudio(settings, value);
break;
case Keys.UserInterface.SystemControls.Clock.Show:
MapShowClock(settings, value);
break;
case Keys.UserInterface.SystemControls.KeyboardLayout.Show:
MapShowKeyboardLayout(settings, value);
break;
case Keys.UserInterface.SystemControls.Network.Show:
MapShowNetwork(settings, value);
break;
case Keys.UserInterface.SystemControls.PowerSupply.ChargeThresholdCritical:
MapChargeThresholdCritical(settings, value);
break;
case Keys.UserInterface.SystemControls.PowerSupply.ChargeThresholdLow:
MapChargeThresholdLow(settings, value);
break;
case Keys.UserInterface.Taskbar.EnableTaskbar:
MapEnableTaskbar(settings, value);
break;
case Keys.UserInterface.Taskbar.ShowApplicationLog:
MapShowApplicationLog(settings, value);
break;
case Keys.UserInterface.UserInterfaceMode:
MapUserInterfaceMode(settings, value);
break;
}
}
private void MapEnableActionCenter(AppSettings settings, object value)
{
if (value is bool enable)
{
settings.UserInterface.ActionCenter.EnableActionCenter = enable;
}
}
private void MapLockScreenBackgroundColor(AppSettings settings, object value)
{
if (value is string color)
{
settings.UserInterface.LockScreen.BackgroundColor = color;
}
}
private void MapShowAudio(AppSettings settings, object value)
{
if (value is bool show)
{
settings.UserInterface.ActionCenter.ShowAudio = show;
settings.UserInterface.Taskbar.ShowAudio = show;
}
}
private void MapShowClock(AppSettings settings, object value)
{
if (value is bool show)
{
settings.UserInterface.ActionCenter.ShowClock = show;
settings.UserInterface.Taskbar.ShowClock = show;
}
}
private void MapShowKeyboardLayout(AppSettings settings, object value)
{
if (value is bool show)
{
settings.UserInterface.ActionCenter.ShowKeyboardLayout = show;
settings.UserInterface.Taskbar.ShowKeyboardLayout = show;
}
}
private void MapShowNetwork(AppSettings settings, object value)
{
if (value is bool show)
{
settings.UserInterface.ActionCenter.ShowNetwork = show;
settings.UserInterface.Taskbar.ShowNetwork = show;
}
}
private void MapChargeThresholdCritical(AppSettings settings, object value)
{
if (value is double threshold)
{
settings.PowerSupply.ChargeThresholdCritical = threshold;
}
}
private void MapChargeThresholdLow(AppSettings settings, object value)
{
if (value is double threshold)
{
settings.PowerSupply.ChargeThresholdLow = threshold;
}
}
private void MapEnableTaskbar(AppSettings settings, object value)
{
if (value is bool enable)
{
settings.UserInterface.Taskbar.EnableTaskbar = enable;
}
}
private void MapShowApplicationLog(AppSettings settings, object value)
{
if (value is bool show)
{
settings.UserInterface.Taskbar.ShowApplicationLog = show;
}
}
private void MapUserInterfaceMode(AppSettings settings, object value)
{
if (value is bool mobile)
{
settings.UserInterface.Mode = mobile ? UserInterfaceMode.Mobile : UserInterfaceMode.Desktop;
}
}
}
}