Commit 53a1a5e1 authored by ibuler's avatar ibuler

Merge branch 'dev' of github.com:jumpserver/coco into dev

parents 4a92f2fb 09167f5b
......@@ -120,7 +120,7 @@ class SSHws(Namespace, BaseWebSocketHandler):
def on_leave(self, room):
if self.rooms[room]["admin"] == request.sid:
self.emit("data", "\nAdmin leave", room=room)
self.rooms.remove(room)
del self.rooms[room]
leave_room(room=room)
def on_disconnect(self):
......
......@@ -5,7 +5,11 @@
import abc
import logging
import threading
import time
import os
import gzip
import json
import shutil
from .alignment import MemoryQueue
......@@ -98,18 +102,34 @@ class ServerReplayRecorder(ReplayRecorder):
:return:
"""
# Todo: <liuzheng712@gmail.com>
self.file.write(data)
if len(data['data']) > 0:
# print(json.dumps(
# data['data'].decode('utf-8', 'replace')))
self.file.write(
'"' + str(data['timestamp'] - self.starttime) + '":' + json.dumps(
data['data'].decode('utf-8', 'replace')) + ',')
def session_start(self, session_id):
self.starttime = time.time()
self.file = open(os.path.join(
self.app.config['LOG_DIR'], session_id + '.replay'
), 'a')
self.file.write('{')
def session_end(self, session_id):
self.file.write('"0":""}')
self.file.close()
with open(os.path.join(self.app.config['LOG_DIR'], session_id + '.replay'), 'rb') as f_in, \
gzip.open(os.path.join(self.app.config['LOG_DIR'], session_id + '.replay.gz'), 'wb') as f_out:
shutil.copyfileobj(f_in, f_out)
if self.push_to_server(session_id):
logger.info("Succeed to push {}'s {}".format(session_id, "record"))
else:
logger.error("Failed to push {}'s {}".format(session_id, "record"))
def push_to_server(self):
pass
def push_to_server(self, session_id):
return self.app.service.push_session_replay(os.path.join(self.app.config['LOG_DIR'], session_id + '.replay'),
session_id)
def __del__(self):
print("{} has been gc".format(self))
......
......@@ -8,13 +8,11 @@ import datetime
import selectors
import time
BUF_SIZE = 1024
logger = logging.getLogger(__file__)
class Session:
def __init__(self, client, server, command_recorder=None, replay_recorder=None):
self.id = str(uuid.uuid4())
self.client = client # Master of the session, it's a client sock
......@@ -123,6 +121,7 @@ class Session:
events = self.sel.select()
for sock in [key.fileobj for key, _ in events]:
data = sock.recv(BUF_SIZE)
# self.put_replay(data)
if sock == self.server:
if len(data) == 0:
msg = "Server close the connection"
......@@ -184,8 +183,3 @@ class Session:
def __del__(self):
logger.info("Session {} object has been GC")
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment