From c43df2e7129718fdf42cb39ad73d3c968e148266 Mon Sep 17 00:00:00 2001 From: dbuechel Date: Wed, 19 Feb 2020 15:32:38 +0100 Subject: [PATCH] SEBWIN-358: Implemented user agent suffix. --- SafeExamBrowser.Browser/BrowserApplication.cs | 12 ++++++++++-- .../DataMapping/BrowserDataMapper.cs | 11 +++++++++++ .../ConfigurationData/Keys.cs | 1 + SafeExamBrowser.Settings/Browser/BrowserSettings.cs | 5 +++++ 4 files changed, 27 insertions(+), 2 deletions(-) diff --git a/SafeExamBrowser.Browser/BrowserApplication.cs b/SafeExamBrowser.Browser/BrowserApplication.cs index b2e8e4c1..750e6707 100644 --- a/SafeExamBrowser.Browser/BrowserApplication.cs +++ b/SafeExamBrowser.Browser/BrowserApplication.cs @@ -247,15 +247,23 @@ namespace SafeExamBrowser.Browser { var osVersion = $"{Environment.OSVersion.Version.Major}.{Environment.OSVersion.Version.Minor}"; var sebVersion = $"SEB/{appConfig.ProgramInformationalVersion}"; + var userAgent = default(string); if (settings.UseCustomUserAgent) { - return $"{settings.CustomUserAgent} {sebVersion}"; + userAgent = $"{settings.CustomUserAgent} {sebVersion}"; } else { - return $"Mozilla/5.0 (Windows NT {osVersion}) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/{Cef.ChromiumVersion} {sebVersion}"; + userAgent = $"Mozilla/5.0 (Windows NT {osVersion}) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/{Cef.ChromiumVersion} {sebVersion}"; } + + if (!string.IsNullOrWhiteSpace(settings.UserAgentSuffix)) + { + userAgent = $"{userAgent} {settings.UserAgentSuffix}"; + } + + return userAgent; } private string ToScheme(ProxyProtocol protocol) diff --git a/SafeExamBrowser.Configuration/ConfigurationData/DataMapping/BrowserDataMapper.cs b/SafeExamBrowser.Configuration/ConfigurationData/DataMapping/BrowserDataMapper.cs index 7208a1d0..32a13394 100644 --- a/SafeExamBrowser.Configuration/ConfigurationData/DataMapping/BrowserDataMapper.cs +++ b/SafeExamBrowser.Configuration/ConfigurationData/DataMapping/BrowserDataMapper.cs @@ -126,6 +126,9 @@ namespace SafeExamBrowser.Configuration.ConfigurationData.DataMapping case Keys.Browser.StartUrl: MapStartUrl(settings, value); break; + case Keys.Browser.UserAgentSuffix: + MapUserAgentSuffix(settings, value); + break; } } @@ -403,6 +406,14 @@ namespace SafeExamBrowser.Configuration.ConfigurationData.DataMapping } } + private void MapUserAgentSuffix(AppSettings settings, object value) + { + if (value is string suffix) + { + settings.Browser.UserAgentSuffix = suffix; + } + } + private void MapFilterRules(AppSettings settings, object value) { const int ALLOW = 1; diff --git a/SafeExamBrowser.Configuration/ConfigurationData/Keys.cs b/SafeExamBrowser.Configuration/ConfigurationData/Keys.cs index f2ae29ac..7c9cdf3d 100644 --- a/SafeExamBrowser.Configuration/ConfigurationData/Keys.cs +++ b/SafeExamBrowser.Configuration/ConfigurationData/Keys.cs @@ -64,6 +64,7 @@ namespace SafeExamBrowser.Configuration.ConfigurationData internal const string StartUrl = "startURL"; internal const string UserAgentModeDesktop = "browserUserAgentWinDesktopMode"; internal const string UserAgentModeMobile = "browserUserAgentWinTouchMode"; + internal const string UserAgentSuffix = "browserUserAgent"; internal static class AdditionalWindow { diff --git a/SafeExamBrowser.Settings/Browser/BrowserSettings.cs b/SafeExamBrowser.Settings/Browser/BrowserSettings.cs index 9b247e87..6b984384 100644 --- a/SafeExamBrowser.Settings/Browser/BrowserSettings.cs +++ b/SafeExamBrowser.Settings/Browser/BrowserSettings.cs @@ -141,6 +141,11 @@ namespace SafeExamBrowser.Settings.Browser /// public bool UseCustomUserAgent { get; set; } + /// + /// A custom suffix to be appended to the user agent. + /// + public string UserAgentSuffix { get; set; } + public BrowserSettings() { AdditionalWindow = new WindowSettings();