From cea16fc41fe4bfd064e550dbca9f7b5de0d3f924 Mon Sep 17 00:00:00 2001 From: feng <1304903146@qq.com> Date: Mon, 26 Feb 2024 10:50:44 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E5=91=BD=E4=BB=A4=E4=B8=8A=E4=BC=A0=20?= =?UTF-8?q?=E5=8F=96=E6=B6=88input=E9=95=BF=E5=BA=A6=E9=99=90=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/terminal/backends/command/db.py | 7 ++++--- apps/terminal/serializers/command.py | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/apps/terminal/backends/command/db.py b/apps/terminal/backends/command/db.py index 1cdc56bda..207ec70e1 100644 --- a/apps/terminal/backends/command/db.py +++ b/apps/terminal/backends/command/db.py @@ -2,10 +2,10 @@ import datetime from django.db import transaction -from django.utils import timezone from django.db.utils import OperationalError -from common.utils.common import pretty_string +from django.utils import timezone +from common.utils.common import pretty_string from .base import CommandBase @@ -19,9 +19,10 @@ class CommandStore(CommandBase): """ 保存命令到数据库 """ + cmd_input = pretty_string(command['input']) self.model.objects.create( user=command["user"], asset=command["asset"], - account=command["account"], input=command["input"], + account=command["account"], input=cmd_input, output=command["output"], session=command["session"], risk_level=command.get("risk_level", 0), org_id=command["org_id"], timestamp=command["timestamp"] diff --git a/apps/terminal/serializers/command.py b/apps/terminal/serializers/command.py index 11b16f5ad..0c2e9c949 100644 --- a/apps/terminal/serializers/command.py +++ b/apps/terminal/serializers/command.py @@ -15,7 +15,7 @@ class SimpleSessionCommandSerializer(serializers.ModelSerializer): """ 简单Session命令序列类, 用来提取公共字段 """ user = serializers.CharField(label=_("User")) # 限制 64 字符,见 validate_user asset = serializers.CharField(max_length=128, label=_("Asset")) - input = serializers.CharField(max_length=2048, label=_("Command")) + input = serializers.CharField(label=_("Command")) session = serializers.CharField(max_length=36, label=_("Session ID")) risk_level = LabeledChoiceField( choices=RiskLevelChoices.choices,