/// <summary> /// Initializes a new instance of the <see cref="AddWebsiteModule"/> class. /// </summary> /// <param name="stumpsHost">The <see cref="IStumpsHost"/> used by the instance.</param> /// <exception cref="ArgumentNullException"><paramref name="stumpsHost"/> is <c>null</c>.</exception> public AddWebsiteModule(IStumpsHost stumpsHost) { stumpsHost = stumpsHost ?? throw new ArgumentNullException(nameof(stumpsHost)); Get["/AddWebsite"] = _ => { var port = NetworkInformation.FindRandomOpenPort(); var model = new { OpenPort = port }; return(View["addwebsite", model]); }; Post["/AddWebsite"] = _ => { var hostNameTextBox = ((string)(Request.Form.hostNameTextBox.Value ?? string.Empty)).Trim(); var portTextBox = ((string)(Request.Form.portTextBox.Value ?? string.Empty)).Trim(); var useSslCheckBox = ((string)(Request.Form.useSslCheckBox.Value ?? "off")).Trim(); int port; port = int.TryParse(portTextBox, out port) ? port : 0; var useSsl = useSslCheckBox.Equals("on", StringComparison.OrdinalIgnoreCase); if (!string.IsNullOrEmpty(hostNameTextBox) && port > 0) { stumpsHost.CreateServerInstance(hostNameTextBox, port, useSsl, true); } return(Response.AsRedirect("/")); }; }
/// <summary> /// Initializes a new instance of the <see cref="T:Stumps.Web.ApiModules.ProxyServerModule"/> class. /// </summary> /// <param name="stumpsHost">The <see cref="T:Stumps.Server.IStumpsHost"/> used by the instance.</param> /// <exception cref="System.ArgumentNullException"><paramref name="stumpsHost"/> is <c>null</c>.</exception> public ProxyServerModule(IStumpsHost stumpsHost) : base("/api") { if (stumpsHost == null) { throw new ArgumentNullException("stumpsHost"); } Get["/proxy"] = _ => { var modelList = new List<ProxyServerDetailsModel>(); var serverList = stumpsHost.FindAll(); foreach (var server in serverList) { var model = new ProxyServerDetailsModel { AutoStart = server.AutoStart, ExternalHostName = server.RemoteServerHostName, IsRunning = server.IsRunning, Port = server.ListeningPort, RecordCount = server.Recordings.Count, RecordTraffic = server.RecordTraffic, RequestsServed = server.TotalRequestsServed, StumpsCount = server.StumpCount, StumpsServed = server.RequestsServedWithStump, ProxyId = server.ServerId, UseSsl = server.UseSsl }; modelList.Add(model); } return Response.AsJson(modelList); }; Post["/proxy"] = _ => { var model = this.Bind<ProxyServerModel>(); stumpsHost.CreateServerInstance(model.ExternalHostName, model.Port, model.UseSsl, model.AutoStart); return HttpStatusCode.Created; }; Delete["/proxy/{serverId}"] = _ => { var serverId = (string)_.serverId; stumpsHost.DeleteServerInstance(serverId); return HttpStatusCode.OK; }; }
/// <summary> /// Initializes a new instance of the <see cref="ProxyServerModule"/> class. /// </summary> /// <param name="stumpsHost">The <see cref="IStumpsHost"/> used by the instance.</param> /// <exception cref="ArgumentNullException"><paramref name="stumpsHost"/> is <c>null</c>.</exception> public ProxyServerModule(IStumpsHost stumpsHost) : base("/api") { stumpsHost = stumpsHost ?? throw new ArgumentNullException(nameof(stumpsHost)); Get["/proxy"] = _ => { var modelList = new List <ProxyServerDetailsModel>(); var serverList = stumpsHost.FindAll(); foreach (var server in serverList) { var model = new ProxyServerDetailsModel { AutoStart = server.AutoStart, ExternalHostName = server.RemoteServerHostName, IsRunning = server.IsRunning, Port = server.ListeningPort, RecordCount = server.Recordings.Count, RecordTraffic = server.RecordTraffic, RequestsServed = server.TotalRequestsServed, StumpsCount = server.StumpCount, StumpsServed = server.RequestsServedWithStump, ProxyId = server.ServerId, UseSsl = server.UseSsl }; modelList.Add(model); } return(Response.AsJson(modelList)); }; Post["/proxy"] = _ => { var model = this.Bind <ProxyServerModel>(); stumpsHost.CreateServerInstance(model.ExternalHostName, model.Port, model.UseSsl, model.AutoStart); return(HttpStatusCode.Created); }; Delete["/proxy/{serverId}"] = _ => { var serverId = (string)_.serverId; stumpsHost.DeleteServerInstance(serverId); return(HttpStatusCode.OK); }; }
/// <summary> /// Initializes a new instance of the <see cref="T:Stumps.Web.ViewModules.AddWebsiteModule"/> class. /// </summary> /// <param name="stumpsHost">The <see cref="T:Stumps.Server.IStumpsHost"/> used by the instance.</param> /// <exception cref="System.ArgumentNullException"><paramref name="stumpsHost"/> is <c>null</c>.</exception> public AddWebsiteModule(IStumpsHost stumpsHost) { if (stumpsHost == null) { throw new ArgumentNullException("stumpsHost"); } Get["/AddWebsite"] = _ => { var port = NetworkInformation.FindRandomOpenPort(); var model = new { OpenPort = port }; return View["addwebsite", model]; }; Post["/AddWebsite"] = _ => { var hostNameTextBox = ((string)(Request.Form.hostNameTextBox.Value ?? string.Empty)).Trim(); var portTextBox = ((string)(Request.Form.portTextBox.Value ?? string.Empty)).Trim(); var useSslCheckBox = ((string)(Request.Form.useSslCheckBox.Value ?? "off")).Trim(); int port; port = int.TryParse(portTextBox, out port) ? port : 0; var useSsl = useSslCheckBox.Equals("on", StringComparison.OrdinalIgnoreCase); if (!string.IsNullOrEmpty(hostNameTextBox) && port > 0) { stumpsHost.CreateServerInstance(hostNameTextBox, port, useSsl, true); } return Response.AsRedirect("/"); }; }