mirror of
https://github.com/immense/Remotely.git
synced 2025-10-26 11:27:15 +00:00
Added forwarded headers as the default. Moved around some error handling.
This commit is contained in:
parent
4ccfd54a38
commit
8be5796cee
@ -19,42 +19,50 @@ namespace Remotely_Agent
|
||||
public static bool IsDebug { get; set; }
|
||||
static void Main(string[] args)
|
||||
{
|
||||
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
|
||||
SetWorkingDirectory();
|
||||
var argDict = ProcessArgs(args);
|
||||
|
||||
JsonConvert.DefaultSettings = () =>
|
||||
try
|
||||
{
|
||||
var settings = new JsonSerializerSettings();
|
||||
settings.Error = (sender, arg) =>
|
||||
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
|
||||
SetWorkingDirectory();
|
||||
var argDict = ProcessArgs(args);
|
||||
|
||||
JsonConvert.DefaultSettings = () =>
|
||||
{
|
||||
arg.ErrorContext.Handled = true;
|
||||
var settings = new JsonSerializerSettings();
|
||||
settings.Error = (sender, arg) =>
|
||||
{
|
||||
arg.ErrorContext.Handled = true;
|
||||
};
|
||||
return settings;
|
||||
};
|
||||
return settings;
|
||||
};
|
||||
|
||||
if (argDict.ContainsKey("update"))
|
||||
{
|
||||
Updater.CoreUpdate();
|
||||
}
|
||||
if (argDict.ContainsKey("update"))
|
||||
{
|
||||
Updater.CoreUpdate();
|
||||
}
|
||||
|
||||
if (OSUtils.IsWindows)
|
||||
{
|
||||
if (OSUtils.IsWindows)
|
||||
{
|
||||
#if DEBUG
|
||||
IsDebug = true;
|
||||
DeviceSocket.Connect();
|
||||
IsDebug = true;
|
||||
DeviceSocket.Connect();
|
||||
#else
|
||||
ServiceBase.Run(new WindowsService());
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
DeviceSocket.Connect();
|
||||
}
|
||||
|
||||
while (true)
|
||||
{
|
||||
System.Threading.Thread.Sleep(1000);
|
||||
}
|
||||
}
|
||||
else
|
||||
catch (Exception ex)
|
||||
{
|
||||
DeviceSocket.Connect();
|
||||
}
|
||||
|
||||
while (true)
|
||||
{
|
||||
System.Threading.Thread.Sleep(1000);
|
||||
Logger.Write(ex);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -37,22 +37,7 @@ namespace Remotely_Agent.Services
|
||||
|
||||
RegisterMessageHandlers(HubConnection);
|
||||
|
||||
try
|
||||
{
|
||||
await HubConnection.StartAsync();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.Write(ex);
|
||||
if (!ConnectionInfo.Host.StartsWith("https"))
|
||||
{
|
||||
Logger.Write($"Failed to connect to {ConnectionInfo.Host}. Trying with HTTPS.");
|
||||
ConnectionInfo.Host = ConnectionInfo.Host.ToLower().Replace("http:", "https:");
|
||||
Connect();
|
||||
return;
|
||||
}
|
||||
throw;
|
||||
}
|
||||
await HubConnection.StartAsync();
|
||||
|
||||
var device = Device.Create(ConnectionInfo);
|
||||
|
||||
|
||||
@ -38,6 +38,7 @@ namespace Remotely_ScreenCast.Linux
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.Write(ex);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -49,6 +49,7 @@ namespace Remotely_ScreenCast.Win
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.Write(ex);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1 +1 @@
|
||||
2019.03.29.0908
|
||||
2019.03.29.1301
|
||||
|
||||
@ -66,41 +66,49 @@ namespace Remotely_Server.Services
|
||||
|
||||
public async Task DeviceCameOnline(Device device)
|
||||
{
|
||||
if (ServiceConnections.Any(x => x.Value.ID == device.ID))
|
||||
{
|
||||
DataService.WriteEvent(new EventLog()
|
||||
{
|
||||
EventType = EventTypes.Info,
|
||||
OrganizationID = Device.OrganizationID,
|
||||
Message = $"Device connection for {device?.DeviceName} was denied because it is already connected."
|
||||
});
|
||||
Context.Abort();
|
||||
return;
|
||||
}
|
||||
device.IsOnline = true;
|
||||
device.LastOnline = DateTime.Now;
|
||||
Device = device;
|
||||
if (DataService.AddOrUpdateDevice(device))
|
||||
{
|
||||
var failCount = 0;
|
||||
while (!ServiceConnections.TryAdd(Context.ConnectionId, device))
|
||||
{
|
||||
if (failCount > 3)
|
||||
{
|
||||
Context.Abort();
|
||||
return;
|
||||
}
|
||||
failCount++;
|
||||
await Task.Delay(1000);
|
||||
}
|
||||
await this.Groups.AddToGroupAsync(this.Context.ConnectionId, device.OrganizationID);
|
||||
await BrowserHub.Clients.Group(Device.OrganizationID).SendAsync("DeviceCameOnline", Device);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Organization wasn't found.
|
||||
await Clients.Caller.SendAsync("UninstallClient");
|
||||
}
|
||||
try
|
||||
{
|
||||
if (ServiceConnections.Any(x => x.Value.ID == device.ID))
|
||||
{
|
||||
DataService.WriteEvent(new EventLog()
|
||||
{
|
||||
EventType = EventTypes.Info,
|
||||
OrganizationID = device.OrganizationID,
|
||||
Message = $"Device connection for {device?.DeviceName} was denied because it is already connected."
|
||||
});
|
||||
Context.Abort();
|
||||
return;
|
||||
}
|
||||
device.IsOnline = true;
|
||||
device.LastOnline = DateTime.Now;
|
||||
Device = device;
|
||||
if (DataService.AddOrUpdateDevice(device))
|
||||
{
|
||||
var failCount = 0;
|
||||
while (!ServiceConnections.TryAdd(Context.ConnectionId, device))
|
||||
{
|
||||
if (failCount > 3)
|
||||
{
|
||||
Context.Abort();
|
||||
return;
|
||||
}
|
||||
failCount++;
|
||||
await Task.Delay(1000);
|
||||
}
|
||||
await this.Groups.AddToGroupAsync(this.Context.ConnectionId, device.OrganizationID);
|
||||
await BrowserHub.Clients.Group(Device.OrganizationID).SendAsync("DeviceCameOnline", Device);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Organization wasn't found.
|
||||
await Clients.Caller.SendAsync("UninstallClient");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
DataService.WriteEvent(ex);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task DeviceHeartbeat(Device device)
|
||||
|
||||
@ -134,10 +134,10 @@ namespace Remotely_Server
|
||||
app.UseCookiePolicy();
|
||||
|
||||
// Uncomment to run .NET Core behind a reverse proxy.
|
||||
//app.UseForwardedHeaders(new ForwardedHeadersOptions
|
||||
//{
|
||||
// ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
|
||||
//});
|
||||
app.UseForwardedHeaders(new ForwardedHeadersOptions
|
||||
{
|
||||
ForwardedHeaders = ForwardedHeaders.All
|
||||
});
|
||||
|
||||
app.UseAuthentication();
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user