private void DoSetUser(ManosApp app, object user_data) { #if DISABLE_POSIX throw new InvalidOperationException("Attempt to set user on a non-posix build."); #else string user = user_data as string; Console.WriteLine("setting user to: '{0}'", user); if (user == null) { AppHost.Stop(); throw new InvalidOperationException(String.Format("Attempting to set user to null.")); } Passwd pwd = Syscall.getpwnam(user); if (pwd == null) { AppHost.Stop(); throw new InvalidOperationException(String.Format("Unable to find user '{0}'.", user)); } int error = Syscall.seteuid(pwd.pw_uid); if (error != 0) { AppHost.Stop(); throw new InvalidOperationException(String.Format("Unable to switch to user '{0}' error: '{1}'.", user, error)); } #endif }
public void Run() { // Load the config. ManosConfig.Load(); app = Loader.LoadLibrary <ManosApp> (ApplicationAssembly, Arguments); Console.WriteLine("Running {0} on port {1}.", app, Port); if (User != null) { SetServerUser(User); } var listenAddress = Manos.IO.IPAddress.Any; if (IPAddress != null) { listenAddress = Manos.IO.IPAddress.Parse(IPAddress); } AppHost.ListenAt(new Manos.IO.IPEndPoint(listenAddress, Port)); if (SecurePort != null) { AppHost.InitializeTLS("NORMAL"); AppHost.SecureListenAt(new Manos.IO.IPEndPoint(listenAddress, SecurePort.Value), CertificateFile, KeyFile); Console.WriteLine("Running {0} on secure port {1}.", app, SecurePort); } AppHost.Start(app); }
public static bool TryGetDataForParamList(ParameterInfo [] parameters, ManosApp app, IManosContext ctx, out object [] data) { data = new object [parameters.Length]; int param_start = 1; data [0] = ctx; if (typeof(ManosApp).IsAssignableFrom(parameters [1].ParameterType)) { data [1] = app; ++param_start; } for (int i = param_start; i < data.Length; i++) { string name = parameters [i].Name; if (!TryConvertType(ctx, name, parameters [i], out data [i])) { return(false); } } return(true); }
public ManosBrowser(ManosApp app) { _app = app; _app.StartInternal(); Request = new MockHttpRequest(); Response = new MockHttpResponse(); Transaction = new MockHttpTransaction(Request, Response); }
public ManosBrowser(ManosApp app) { _app = app; _app.StartInternal (); Request = new MockHttpRequest (); Response = new MockHttpResponse (); Transaction = new MockHttpTransaction (Request, Response); }
protected virtual void HandleExpires(ManosApp app, object obj_item) { CacheItem item = (CacheItem) obj_item; if (item.IsRemoved) return; item.IsRemoved = true; lock (lock_obj) { items.Remove (item.Key); } }
public void Run(ManosApp app) { try { callback (app, data); } catch (Exception e) { Console.Error.WriteLine ("Exception in timeout callback."); Console.Error.WriteLine (e); } repeat.RepeatPerformed (); }
protected virtual void HandleExpires(ManosApp app, object obj_item) { CacheItem item = (CacheItem)obj_item; if (item.IsRemoved) { return; } item.IsRemoved = true; items.Remove(item.Key); }
public void Invoke(ManosApp app, IManosContext ctx) { object [] data; if (!TryGetDataForParamList(parameters, app, ctx, out data)) { // TODO: More graceful way of handling this? ctx.Transaction.Abort(400, "Can not convert parameters to match Action argument list."); return; } action(target, data); }
public static bool TryGetDataForParamList(ParameterInfo [] parameters, ManosApp app, IManosContext ctx, out object [] data) { data = new object [parameters.Length]; data [0] = app; data [1] = ctx; for (int i = 2; i < data.Length; i++) { string name = parameters [i].Name; string strd = ctx.Request.Data.Get (name); if (!TryConvertType (ctx, parameters [i].ParameterType, strd, out data [i])) return false; } return true; }
public ManosApp LoadLibrary(string library) { Assembly a = Assembly.LoadFrom(library); foreach (Type t in a.GetTypes()) { if (t.BaseType == typeof(ManosApp)) { if (app != null) { throw new Exception("Library contains multiple apps."); } app = CreateAppInstance(t); } } return(app); }
public void Run() { app = Loader.LoadLibrary <ManosApp> (ApplicationAssembly, Arguments); Console.WriteLine("Running {0} on port {1}.", app, Port); if (User != null) { SetServerUser(User); } if (IPAddress != null) { AppHost.IPAddress = System.Net.IPAddress.Parse(IPAddress); } AppHost.Port = Port; AppHost.Start(app); }
void StartServer() { if (app == null) { app = LoadLibrary(ApplicationAssembly); } _statusLabel.Text = "Started on port " + _port.Value; var listenAddress = System.Net.IPAddress.Any; AppHost.ListenAt(new System.Net.IPEndPoint(listenAddress, _port.Value)); _thread = new Thread(new ThreadStart(delegate { Console.WriteLine("Before Start!"); AppHost.Start(app); Console.WriteLine("Duh"); })); _thread.IsBackground = true; _thread.Start(); }
public override void OnPostProcessRequest(ManosApp app, IHttpTransaction transaction) { // LogFormat "%h %l %u %t "%r" %>s %b "%{Referer}i" "%{User-Agent}i"" combined // %h - Remote host -- DONT HAVE // %l - Remote log name -- DONT HAVE // %u - Remote user -- DONT HAVE // %t - Date+Time // %r - Request path // %s - Status Code // %b - Bytes sent // %Referer - // %User Agent - string line = String.Format("- - - [{0}] \"{1}\" {2} {3} - -\n", DateTime.Now.ToString("dd/MMM/yyyy:HH:mm:ss K"), transaction.Request.Path, transaction.Response.StatusCode, transaction.Response.Headers.ContentLength); byte [] data = Encoding.Default.GetBytes(line); stream.BeginWrite(data, 0, data.Length, null, null); }
public static bool TryGetDataForParamList(ParameterInfo [] parameters, ManosApp app, IManosContext ctx, out object [] data) { data = new object [parameters.Length]; int param_start = 1; data [0] = ctx; if (typeof (ManosApp).IsAssignableFrom (parameters [1].ParameterType)) { data [1] = app; ++param_start; } for (int i = param_start; i < data.Length; i++) { string name = parameters [i].Name; UnsafeString strd = ctx.Request.Data.Get (name); if (!TryConvertType (ctx, parameters [i].ParameterType, strd, out data [i])) return false; } return true; }
public void Run() { // Load the config. ManosConfig.Load(); app = Loader.LoadLibrary <ManosApp> (ApplicationAssembly, Arguments); Console.WriteLine("Running {0} on port {1}.", app, Port); if (User != null) { SetServerUser(User); } var listenAddress = System.Net.IPAddress.Any; if (IPAddress != null) { listenAddress = System.Net.IPAddress.Parse(IPAddress); } AppHost.ListenAt(new System.Net.IPEndPoint(listenAddress, Port)); AppHost.Start(app); }
private void DoSetUser(ManosApp app, object user_data) { #if DISABLE_POSIX throw new InvalidOperationException ("Attempt to set user on a non-posix build."); #else var user = user_data as string; Console.WriteLine("setting user to: '{0}'", user); if (user == null) { AppHost.Stop(); throw new InvalidOperationException(String.Format("Attempting to set user to null.")); } Passwd pwd = Syscall.getpwnam(user); if (pwd == null) { AppHost.Stop(); throw new InvalidOperationException(String.Format("Unable to find user '{0}'.", user)); } int error = Syscall.seteuid(pwd.pw_uid); if (error != 0) { AppHost.Stop(); throw new InvalidOperationException(String.Format("Unable to switch to user '{0}' error: '{1}'.", user, error)); } #endif }
private void ExpireTransactions(ManosApp app, object data) { DateTime now = DateTime.UtcNow; int count = transactions.Count (); transactions.RemoveAll (t => t.IOStream.Expires <= now); }
public void Run() { // Setup the document root if (DocumentRoot != null) { Directory.SetCurrentDirectory(Path.Combine(Directory.GetCurrentDirectory(), DocumentRoot)); } // Load the config. ManosConfig.Load(); app = Loader.LoadLibrary<ManosApp>(ApplicationAssembly, Arguments); Console.WriteLine("Running {0} on port {1}.", app, Port); if (User != null) SetServerUser(User); IPAddress listenAddress = IO.IPAddress.Any; if (IPAddress != null) listenAddress = IO.IPAddress.Parse(IPAddress); AppHost.ListenAt(new IPEndPoint(listenAddress, Port)); if (SecurePort != null) { AppHost.InitializeTLS("NORMAL"); AppHost.SecureListenAt(new IPEndPoint(listenAddress, SecurePort.Value), CertificateFile, KeyFile); Console.WriteLine("Running {0} on secure port {1}.", app, SecurePort); } if (Browse != null) { string hostname = IPAddress == null ? "http://localhost" : "http://" + IPAddress; if (Port != 80) hostname += ":" + Port; if (Browse == "") { Browse = hostname; } if (Browse.StartsWith("/")) { Browse = hostname + Browse; } if (!Browse.StartsWith("http://") && !Browse.StartsWith("https://")) Browse = "http://" + Browse; AppHost.AddTimeout(TimeSpan.FromMilliseconds(10), RepeatBehavior.Single, Browse, DoBrowse); } AppHost.Start(app); }
private static void DoBrowse(ManosApp app, object user_data) { var BrowseTo = user_data as string; Console.WriteLine("Launching {0}", BrowseTo); Process.Start(BrowseTo); }
public void Invoke(ManosApp app, IManosContext ctx) { action(ctx); }
public void Invoke(ManosApp app, IManosContext ctx) { throw new System.NotImplementedException(); }
public void SomeStaticActionTwoStringsShouldMatch(ManosApp app, IManosContext ctx, string a, string b) { action_invoked_properly = (a == b); }
public void SomeStaticActionBoolParam(ManosApp app, IManosContext ctx, bool b) { action_invoked_properly = b; }
private static void DoBrowseTo(ManosApp app, object user_data) { string BrowseTo=user_data as string; Console.WriteLine("Launching {0}", BrowseTo); System.Diagnostics.Process.Start(BrowseTo); }
public static bool TryGetDataForParamList(ParameterInfo[] parameters, ManosApp app, IManosContext ctx, out object[] data) { data = new object[parameters.Length]; for (int i = 0; i < data.Length; i++) { // Context? if (typeof(IManosContext).IsAssignableFrom(parameters[i].ParameterType)) { data[i] = ctx; continue; } // App? if (app != null && typeof(ManosApp).IsAssignableFrom(parameters[i].ParameterType)) { data[i] = app; continue; } // Some other parameter string name = parameters[i].Name; if (!TryConvertType(ctx, name, parameters[i], out data[i])) return false; } return true; }
public void Invoke(ManosApp app, IManosContext ctx) { action (ctx); }
public void Invoke(ManosApp app, IManosContext ctx) { object [] data; if (!TryGetDataForParamList (parameters, app, ctx, out data)) { // TODO: More graceful way of handling this? ctx.Transaction.Abort (400, "Can not convert parameters to match Action argument list."); return; } action (target, data); }
public void SomeStaticActionNoParams(ManosApp app, IManosContext ctx) { action_invoked_properly = true; }