mirror of
https://github.com/immense/Remotely.git
synced 2025-10-26 11:27:15 +00:00
Create ScriptingController.
This commit is contained in:
parent
329ac46b52
commit
02480d8915
@ -40,7 +40,6 @@ namespace Remotely.Agent.Services
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case "winps":
|
||||
if (OSUtils.IsWindows)
|
||||
{
|
||||
@ -81,6 +80,7 @@ namespace Remotely.Agent.Services
|
||||
if (Encoding.UTF8.GetBytes(serializedResult).Length > 400000)
|
||||
{
|
||||
await SendResultsViaAjax("Bash", result);
|
||||
await hubConnection.InvokeAsync("BashResultViaAjax", commandID);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -98,6 +98,51 @@ namespace Remotely.Agent.Services
|
||||
await hubConnection.InvokeAsync("DisplayMessage", "There was an error executing the command. It has been logged on the client device.", "Error executing command.", senderConnectionID);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task ExecuteCommandFromApi(string mode, string requestID, string command, string commandID, string senderConnectionID, HubConnection hubConnection)
|
||||
{
|
||||
try
|
||||
{
|
||||
switch (mode.ToLower())
|
||||
{
|
||||
case "pscore":
|
||||
var psCoreResult = PSCore.GetCurrent(senderConnectionID).WriteInput(command, commandID);
|
||||
await SendResultsViaAjax("PSCore", psCoreResult);
|
||||
break;
|
||||
|
||||
case "winps":
|
||||
if (OSUtils.IsWindows)
|
||||
{
|
||||
var result = WindowsPS.GetCurrent(senderConnectionID).WriteInput(command, commandID);
|
||||
await SendResultsViaAjax("WinPS", result);
|
||||
}
|
||||
break;
|
||||
case "cmd":
|
||||
if (OSUtils.IsWindows)
|
||||
{
|
||||
var result = CMD.GetCurrent(senderConnectionID).WriteInput(command, commandID);
|
||||
await SendResultsViaAjax("CMD", result);
|
||||
}
|
||||
break;
|
||||
case "bash":
|
||||
if (OSUtils.IsLinux)
|
||||
{
|
||||
var result = Bash.GetCurrent(senderConnectionID).WriteInput(command, commandID);
|
||||
await SendResultsViaAjax("Bash", result);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
await hubConnection.InvokeAsync("CommandResultViaApi", commandID, requestID);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.Write(ex);
|
||||
await hubConnection.InvokeAsync("DisplayMessage", "There was an error executing the command. It has been logged on the client device.", "Error executing command.", senderConnectionID);
|
||||
}
|
||||
}
|
||||
private async Task SendResultsViaAjax(string resultType, object result)
|
||||
{
|
||||
var targetURL = ConfigService.GetConnectionInfo().Host + $"/API/Commands/{resultType}";
|
||||
|
||||
13
Server/API/ScriptingController.cs
Normal file
13
Server/API/ScriptingController.cs
Normal file
@ -0,0 +1,13 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Remotely.Server.API
|
||||
{
|
||||
[ApiController]
|
||||
public class ScriptingController : ControllerBase
|
||||
{
|
||||
}
|
||||
}
|
||||
@ -24,6 +24,7 @@ namespace Remotely.Server.Services
|
||||
}
|
||||
|
||||
public static ConcurrentDictionary<string, Device> ServiceConnections { get; } = new ConcurrentDictionary<string, Device>();
|
||||
public static ConcurrentDictionary<string, string> ApiScriptResults { get; } = new ConcurrentDictionary<string, string>();
|
||||
public IHubContext<RCBrowserSocketHub> RCBrowserHub { get; }
|
||||
private IHubContext<BrowserSocketHub> BrowserHub { get; }
|
||||
private DataService DataService { get; }
|
||||
@ -44,6 +45,7 @@ namespace Remotely.Server.Services
|
||||
var commandContext = DataService.GetCommandContext(commandID);
|
||||
return BrowserHub.Clients.Client(commandContext.SenderConnectionID).SendAsync("BashResultViaAjax", commandID, Device.ID);
|
||||
}
|
||||
|
||||
public Task Chat(string message, string senderConnectionID)
|
||||
{
|
||||
return BrowserHub.Clients.Client(senderConnectionID).SendAsync("Chat", Device.DeviceName, message);
|
||||
@ -55,7 +57,7 @@ namespace Remotely.Server.Services
|
||||
return BrowserHub.Clients.Client(commandContext.SenderConnectionID).SendAsync("CMDResultViaAjax", commandID, Device.ID);
|
||||
}
|
||||
|
||||
public Task CommandResult(GenericCommandResult result)
|
||||
public Task CommandResult(GenericCommandResult result)
|
||||
{
|
||||
result.DeviceID = Device.ID;
|
||||
var commandContext = DataService.GetCommandContext(result.CommandContextID);
|
||||
@ -64,6 +66,11 @@ namespace Remotely.Server.Services
|
||||
return BrowserHub.Clients.Client(commandContext.SenderConnectionID).SendAsync("CommandResult", result);
|
||||
}
|
||||
|
||||
public void CommandResultViaApi(string commandID, string requestID)
|
||||
{
|
||||
ApiScriptResults.AddOrUpdate(requestID, commandID, (k, v) => commandID);
|
||||
}
|
||||
|
||||
public Task DeviceCameOnline(Device device)
|
||||
{
|
||||
try
|
||||
|
||||
Loading…
Reference in New Issue
Block a user