Skip to content

Commit

Permalink
Verify URI format for server URL.
Browse files Browse the repository at this point in the history
  • Loading branch information
bitbound committed Dec 18, 2020
1 parent d3bec58 commit f971075
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 15 deletions.
14 changes: 8 additions & 6 deletions Agent.Installer.Win/Services/InstallerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public async Task<bool> 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;
}
Expand Down Expand Up @@ -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.");
Expand Down
24 changes: 20 additions & 4 deletions Agent.Installer.Win/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
15 changes: 10 additions & 5 deletions Utilities/Publish.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}


Expand Down Expand Up @@ -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
}

0 comments on commit f971075

Please sign in to comment.