public void UpdateServer(ApiModel.Server serverUpdate) { ServerOptions newSettings = serverOptions.CurrentValue; RelayOptions newRelaySettings = relayOptions.CurrentValue; newSettings.Port = serverUpdate.PortNumber; newSettings.HostName = serverUpdate.HostName; newSettings.AllowRemoteConnections = serverUpdate.AllowRemoteConnections; newSettings.NumberOfMessagesToKeep = serverUpdate.NumberOfMessagesToKeep; newSettings.NumberOfSessionsToKeep = serverUpdate.NumberOfSessionsToKeep; newRelaySettings.SmtpServer = serverUpdate.RelayOptions.SmtpServer; newRelaySettings.SmtpPort = serverUpdate.RelayOptions.SmtpPort; newRelaySettings.SenderAddress = serverUpdate.RelayOptions.SenderAddress; newRelaySettings.Login = serverUpdate.RelayOptions.Login; newRelaySettings.Password = serverUpdate.RelayOptions.Password; newRelaySettings.AutomaticEmails = serverUpdate.RelayOptions.AutomaticEmails; if (!serverUpdate.IsRunning && this.server.IsRunning) { this.server.Stop(); } else if (serverUpdate.IsRunning && !this.server.IsRunning) { this.server.TryStart(); } string dataDir = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "smtp4dev"); string settingsFile = Path.Join(dataDir, "appsettings.json"); System.IO.File.WriteAllText(settingsFile, JsonSerializer.Serialize(new { ServerOptions = newSettings, RelayOptions = newRelaySettings }, new JsonSerializerOptions { WriteIndented = true })); }
public static int RunRelay(RelayOptions options) { Console.WriteLine($"Running relay on port {options.RelayPort}"); var ports = new List <PortMapping>(); foreach (var mapping in options.Map) { var split = mapping.Split(','); if (split.Length != 3 || !ushort.TryParse(split[0], out var target) || !ushort.TryParse(split[1], out var intern) || !ushort.TryParse(split[2], out var external)) { Console.WriteLine($"Invalid port mapping - '{mapping}'"); return(1); } ports.Add(new PortMapping(target, intern, external)); Console.WriteLine($"{target}: ({intern}, {external})"); } var server = new MainServer(IPAddress.Any, options.RelayPort, ports); server.Start(); while (Console.ReadLine() != "q") { ; } return(0); }
public MetaController(IEnumerable<IModMetaSource> sources, ILogger<MetaController> logger, IOptions<RelayOptions> options) { Sources = sources; _options = options.Value; if (!Sources.Any()) { logger.LogWarning("No metadata sources configured! If no plugins are loaded, queries will always return empty results"); } else { logger.LogTrace("Loaded metadata sources!"); } _logger = logger; }
public ActionResult UpdateServer(ApiModel.Server serverUpdate) { if (!hostingEnvironmentHelper.SettingsAreEditable) { return(Forbid()); } ServerOptions newSettings = serverOptions.CurrentValue; RelayOptions newRelaySettings = relayOptions.CurrentValue; newSettings.Port = serverUpdate.PortNumber; newSettings.HostName = serverUpdate.HostName; newSettings.AllowRemoteConnections = serverUpdate.AllowRemoteConnections; newSettings.NumberOfMessagesToKeep = serverUpdate.NumberOfMessagesToKeep; newSettings.NumberOfSessionsToKeep = serverUpdate.NumberOfSessionsToKeep; newSettings.ImapPort = serverUpdate.ImapPortNumber; newRelaySettings.SmtpServer = serverUpdate.RelayOptions.SmtpServer; newRelaySettings.SmtpPort = serverUpdate.RelayOptions.SmtpPort; newRelaySettings.TlsMode = Enum.Parse <SecureSocketOptions>(serverUpdate.RelayOptions.TlsMode); newRelaySettings.SenderAddress = serverUpdate.RelayOptions.SenderAddress; newRelaySettings.Login = serverUpdate.RelayOptions.Login; newRelaySettings.Password = serverUpdate.RelayOptions.Password; newRelaySettings.AutomaticEmails = serverUpdate.RelayOptions.AutomaticEmails; System.IO.File.WriteAllText(hostingEnvironmentHelper.GetEditableSettingsFilePath(), JsonSerializer.Serialize(new { ServerOptions = newSettings, RelayOptions = newRelaySettings }, new JsonSerializerOptions { WriteIndented = true })); if (!serverUpdate.IsRunning && this.server.IsRunning) { this.server.Stop(); } else if (serverUpdate.IsRunning && !this.server.IsRunning) { this.server.TryStart(); } if (!serverUpdate.IsRunning && this.imapServer.IsRunning) { this.imapServer.Stop(); } else if (serverUpdate.IsRunning && !this.imapServer.IsRunning) { this.imapServer.TryStart(); } return(Ok()); }
/// <summary> /// Enables relay schema style. /// </summary> public static ISchemaBuilder EnableRelaySupport( this ISchemaBuilder schemaBuilder, RelayOptions options = null) { options ??= new(); if (options.AddQueryFieldToMutationPayloads) { schemaBuilder.TryAddTypeInterceptor <QueryFieldTypeInterceptor>(); } return(schemaBuilder .SetContextData(IsRelaySupportEnabled, 1) .SetRelayOptions(options) .TryAddTypeInterceptor <NodeFieldTypeInterceptor>() .AddType <NodeType>()); }