SEBWIN-358: Implemented user agent suffix.

This commit is contained in:
dbuechel 2020-02-19 15:32:38 +01:00
parent 6ad5d062db
commit c43df2e712
4 changed files with 27 additions and 2 deletions

View file

@ -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)

View file

@ -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;

View file

@ -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
{

View file

@ -141,6 +141,11 @@ namespace SafeExamBrowser.Settings.Browser
/// </summary>
public bool UseCustomUserAgent { get; set; }
/// <summary>
/// A custom suffix to be appended to the user agent.
/// </summary>
public string UserAgentSuffix { get; set; }
public BrowserSettings()
{
AdditionalWindow = new WindowSettings();