def connect(self): """ 打开 websocket 连接 :return: """ async_to_sync(self.channel_layer.group_add)("heartbeat", self.channel_name) self.accept() query_string = self.scope.get('query_string') ssh_args = QueryDict(query_string=query_string, encoding='utf-8') token = ssh_args.get('token') if Xcache.alive_token(token): result = HeartBeat.first_heartbeat_result() self.send(json.dumps(result)) return else: self.disconnect()
def connect(self): """ 打开 websocket 连接 :return: """ async_to_sync(self.channel_layer.group_add)("msfconsole", self.channel_name) self.accept() query_string = self.scope.get('query_string') ssh_args = QueryDict(query_string=query_string, encoding='utf-8') token = ssh_args.get('token') if Xcache.alive_token(token): result = Console.get_active_console() if result: return else: self.disconnect(True) return else: self.disconnect(True)