Skip to content

Commit

Permalink
Merge in abstractions in Server project. Remove unneeded RemoteContro…
Browse files Browse the repository at this point in the history
…lSessionLimit.
  • Loading branch information
bitbound committed Jul 16, 2024
1 parent 81641af commit 9e055af
Show file tree
Hide file tree
Showing 33 changed files with 283 additions and 877 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ All other configuration is done in the Server Config page once you're logged in.
- Set this to -1 or increase it to a specific number to allow multi-tenancy.
- RedirectToHttps: Whether ASP.NET Core will redirect all traffic from HTTP to HTTPS. This is independent of Caddy, Nginx, and IIS configurations that do the same.
- RemoteControlNotifyUsers: Whether to show a notification to the end user when an unattended remote control session starts.
- RemoteControlSessionLimit: How many concurrent remote control sessions are allowed per organization.
- RemoteControlRequiresAuthentication: Whether the remote control page requires authentication to establish a connection.
- Require2FA: Require users to set up 2FA before they can use the main app.
- Smpt-: SMTP settings for auto-generated system emails (such as registration and password reset).
Expand Down
25 changes: 4 additions & 21 deletions Server/API/RemoteControlController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using Remotely.Server.Models;
using Remotely.Server.Services;
using Remotely.Server.Auth;
using Remotely.Server.Abstractions;
using Remotely.Shared.Helpers;
using Remotely.Server.Extensions;
using Remotely.Shared.Entities;
Expand All @@ -24,7 +23,6 @@ public class RemoteControlController : ControllerBase
private readonly IAgentHubSessionCache _serviceSessionCache;
private readonly IDataService _dataService;
private readonly IOtpProvider _otpProvider;
private readonly IHubEventHandler _hubEvents;
private readonly SignInManager<RemotelyUser> _signInManager;
private readonly ILogger<RemoteControlController> _logger;

Expand All @@ -35,15 +33,13 @@ public RemoteControlController(
IHubContext<AgentHub, IAgentHubClient> agentHub,
IAgentHubSessionCache serviceSessionCache,
IOtpProvider otpProvider,
IHubEventHandler hubEvents,
ILogger<RemoteControlController> logger)
{
_dataService = dataService;
_agentHub = agentHub;
_remoteControlSessionCache = remoteControlSessionCache;
_serviceSessionCache = serviceSessionCache;
_otpProvider = otpProvider;
_hubEvents = hubEvents;
_signInManager = signInManager;
_logger = logger;
}
Expand Down Expand Up @@ -134,20 +130,12 @@ private async Task<IActionResult> InitiateRemoteControl(string deviceID, string
}
}

var sessionCount = _remoteControlSessionCache.Sessions
.OfType<RemoteControlSessionEx>()
.Count(x => x.OrganizationId == orgId);

var settings = await _dataService.GetSettings();
if (sessionCount > settings.RemoteControlSessionLimit)
{
return BadRequest("There are already the maximum amount of active remote control sessions for your organization.");
}
var sessionCount = _remoteControlSessionCache.Sessions.Count(x => x.OrganizationId == orgId);

var sessionId = Guid.NewGuid();
var accessKey = RandomGenerator.GenerateAccessKey();

var session = new RemoteControlSessionEx()
var session = new RemoteControlSession()
{
UnattendedSessionId = sessionId,
UserConnectionId = HttpContext.Connection.Id,
Expand All @@ -158,13 +146,8 @@ private async Task<IActionResult> InitiateRemoteControl(string deviceID, string

_remoteControlSessionCache.AddOrUpdate($"{sessionId}", session, (k, v) =>
{
if (v is RemoteControlSessionEx ex)
{
ex.AgentConnectionId = HttpContext.Connection.Id;
return ex;
}
v.Dispose();
return session;
v.AgentConnectionId = HttpContext.Connection.Id;
return v;
});

var orgNameResult = await _dataService.GetOrganizationNameById(orgId);
Expand Down
94 changes: 0 additions & 94 deletions Server/Abstractions/IHubEventHandler.cs

This file was deleted.

26 changes: 0 additions & 26 deletions Server/Abstractions/ISessionRecordingSink.cs

This file was deleted.

26 changes: 0 additions & 26 deletions Server/Abstractions/IViewerAuthorizer.cs

This file was deleted.

18 changes: 0 additions & 18 deletions Server/Abstractions/IViewerOptionsProvider.cs

This file was deleted.

20 changes: 0 additions & 20 deletions Server/Abstractions/IViewerPageDataProvider.cs

This file was deleted.

21 changes: 7 additions & 14 deletions Server/Components/Devices/Terminal.razor.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
using Remotely.Server.Abstractions;
using Bitbound.SimpleMessenger;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Rendering;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.Extensions.Logging;
using Remotely.Server.Components.ModalContents;
using Remotely.Server.Hubs;
using Remotely.Server.Models.Messages;
Expand All @@ -13,10 +10,6 @@
using Remotely.Shared.Enums;
using Remotely.Shared.Models;
using Remotely.Shared.Utilities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Remotely.Server.Components.Devices;

Expand Down Expand Up @@ -122,7 +115,7 @@ private void ApplyCompletion(PwshCommandCompletion completion)
var match = completion.CompletionMatches[completion.CurrentMatchIndex];

var replacementText = string.Concat(
_lastCompletionInput.Substring(0, completion.ReplacementIndex),
_lastCompletionInput[..completion.ReplacementIndex],
match.CompletionText,
_lastCompletionInput[(completion.ReplacementIndex + completion.ReplacementLength)..]);

Expand Down Expand Up @@ -170,7 +163,7 @@ private void EvaluateInputKeypress(KeyboardEventArgs ev)
}

var devices = CardStore.SelectedDevices.ToArray();
if (!devices.Any())
if (devices.Length == 0)
{
ToastService.ShowToast("You must select at least one device.", classString: "bg-warning");
return;
Expand Down Expand Up @@ -281,7 +274,7 @@ private async Task ShowQuickScripts()
EnsureUserSet();

var quickScripts = await DataService.GetQuickScripts(User.Id);
if (quickScripts?.Any() != true)
if (quickScripts.Count == 0)
{
ToastService.ShowToast("No quick scripts saved.", classString: "bg-warning");
return;
Expand All @@ -307,8 +300,8 @@ void showModal(RenderTreeBuilder builder)

private void ShowTerminalHelp()
{
ModalService.ShowModal("Terminal Help", new[]
{
ModalService.ShowModal("Terminal Help",
[
"Enter terminal commands that will execute on all selected devices.",

"Tab completion is available for PowerShell Core (PSCore) and Windows PowerShell (WinPS). Tab and Shift + Tab " +
Expand All @@ -324,7 +317,7 @@ private void ShowTerminalHelp()

"Note: The first PS Core command or tab completion takes a few moments while the service is " +
"starting on the remote device."
});
]);
}

private async void TerminalStore_TerminalLinesChanged(object? sender, EventArgs e)
Expand Down
3 changes: 0 additions & 3 deletions Server/Components/ModalHarness.razor
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@
</div>

@code {
private string? _showClass;
private string? _displayStyle;

private IJSObjectReference? _module;
private ElementReference _modalRef;

Expand Down
7 changes: 0 additions & 7 deletions Server/Components/Pages/ServerConfig.razor
Original file line number Diff line number Diff line change
Expand Up @@ -215,13 +215,6 @@
<br />
<ValidationMessage For="() => Input.RemoteControlRequiresAuthentication" />
</div>
<div class="form-group">
<label class="control-label">Remote Control Session Limit</label>
<br />
<InputNumber @bind-Value="Input.RemoteControlSessionLimit" class="form-control" autocomplete="off" />
<br />
<ValidationMessage For="() => Input.RemoteControlSessionLimit" />
</div>
<div class="form-group">
<label>Require 2FA</label>
<br />
Expand Down
11 changes: 1 addition & 10 deletions Server/Components/Scripts/RunScript.razor.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,11 @@
using Remotely.Server.Abstractions;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.SignalR;
using Remotely.Server.Components.Pages;
using Remotely.Server.Hubs;
using Remotely.Server.Migrations.PostgreSql;
using Remotely.Server.Migrations.Sqlite;
using Remotely.Server.Migrations.SqlServer;
using Remotely.Server.Services;
using Remotely.Shared.Entities;
using Remotely.Shared.Enums;
using Remotely.Shared.Utilities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Remotely.Server.Components.Scripts;

Expand Down
Loading

0 comments on commit 9e055af

Please sign in to comment.