Example #1
0
        private static void AppServer_NewRequestReceived(TelnetSession session, SuperSocket.SocketBase.Protocol.StringRequestInfo requestInfo)
        {
            switch (requestInfo.Key.ToUpper())
            {
            case ("ECHO"):
                session.Send(requestInfo.Body);
                break;

            case ("ADD"):
                session.Send(requestInfo.Parameters.Select(p => Convert.ToInt32(p)).Sum().ToString());
                break;

            case ("MULT"):

                var result = 1;

                foreach (var factor in requestInfo.Parameters.Select(p => Convert.ToInt32(p)))
                {
                    result *= factor;
                }

                session.Send(result.ToString());
                break;
            }
        }
Example #2
0
        protected void ConfigureTelnetContainer()
        {
            Container = TelnetSession.TelnetContainer(
                UnityConfigurator.Configure());

            MockConnection = new Mock <TelnetConnection>(null, null);
            Container.RegisterInstance(MockConnection.Object);
        }
 public void SetTelnetSession(TelnetSession session)
 {
     this.session = session;
     if (session.SessionType == "TL1")
         CommandEndByte = ";";
     else
         CommandEndByte = "\r";
 }
Example #4
0
        //callback from the tcp listner, rcvs the local connection request from mega
        void m_listener_NewClientConnectEvent(System.Net.Sockets.TcpClient newClient)
        {
            Debug.WriteLine("ENTER m_listener_NewClientConnectEvent");
            //the connection to/from mega
            ITelnetSessionControl newSession = new TelnetSession(newClient);

            //wrapper to hold loval and remote connections
            //ITelnetProxySessionControl newProxySession = new TelnetProxySession(newSession);
            //prompt mega for remote connection info
            ThreadPool.QueueUserWorkItem(cb_OnStartNewTelnetProxySession, newSession);
        }
        public TermianlLayoutDocument(TelnetSession session,bool isopen, bool LogFileEnable)
        {
            TerminalBoxObj = new TerminalBox(session, LogFileEnable);
            this.Content = TerminalBoxObj;
            Title = session.SessionName;
            ToolTip = session.ServerIP + ":" + session.ServerPort;
            IconSource = new BitmapImage(new Uri(@"\Resources\Images\ServerSession\DisSessionIcon.png",UriKind.RelativeOrAbsolute));

            if (isopen)
                MainWindow.GetMainWindow().AddServerSession(this);

            IsOpen = isopen;
        }
Example #6
0
        //public TerminalRichTextEditor TerminalRichTextEditorObj { get; set; }
        public Terminal(TelnetSession Session)
            : base()
        {
            // it should not be less than 10000

            this.Session = Session;
            InitializeComponent();
            ConsoleTextBox.Caret = this.Caret;
            consolebuffer = new BufferString();
            logfile = new LogFile(this);
            ConsoleTextBox.TextInput += ConsoleTextBox_TextInput;
            //ConsoleTextBox.KeyDownEvent += ConsoleTextBox_KeyDown;
            ConsoleTextBox.AddHandler(KeyDownEvent, new RoutedEventHandler(ConsoleTextBox_KeyDown), true);
            ConsoleTextBox.AddHandler(KeyUpEvent, new RoutedEventHandler(ConsoleTextBox_KeyUp), true);
        }
 public TerminalBox(TelnetSession session,bool LogFileEnable)
 {
     Session = session;
     autoreconnecttime = 500;
     InitializeComponent();
     RichTextBox.SetTelnetSession(session);
     RichTextBox.WriteInStream += Write;
     RichTextBox.WriteStream += WriteAsync;
     //RichTextBox.UpdateCaret += UpdateCaret;
     SetupTextBox();
     this.LogFileEnable = LogFileEnable;
     if(LogFileEnable)
     logfile = new LogFile(session);
     ShowNoConnectionBanner();
 }
Example #8
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();
            }
        }
        //private static int AttachListenerToSession(int id, ITelnetProxySessionControl newSession, ITelnetProxySessionControl existingSession)
        //{
        //    int result = -1;

        //    if (!existingSession.AttachListener(ETelnetProxySession.Remote, newSession))
        //    {
        //        Debug.WriteLine("Failed to attach listner to Session " + result, DBG_CAT);
        //    }

        //    if (!newSession.AttachListener(ETelnetProxySession.Client, existingSession))
        //    {
        //        Debug.WriteLine("Failed to attach writer to Session " + result, DBG_CAT);
        //    }

        //    return 1;
        //}

        private int CreateNewSessionScript(ITelnetProxySessionControl newProxySession)
        {
            Match m = BlockUntilAnswered(newProxySession, ETelnetProxySession.Client, "CON?", csvRegex_new, 5, 5);

            if (m == null && !m.Success)
            {
                return(BAD_ID_REGEX);
            }

            string ip   = m.Groups[1].Value;
            int    port = -1;

            if (!int.TryParse(m.Groups[2].Value, out port))
            {
                return(ID_BAD_PORT_CAST_TO_INT);
            }

            try
            {
                System.Net.IPHostEntry entry = System.Net.Dns.GetHostEntry(ip);
                if (entry.AddressList.Length == 0)
                {
                    Debug.WriteLine("Failed to resolve: " + ip, "StartScript");
                    return(BAD_ID);
                }
                ip = entry.AddressList[0].ToString();
            }
            catch (Exception)
            {
                Debug.WriteLine("Failed to parse ip or port from: " + ip + " " + port, "StartScript");
                return(BAD_ID);
            }

            ITelnetSessionControl remoteSession = new TelnetSession(ip, port);

            remoteSession.Name = "Remote";
            if (!remoteSession.Connect())
            {
                Debug.WriteLine("Failed to connected to Remote Server");
                return(BAD_REMOTE_CONNECTION);
            }

            newProxySession.AddSession(ETelnetProxySession.Remote, remoteSession);
            remoteSession.BeginRead();
            return(1);
        }
Example #10
0
        private void OnNewConnection(IAsyncResult asyncResult)
        {
            System.Net.Sockets.Socket client = _listenerSocket.EndAccept(asyncResult);
            client.NoDelay = true;

            _listenerSocket.BeginAccept(OnNewConnection, this);

            switch (_sessionType)
            {
            case EnumSessionType.Telnet:
            {
                _logger.Info($"Accepting incoming Telnet connection from {client.RemoteEndPoint}...");
                var telnetSession = new TelnetSession(client);
                break;
            }

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

                _logger.Info($"Accepting incoming Rlogin connection from {client.RemoteEndPoint}...");
                var rloginSession = new RloginSession(client, _moduleIdentifier);
                break;
            }

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Example #11
0
 static void telnetServer_NewSessionConnected(TelnetSession session)
 {
     Console.WriteLine("{0}: Session {1} is opened.", session.AppServer.Name, session.SessionID);
 }
Example #12
0
 static void telnetServer_SessionClosed(TelnetSession session, CloseReason reason)
 {
     Console.WriteLine("{0}: Session {1} is closed.", session.AppServer.Name, session.SessionID);
 }
Example #13
0
 private static void AppServer_NewSessionConnected(TelnetSession session)
 {
     session.Send("Welcome to SuperSocket Telnet Server");
 }
Example #14
0
 private static void AppServer_SessionClosed(TelnetSession session, CloseReason value)
 {
     Console.WriteLine(string.Format("{0}断开连接", session.SessionID));
     session.Send(value.ToString());
 }
Example #15
0
 private static void TelnetServer_NewSessionConnected(TelnetSession session)
 {
     Console.WriteLine("使用的session类型:{0},\nsession的id:{1},\n使用的server类型:{2}",
                       session, session.Id, session.Server);
 }