public void Start()
		{
			Action Stop =
				delegate
				{
					this.Stop = null;
				};

			foreach (var Port in Ports)
			{
				var t = Port.ToThreadedTcpListener(
					s =>
					{
						var hr = new HeaderReader();
						var hr_Method_path = "";

						hr.Method +=
							(method, path) =>
							{
								hr_Method_path = path;
							};

						hr.Header +=
							(key, value) =>
							{
								//Console.WriteLine(key + ": " + value);
							};

						hr.Read(s);

						if (!string.IsNullOrEmpty(hr_Method_path))
						{
							Console.WriteLine(">> " + hr_Method_path);

							this.CommandRequest(s, hr_Method_path);

						}
						s.Close();
					}
				);

				Stop +=
					delegate
					{
						t.IsDisposed = true;
						t.Listener.Server.Close();
						t.Thread.Join();
					};
			}

			this.Stop = Stop;
		}
Beispiel #2
0
        public void Invoke()
        {
            var uri = this.Target;
            var t   = new TcpClient();

            t.Connect(uri.Host, this.Port);

            //var w = new StreamWriter(t.GetStream());

            var w = new StringBuilder();

            w.AppendLine("GET" + " " + uri.PathAndQuery + " HTTP/1.1");
            w.AppendLine("Host: " + uri.Host);
            w.AppendLine("Connection: Close");

            // http://www.botsvsbrowsers.com/
            w.Append(@"User-Agent: jsc
Referer: " + this.Referer + @"
Accept:  */*
Accept-Encoding:  gzip,deflate
Accept-Language:  et-EE,et;q=0.8,en-US;q=0.6,en;q=0.4
Accept-Charset:  windows-1257,utf-8;q=0.7,*;q=0.3
");
            w.AppendLine();

            var data = Encoding.UTF8.GetBytes(w.ToString());

            t.GetStream().Write(data, 0, data.Length);

            if (ContentExpected)
            {
                var hr = new HeaderReader();

                hr.Read(t.GetStream());

                this.Content = hr.Reader.ReadToEnd();
            }

            // it will take up to a minute to show up
            t.Close();
        }
		public void Invoke()
		{
			var uri = this.Target;
			var t = new TcpClient();

			t.Connect(uri.Host, this.Port);

			//var w = new StreamWriter(t.GetStream());

			var w = new StringBuilder();

			w.AppendLine("GET" + " " + uri.PathAndQuery + " HTTP/1.1");
			w.AppendLine("Host: " + uri.Host);
			w.AppendLine("Connection: Close");

			// http://www.botsvsbrowsers.com/
			w.Append(@"User-Agent: jsc
Referer: " + this.Referer + @"
Accept:  */*
Accept-Encoding:  gzip,deflate
Accept-Language:  et-EE,et;q=0.8,en-US;q=0.6,en;q=0.4
Accept-Charset:  windows-1257,utf-8;q=0.7,*;q=0.3
");
			w.AppendLine();

			var data = Encoding.UTF8.GetBytes(w.ToString());

			t.GetStream().Write(data, 0, data.Length);

			if (ContentExpected)
			{
				var hr = new HeaderReader();

				hr.Read(t.GetStream());

				this.Content = hr.Reader.ReadToEnd();
			}

			// it will take up to a minute to show up
			t.Close();
		}
		private void ForkClient(Stream s)
		{
			// http://en.wikipedia.org/wiki/List_of_HTTP_headers

			// somebody connected to us
			// this is a new thread
			var a = new IncomingDataArguments
			{
				Server = this
			};

			var hr = new HeaderReader();

			var LogText = "";

			hr.Method +=
				(method, path) =>
				{
					Console.WriteLine(path);

					a.PathAndQuery = path;
					a.SetLogText = k => LogText = k;

					RaiseIncomingData(this, a);
				};

			hr.Header +=
				(key, value) =>
				{
					//Console.WriteLine(key + ": " + value);
				};

			hr.Read(s);

			var w = new BinaryWriter(s);
			var ww = new StringBuilder();

			// default response

			ww.AppendLine("HTTP/1.0 200 OK");
			ww.AppendLine("Content-Type: " + a);
			ww.AppendLine();

			if (a.Content == null)
			{
				foreach (var k in this.Locals)
				{
					ww.AppendLine("<div>at this location you can talk to <b>" + k.Name + "</b></div>");
				}

				// show remote users?

				ww.AppendLine("<hr />");

				ww.AppendLine("<pre>");

				// escape html entities?
				ww.AppendLine(LogText);

				ww.AppendLine("</pre>");
			}
			else
			{
				ww.Append(a.Content);
			}

			w.Write(Encoding.ASCII.GetBytes(ww.ToString()));


			s.Close();
		}