mirror of
https://github.com/immense/Remotely.git
synced 2025-10-26 11:27:15 +00:00
Add organization name to chat service.
This commit is contained in:
parent
9c5f57e616
commit
29f01e1925
@ -385,6 +385,11 @@ namespace Remotely.Agent.Installer.Win.Services
|
||||
Logger.Write("Restoring backup.");
|
||||
ClearInstallDirectory();
|
||||
ZipFile.ExtractToDirectory(backupPath, InstallPath);
|
||||
var serv = ServiceController.GetServices().FirstOrDefault(ser => ser.ServiceName == "Remotely_Service");
|
||||
if (serv?.Status != ServiceControllerStatus.Running)
|
||||
{
|
||||
serv?.Start();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
@ -21,7 +21,7 @@ namespace Remotely.Agent.Services
|
||||
|
||||
private ConnectionInfo ConnectionInfo { get; }
|
||||
|
||||
public async Task<int> LaunchChatService(string requesterID, HubConnection hubConnection)
|
||||
public async Task<int> LaunchChatService(string orgName, string requesterID, HubConnection hubConnection)
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -39,11 +39,11 @@ namespace Remotely.Agent.Services
|
||||
|
||||
if (Program.IsDebug)
|
||||
{
|
||||
return Process.Start("conhost.exe", $"{rcBinaryPath} -mode Chat -requester {requesterID}").Id;
|
||||
return Process.Start(rcBinaryPath, $"-mode Chat -requester {requesterID} -organization \"{orgName}\"").Id;
|
||||
}
|
||||
else
|
||||
{
|
||||
var result = Win32Interop.OpenInteractiveProcess($"{rcBinaryPath} -mode Chat -requester {requesterID}", "default", false, out var procInfo);
|
||||
var result = Win32Interop.OpenInteractiveProcess($"{rcBinaryPath} -mode Chat -requester {requesterID} -organization \"{orgName}\"", "default", false, out var procInfo);
|
||||
if (!result)
|
||||
{
|
||||
await hubConnection.InvokeAsync("DisplayMessage", "Remote control failed to start on target device.", "Failed to start remote control.", requesterID);
|
||||
@ -56,7 +56,7 @@ namespace Remotely.Agent.Services
|
||||
}
|
||||
else if (OSUtils.IsLinux)
|
||||
{
|
||||
var args = $"xterm -e {rcBinaryPath} -mode Chat -requester {requesterID} & disown";
|
||||
var args = $"xterm -e {rcBinaryPath} -mode Chat -requester {requesterID} -organization \"{orgName}\" & disown";
|
||||
return StartLinuxScreenCaster(args);
|
||||
}
|
||||
}
|
||||
|
||||
@ -35,7 +35,7 @@ namespace Remotely.Agent.Services
|
||||
};
|
||||
|
||||
private MemoryCache ChatClients { get; } = new MemoryCache("ChatClients");
|
||||
public async Task SendMessage(string message, string senderConnectionID, HubConnection hubConnection)
|
||||
public async Task SendMessage(string message, string orgName, string senderConnectionID, HubConnection hubConnection)
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -45,7 +45,7 @@ namespace Remotely.Agent.Services
|
||||
if (!ChatClients.Contains(senderConnectionID))
|
||||
{
|
||||
var rcBinaryPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ScreenCast", OSUtils.ScreenCastExecutableFileName);
|
||||
var procID = await AppLauncher.LaunchChatService(senderConnectionID, hubConnection);
|
||||
var procID = await AppLauncher.LaunchChatService(orgName, senderConnectionID, hubConnection);
|
||||
|
||||
var clientPipe = new NamedPipeClientStream(".", "Remotely_Chat" + senderConnectionID, PipeDirection.InOut, PipeOptions.Asynchronous);
|
||||
clientPipe.Connect(15000);
|
||||
|
||||
@ -109,8 +109,8 @@ namespace Remotely.Agent.Services
|
||||
|
||||
private void RegisterMessageHandlers()
|
||||
{
|
||||
HubConnection.On("Chat", async (string message, string senderConnectionID) => {
|
||||
await ChatService.SendMessage(message, senderConnectionID, HubConnection);
|
||||
HubConnection.On("Chat", async (string message, string orgName, string senderConnectionID) => {
|
||||
await ChatService.SendMessage(message, orgName, senderConnectionID, HubConnection);
|
||||
});
|
||||
HubConnection.On("ExecuteCommand", (async (string mode, string command, string commandID, string senderConnectionID) =>
|
||||
{
|
||||
|
||||
@ -34,9 +34,11 @@ namespace Remotely.ScreenCast.Core
|
||||
public string DeviceID { get; private set; }
|
||||
public string Host { get; private set; }
|
||||
public AppMode Mode { get; private set; }
|
||||
public string OrganizationName { get; private set; }
|
||||
public string RequesterID { get; private set; }
|
||||
public string ServiceID { get; private set; }
|
||||
public ConcurrentDictionary<string, Viewer> Viewers { get; } = new ConcurrentDictionary<string, Viewer>();
|
||||
|
||||
public async Task Connect()
|
||||
{
|
||||
await CasterSocket.Connect(Host);
|
||||
@ -48,35 +50,66 @@ namespace Remotely.ScreenCast.Core
|
||||
|
||||
for (var i = 0; i < args.Length; i += 2)
|
||||
{
|
||||
var key = args?[i];
|
||||
if (key != null)
|
||||
try
|
||||
{
|
||||
key = key.Trim().Replace("-", "").ToLower();
|
||||
var value = args?[i + 1];
|
||||
if (value != null)
|
||||
var key = args?[i];
|
||||
if (key != null)
|
||||
{
|
||||
ArgDict[key] = args[i + 1].Trim();
|
||||
if (!key.Contains("-"))
|
||||
{
|
||||
Logger.Write("Command line arguments are invalid.");
|
||||
i -= 1;
|
||||
continue;
|
||||
}
|
||||
key = key.Trim().Replace("-", "").ToLower();
|
||||
if (i + 1 == args.Length)
|
||||
{
|
||||
ArgDict.Add(key, "true");
|
||||
continue;
|
||||
}
|
||||
var value = args?[i + 1];
|
||||
if (value != null)
|
||||
{
|
||||
if (value.StartsWith("-"))
|
||||
{
|
||||
ArgDict.Add(key, "true");
|
||||
i -= 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
ArgDict.Add(key, args[i + 1].Trim());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.Write(ex);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Mode = (AppMode)Enum.Parse(typeof(AppMode), ArgDict["mode"], true);
|
||||
|
||||
if (Mode == AppMode.Normal || Mode == AppMode.Unattended)
|
||||
if (ArgDict.TryGetValue("host", out var host))
|
||||
{
|
||||
Host = ArgDict["host"];
|
||||
Host = host;
|
||||
}
|
||||
|
||||
if (Mode == AppMode.Chat || Mode == AppMode.Unattended)
|
||||
if (ArgDict.TryGetValue("requester", out var requester))
|
||||
{
|
||||
RequesterID = ArgDict["requester"];
|
||||
RequesterID = requester;
|
||||
}
|
||||
|
||||
if (Mode == AppMode.Unattended)
|
||||
if (ArgDict.TryGetValue("serviceid", out var serviceID))
|
||||
{
|
||||
ServiceID = ArgDict["serviceid"];
|
||||
DeviceID = ArgDict["deviceid"];
|
||||
ServiceID = serviceID;
|
||||
}
|
||||
if (ArgDict.TryGetValue("deviceid", out var deviceID))
|
||||
{
|
||||
DeviceID = deviceID;
|
||||
}
|
||||
if (ArgDict.TryGetValue("organization", out var orgName))
|
||||
{
|
||||
OrganizationName = orgName;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -26,10 +26,9 @@ namespace Remotely.ScreenCast.Core.Services
|
||||
";
|
||||
|
||||
private NamedPipeServerStream NamedPipeStream { get; set; }
|
||||
private StreamWriter Writer { get; set; }
|
||||
private StreamReader Reader { get; set; }
|
||||
|
||||
public async Task StartChat(string requesterID)
|
||||
private StreamWriter Writer { get; set; }
|
||||
public async Task StartChat(string requesterID, string organizationName)
|
||||
{
|
||||
NamedPipeStream = new NamedPipeServerStream("Remotely_Chat" + requesterID, PipeDirection.InOut, 10, PipeTransmissionMode.Byte, PipeOptions.Asynchronous);
|
||||
Writer = new StreamWriter(NamedPipeStream);
|
||||
@ -38,7 +37,14 @@ namespace Remotely.ScreenCast.Core.Services
|
||||
Console.BackgroundColor = ConsoleColor.Black;
|
||||
Console.ForegroundColor = ConsoleColor.Cyan;
|
||||
Console.Title = "Remotely Chat";
|
||||
Console.Write(AsciiLogo);
|
||||
if (string.IsNullOrWhiteSpace(organizationName))
|
||||
{
|
||||
Console.Write(AsciiLogo);
|
||||
}
|
||||
else
|
||||
{
|
||||
WriteOrgnanizationName(organizationName);
|
||||
}
|
||||
Console.ForegroundColor = ConsoleColor.White;
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("Your IT administrator would like to chat!");
|
||||
@ -103,5 +109,51 @@ namespace Remotely.ScreenCast.Core.Services
|
||||
Console.Write("You: ");
|
||||
Console.ForegroundColor = ConsoleColor.White;
|
||||
}
|
||||
|
||||
private void WriteOrgnanizationName(string organizationName)
|
||||
{
|
||||
Console.WriteLine();
|
||||
Console.WriteLine();
|
||||
|
||||
Console.Write(" ");
|
||||
for (var i = 0; i < organizationName.Length + 10; i++)
|
||||
{
|
||||
Console.Write("/");
|
||||
}
|
||||
Console.WriteLine();
|
||||
|
||||
|
||||
Console.Write(" ///");
|
||||
for (var i = 0; i < organizationName.Length + 4; i++)
|
||||
{
|
||||
Console.Write(" ");
|
||||
}
|
||||
Console.Write("///");
|
||||
Console.WriteLine();
|
||||
|
||||
|
||||
Console.WriteLine($" /// {organizationName} ///");
|
||||
|
||||
|
||||
Console.Write(" ///");
|
||||
for (var i = 0; i < organizationName.Length + 4; i++)
|
||||
{
|
||||
Console.Write(" ");
|
||||
}
|
||||
Console.Write("///");
|
||||
Console.WriteLine();
|
||||
|
||||
|
||||
Console.Write(" ");
|
||||
for (var i = 0; i < organizationName.Length + 10; i++)
|
||||
{
|
||||
Console.Write("/");
|
||||
}
|
||||
Console.WriteLine();
|
||||
|
||||
|
||||
Console.WriteLine();
|
||||
Console.WriteLine();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -8,6 +8,7 @@ using Remotely.ScreenCast.Core.Communication;
|
||||
using Remotely.ScreenCast.Core.Interfaces;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Linq;
|
||||
|
||||
namespace Remotely.ScreenCast.Linux
|
||||
{
|
||||
@ -26,11 +27,11 @@ namespace Remotely.ScreenCast.Linux
|
||||
|
||||
Conductor = Services.GetRequiredService<Conductor>();
|
||||
|
||||
Conductor.ProcessArgs(args);
|
||||
Conductor.ProcessArgs(Environment.GetCommandLineArgs().Skip(1).ToArray());
|
||||
|
||||
if (Conductor.Mode == Core.Enums.AppMode.Chat)
|
||||
{
|
||||
Services.GetRequiredService<ChatHostService>().StartChat(Conductor.RequesterID).Wait();
|
||||
Services.GetRequiredService<ChatHostService>().StartChat(Conductor.RequesterID, Conductor.OrganizationName).Wait();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@ -42,11 +42,11 @@ namespace Remotely.ScreenCast.Win
|
||||
BuildServices();
|
||||
|
||||
Conductor = Services.GetRequiredService<Conductor>();
|
||||
Conductor.ProcessArgs(args);
|
||||
Conductor.ProcessArgs(Environment.GetCommandLineArgs().Skip(1).ToArray());
|
||||
|
||||
if (Conductor.Mode == Core.Enums.AppMode.Chat)
|
||||
{
|
||||
Services.GetRequiredService<ChatHostService>().StartChat(Conductor.RequesterID).Wait();
|
||||
Services.GetRequiredService<ChatHostService>().StartChat(Conductor.RequesterID, Conductor.OrganizationName).Wait();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@ -46,22 +46,20 @@ namespace Remotely.ScreenCast.Win.Services
|
||||
|
||||
private void ClipboardWatcher_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
|
||||
{
|
||||
Win32Interop.SwitchToInputDesktop();
|
||||
|
||||
var thread = new Thread(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
Win32Interop.SwitchToInputDesktop();
|
||||
|
||||
|
||||
if (Clipboard.ContainsText() && Clipboard.GetText() != ClipboardText)
|
||||
{
|
||||
ClipboardText = Clipboard.GetText();
|
||||
ClipboardTextChanged.Invoke(this, ClipboardText);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.Write(ex);
|
||||
}
|
||||
catch { }
|
||||
});
|
||||
thread.SetApartmentState(ApartmentState.STA);
|
||||
thread.Start();
|
||||
|
||||
@ -53,7 +53,8 @@ namespace Remotely.Server.Services
|
||||
{
|
||||
deviceIDs = DataService.FilterDeviceIDsByUserPermission(deviceIDs, RemotelyUser);
|
||||
var connections = GetActiveClientConnections(deviceIDs);
|
||||
return DeviceHub.Clients.Clients(connections.Select(x => x.Key).ToList()).SendAsync("Chat", $"{RemotelyUser.UserName}: {message}", Context.ConnectionId);
|
||||
var organizationName = DataService.GetOrganizationName(RemotelyUser.UserName);
|
||||
return DeviceHub.Clients.Clients(connections.Select(x => x.Key).ToList()).SendAsync("Chat", $"{RemotelyUser.UserName}: {message}", organizationName, Context.ConnectionId);
|
||||
}
|
||||
|
||||
public Task DeployScript(string fileID, string mode, string[] deviceIDs)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user