public void CommandToStringTests() { var shoot = OutputConvertors.CommandToString(Command.Shoot); Assert.AreEqual("SHOOT#", shoot); var left = OutputConvertors.CommandToString(Command.Left); Assert.AreEqual("LEFT#", left); var right = OutputConvertors.CommandToString(Command.Right); Assert.AreEqual("RIGHT#", right); var up = OutputConvertors.CommandToString(Command.Up); Assert.AreEqual("UP#", up); var down = OutputConvertors.CommandToString(Command.Down); Assert.AreEqual("DOWN#", down); var join = OutputConvertors.CommandToString(Command.Join); Assert.AreEqual("JOIN#", join); }
public static void Main(string[] args) { Output.TcpOutput.OnNext(OutputConvertors.CommandToString(Command.Join)); var outputSubscription = SubscriptionManager.OutputSubscription; var connection = SubscriptionManager.StateAndMessageStream.Connect(); Console.ReadKey(); outputSubscription.Dispose(); connection.Dispose(); }
public bool CheckCookie(HttpCookie cookie) { if (base.Check(cookie.Name)) { HttpCookie tempCookie = OutputConvertors.DuplicateCookie(cookie); string cookieName = ""; switch (encryptionMethod) { case (ViewStateStatus.Method.MD5): { cookieName = FormsAuthentication.HashPasswordForStoringInConfigFile(cookie.Name, "md5"); break; } case (ViewStateStatus.Method.SHA1): { cookieName = FormsAuthentication.HashPasswordForStoringInConfigFile(cookie.Name, "sha1"); break; } case (ViewStateStatus.Method.GUID): { cookieName = Guid.NewGuid().ToString(); break; } case (ViewStateStatus.Method.NONE): { cookieName = cookieName; break; } } cookie.Values.Clear(); cookie.Name = cookieName; cookie.Value = ""; storage.Add(cookieName, tempCookie); return(true); } return(false); }
private void ConnectButton_Click(object sender, RoutedEventArgs e) { Output.TcpOutput.OnNext(OutputConvertors.CommandToString(Command.Join)); Task.Run(() => SubscriptionManager.StateAndMessageStream.Connect()); }
/// <summary> /// The Custom MainHandlingSection, which will be used to handle The PreRequests /// </summary> /// <param name="sender">The HttpApplication</param> /// <param name="e">The Sended Event Arguments</param> public void MainHandlingSection(object sender, EventArgs e) { HttpApplication httpApplication = (HttpApplication)sender; HttpContext httpContext = HttpContext.Current; HttpResponse response = httpContext.Response; HttpRequest request = httpContext.Request; int _errorcount = 0; #region Show and Log The Post Body if (httpContext.Request.RequestType == "POST") { if (this.viewStateStatus != null && this.viewStateStatus.Active == true) { log.Debug("Processing View State Putting It Back"); ReflectionUtils.makeTheRequestFormDataEditable(); string viewState = httpContext.Request.Form[VIEW_STATE_TEXT]; viewState = this.viewStateStatus.ViewStateStorage.Get(viewState); if (viewState != null) { httpContext.Request.Form[VIEW_STATE_TEXT] = this.viewStateStatus.ViewStateStorage.Get(viewState); } log.Debug("End Of View State Process"); } Stream httpStream = httpContext.Request.InputStream; StreamReader reader = new StreamReader(httpStream); String rawRequest = reader.ReadToEnd(); log.Debug("The Raw Request To The Application"); log.Debug("------------------------------------------------------------------------------"); log.Debug(rawRequest); log.Debug("------------------------------------------------------------------------------"); } #endregion if (request.Url.ToString().IndexOf(DefenceMainSettings.DEFAULT_PAGE) > 0) { response.Write(DoLogTable()); response.End(); } else if (request.Url.ToString().IndexOf(DefenceMainSettings.DEFAULT_REPORT_PAGE) > 0) { response.Write(HTMLFormatting.getStatusPage()); response.End(); } else { if (log.IsDebugEnabled) { ReflectionUtils.MakePropertyStringArray(httpApplication.Request); log.Debug(request.ContentEncoding.EncodingName); log.Debug(request.ContentEncoding.WebName); log.Debug(request.ContentEncoding.WindowsCodePage); } //Checks The Application Encoding For The Non Utf-8 Requests To Fix The Asp.Net Filtering Bug bool DoUpperCheck = (request.ContentEncoding.WebName == "utf-8" ? false : true); string lasterror = ""; #region Ip Block Processor if (ipblock == null) { ipblock = new ArrayList(); IEnumerator enumerator = blocklist.GetEnumerator(); while (enumerator.MoveNext()) { if (enumerator.Current is IPRule) { ipblock.Add(enumerator.Current); } } enumerator = ipblock.GetEnumerator(); while (enumerator.MoveNext()) { blocklist.Remove(enumerator.Current); } } //Gets The Ip Of The Current Request string ClientIP = httpContext.Request.UserHostAddress; #endregion bool status = false; #region The Form Parameter Processor if (HandleForms == 1 && (httpContext.Request.RequestType.Equals("POST"))) { log.Info("Begin With The Form Handling"); for (int formx = 0; formx < httpContext.Request.Form.Count; formx++) { log.Info("Checking Form Object " + httpContext.Request.Form.GetKey(formx) + "-->" + httpContext.Request.Form[formx]); string formPart = OutputConvertors.ClearHalfFullWidth(httpContext.Request.Form[formx], DoUpperCheck); Rule oldRule = null; if (!CheckValue(formPart, ref lasterror, out oldRule)) { if (oldRule.RuleAction() == (int)Rule.ActionTypes.Warn) { log.Warn("Invalid Objects has been found according to rule " + lasterror); } else if (oldRule.RuleAction() == (int)Rule.ActionTypes.Deny) { log.Error("Invalid Objects has been found according to rule " + lasterror); _errorcount++; httpContext.AddError(new ValidationException("Invalid Objects has been found according to rule " + lasterror)); } else if (oldRule.RuleAction() == (int)Rule.ActionTypes.Allow) { log.Info("Invalid Objects has been found according to rule " + lasterror); //_errorcount++; } } } log.Info("End Of The Form Handling"); } #endregion #region The QueryString Processor if (HandleQueries == 1 && !(status)) { log.Info("Begin With The Querystring Handling"); for (int queryx = 0; queryx < httpContext.Request.QueryString.Count; queryx++) { string queryPart = OutputConvertors.ClearHalfFullWidth(httpContext.Request.QueryString[queryx], DoUpperCheck); Rule oldRule = null; if (!CheckValue(queryPart, ref lasterror, out oldRule)) { if (oldRule.RuleAction() == (int)Rule.ActionTypes.Warn) { log.Warn("Invalid Objects has been found according to rule " + lasterror); } else if (oldRule.RuleAction() == (int)Rule.ActionTypes.Deny) { log.Error("Invalid Objects has been found according to rule " + lasterror); _errorcount++; httpContext.AddError(new ValidationException("Invalid Objects has been found according to rule " + lasterror)); } else if (oldRule.RuleAction() == (int)Rule.ActionTypes.Allow) { log.Info("Invalid Objects has been found according to rule " + lasterror); } } } log.Info("End With The Querystring Handling"); } #endregion #region The Cookie Processor if (HandleCookies == 1 && !(status)) { log.Info("Begin With The Cookie Handling"); IEnumerator enums = httpContext.Request.Cookies.Keys.GetEnumerator(); while (enums.MoveNext()) { string key = (string)enums.Current; HttpCookie cook = httpContext.Request.Cookies[key]; log.Info("The Cookie Object To Be Check :" + cook.Name + "--->" + cook.Value); string cookiePart = OutputConvertors.ClearHalfFullWidth(cook.Value, DoUpperCheck); Rule oldRule = null; if (!CheckValue(cookiePart, ref lasterror, out oldRule)) { if (oldRule.RuleAction() == (int)Rule.ActionTypes.Warn) { log.Warn("Invalid Objects has been found according to rule " + lasterror); } else if (oldRule.RuleAction() == (int)Rule.ActionTypes.Deny) { log.Error("Invalid Objects has been found according to rule " + lasterror); _errorcount++; httpContext.AddError(new ValidationException("Invalid Objects has been found according to rule " + lasterror)); } else if (oldRule.RuleAction() == (int)Rule.ActionTypes.Allow) { log.Info("Invalid Objects has been found according to rule " + lasterror); } } } log.Info("End With The Cookie Handling"); } #endregion if (_errorcount > 0) { httpApplication.Response.AddHeader("X-DefAppInformation", "Invalid Object Has Been Found"); } else { httpApplication.Response.AddHeader("X-DefAppInformation", "Clean Request"); } } }