From 2945454bf8d07998bd1a230d448b1add3fdd16c4 Mon Sep 17 00:00:00 2001 From: Griatch Date: Wed, 20 Aug 2014 10:25:24 +0200 Subject: [PATCH] Forgot to add the naws.py file. :) --- src/server/portal/naws.py | 61 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 src/server/portal/naws.py diff --git a/src/server/portal/naws.py b/src/server/portal/naws.py new file mode 100644 index 0000000000..e148ccaa20 --- /dev/null +++ b/src/server/portal/naws.py @@ -0,0 +1,61 @@ +""" + +NAWS - Negotiate About Window Size + +This implements the NAWS telnet option as per +https://www.ietf.org/rfc/rfc1073.txt + +NAWS allows telnet clients to report their +current window size to the client and update +it when the size changes + +""" +from django.conf import settings +from src.utils import utils + +NAWS = chr(31) +IS = chr(0) +# default taken from telnet specification +DEFAULT_WIDTH = settings.CLIENT_DEFAULT_WIDTH +DEFAULT_HEIGHT = settings.CLIENT_DEFAULT_HEIGHT + +# try to get the customized mssp info, if it exists. + +class Naws(object): + """ + Implements the MSSP protocol. Add this to a + variable on the telnet protocol to set it up. + """ + def __init__(self, protocol): + """ + initialize NAWS by storing protocol on ourselves + and calling the client to see if it supports + NAWS. + """ + self.naws_step = 0 + self.protocol = protocol + self.protocol.protocol_flags['SCREENWIDTH'] = {0: DEFAULT_WIDTH} # windowID (0 is root):width + self.protocol.protocol_flags['SCREENHEIGHT'] = {0: DEFAULT_HEIGHT} # windowID:width + self.protocol.negotiationMap[NAWS] = self.negotiate_sizes + self.protocol.do(NAWS).addCallbacks(self.do_naws, self.no_naws) + + def no_naws(self, option): + """ + This is the normal operation. + """ + self.protocol.handshake_done() + + def do_naws(self, option): + """ + Negotiate all the information. + """ + self.protocol.handshake_done() + + def negotiate_sizes(self, options): + if len(options) == 4: + # NAWS is negotiated with 16bit words + width = options[0] + options[1] + self.protocol.protocol_flags['SCREENWIDTH'][0] = int(width.encode('hex'), 16) + height = options[2] + options[3] + self.protocol.protocol_flags['SCREENHEIGHT'][0] = int(height.encode('hex'), 16) +