示例#1
0
文件: MaxAmp2.cs 项目: maximkha/mcs
            private void HandlePost(StateObj State, string S, string location)
            {
                string URL = ProcessUrl(location).Replace(" ", String.Empty);
                Dictionary <string, string> PostParams = new Dictionary <string, string>();
                string Location = S.Substring(5, S.IndexOf(' ', S.IndexOf(' ') + 1) - 4);

                Console.WriteLine("Post");

                string Str = S.Substring(5);

                Console.WriteLine("Trimmed!");
                string[] Lines = Str.Split('\n');

                int i;

                for (i = 0; i < Lines.Length; i++)
                {
                    if (string.IsNullOrWhiteSpace(Lines[i]))
                    //if (lines[i].Length == 0)          //or maybe this suits better..
                    //if (lines[i].Equals(string.Empty)) //or this
                    {
                        //Console.WriteLine(i);
                        break;
                    }
                    //Console.WriteLine(i);
                }


                if (i != Lines.Length - 1)
                {
                    //Next Line should be the one with post data
                    Console.WriteLine(Lines[i + 1]);
                    Console.WriteLine("-----------");
                    string[] PostParameters = Lines[i + 1].Replace("+", " ").Split('&');

                    foreach (string PostParameter in PostParameters)
                    {
                        string[] KeyAndValue = PostParameter.Split('=');
                        PostParams.Add(KeyAndValue[0], KeyAndValue[1]);
                    }

                    foreach (KeyValuePair <string, string> kvp in PostParams)
                    {
                        Console.WriteLine("Key = {0}, Value = {1}", kvp.Key, kvp.Value);
                    }
                    //Console.WriteLine(generateJSON(PostParams));
                    Console.WriteLine("URL:" + URL + " " + Virtdirs.ContainsKey(URL));
                    if (Virtdirs.ContainsKey(URL))
                    {
                        //returnText(State, CallVirtDir(ProcessUrl(cr.RawUrl), Hreq), "text/html");
                        PrevReq Hreq = new PrevReq(URL, State.Client.RemoteEndPoint.ToString(), State.S.ToString(), "POST", PostParams);
                        string  text = CallVirtDir(URL, Hreq);
                        SendText(State, GenerateHeader("HTTP/1.1 200 OK", "text/html", Encoding.ASCII.GetByteCount(text)) + text);
                    }
                }
            }
示例#2
0
文件: MaxAmp2.cs 项目: maximkha/mcs
            private String CallVirtDir(string Name, PrevReq Hreq)
            {
                Func <PrevReq, string> Callback = Virtdirs[Name];

                return(Callback.Invoke(Hreq));
            }
示例#3
0
文件: MaxAmp2.cs 项目: maximkha/mcs
            private void HandleFileReq(StateObj State, String Locs)
            {
                try
                {
                    string URL = ProcessUrl(Locs);
                    //var fullPath = Path.Combine(RootPath, URL); //string.IsNullOrEmpty(URL) ? rootpath : Path.Combine(rootpath, URL);
                    //if (fullPath == "/") fullPath = RootPath;
                    var fullPath = RootPath + URL;
                    Console.WriteLine("FP: " + fullPath);
                    Console.WriteLine("URL:" + URL);

                    bool innf = true;

                    //Index files
                    foreach (string file in indexfiles)
                    {
                        string fn = Path.Combine(fullPath, file);
                        if (File.Exists(fn))
                        {
                            GetFileContents(State, fn);
                            innf = false;
                        }
                    }

                    Console.WriteLine("URL:" + URL + " " + Virtdirs.ContainsKey(URL));
                    if (Virtdirs.ContainsKey(URL))
                    {
                        //returnText(State, CallVirtDir(ProcessUrl(cr.RawUrl), Hreq), "text/html");
                        PrevReq Hreq = new PrevReq(URL, State.Client.RemoteEndPoint.ToString(), State.S.ToString(), "GET");
                        string  text = CallVirtDir(URL, Hreq);
                        SendText(State, GenerateHeader("HTTP/1.1 200 OK", "text/html", Encoding.ASCII.GetByteCount(text)) + text);
                        innf = false;
                    }


                    //Directories and files
                    if (innf)
                    {
                        Console.WriteLine(File.Exists(fullPath));
                        //files
                        if (File.Exists(fullPath))
                        {
                            GetFileContents(State, fullPath);
                        }
                        //dir listing
                        else if (Directory.Exists(fullPath))
                        {
                            //returnText(State, (GetDir(fullPath, State)), "text/html");
                            string R;
                            string M = GetDir(State, fullPath);
                            R = GenerateHeader("HTTP/1.1 200 OK", "text/html", Encoding.ASCII.GetByteCount(M)) + M;
                            SendText(State, R);
                        }
                        else
                        {
                            SendText(State, GenError(404));                          //404 nothing
                        }
                    }
                }
                catch (Exception E)
                {
                    ErrorArg ErA;
                    ErA.Location    = "MAS2.HandleFileReq(StateObj State, String Locs)";
                    ErA.Severity    = 3;                 //Lower Severity more important
                    ErA.TimeAndDate = DateTime.Now.ToString("MMMM,dd,yyyy h:mm:ss tt", CultureInfo.InvariantCulture);
                    ErA.Error       = E.ToString();
                    HandleError(ErA, "HFR");
                }
            }