aboutsummaryrefslogtreecommitdiffstats
path: root/termcast.py
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2014-09-14 20:37:02 -0400
committerJesse Luehrs <doy@tozt.net>2014-09-14 20:37:02 -0400
commit4fd854da5a59da2478a40277b43c26686e25469b (patch)
tree00cc68963be3ce9c0d9040ea9502075e3e500ca0 /termcast.py
parentfc45d0b642b482f47638ca9b0f8fe69c8c9006b3 (diff)
downloadpython-termcast-server-4fd854da5a59da2478a40277b43c26686e25469b.tar.gz
python-termcast-server-4fd854da5a59da2478a40277b43c26686e25469b.zip
split the termcast and ssh handling out into separate files
Diffstat (limited to 'termcast.py')
-rw-r--r--termcast.py56
1 files changed, 56 insertions, 0 deletions
diff --git a/termcast.py b/termcast.py
new file mode 100644
index 0000000..171980d
--- /dev/null
+++ b/termcast.py
@@ -0,0 +1,56 @@
+import re
+
+import vt100
+
+class Handler(object):
+ def __init__(self):
+ self.buf = b''
+ self.vt = vt100.vt100()
+
+ def process(self, data):
+ self.buf += data
+ self.vt.process(data)
+
+ def get_term(self):
+ term = ''
+ for i in range(0, 24):
+ for j in range(0, 80):
+ term += self.vt.cell(i, j).contents.contents()
+ term += "\n"
+
+ return term[:-1]
+
+class Connection(object):
+ def __init__(self, client, connection_id):
+ self.client = client
+
+ def run(self, ssh_connections):
+ buf = b''
+ while len(buf) < 1024 and b"\n" not in buf:
+ buf += self.client.recv(1024)
+
+ pos = buf.find(b"\n")
+ if pos == -1:
+ print("no authentication found")
+ return
+
+ auth = buf[:pos]
+ buf = buf[pos+1:]
+
+ auth_re = re.compile(b'^hello ([^ ]+) ([^ ]+)$')
+ m = auth_re.match(auth)
+ if m is None:
+ print("no authentication found (%s)" % auth)
+ return
+
+ print(b"got auth: " + auth)
+ self.handler = Handler()
+ self.client.send(b"hello, " + m.group(1) + b"\n")
+
+ self.handler.process(buf)
+ while True:
+ buf = self.client.recv(1024)
+ if len(buf) > 0:
+ self.handler.process(buf)
+ else:
+ return