Beispiel #1
0
        static void HandleZipFile(string pth, BinaryWriter resp)
        {
            var targetDir = TempFileUtil.CreateTempDir();

            Console.WriteLine($"Unzip {pth} to {targetDir}");

            try
            {
                ZipFile.ExtractToDirectory(pth, targetDir);
            } catch (InvalidDataException ex) {
                resp.Write($"EE: invalid zip file: {ex.Message}");
                return;
            }
            var autoexec = Path.Combine(targetDir, "autoexec.cmd");

            if (!File.Exists(autoexec))
            {
                resp.Write("EE: Missing autoexec.cmd from zip");
                return;
            }

            RunProcessAndWriteExitCode(resp, psi =>
            {
                psi.WorkingDirectory = targetDir;
                psi.FileName         = "cmd";
                psi.Arguments        = "/c autoexec.cmd";
            });
        }
Beispiel #2
0
        static void HandleSocket(Socket sock)
        {
            var networkStream = new BufferedStream(new NetworkStream(sock));
            var writer        = new BinaryWriter(networkStream);
            var reader        = new BinaryReader(networkStream);

            var pth = TempFileUtil.GetTempFileName();

            void copyBulkStreamToNewFile(string fname)
            {
                using (var f = new BinaryWriter(File.OpenWrite(pth)))
                {
                    RespProtocol.ReadBulkString(reader, f);
                }
            }

            while (true)
            {
                // main command - handle loop
                var cmd      = RespProtocol.ReadSimpleString(reader);
                var cmdParts = cmd.Split(new char[] { ' ' }, 2);
                Console.WriteLine($"Command: {cmd}");
                // 1: run simple script
                if (cmd == "run")
                {
                    copyBulkStreamToNewFile(pth);
                    HandleStoredFile(pth, writer);
                    writer.Close();
                    break;
                }
                if (cmd == "ziprun")
                {
                    copyBulkStreamToNewFile(pth);
                    HandleZipFile(pth, writer);
                    writer.Close();
                    break;
                }
                if (cmdParts[0] == "save")
                {
                    copyBulkStreamToNewFile(cmdParts[1]);
                    writer.Close();
                    break;
                }

                if (cmdParts[0] == "get")
                {
                    HandleGet(cmdParts[1], writer);
                    writer.Close();
                    break;
                }

                Console.WriteLine($"Unknown command: {cmd}");
            }
        }