2018-02-06 15:12:11 +01:00
|
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2018 ETH Zürich, Educational Development and Technology (LET)
|
|
|
|
|
*
|
|
|
|
|
* 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.Contracts.Configuration;
|
|
|
|
|
using SafeExamBrowser.Contracts.Configuration.Settings;
|
2018-08-31 07:49:41 +02:00
|
|
|
|
using SafeExamBrowser.Contracts.Logging;
|
2018-02-06 15:12:11 +01:00
|
|
|
|
|
|
|
|
|
namespace SafeExamBrowser.Configuration
|
|
|
|
|
{
|
|
|
|
|
public class ConfigurationRepository : IConfigurationRepository
|
|
|
|
|
{
|
2018-03-14 11:04:28 +01:00
|
|
|
|
private const string BASE_ADDRESS = "net.pipe://localhost/safeexambrowser";
|
|
|
|
|
|
2018-09-04 10:58:56 +02:00
|
|
|
|
private readonly string executablePath;
|
|
|
|
|
private readonly string programCopyright;
|
|
|
|
|
private readonly string programTitle;
|
|
|
|
|
private readonly string programVersion;
|
|
|
|
|
|
2018-06-29 09:50:20 +02:00
|
|
|
|
private AppConfig appConfig;
|
2018-02-06 15:12:11 +01:00
|
|
|
|
|
2018-09-04 10:58:56 +02:00
|
|
|
|
public ConfigurationRepository(string executablePath, string programCopyright, string programTitle, string programVersion)
|
|
|
|
|
{
|
2018-10-12 11:16:59 +02:00
|
|
|
|
this.executablePath = executablePath ?? string.Empty;
|
|
|
|
|
this.programCopyright = programCopyright ?? string.Empty;
|
|
|
|
|
this.programTitle = programTitle ?? string.Empty;
|
|
|
|
|
this.programVersion = programVersion ?? string.Empty;
|
2018-02-06 15:12:11 +01:00
|
|
|
|
}
|
|
|
|
|
|
2018-10-12 11:16:59 +02:00
|
|
|
|
public AppConfig InitializeAppConfig()
|
2018-02-06 15:12:11 +01:00
|
|
|
|
{
|
|
|
|
|
var appDataFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), nameof(SafeExamBrowser));
|
|
|
|
|
var startTime = DateTime.Now;
|
|
|
|
|
var logFolder = Path.Combine(appDataFolder, "Logs");
|
|
|
|
|
var logFilePrefix = startTime.ToString("yyyy-MM-dd\\_HH\\hmm\\mss\\s");
|
|
|
|
|
|
2018-06-29 09:50:20 +02:00
|
|
|
|
appConfig = new AppConfig();
|
|
|
|
|
appConfig.ApplicationStartTime = startTime;
|
|
|
|
|
appConfig.AppDataFolder = appDataFolder;
|
|
|
|
|
appConfig.BrowserCachePath = Path.Combine(appDataFolder, "Cache");
|
2018-08-16 11:23:37 +02:00
|
|
|
|
appConfig.BrowserLogFile = Path.Combine(logFolder, $"{logFilePrefix}_Browser.log");
|
2018-06-29 09:50:20 +02:00
|
|
|
|
appConfig.ClientId = Guid.NewGuid();
|
|
|
|
|
appConfig.ClientAddress = $"{BASE_ADDRESS}/client/{Guid.NewGuid()}";
|
2018-09-04 10:58:56 +02:00
|
|
|
|
appConfig.ClientExecutablePath = Path.Combine(Path.GetDirectoryName(executablePath), $"{nameof(SafeExamBrowser)}.Client.exe");
|
2018-08-16 11:23:37 +02:00
|
|
|
|
appConfig.ClientLogFile = Path.Combine(logFolder, $"{logFilePrefix}_Client.log");
|
2018-06-29 09:50:20 +02:00
|
|
|
|
appConfig.ConfigurationFileExtension = ".seb";
|
|
|
|
|
appConfig.DefaultSettingsFileName = "SebClientSettings.seb";
|
|
|
|
|
appConfig.DownloadDirectory = Path.Combine(appDataFolder, "Downloads");
|
2018-08-31 07:49:41 +02:00
|
|
|
|
appConfig.LogLevel = LogLevel.Debug;
|
2018-09-04 10:58:56 +02:00
|
|
|
|
appConfig.ProgramCopyright = programCopyright;
|
2018-06-29 09:50:20 +02:00
|
|
|
|
appConfig.ProgramDataFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), nameof(SafeExamBrowser));
|
2018-09-04 10:58:56 +02:00
|
|
|
|
appConfig.ProgramTitle = programTitle;
|
|
|
|
|
appConfig.ProgramVersion = programVersion;
|
2018-06-29 09:50:20 +02:00
|
|
|
|
appConfig.RuntimeId = Guid.NewGuid();
|
|
|
|
|
appConfig.RuntimeAddress = $"{BASE_ADDRESS}/runtime/{Guid.NewGuid()}";
|
2018-08-16 11:23:37 +02:00
|
|
|
|
appConfig.RuntimeLogFile = Path.Combine(logFolder, $"{logFilePrefix}_Runtime.log");
|
2018-08-14 09:06:35 +02:00
|
|
|
|
appConfig.SebUriScheme = "seb";
|
|
|
|
|
appConfig.SebUriSchemeSecure = "sebs";
|
2018-06-29 09:50:20 +02:00
|
|
|
|
appConfig.ServiceAddress = $"{BASE_ADDRESS}/service";
|
2018-10-12 11:16:59 +02:00
|
|
|
|
|
|
|
|
|
return appConfig;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ISessionConfiguration InitializeSessionConfiguration()
|
|
|
|
|
{
|
|
|
|
|
var configuration = new SessionConfiguration();
|
|
|
|
|
|
|
|
|
|
UpdateAppConfig();
|
|
|
|
|
|
|
|
|
|
configuration.AppConfig = CloneAppConfig();
|
|
|
|
|
configuration.Id = Guid.NewGuid();
|
|
|
|
|
configuration.StartupToken = Guid.NewGuid();
|
|
|
|
|
|
|
|
|
|
return configuration;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public LoadStatus TryLoadSettings(Uri resource, out Settings settings, string adminPassword = null, string settingsPassword = null)
|
|
|
|
|
{
|
|
|
|
|
// TODO: Implement loading mechanism
|
|
|
|
|
|
|
|
|
|
settings = LoadDefaultSettings();
|
|
|
|
|
|
|
|
|
|
return LoadStatus.Success;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Settings LoadDefaultSettings()
|
|
|
|
|
{
|
|
|
|
|
// TODO: Implement default settings
|
|
|
|
|
|
|
|
|
|
var settings = new Settings();
|
|
|
|
|
|
|
|
|
|
settings.KioskMode = new Random().Next(10) < 5 ? KioskMode.CreateNewDesktop : KioskMode.DisableExplorerShell;
|
|
|
|
|
settings.ServicePolicy = ServicePolicy.Optional;
|
|
|
|
|
|
|
|
|
|
settings.Browser.StartUrl = "https://www.safeexambrowser.org/testing";
|
|
|
|
|
settings.Browser.AllowAddressBar = true;
|
|
|
|
|
settings.Browser.AllowBackwardNavigation = true;
|
|
|
|
|
settings.Browser.AllowDeveloperConsole = true;
|
|
|
|
|
settings.Browser.AllowForwardNavigation = true;
|
|
|
|
|
settings.Browser.AllowReloading = true;
|
|
|
|
|
settings.Browser.AllowDownloads = true;
|
|
|
|
|
|
|
|
|
|
settings.Taskbar.AllowApplicationLog = true;
|
|
|
|
|
settings.Taskbar.AllowKeyboardLayout = true;
|
|
|
|
|
settings.Taskbar.AllowWirelessNetwork = true;
|
|
|
|
|
|
|
|
|
|
return settings;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private AppConfig CloneAppConfig()
|
|
|
|
|
{
|
|
|
|
|
return new AppConfig
|
|
|
|
|
{
|
|
|
|
|
AppDataFolder = appConfig.AppDataFolder,
|
|
|
|
|
ApplicationStartTime = appConfig.ApplicationStartTime,
|
|
|
|
|
BrowserCachePath = appConfig.BrowserCachePath,
|
|
|
|
|
BrowserLogFile = appConfig.BrowserLogFile,
|
|
|
|
|
ClientAddress = appConfig.ClientAddress,
|
|
|
|
|
ClientExecutablePath = appConfig.ClientExecutablePath,
|
|
|
|
|
ClientId = appConfig.ClientId,
|
|
|
|
|
ClientLogFile = appConfig.ClientLogFile,
|
|
|
|
|
ConfigurationFileExtension = appConfig.ConfigurationFileExtension,
|
|
|
|
|
DefaultSettingsFileName = appConfig.DefaultSettingsFileName,
|
|
|
|
|
DownloadDirectory = appConfig.DownloadDirectory,
|
|
|
|
|
LogLevel = appConfig.LogLevel,
|
|
|
|
|
ProgramCopyright = appConfig.ProgramCopyright,
|
|
|
|
|
ProgramDataFolder = appConfig.ProgramDataFolder,
|
|
|
|
|
ProgramTitle = appConfig.ProgramTitle,
|
|
|
|
|
ProgramVersion = appConfig.ProgramVersion,
|
|
|
|
|
RuntimeAddress = appConfig.RuntimeAddress,
|
|
|
|
|
RuntimeId = appConfig.RuntimeId,
|
|
|
|
|
RuntimeLogFile = appConfig.RuntimeLogFile,
|
|
|
|
|
SebUriScheme = appConfig.SebUriScheme,
|
|
|
|
|
SebUriSchemeSecure = appConfig.SebUriSchemeSecure,
|
|
|
|
|
ServiceAddress = appConfig.ServiceAddress
|
|
|
|
|
};
|
2018-02-06 15:12:11 +01:00
|
|
|
|
}
|
2018-03-14 11:04:28 +01:00
|
|
|
|
|
2018-06-29 09:50:20 +02:00
|
|
|
|
private void UpdateAppConfig()
|
2018-03-14 11:04:28 +01:00
|
|
|
|
{
|
2018-10-12 11:16:59 +02:00
|
|
|
|
appConfig.ClientId = Guid.NewGuid();
|
|
|
|
|
appConfig.ClientAddress = $"{BASE_ADDRESS}/client/{Guid.NewGuid()}";
|
2018-03-14 11:04:28 +01:00
|
|
|
|
}
|
2018-02-06 15:12:11 +01:00
|
|
|
|
}
|
|
|
|
|
}
|