Create scripting controller.

This commit is contained in:
Jared Goodwin 2020-02-02 09:03:36 -08:00
parent 6662a48a13
commit a4fd12c597
3 changed files with 35 additions and 2 deletions

View File

@ -114,6 +114,17 @@ namespace Remotely.Agent.Services
await CommandExecutor.ExecuteCommand(mode, command, commandID, senderConnectionID, HubConnection);
}));
HubConnection.On("ExecuteCommandFromApi", (async (string mode, string requesterID, string command, string commandID, string senderConnectionID) =>
{
if (!IsServerVerified)
{
Logger.Write($"Command attempted before server was verified. Mode: {mode}. Command: {command}. Sender: {senderConnectionID}");
Uninstaller.UninstallAgent();
return;
}
await CommandExecutor.ExecuteCommandFromApi(mode, requesterID, command, commandID, senderConnectionID, HubConnection);
}));
HubConnection.On("TransferFiles", async (string transferID, List<string> fileIDs, string requesterID) =>
{
Logger.Write($"File transfer started by {requesterID}.");

View File

@ -9,5 +9,28 @@ namespace Remotely.Server.API
[ApiController]
public class ScriptingController : ControllerBase
{
//public Task ExecuteCommand(string mode, string command, string[] deviceIDs)
//{
// deviceIDs = DataService.FilterDeviceIDsByUserPermission(deviceIDs, RemotelyUser);
// var connections = GetActiveClientConnections(deviceIDs);
// var commandContext = new CommandContext()
// {
// CommandMode = mode,
// CommandText = command,
// SenderConnectionID = Context.ConnectionId,
// SenderUserID = Context.UserIdentifier,
// TargetDeviceIDs = connections.Select(x => x.Value.ID).ToArray(),
// OrganizationID = RemotelyUser.OrganizationID
// };
// DataService.AddOrUpdateCommandContext(commandContext);
// Clients.Caller.SendAsync("CommandContextCreated", commandContext);
// foreach (var connection in connections)
// {
// DeviceHub.Clients.Client(connection.Key).SendAsync("ExecuteCommand", mode, command, commandContext.ID, Context.ConnectionId);
// }
// return Task.CompletedTask;
//}
}
}

View File

@ -102,8 +102,7 @@ namespace Remotely.Server.Services
return Task.CompletedTask;
}
public override async Task OnConnectedAsync()
public override async Task OnConnectedAsync()
{
RemotelyUser = DataService.GetUserByID(Context.UserIdentifier);
if (await IsConnectionValid() == false)