Example #1
0
        public override void handleGETRequest(HttpProcessor p)
        {
            if (p.http_url == "/")
            {
                p.http_url = "/index.html";
            }
            Console.WriteLine("request: {0}", p.http_url);
            Console.WriteLine(Directory.GetCurrentDirectory());
            int        nBytes = 2048;
            FileStream fs;

            try
            {
                if (p.http_url.Split('/')[1] == "Files")
                {
                    fs = new FileStream(Directory.GetCurrentDirectory() + p.http_url, FileMode.Open, FileAccess.Read);
                    p.writeSuccessRar("", fs.Length, @"application/x-rar-compressed, application/octet-stream");
                    while (true)
                    {
                        byte[] ByteArray  = new byte[nBytes];
                        int    nBytesRead = fs.Read(ByteArray, 0, nBytes);
                        if (nBytesRead == 0)
                        {
                            break;
                        }
                        p.outputStream.BaseStream.Write(ByteArray, 0, ByteArray.Length);
                    }

                    fs.Close();
                }
                else
                {
                    p.writeSuccess();
                    p.outputStream.Write(@"<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.0 Transitional//EN'>
<html><meta charset='utf-8'><head><title></title></head>
");
                    if (!p.isAuth())
                    {
                        p.printAuth();
                        return;
                    }
                    p.outputStream.Write(@"<body>");
                    PrintTable(p);
                }
            }
            catch (Exception ex)
            {
                p.outputStream.WriteLine("404 - файл " + p.http_url + " не найден.<br>" + ex.Message);
                Console.WriteLine("404 - файл " + p.http_url + " не найден.<br>" + ex.Message);
            }
        }
Example #2
0
        public override void handlePOSTRequest(HttpProcessor p, StreamReader inputData)
        {
            Console.WriteLine("POST request: {0}", p.http_url);
            string data = inputData.ReadToEnd();

            if (!p.isAuth())
            {
                if (!p.setAuth(data))
                {
                    p.outputStream.Write(@"<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.0 Transitional//EN'>
<html><meta charset='utf-8'><head><title></title>
<h3>Неправильные данные</h3>");
                    p.printAuth();
                }
                else
                {
                    p.outputStream.Write(@"<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.0 Transitional//EN'>
<html><meta charset='utf-8'><head><title></title>");
                }
                if (!p.isAuth())
                {
                    return;
                }
            }
            else
            {
                p.outputStream.Write(@"<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.0 Transitional//EN'>
<html><meta charset='utf-8'><head>title></title>");
            }
            string proc_id = data.Split('&')[0];

            proc_id = proc_id.Split('=')[1];
            switch (proc_id)
            {
            case "1START":
                try
                {
                    if (process_1 == null)
                    {
                        process_1 = new Process();
                        process_1.StartInfo.FileName         = Directory.GetCurrentDirectory() + @"\Programms\One\Volovich_1_lab_server.exe";
                        process_1.StartInfo.WorkingDirectory = Directory.GetCurrentDirectory() + @"\Programms\One";
                        process_1.Start();
                        p.outputStream.WriteLine("<script>alert('Сервер №1 запущен');</script>");
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    p.outputStream.WriteLine("exception: {0}", ex.Message);
                }
                break;

            case "1END":
                process_1.Kill();
                process_1 = null;
                break;

            case "2START":
                try
                {
                    if (process_2 == null)
                    {
                        process_2 = new Process();
                        process_2.StartInfo.FileName         = Directory.GetCurrentDirectory() + @"\Programms\Two\ServerBox.exe";
                        process_2.StartInfo.WorkingDirectory = Directory.GetCurrentDirectory() + @"\Programms\Three";
                        process_2.Start();
                        p.outputStream.WriteLine("<script> alert('Сервер №2 запущен'); </script>");
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    p.outputStream.WriteLine("exception: {0}", ex.Message);
                }
                break;

            case "2END":
                process_2.Kill();
                process_2 = null;
                break;

            case "3START":
                try
                {
                    if (process_3 == null)
                    {
                        process_3 = new Process();
                        process_3.StartInfo.FileName         = Directory.GetCurrentDirectory() + @"\Programms\Three\MathServer.exe";
                        process_3.StartInfo.WorkingDirectory = Directory.GetCurrentDirectory() + @"\Programms\Three";
                        process_3.Start();
                        p.outputStream.WriteLine("<script> alert('Сервер №3 запущен'); </script>");
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    p.outputStream.WriteLine("exception: {0}", ex.Message);
                }
                break;

            case "3END":
                process_3.Kill();
                process_3 = null;
                break;


            case "4START":
                try
                {
                    if (process_4 == null)
                    {
                        process_4 = new Process();
                        process_4.StartInfo.FileName         = Directory.GetCurrentDirectory() + @"\Programms\Four\SponsorServer.exe";
                        process_4.StartInfo.WorkingDirectory = Directory.GetCurrentDirectory() + @"\Programms\Four";
                        process_4.Start();
                        p.outputStream.WriteLine("<script> alert('Сервер №4 запущен'); </script>");
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    p.outputStream.WriteLine("exception: {0}", ex.Message);
                }
                break;

            case "4END":
                process_4.Kill();
                process_4 = null;
                break;

            default:
                break;
            }
            p.outputStream.Write(@"</head><body>");
            PrintTable(p);
            p.outputStream.Write(@"</body></html>");
        }