public override void Command(MenuItem menuItem, string UserInput) { HTTPListenerMenuItem httpListenerMenuItem = (HTTPListenerMenuItem)menuItem; httpListenerMenuItem.Refresh(); EliteConsoleMenu menu = new EliteConsoleMenu(EliteConsoleMenu.EliteConsoleMenuType.Parameter, "HTTP Listener"); menu.Rows.Add(new List <string> { "Name:", httpListenerMenuItem.httpListener.Name }); menu.Rows.Add(new List <string> { "Description:", httpListenerMenuItem.httpListener.Description }); menu.Rows.Add(new List <string> { "URL:", httpListenerMenuItem.httpListener.Url }); menu.Rows.Add(new List <string> { " ConnectAddress:", httpListenerMenuItem.httpListener.ConnectAddress }); menu.Rows.Add(new List <string> { " BindAddress:", httpListenerMenuItem.httpListener.BindAddress }); menu.Rows.Add(new List <string> { " BindPort:", httpListenerMenuItem.httpListener.BindPort.ToString() }); menu.Rows.Add(new List <string> { " UseSSL:", (httpListenerMenuItem.httpListener.UseSSL ?? default) ? "True" : "False" });
public override void Command(MenuItem menuItem, string UserInput) { HTTPListenerMenuItem httpListenerMenuItem = (HTTPListenerMenuItem)menuItem; // TODO: error if http lsitener already on this port if ((httpListenerMenuItem.httpListener.UseSSL ?? default) && (httpListenerMenuItem.httpListener.SslCertHash == "" || httpListenerMenuItem.httpListener.SslCertificate == "")) { EliteConsole.PrintWarning("No SSLCertificate specified. Would you like to generate and use a self-signed certificate? [y/N] "); string input = EliteConsole.Read(); if (input.ToLower().StartsWith("y")) { X509Certificate2 certificate = Utilities.CreateSelfSignedCertificate(httpListenerMenuItem.httpListener.BindAddress); string autopath = "httplistener-" + httpListenerMenuItem.httpListener.Id + "-certificate.pfx"; File.WriteAllBytes(Path.Combine(Common.EliteDataFolder, autopath), certificate.Export(X509ContentType.Pfx, httpListenerMenuItem.httpListener.SslCertificatePassword)); EliteConsole.PrintFormattedInfoLine("Certificate written to: " + autopath); httpListenerMenuItem.AdditionalOptions.FirstOrDefault(O => O.Name == "Set").Command(httpListenerMenuItem, "Set SSLCertPath " + autopath); } else { EliteConsole.PrintFormattedErrorLine("Must specify an SSLCertfiicate to Start an HTTP Listener with SSL."); return; } } httpListenerMenuItem.Refresh(); httpListenerMenuItem.httpListener.Status = ListenerStatus.Active; httpListenerMenuItem.httpListener = this.CovenantClient.ApiListenersHttpPut(httpListenerMenuItem.httpListener); EventModel eventModel = new EventModel { Message = "Started HTTP Listener: " + httpListenerMenuItem.httpListener.Name + " at: " + httpListenerMenuItem.httpListener.Url, Level = EventLevel.Highlight, Context = "*" }; eventModel = this.CovenantClient.ApiEventsPost(eventModel); this.EventPrinter.PrintEvent(eventModel); httpListenerMenuItem.RefreshHTTPTemplate(); httpListenerMenuItem.Refresh(); }