Ejemplo n.º 1
0
            /// <inheritdoc/>
            public ServerResponseType HandleMessage(Backend backend, ServerMessageType message, string session, BinaryReader datareader, BinaryWriter datawriter)
            {
                PseudoTerminal _master = null;
                PseudoTerminal _slave  = null;

                var options = new TerminalOptions();

                options.LFlag = PtyConstants.ICANON;
                options.C_cc[PtyConstants.VERASE] = (byte)'\b';
                options.C_cc[PtyConstants.VEOL]   = (byte)'\r';
                options.C_cc[PtyConstants.VEOL2]  = (byte)'\n';

                PseudoTerminal.CreatePair(out _master, out _slave, options);



                int slaveRemoteId = _remoteStreams.Create(_slave, session);


                var stdout = new StreamWriter(new BroadcastingStream(backend, session));

                stdout.AutoFlush = true;
                var stdin = new StreamReader(_master);

                string commandname = datareader.ReadString();
                int    argCount    = datareader.ReadInt32();

                string[] argv = new string[argCount];
                for (int i = 0; i < argCount; i++)
                {
                    argv[i] = datareader.ReadString();
                }

                var trmmgr = backend.GetBackendComponent <TerminalManager>();

                Task.Run(() =>
                {
                    try
                    {
                        trmmgr.RunCommand(backend, commandname, argv, session, stdin, stdout);
                    }
                    catch (TerminationRequestException)
                    {
                        Logger.Log("Terminated command.");
                    }
                    finally
                    {
                        stdout.Write((char)0x02);
                    }
                });
                datawriter.Write(slaveRemoteId);

                return(ServerResponseType.REQ_SUCCESS);
            }
Ejemplo n.º 2
0
        /// <inheritdoc/>
        public ServerResponseType HandleMessage(Backend backend, ServerMessageType message, string session, BinaryReader datareader, BinaryWriter datawriter)
        {
            var trmmgr = backend.GetBackendComponent <TerminalManager>();
            var cmds   = trmmgr.GetCommandList().ToArray();

            datawriter.Write(cmds.Length);
            foreach (var cmd in cmds)
            {
                datawriter.Write(cmd.Key);
                datawriter.Write(cmd.Value);
            }
            return(ServerResponseType.REQ_SUCCESS);
        }
Ejemplo n.º 3
0
        /// <inheritdoc/>
        public ServerResponseType HandleMessage(Backend backend, ServerMessageType message, string session, BinaryReader datareader, BinaryWriter datawriter)
        {
            var    termmgr = backend.GetBackendComponent <TerminalManager>();
            string cmd     = datareader.ReadString();
            string manpage = termmgr.GetManpage(cmd);

            if (manpage != null)
            {
                datawriter.Write(manpage);
            }
            else
            {
                datawriter.Write("No manpage found for this command.");
            }
            return(ServerResponseType.REQ_SUCCESS);
        }