Beispiel #1
0
        private void listener_BeginRead(object sender, TCPEventArgs e)
        {
            try
            {
                TCPClient client = ((TCPListener)sender).TCPClients[e.SocketID];

                string data         = GetData(e.Data);
                string commandValue = string.Empty;

                //Check for quit
                if (data.ToUpper() == "QUIT")
                {
                    Console.WriteLine("Goodbye");
                    client.DisconnectSocket();
                    return;
                }

                //Process the command
                if (!client.Authenticated)
                {
                    client.LoginAttempt++;

                    string[] vals = data.Split(' ');
                    if (vals == null || vals.Length < 2)
                    {
                        client.WriteLine("Send <USER> <PASS> for authentication");
                    }
                    else
                    {
                        Account acc = Konsole.Commands.HelperTools.GetAccByName(vals[0]);

                        if (acc != null && acc.Password.ToUpper() == vals[1].ToUpper())
                        {
                            if (acc.AccessLevel >= TelnetConfig.MinimumAccessLevel)
                            {
                                client.Authenticated = true;
                                client.Account       = acc;
                                client.WriteLine(string.Concat("Welcome ", acc.Username, ", you have been authenticated"));
                                Console.WriteLine("Telnet client authenticated: {0}", acc.Username);
                            }
                            else
                            {
                                client.WriteLine("Your access level is too low to use the telnet interface");
                                Console.WriteLine("Inadequite accesslevel on slot: {0} Account: {1} IP:{2}", e.SocketID, acc.Username, e.Endpoint.ToString());
                                client.DisconnectSocket();
                                return;
                            }
                        }
                        else
                        {
                            if (client.LoginAttempt == 3)
                            {
                                client.WriteLine("Login attempts exceeded. 3 strikes, you're out!");
                                client.DisconnectSocket();
                                Console.WriteLine("Telnet authentication attempts exceeded on IP: {0}", e.Endpoint.ToString());
                                return;
                            }
                            else
                            {
                                client.WriteLine("Bad credentials, try again\r\nSend <USER> <PASS> for authentication");
                            }
                        }
                    }
                }
                else
                {
                    KonsoleCommands.ProcessKonsoleInput(data);
                    Console.WriteLine("[WowwoW <? for help>]");
                }
            }
            catch (Exception ex)
            {
                SocketHelper.ShowError(this, ex);
            }
        }