示例#1
0
        public LocalConsoleSession(ILogger logger, string sessionId, IMbbsHost host) : base(sessionId)
        {
            _logger            = logger;
            _host              = host;
            SendToClientMethod = dataToSend => UnicodeANSIOutput(dataToSend);

            //Timer to trigger btuche() if enabled
            _timer = new Timer(_ =>
            {
                if (EchoEmptyInvokeEnabled && DataToClient.Count == 0)
                {
                    EchoEmptyInvoke = true;
                }
            }, this, TimeSpan.FromMilliseconds(500), TimeSpan.FromMilliseconds(500));

            Console.Clear();

            Console.OutputEncoding = Encoding.Unicode;

            //Detect if we're on Windows and enable VT100 on the current Terminal Window
            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                new Win32VT100().Enable();
            }

            SessionState = EnumSessionState.Unauthenticated;

            (_logger as CustomLogger)?.DisableConsoleLogging();

            _consoleInputThreadIsRunning = true;
            _consoleInputThread          = new Thread(InputThread);
            _consoleInputThread.Start();
            _host.AddSession(this);
        }
示例#2
0
        public LocalConsoleSession(ILogger logger, string sessionId, IMbbsHost host) : base(sessionId)
        {
            _logger            = logger;
            _host              = host;
            SendToClientMethod = dataToSend => UnicodeANSIOutput(dataToSend);

            //Timer to trigger btuche() if enabled
            _timer = new Timer(_ =>
            {
                if (EchoEmptyInvokeEnabled && DataToClient.Count == 0)
                {
                    EchoEmptyInvoke = true;
                }
            }, this, TimeSpan.FromMilliseconds(500), TimeSpan.FromMilliseconds(500));

            Console.Clear();
            Console.OutputEncoding = Encoding.Unicode;
            SessionState           = EnumSessionState.Unauthenticated;

            (_logger as CustomLogger)?.DisableConsoleLogging();

            _consoleInputThreadIsRunning = true;
            _consoleInputThread          = new Thread(InputThread);
            _consoleInputThread.Start();
            _host.AddSession(this);
        }
示例#3
0
        public TelnetSession(Socket telnetConnection) : base(telnetConnection.RemoteEndPoint.ToString())
        {
            SessionType        = EnumSessionType.Telnet;
            SendToClientMethod = Send;
            _host   = ServiceResolver.GetService <IMbbsHost>();
            _logger = ServiceResolver.GetService <ILogger>();

            _telnetConnection = telnetConnection;
            _telnetConnection.ReceiveTimeout    = (1000 * 60) * 5; //5 Minutes
            _telnetConnection.ReceiveBufferSize = socketReceiveBuffer.Length;
            _telnetConnection.Blocking          = false;

            SessionState = EnumSessionState.Negotiating;

            _senderThread = new Thread(SendWorker);
            _senderThread.Start();

            //Add this Session to the Host
            _host.AddSession(this);

            Send(ANSI_ERASE_DISPLAY);
            Send(ANSI_RESET_CURSOR);

            SessionState = EnumSessionState.Unauthenticated;

            ListenForData();
        }
示例#4
0
        private void OnNewConnection(IAsyncResult asyncResult)
        {
            System.Net.Sockets.Socket client;
            try
            {
                client = _listenerSocket.EndAccept(asyncResult);
            } catch (ObjectDisposedException) {
                // ignore, happens during shutdown
                return;
            }

            client.NoDelay = true;

            _listenerSocket.BeginAccept(OnNewConnection, this);

            switch (_sessionType)
            {
            case EnumSessionType.Telnet:
            {
                _logger.Info($"Accepting incoming Telnet connection from {client.RemoteEndPoint}...");
                var session = new TelnetSession(_host, _logger, client, _configuration, _textVariableService);
                _host.AddSession(session);
                session.Start();
                break;
            }

            case EnumSessionType.Rlogin:
            {
                if (((IPEndPoint)client.RemoteEndPoint).Address.ToString() != _configuration.RloginRemoteIP)
                {
                    _logger.Info(
                        $"Rejecting incoming Rlogin connection from unauthorized Remote Host: {client.RemoteEndPoint}");
                    client.Close();
                    return;
                }

                _logger.Info($"Accepting incoming Rlogin connection from {client.RemoteEndPoint}...");
                var session = new RloginSession(_host, _logger, client, _channelDictionary, _configuration, _textVariableService, _moduleIdentifier);
                _host.AddSession(session);
                session.Start();
                break;
            }

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
示例#5
0
        public RloginSession(Socket rloginConnection, string moduleIdentifier = null) : base(rloginConnection.RemoteEndPoint.ToString())
        {
            ModuleIdentifier   = moduleIdentifier;
            SessionType        = EnumSessionType.Rlogin;
            SendToClientMethod = Send;
            _host             = ServiceResolver.GetService <IMbbsHost>();
            _logger           = ServiceResolver.GetService <ILogger>();
            _rloginConnection = rloginConnection;
            _rloginConnection.ReceiveTimeout    = (1000 * 60) * 5;
            _rloginConnection.ReceiveBufferSize = 128;
            SessionState = EnumSessionState.Negotiating;

            //Start Listeners & Senders
            _sendThread = new Thread(SendWorker);
            _sendThread.Start();
            _receiveThread = new Thread(ReceiveWorker);
            _receiveThread.Start();

            //Add this Session to the Host
            _host.AddSession(this);
        }