public void should_delete_non_http_binding() { // Arrange string hostname = "helloworld.local"; string bindingInfo = "*:helloworld.local"; var serverConfig = new WebServerConfig(new LoggerStub()); serverConfig .AddSite(TestSiteName, 563, 4887) .AddNonHttpBinding(hostname, "net.pipe") .Commit(); // Act serverConfig .GetSite(TestSiteName) .DeleteNonHttpBinding(hostname, "net.pipe") .Commit(); // Assert var mgr = new ServerManager(); var site = mgr.Sites[TestSiteName]; Binding binding = site.Bindings.FirstOrDefault(x => x.BindingInformation == bindingInfo); Assert.That(binding, Is.Null); }
//public void Initialize(Func<HttpServerConfigVM, Task> onSaveAndApply, Func<string, string, string, Task<HttpServerConfigVM>> onRefresh) //{ // this.OnSaveAndApply = onSaveAndApply; // this.OnRefresh = onRefresh; //} private async void miRefresh_Click(object sender, RoutedEventArgs e) { configVM.IsLoading = true; cmServerConfig.ShowMessageProcess("Refreshing..."); try { Tuple <WebServerConfig, SSLCertVM, SSLCertVM> obj = await Services.OPHttpClient.RequestJsonAsync <Tuple <WebServerConfig, SSLCertVM, SSLCertVM> >(HttpMethod.Get, configVM.Host + "/config/load", configVM.ConfigUsername, configVM.Password); WebServerConfig newWebServerConfig = obj.Item1; if (newWebServerConfig != null) { configVM.Update(newWebServerConfig, obj.Item3.SubjectAlternativeNames); pbConfigPassword.Password = Services.PasswordField; pbConfigPasswordRetype.Password = Services.PasswordField; ((HttpServerConfigVM)uCHttpServerConfig.DataContext).Update(newWebServerConfig, obj.Item2.SubjectAlternativeNames); await Task.Delay(500); cmServerConfig.StopMessage(); } } catch { cmServerConfig.ShowMessageError("Refresh Failed!"); } configVM.IsLoading = false; }
public async void TestWebServerComms() { WebServer webServer = new WebServer(); var resStart = await webServer.StartAsync(); Assert.True(resStart); using (var httpClient = new OPHttpClient()) { StoreName storeName = StoreName.My; StoreLocation storeLocation = StoreLocation.LocalMachine; List <SSLCertVM> certs = await httpClient.RequestJsonAsync <List <SSLCertVM> >(HttpMethod.Get, "http://localhost:5024/config/getsslcerts?storename=" + storeName + "&storelocation=" + storeLocation, "Administrator", "Admin"); Assert.NotNull(certs); WebServerConfig config = await httpClient.RequestJsonAsync <WebServerConfig>(HttpMethod.Get, "http://localhost:5024/config/load", "Administrator", "Admin"); Assert.NotNull(config); var req2 = await httpClient.RequestStatusOnlyAsync(HttpMethod.Put, "http://localhost:5024/config/save", "Administrator", "Admin", new StringContent(JsonConvert.SerializeObject(config), Encoding.UTF8, "application/json")); Assert.Equal(HttpStatusCode.OK, req2); var req3 = await httpClient.RequestStatusOnlyAsync(HttpMethod.Put, "http://localhost:5024/config/save", "Administrator", "Admin", new StringContent("Some Random Data which is not a proper Json", Encoding.UTF8, "application/json")); Assert.Equal(HttpStatusCode.InternalServerError, req3); } }
static void Main(string[] args) { var logger = new ConsoleLogger(); var serverConfig = new WebServerConfig(logger); if (!serverConfig.IsIis7OrAbove) { logger.LogHeading("IIS7 is not installed on this machine. IIS configuration setup terminated."); return; } var envConfig = new Config(); try { serverConfig .AddAppPool(envConfig.SiteName, "v4.0", ManagedPipelineMode.Integrated, ProcessModelIdentityType.LocalService) .WithProcessModel(envConfig.IdleTimeout, envConfig.PingingEnabled) .Commit(); serverConfig .AddSite(envConfig.SiteName, envConfig.PortNumber, envConfig.PortNumber) .AddApplication("/", envConfig.WebRoot, envConfig.SiteName) .WithLogging(false) .Commit(); } catch (Exception e) { logger.LogError(e); } }
public static void init() { string path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); try { Console.WriteLine("\nBegin config initialization..."); // Open the text file using a stream reader. using (StreamReader sr = new StreamReader(path + Path.DirectorySeparatorChar + "config.json")) { // Read the stream to a string, and write the string to the console. String line = sr.ReadToEnd(); CommonConfig commonConfig = JsonConvert.DeserializeObject <CommonConfig>(line); db = commonConfig.dbConfig; logs = commonConfig.logsConfig; webServer = commonConfig.webServer; Console.WriteLine("Config initialized successfully."); } } catch (Exception e) { Console.WriteLine("\nError on read \"config.json\", program can not by start:"); Console.WriteLine(e.Message); LoggerService.writeError(e.Message, e.StackTrace); // Console app System.Environment.Exit(1); } }
private void LoadGlobalConfig() { var data = _jsonConfigReader.Read(GlobalConfigFilename); // read the global config data. // make sure we were able to load global config. if (data == null) { // gracefully exit _logger.Error("Couldn't read config/config.json! Make sure you rename config/config-example.json as config/config.json."); Environment.Exit(-1); } // load log config. LogConfig = new LogConfig(data.logging); // read the log config first, so rest of the config loaders can use log subsystem. _logManager.EmitConfiguration(LogConfig); // assign the log configuration to log manager. // print a version banner. _logger.Information("CoiniumServ {0:l} {1:l} warming-up..", VersionInfo.CodeName, Assembly.GetAssembly(typeof(Program)).GetName().Version); PlatformManager.PrintPlatformBanner(); // load rest of the configs. StackConfig = new StackConfig(data.stack); StatisticsConfig = new StatisticsConfig(data.statistics); WebServerConfig = new WebServerConfig(data.website); }
public void should_delete_binding() { // Arrange string hostname = "helloworld.local"; string bindingInfo = "*:4887:helloworld.local"; var serverConfig = new WebServerConfig(new LoggerStub()); serverConfig .AddSite(TestSiteName, 563, 4887) .AddBinding(4887, hostname, false) .Commit(); // Act serverConfig .GetSite(TestSiteName) .DeleteBinding(4887, hostname) .Commit(); // Assert var mgr = new ServerManager(); var site = mgr.Sites[TestSiteName]; Binding binding = site.Bindings.FirstOrDefault(x => x.BindingInformation == bindingInfo); Assert.That(binding, Is.Null); Assert.That(site.Bindings.ByProtocol("http").BindingInformation, Is.EqualTo("*:4887:")); }
public void should_remove_virtual_directory() { // Arrange const string virtualDirectoryPhysicalPath = @"C:\temp\test"; const string iisPath = "/test"; var serverConfig = new WebServerConfig(new LoggerStub()); // Act serverConfig .AddSite(TestSiteName, 563, 8887) .AddVirtualDirectory(iisPath, virtualDirectoryPhysicalPath) .Commit(); serverConfig .GetSite(TestSiteName) .DeleteVirtualDirectory("/test") .Commit(); // Assert var mgr = new ServerManager(); var site = mgr.Sites[TestSiteName]; Assert.That(site.Applications[0].VirtualDirectories[iisPath], Is.Null); }
/// <summary> /// Create single instance /// </summary> /// <param name="pWebServerConfig"></param> /// <returns></returns> public static DomainFacade getInstance(WebServerConfig pWebServerConfig, IPlugin pPlugin) { if (cInstance == null) { cInstance = new DomainFacade(pWebServerConfig, pPlugin); } return(cInstance); }
/// <summary> /// Create single instance /// </summary> /// <param name="pWebServerConfig"></param> /// <returns></returns> public static InfrastructureFacade getInstance(WebServerConfig pWebServerConfig, IPlugin pPlugin) { if (cInstance == null) { cInstance = new InfrastructureFacade(pWebServerConfig, pPlugin); } return(cInstance); }
private DomainFacade(WebServerConfig pWebServerConfig, IPlugin pPlugin) { cPlugin = pPlugin; cInfrastructure = InfrastructureFacade.getInstance(pWebServerConfig, pPlugin); cObserverList = new List <IObserver>(); cRecordList = new List <Account>(); cRedirectURL = String.Empty; cRemoteHostName = String.Empty; }
//public Func<ServerConfigVM,Task<bool>> OnSaveAndApply; //public Func<string, string, string, Task<WebServerConfig>> OnRefresh; private async void opbLogin_Click(object sender, RoutedEventArgs e) { cmLogin.ShowMessageProcess("Logging in..."); configVM.Host = optbHost.Text; configVM.IsLoggingIn = true; configVM.LoggedIn = false; configVM.Password = pbPassword.Password; uCHttpServerConfig.ucLogConsole.ClearLogs(); try { //WebServerConfig newWebServerConfig = await this.OnRefresh?.Invoke(configVM.Host, configVM.Username, pbConfigPassword.Password); Tuple <WebServerConfig, SSLCertVM, SSLCertVM> obj = await Services.OPHttpClient.RequestJsonAsync <Tuple <WebServerConfig, SSLCertVM, SSLCertVM> >(HttpMethod.Get, configVM.Host + "/config/load", configVM.ConfigUsername, configVM.Password); WebServerConfig newWebServerConfig = obj.Item1; if (newWebServerConfig != null) { configVM.Update(newWebServerConfig, obj.Item3.SubjectAlternativeNames); pbConfigPassword.Password = Services.PasswordField; pbConfigPasswordRetype.Password = Services.PasswordField; ((HttpServerConfigVM)uCHttpServerConfig.DataContext).Update(newWebServerConfig, obj.Item2.SubjectAlternativeNames); //configVM.HttpServerConfigVM.Update(newHttpServerConfig); //configVM.HttpServerConfigVM = new HttpServerConfigVM(newHttpServerConfig); //uCHttpServerConfig.DataContext = null; //uCHttpServerConfig.DataContext = configVM.HttpServerConfigVM; Settings settings = ((Settings)Services.Config); settings.LastHost = configVM.Host; settings.LastUsername = configVM.Username; Services.SaveConfigFile("settings.json", settings); httpServerConfigVM.ClientIsLocal = configVM.Host.Contains("localhost") || configVM.Host.Contains("127.0.0.1"); cmLogin.ShowMessageSuccess("Login Success!"); await Task.Delay(1000); configVM.ShowLoginWindow = false; configVM.LoggedIn = true; } else { cmLogin.ShowMessageError("Login Failed!"); configVM.LoggedIn = false; } } catch { cmLogin.ShowMessageError("Login Failed!"); configVM.LoggedIn = false; } finally { configVM.IsLoggingIn = false; } }
public void should_set_private_memory_limit() { var webServerConfig = new WebServerConfig(new LoggerStub()); webServerConfig .AddAppPool(TestAppPoolName, "v2.0", ManagedPipelineMode.Integrated, ProcessModelIdentityType.LocalService, 666) .Commit(); var serverManger = new ServerManager(); var appPool = serverManger.ApplicationPools[TestAppPoolName]; Assert.That(appPool.Recycling.PeriodicRestart.PrivateMemory, Is.EqualTo(666)); }
public void onStartAttack() { if (Config.IsActive) { if (InvokeRequired) { BeginInvoke(new onStartAttackDelegate(onStartAttack), new object[] { }); return; } // if (InvokeRequired) PluginParameters.HostApplication.PluginSetStatus(this, "green"); setGUIInactive(); if ((!CB_RedirectTo.Checked && !String.IsNullOrEmpty(TB_RemoteHost.Text)) || (CB_RedirectTo.Checked && !String.IsNullOrEmpty(TB_RedirectURL.Text))) { WebServerConfig pConfig = new WebServerConfig { BasisDirectory = Config.BaseDir, isDebuggingOn = PluginParameters.HostApplication.IsDebuggingOn(), isRedirect = CB_RedirectTo.Checked, RedirectToURL = TB_RedirectURL.Text, RemoteHostName = TB_RemoteHost.Text, onWebServerExit = onWebServerExited }; try { cTask.startProxies(pConfig); } catch (Exception lEx) { String lLogMsg = String.Format("{0}: {1}", Config.PluginName, lEx.Message); setGUIActive(); PluginParameters.HostApplication.LogMessage(lLogMsg); PluginParameters.HostApplication.PluginSetStatus(this, "red"); PluginParameters.HostApplication.LogMessage(String.Format("{0}: {1}", Config.PluginName, lEx.Message)); cTask.onStop(); } } else { PluginParameters.HostApplication.LogMessage(String.Format("{0}: No forwarding host/URL defined. Stopping the pluggin.", Config.PluginName)); PluginParameters.HostApplication.PluginSetStatus(this, "grey"); cTask.onStop(); } // if (lRemoteHost ... } // if (cIsActiv... }
public void should_create_apppool_with_timeout_and_pinging_not_enabled() { var webServerConfig = new WebServerConfig(new LoggerStub()); webServerConfig .AddAppPool(TestAppPoolName, "v2.0", ManagedPipelineMode.Integrated, ProcessModelIdentityType.LocalService) .WithProcessModel(TimeSpan.FromDays(1), false) .Commit(); var serverManger = new ServerManager(); var appPool = serverManger.ApplicationPools[TestAppPoolName]; Assert.That(appPool.ProcessModel.PingingEnabled, Is.False); Assert.That(appPool.ProcessModel.IdleTimeout, Is.EqualTo(TimeSpan.FromDays(1))); }
public void should_create_app_pool() { var webServerConfig = new WebServerConfig(new LoggerStub()); webServerConfig .AddAppPool(TestAppPoolName, "v2.0", ManagedPipelineMode.Integrated, ProcessModelIdentityType.LocalService) .Commit(); var serverManger = new ServerManager(); var appPool = serverManger.ApplicationPools[TestAppPoolName]; Assert.That(appPool.ManagedRuntimeVersion, Is.EqualTo("v2.0")); Assert.That(appPool.ManagedPipelineMode, Is.EqualTo(ManagedPipelineMode.Integrated)); Assert.That(appPool.ProcessModel.IdentityType, Is.EqualTo(ProcessModelIdentityType.LocalService)); }
public void should_create_apppool_with_apppool_queuelength_and_rapid_fail_protection() { var webServerConfig = new WebServerConfig(new LoggerStub()); webServerConfig .AddAppPool(TestAppPoolName, "v2.0", ManagedPipelineMode.Integrated, ProcessModelIdentityType.LocalService) .WithAppPoolQueueLength(10) .WithRapidFailProtection(true) .Commit(); var serverManger = new ServerManager(); var appPool = serverManger.ApplicationPools[TestAppPoolName]; Assert.That(appPool.QueueLength, Is.EqualTo(10)); Assert.That(appPool.Failure["RapidFailProtection"].ToString(), Is.EqualTo("True")); }
private void ReadGlobalConfig() { var data = _jsonConfigReader.Read(GlobalConfigFilename); // read the global config data. if (data == null) // make sure it exists, else gracefully exists { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Couldn't read config/config.json! Make sure you rename config/config-example.json as config/config.json."); Console.ResetColor(); Environment.Exit(-1); } StackConfig = new StackConfig(data.stack); WebServerConfig = new WebServerConfig(data.website); LogConfig = new LogConfig(data.logging); }
public void should_add_site() { // Arrange var serverConfig = new WebServerConfig(new LoggerStub()); // Act serverConfig .AddSite(TestSiteName, 563, 8887) .Commit(); // Assert var mgr = new ServerManager(); var site = mgr.Sites[TestSiteName]; Assert.That(site.Id, Is.EqualTo(563)); Assert.That(site.Bindings.ByProtocol("http").BindingInformation, Is.EqualTo("*:8887:")); Assert.That(site.ServerAutoStart, Is.True); }
public void should_add_virtual_directory_with_config_substitution() { // Arrange string iisPath = "/test"; var serverConfig = new WebServerConfig(new LoggerStub()); // Act serverConfig .AddSite(TestSiteName, 563, 8887) .AddVirtualDirectory(iisPath, @"{WebRoot}\mysite") .Commit(); // Assert var mgr = new ServerManager(); var site = mgr.Sites[TestSiteName]; Assert.That(site.Applications[0].VirtualDirectories[iisPath].PhysicalPath, Is.EqualTo(@"d:\websites\mysite")); }
public void should_create_site_with_ssl_port() { // Arrange string certPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "iisconfiguration.pfx"); var serverConfig = new WebServerConfig(new LoggerStub()); // Act serverConfig .AddSite(TestSiteName, 563, 8887) .WithSecurePort(4887, certPath, "password") .Commit(); // Assert var mgr = new ServerManager(); var site = mgr.Sites[TestSiteName]; Assert.That(site.Bindings.ByProtocol("https").BindingInformation, Is.EqualTo("*:4887:")); }
public void should_add_site_with_application() { // Arrange const string applicationPhysicalPath = @"C:\temp"; var serverConfig = new WebServerConfig(new LoggerStub()); // Act serverConfig .AddSite(TestSiteName, 563, 8887) .AddApplication("/", applicationPhysicalPath, TestSiteName) .Commit(); // Assert var mgr = new ServerManager(); var site = mgr.Sites[TestSiteName]; Assert.That(site.Applications[0].ApplicationPoolName, Is.EqualTo(TestSiteName)); Assert.That(site.Applications[0].VirtualDirectories[0].PhysicalPath, Is.EqualTo(applicationPhysicalPath)); }
public void should_add_non_http_binding() { // Arrange string expectedBindingInfo = "helloworld.local"; var serverConfig = new WebServerConfig(new LoggerStub()); // Act serverConfig .AddSite(TestSiteName, 563, 4887) .AddNonHttpBinding(expectedBindingInfo, "net.pipe") .Commit(); // Assert var mgr = new ServerManager(); var site = mgr.Sites[TestSiteName]; Binding binding = site.Bindings.First(x => x.BindingInformation == expectedBindingInfo); Assert.That(binding, Is.Not.Null); }
public void should_add_site_with_alternate_logging_directory() { // Arrange var serverConfig = new WebServerConfig(new LoggerStub()); // Act serverConfig .AddSite(TestSiteName, 563, 8887) .WithLogDirectory(@"C:\logs") .Commit(); // Assert var mgr = new ServerManager(); var site = mgr.Sites[TestSiteName]; Assert.That(site.Id, Is.EqualTo(563)); Assert.That(site.Bindings.ByProtocol("http").BindingInformation, Is.EqualTo("*:8887:")); Assert.That(site.LogFile.Directory, Is.EqualTo(@"C:\logs")); }
public IActionResult Server(WebServerConfig model) { if (model != null) { SystemController.webServerConfig = model; dynamic json = ReadConfig(); json.WebServer.Address = model.Address; WriteConfig(json); json = JObject.Parse(System.IO.File.ReadAllText(hosting_file)); json.urls = model.Address; System.IO.File.WriteAllText(hosting_file, json.ToString()); configuration.Reload(); } return(RedirectToAction("Index")); }
public IActionResult Server(WebServerConfig model) { if (model != null) { SystemController.webServerConfig = model; dynamic json = ReadConfig(); json.WebServer.Address = model.Address; WriteConfig(json); json = JObject.Parse(System.IO.File.ReadAllText(project_file)); json.commands.web = $"Microsoft.AspNet.Server.Kestrel --server.urls {model.Address}"; System.IO.File.WriteAllText(project_file, json.ToString()); configuration.Reload(); } return(RedirectToAction("Index")); }
public void Start() { var logger = new ConsoleLogger(); var serverConfig = new WebServerConfig(logger); // Current directory: src\Roadkill.Tests\bin\Debug string webRoot = Environment.CurrentDirectory + @"..\..\..\..\Roadkill.Web"; var dirInfo = new DirectoryInfo(webRoot); serverConfig .AddAppPool(_siteName, "v4.0", ManagedPipelineMode.Integrated, ProcessModelIdentityType.LocalService) .WithProcessModel(TimeSpan.FromMinutes(60), false) .Commit(); serverConfig .AddSite(_siteName, _webPort, _webPort) .AddApplication("/", dirInfo.FullName, _siteName) .WithLogging(false) .Commit(); }
private InfrastructureFacade(WebServerConfig pWebServerConfig, IPlugin pPlugin) { cWebServerConfig = pWebServerConfig; cPlugin = pPlugin; cHTTPRevProxyPath = String.Format("{0}{1}", pWebServerConfig.BasisDirectory, cHTTPRevProxyBin); cHTTPSRevProxyPath = String.Format("{0}{1}", pWebServerConfig.BasisDirectory, cHTTPSRevProxyBin); // Create Session directory if it doesn't exist try { if (!Directory.Exists(cPlugin.Config.SessionDir)) { Directory.CreateDirectory(cPlugin.Config.SessionDir); } } catch (Exception lEx) { } }
public void Start() { var logger = new ConsoleLogger(); var serverConfig = new WebServerConfig(logger); // Current directory: src\Roadkill.Tests\bin\Debug string webRoot = Environment.CurrentDirectory + @"..\..\..\..\Roadkill.Web"; var dirInfo = new DirectoryInfo(webRoot); serverConfig .AddAppPool(_siteName, "v4.0", ManagedPipelineMode.Integrated, ProcessModelIdentityType.LocalService) .WithProcessModel(TimeSpan.FromMinutes(60), false) .Commit(); serverConfig .AddSite(_siteName, _webPort, _webPort) .AddApplication("/", dirInfo.FullName, _siteName) .WithLogging(false) .Commit(); }
public void should_add_binding() { // Arrange string hostname = ""; string expectedBindingInfo = "*:4887:"; var serverConfig = new WebServerConfig(new LoggerStub()); // Act serverConfig .AddSite(TestSiteName, 563, 4887) .AddBinding(4887, hostname, false) .Commit(); // Assert var mgr = new ServerManager(); var site = mgr.Sites[TestSiteName]; Binding binding = site.Bindings.First(x => x.BindingInformation == expectedBindingInfo); Assert.That(binding, Is.Not.Null); }
public void should_add_protocol() { // Arrange string hostname = "helloworld.local"; string expectedProtocol = "http,net.pipe"; var serverConfig = new WebServerConfig(new LoggerStub()); // Act serverConfig .AddSite(TestSiteName, 563, 4887) .AddBinding(4887, hostname, false) .AddProtocol(4887, hostname, "net.pipe") .Commit(); // Assert var mgr = new ServerManager(); var site = mgr.Sites[TestSiteName]; var application = site.Applications.First(); Assert.AreEqual(expectedProtocol, application.EnabledProtocols); }
/// <summary> /// /// </summary> /// <param name="pWebServerConfig"></param> public void onInit(WebServerConfig pWebServerConfig) { Process[] lProcInstances; cWebServerConfig = pWebServerConfig; if ((lProcInstances = Process.GetProcessesByName(cHTTPRevProxyName)) != null && lProcInstances.Length > 0) { foreach (Process lProc in lProcInstances) { try { lProc.Kill(); } catch (Exception) { } } } if ((lProcInstances = Process.GetProcessesByName(cHTTPSRevProxyName)) != null && lProcInstances.Length > 0) { foreach (Process lProc in lProcInstances) { try { lProc.Kill(); } catch (Exception) { } } } }
public DefaultWebServer(WebServerConfig wsc, StringBuilder sb) { Assert.IsTrue(wsc.Port > 0, "No port number specified"); Assert.IsNotNull("No host name specified", wsc.Host); sb.Append("-WebServer:" + wsc.Host + ":" + wsc.Port); }
public DefaultWebServer(WebServerConfig wsc) { Assert.IsNotNull(wsc.Host); Assert.IsTrue(wsc.Port > 0); }