public override void OnOperation(HttpListenerContext context, Authentication authentication) { context.Response.ContentType = "application/json"; byte[] data = Misc.ToByteArray(context.Request.InputStream); string json = Encoding.UTF8.GetString(data); if (!authentication.IsSignedIn) { HttpStream stream = new HttpStream(context.Response); stream.Send(new SignOutResponse() { Error = "You are not signed in." }.ToJson()); stream.Close(); return; } SessionsManager.Instance.RemoveSession(authentication.SessionID); // Delete the sessionID cookie Cookie cookie = context.Request.Cookies["SessionID"]; cookie.Expires = DateTime.Now.AddDays(-10); cookie.Value = null; context.Response.SetCookie(cookie); HttpStream httpStream = new HttpStream(context.Response); httpStream.Send(new SignOutResponse() { message = "signed out!" }.ToJson()); httpStream.Close(); }
public override void OnOperation(HttpListenerContext context, Authentication authentication) { context.Response.ContentType = "text/plain"; HttpStream stream = new HttpStream(context.Response); stream.Send(authentication.IP); stream.Close(); }
public override void OnOperation(HttpListenerContext context, Authentication authentication) { if (!context.Request.IsWebSocketRequest) { context.Response.StatusCode = (int)HttpStatusCode.BadRequest; HttpStream httpStream = new HttpStream(context.Response); httpStream.Send("<html><body>websocket only!</body></html>"); httpStream.Close(); } if (!authentication.HasAtLeastAuthenticationLevel(Users.AuthenticationLevel.Admin)) { HttpListenerWebSocketContext webNoSocket = context.AcceptWebSocketAsync(null).ConfigureAwait(true).GetAwaiter().GetResult(); byte[] buffer = Encoding.UTF8.GetBytes("You do not have the requierd permissions to use this."); webNoSocket.WebSocket.SendAsync(new ArraySegment <byte>(buffer), WebSocketMessageType.Text, true, System.Threading.CancellationToken.None).ConfigureAwait(true).GetAwaiter().GetResult(); webNoSocket.WebSocket.CloseAsync(WebSocketCloseStatus.NormalClosure, "You do not have the requierd permissions to use this.", System.Threading.CancellationToken.None).ConfigureAwait(true).GetAwaiter().GetResult(); webNoSocket.WebSocket.Dispose(); return; } Task.Factory.StartNew(() => handleWebSocket(context, authentication)); }
public override void OnOperation(HttpListenerContext context, Authentication authentication) { string key = Utils.GenerateSecureKey(); NotesManager.Instance.SetNote(key, "Operation still loading...."); HttpStream stream = new HttpStream(context.Response); stream.Send("Link: https://modbot.org/api?operation=noteOperation&key=" + key); stream.Close(); string output; try { output = OnFrontendPushed(); } catch (Exception e) { output = "Error!\n" + e.ToString(); } NotesManager.Instance.SetNote(key, output); }