public void Start() { //HttpServer.Logging.LogFactory.Assign(new HttpServer.Logging.ConsoleLogFactory(null)); // TODO: more than one Interception can be configured with the same port and IP foreach (var interception in state_.Config.Interceptions) { IPAddress ip = GetIp(interception.IPv4); if (ip == null) { state_.Logger.Error("Invalid IPv4 address: {0}", interception.IPv4); continue; } state_.Logger.Information("Intercept {0} {2} {3}:{1}", interception.Protocol, interception.Port, interception.Name, ip); try { HttpListener listener = interception.Protocol == Protocol.Https ? HttpListener.Create(ip, interception.Port, certificatesMgr_.GetCertificate(interception.Name)) : HttpListener.Create(ip, interception.Port); listener.RequestReceived += OnRequest; listener.Start(state_.Config.Web.WebBacklog); listeners_.Add(listener); } catch (System.Net.Sockets.SocketException e) { state_.Logger.Exception(e, "Error setting up listener on port {0}", interception.Port); } } }
private static void Main(string[] args) { var filter = new LogFilter(); filter.AddStandardRules(); //LogFactory.Assign(new ConsoleLogFactory(filter)); // create a server. var server = new Server(); // same as previous example. var module = new FileModule(); module.Resources.Add(new FileResources("/", Environment.CurrentDirectory + "\\files\\")); server.Add(module); server.RequestReceived += OnRequest; server.Add(new MultiPartDecoder()); // use one http listener. server.Add(HttpListener.Create(IPAddress.Any, 8085)); server.Add(new SimpleRouter("/", "/index.html")); // start server, can have max 5 pending accepts. server.Start(5); Console.ReadLine(); }
private static void Main(string[] args) { HttpListener listener = HttpListener.Create(IPAddress.Any, 8089); listener.RequestReceived += OnRequest; listener.Start(5); Thread.Sleep(9000000); }
/// <summary> /// Starts this UPnP control point. All device templates should be configured at the time this method gets called. /// The network tracker must be started after this method is called, else we might miss some connect events. /// </summary> public void Start() { lock (_cpData.SyncObj) { if (_isActive) { throw new IllegalCallException("UPnP control point mustn't be started multiple times"); } UPnPConfiguration.LOGGER.Debug("Will listen on IPs filtered by [{0}]", (UPnPConfiguration.IP_ADDRESS_BINDINGS != null ? String.Join(",", UPnPConfiguration.IP_ADDRESS_BINDINGS) : null)); _cpData.HttpPortV4 = 0; if (UPnPConfiguration.USE_IPV4) { foreach (IPAddress address in NetworkHelper.GetBindableIPAddresses(AddressFamily.InterNetwork, UPnPConfiguration.IP_ADDRESS_BINDINGS)) { HttpListener httpListenerV4 = HttpListener.Create(address, _cpData.HttpPortV4); httpListenerV4.RequestReceived += OnHttpListenerRequestReceived; try { httpListenerV4.Start(DEFAULT_HTTP_REQUEST_QUEUE_SIZE); // Might fail if IPv4 isn't installed _cpData.HttpPortV4 = httpListenerV4.LocalEndpoint.Port; UPnPConfiguration.LOGGER.Debug("UPnPControlPoint: HTTP listener for IPv4 protocol started at address '{0}' on port '{1}'", address, _cpData.HttpPortV4); _httpListeners.Add(httpListenerV4); } catch (SocketException e) { UPnPConfiguration.LOGGER.Warn("UPnPControlPoint: Error starting HTTP server (IPv4)", e); } } } _cpData.HttpPortV6 = 0; if (UPnPConfiguration.USE_IPV6) { foreach (IPAddress address in NetworkHelper.GetBindableIPAddresses(AddressFamily.InterNetworkV6, UPnPConfiguration.IP_ADDRESS_BINDINGS)) { HttpListener httpListenerV6 = HttpListener.Create(address, _cpData.HttpPortV6); httpListenerV6.RequestReceived += OnHttpListenerRequestReceived; try { httpListenerV6.Start(DEFAULT_HTTP_REQUEST_QUEUE_SIZE); // Might fail if IPv6 isn't installed _cpData.HttpPortV6 = httpListenerV6.LocalEndpoint.Port; UPnPConfiguration.LOGGER.Debug("UPnPControlPoint: HTTP listener for IPv6 protocol started at address '{0}' on port '{1}'", address, _cpData.HttpPortV6); _httpListeners.Add(httpListenerV6); } catch (SocketException e) { UPnPConfiguration.LOGGER.Warn("UPnPControlPoint: Error starting HTTP server (IPv6)", e); } } } _networkTracker.RootDeviceRemoved += OnRootDeviceRemoved; _networkTracker.DeviceRebooted += OnDeviceRebooted; _isActive = true; } }
private static void Main(string[] args) { AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); Console.Title = "Web Server"; Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine(" Rains Soft Web Server"); Console.WriteLine(" Rains Soft"); Console.WriteLine(" http://www.mobanhou.com"); Console.WriteLine(); Console.ResetColor(); int i = 0; while (true) { if (i > 9) { Console.WriteLine("."); break; } else { Console.Write("."); i++; } System.Threading.Thread.Sleep(500); } var filter = new LogFilter(); filter.AddStandardRules(); var log = new ConsoleLogFactory(filter); LogFactory.Assign(log); Logger = LogFactory.CreateLogger(log.GetType()) as ConsoleAndTextLogger; Logger.Info("create server"); // create a server. var server = new Server(); // same as previous example. var module = new FileModule(); module.Resources.Add(new FileResources("/", Environment.CurrentDirectory + "\\files\\")); server.Add(module); server.Add(new CustomHttpModule()); server.RequestReceived += OnRequest; server.Add(new MultiPartDecoder()); // use one http listener. server.Add(HttpListener.Create(IPAddress.Any, 8085)); server.Add(new SimpleRouter("/", "/index.html")); Logger.Info("start server"); // start server, can have max 5 pending accepts. server.Start(5); Console.Beep(); Console.ReadLine(); }
/// <summary> /// Starts this UPnP control point. All device templates should be configured at the time this method gets called. /// The network tracker must be started after this method is called, else we might miss some connect events. /// </summary> public void Start() { lock (_cpData.SyncObj) { if (_isActive) { throw new IllegalCallException("UPnP control point mustn't be started multiple times"); } if (UPnPConfiguration.USE_IPV4) { _httpListenerV4 = HttpListener.Create(IPAddress.Any, 0); _httpListenerV4.RequestReceived += OnHttpListenerRequestReceived; try { _httpListenerV4.Start(DEFAULT_HTTP_REQUEST_QUEUE_SIZE); // Might fail if IPv4 isn't installed _cpData.HttpPortV4 = _httpListenerV4.LocalEndpoint.Port; } catch (SocketException e) { _httpListenerV4 = null; _cpData.HttpPortV4 = 0; UPnPConfiguration.LOGGER.Warn("UPnPControlPoint: Error starting HTTP server (IPv4)", e); } } else { _httpListenerV4 = null; _cpData.HttpPortV4 = 0; } if (UPnPConfiguration.USE_IPV6) { _httpListenerV6 = HttpListener.Create(IPAddress.IPv6Any, 0); _httpListenerV6.RequestReceived += OnHttpListenerRequestReceived; try { _httpListenerV6.Start(DEFAULT_HTTP_REQUEST_QUEUE_SIZE); // Might fail if IPv6 isn't installed _cpData.HttpPortV6 = _httpListenerV6.LocalEndpoint.Port; } catch (SocketException e) { _httpListenerV6 = null; _cpData.HttpPortV6 = 0; UPnPConfiguration.LOGGER.Warn("UPnPControlPoint: Error starting HTTP server (IPv6)", e); } } else { _httpListenerV6 = null; _cpData.HttpPortV6 = 0; } _networkTracker.RootDeviceRemoved += OnRootDeviceRemoved; _networkTracker.DeviceRebooted += OnDeviceRebooted; _isActive = true; } }
public void Start() { // use one http listener. server.Add(HttpListener.Create(IPAddress.Any, 8888)); shouldContinue = true; server.Start(5); }
public virtual void Start() { if (listener == null) { listener = HttpListener.Create(Ip, Port); listener.RequestReceived += OnRequest; listener.Start(int.MaxValue); } }
public void StartTutorial() { Console.WriteLine("Welcome to Tutorial #1!"); Console.WriteLine(); Console.WriteLine("HttpListener allows you to handle everything yourself."); Console.WriteLine(); Console.WriteLine("Browse to http://localhost:8081/hello and http://localhost:8081/goodbye to view the contents"); _listener = HttpListener.Create(IPAddress.Any, 8081); _listener.RequestReceived += OnRequest; _listener.Start(5); }
private static void Main(string[] args) { var certificate = new X509Certificate2("C:\\OpenSSL\\bin\\newcert.p12", "test"); // We do the cast since we want to specify UseClientCert var listener = (SecureHttpListener)HttpListener.Create(IPAddress.Any, 8080, certificate); listener.UseClientCertificate = true; listener.RequestReceived += OnRequest; listener.Start(5); Console.ReadLine(); }
public static void Start() { if (_webServer != null) { _webServer.Start(0); return; } _webServer = new Server(); _webServer.Add(HttpListener.Create(IPAddress.Any, 8080)); _webServer.PrepareRequest += OnRequest; _webServer.Add(new StaticResourceHandler()); _webServer.Add(new PageHandler()); _webServer.Add(new SimpleRouter("/", "index.htm")); UserSession.Init(_webServer, true); _webServer.Start(0); }
public virtual void Start() { try { listener = HttpListener.Create(Ip, Port); listener.RequestReceived += OnRequest; listener.Start(int.MaxValue); } catch (Exception ex) { TShock.Log.Error("Fatal Startup Exception"); TShock.Log.Error(ex.ToString()); TShock.Log.ConsoleError("Invalid REST configuration: \nYou may already have a REST service bound to port {0}. \nPlease adjust your configuration and restart the server. \nPress any key to exit.", Port); Console.ReadLine(); Environment.Exit(1); } }
/// <summary> /// Starts the RESTful API service /// </summary> public virtual void Start() { try { listener = HttpListener.Create(Ip, Port); listener.RequestReceived += OnRequest; listener.Start(int.MaxValue); tokenBucketTimer = new Timer((e) => { DegradeBucket(); }, null, TimeSpan.Zero, TimeSpan.FromMinutes(Math.Max(TShock.Config.RESTRequestBucketDecreaseIntervalMinutes, 1))); } catch (Exception ex) { TShock.Log.Error("致命的启动错误."); TShock.Log.Error(ex.ToString()); TShock.Log.ConsoleError("REST配置无效: \n可能端口{0}被已经启动另外的REST占用. \n请调整REST配置并重启服务器. \n任意键退出.", Port); Console.ReadLine(); Environment.Exit(1); } }
private void btnDesbLocal_Click(object sender, EventArgs e) { btnDesbLocal.Enabled = false; btnDesbRemoto.Enabled = false; var certificate = new X509Certificate2("cert.p12", "acs.gvt.com.br"); var listener = (SecureHttpListener)HttpListener.Create(IPAddress.Any, 443, certificate); unlockSent = 0; listener.UseClientCertificate = true; listener.RequestReceived += OnRequestDesbloqueio; listener.Start(5); AppendTextBox("Desbloqueio local. Servidor web iniciado.\r\n"); if (configToken.Length == 6) { checkBox1.Enabled = false; AppendTextBox("Apontando host acs.gvt.com.br para " + ipGerencia + "\r\n"); webBrowser1.Navigate("http://" + ipModem + "/cgi-bin/generic.cgi?token=" + configToken + "&write=LANDevice_1_HostConfig_StaticHost_1_IPAddress:" + ipGerencia + "&write=LANDevice_1_HostConfig_StaticHost_1_Hostname:acs.gvt.com.br"); } }
/// <summary> /// Starts the RESTful API service /// </summary> public virtual void Start() { try { listener = HttpListener.Create(Ip, Port); listener.RequestReceived += OnRequest; listener.Start(Int32.MaxValue); tokenBucketTimer = new Timer((e) => { DegradeBucket(); }, null, TimeSpan.Zero, TimeSpan.FromMinutes(Math.Max(Restful.Instance.Config.RequestBucketDecreaseIntervalMinutes, 1))); } catch (Exception ex) { TShock.Log.Error("Fatal Startup Exception"); TShock.Log.Error(ex.ToString()); TShock.Log.ConsoleError("Invalid REST configuration: \nYou may already have a REST service bound to port {0}. \nPlease adjust your configuration and restart the server. \nPress any key to exit.", Port); Console.ReadLine(); Environment.Exit(1); } }
static void Main(string[] args) { // create a server. var server = new Server(); // same as previous example. var module = new FileModule(); module.Resources.Add(new FileResources("/", Environment.CurrentDirectory + "\\files\\")); server.Add(module); // use one http listener. server.Add(HttpListener.Create(IPAddress.Any, 8085)); // add our own module. server.Add(new Streamer()); // start server, can have max 5 pending accepts. server.Start(5); Console.ReadLine(); }
//Control public static void Init() { adminServer = new Server(); //Handle the requests for static files var adminModule = new FileModule(); adminModule.Resources.Add(new FileResources("/assets/", YAMS.Core.RootFolder + "\\web\\assets\\")); adminServer.Add(adminModule); //Handle requests to API adminServer.Add(new Web.AdminAPI()); adminServer.Add(HttpListener.Create(IPAddress.Any, Convert.ToInt32(YAMS.Database.GetSetting("AdminListenPort", "YAMS")))); adminServer.ErrorPageRequested += new EventHandler <ErrorPageEventArgs>(myServer_ErrorPageRequested); adminServerThread = new Thread(new ThreadStart(StartAdmin)); adminServerThread.Start(); //Open firewall ports if (Database.GetSetting("EnableOpenFirewall", "YAMS") == "true") { Networking.OpenFirewallPort(Convert.ToInt32(YAMS.Database.GetSetting("AdminListenPort", "YAMS")), "Admin website"); } }
private void StartHTTP() { if (HTTPRunning) { return; } int m_port_original = 0; int m_optional_port = 0; try { m_port_original = (int)m_port; m_optional_port = m_port_original + 1; m_HttpListener = CoolHTTPListener.Create(IPAddress.Any, (int)m_port); m_HttpListener.ExceptionThrown += httpServerException; m_HttpListener.RequestReceived += OnRequest; m_HttpListener.Start(m_BotConfig.httpserver.BacklogQueue); HTTPRunning = true; } catch (Exception e) { m_Output.LogMessage("error", "[HTTPD]: Failed to start HTTPD with " + e.Message + ". Trying alternate port." + Environment.NewLine); try { m_HttpListener = CoolHTTPListener.Create(IPAddress.Any, (int)m_optional_port); m_HttpListener.ExceptionThrown += httpServerException; m_HttpListener.RequestReceived += OnRequest; m_HttpListener.Start(m_BotConfig.httpserver.BacklogQueue); HTTPRunning = true; } catch (Exception f) { m_Output.LogMessage("error", "[HTTPD]: Failed to start HTTPD with " + f.Message + Environment.NewLine); } } }
public void StartTutorial() { if (!File.Exists("../../certInProjectFolder.p12")) { Console.WriteLine("Create a certificate first. "); Console.WriteLine("OpenSSL: http://www.openssl.org/"); Console.WriteLine("Create a certificate: http://www.towersoft.com/sdk/doku.php?id=ice:setting_up_an_ice_server_to_use_ssl"); Console.WriteLine(); Console.WriteLine("Create the cert and place it in the tutorial project folder with the name 'certInProjectFolder.p12'."); return; } Console.WriteLine("Welcome to tutorial number 2, which will demonstrate how to setup HttpListener for secure requests."); Console.WriteLine(); Console.WriteLine("You will need to create a certificate yourself. A good guide for OpenSSL can be found here:"); Console.WriteLine("http://www.towersoft.com/sdk/doku.php?id=ice:setting_up_an_ice_server_to_use_ssl"); Console.WriteLine(); Console.WriteLine("Browse to https://localhost/hello when you have installed your certificate."); _cert = new X509Certificate2("../../certInProjectFolder.p12", "yourCertPassword"); _listener = HttpListener.Create(IPAddress.Any, 443, _cert); _listener.RequestReceived += OnSecureRequest; _listener.Start(5); }
//Control public static void Init() { //See if there is a new version of the web files waiting before we start the server if (File.Exists(Core.RootFolder + @"\web.zip")) { if (Directory.Exists(Core.RootFolder + @"\web\")) { Directory.Delete(Core.RootFolder + @"\web\", true); } Directory.CreateDirectory(YAMS.Core.RootFolder + @"\web\"); AutoUpdate.ExtractZip(YAMS.Core.RootFolder + @"\web.zip", YAMS.Core.RootFolder + @"\web\"); File.Delete(Core.RootFolder + @"\web.zip"); } adminServer = new Server(); publicServer = new Server(); //Handle the requests for static files var adminModule = new FileModule(); adminModule.Resources.Add(new FileResources("/assets/", YAMS.Core.RootFolder + "\\web\\assets\\")); adminServer.Add(adminModule); //Add any server specific folders var publicModule = new FileModule(); publicModule.Resources.Add(new FileResources("/assets/", YAMS.Core.RootFolder + "\\web\\assets\\")); SqlCeDataReader readerServers = YAMS.Database.GetServers(); while (readerServers.Read()) { var intServerID = readerServers["ServerID"].ToString(); if (!Directory.Exists(Core.StoragePath + intServerID + "\\renders\\")) { Directory.CreateDirectory(Core.StoragePath + intServerID + "\\renders\\"); } publicModule.Resources.Add(new FileResources("/servers/" + intServerID + "/renders/", Core.StoragePath + intServerID + "\\renders\\")); if (!Directory.Exists(Core.StoragePath + intServerID + "\\backups\\")) { Directory.CreateDirectory(Core.StoragePath + intServerID + "\\backups\\"); } publicModule.Resources.Add(new FileResources("/servers/" + intServerID + "/backups/", Core.StoragePath + intServerID + "\\backups\\")); } publicServer.Add(publicModule); //Handle requests to API adminServer.Add(new Web.AdminAPI()); publicServer.Add(new Web.PublicAPI()); adminServer.Add(HttpListener.Create(IPAddress.Any, Convert.ToInt32(YAMS.Database.GetSetting("AdminListenPort", "YAMS")))); publicServer.Add(HttpListener.Create(IPAddress.Any, Convert.ToInt32(YAMS.Database.GetSetting("PublicListenPort", "YAMS")))); adminServer.ErrorPageRequested += new EventHandler <ErrorPageEventArgs>(myServer_ErrorPageRequested); publicServer.ErrorPageRequested += new EventHandler <ErrorPageEventArgs>(myServer_ErrorPageRequested); adminServerThread = new Thread(new ThreadStart(StartAdmin)); publicServerThread = new Thread(new ThreadStart(StartPublic)); adminServerThread.Start(); publicServerThread.Start(); //Open firewall ports Networking.OpenFirewallPort(Convert.ToInt32(YAMS.Database.GetSetting("AdminListenPort", "YAMS")), "Admin website"); Networking.OpenFirewallPort(Convert.ToInt32(YAMS.Database.GetSetting("PublicListenPort", "YAMS")), "Public website"); Networking.OpenUPnP(Convert.ToInt32(YAMS.Database.GetSetting("AdminListenPort", "YAMS")), "Admin website"); Networking.OpenUPnP(Convert.ToInt32(YAMS.Database.GetSetting("PublicListenPort", "YAMS")), "Public website"); }
public void Start(IPAddress a, int port) { listener = HttpListener.Create(a, port); listener.RequestReceived += listener_RequestReceived; listener.Start(1000); }
public CapsServer(IPAddress address, int port) { serverOwned = true; capsHandler = BuildCapsHandler(@"^/caps/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$"); server = HttpListener.Create(log4netLogWriter.Instance, address, port); }
/// <summary> /// Starts this UPnP server, i.e. starts a network listener and sends notifications about provided devices. /// </summary> /// <param name="advertisementInterval">Interval in seconds to repeat UPnP advertisements in the network. /// The UPnP architecture document (UPnP-arch-DeviceArchitecture-v1 1-20081015, 1.2.2, page 21) states a /// minimum of 1800 seconds. But in the world of today, that value is much to high for many applications and in many /// cases, a value of much less than 1800 seconds is choosen. For servers which will frequently change their /// availability, this value should be short, for more durable serves, this interval can be much longer (maybe a day).</param> public void Bind(int advertisementInterval = UPnPConsts.DEFAULT_ADVERTISEMENT_EXPIRATION_TIME) { lock (_serverData.SyncObj) { if (_serverData.IsActive) { throw new IllegalCallException("UPnP subsystem mustn't be started multiple times"); } _serverData.HTTP_PORTv4 = 0; if (UPnPConfiguration.USE_IPV4) { foreach (IPAddress address in NetworkHelper.GetBindableIPAddresses(AddressFamily.InterNetwork, UPnPConfiguration.IP_ADDRESS_BINDINGS)) { HttpListener httpListenerV4 = HttpListener.Create(address, _serverData.HTTP_PORTv4); httpListenerV4.RequestReceived += OnHttpListenerRequestReceived; try { httpListenerV4.Start(DEFAULT_HTTP_REQUEST_QUEUE_SIZE); // Might fail if IPv4 isn't installed _serverData.HTTP_PORTv4 = httpListenerV4.LocalEndpoint.Port; UPnPConfiguration.LOGGER.Info("UPnP server: HTTP listener for IPv4 protocol started on port {0}", _serverData.HTTP_PORTv4); _serverData.HTTPListeners.Add(httpListenerV4); } catch (SocketException e) { UPnPConfiguration.LOGGER.Warn("UPnPServer: Error starting HTTP server (IPv4)", e); } } } else { UPnPConfiguration.LOGGER.Info("UPnP server: IPv4 protocol disabled, so no HTTP listener started for IPv4"); } _serverData.HTTP_PORTv6 = 0; if (UPnPConfiguration.USE_IPV6) { foreach (IPAddress address in NetworkHelper.GetBindableIPAddresses(AddressFamily.InterNetworkV6, UPnPConfiguration.IP_ADDRESS_BINDINGS)) { HttpListener httpListenerV6 = HttpListener.Create(address, _serverData.HTTP_PORTv6); // Might fail if IPv6 isn't installed httpListenerV6.RequestReceived += OnHttpListenerRequestReceived; try { httpListenerV6.Start(DEFAULT_HTTP_REQUEST_QUEUE_SIZE); _serverData.HTTP_PORTv6 = httpListenerV6.LocalEndpoint.Port; UPnPConfiguration.LOGGER.Info("UPnP server: HTTP listener for IPv6 protocol started at port {0}", _serverData.HTTP_PORTv6); _serverData.HTTPListeners.Add(httpListenerV6); } catch (SocketException e) { UPnPConfiguration.LOGGER.Warn("UPnPServer: Error starting HTTP server (IPv6)", e); } } } else { UPnPConfiguration.LOGGER.Info("UPnP server: IPv6 protocol disabled, so no HTTP listener started for IPv6"); } _serverData.SSDPController = new SSDPServerController(_serverData) { AdvertisementExpirationTime = advertisementInterval }; _serverData.GENAController = new GENAServerController(_serverData); InitializeDiscoveryEndpoints(); NetworkChange.NetworkAddressChanged += OnNetworkAddressChanged; _serverData.IsActive = true; // At the end, start the controllers _serverData.SSDPController.Start(); _serverData.GENAController.Start(); UPnPConfiguration.LOGGER.Info("UPnP server online hosting {0} UPnP root devices", _serverData.Server.RootDevices.Count); } }
public CapsServer(IPAddress address, int port, X509Certificate sslCertificate, X509Certificate rootCA, bool requireClientCertificate) { serverOwned = true; capsHandler = BuildCapsHandler(@"^/caps/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$"); server = HttpListener.Create(log4netLogWriter.Instance, address, port, sslCertificate, rootCA, SslProtocols.Default, requireClientCertificate); }
public WebInterface() { if (WebInterfaceEnabled) { this.server = new Server(); this.interpreter = new ManagedFileModule(); this.server.Add(this.interpreter); this.reader = new FileModule(); this.resource = new FileResources("/", Path.Combine(Directory.GetCurrentDirectory(), "WebInterface")); this.reader.Resources.Add(resource); this.server.Add(this.reader); this.server.Add(new SimpleRouter("/", "/index.html")); if (WebInterfaceDebug) { if (UseSSL) { // } else { // } } if (UseSSL) { try { this.certificate = new X509Certificate2(CertificatePath); } catch (DirectoryNotFoundException) { Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("({0}) <Web Interface> Error: The directory specified could not be found.", DateTime.Now.ToString("hh:mm")); } catch (IOException) { Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("({0}) <Web Interface> Error: A file in the directory could not be accessed.", DateTime.Now.ToString("hh:mm")); } catch (NullReferenceException) { Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("({0}) <Web Interface> File must be a .cer file. Program does not have access to that type of file.", DateTime.Now.ToString("hh:mm")); } Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("({0}) <Web Interface> Loaded Certificate: {1} Valid Date: {2} Expiry Date: {3}", DateTime.Now.ToString("hh:mm"), Path.GetFileName(CertificatePath), this.certificate.NotBefore, this.certificate.NotAfter); this.securelistener = (SecureHttpListener)HttpListener.Create(IPAddress.Parse(ListenAddress), Port, this.certificate); this.securelistener.UseClientCertificate = true; this.server.Add(this.securelistener); } else { this.listener = HttpListener.Create(IPAddress.Parse(ListenAddress), Port); this.server.Add(this.listener); } this.reader.ContentTypes.Clear(); this.reader.ContentTypes.Add("default", new ContentTypeHeader("application/octet-stream")); foreach (var mimetype in AllowedMimeTypes) { var sbstr = mimetype.Split(','); switch (sbstr.Length) { case 2: if (sbstr[0].Length != 0 && sbstr[1].Length != 0) { try { this.reader.ContentTypes.Add(sbstr[0], new ContentTypeHeader(sbstr[1])); } catch (ArgumentException) { Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("({0}) <Web Interface> Config.xml contains duplicate Mime Types.", DateTime.Now.ToString("hh:mm")); } } else { Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("({0}) <Web Interface> Config.xml contains invalid Mime Types.", DateTime.Now.ToString("hh:mm")); } break; default: Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("({0}) <Web Interface> Config.xml contains invalid Mime Types.", DateTime.Now.ToString("hh:mm")); break; } } try { this.server.Start(5); SessionManager.Start(this.server); Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("({0}) <Web Interface> Running on Port {1}...", DateTime.Now.ToString("hh:mm"), Port); } catch (SocketException e) { Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("({0}) <Web Interface> {1}", DateTime.Now.ToString("hh:mm"), e); } } else { Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("({0}) <Web Interface> Disabled", DateTime.Now.ToString("hh:mm")); } }