From 74355e522053b9f84eb79413ca34a4d400a7f98a Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Fri, 25 Apr 2025 18:41:01 -0400 Subject: [PATCH] Implement partial telnet for VMWare The vmware serial support demands more proper telnet support, provide some support for negotiating do/don't, will/won't opcodes. --- .../plugins/hardwaremanagement/vcenter.py | 31 +++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/confluent_server/confluent/plugins/hardwaremanagement/vcenter.py b/confluent_server/confluent/plugins/hardwaremanagement/vcenter.py index 8dc6aa60..1f95f5f2 100644 --- a/confluent_server/confluent/plugins/hardwaremanagement/vcenter.py +++ b/confluent_server/confluent/plugins/hardwaremanagement/vcenter.py @@ -38,6 +38,7 @@ class VmConsole(conapi.Console): self.socket.sendall(data) def close(self): + self.connected = False if self.socket: self.socket.close() @@ -46,12 +47,38 @@ class VmConsole(conapi.Console): try: pendingdata = self.socket.recv(1024) except Exception as e: - print(repr(e)) pendingdata = '' if pendingdata == '': + self.connected = False self.datacallback(conapi.ConsoleEvent.Disconnect) return - self.datacallback(pendingdata) + reply = b'' + while pendingdata and pendingdata[0] == 255: + cmd = pendingdata[1] + if cmd == 255: + pendingdata = pendingdata[1:] + break + subcmd = pendingdata[2] + if cmd == 253: # DO + # binary, suppress go ohaed + if subcmd in (0, 3): + reply += b'\xff\xfb' + bytes([subcmd]) # will + else: + reply += b'\xff\xfc' + bytes([subcmd]) # won't do anything else + pendingdata = pendingdata[3:] + elif cmd == 251: # will + # binary, suppress go ahead, echo + if subcmd in (0, 1, 3): + reply += b'\xff\xfd' + bytes([subcmd]) # do the implemented things + else: + reply += B'\xff\xfe' + bytes([subcmd]) # don't do others' + pendingdata = pendingdata[3:] + else: + raise Exception(repr(pendingdata[:3])) + if reply: + self.write(reply) + if pendingdata: + self.datacallback(pendingdata)