From 246b8a8c50391aab7a5fe50bd2bd074f6bfe47e3 Mon Sep 17 00:00:00 2001 From: Jordan Brown Date: Mon, 10 Aug 2020 11:43:14 -0400 Subject: [PATCH 1/3] Fix a 500 error on invalid configuration delete request --- .../Controllers/ConfigurationController.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Tgstation.Server.Host/Controllers/ConfigurationController.cs b/src/Tgstation.Server.Host/Controllers/ConfigurationController.cs index cecd5f2c93..3a76b8bc5b 100644 --- a/src/Tgstation.Server.Host/Controllers/ConfigurationController.cs +++ b/src/Tgstation.Server.Host/Controllers/ConfigurationController.cs @@ -1,4 +1,4 @@ -using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; @@ -291,6 +291,9 @@ namespace Tgstation.Server.Host.Controllers if (directory == null) throw new ArgumentNullException(nameof(directory)); + if (directory.Path == null) + return BadRequest(new ErrorMessage(ErrorCode.ModelValidationFailure)); + if (ForbidDueToModeConflicts(directory.Path, out var systemIdentity)) return Forbid(); From 9c5f9e18812a1f76dae0c9ebed1c61273b32d784 Mon Sep 17 00:00:00 2001 From: Jordan Brown Date: Mon, 10 Aug 2020 14:55:03 -0400 Subject: [PATCH 2/3] Allow DreamDaemon through Windows firewall - Run during installation - Added error code for firewall enabling failure - API to 7.2.0 - Client to 8.2.0 - Fixes #960 --- build/Version.props | 4 +- src/Tgstation.Server.Api/Models/ErrorCode.cs | 8 +- .../Components/Byond/WindowsByondInstaller.cs | 136 +++++++++++------- 3 files changed, 94 insertions(+), 54 deletions(-) diff --git a/build/Version.props b/build/Version.props index c2ecbd805c..c70c2b149a 100644 --- a/build/Version.props +++ b/build/Version.props @@ -4,8 +4,8 @@ 4.4.3 2.0.0 - 7.1.0 - 8.1.0 + 7.2.0 + 8.2.0 5.2.3 0.4.0 1.1.0 diff --git a/src/Tgstation.Server.Api/Models/ErrorCode.cs b/src/Tgstation.Server.Api/Models/ErrorCode.cs index 174de92a6f..6c9772d582 100644 --- a/src/Tgstation.Server.Api/Models/ErrorCode.cs +++ b/src/Tgstation.Server.Api/Models/ErrorCode.cs @@ -563,6 +563,12 @@ namespace Tgstation.Server.Api.Models /// An attempt to connect a chat bot failed. /// [Description("Failed to connect chat bot!")] - ChatCannotConnectProvider + ChatCannotConnectProvider, + + /// + /// Attempt to add DreamDaemon to the list of firewall exempt processes failed. + /// + [Description("Failed to allow DreamDaemon through the Windows firewall!")] + ByondDreamDaemonFirewallFail, } } diff --git a/src/Tgstation.Server.Host/Components/Byond/WindowsByondInstaller.cs b/src/Tgstation.Server.Host/Components/Byond/WindowsByondInstaller.cs index eb249c99c7..12782bbb8b 100644 --- a/src/Tgstation.Server.Host/Components/Byond/WindowsByondInstaller.cs +++ b/src/Tgstation.Server.Host/Components/Byond/WindowsByondInstaller.cs @@ -1,4 +1,4 @@ -using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging; using System; using System.Text; using System.Threading; @@ -84,65 +84,99 @@ namespace Tgstation.Server.Host.Components.Byond public void Dispose() => semaphore.Dispose(); /// - public override async Task InstallByond(string path, Version version, CancellationToken cancellationToken) - { - async Task SetNoPromptTrusted() - { - var configPath = IOManager.ConcatPath(path, ByondConfigDir); - await IOManager.CreateDirectory(configPath, cancellationToken).ConfigureAwait(false); + public override Task InstallByond(string path, Version version, CancellationToken cancellationToken) + => Task.WhenAll( + SetNoPromptTrusted(path, cancellationToken), + InstallDirectX(path, cancellationToken), + AddDreamDaemonToFirewall(path, cancellationToken)); - var configFilePath = IOManager.ConcatPath(configPath, ByondDDConfig); - Logger.LogTrace("Disabling trusted prompts in {0}...", configFilePath); - await IOManager.WriteAllBytes( - configFilePath, - Encoding.UTF8.GetBytes(ByondNoPromptTrustedMode), - cancellationToken) - .ConfigureAwait(false); + async Task SetNoPromptTrusted(string path, CancellationToken cancellationToken) + { + var configPath = IOManager.ConcatPath(path, ByondConfigDir); + await IOManager.CreateDirectory(configPath, cancellationToken).ConfigureAwait(false); + + var configFilePath = IOManager.ConcatPath(configPath, ByondDDConfig); + Logger.LogTrace("Disabling trusted prompts in {0}...", configFilePath); + await IOManager.WriteAllBytes( + configFilePath, + Encoding.UTF8.GetBytes(ByondNoPromptTrustedMode), + cancellationToken) + .ConfigureAwait(false); + } + + async Task InstallDirectX(string path, CancellationToken cancellationToken) + { + using var lockContext = await SemaphoreSlimContext.Lock(semaphore, cancellationToken).ConfigureAwait(false); + if (installedDirectX) + { + Logger.LogTrace("DirectX already installed."); + return; } - var setNoPromptTrustedModeTask = SetNoPromptTrusted(); + Logger.LogTrace("Installing DirectX redistributable..."); - // after this version lummox made DD depend of directx lol - // but then he became amazing and not only fixed it but also gave us 30s compiles \[T]/ - // then he readded it again so -_- - if (!installedDirectX) - using (await SemaphoreSlimContext.Lock(semaphore, cancellationToken).ConfigureAwait(false)) - if (!installedDirectX) - { - // ^check again because race conditions - Logger.LogTrace("Installing DirectX redistributable..."); + // always install it, it's pretty fast and will do better redundancy checking than us + var rbdx = IOManager.ConcatPath(path, ByondDXDir); - // always install it, it's pretty fast and will do better redundancy checking than us - var rbdx = IOManager.ConcatPath(path, ByondDXDir); + try + { + // noShellExecute because we aren't doing runas shennanigans + using var directXInstaller = processExecutor.LaunchProcess( + IOManager.ConcatPath(rbdx, "DXSETUP.exe"), + rbdx, + "/silent", + noShellExecute: true); - // noShellExecute because we aren't doing runas shennanigans - IProcess directXInstaller; - try - { - directXInstaller = processExecutor.LaunchProcess( - IOManager.ConcatPath(rbdx, "DXSETUP.exe"), - rbdx, "/silent", - noShellExecute: true); - } - catch (Exception e) - { - throw new JobException(ErrorCode.ByondDirectXInstallFail, e); - } + int exitCode; + using (cancellationToken.Register(() => directXInstaller.Terminate())) + exitCode = await directXInstaller.Lifetime.ConfigureAwait(false); + cancellationToken.ThrowIfCancellationRequested(); - using (directXInstaller) - { - int exitCode; - using (cancellationToken.Register(() => directXInstaller.Terminate())) - exitCode = await directXInstaller.Lifetime.ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); + if (exitCode != 0) + throw new JobException(ErrorCode.ByondDirectXInstallFail, new JobException($"Invalid exit code: {exitCode}")); + installedDirectX = true; + } + catch (Exception e) + { + throw new JobException(ErrorCode.ByondDirectXInstallFail, e); + } + } - if (exitCode != 0) - throw new JobException(ErrorCode.ByondDirectXInstallFail, new JobException($"Invalid exit code: {exitCode}")); - installedDirectX = true; - } - } + async Task AddDreamDaemonToFirewall(string path, CancellationToken cancellationToken) + { + var dreamDaemonPath = IOManager.ResolvePath( + IOManager.ConcatPath( + path, + ByondManager.BinPath, + DreamDaemonName)); - await setNoPromptTrustedModeTask.ConfigureAwait(false); + try + { + using var netshProcess = processExecutor.LaunchProcess( + "netsh.exe", + IOManager.ResolvePath(), + $"advfirewall firewall add rule name=\"TGS DreamDaemon\" program=\"{dreamDaemonPath}\" protocol=tcp dir=in enable=yes action=allow", + true, + true, + true); + + int exitCode; + using (cancellationToken.Register(() => netshProcess.Terminate())) + exitCode = await netshProcess.Lifetime.ConfigureAwait(false); + cancellationToken.ThrowIfCancellationRequested(); + + Logger.LogDebug( + "netsh.exe output:{0}{1}", + Environment.NewLine, + await netshProcess.GetCombinedOutput(cancellationToken).ConfigureAwait(false)); + + if (exitCode != 0) + throw new JobException(ErrorCode.ByondDreamDaemonFirewallFail, new JobException($"Invalid exit code: {exitCode}")); + } + catch (Exception ex) + { + throw new JobException(ErrorCode.ByondDreamDaemonFirewallFail, ex); + } } } } From a7e6a064e6fc7c9431584fc13dc800507179cd93 Mon Sep 17 00:00:00 2001 From: Jordan Brown Date: Mon, 10 Aug 2020 14:56:22 -0400 Subject: [PATCH 3/3] Version bump to 4.4.4 --- build/Version.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/Version.props b/build/Version.props index c70c2b149a..516f856b60 100644 --- a/build/Version.props +++ b/build/Version.props @@ -2,7 +2,7 @@ - 4.4.3 + 4.4.4 2.0.0 7.2.0 8.2.0