diff --git a/Agent.Installer.Win/Services/InstallerService.cs b/Agent.Installer.Win/Services/InstallerService.cs index 51866f1b3..ddd7f92c6 100644 --- a/Agent.Installer.Win/Services/InstallerService.cs +++ b/Agent.Installer.Win/Services/InstallerService.cs @@ -100,7 +100,7 @@ public async Task Uninstall() ProcessEx.StartHidden("netsh", "advfirewall firewall delete rule name=\"Remotely Desktop Unattended\"").WaitForExit(); - GetRegistryBaseKey().DeleteSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Remotely", false); + GetRegistryBaseKey().DeleteSubKeyTree(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Remotely", false); return true; } @@ -260,13 +260,15 @@ private async Task DownloadRemotelyAgent(string serverUrl) else { ProgressMessageChanged.Invoke(this, "Downloading Remotely agent."); - var client = new WebClient(); - client.DownloadProgressChanged += (sender, args) => + using (var client = new WebClient()) { - ProgressValueChanged?.Invoke(this, args.ProgressPercentage); - }; + client.DownloadProgressChanged += (sender, args) => + { + ProgressValueChanged?.Invoke(this, args.ProgressPercentage); + }; - await client.DownloadFileTaskAsync($"{serverUrl}/Downloads/Remotely-Win10-{Platform}.zip", targetFile); + await client.DownloadFileTaskAsync($"{serverUrl}/Downloads/Remotely-Win10-{Platform}.zip", targetFile); + } } ProgressMessageChanged.Invoke(this, "Extracting Remotely files."); diff --git a/Agent.Installer.Win/ViewModels/MainWindowViewModel.cs b/Agent.Installer.Win/ViewModels/MainWindowViewModel.cs index 60d71a023..3ccb3e215 100644 --- a/Agent.Installer.Win/ViewModels/MainWindowViewModel.cs +++ b/Agent.Installer.Win/ViewModels/MainWindowViewModel.cs @@ -276,13 +276,29 @@ private bool CheckIsAdministrator() private bool CheckParams() { - var result = !string.IsNullOrWhiteSpace(OrganizationID) || !string.IsNullOrWhiteSpace(ServerUrl); - if (!result) + if (string.IsNullOrWhiteSpace(OrganizationID) || string.IsNullOrWhiteSpace(ServerUrl)) { Logger.Write("ServerUrl or OrganizationID param is missing. Unable to install."); - MessageBoxEx.Show("Required settings are missing. Please enter a server URL and organization ID.", "Invalid Installer", MessageBoxButton.OK, MessageBoxImage.Error); + MessageBoxEx.Show("Required settings are missing. Please enter a server URL and organization ID.", "Invalid Input", MessageBoxButton.OK, MessageBoxImage.Error); + return false; } - return result; + + if (!Guid.TryParse(OrganizationID, out _)) + { + Logger.Write("OrganizationID is not a valid GUID."); + MessageBoxEx.Show("Organization ID must be a valid GUID.", "Invalid Organization ID", MessageBoxButton.OK, MessageBoxImage.Error); + return false; + } + + if (!Uri.TryCreate(ServerUrl, UriKind.Absolute, out var serverUri) || + (serverUri.Scheme != Uri.UriSchemeHttp && serverUri.Scheme != Uri.UriSchemeHttps)) + { + Logger.Write("ServerUrl is not valid."); + MessageBoxEx.Show("Server URL must be a valid Uri.", "Invalid Server URL", MessageBoxButton.OK, MessageBoxImage.Error); + return false; + } + + return true; } private void CopyCommandLineArgs() diff --git a/Utilities/Publish.ps1 b/Utilities/Publish.ps1 index 1c40d9270..44c3e95be 100644 --- a/Utilities/Publish.ps1 +++ b/Utilities/Publish.ps1 @@ -85,18 +85,23 @@ if ([string]::IsNullOrWhiteSpace($MSBuildPath) -or !(Test-Path -Path $MSBuildPat return } -# Add Current Version file to root content folder for client update checks. -# TODO: Remove after a few releases. -Set-Content -Path "$Root\Server\CurrentVersion.txt" -Value $CurrentVersion.Trim() -Encoding UTF8 -Force # Update hostname. if ($Hostname.Length -gt 0) { + [Uri]$HostNameUri = $null + + if (![System.Uri]::TryCreate($HostName, [System.UriKind]::Absolute, [ref] $HostNameUri) -or + ($HostNameUri.Scheme -notlike [System.Uri]::UriSchemeHttp -and $HostNameUri.Scheme -notlike [System.Uri]::UriSchemeHttps)) { + Write-Error "`nThe HostName variable is not a valid HTTP Uri." + return + } + Replace-LineInFile -FilePath "$Root\Desktop.Win\Services\Config.cs" -MatchPattern "public string Host " -ReplaceLineWith "public string Host { get; set; } = `"$($Hostname)`";" -MaxCount 1 Replace-LineInFile -FilePath "$Root\Desktop.Linux\Services\Config.cs" -MatchPattern "public string Host " -ReplaceLineWith "public string Host { get; set; } = `"$($Hostname)`";" -MaxCount 1 Replace-LineInFile -FilePath "$Root\Agent.Installer.Win\ViewModels\MainWindowViewModel.cs" -MatchPattern "private string serverUrl" -ReplaceLineWith "private string serverUrl = `"$($Hostname)`";" -MaxCount 1 } else { - Write-Host "`nWARNING: No hostname parameter was specified. The server name will need to be entered manually in the desktop client.`n" -ForegroundColor DarkYellow + Write-Warning "`nNo hostname parameter was specified. The server name will need to be entered manually in the desktop client.`n" } @@ -209,5 +214,5 @@ if ($RID.Length -gt 0 -and $OutDir.Length -gt 0) { dotnet publish /p:Version=$CurrentVersion /p:FileVersion=$CurrentVersion --runtime $RID --configuration Release --output $OutDir "$Root\Server\" } else { - Write-Host "`r`nSkipping server deployment. Params -outdir and -rid not specified." -ForegroundColor DarkYellow + Write-Host "`nSkipping server deployment. Params -outdir and -rid not specified." -ForegroundColor DarkYellow } \ No newline at end of file