public IHttpServer GetHttpServer (uint port, bool secure, string certPath, string certPass, SslProtocols sslProtocol) { if ((port == m_Port || port == 0) && HttpServer != null) return HttpServer; BaseHttpServer server; if(m_Servers.TryGetValue(port, out server) && server.Secure == secure) return server; string hostName = m_config.Configs["Network"].GetString("HostName", "http" + (secure ? "s" : "") + "://" + Utilities.GetExternalIp()); //Clean it up a bit if (hostName.StartsWith("http://") || hostName.StartsWith("https://")) hostName = hostName.Replace("https://", "").Replace("http://", ""); if (hostName.EndsWith ("/")) hostName = hostName.Remove (hostName.Length - 1, 1); server = new BaseHttpServer(port, hostName, secure); try { if(secure)//Set these params now server.SetSecureParams(certPath, certPass, sslProtocol); server.Start(); } catch(Exception) { //Remove the server from the list m_Servers.Remove (port); //Then pass the exception upwards throw; } return (m_Servers[port] = server); }
protected override void StartupSpecific() { m_storageManager = CreateStorageManager(); m_clientStackManager = CreateClientStackManager(); Initialize(); // Main HTTP server first m_httpServer = new BaseHttpServer(m_httpServerPort, null); m_httpServer.HostName = m_networkServersInfo.HostName; MainServer.AddHttpServer(m_httpServer); m_log.InfoFormat("[REGION]: Starting HTTP server on {0}:{1}", m_httpServer.HostName, m_httpServerPort); m_httpServer.Start(); // If specified configure an ssl server for use as well // you need a Cert Request/Signed pair installed in the MY store with the CN specified if (m_networkServersInfo.HttpUsesSSL) { if (m_networkServersInfo.HttpListenerPort == m_networkServersInfo.httpSSLPort) { m_log.Error("[HTTP]: HTTP Server config failed. HTTP Server and HTTPS server must be on different ports"); } else { /// XXX Should also support specifying an IP Address BaseHttpServer secureServer = new BaseHttpServer(m_networkServersInfo.httpSSLPort, null); secureServer.HostName = m_networkServersInfo.HostName; if (m_networkServersInfo.HttpSSLCN != null) secureServer.SetSecureParams(m_networkServersInfo.HttpSSLCN, m_networkServersInfo.sslProtocol); else secureServer.SetSecureParams(m_networkServersInfo.HttpSSLCert, m_networkServersInfo.HttpSSLPassword, m_networkServersInfo.sslProtocol); MainServer.AddHttpServer(secureServer); m_log.Info("[REGION]: Starting HTTPS server"); secureServer.Start(); } } base.StartupSpecific(); }