shmup / miniboa

An asynchronous, single-threaded, poll-based Telnet server
Apache License 2.0
60 stars 12 forks source link

Bug? Problem with telnet embedded command under python3.6 #22

Closed felmur closed 6 years ago

felmur commented 6 years ago

Hi, I have a problem with internal telnetclient commands.

I create a simple script in which I activate a TelnetServer and then, when I connect a terminal, I request the type of terminal connected, using the request_terminal_type () function.

If I run the script with python 2.7, everything works properly.

Under python 3.6, instead, I see spurious characters appear on the terminal with which I am connected and the request for request_terminal_type () is never found.

I tried both xterm terminals and putty terminals, with the same result.

I think I identified the problem in the socket_send () function of the TelnetClient.

In this function, in fact, all that is transmitted to the remote terminal is coded in 'utf-8'.

if PYTHON_2:
     sent = self.sock.send (self.send_buffer)
else:
     # convert to ansi before sending
     sent = self.sock.send (bytes (self.send_buffer, "utf-8"))

This does not seem to be well accepted by the remote terminals, which simply display the special characters corresponding to the command and do not execute them.

Do I miss something?

Greetings

import os
from miniboa import TelnetServer
from time import sleep

server = TelnetServer()
clients = []

def on_connect(client):
    client.request_terminal_type()
    client.send("Hello, my friend. Stay awhile and listen.")
    clients.append(client)

def on_disconnect(client):
    clients.remove(client)

def check_client():
    for client in clients:
        if client.active:
            print(client.terminal_type)

server = TelnetServer(
    port=3333,
    address='',
    on_connect=on_connect,
    on_disconnect=on_disconnect)

while True:
    server.poll()
    check_client()
shmup commented 6 years ago

Ah dang @felmur well I'm curious if you could try something for me.

Something I changed recently, as per another issue, is going from cp1252 to utf-8 and.. well maybe you exposed a problem with that.

https://github.com/shmup/miniboa/commit/09e90ff39d6c11b8166ab2599097a68897ca1d4a

Would you be willing to try reverting those relevant lines back to cp1252 (where it says utf-8), in telnet.py and seeing if the problem is fixed? If so, I'm going to revert back to cp1252 encoding and think more on the other issue that was opened.

shmup commented 6 years ago

@felmur I tested your code block myself, see that I did introduce the problem by using utf-8, and so I went back to cp1252 encoding. Should be fine now; I pushed the new change up to pypi if you had previously installed miniboa via pip.

felmur commented 6 years ago

Thanks, telnet command works now.