Skip to content

Commit

Permalink
Merge master.
Browse files Browse the repository at this point in the history
  • Loading branch information
bitbound committed May 4, 2023
2 parents 1efe17d + 0857b38 commit 0381742
Show file tree
Hide file tree
Showing 23 changed files with 98 additions and 2,641 deletions.
1 change: 1 addition & 0 deletions Agent/Agent.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@

<ItemGroup>
<ProjectReference Include="..\Shared\Shared.csproj" />
<ProjectReference Include="..\submodules\Immense.RemoteControl\Immense.RemoteControl.Desktop.Native\Immense.RemoteControl.Desktop.Native.csproj" />
</ItemGroup>


Expand Down
5 changes: 2 additions & 3 deletions Agent/Services/AgentHubConnection.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
using Microsoft.AspNetCore.SignalR.Client;
using Immense.RemoteControl.Desktop.Native.Windows;
using Microsoft.AspNetCore.SignalR.Client;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Remotely.Agent.Extensions;
using Remotely.Agent.Interfaces;
using Remotely.Shared.Enums;
using Remotely.Shared.Models;
using Remotely.Shared.Services;
using Remotely.Shared.Utilities;
using Remotely.Shared.Win32;
using System;
using System.Collections.Generic;
using System.IO;
Expand Down
4 changes: 0 additions & 4 deletions Agent/Services/MacOS/DeviceInfoGeneratorMac.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@
using Remotely.Agent.Interfaces;
using Remotely.Shared.Models;
using Remotely.Shared.Services;
using Remotely.Shared.Utilities;
using Remotely.Shared.Win32;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Remotely.Agent.Services.MacOS
Expand Down
10 changes: 5 additions & 5 deletions Agent/Services/Windows/AppLauncherWin.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using Microsoft.AspNetCore.SignalR.Client;
using Immense.RemoteControl.Desktop.Native.Windows;
using Microsoft.AspNetCore.SignalR.Client;
using Microsoft.Extensions.Logging;
using Remotely.Agent.Interfaces;
using Remotely.Shared.Models;
using Remotely.Shared.Utilities;
using Remotely.Shared.Win32;
using System;
using System.Collections.Generic;
using System.Diagnostics;
Expand Down Expand Up @@ -42,7 +42,7 @@ public async Task<int> LaunchChatService(string pipeName, string userConnectionI
await hubConnection.SendAsync("DisplayMessage", $"Starting chat service.", "Starting chat service.", "bg-success", userConnectionId);
if (WindowsIdentity.GetCurrent().IsSystem)
{
var result = Win32Interop.OpenInteractiveProcess(
var result = Win32Interop.CreateInteractiveSystemProcess(
_rcBinaryPath +
$" --mode Chat" +
$" --host \"{_connectionInfo.Host}\"" +
Expand Down Expand Up @@ -114,7 +114,7 @@ public async Task LaunchRemoteControl(int targetSessionId, string sessionId, str
userConnectionId);
if (WindowsIdentity.GetCurrent().IsSystem)
{
var result = Win32Interop.OpenInteractiveProcess(
var result = Win32Interop.CreateInteractiveSystemProcess(
_rcBinaryPath +
$" --mode Unattended" +
$" --host {_connectionInfo.Host}" +
Expand Down Expand Up @@ -170,7 +170,7 @@ public async Task RestartScreenCaster(List<string> viewerIDs, string sessionId,
// Give a little time for session changing, etc.
await Task.Delay(1000);

var result = Win32Interop.OpenInteractiveProcess(_rcBinaryPath +
var result = Win32Interop.CreateInteractiveSystemProcess(_rcBinaryPath +
$" --mode Unattended" +
$" --relaunch true" +
$" --host {_connectionInfo.Host}" +
Expand Down
7 changes: 2 additions & 5 deletions Agent/Services/Windows/DeviceInfoGeneratorWin.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
using Microsoft.Extensions.Logging;
using Immense.RemoteControl.Desktop.Native.Windows;
using Microsoft.Extensions.Logging;
using Remotely.Agent.Interfaces;
using Remotely.Shared.Models;
using Remotely.Shared.Utilities;
using Remotely.Shared.Win32;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Remotely.Agent.Services.Windows
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ ImmyBot experienced explosive growth this year and we only have 4 developers whi
## Project Links
Subreddit: https://www.reddit.com/r/remotely_app/
Docker: https://hub.docker.com/r/immybot/remotely
Tutorial: https://www.youtube.com/watch?v=t-TFvr7sZ6M (Thanks, @bmcgonag!)

![image](.github/media/ask-remote.png)

Expand Down
15 changes: 15 additions & 0 deletions Remotely.sln
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Immense.RemoteControl.Share
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Immense.RemoteControl.Desktop", "submodules\Immense.RemoteControl\Immense.RemoteControl.Desktop\Immense.RemoteControl.Desktop.csproj", "{034984DC-4B47-42E9-8648-F258C40C7926}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Immense.RemoteControl.Desktop.Native", "submodules\Immense.RemoteControl\Immense.RemoteControl.Desktop.Native\Immense.RemoteControl.Desktop.Native.csproj", "{7A8378BC-8169-4A33-93C6-47C699C5E74D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -275,6 +277,18 @@ Global
{034984DC-4B47-42E9-8648-F258C40C7926}.Release|x64.Build.0 = Release|Any CPU
{034984DC-4B47-42E9-8648-F258C40C7926}.Release|x86.ActiveCfg = Release|Any CPU
{034984DC-4B47-42E9-8648-F258C40C7926}.Release|x86.Build.0 = Release|Any CPU
{7A8378BC-8169-4A33-93C6-47C699C5E74D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7A8378BC-8169-4A33-93C6-47C699C5E74D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7A8378BC-8169-4A33-93C6-47C699C5E74D}.Debug|x64.ActiveCfg = Debug|Any CPU
{7A8378BC-8169-4A33-93C6-47C699C5E74D}.Debug|x64.Build.0 = Debug|Any CPU
{7A8378BC-8169-4A33-93C6-47C699C5E74D}.Debug|x86.ActiveCfg = Debug|Any CPU
{7A8378BC-8169-4A33-93C6-47C699C5E74D}.Debug|x86.Build.0 = Debug|Any CPU
{7A8378BC-8169-4A33-93C6-47C699C5E74D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7A8378BC-8169-4A33-93C6-47C699C5E74D}.Release|Any CPU.Build.0 = Release|Any CPU
{7A8378BC-8169-4A33-93C6-47C699C5E74D}.Release|x64.ActiveCfg = Release|Any CPU
{7A8378BC-8169-4A33-93C6-47C699C5E74D}.Release|x64.Build.0 = Release|Any CPU
{7A8378BC-8169-4A33-93C6-47C699C5E74D}.Release|x86.ActiveCfg = Release|Any CPU
{7A8378BC-8169-4A33-93C6-47C699C5E74D}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -290,6 +304,7 @@ Global
{8CBED18D-64A8-44C0-8433-EE14E93B472A} = {48C738FB-359E-43DB-B338-FD7CB1CCF6A8}
{FEF0D431-EB2F-4C08-A125-8DF59AFDA525} = {48C738FB-359E-43DB-B338-FD7CB1CCF6A8}
{034984DC-4B47-42E9-8648-F258C40C7926} = {48C738FB-359E-43DB-B338-FD7CB1CCF6A8}
{7A8378BC-8169-4A33-93C6-47C699C5E74D} = {48C738FB-359E-43DB-B338-FD7CB1CCF6A8}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {EAE10B28-119B-437C-9E68-06F0EE3F968A}
Expand Down
33 changes: 33 additions & 0 deletions Server/API/HealthCheckController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Remotely.Server.Auth;
using Remotely.Server.Services;
using System.Threading.Tasks;

namespace Remotely.Server.API
{
/// <summary>
/// Can only be accessed from the local machine. The sole purpose
/// is to provide a healthcheck endpoint for Docker that exercises
/// the database connection.
/// </summary>
[Route("api/[controller]")]
[ApiController]
[ServiceFilter(typeof(LocalOnlyFilter))]
public class HealthCheckController : ControllerBase
{
private readonly IDataService _dataService;

public HealthCheckController(IDataService dataService)
{
_dataService = dataService;
}

[HttpGet]
public async Task<IActionResult> Get()
{
var orgCount = await _dataService.GetOrganizationCountAsync();
return Ok($"Organization Count: {orgCount}");
}
}
}
19 changes: 19 additions & 0 deletions Server/Auth/LocalOnlyFilter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using System.Net;

namespace Remotely.Server.Auth
{
public class LocalOnlyFilter : IAuthorizationFilter
{
public void OnAuthorization(AuthorizationFilterContext context)
{
var remoteIp = context.HttpContext.Connection.RemoteIpAddress;
if (!IPAddress.IsLoopback(remoteIp))
{
context.Result = new UnauthorizedResult();
return;
}
}
}
}
4 changes: 3 additions & 1 deletion Server/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ COPY /_immense.Remotely/Server/linux-x64/Server /app
WORKDIR /app

RUN \
apt-get -y update && \
apt-get -y install curl && \
mkdir -p /remotely-data && \
sed -i 's/DataSource=Remotely.db/DataSource=\/remotely-data\/Remotely.db/' /app/appsettings.json

Expand All @@ -23,4 +25,4 @@ RUN chmod +x "/src/DockerMain.sh"
ENTRYPOINT ["/src/DockerMain.sh"]

HEALTHCHECK --interval=5m --timeout=3s \
CMD curl -f http://localhost:5000/ || exit 1
CMD curl -f http://localhost:5000/api/healthcheck || exit 1
7 changes: 6 additions & 1 deletion Server/Dockerfile.local
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,16 @@ COPY ./DockerMain.sh .
WORKDIR /app

RUN \
apt-get -y update && \
apt-get -y install curl && \
mkdir -p /remotely-data && \
sed -i 's/DataSource=Remotely.db/DataSource=\/remotely-data\/Remotely.db/' ./appsettings.json

VOLUME "/remotely-data"

RUN chmod +x "/src/DockerMain.sh"

ENTRYPOINT ["/src/DockerMain.sh"]
ENTRYPOINT ["/src/DockerMain.sh"]

HEALTHCHECK --interval=5m --timeout=3s \
CMD curl -f http://localhost:5000/api/healthcheck || exit 1
1 change: 1 addition & 0 deletions Server/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@
services.AddTransient<IDataService, DataService>();
services.AddSingleton<IApplicationConfig, ApplicationConfig>();
services.AddScoped<ApiAuthorizationFilter>();
services.AddScoped<LocalOnlyFilter>();
services.AddScoped<ExpiringTokenFilter>();
services.AddHostedService<DbCleanupService>();
services.AddHostedService<ScriptScheduler>();
Expand Down
8 changes: 8 additions & 0 deletions Server/Services/DataService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ public interface IDataService
Task<Organization> GetOrganizationByUserName(string userName);

int GetOrganizationCount();
Task<int> GetOrganizationCountAsync();

string GetOrganizationNameById(string organizationID);

Expand Down Expand Up @@ -1399,6 +1400,13 @@ public int GetOrganizationCount()
return dbContext.Organizations.Count();
}

public async Task<int> GetOrganizationCountAsync()
{
using var dbContext = _appDbFactory.GetContext();

return await dbContext.Organizations.CountAsync();
}

public string GetOrganizationNameById(string organizationID)
{
using var dbContext = _appDbFactory.GetContext();
Expand Down
3 changes: 2 additions & 1 deletion Shared/Models/RemoteControlDtos/WindowsSessionsDto.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Remotely.Shared.Enums;
using Immense.RemoteControl.Desktop.Native.DataStructures;
using Remotely.Shared.Enums;
using System.Collections.Generic;
using System.Runtime.Serialization;

Expand Down
24 changes: 0 additions & 24 deletions Shared/Models/WindowsSession.cs

This file was deleted.

0 comments on commit 0381742

Please sign in to comment.