U 改进webssh安全性

pull/103/head
vapao 2020-05-25 10:33:21 +08:00
parent 9485289641
commit ad08f2c355
1 changed files with 10 additions and 1 deletions

View File

@ -4,9 +4,11 @@
from channels.generic.websocket import WebsocketConsumer from channels.generic.websocket import WebsocketConsumer
from django_redis import get_redis_connection from django_redis import get_redis_connection
from apps.setting.utils import AppSetting from apps.setting.utils import AppSetting
from apps.account.models import User
from apps.host.models import Host from apps.host.models import Host
from threading import Thread from threading import Thread
import json import json
import time
class ExecConsumer(WebsocketConsumer): class ExecConsumer(WebsocketConsumer):
@ -69,7 +71,14 @@ class SSHConsumer(WebsocketConsumer):
# print('Connection close') # print('Connection close')
def connect(self): def connect(self):
user = User.objects.filter(access_token=self.token).first()
if user and user.token_expired >= time.time() and user.is_active:
self.accept() self.accept()
self._init()
else:
self.close()
def _init(self):
self.send(bytes_data=b'Connecting ...\r\n') self.send(bytes_data=b'Connecting ...\r\n')
host = Host.objects.filter(pk=self.id).first() host = Host.objects.filter(pk=self.id).first()
if not host: if not host: