public static void ParseAndProcess(WebKit webKit, HttpListenerContext context, string[] args, string user, string ipAddress) { try { if (args != null && args.Length > 0) { //paremeters.Clear(); string id = args.ElementAt(0).Trim(); if (id != null && id.Length > 0) { RemoveFirst(ref args); for (var i = 0; i < args.Length; i++) { var arg = args[i].ToString(); if (arg.Length > 0) { if (arg.Contains('=')) arg = arg.Remove(0, arg.IndexOf('=') + 1).Trim(); if (arg.Length > 0) args[i] = arg; } } var arguments = new Args() { Arguments = args, AuthName = user, IpAddress = ipAddress, WebKit = webKit }; //InsertAtFirst( //Data.Insert(0, IPAddress); //foreach (string param in Data) //{ // string parameter = param.Trim(); // if (parameter.Length > 0) // { // if (parameter.Contains('=')) // { // parameter = parameter.Remove(0, parameter.IndexOf('=') + 1); // } // paremeters.Add(parameter); // } //} //paremeters.Insert(0, WebKit); //var args = new Args() //{ // WebKit = WebKit, // Sender = new Utility.WebSender( //}; var serialized = ProcessPacket(id, arguments); context.WriteString(String.Empty, serialized); } } } catch (ExitException) { throw; } catch (HttpListenerException) { } catch (ArgumentException) { } catch (Exception e) { ProgramLog.Log(e); } }
public static bool CheckAuthenticity(HttpListenerContext context, WebKit webkit, string httpData, string ipAddress) { var identity = context.User.Identity; int slot; if (NeedsKick(ipAddress, identity.Name, webkit, out slot)) { RemoveKickedUser(ipAddress, identity.Name, webkit, slot); var res = new Dictionary<String, Object>(); res["main-interval-rm"] = "http://tdsm.org"; var serialized = Json.Serialize(webkit.WebServer, res); context.WriteString(serialized); WebKit.Log("{0} disconnected from {1}", identity.Name, ipAddress ?? "HTTP"); return false; } switch (identity.AuthenticationType) { case "Basic": var basicIdentity = (identity as HttpListenerBasicIdentity).ToTDSMIdentity(webkit); lock (webkit.WebSessions) { if (basicIdentity.AuthStatus != AuthStatus.MATCH) { context.Disconnect("Credentials incorrect."); WebKit.Log("{0} disconnected from {1}", basicIdentity.Name, ipAddress ?? "HTTP"); return false; } else { Identity ident; if (!webkit.WebSessions.ContainsKey(basicIdentity.Name)) WebKit.Log("{0} logged in from {1}", basicIdentity.Name, ipAddress ?? "HTTP"); else if (webkit.WebSessions.TryGetValue(basicIdentity.Name, out ident)) { if ((DateTime.Now - ident.LastUpdate).TotalMilliseconds > (webkit.MainUpdateInterval * 2)) WebKit.Log("{0} logged in from {1}", basicIdentity.Name, ipAddress ?? "HTTP"); } } if (webkit.WebSessions.ContainsKey(basicIdentity.Name)) { var newIdent = webkit.WebSessions[basicIdentity.Name]; newIdent.IpAddress = ipAddress; newIdent.LastUpdate = DateTime.Now; webkit.WebSessions[basicIdentity.Name] = newIdent; } else webkit.WebSessions[basicIdentity.Name] = new Identity() { IpAddress = ipAddress, LastUpdate = DateTime.Now }; } return true; //case "NTLM": // var identity = iIdentity as WindowsIdentity; // var ident1 = iIdentity as System.Security.Principal.WindowsPrincipal; // var ident2 = iIdentity as System.Security.Principal.GenericPrincipal; // var ident3 = iIdentity as System.Security.Principal.GenericIdentity; // break; default: context.Disconnect("Unauthorised access."); WebKit.Log("Connection is unsupported from {0}@{1}", identity.Name, ipAddress ?? "HTTP"); return false; } }