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,42 @@
/*
* 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.Net.Http;
using SafeExamBrowser.Logging.Contracts;
using SafeExamBrowser.Server.Data;
using SafeExamBrowser.Settings.Server;
namespace SafeExamBrowser.Server.Requests
{
internal class ApiRequest : BaseRequest
{
internal ApiRequest(
ApiVersion1 api,
HttpClient httpClient,
ILogger logger,
Parser parser,
ServerSettings settings) : base(api, httpClient, logger, parser, settings)
{
}
internal bool TryExecute(out ApiVersion1 api, out string message)
{
var success = TryExecute(HttpMethod.Get, settings.ApiUrl, out var response);
api = new ApiVersion1();
message = response.ToLogString();
if (success)
{
parser.TryParseApi(response.Content, out api);
}
return success;
}
}
}

View File

@@ -0,0 +1,37 @@
/*
* 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.Net.Http;
using SafeExamBrowser.Logging.Contracts;
using SafeExamBrowser.Server.Data;
using SafeExamBrowser.Settings.Server;
namespace SafeExamBrowser.Server.Requests
{
internal class AppSignatureKeyRequest : BaseRequest
{
internal AppSignatureKeyRequest(
ApiVersion1 api,
HttpClient httpClient,
ILogger logger,
Parser parser,
ServerSettings settings) : base(api, httpClient, logger, parser, settings)
{
}
internal bool TryExecute(string appSignatureKey, out string message)
{
var content = $"seb_signature_key={appSignatureKey}";
var success = TryExecute(new HttpMethod("PATCH"), api.HandshakeEndpoint, out var response, content, ContentType.URL_ENCODED, Authorization, Token);
message = response.ToLogString();
return success;
}
}
}

View File

@@ -0,0 +1,63 @@
/*
* 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 System.Net.Http;
using SafeExamBrowser.Configuration.Contracts;
using SafeExamBrowser.Logging.Contracts;
using SafeExamBrowser.Server.Contracts.Data;
using SafeExamBrowser.Server.Data;
using SafeExamBrowser.Settings.Server;
using SafeExamBrowser.SystemComponents.Contracts;
namespace SafeExamBrowser.Server.Requests
{
internal class AvailableExamsRequest : BaseRequest
{
private readonly AppConfig appConfig;
private readonly ISystemInfo systemInfo;
private readonly IUserInfo userInfo;
internal AvailableExamsRequest(
ApiVersion1 api,
AppConfig appConfig,
HttpClient httpClient,
ILogger logger,
Parser parser,
ServerSettings settings,
ISystemInfo systemInfo,
IUserInfo userInfo) : base(api, httpClient, logger, parser, settings)
{
this.appConfig = appConfig;
this.systemInfo = systemInfo;
this.userInfo = userInfo;
}
internal bool TryExecute(string examId, out IEnumerable<Exam> exams, out string message)
{
var clientInfo = $"client_id={userInfo.GetUserName()}&seb_machine_name={systemInfo.Name}";
var versionInfo = $"seb_os_name={systemInfo.OperatingSystemInfo}&seb_version={appConfig.ProgramInformationalVersion}";
var content = $"institutionId={settings.Institution}&{clientInfo}&{versionInfo}{(examId == default ? "" : $"&examId={examId}")}";
var success = TryExecute(HttpMethod.Post, api.HandshakeEndpoint, out var response, content, ContentType.URL_ENCODED, Authorization);
exams = default;
message = response.ToLogString();
if (success)
{
var hasExams = parser.TryParseExams(response.Content, out exams);
var hasToken = TryRetrieveConnectionToken(response);
success = hasExams && hasToken;
}
return success;
}
}
}

View File

@@ -0,0 +1,213 @@
/*
* 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.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
using SafeExamBrowser.Logging.Contracts;
using SafeExamBrowser.Server.Data;
using SafeExamBrowser.Settings.Server;
namespace SafeExamBrowser.Server.Requests
{
internal abstract class BaseRequest
{
private static string connectionToken;
private static string oauth2Token;
private readonly HttpClient httpClient;
private bool hadException;
protected readonly ApiVersion1 api;
protected readonly ILogger logger;
protected readonly Parser parser;
protected readonly ServerSettings settings;
protected (string, string) Authorization => (Header.AUTHORIZATION, $"Bearer {oauth2Token}");
protected (string, string) Token => (Header.CONNECTION_TOKEN, connectionToken);
internal static string ConnectionToken
{
get { return connectionToken; }
set { connectionToken = value; }
}
internal static string Oauth2Token
{
get { return oauth2Token; }
set { oauth2Token = value; }
}
protected BaseRequest(ApiVersion1 api, HttpClient httpClient, ILogger logger, Parser parser, ServerSettings settings)
{
this.api = api;
this.httpClient = httpClient;
this.logger = logger;
this.parser = parser;
this.settings = settings;
}
protected bool TryExecute(
HttpMethod method,
string url,
out HttpResponseMessage response,
string content = default,
string contentType = default,
params (string name, string value)[] headers)
{
response = default;
for (var attempt = 0; attempt < settings.RequestAttempts && (response == default || !response.IsSuccessStatusCode); attempt++)
{
var request = BuildRequest(method, url, content, contentType, headers);
try
{
response = httpClient.SendAsync(request).GetAwaiter().GetResult();
if (PerformLoggingFor(request))
{
logger.Debug($"Completed request: {request.Method} '{request.RequestUri}' -> {response.ToLogString()}");
}
if (response.StatusCode == HttpStatusCode.Unauthorized && parser.IsTokenExpired(response.Content))
{
logger.Info("OAuth2 token has expired, attempting to retrieve new one...");
if (TryRetrieveOAuth2Token(out var message))
{
headers = UpdateOAuth2Token(headers);
}
}
}
catch (TaskCanceledException)
{
if (PerformLoggingFor(request))
{
logger.Warn($"Request {request.Method} '{request.RequestUri}' did not complete within {settings.RequestTimeout}ms!");
}
break;
}
catch (Exception e)
{
if (PerformLoggingFor(request) && IsFirstException())
{
logger.Warn($"Request {request.Method} '{request.RequestUri}' has failed: {e.ToSummary()}!");
}
}
}
return response != default && response.IsSuccessStatusCode;
}
protected bool TryRetrieveConnectionToken(HttpResponseMessage response)
{
var success = parser.TryParseConnectionToken(response, out connectionToken);
if (success)
{
logger.Info("Successfully retrieved connection token.");
}
else
{
logger.Error("Failed to retrieve connection token!");
}
return success;
}
protected bool TryRetrieveOAuth2Token(out string message)
{
var secret = Convert.ToBase64String(Encoding.UTF8.GetBytes($"{settings.ClientName}:{settings.ClientSecret}"));
var authorization = (Header.AUTHORIZATION, $"Basic {secret}");
var content = "grant_type=client_credentials&scope=read write";
var success = TryExecute(HttpMethod.Post, api.AccessTokenEndpoint, out var response, content, ContentType.URL_ENCODED, authorization);
message = response.ToLogString();
if (success && parser.TryParseOauth2Token(response.Content, out oauth2Token))
{
logger.Info("Successfully retrieved OAuth2 token.");
}
else
{
logger.Error("Failed to retrieve OAuth2 token!");
}
return success;
}
private HttpRequestMessage BuildRequest(
HttpMethod method,
string url,
string content = default,
string contentType = default,
params (string name, string value)[] headers)
{
var request = new HttpRequestMessage(method, url);
if (content != default)
{
request.Content = new StringContent(content, Encoding.UTF8);
if (contentType != default)
{
request.Content.Headers.ContentType = MediaTypeHeaderValue.Parse(contentType);
}
}
request.Headers.Add(Header.ACCEPT, "application/json, */*");
foreach (var (name, value) in headers)
{
request.Headers.Add(name, value);
}
return request;
}
private bool IsFirstException()
{
var isFirst = !hadException;
hadException = true;
return isFirst;
}
private bool PerformLoggingFor(HttpRequestMessage request)
{
return request.RequestUri.AbsolutePath != api.LogEndpoint && request.RequestUri.AbsolutePath != api.PingEndpoint;
}
private (string name, string value)[] UpdateOAuth2Token((string name, string value)[] headers)
{
var result = new List<(string name, string value)>();
foreach (var header in headers)
{
if (header.name == Header.AUTHORIZATION)
{
result.Add((Header.AUTHORIZATION, $"Bearer {oauth2Token}"));
}
else
{
result.Add(header);
}
}
return result.ToArray();
}
}
}

View File

@@ -0,0 +1,45 @@
/*
* 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.Net.Http;
using Newtonsoft.Json.Linq;
using SafeExamBrowser.Logging.Contracts;
using SafeExamBrowser.Server.Data;
using SafeExamBrowser.Settings.Server;
namespace SafeExamBrowser.Server.Requests
{
internal class ConfirmLockScreenRequest : BaseRequest
{
internal ConfirmLockScreenRequest(
ApiVersion1 api,
HttpClient httpClient,
ILogger logger,
Parser parser,
ServerSettings settings) : base(api, httpClient, logger, parser, settings)
{
}
internal bool TryExecute(int lockScreenId, out string message)
{
var json = new JObject
{
["numericValue"] = lockScreenId,
["timestamp"] = DateTime.Now.ToUnixTimestamp(),
["type"] = "NOTIFICATION_CONFIRMED"
};
var content = json.ToString();
var success = TryExecute(HttpMethod.Post, api.LogEndpoint, out var response, content, ContentType.JSON, Authorization, Token);
message = response.ToLogString();
return success;
}
}
}

View File

@@ -0,0 +1,16 @@
/*
* 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/.
*/
namespace SafeExamBrowser.Server.Requests
{
internal static class ContentType
{
internal const string JSON = "application/json;charset=UTF-8";
internal const string URL_ENCODED = "application/x-www-form-urlencoded";
}
}

View File

@@ -0,0 +1,37 @@
/*
* 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.Net.Http;
using SafeExamBrowser.Logging.Contracts;
using SafeExamBrowser.Server.Data;
using SafeExamBrowser.Settings.Server;
namespace SafeExamBrowser.Server.Requests
{
internal class DisconnectionRequest : BaseRequest
{
internal DisconnectionRequest(
ApiVersion1 api,
HttpClient httpClient,
ILogger logger,
Parser parser,
ServerSettings settings) : base(api, httpClient, logger, parser, settings)
{
}
internal bool TryExecute(out string message)
{
var content = "delete=true";
var success = TryExecute(HttpMethod.Delete, api.HandshakeEndpoint, out var response, content, ContentType.URL_ENCODED, Authorization, Token);
message = response.ToLogString();
return success;
}
}
}

View File

@@ -0,0 +1,39 @@
/*
* 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.Net.Http;
using SafeExamBrowser.Logging.Contracts;
using SafeExamBrowser.Server.Contracts.Data;
using SafeExamBrowser.Server.Data;
using SafeExamBrowser.Settings.Server;
namespace SafeExamBrowser.Server.Requests
{
internal class ExamConfigurationRequest : BaseRequest
{
internal ExamConfigurationRequest(
ApiVersion1 api,
HttpClient httpClient,
ILogger logger,
Parser parser,
ServerSettings settings) : base(api, httpClient, logger, parser, settings)
{
}
internal bool TryExecute(Exam exam, out HttpContent content, out string message)
{
var url = $"{api.ConfigurationEndpoint}?examId={exam.Id}";
var success = TryExecute(HttpMethod.Get, url, out var response, default, default, Authorization, Token);
content = response?.Content;
message = response.ToLogString();
return success;
}
}
}

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/.
*/
namespace SafeExamBrowser.Server.Requests
{
internal static class Header
{
internal const string ACCEPT = "Accept";
internal const string APP_SIGNATURE_KEY_SALT = "SEBExamSalt";
internal const string AUTHORIZATION = "Authorization";
internal const string BROWSER_EXAM_KEY = "SEBServerBEK";
internal const string CONNECTION_TOKEN = "SEBConnectionToken";
}
}

View File

@@ -0,0 +1,46 @@
/*
* 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.Net.Http;
using Newtonsoft.Json.Linq;
using SafeExamBrowser.Logging.Contracts;
using SafeExamBrowser.Server.Data;
using SafeExamBrowser.Settings.Server;
namespace SafeExamBrowser.Server.Requests
{
internal class LockScreenRequest : BaseRequest
{
internal LockScreenRequest(
ApiVersion1 api,
HttpClient httpClient,
ILogger logger,
Parser parser,
ServerSettings settings) : base(api, httpClient, logger, parser, settings)
{
}
internal bool TryExecute(int lockScreenId, string text, out string message)
{
var json = new JObject
{
["numericValue"] = lockScreenId,
["text"] = $"<lockscreen> {text}",
["timestamp"] = DateTime.Now.ToUnixTimestamp(),
["type"] = "NOTIFICATION"
};
var content = json.ToString();
var success = TryExecute(HttpMethod.Post, api.LogEndpoint, out var response, content, ContentType.JSON, Authorization, Token);
message = response.ToLogString();
return success;
}
}
}

View File

@@ -0,0 +1,42 @@
/*
* 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.Net.Http;
using Newtonsoft.Json.Linq;
using SafeExamBrowser.Logging.Contracts;
using SafeExamBrowser.Server.Data;
using SafeExamBrowser.Settings.Server;
namespace SafeExamBrowser.Server.Requests
{
internal class LogRequest : BaseRequest
{
internal LogRequest(
ApiVersion1 api,
HttpClient httpClient,
ILogger logger,
Parser parser,
ServerSettings settings) : base(api, httpClient, logger, parser, settings)
{
}
internal bool TryExecute(ILogMessage message)
{
var json = new JObject
{
["text"] = message.Message,
["timestamp"] = message.DateTime.ToUnixTimestamp(),
["type"] = message.Severity.ToLogType()
};
var success = TryExecute(HttpMethod.Post, api.LogEndpoint, out _, json.ToString(), ContentType.JSON, Authorization, Token);
return success;
}
}
}

View File

@@ -0,0 +1,45 @@
/*
* 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.Net.Http;
using Newtonsoft.Json.Linq;
using SafeExamBrowser.Logging.Contracts;
using SafeExamBrowser.Server.Data;
using SafeExamBrowser.Settings.Server;
namespace SafeExamBrowser.Server.Requests
{
internal class LowerHandRequest : BaseRequest
{
internal LowerHandRequest(
ApiVersion1 api,
HttpClient httpClient,
ILogger logger,
Parser parser,
ServerSettings settings) : base(api, httpClient, logger, parser, settings)
{
}
internal bool TryExecute(int handId, out string message)
{
var json = new JObject
{
["numericValue"] = handId,
["timestamp"] = DateTime.Now.ToUnixTimestamp(),
["type"] = "NOTIFICATION_CONFIRMED"
};
var content = json.ToString();
var success = TryExecute(HttpMethod.Post, api.LogEndpoint, out var response, content, ContentType.JSON, Authorization, Token);
message = response.ToLogString();
return success;
}
}
}

View File

@@ -0,0 +1,52 @@
/*
* 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.Net.Http;
using Newtonsoft.Json.Linq;
using SafeExamBrowser.Logging.Contracts;
using SafeExamBrowser.Server.Data;
using SafeExamBrowser.Settings.Logging;
using SafeExamBrowser.Settings.Server;
using SafeExamBrowser.SystemComponents.Contracts.Network;
namespace SafeExamBrowser.Server.Requests
{
internal class NetworkAdapterRequest : BaseRequest
{
internal NetworkAdapterRequest(
ApiVersion1 api,
HttpClient httpClient,
ILogger logger,
Parser parser,
ServerSettings settings) : base(api, httpClient, logger, parser, settings)
{
}
internal bool TryExecute(IWirelessNetwork network, out string message)
{
var json = new JObject
{
["text"] = $"<wlan> {(network != default ? $"{network.Name}: {network.Status}, {network.SignalStrength}%" : "not connected")}",
["timestamp"] = DateTime.Now.ToUnixTimestamp(),
["type"] = LogLevel.Info.ToLogType()
};
if (network != default)
{
json["numericValue"] = network.SignalStrength;
}
var success = TryExecute(HttpMethod.Post, api.LogEndpoint, out var response, json.ToString(), ContentType.JSON, Authorization, Token);
message = response.ToLogString();
return success;
}
}
}

View File

@@ -0,0 +1,32 @@
/*
* 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.Net.Http;
using SafeExamBrowser.Logging.Contracts;
using SafeExamBrowser.Server.Data;
using SafeExamBrowser.Settings.Server;
namespace SafeExamBrowser.Server.Requests
{
internal class OAuth2TokenRequest : BaseRequest
{
internal OAuth2TokenRequest(
ApiVersion1 api,
HttpClient httpClient,
ILogger logger,
Parser parser,
ServerSettings settings) : base(api, httpClient, logger, parser, settings)
{
}
internal bool TryExecute(out string message)
{
return TryRetrieveOAuth2Token(out message);
}
}
}

View File

@@ -0,0 +1,45 @@
/*
* 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.Net.Http;
using SafeExamBrowser.Logging.Contracts;
using SafeExamBrowser.Server.Data;
using SafeExamBrowser.Settings.Server;
namespace SafeExamBrowser.Server.Requests
{
internal class PingRequest : BaseRequest
{
internal PingRequest(
ApiVersion1 api,
HttpClient httpClient,
ILogger logger,
Parser parser,
ServerSettings settings) : base(api, httpClient, logger, parser, settings)
{
}
internal bool TryExecute(int pingNumber, out HttpContent content, out string message, string confirmation = default)
{
var requestContent = $"timestamp={DateTime.Now.ToUnixTimestamp()}&ping-number={pingNumber}";
if (confirmation != default)
{
requestContent = $"{requestContent}&instruction-confirm={confirmation}";
}
var success = TryExecute(HttpMethod.Post, api.PingEndpoint, out var response, requestContent, ContentType.URL_ENCODED, Authorization, Token);
content = response?.Content;
message = response.ToLogString();
return success;
}
}
}

View File

@@ -0,0 +1,64 @@
/*
* 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.Net.Http;
using Newtonsoft.Json.Linq;
using SafeExamBrowser.Logging.Contracts;
using SafeExamBrowser.Server.Data;
using SafeExamBrowser.Settings.Logging;
using SafeExamBrowser.Settings.Server;
using SafeExamBrowser.SystemComponents.Contracts.PowerSupply;
namespace SafeExamBrowser.Server.Requests
{
internal class PowerSupplyRequest : BaseRequest
{
internal PowerSupplyRequest(
ApiVersion1 api,
HttpClient httpClient,
ILogger logger,
Parser parser,
ServerSettings settings) : base(api, httpClient, logger, parser, settings)
{
}
internal bool TryExecute(IPowerSupplyStatus status, bool previouslyConnected, int previousValue, out string message)
{
var connected = status.IsOnline;
var text = default(string);
var value = Convert.ToInt32(status.BatteryCharge * 100);
if (value != previousValue)
{
var chargeInfo = $"{status.BatteryChargeStatus} at {value}%";
var gridInfo = $"{(connected ? "connected to" : "disconnected from")} the power grid";
text = $"<battery> {chargeInfo}, {status.BatteryTimeRemaining} remaining, {gridInfo}";
}
else if (connected != previouslyConnected)
{
text = $"<battery> Device has been {(connected ? "connected to" : "disconnected from")} power grid";
}
var json = new JObject
{
["numericValue"] = value,
["text"] = text,
["timestamp"] = DateTime.Now.ToUnixTimestamp(),
["type"] = LogLevel.Info.ToLogType()
};
var success = TryExecute(HttpMethod.Post, api.LogEndpoint, out var response, json.ToString(), ContentType.JSON, Authorization, Token);
message = response.ToLogString();
return success;
}
}
}

View File

@@ -0,0 +1,46 @@
/*
* 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.Net.Http;
using Newtonsoft.Json.Linq;
using SafeExamBrowser.Logging.Contracts;
using SafeExamBrowser.Server.Data;
using SafeExamBrowser.Settings.Server;
namespace SafeExamBrowser.Server.Requests
{
internal class RaiseHandRequest : BaseRequest
{
internal RaiseHandRequest(
ApiVersion1 api,
HttpClient httpClient,
ILogger logger,
Parser parser,
ServerSettings settings) : base(api, httpClient, logger, parser, settings)
{
}
internal bool TryExecute(int handId, string text, out string message)
{
var json = new JObject
{
["numericValue"] = handId,
["text"] = $"<raisehand> {text}",
["timestamp"] = DateTime.Now.ToUnixTimestamp(),
["type"] = "NOTIFICATION"
};
var content = json.ToString();
var success = TryExecute(HttpMethod.Post, api.LogEndpoint, out var response, content, ContentType.JSON, Authorization, Token);
message = response.ToLogString();
return success;
}
}
}

View File

@@ -0,0 +1,41 @@
/*
* 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.Net.Http;
using SafeExamBrowser.Logging.Contracts;
using SafeExamBrowser.Server.Contracts.Data;
using SafeExamBrowser.Server.Data;
using SafeExamBrowser.Settings.Server;
namespace SafeExamBrowser.Server.Requests
{
internal class SelectExamRequest : BaseRequest
{
internal SelectExamRequest(ApiVersion1 api, HttpClient httpClient, ILogger logger, Parser parser, ServerSettings settings) : base(api, httpClient, logger, parser, settings)
{
}
internal bool TryExecute(Exam exam, out string message, out string appSignatureKeySalt, out string browserExamKey)
{
var content = $"examId={exam.Id}";
var success = TryExecute(HttpMethod.Put, api.HandshakeEndpoint, out var response, content, ContentType.URL_ENCODED, Authorization, Token);
appSignatureKeySalt = default;
browserExamKey = default;
message = response.ToLogString();
if (success)
{
parser.TryParseAppSignatureKeySalt(response, out appSignatureKeySalt);
parser.TryParseBrowserExamKey(response, out browserExamKey);
}
return success;
}
}
}

View File

@@ -0,0 +1,38 @@
/*
* 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.Net.Http;
using SafeExamBrowser.Logging.Contracts;
using SafeExamBrowser.Server.Data;
using SafeExamBrowser.Settings.Server;
namespace SafeExamBrowser.Server.Requests
{
internal class UserIdentifierRequest : BaseRequest
{
internal UserIdentifierRequest(
ApiVersion1 api,
HttpClient httpClient,
ILogger logger,
Parser parser,
ServerSettings settings) : base(api, httpClient, logger, parser, settings)
{
}
internal bool TryExecute(string examId, string identifier, out string message)
{
var content = $"examId={examId}&seb_user_session_id={identifier}";
var method = new HttpMethod("PATCH");
var success = TryExecute(method, api.HandshakeEndpoint, out var response, content, ContentType.URL_ENCODED, Authorization, Token);
message = response.ToLogString();
return success;
}
}
}