diff --git a/Desktop.Core/Services/DeviceInitService.cs b/Desktop.Core/Services/DeviceInitService.cs index 5760e194..80255be8 100644 --- a/Desktop.Core/Services/DeviceInitService.cs +++ b/Desktop.Core/Services/DeviceInitService.cs @@ -50,11 +50,17 @@ namespace Remotely.Desktop.Core.Services var config = _configService.GetConfig(); + var host = _conductor?.Host; + if (string.IsNullOrWhiteSpace(host)) + { + host = config.Host; + } + var fileName = Path.GetFileNameWithoutExtension(Process.GetCurrentProcess().MainModule.FileName); if (fileName.Contains("[") && fileName.Contains("]") && - !string.IsNullOrWhiteSpace(_conductor?.Host)) + !string.IsNullOrWhiteSpace(host)) { var codeLength = AppConstants.RelayCodeLength + 2; @@ -65,11 +71,11 @@ namespace Remotely.Desktop.Core.Services { var relayCode = codeSection[1..5]; - using var response = await httpClient.GetAsync($"{_conductor.Host}/api/Relay/{relayCode}").ConfigureAwait(false); + using var response = await httpClient.GetAsync($"{host.TrimEnd('/')}/api/Relay/{relayCode}").ConfigureAwait(false); if (response.IsSuccessStatusCode) { var organizationId = await response.Content.ReadAsStringAsync(); - config.Host = _conductor.Host; + config.Host = host; config.OrganizationId = organizationId; _configService.Save(config); @@ -81,12 +87,12 @@ namespace Remotely.Desktop.Core.Services } } - if (!string.IsNullOrWhiteSpace(_conductor?.Host)) + if (!string.IsNullOrWhiteSpace(host)) { - config.Host = _conductor.Host; + config.Host = host; config.OrganizationId = _conductor.OrganizationId; _configService.Save(config); - var brandingUrl = $"{_conductor.Host.TrimEnd('/')}/api/branding/{_conductor.OrganizationId}"; + var brandingUrl = $"{host.TrimEnd('/')}/api/branding/{_conductor.OrganizationId}"; _brandingInfo = await httpClient.GetFromJsonAsync(brandingUrl).ConfigureAwait(false); } } diff --git a/Server/Areas/Identity/Pages/Account/Manage/Organization.cshtml b/Server/Areas/Identity/Pages/Account/Manage/Organization.cshtml index d3d88f3a..fca65e27 100644 --- a/Server/Areas/Identity/Pages/Account/Manage/Organization.cshtml +++ b/Server/Areas/Identity/Pages/Account/Manage/Organization.cshtml @@ -27,6 +27,8 @@
+ +
diff --git a/Server/Services/DataService.cs b/Server/Services/DataService.cs index ae2efbf5..6d9500f0 100644 --- a/Server/Services/DataService.cs +++ b/Server/Services/DataService.cs @@ -130,6 +130,8 @@ namespace Remotely.Server.Services bool JoinViaInvitation(string userName, string inviteID); + void PopulateRelayCodes(); + void RemoveDevices(string[] deviceIDs); Task RemoveUserFromDeviceGroup(string orgID, string groupID, string userID); @@ -1053,6 +1055,22 @@ namespace Remotely.Server.Services return true; } + public void PopulateRelayCodes() + { + foreach (var organization in _dbContext.Organizations) + { + if (string.IsNullOrWhiteSpace(organization.RelayCode)) + { + do + { + organization.RelayCode = new string(Guid.NewGuid().ToString().Take(4).ToArray()); + } + while (_dbContext.Organizations.Any(x => x.ID != organization.ID && x.RelayCode == organization.RelayCode)); + } + } + _dbContext.SaveChanges(); + } + public void RemoveDevices(string[] deviceIDs) { var devices = _dbContext.Devices diff --git a/Server/Startup.cs b/Server/Startup.cs index 8a769357..add6985a 100644 --- a/Server/Startup.cs +++ b/Server/Startup.cs @@ -228,12 +228,14 @@ namespace Remotely.Server } catch (Exception ex) { - dataService.WriteEvent(ex, null); + Console.WriteLine(ex.Message); } loggerFactory.AddProvider(new DbLoggerProvider(env, app.ApplicationServices)); dataService.SetAllDevicesNotOnline(); dataService.CleanupOldRecords(); + // TODO: Remove after a few versions. + dataService.PopulateRelayCodes(); } diff --git a/Server/wwwroot/src/Pages/OrganizationManagement.ts b/Server/wwwroot/src/Pages/OrganizationManagement.ts index b9c4442d..3f97fad6 100644 --- a/Server/wwwroot/src/Pages/OrganizationManagement.ts +++ b/Server/wwwroot/src/Pages/OrganizationManagement.ts @@ -23,9 +23,14 @@ export const OrganizationManagement = { document.getElementById("defaultOrgHelp").addEventListener("click", () => { ShowModal("Default Organization", `This option is only available for server administrators. When - selected during registration, it sets this organization as the default for the server. The - quick support downloads, which aren't normally associated with an organization, will use - this organization's branding.`); + selected, it sets this organization as the default for the server. If the organization can't + be determined in the quick support apps, they will use the default organization's branding.`); + }); + + document.getElementById("relayCodeHelp").addEventListener("click", () => { + ShowModal("Relay Code", `This relay code will be appended to EXE filenames. If the clients + were built from source and have the server URL embedded, they will use this code to look + up the branding to use for your organization.`); });