2018-01-16 08:14:57 +01:00
|
|
|
|
/*
|
2018-01-16 08:24:00 +01:00
|
|
|
|
* Copyright (c) 2018 ETH Zürich, Educational Development and Technology (LET)
|
2018-01-16 08:14:57 +01:00
|
|
|
|
*
|
|
|
|
|
* 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/.
|
|
|
|
|
*/
|
|
|
|
|
|
2018-02-12 12:21:55 +01:00
|
|
|
|
using System;
|
2018-01-16 08:14:57 +01:00
|
|
|
|
using System.Collections.Generic;
|
2018-02-16 13:15:16 +01:00
|
|
|
|
using System.Diagnostics;
|
2018-01-17 08:26:44 +01:00
|
|
|
|
using SafeExamBrowser.Browser;
|
2018-02-12 12:21:55 +01:00
|
|
|
|
using SafeExamBrowser.Client.Behaviour;
|
|
|
|
|
using SafeExamBrowser.Client.Behaviour.Operations;
|
|
|
|
|
using SafeExamBrowser.Client.Communication;
|
2018-02-28 09:45:29 +01:00
|
|
|
|
using SafeExamBrowser.Client.Notifications;
|
2018-01-17 08:26:44 +01:00
|
|
|
|
using SafeExamBrowser.Configuration;
|
2018-01-16 08:14:57 +01:00
|
|
|
|
using SafeExamBrowser.Contracts.Behaviour;
|
2018-03-06 11:49:51 +01:00
|
|
|
|
using SafeExamBrowser.Contracts.Behaviour.OperationModel;
|
2018-03-15 14:32:07 +01:00
|
|
|
|
using SafeExamBrowser.Contracts.Communication.Hosts;
|
|
|
|
|
using SafeExamBrowser.Contracts.Communication.Proxies;
|
2018-01-17 08:26:44 +01:00
|
|
|
|
using SafeExamBrowser.Contracts.Configuration;
|
|
|
|
|
using SafeExamBrowser.Contracts.I18n;
|
|
|
|
|
using SafeExamBrowser.Contracts.Logging;
|
|
|
|
|
using SafeExamBrowser.Contracts.UserInterface;
|
2018-03-14 12:07:20 +01:00
|
|
|
|
using SafeExamBrowser.Contracts.UserInterface.MessageBox;
|
2018-01-17 08:26:44 +01:00
|
|
|
|
using SafeExamBrowser.Contracts.WindowsApi;
|
2018-03-13 10:57:47 +01:00
|
|
|
|
using SafeExamBrowser.Core.Behaviour.OperationModel;
|
2018-03-16 15:46:53 +01:00
|
|
|
|
using SafeExamBrowser.Core.Communication.Hosts;
|
2018-03-16 09:28:33 +01:00
|
|
|
|
using SafeExamBrowser.Core.Communication.Proxies;
|
2018-01-17 08:26:44 +01:00
|
|
|
|
using SafeExamBrowser.Core.I18n;
|
|
|
|
|
using SafeExamBrowser.Core.Logging;
|
2018-02-12 12:21:55 +01:00
|
|
|
|
using SafeExamBrowser.Monitoring.Display;
|
|
|
|
|
using SafeExamBrowser.Monitoring.Keyboard;
|
|
|
|
|
using SafeExamBrowser.Monitoring.Mouse;
|
|
|
|
|
using SafeExamBrowser.Monitoring.Processes;
|
|
|
|
|
using SafeExamBrowser.Monitoring.Windows;
|
|
|
|
|
using SafeExamBrowser.SystemComponents;
|
2018-01-16 08:14:57 +01:00
|
|
|
|
using SafeExamBrowser.UserInterface.Classic;
|
2018-01-17 08:26:44 +01:00
|
|
|
|
using SafeExamBrowser.WindowsApi;
|
2018-01-16 08:14:57 +01:00
|
|
|
|
|
|
|
|
|
namespace SafeExamBrowser.Client
|
|
|
|
|
{
|
|
|
|
|
internal class CompositionRoot
|
|
|
|
|
{
|
2018-02-16 13:15:16 +01:00
|
|
|
|
private string logFilePath;
|
|
|
|
|
private string runtimeHostUri;
|
|
|
|
|
private Guid startupToken;
|
|
|
|
|
|
2018-02-15 15:42:54 +01:00
|
|
|
|
private ClientConfiguration configuration;
|
2018-02-21 14:01:21 +01:00
|
|
|
|
private IClientHost clientHost;
|
2018-01-17 08:26:44 +01:00
|
|
|
|
private ILogger logger;
|
2018-03-14 12:07:20 +01:00
|
|
|
|
private IMessageBox messageBox;
|
2018-01-17 08:26:44 +01:00
|
|
|
|
private INativeMethods nativeMethods;
|
2018-03-08 15:27:12 +01:00
|
|
|
|
private IRuntimeProxy runtimeProxy;
|
2018-01-17 08:26:44 +01:00
|
|
|
|
private ISystemInfo systemInfo;
|
|
|
|
|
private IText text;
|
|
|
|
|
private IUserInterfaceFactory uiFactory;
|
2018-01-16 08:14:57 +01:00
|
|
|
|
|
2018-02-12 12:21:55 +01:00
|
|
|
|
internal IClientController ClientController { get; private set; }
|
2018-01-17 08:26:44 +01:00
|
|
|
|
internal Taskbar Taskbar { get; private set; }
|
|
|
|
|
|
2018-02-21 14:01:21 +01:00
|
|
|
|
internal void BuildObjectGraph(Action shutdown)
|
2018-01-16 08:14:57 +01:00
|
|
|
|
{
|
2018-02-16 13:15:16 +01:00
|
|
|
|
ValidateCommandLineArguments();
|
2018-02-12 12:21:55 +01:00
|
|
|
|
|
|
|
|
|
configuration = new ClientConfiguration();
|
2018-01-17 14:08:39 +01:00
|
|
|
|
logger = new Logger();
|
2018-01-17 08:26:44 +01:00
|
|
|
|
nativeMethods = new NativeMethods();
|
|
|
|
|
systemInfo = new SystemInfo();
|
|
|
|
|
|
2018-02-16 13:15:16 +01:00
|
|
|
|
InitializeLogging();
|
2018-01-17 08:26:44 +01:00
|
|
|
|
|
|
|
|
|
text = new Text(logger);
|
2018-03-14 12:07:20 +01:00
|
|
|
|
messageBox = new MessageBox(text);
|
2018-02-07 13:25:49 +01:00
|
|
|
|
uiFactory = new UserInterfaceFactory(text);
|
2018-03-15 09:55:04 +01:00
|
|
|
|
runtimeProxy = new RuntimeProxy(runtimeHostUri, new ProxyObjectFactory(), new ModuleLogger(logger, typeof(RuntimeProxy)));
|
2018-02-12 12:21:55 +01:00
|
|
|
|
|
|
|
|
|
var displayMonitor = new DisplayMonitor(new ModuleLogger(logger, typeof(DisplayMonitor)), nativeMethods);
|
|
|
|
|
var processMonitor = new ProcessMonitor(new ModuleLogger(logger, typeof(ProcessMonitor)), nativeMethods);
|
|
|
|
|
var windowMonitor = new WindowMonitor(new ModuleLogger(logger, typeof(WindowMonitor)), nativeMethods);
|
|
|
|
|
|
|
|
|
|
Taskbar = new Taskbar(new ModuleLogger(logger, typeof(Taskbar)));
|
|
|
|
|
|
|
|
|
|
var operations = new Queue<IOperation>();
|
|
|
|
|
|
|
|
|
|
operations.Enqueue(new I18nOperation(logger, text));
|
2018-02-16 13:15:16 +01:00
|
|
|
|
operations.Enqueue(new RuntimeConnectionOperation(logger, runtimeProxy, startupToken));
|
2018-02-12 12:21:55 +01:00
|
|
|
|
operations.Enqueue(new ConfigurationOperation(configuration, logger, runtimeProxy));
|
|
|
|
|
operations.Enqueue(new DelayedInitializationOperation(BuildCommunicationHostOperation));
|
2018-02-21 14:01:21 +01:00
|
|
|
|
operations.Enqueue(new DelegateOperation(UpdateClientControllerDependencies));
|
2018-02-16 13:15:16 +01:00
|
|
|
|
// TODO
|
|
|
|
|
//operations.Enqueue(new DelayedInitializationOperation(BuildKeyboardInterceptorOperation));
|
|
|
|
|
//operations.Enqueue(new WindowMonitorOperation(logger, windowMonitor));
|
|
|
|
|
//operations.Enqueue(new ProcessMonitorOperation(logger, processMonitor));
|
2018-02-12 12:21:55 +01:00
|
|
|
|
operations.Enqueue(new DisplayMonitorOperation(displayMonitor, logger, Taskbar));
|
|
|
|
|
operations.Enqueue(new DelayedInitializationOperation(BuildTaskbarOperation));
|
|
|
|
|
operations.Enqueue(new DelayedInitializationOperation(BuildBrowserOperation));
|
|
|
|
|
operations.Enqueue(new ClipboardOperation(logger, nativeMethods));
|
2018-02-16 13:15:16 +01:00
|
|
|
|
//operations.Enqueue(new DelayedInitializationOperation(BuildMouseInterceptorOperation));
|
2018-02-12 12:21:55 +01:00
|
|
|
|
|
|
|
|
|
var sequence = new OperationSequence(logger, operations);
|
|
|
|
|
|
2018-03-14 12:07:20 +01:00
|
|
|
|
ClientController = new ClientController(displayMonitor, logger, messageBox, sequence, processMonitor, runtimeProxy, shutdown, Taskbar, uiFactory, windowMonitor);
|
2018-02-12 12:21:55 +01:00
|
|
|
|
}
|
|
|
|
|
|
2018-02-16 13:15:16 +01:00
|
|
|
|
internal void LogStartupInformation()
|
|
|
|
|
{
|
|
|
|
|
logger.Log($"# New client instance started at {DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")}");
|
|
|
|
|
logger.Log(string.Empty);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal void LogShutdownInformation()
|
2018-02-12 12:21:55 +01:00
|
|
|
|
{
|
2018-02-16 13:15:16 +01:00
|
|
|
|
logger?.Log($"# Client instance terminated at {DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ValidateCommandLineArguments()
|
|
|
|
|
{
|
|
|
|
|
var args = Environment.GetCommandLineArgs();
|
2018-02-15 15:42:54 +01:00
|
|
|
|
var hasFour = args?.Length == 4;
|
2018-02-12 12:21:55 +01:00
|
|
|
|
|
2018-02-15 15:42:54 +01:00
|
|
|
|
if (hasFour)
|
2018-02-12 12:21:55 +01:00
|
|
|
|
{
|
|
|
|
|
var hasLogfilePath = Uri.TryCreate(args?[1], UriKind.Absolute, out Uri filePath) && filePath.IsFile;
|
|
|
|
|
var hasHostUri = Uri.TryCreate(args?[2], UriKind.Absolute, out Uri hostUri) && hostUri.IsWellFormedOriginalString();
|
|
|
|
|
var hasToken = Guid.TryParse(args?[3], out Guid token);
|
|
|
|
|
|
|
|
|
|
if (hasLogfilePath && hasHostUri && hasToken)
|
|
|
|
|
{
|
2018-02-16 13:15:16 +01:00
|
|
|
|
logFilePath = args[1];
|
|
|
|
|
runtimeHostUri = args[2];
|
|
|
|
|
startupToken = Guid.Parse(args[3]);
|
|
|
|
|
|
2018-02-12 12:21:55 +01:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-16 13:15:16 +01:00
|
|
|
|
throw new ArgumentException("Invalid arguments! Required: SafeExamBrowser.Client.exe <logfile path> <host URI> <token>");
|
2018-02-12 12:21:55 +01:00
|
|
|
|
}
|
|
|
|
|
|
2018-02-16 13:15:16 +01:00
|
|
|
|
private void InitializeLogging()
|
2018-02-12 12:21:55 +01:00
|
|
|
|
{
|
2018-02-16 13:15:16 +01:00
|
|
|
|
var logFileWriter = new LogFileWriter(new DefaultLogFormatter(), logFilePath);
|
2018-02-12 12:21:55 +01:00
|
|
|
|
|
|
|
|
|
logFileWriter.Initialize();
|
|
|
|
|
logger.Subscribe(logFileWriter);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private IOperation BuildBrowserOperation()
|
|
|
|
|
{
|
2018-03-08 15:27:12 +01:00
|
|
|
|
var moduleLogger = new ModuleLogger(logger, typeof(BrowserApplicationController));
|
2018-03-14 12:07:20 +01:00
|
|
|
|
var browserController = new BrowserApplicationController(configuration.Settings.Browser, configuration.RuntimeInfo, moduleLogger, messageBox, runtimeProxy, text, uiFactory);
|
2018-02-12 12:21:55 +01:00
|
|
|
|
var browserInfo = new BrowserApplicationInfo();
|
|
|
|
|
var operation = new BrowserOperation(browserController, browserInfo, logger, Taskbar, uiFactory);
|
|
|
|
|
|
|
|
|
|
return operation;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private IOperation BuildCommunicationHostOperation()
|
|
|
|
|
{
|
2018-02-16 13:15:16 +01:00
|
|
|
|
var processId = Process.GetCurrentProcess().Id;
|
2018-03-16 15:46:53 +01:00
|
|
|
|
var factory = new HostObjectFactory();
|
|
|
|
|
var host = new ClientHost(configuration.RuntimeInfo.ClientAddress, factory, new ModuleLogger(logger, typeof(ClientHost)), processId);
|
2018-02-12 12:21:55 +01:00
|
|
|
|
var operation = new CommunicationOperation(host, logger);
|
|
|
|
|
|
2018-02-21 14:01:21 +01:00
|
|
|
|
clientHost = host;
|
|
|
|
|
clientHost.StartupToken = startupToken;
|
2018-02-16 13:15:16 +01:00
|
|
|
|
|
2018-02-12 12:21:55 +01:00
|
|
|
|
return operation;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private IOperation BuildKeyboardInterceptorOperation()
|
|
|
|
|
{
|
|
|
|
|
var keyboardInterceptor = new KeyboardInterceptor(configuration.Settings.Keyboard, new ModuleLogger(logger, typeof(KeyboardInterceptor)));
|
|
|
|
|
var operation = new KeyboardInterceptorOperation(keyboardInterceptor, logger, nativeMethods);
|
|
|
|
|
|
|
|
|
|
return operation;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private IOperation BuildMouseInterceptorOperation()
|
|
|
|
|
{
|
|
|
|
|
var mouseInterceptor = new MouseInterceptor(new ModuleLogger(logger, typeof(MouseInterceptor)), configuration.Settings.Mouse);
|
|
|
|
|
var operation = new MouseInterceptorOperation(logger, mouseInterceptor, nativeMethods);
|
|
|
|
|
|
|
|
|
|
return operation;
|
2018-01-17 08:26:44 +01:00
|
|
|
|
}
|
|
|
|
|
|
2018-02-12 12:21:55 +01:00
|
|
|
|
private IOperation BuildTaskbarOperation()
|
2018-01-17 08:26:44 +01:00
|
|
|
|
{
|
2018-02-12 12:21:55 +01:00
|
|
|
|
var keyboardLayout = new KeyboardLayout(new ModuleLogger(logger, typeof(KeyboardLayout)), text);
|
2018-02-28 09:45:29 +01:00
|
|
|
|
var logController = new LogNotificationController(logger, uiFactory);
|
|
|
|
|
var logInfo = new LogNotificationInfo(text);
|
2018-02-12 12:21:55 +01:00
|
|
|
|
var powerSupply = new PowerSupply(new ModuleLogger(logger, typeof(PowerSupply)), text);
|
|
|
|
|
var wirelessNetwork = new WirelessNetwork(new ModuleLogger(logger, typeof(WirelessNetwork)), text);
|
2018-02-28 09:45:29 +01:00
|
|
|
|
var operation = new TaskbarOperation(logger, logInfo, logController, keyboardLayout, powerSupply, wirelessNetwork, systemInfo, Taskbar, configuration.Settings.Taskbar, text, uiFactory);
|
2018-01-17 14:08:39 +01:00
|
|
|
|
|
2018-02-12 12:21:55 +01:00
|
|
|
|
return operation;
|
2018-01-16 08:14:57 +01:00
|
|
|
|
}
|
2018-02-21 14:01:21 +01:00
|
|
|
|
|
|
|
|
|
private void UpdateClientControllerDependencies()
|
|
|
|
|
{
|
|
|
|
|
ClientController.ClientHost = clientHost;
|
|
|
|
|
ClientController.RuntimeInfo = configuration.RuntimeInfo;
|
|
|
|
|
ClientController.SessionId = configuration.SessionId;
|
|
|
|
|
ClientController.Settings = configuration.Settings;
|
|
|
|
|
}
|
2018-01-16 08:14:57 +01:00
|
|
|
|
}
|
|
|
|
|
}
|