Skip to content

Commit

Permalink
Add deploy page.
Browse files Browse the repository at this point in the history
  • Loading branch information
bitbound committed May 31, 2024
1 parent d9d68d7 commit d06c8d7
Show file tree
Hide file tree
Showing 7 changed files with 288 additions and 160 deletions.
72 changes: 70 additions & 2 deletions .azure-pipelines/Release Build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,71 @@ pr:
- master

jobs:
- job: Build
displayName: Build
#- job: Mac_Build
# displayName: Mac Build
# timeoutInMinutes: 360
# pool:
# vmImage: macos-latest
# steps:
#
# - task: InstallSSHKey@0
# inputs:
# knownHostsEntry: |
# github.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOMqqnkVzrm0SdG6UOoqKLsabgH5C9okWi0dh2l9GKJl
# github.com ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ==
# github.com ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBEmKSENjQEezOmxkZMy7opKgwFB9nkt5YRrYMjNuG5N87uRgg6CLrbo5wAdT/y6v0mKV0U2w0WZ2YB/++Tpockg=
# sshKeySecureFile: 'pipelines_rsa'
#
# - checkout: self
# submodules: recursive
# clean: true
# fetchTags: false
#
# - task: PowerShell@2
# displayName: Add CurrentVersion Variable
# inputs:
# targetType: inline
# script: |
# $VersionString = git show -s --format=%ci $(Build.SourceVersion)
# $VersionDate = [DateTimeOffset]::Parse($VersionString)
# $CurrentVersion = $VersionDate.ToString("yyyy.MM.dd.HHmm")
#
# [System.Console]::WriteLine("##vso[task.setvariable variable=CurrentVersion]$CurrentVersion")
#
# Write-Host "Setting current version to $CurrentVersion."
#
# - task: UseDotNet@2
# displayName: Use .NET SDK
# inputs:
# version: 8.x
#
# - task: DotNetCoreCLI@2
# displayName: dotnet publish x64
# inputs:
# command: publish
# publishWebProjects: false
# projects: '**/Agent.csproj'
# arguments: -c $(BuildConfiguration) -r osx-x64 -o "$(Build.SourcesDirectory)/Agent/bin/publish" /p:Version=$(CurrentVersion) /p:FileVersion=$(CurrentVersion)
# zipAfterPublish: false
# modifyOutputPath: false
#
# - task: PowerShell@2
# displayName: PowerShell Script
# inputs:
# targetType: inline
# script: |
# Compress-Archive -Path "$(Build.SourcesDirectory)/Agent/bin/publish/*" -DestinationPath "$(Build.SourcesDirectory)/Agent/bin/Remotely-MacOS-x64.zip" -Force
#
# - task: PublishPipelineArtifact@1
# displayName: Publish macOS x64 Agent
# inputs:
# path: $(Build.SourcesDirectory)/Agent/bin/Remotely-MacOS-x64.zip
# artifactName: Mac-x64-Agent

- job: Windows_Build
displayName: Windows Build
timeoutInMinutes: 360
#dependsOn: Mac_Build
pool:
vmImage: windows-latest

Expand All @@ -28,6 +90,12 @@ jobs:
- task: VisualStudioTestPlatformInstaller@1
displayName: Visual Studio Test Platform Installer

# - task: DownloadPipelineArtifact@2
# displayName: Download macOS x64 Agent
# inputs:
# artifact: Mac-x64-Agent
# path: $(Build.SourcesDirectory)\Server\wwwroot\Content\

- task: PowerShell@2
displayName: Add CurrentVersion Variable
inputs:
Expand Down
30 changes: 18 additions & 12 deletions Server/Components/Layout/NavMenu.razor
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,20 @@

<div class="@NavMenuCssClass" @onclick="ToggleNavMenu">
<ul class="nav flex-column">

<li class="nav-item px-3">
<NavLink class="nav-link" href="" Match="NavLinkMatch.All">
<span class="oi oi-home" aria-hidden="true"></span> Home
</NavLink>
</li>

<li class="nav-item px-3">
<NavLink class="nav-link" href="/RemoteControl/Viewer" target="_blank">
<span class="oi oi-monitor" aria-hidden="true"></span> Remote Control
</NavLink>

</li>
<li class="nav-item px-3">
<NavLink class="nav-link" href="downloads">
<span class="oi oi-cloud-download" aria-hidden="true"></span> Downloads
</NavLink>
</li>

<AuthorizeView>
<Authorized>
<li class="nav-item px-3">
<NavLink class="nav-link" href="deploy">
<span class="oi oi-data-transfer-upload" aria-hidden="true"></span> Deploy
</NavLink>
</li>
<li class="nav-item px-3">
<NavLink class="nav-link" href="scripts">
<span class="oi oi-script" aria-hidden="true"></span> Scripts
Expand All @@ -64,6 +58,18 @@
</Authorized>
</AuthorizeView>

<li class="nav-item px-3">
<NavLink class="nav-link" href="/RemoteControl/Viewer" target="_blank">
<span class="oi oi-monitor" aria-hidden="true"></span> Remote Control
</NavLink>

</li>
<li class="nav-item px-3">
<NavLink class="nav-link" href="downloads">
<span class="oi oi-cloud-download" aria-hidden="true"></span> Downloads
</NavLink>
</li>

@if (_user?.IsAdministrator == true)
{
<li class="nav-item px-3 pt-3 small text-muted">
Expand Down
126 changes: 126 additions & 0 deletions Server/Components/Pages/Deploy.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
@page "/deploy"
@attribute [Authorize]
@inject NavigationManager NavMan
@inject IAuthService Auth
@inject IDataService DataService
@inject IJsInterop JsInterop
@inject IToastService Toasts
@inject ILogger<Deploy> Logger

<h3>Deploy Scripts</h3>
<p class="text-info col-sm-12 mb-4">
Copy and paste on a remote computer to install the agent.
</p>

<div class="row">
<div class="col-sm-12 mb-3">
<div class="mb-1">
<strong>Windows 10/11 (32-Bit and 64-Bit)</strong>
</div>

<div class="input-group">
<input type="text" class="form-control" readonly value="@_windowsScript" />
<button class="btn btn-primary" type="button" id="button-addon2" @onclick="() => CopyToClipboard(_windowsScript)">
<i class="oi oi-clipboard"></i>
</button>
</div>
</div>

<div class="col-sm-12 mb-3">
<div class="mb-1">
<strong>Ubuntu (64-Bit)</strong>
</div>

<div class="input-group">
<input type="text" class="form-control" readonly value="@_ubuntuScript" />
<button class="btn btn-primary" type="button" id="button-addon2" @onclick="() => CopyToClipboard(_ubuntuScript)">
<i class="oi oi-clipboard"></i>
</button>
</div>
</div>

<div class="col-sm-12 mb-3">
<div class="mb-1">
<strong>Manjaro (64-Bit)</strong>
</div>

<div class="input-group">
<input type="text" class="form-control" readonly value="@_manjaroScript" />
<button class="btn btn-primary" type="button" id="button-addon2" @onclick="() => CopyToClipboard(_manjaroScript)">
<i class="oi oi-clipboard"></i>
</button>
</div>
</div>
</div>

@code {
private string? _organizationId;
private bool _isAuthenticated;
private string _windowsScript = string.Empty;
private string _ubuntuScript = string.Empty;
private string _manjaroScript = string.Empty;

protected override async Task OnInitializedAsync()
{
_isAuthenticated = await Auth.IsAuthenticated();

if (_isAuthenticated)
{
var userResult = await Auth.GetUser();
if (userResult.IsSuccess)
{
_organizationId = userResult.Value.OrganizationID;
}
}
else
{
var orgResult = await DataService.GetDefaultOrganization();
if (orgResult.IsSuccess)
{
_organizationId = orgResult.Value.ID;
}
}

SetScriptContent();

await base.OnInitializedAsync();
}

private async Task CopyToClipboard(string text)
{
try
{
var result = await JsInterop.SetClipboardText(text);
if (result)
{
Toasts.ShowToast2("Script copied to clipboard", ToastType.Success);
return;
}
}
catch (Exception ex)
{
Logger.LogError(ex, "Error while copying script to clipboard.");
}
Toasts.ShowToast2("Failed to set clipboard content", ToastType.Error);
}

private void SetScriptContent()
{
_windowsScript =
$"Invoke-WebRequest -Uri '{NavMan.BaseUri}api/ClientDownloads/WindowsInstaller/{_organizationId}' -OutFile \"${{env:TEMP}}\\Install-Remotely.ps1\" -UseBasicParsing;"+
"Start-Process -FilePath 'powershell.exe' -ArgumentList (\"-executionpolicy\", \"bypass\", \"-f\", \"${env:TEMP}\\Install-Remotely.ps1\") -Verb RunAs;";

_ubuntuScript = GetLinuxScript("UbuntuInstaller-x64");

_manjaroScript = GetLinuxScript("ManjaroInstaller-x64");
}

private string GetLinuxScript(string platformId)
{
return
$"sudo rm -f /tmp/Install-Remotely.sh && " +
$"sudo wget -q -O /tmp/Install-Remotely.sh {NavMan.BaseUri}api/ClientDownloads/{platformId}/{_organizationId} && " +
$"sudo chmod +x /tmp/Install-Remotely.sh && " +
$"sudo /tmp/Install-Remotely.sh";
}
}
Loading

0 comments on commit d06c8d7

Please sign in to comment.