From 833b49a82208132c7da1b9b806f94f5026a8a50b Mon Sep 17 00:00:00 2001 From: vapao Date: Mon, 27 Jun 2022 14:04:13 +0800 Subject: [PATCH] =?UTF-8?q?U=20=E6=96=B0=E5=A2=9E=E4=BC=9A=E8=AF=9D?= =?UTF-8?q?=E8=BF=87=E6=9C=9F=E6=97=B6=E9=97=B4=E9=85=8D=E7=BD=AETOKEN=5FT?= =?UTF-8?q?TL?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spug_api/apps/account/views.py | 3 ++- spug_api/libs/ssh.py | 5 ++--- spug_api/spug/settings.py | 1 + 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/spug_api/apps/account/views.py b/spug_api/apps/account/views.py index 085ed73..8f60643 100644 --- a/spug_api/apps/account/views.py +++ b/spug_api/apps/account/views.py @@ -2,6 +2,7 @@ # Copyright: (c) # Released under the AGPL-3.0 License. from django.core.cache import cache +from django.conf import settings from libs.mixins import AdminView, View from libs import JsonParser, Argument, human_datetime, json_response from libs.utils import get_request_real_ip, generate_random_str @@ -245,7 +246,7 @@ def handle_user_info(request, user, captcha): x_real_ip = get_request_real_ip(request.headers) token_isvalid = user.access_token and len(user.access_token) == 32 and user.token_expired >= time.time() user.access_token = user.access_token if token_isvalid else uuid.uuid4().hex - user.token_expired = time.time() + 8 * 60 * 60 + user.token_expired = time.time() + settings.TOKEN_TTL user.last_login = human_datetime() user.last_ip = x_real_ip user.save() diff --git a/spug_api/libs/ssh.py b/spug_api/libs/ssh.py index f964c99..7624d72 100644 --- a/spug_api/libs/ssh.py +++ b/spug_api/libs/ssh.py @@ -155,11 +155,10 @@ class SSH: command = 'set +o history\nset +o zle\nset -o no_nomatch\nexport PS1= && stty -echo\n' command = self._handle_command(command, self.default_env) self.channel.sendall(command) - out = line = '' + out = '' while True: if self.channel.recv_ready(): - line = self._decode(self.channel.recv(8196)) - out += line + out += self._decode(self.channel.recv(8196)) if self.regex.search(out): self.stdout = self.channel.makefile('r') break diff --git a/spug_api/spug/settings.py b/spug_api/spug/settings.py index d1938f2..1cbfeea 100644 --- a/spug_api/spug/settings.py +++ b/spug_api/spug/settings.py @@ -102,6 +102,7 @@ TEMPLATES = [ }, ] +TOKEN_TTL = 8 * 3600 SCHEDULE_KEY = 'spug:schedule' SCHEDULE_WORKER_KEY = 'spug:schedule:worker' MONITOR_KEY = 'spug:monitor'