Add DownloadFile command.

This commit is contained in:
Jared Goodwin 2020-02-23 20:49:39 -08:00
parent c23ce15b4f
commit e43ca309e8
12 changed files with 81 additions and 15 deletions

View File

@ -112,6 +112,21 @@ namespace Remotely.Agent.Services
HubConnection.On("Chat", async (string message, string orgName, string senderConnectionID) => {
await ChatService.SendMessage(message, orgName, senderConnectionID, HubConnection);
});
HubConnection.On("DownloadFile", async (string filePath, string senderConnectionID) =>
{
filePath = filePath.Replace("\"", "");
if (!File.Exists(filePath))
{
await HubConnection.SendAsync("DisplayMessage", "File not found on remote device.", "File not found.", senderConnectionID);
return;
}
var wr = WebRequest.CreateHttp($"{ConnectionInfo.Host}/API/FileSharing/");
var wc = new WebClient();
var response = await wc.UploadFileTaskAsync($"{ConnectionInfo.Host}/API/FileSharing/", filePath);
var fileIDs = JsonSerializer.Deserialize<string[]>(Encoding.UTF8.GetString(response));
await HubConnection.SendAsync("DownloadFile", fileIDs[0], senderConnectionID);
});
HubConnection.On("ExecuteCommand", (async (string mode, string command, string commandID, string senderConnectionID) =>
{
if (!IsServerVerified)

View File

@ -79,6 +79,16 @@ namespace Remotely.Server.Services
return Task.CompletedTask;
}
public Task DownloadFile(string filePath, string deviceID)
{
if (DataService.DoesUserHaveAccessToDevice(deviceID, RemotelyUser))
{
var targetDevice = DeviceSocketHub.ServiceConnections.FirstOrDefault(x => x.Value.ID == deviceID);
DeviceHub.Clients.Client(targetDevice.Key).SendAsync("DownloadFile", filePath, Context.ConnectionId);
}
return Task.CompletedTask;
}
public Task ExecuteCommandOnClient(string mode, string command, string[] deviceIDs)
{
deviceIDs = DataService.FilterDeviceIDsByUserPermission(deviceIDs, RemotelyUser);

View File

@ -138,7 +138,11 @@ namespace Remotely.Server.Services
{
return BrowserHub.Clients.Client(requesterID).SendAsync("DisplayMessage", consoleMessage, popupMessage);
}
public override Task OnConnectedAsync()
public Task DownloadFile(string fileID, string requesterID)
{
return BrowserHub.Clients.Client(requesterID).SendAsync("DownloadFile", fileID);
}
public override Task OnConnectedAsync()
{
return base.OnConnectedAsync();
}

View File

@ -82,6 +82,9 @@ function applyMessageHandlers(hubConnection) {
hubConnection.on("DisplayConsoleHTML", (message) => {
AddConsoleHTML(message);
});
hubConnection.on("DownloadFile", (fileID) => {
location.assign(`/API/FileSharing/${fileID}`);
});
hubConnection.on("TransferCompleted", (transferID) => {
var completedWrapper = document.getElementById(transferID + "-completed");
var count = parseInt(completedWrapper.innerHTML);

File diff suppressed because one or more lines are too long

View File

@ -97,7 +97,9 @@ function applyMessageHandlers(hubConnection) {
hubConnection.on("DisplayConsoleHTML", (message: string) => {
AddConsoleHTML(message);
});
hubConnection.on("DownloadFile", (fileID: string) => {
location.assign(`/API/FileSharing/${fileID}`);
});
hubConnection.on("TransferCompleted", (transferID: string) => {
var completedWrapper = document.getElementById(transferID + "-completed");
var count = parseInt(completedWrapper.innerHTML);

View File

@ -137,19 +137,21 @@ export function ExtractParameters(commandText) {
if (startParams == -1) {
return parameterArray;
}
commandText.substr(startParams).trim().split("-").forEach(x => {
commandText.substr(startParams).trim().split(" -").forEach(x => {
if (x.trim().length == 0) {
return;
}
var kv = x.trim();
var key = "";
var value = "";
if (x.indexOf(" ") == -1 || x.substr(x.indexOf(" ")).trim().length == 0) {
key = x.trim();
if (kv.indexOf(" ") == -1 || kv.substr(kv.indexOf(" ")).trim().length == 0) {
key = kv;
}
else {
key = x.substr(0, x.indexOf(" "));
value = x.substr(x.indexOf(" ")).trim();
key = kv.substr(0, kv.indexOf(" "));
value = kv.substr(kv.indexOf(" ")).trim();
}
key = key.replace("-", "");
parameterArray.push(new CommandLineParameter(key, value));
});
return parameterArray;

File diff suppressed because one or more lines are too long

View File

@ -149,19 +149,21 @@ export function ExtractParameters(commandText: string): Array<CommandLineParamet
if (startParams == -1) {
return parameterArray;
}
commandText.substr(startParams).trim().split("-").forEach(x => {
commandText.substr(startParams).trim().split(" -").forEach(x => {
if (x.trim().length == 0) {
return;
}
var kv = x.trim();
var key = "";
var value = "";
if (x.indexOf(" ") == -1 || x.substr(x.indexOf(" ")).trim().length == 0) {
key = x.trim();
if (kv.indexOf(" ") == -1 || kv.substr(kv.indexOf(" ")).trim().length == 0) {
key = kv;
}
else {
key = x.substr(0, x.indexOf(" "));
value = x.substr(x.indexOf(" ")).trim();
key = kv.substr(0, kv.indexOf(" "));
value = kv.substr(kv.indexOf(" ")).trim();
}
key = key.replace("-", "");
parameterArray.push(new CommandLineParameter(key, value));
});

View File

@ -44,6 +44,17 @@ var commands = [
};
fileInput.click();
}),
new ConsoleCommand("DownloadFile", [
new Parameter("path", "The path on the remote computer of the file to download.", "String"),
], "Download a file from the remote computer.", `DownloadFile -path "C:\Users\Me\Pictures\ThatFunnyPic.png"`, "", (parameters, paramDictionary) => {
var selectedDevices = Main.DataGrid.GetSelectedDevices();
if (selectedDevices.length == 0) {
AddConsoleOutput("No devices are selected.");
return;
}
;
BrowserSockets.Connection.invoke("DownloadFile", paramDictionary["path"], selectedDevices[0].ID);
}),
new ConsoleCommand("GetLogs", [], "Retrieve the logs from the remote agent.", "GetLogs", "", (parameters, paramDictionary) => {
var selectedDevices = Main.DataGrid.GetSelectedDevices();
if (selectedDevices.length == 0) {

File diff suppressed because one or more lines are too long

View File

@ -62,6 +62,23 @@ var commands: Array<ConsoleCommand> = [
fileInput.click();
}
),
new ConsoleCommand(
"DownloadFile",
[
new Parameter("path", "The path on the remote computer of the file to download.", "String"),
],
"Download a file from the remote computer.",
`DownloadFile -path "C:\Users\Me\Pictures\ThatFunnyPic.png"`,
"",
(parameters, paramDictionary) => {
var selectedDevices = Main.DataGrid.GetSelectedDevices();
if (selectedDevices.length == 0) {
AddConsoleOutput("No devices are selected.");
return;
};
BrowserSockets.Connection.invoke("DownloadFile", paramDictionary["path"], selectedDevices[0].ID);
}
),
new ConsoleCommand(
"GetLogs",
[