Skip to content

Commit

Permalink
Add support request desktop shortcut.
Browse files Browse the repository at this point in the history
  • Loading branch information
bitbound committed Apr 30, 2020
1 parent a6f2acf commit 911d2ef
Show file tree
Hide file tree
Showing 17 changed files with 232 additions and 27 deletions.
11 changes: 11 additions & 0 deletions Agent.Installer.Win/Agent.Installer.Win.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,17 @@
<ItemGroup>
<Resource Include="Assets\Remotely_Icon.png" />
</ItemGroup>
<ItemGroup>
<COMReference Include="IWshRuntimeLibrary">
<Guid>{F935DC20-1CF0-11D0-ADB9-00C04FD58A0B}</Guid>
<VersionMajor>1</VersionMajor>
<VersionMinor>0</VersionMinor>
<Lcid>0</Lcid>
<WrapperTool>tlbimp</WrapperTool>
<Isolated>False</Isolated>
<EmbedInteropTypes>True</EmbedInteropTypes>
</COMReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>if $(ConfigurationName) == Debug (
Expand Down
54 changes: 39 additions & 15 deletions Agent.Installer.Win/Services/InstallerService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.VisualBasic.FileIO;
using IWshRuntimeLibrary;
using Microsoft.VisualBasic.FileIO;
using Microsoft.Win32;
using Remotely.Shared.Models;
using System;
Expand All @@ -15,6 +16,7 @@
using System.Threading.Tasks;
using System.Web.Script.Serialization;
using System.Windows;
using FileIO = System.IO.File;

namespace Remotely.Agent.Installer.Win.Services
{
Expand Down Expand Up @@ -55,9 +57,9 @@ public async Task<bool> Install(string serverUrl,

await DownloadRemotelyAgent(serverUrl);

File.WriteAllText(Path.Combine(InstallPath, "ConnectionInfo.json"), Serializer.Serialize(connectionInfo));
FileIO.WriteAllText(Path.Combine(InstallPath, "ConnectionInfo.json"), Serializer.Serialize(connectionInfo));

File.Copy(Assembly.GetExecutingAssembly().Location, Path.Combine(InstallPath, "Remotely_Installer.exe"));
FileIO.Copy(Assembly.GetExecutingAssembly().Location, Path.Combine(InstallPath, "Remotely_Installer.exe"));

CreateDeviceSetupOptions(deviceGroup, deviceAlias);

Expand All @@ -66,6 +68,8 @@ public async Task<bool> Install(string serverUrl,
InstallService();

CreateUninstallKey();

CreateSupportShortcut(serverUrl, deviceUuid);

return true;
}
Expand All @@ -78,6 +82,26 @@ public async Task<bool> Install(string serverUrl,

}

private void CreateSupportShortcut(string serverUrl, string deviceUuid)
{
var systemRoot = Path.GetPathRoot(Environment.SystemDirectory);
var shortcutLocation = Path.Combine(systemRoot, "Users", "Public", "Desktop", "Get Support.lnk");
var shell = new WshShell();
var shortcut = (IWshShortcut)shell.CreateShortcut(shortcutLocation);
shortcut.Description = "Get IT support";
shortcut.IconLocation = Path.Combine(InstallPath, "Remotely_Agent.exe");
shortcut.TargetPath = serverUrl.TrimEnd('/') + $"/GetSupport?deviceID={deviceUuid}";
shortcut.Save();


shortcutLocation = Path.Combine(InstallPath, "Get Support.lnk");
shortcut = (IWshShortcut)shell.CreateShortcut(shortcutLocation);
shortcut.Description = "Get IT support";
shortcut.IconLocation = Path.Combine(InstallPath, "Remotely_Agent.exe");
shortcut.TargetPath = serverUrl.TrimEnd('/') + $"/GetSupport?deviceID={deviceUuid}";
shortcut.Save();
}

public async Task<bool> Uninstall()
{
try
Expand Down Expand Up @@ -124,9 +148,9 @@ private void BackupDirectory()
Logger.Write("Backing up current installation.");
ProgressMessageChanged?.Invoke(this, "Backing up current installation.");
var backupPath = Path.Combine(Path.GetTempPath(), "Remotely_Backup.zip");
if (File.Exists(backupPath))
if (FileIO.Exists(backupPath))
{
File.Delete(backupPath);
FileIO.Delete(backupPath);
}
ZipFile.CreateFromDirectory(InstallPath, backupPath, CompressionLevel.Fastest, false);
}
Expand All @@ -152,9 +176,9 @@ private void ClearInstallDirectory()
{
try
{
if (File.Exists(entry))
if (FileIO.Exists(entry))
{
File.Delete(entry);
FileIO.Delete(entry);
}
else if (Directory.Exists(entry))
{
Expand All @@ -180,7 +204,7 @@ private void CreateDeviceSetupOptions(string deviceGroup, string deviceAlias)
DeviceAlias = deviceAlias
};

File.WriteAllText(Path.Combine(InstallPath, "DeviceSetupOptions.json"), Serializer.Serialize(setupOptions));
FileIO.WriteAllText(Path.Combine(InstallPath, "DeviceSetupOptions.json"), Serializer.Serialize(setupOptions));
}
}

Expand All @@ -207,7 +231,7 @@ private async Task DownloadRemotelyAgent(string serverUrl)

if (CommandLineParser.CommandLineArgs.TryGetValue("path", out var result))
{
File.Copy(result, targetFile, true);
FileIO.Copy(result, targetFile, true);
}
else
{
Expand Down Expand Up @@ -239,7 +263,7 @@ private async Task DownloadRemotelyAgent(string serverUrl)
var wr = WebRequest.CreateHttp($"{serverUrl}/Downloads/Remotely-Win10-{Platform}.zip");
wr.Method = "Head";
var response = (HttpWebResponse)await wr.GetResponseAsync();
File.WriteAllText(Path.Combine(InstallPath, "etag.txt"), response.Headers["ETag"]);
FileIO.WriteAllText(Path.Combine(InstallPath, "etag.txt"), response.Headers["ETag"]);

ZipFile.ExtractToDirectory(targetFile, tempDir);
var fileSystemEntries = Directory.GetFileSystemEntries(tempDir);
Expand All @@ -249,9 +273,9 @@ private async Task DownloadRemotelyAgent(string serverUrl)
{
ProgressValueChanged?.Invoke(this, (int)((double)i / (double)fileSystemEntries.Length * 100d));
var entry = fileSystemEntries[i];
if (File.Exists(entry))
if (FileIO.Exists(entry))
{
File.Copy(entry, Path.Combine(InstallPath, Path.GetFileName(entry)), true);
FileIO.Copy(entry, Path.Combine(InstallPath, Path.GetFileName(entry)), true);
}
else if (Directory.Exists(entry))
{
Expand All @@ -271,9 +295,9 @@ private ConnectionInfo GetConnectionInfo(string organizationId, string serverUrl
{
ConnectionInfo connectionInfo;
var connectionInfoPath = Path.Combine(InstallPath, "ConnectionInfo.json");
if (File.Exists(connectionInfoPath))
if (FileIO.Exists(connectionInfoPath))
{
connectionInfo = Serializer.Deserialize<ConnectionInfo>(File.ReadAllText(connectionInfoPath));
connectionInfo = Serializer.Deserialize<ConnectionInfo>(FileIO.ReadAllText(connectionInfoPath));
connectionInfo.ServerVerificationToken = null;
}
else
Expand Down Expand Up @@ -393,7 +417,7 @@ private void RestoreBackup()
try
{
var backupPath = Path.Combine(Path.GetTempPath(), "Remotely_Backup.zip");
if (File.Exists(backupPath))
if (FileIO.Exists(backupPath))
{
Logger.Write("Restoring backup.");
ClearInstallDirectory();
Expand Down
2 changes: 1 addition & 1 deletion Server/API/AlertsController.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Microsoft.AspNetCore.Mvc;
using Remotely.Server.Auth;
using Remotely.Server.Attributes;
using Remotely.Server.Services;
using Remotely.Shared.Models;
using System;
Expand Down
2 changes: 1 addition & 1 deletion Server/API/ClientDownloadsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Hosting;
using Remotely.Server.Services;
using Remotely.Server.Auth;
using System.Text;
using Microsoft.Extensions.Configuration;
using System.Threading;
using Remotely.Server.Attributes;

namespace Remotely.Server.API
{
Expand Down
2 changes: 1 addition & 1 deletion Server/API/CommandsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using Remotely.Shared.Models;
using Remotely.Server.Services;
using Microsoft.AspNetCore.Mvc;
using Remotely.Server.Auth;
using Remotely.Server.Attributes;

// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860

Expand Down
2 changes: 1 addition & 1 deletion Server/API/DevicesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using Remotely.Server.Services;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Remotely.Server.Auth;
using Remotely.Server.Attributes;

// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860

Expand Down
2 changes: 1 addition & 1 deletion Server/API/OrganizationManagementController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using Remotely.Shared.ViewModels.Organization;
using System.Text;
using Microsoft.AspNetCore.WebUtilities;
using Remotely.Server.Auth;
using Remotely.Server.Attributes;

// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860

Expand Down
2 changes: 1 addition & 1 deletion Server/API/RemoteControlController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
using Remotely.Shared.Models;
using Remotely.Server.Models;
using Remotely.Server.Services;
using Remotely.Server.Auth;
using Remotely.Server.Attributes;
using Remotely.Shared.Helpers;

// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
Expand Down
2 changes: 1 addition & 1 deletion Server/API/ScriptingController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
using System.Threading.Tasks;
using Remotely.Shared.Helpers;
using System.IO;
using Remotely.Server.Auth;
using Remotely.Server.Attributes;

namespace Remotely.Server.API
{
Expand Down
2 changes: 1 addition & 1 deletion Server/API/ServerLogsController.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Text;
using System.Text.Json;
using Microsoft.AspNetCore.Mvc;
using Remotely.Server.Auth;
using Remotely.Server.Attributes;
using Remotely.Server.Services;

namespace Remotely.Server.API
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Remotely.Server.Auth;
using Remotely.Server.Services;
using Remotely.Shared.Models;
using Remotely.Shared.Utilities;

namespace Remotely.Server.Areas.Identity.Pages.Account.Manage
{
Expand Down
35 changes: 35 additions & 0 deletions Server/Attributes/ActionRateLimiterAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.Extensions.Caching.Memory;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Threading.Tasks;

namespace Remotely.Server.Attributes
{
[AttributeUsage(AttributeTargets.Method)]
public class ActionRateLimiterAttribute : ActionFilterAttribute
{
public string Action { get; set; }
public int TimeoutInSeconds { get; set; } = 5;
private static MemoryCache RequestCache { get; } = new MemoryCache(new MemoryCacheOptions());


public override void OnActionExecuting(ActionExecutingContext context)
{
var ip = context.HttpContext.Request.HttpContext.Connection.RemoteIpAddress;
var key = $"Action-{ip}";

if (!RequestCache.TryGetValue(key, out _))
{
RequestCache.Set(key, true, TimeSpan.FromSeconds(TimeoutInSeconds));
}
else
{
context.HttpContext.Response.StatusCode = (int)HttpStatusCode.TooManyRequests;
}
base.OnActionExecuting(context);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using Microsoft.AspNetCore.Mvc.Filters;
using Remotely.Server.Services;

namespace Remotely.Server.Auth
namespace Remotely.Server.Attributes
{
public class ApiAuthorizationFilter : ActionFilterAttribute, IAuthorizationFilter
{
Expand Down
68 changes: 68 additions & 0 deletions Server/Pages/GetSupport.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
@page
@model Remotely.Server.Pages.GetSupportModel
@{
ViewData["Title"] = "Get Support";
}

@if (!Request.Query.ContainsKey("deviceUuid"))
{
<h3 class="mb-3">Get Support</h3>
<p>
Device ID is missing. Please use a valid shortcut to the support page, which will include the device ID.
</p>
}
else
{
<div class="col-sm-6 offset-sm-3">
@if (!string.IsNullOrWhiteSpace(Model.StatusMessage))
{
<div class="alert alert-success alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
@Model.StatusMessage
</div>
}
<h3 class="mb-3">Get Support</h3>
<form method="post">
<div asp-validation-summary="All" class="text-danger"></div>
<div class="form-group">
<label class="col-form-label">Your Name:</label>
<br />
<input type="text" class="form-control" asp-for="Input.Name" />
<span asp-validation-for="Input.Name" class="text-danger"></span>
</div>
<div class="form-group">
<label class="col-form-label">Email:</label>
<br />
<input type="email" class="form-control" asp-for="Input.Email" />
<span asp-validation-for="Input.Email" class="text-danger"></span>
</div>
<div class="form-group">
<label class="col-form-label">Phone:</label>
<br />
<input type="tel" class="form-control" asp-for="Input.Phone" />
<span asp-validation-for="Input.Phone" class="text-danger"></span>
</div>
<div class="form-group">
<label class="col-form-label">Chat Response OK?</label>
<br />
<input type="checkbox" checked="checked" asp-for="Input.ChatResponseOk" />
<span asp-validation-for="Input.ChatResponseOk" class="text-danger"></span>
</div>
<div class="text-right">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</form>
</div>

<style>
input[type='checkbox'] {
width: 25px;
height: 25px;
}
</style>

@section Scripts {
<partial name="_ValidationScriptsPartial" />
}

}
Loading

0 comments on commit 911d2ef

Please sign in to comment.