def disconnect(self, close_code):
将连接状态置为False
self.therecord.is_connecting = False
self.therecord.save()
async_to_sync(self.channel_layer.group_discard)(
self.group_name,
self.channel_name
)
self.ssh.close()
def receive(self, text_data=None):
text_data = json.loads(text_data)
if text_data.get(‘flag’) == ‘resize’:
self.ssh.resize_pty(cols=text_data[‘cols’], rows=text_data[‘rows’])
else:
self.ssh.shell(data=text_data.get(‘data’, ‘’))
def ssh_message(self, event):
self.send(text_data=json.dumps(
event[‘message’]
))
在connect连接建立时新建一条记录,存储主机、用户、group_name
、channel_name
以及初始窗口的cols
、rows
信息,同时标记is_connecting
为True,这里的group_name
命名与文章[『堡垒机的核心武器:WebSSH录像实现』](()中我们定义的录像文件名规则一致,另外