From 2741d7cbdc3b98505ad96ec869988e5a74adb773 Mon Sep 17 00:00:00 2001 From: "fangfang.dong" Date: Wed, 26 Jul 2023 19:36:15 +0800 Subject: [PATCH 1/4] =?UTF-8?q?feat:=20=E7=BB=88=E7=AB=AF=E4=BC=9A?= =?UTF-8?q?=E8=AF=9D=E5=88=86=E4=BA=AB=E5=A2=9E=E5=8A=A0=E6=B6=88=E6=81=AF?= =?UTF-8?q?=E9=80=9A=E7=9F=A5=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/locale/ja/LC_MESSAGES/django.po | 88 +++++++++++-------- apps/locale/zh/LC_MESSAGES/django.po | 88 +++++++++++-------- .../migrations/0064_sessionsharing_origin.py | 18 ++++ apps/terminal/models/session/sharing.py | 14 ++- apps/terminal/notifications.py | 24 +++++ apps/terminal/serializers/sharing.py | 2 +- apps/terminal/signal_handlers/__init__.py | 1 + .../signal_handlers/session_sharing.py | 13 +++ .../terminal/_msg_session_sharing.html | 16 ++++ 9 files changed, 186 insertions(+), 78 deletions(-) create mode 100644 apps/terminal/migrations/0064_sessionsharing_origin.py create mode 100644 apps/terminal/signal_handlers/session_sharing.py create mode 100644 apps/terminal/templates/terminal/_msg_session_sharing.html diff --git a/apps/locale/ja/LC_MESSAGES/django.po b/apps/locale/ja/LC_MESSAGES/django.po index 424fbf22b..893c9f0e6 100644 --- a/apps/locale/ja/LC_MESSAGES/django.po +++ b/apps/locale/ja/LC_MESSAGES/django.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2023-07-25 15:37+0800\n" +"POT-Creation-Date: 2023-07-26 19:15+0800\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -202,6 +202,7 @@ msgstr "作成のみ" #: terminal/backends/command/models.py:17 terminal/models/session/session.py:31 #: terminal/notifications.py:155 terminal/serializers/command.py:17 #: terminal/templates/terminal/_msg_command_warning.html:4 +#: terminal/templates/terminal/_msg_session_sharing.html:4 #: tickets/models/ticket/apply_asset.py:16 xpack/plugins/cloud/models.py:212 msgid "Asset" msgstr "資産" @@ -236,6 +237,7 @@ msgstr "ソース ID" #: perms/models/asset_permission.py:70 perms/serializers/permission.py:39 #: terminal/backends/command/models.py:18 terminal/models/session/session.py:33 #: terminal/templates/terminal/_msg_command_warning.html:8 +#: terminal/templates/terminal/_msg_session_sharing.html:8 #: tickets/models/ticket/command_confirm.py:13 xpack/plugins/cloud/models.py:85 msgid "Account" msgstr "アカウント" @@ -314,7 +316,7 @@ msgid "Trigger mode" msgstr "トリガーモード" #: accounts/models/automations/backup_account.py:97 audits/models.py:194 -#: terminal/models/session/sharing.py:111 xpack/plugins/cloud/models.py:168 +#: terminal/models/session/sharing.py:119 xpack/plugins/cloud/models.py:168 msgid "Reason" msgstr "理由" @@ -655,10 +657,11 @@ msgstr "ID" #: perms/api/user_permission/mixin.py:55 perms/models/asset_permission.py:58 #: perms/serializers/permission.py:30 rbac/builtin.py:123 #: rbac/models/rolebinding.py:49 terminal/backends/command/models.py:16 -#: terminal/models/session/session.py:29 terminal/models/session/sharing.py:32 +#: terminal/models/session/session.py:29 terminal/models/session/sharing.py:35 #: terminal/notifications.py:156 terminal/notifications.py:205 #: terminal/serializers/command.py:16 #: terminal/templates/terminal/_msg_command_warning.html:6 +#: terminal/templates/terminal/_msg_session_sharing.html:6 #: tickets/models/comment.py:21 users/const.py:14 users/models/user.py:947 #: users/models/user.py:983 users/serializers/group.py:18 msgid "User" @@ -696,7 +699,7 @@ msgid "Key password" msgstr "キーパスワード" #: accounts/serializers/account/base.py:80 -#: assets/serializers/asset/common.py:309 +#: assets/serializers/asset/common.py:311 msgid "Spec info" msgstr "特別情報" @@ -745,7 +748,7 @@ msgstr "自動タスク実行履歴" #: accounts/serializers/automations/change_secret.py:155 audits/const.py:53 #: audits/models.py:59 audits/signal_handlers/activity_log.py:33 #: common/const/choices.py:18 ops/const.py:56 ops/serializers/celery.py:40 -#: terminal/const.py:76 terminal/models/session/sharing.py:107 +#: terminal/const.py:76 terminal/models/session/sharing.py:115 #: tickets/views/approve.py:115 msgid "Success" msgstr "成功" @@ -829,7 +832,7 @@ msgstr "レビュー担当者" #: acls/models/base.py:43 authentication/models/access_key.py:17 #: authentication/models/connection_token.py:53 #: authentication/templates/authentication/_access_key_modal.html:32 -#: perms/models/asset_permission.py:76 terminal/models/session/sharing.py:27 +#: perms/models/asset_permission.py:76 terminal/models/session/sharing.py:30 #: tickets/const.py:37 msgid "Active" msgstr "アクティブ" @@ -839,7 +842,7 @@ msgid "Users" msgstr "ユーザー" #: acls/models/base.py:98 assets/models/automations/base.py:17 -#: assets/models/cmd_filter.py:38 assets/serializers/asset/common.py:308 +#: assets/models/cmd_filter.py:38 assets/serializers/asset/common.py:310 #: rbac/tree.py:35 msgid "Accounts" msgstr "アカウント" @@ -1152,10 +1155,6 @@ msgstr "" msgid "Other" msgstr "その他" -#: assets/const/protocol.py:43 -msgid "SFTP enabled" -msgstr "SFTP が有効" - #: assets/const/protocol.py:48 msgid "SFTP home" msgstr "SFTP ルート パス" @@ -1368,7 +1367,7 @@ msgstr "ドメイン" msgid "Labels" msgstr "ラベル" -#: assets/models/asset/common.py:158 assets/serializers/asset/common.py:310 +#: assets/models/asset/common.py:158 assets/serializers/asset/common.py:312 #: assets/serializers/asset/host.py:11 msgid "Gathered info" msgstr "資産ハードウェア情報の収集" @@ -1702,19 +1701,19 @@ msgid "Node path" msgstr "ノードパスです" #: assets/serializers/asset/common.py:145 -#: assets/serializers/asset/common.py:311 +#: assets/serializers/asset/common.py:313 msgid "Auto info" msgstr "自動情報" -#: assets/serializers/asset/common.py:234 +#: assets/serializers/asset/common.py:236 msgid "Platform not exist" msgstr "プラットフォームが存在しません" -#: assets/serializers/asset/common.py:270 +#: assets/serializers/asset/common.py:272 msgid "port out of range (0-65535)" msgstr "ポート番号が範囲外です (0-65535)" -#: assets/serializers/asset/common.py:277 +#: assets/serializers/asset/common.py:279 msgid "Protocol is required: {}" msgstr "プロトコルが必要です: {}" @@ -1998,6 +1997,7 @@ msgstr "マップディレクトリ" #: audits/const.py:23 rbac/tree.py:229 #: terminal/templates/terminal/_msg_command_warning.html:18 +#: terminal/templates/terminal/_msg_session_sharing.html:10 msgid "View" msgstr "表示" @@ -2061,7 +2061,7 @@ msgid "Job audit log" msgstr "ジョブ監査ログ" #: audits/models.py:51 audits/models.py:95 audits/models.py:166 -#: terminal/models/session/session.py:38 terminal/models/session/sharing.py:99 +#: terminal/models/session/session.py:38 terminal/models/session/sharing.py:107 msgid "Remote addr" msgstr "リモートaddr" @@ -2078,8 +2078,8 @@ msgid "File" msgstr "書類" #: audits/models.py:62 terminal/backends/command/models.py:21 -#: terminal/models/session/replay.py:9 terminal/models/session/sharing.py:18 -#: terminal/models/session/sharing.py:81 +#: terminal/models/session/replay.py:9 terminal/models/session/sharing.py:21 +#: terminal/models/session/sharing.py:89 #: terminal/templates/terminal/_msg_command_alert.html:10 #: terminal/templates/terminal/_msg_command_warning.html:17 #: tickets/models/ticket/command_confirm.py:15 @@ -2940,7 +2940,8 @@ msgid "request new one" msgstr "新しいものを要求する" #: authentication/templates/authentication/_msg_reset_password_code.html:12 -#: terminal/models/session/sharing.py:25 terminal/models/session/sharing.py:83 +#: terminal/models/session/sharing.py:28 terminal/models/session/sharing.py:91 +#: terminal/templates/terminal/_msg_session_sharing.html:12 #: users/forms/profile.py:107 users/templates/users/forgot_password.html:66 msgid "Verify code" msgstr "コードの確認" @@ -3688,7 +3689,7 @@ msgstr "アルグ" #: ops/models/adhoc.py:25 ops/models/base.py:16 ops/models/base.py:53 #: ops/models/job.py:106 ops/models/job.py:192 ops/models/playbook.py:25 -#: terminal/models/session/sharing.py:23 +#: terminal/models/session/sharing.py:26 msgid "Creator" msgstr "作成者" @@ -3729,7 +3730,7 @@ msgstr "タスクモニターを表示できます" msgid "Kwargs" msgstr "クワーグ" -#: ops/models/celery.py:61 terminal/models/session/sharing.py:114 +#: ops/models/celery.py:61 terminal/models/session/sharing.py:122 #: tickets/const.py:25 msgid "Finished" msgstr "終了" @@ -3925,6 +3926,7 @@ msgstr "アプリ組織" #: rbac/const.py:7 rbac/models/rolebinding.py:56 #: rbac/serializers/rolebinding.py:40 settings/serializers/auth/ldap.py:63 #: terminal/templates/terminal/_msg_command_warning.html:21 +#: terminal/templates/terminal/_msg_session_sharing.html:14 #: tickets/models/ticket/general.py:302 tickets/serializers/ticket/ticket.py:60 msgid "Organization" msgstr "組織" @@ -5742,7 +5744,7 @@ msgstr "出力" msgid "Risk level" msgstr "リスクレベル" -#: terminal/connect_methods.py:34 +#: terminal/connect_methods.py:35 msgid "DB Client" msgstr "データベース クライアント" @@ -5998,7 +6000,7 @@ msgstr "セッション再生をダウンロードできます" msgid "Account id" msgstr "アカウント ID" -#: terminal/models/session/session.py:36 terminal/models/session/sharing.py:104 +#: terminal/models/session/session.py:36 terminal/models/session/sharing.py:112 msgid "Login from" msgstr "ログイン元" @@ -6030,56 +6032,61 @@ msgstr "セッションを終了できます" msgid "Can validate session action perm" msgstr "セッションアクションのパーマを検証できます" -#: terminal/models/session/sharing.py:30 +#: terminal/models/session/sharing.py:33 msgid "Expired time (min)" msgstr "期限切れ時間 (分)" -#: terminal/models/session/sharing.py:35 terminal/serializers/sharing.py:20 +#: terminal/models/session/sharing.py:37 terminal/serializers/sharing.py:20 #: terminal/serializers/sharing.py:52 msgid "Action permission" msgstr "アクションパーミッション" -#: terminal/models/session/sharing.py:40 terminal/models/session/sharing.py:86 +#: terminal/models/session/sharing.py:39 +msgid "Origin" +msgstr "" + +#: terminal/models/session/sharing.py:43 terminal/models/session/sharing.py:94 +#: terminal/notifications.py:261 msgid "Session sharing" msgstr "セッション共有" -#: terminal/models/session/sharing.py:42 +#: terminal/models/session/sharing.py:45 msgid "Can add super session sharing" msgstr "スーパーセッション共有を追加できます" -#: terminal/models/session/sharing.py:69 +#: terminal/models/session/sharing.py:77 msgid "Link not active" msgstr "リンクがアクティブでない" -#: terminal/models/session/sharing.py:71 +#: terminal/models/session/sharing.py:79 msgid "Link expired" msgstr "リンク期限切れ" -#: terminal/models/session/sharing.py:73 +#: terminal/models/session/sharing.py:81 msgid "User not allowed to join" msgstr "ユーザーはセッションに参加できません" -#: terminal/models/session/sharing.py:90 terminal/serializers/sharing.py:71 +#: terminal/models/session/sharing.py:98 terminal/serializers/sharing.py:71 msgid "Joiner" msgstr "ジョイナー" -#: terminal/models/session/sharing.py:93 +#: terminal/models/session/sharing.py:101 msgid "Date joined" msgstr "参加日" -#: terminal/models/session/sharing.py:96 +#: terminal/models/session/sharing.py:104 msgid "Date left" msgstr "日付が残っています" -#: terminal/models/session/sharing.py:119 +#: terminal/models/session/sharing.py:127 msgid "Session join record" msgstr "セッション参加記録" -#: terminal/models/session/sharing.py:135 +#: terminal/models/session/sharing.py:143 msgid "Invalid verification code" msgstr "検証コードが無効" -#: terminal/models/session/sharing.py:142 +#: terminal/models/session/sharing.py:150 msgid "You have already joined this session" msgstr "すでにこのセッションに参加しています" @@ -6388,6 +6395,10 @@ msgstr "チェックコマンドと録画ストレージの接続性" msgid "view" msgstr "表示" +#: terminal/templates/terminal/_msg_session_sharing.html:10 +msgid "Session sharing URL" +msgstr "セッション共有 URL" + #: terminal/utils/db_port_mapper.py:85 msgid "" "No available port is matched. The number of databases may have exceeded the " @@ -7892,6 +7903,9 @@ msgstr "究極のエディション" msgid "Community edition" msgstr "コミュニティ版" +#~ msgid "SFTP enabled" +#~ msgstr "SFTP が有効" + #~ msgid "Item" #~ msgstr "アイテム" diff --git a/apps/locale/zh/LC_MESSAGES/django.po b/apps/locale/zh/LC_MESSAGES/django.po index 10fd864cc..1ee0dc26f 100644 --- a/apps/locale/zh/LC_MESSAGES/django.po +++ b/apps/locale/zh/LC_MESSAGES/django.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: JumpServer 0.3.3\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2023-07-25 15:37+0800\n" +"POT-Creation-Date: 2023-07-26 19:14+0800\n" "PO-Revision-Date: 2021-05-20 10:54+0800\n" "Last-Translator: ibuler \n" "Language-Team: JumpServer team\n" @@ -201,6 +201,7 @@ msgstr "仅创建" #: terminal/backends/command/models.py:17 terminal/models/session/session.py:31 #: terminal/notifications.py:155 terminal/serializers/command.py:17 #: terminal/templates/terminal/_msg_command_warning.html:4 +#: terminal/templates/terminal/_msg_session_sharing.html:4 #: tickets/models/ticket/apply_asset.py:16 xpack/plugins/cloud/models.py:212 msgid "Asset" msgstr "资产" @@ -235,6 +236,7 @@ msgstr "来源 ID" #: perms/models/asset_permission.py:70 perms/serializers/permission.py:39 #: terminal/backends/command/models.py:18 terminal/models/session/session.py:33 #: terminal/templates/terminal/_msg_command_warning.html:8 +#: terminal/templates/terminal/_msg_session_sharing.html:8 #: tickets/models/ticket/command_confirm.py:13 xpack/plugins/cloud/models.py:85 msgid "Account" msgstr "账号" @@ -313,7 +315,7 @@ msgid "Trigger mode" msgstr "触发模式" #: accounts/models/automations/backup_account.py:97 audits/models.py:194 -#: terminal/models/session/sharing.py:111 xpack/plugins/cloud/models.py:168 +#: terminal/models/session/sharing.py:119 xpack/plugins/cloud/models.py:168 msgid "Reason" msgstr "原因" @@ -651,10 +653,11 @@ msgstr "ID" #: perms/api/user_permission/mixin.py:55 perms/models/asset_permission.py:58 #: perms/serializers/permission.py:30 rbac/builtin.py:123 #: rbac/models/rolebinding.py:49 terminal/backends/command/models.py:16 -#: terminal/models/session/session.py:29 terminal/models/session/sharing.py:32 +#: terminal/models/session/session.py:29 terminal/models/session/sharing.py:35 #: terminal/notifications.py:156 terminal/notifications.py:205 #: terminal/serializers/command.py:16 #: terminal/templates/terminal/_msg_command_warning.html:6 +#: terminal/templates/terminal/_msg_session_sharing.html:6 #: tickets/models/comment.py:21 users/const.py:14 users/models/user.py:947 #: users/models/user.py:983 users/serializers/group.py:18 msgid "User" @@ -692,7 +695,7 @@ msgid "Key password" msgstr "密钥密码" #: accounts/serializers/account/base.py:80 -#: assets/serializers/asset/common.py:309 +#: assets/serializers/asset/common.py:311 msgid "Spec info" msgstr "特殊信息" @@ -741,7 +744,7 @@ msgstr "自动化任务执行历史" #: accounts/serializers/automations/change_secret.py:155 audits/const.py:53 #: audits/models.py:59 audits/signal_handlers/activity_log.py:33 #: common/const/choices.py:18 ops/const.py:56 ops/serializers/celery.py:40 -#: terminal/const.py:76 terminal/models/session/sharing.py:107 +#: terminal/const.py:76 terminal/models/session/sharing.py:115 #: tickets/views/approve.py:115 msgid "Success" msgstr "成功" @@ -825,7 +828,7 @@ msgstr "审批人" #: acls/models/base.py:43 authentication/models/access_key.py:17 #: authentication/models/connection_token.py:53 #: authentication/templates/authentication/_access_key_modal.html:32 -#: perms/models/asset_permission.py:76 terminal/models/session/sharing.py:27 +#: perms/models/asset_permission.py:76 terminal/models/session/sharing.py:30 #: tickets/const.py:37 msgid "Active" msgstr "激活中" @@ -835,7 +838,7 @@ msgid "Users" msgstr "用户管理" #: acls/models/base.py:98 assets/models/automations/base.py:17 -#: assets/models/cmd_filter.py:38 assets/serializers/asset/common.py:308 +#: assets/models/cmd_filter.py:38 assets/serializers/asset/common.py:310 #: rbac/tree.py:35 msgid "Accounts" msgstr "账号管理" @@ -1145,10 +1148,6 @@ msgstr "ChatGPT" msgid "Other" msgstr "其它" -#: assets/const/protocol.py:43 -msgid "SFTP enabled" -msgstr "SFTP 已启用" - #: assets/const/protocol.py:48 msgid "SFTP home" msgstr "SFTP 根路径" @@ -1361,7 +1360,7 @@ msgstr "网域" msgid "Labels" msgstr "标签管理" -#: assets/models/asset/common.py:158 assets/serializers/asset/common.py:310 +#: assets/models/asset/common.py:158 assets/serializers/asset/common.py:312 #: assets/serializers/asset/host.py:11 msgid "Gathered info" msgstr "收集资产硬件信息" @@ -1693,19 +1692,19 @@ msgid "Node path" msgstr "节点路径" #: assets/serializers/asset/common.py:145 -#: assets/serializers/asset/common.py:311 +#: assets/serializers/asset/common.py:313 msgid "Auto info" msgstr "自动化信息" -#: assets/serializers/asset/common.py:234 +#: assets/serializers/asset/common.py:236 msgid "Platform not exist" msgstr "平台不存在" -#: assets/serializers/asset/common.py:270 +#: assets/serializers/asset/common.py:272 msgid "port out of range (0-65535)" msgstr "端口超出范围 (0-65535)" -#: assets/serializers/asset/common.py:277 +#: assets/serializers/asset/common.py:279 msgid "Protocol is required: {}" msgstr "协议是必填的: {}" @@ -1982,6 +1981,7 @@ msgstr "映射目录" #: audits/const.py:23 rbac/tree.py:229 #: terminal/templates/terminal/_msg_command_warning.html:18 +#: terminal/templates/terminal/_msg_session_sharing.html:10 msgid "View" msgstr "查看" @@ -2045,7 +2045,7 @@ msgid "Job audit log" msgstr "作业审计日志" #: audits/models.py:51 audits/models.py:95 audits/models.py:166 -#: terminal/models/session/session.py:38 terminal/models/session/sharing.py:99 +#: terminal/models/session/session.py:38 terminal/models/session/sharing.py:107 msgid "Remote addr" msgstr "远端地址" @@ -2062,8 +2062,8 @@ msgid "File" msgstr "文件" #: audits/models.py:62 terminal/backends/command/models.py:21 -#: terminal/models/session/replay.py:9 terminal/models/session/sharing.py:18 -#: terminal/models/session/sharing.py:81 +#: terminal/models/session/replay.py:9 terminal/models/session/sharing.py:21 +#: terminal/models/session/sharing.py:89 #: terminal/templates/terminal/_msg_command_alert.html:10 #: terminal/templates/terminal/_msg_command_warning.html:17 #: tickets/models/ticket/command_confirm.py:15 @@ -2904,7 +2904,8 @@ msgid "request new one" msgstr "重新申请" #: authentication/templates/authentication/_msg_reset_password_code.html:12 -#: terminal/models/session/sharing.py:25 terminal/models/session/sharing.py:83 +#: terminal/models/session/sharing.py:28 terminal/models/session/sharing.py:91 +#: terminal/templates/terminal/_msg_session_sharing.html:12 #: users/forms/profile.py:107 users/templates/users/forgot_password.html:66 msgid "Verify code" msgstr "验证码" @@ -3641,7 +3642,7 @@ msgstr "参数" #: ops/models/adhoc.py:25 ops/models/base.py:16 ops/models/base.py:53 #: ops/models/job.py:106 ops/models/job.py:192 ops/models/playbook.py:25 -#: terminal/models/session/sharing.py:23 +#: terminal/models/session/sharing.py:26 msgid "Creator" msgstr "创建者" @@ -3682,7 +3683,7 @@ msgstr "可以查看任务监控" msgid "Kwargs" msgstr "其它参数" -#: ops/models/celery.py:61 terminal/models/session/sharing.py:114 +#: ops/models/celery.py:61 terminal/models/session/sharing.py:122 #: tickets/const.py:25 msgid "Finished" msgstr "结束" @@ -3877,6 +3878,7 @@ msgstr "组织管理" #: rbac/const.py:7 rbac/models/rolebinding.py:56 #: rbac/serializers/rolebinding.py:40 settings/serializers/auth/ldap.py:63 #: terminal/templates/terminal/_msg_command_warning.html:21 +#: terminal/templates/terminal/_msg_session_sharing.html:14 #: tickets/models/ticket/general.py:302 tickets/serializers/ticket/ticket.py:60 msgid "Organization" msgstr "组织" @@ -5655,7 +5657,7 @@ msgstr "输出" msgid "Risk level" msgstr "风险等级" -#: terminal/connect_methods.py:34 +#: terminal/connect_methods.py:35 msgid "DB Client" msgstr "数据库客户端" @@ -5911,7 +5913,7 @@ msgstr "可以下载会话录像" msgid "Account id" msgstr "账号 ID" -#: terminal/models/session/session.py:36 terminal/models/session/sharing.py:104 +#: terminal/models/session/session.py:36 terminal/models/session/sharing.py:112 msgid "Login from" msgstr "登录来源" @@ -5943,56 +5945,61 @@ msgstr "可以终断会话" msgid "Can validate session action perm" msgstr "可以验证会话动作权限" -#: terminal/models/session/sharing.py:30 +#: terminal/models/session/sharing.py:33 msgid "Expired time (min)" msgstr "过期时间 (分)" -#: terminal/models/session/sharing.py:35 terminal/serializers/sharing.py:20 +#: terminal/models/session/sharing.py:37 terminal/serializers/sharing.py:20 #: terminal/serializers/sharing.py:52 msgid "Action permission" msgstr "操作权限" -#: terminal/models/session/sharing.py:40 terminal/models/session/sharing.py:86 +#: terminal/models/session/sharing.py:39 +msgid "Origin" +msgstr "" + +#: terminal/models/session/sharing.py:43 terminal/models/session/sharing.py:94 +#: terminal/notifications.py:261 msgid "Session sharing" msgstr "会话分享" -#: terminal/models/session/sharing.py:42 +#: terminal/models/session/sharing.py:45 msgid "Can add super session sharing" msgstr "可以创建超级会话分享" -#: terminal/models/session/sharing.py:69 +#: terminal/models/session/sharing.py:77 msgid "Link not active" msgstr "链接失效" -#: terminal/models/session/sharing.py:71 +#: terminal/models/session/sharing.py:79 msgid "Link expired" msgstr "链接过期" -#: terminal/models/session/sharing.py:73 +#: terminal/models/session/sharing.py:81 msgid "User not allowed to join" msgstr "该用户无权加入会话" -#: terminal/models/session/sharing.py:90 terminal/serializers/sharing.py:71 +#: terminal/models/session/sharing.py:98 terminal/serializers/sharing.py:71 msgid "Joiner" msgstr "加入者" -#: terminal/models/session/sharing.py:93 +#: terminal/models/session/sharing.py:101 msgid "Date joined" msgstr "加入日期" -#: terminal/models/session/sharing.py:96 +#: terminal/models/session/sharing.py:104 msgid "Date left" msgstr "结束日期" -#: terminal/models/session/sharing.py:119 +#: terminal/models/session/sharing.py:127 msgid "Session join record" msgstr "会话加入记录" -#: terminal/models/session/sharing.py:135 +#: terminal/models/session/sharing.py:143 msgid "Invalid verification code" msgstr "验证码不正确" -#: terminal/models/session/sharing.py:142 +#: terminal/models/session/sharing.py:150 msgid "You have already joined this session" msgstr "您已经加入过此会话" @@ -6296,6 +6303,10 @@ msgstr "检查命令及录像存储可连接性 " msgid "view" msgstr "查看" +#: terminal/templates/terminal/_msg_session_sharing.html:10 +msgid "Session sharing URL" +msgstr "会话分享 URL" + #: terminal/utils/db_port_mapper.py:85 msgid "" "No available port is matched. The number of databases may have exceeded the " @@ -7778,6 +7789,9 @@ msgstr "旗舰版" msgid "Community edition" msgstr "社区版" +#~ msgid "SFTP enabled" +#~ msgstr "SFTP 已启用" + #~ msgid "Item" #~ msgstr "项目" diff --git a/apps/terminal/migrations/0064_sessionsharing_origin.py b/apps/terminal/migrations/0064_sessionsharing_origin.py new file mode 100644 index 000000000..91886fc16 --- /dev/null +++ b/apps/terminal/migrations/0064_sessionsharing_origin.py @@ -0,0 +1,18 @@ +# Generated by Django 4.1.10 on 2023-07-26 10:55 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('terminal', '0063_auto_20230621_1133'), + ] + + operations = [ + migrations.AddField( + model_name='sessionsharing', + name='origin', + field=models.URLField(blank=True, null=True, verbose_name='Origin'), + ), + ] diff --git a/apps/terminal/models/session/sharing.py b/apps/terminal/models/session/sharing.py index e5187a3b8..efae4f8a9 100644 --- a/apps/terminal/models/session/sharing.py +++ b/apps/terminal/models/session/sharing.py @@ -3,8 +3,11 @@ import datetime from django.db import models from django.utils import timezone from django.utils.translation import gettext_lazy as _ +from django.utils.functional import cached_property +from common.utils.random import random_string from common.db.models import JMSBaseModel +from common.db.fields import JsonListTextField from orgs.mixins.models import OrgModelMixin from orgs.utils import tmp_to_root_org from users.models import User @@ -30,10 +33,10 @@ class SessionSharing(JMSBaseModel, OrgModelMixin): default=0, verbose_name=_('Expired time (min)'), db_index=True ) users = models.TextField(blank=True, verbose_name=_("User")) - action_permission = models.CharField( max_length=16, verbose_name=_('Action permission'), default='writable' ) + origin = models.URLField(blank=True, null=True, verbose_name=_('Origin')) class Meta: ordering = ('-date_created',) @@ -45,15 +48,20 @@ class SessionSharing(JMSBaseModel, OrgModelMixin): def __str__(self): return 'Creator: {}'.format(self.creator) + @cached_property def users_display(self): if not self.users: return [] with tmp_to_root_org(): - user_ids = self.users.split(',') - users = User.objects.filter(id__in=user_ids) + users = self.users_queryset users = [str(user) for user in users] return users + @cached_property + def users_queryset(self): + user_ids = self.users.split(',') + return User.objects.filter(id__in=user_ids) + @property def date_expired(self): return self.date_created + datetime.timedelta(minutes=self.expired_time) diff --git a/apps/terminal/notifications.py b/apps/terminal/notifications.py index f200650a6..a09f8ccb1 100644 --- a/apps/terminal/notifications.py +++ b/apps/terminal/notifications.py @@ -255,3 +255,27 @@ class StorageConnectivityMessage(SystemMessage): 'subject': subject, 'message': message } + + +class SessionSharingMessage(UserMessage): + message_type_label = _('Session sharing') + + def __init__(self, user, instance): + super().__init__(user) + self.instance = instance + + def get_html_msg(self) -> dict: + instance = self.instance + context = { + 'asset': instance.session.asset, + 'created_by': instance.created_by, + 'account': instance.session.account, + 'session_url': '%s/koko/share/%s/' % (instance.origin, instance.id), + 'verify_code': instance.verify_code, + 'org': instance.org_name, + } + message = render_to_string('terminal/_msg_session_sharing.html', context) + return { + 'subject': self.message_type_label + ' ' + self.instance.created_by, + 'message': message + } diff --git a/apps/terminal/serializers/sharing.py b/apps/terminal/serializers/sharing.py index abc2dbdd3..42d74318b 100644 --- a/apps/terminal/serializers/sharing.py +++ b/apps/terminal/serializers/sharing.py @@ -26,7 +26,7 @@ class SessionSharingSerializer(OrgResourceModelSerializerMixin): fields_small = fields_mini + [ 'verify_code', 'is_active', 'expired_time', 'created_by', 'date_created', 'date_updated', 'users', 'users_display', - 'action_permission' + 'action_permission', 'origin', ] fields_fk = ['session', 'creator'] fields = fields_small + fields_fk diff --git a/apps/terminal/signal_handlers/__init__.py b/apps/terminal/signal_handlers/__init__.py index 265f6416d..5ba51e77a 100644 --- a/apps/terminal/signal_handlers/__init__.py +++ b/apps/terminal/signal_handlers/__init__.py @@ -1,3 +1,4 @@ from .applet import * from .db_port import * from .terminal import * +from .session_sharing import * diff --git a/apps/terminal/signal_handlers/session_sharing.py b/apps/terminal/signal_handlers/session_sharing.py new file mode 100644 index 000000000..f20ccf665 --- /dev/null +++ b/apps/terminal/signal_handlers/session_sharing.py @@ -0,0 +1,13 @@ +from django.db.models.signals import post_save +from django.dispatch import receiver + +from terminal.models import SessionSharing +from terminal.notifications import SessionSharingMessage + + +@receiver(post_save, sender=SessionSharing) +def on_session_sharing_created(sender, instance: SessionSharing, created, **kwargs): + if not created: + return + for user in instance.users_queryset: + SessionSharingMessage(user, instance).publish_async() diff --git a/apps/terminal/templates/terminal/_msg_session_sharing.html b/apps/terminal/templates/terminal/_msg_session_sharing.html new file mode 100644 index 000000000..b28129900 --- /dev/null +++ b/apps/terminal/templates/terminal/_msg_session_sharing.html @@ -0,0 +1,16 @@ +{% load i18n %} + +
+ {% trans 'Asset' %}: {{ asset }} +
+ {% trans 'User' %}: {{ created_by }} +
+ {% trans 'Account' %}: {{ account }} +
+ {% trans 'Session sharing URL' %}: {% trans 'View' %} +
+ {% trans 'Verify code' %}: {{ verify_code }} +
+ {% trans 'Organization' %}: {{ org }} +
+
From 7a37f919644124d97be1f1bf5cd6c980c34f542f Mon Sep 17 00:00:00 2001 From: nut Date: Wed, 26 Jul 2023 19:40:56 +0800 Subject: [PATCH 2/4] Update sharing.py --- apps/terminal/models/session/sharing.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/apps/terminal/models/session/sharing.py b/apps/terminal/models/session/sharing.py index efae4f8a9..e2ef06a5f 100644 --- a/apps/terminal/models/session/sharing.py +++ b/apps/terminal/models/session/sharing.py @@ -5,9 +5,7 @@ from django.utils import timezone from django.utils.translation import gettext_lazy as _ from django.utils.functional import cached_property -from common.utils.random import random_string from common.db.models import JMSBaseModel -from common.db.fields import JsonListTextField from orgs.mixins.models import OrgModelMixin from orgs.utils import tmp_to_root_org from users.models import User From 1239ffd4c834cdd6ee7a974da3ead25e29100a05 Mon Sep 17 00:00:00 2001 From: "fangfang.dong" Date: Thu, 27 Jul 2023 12:52:33 +0800 Subject: [PATCH 3/4] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96=E4=BC=9A?= =?UTF-8?q?=E8=AF=9D=E5=88=86=E4=BA=ABurl=E7=9A=84=E6=9E=84=E9=80=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/locale/ja/LC_MESSAGES/django.po | 54 +++++++++---------- apps/locale/zh/LC_MESSAGES/django.po | 54 +++++++++---------- apps/terminal/models/session/sharing.py | 4 ++ apps/terminal/notifications.py | 2 +- apps/terminal/serializers/sharing.py | 2 +- .../terminal/_msg_session_sharing.html | 2 +- 6 files changed, 61 insertions(+), 57 deletions(-) diff --git a/apps/locale/ja/LC_MESSAGES/django.po b/apps/locale/ja/LC_MESSAGES/django.po index 893c9f0e6..607cafcf2 100644 --- a/apps/locale/ja/LC_MESSAGES/django.po +++ b/apps/locale/ja/LC_MESSAGES/django.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2023-07-26 19:15+0800\n" +"POT-Creation-Date: 2023-07-27 11:11+0800\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -316,7 +316,7 @@ msgid "Trigger mode" msgstr "トリガーモード" #: accounts/models/automations/backup_account.py:97 audits/models.py:194 -#: terminal/models/session/sharing.py:119 xpack/plugins/cloud/models.py:168 +#: terminal/models/session/sharing.py:117 xpack/plugins/cloud/models.py:168 msgid "Reason" msgstr "理由" @@ -657,7 +657,7 @@ msgstr "ID" #: perms/api/user_permission/mixin.py:55 perms/models/asset_permission.py:58 #: perms/serializers/permission.py:30 rbac/builtin.py:123 #: rbac/models/rolebinding.py:49 terminal/backends/command/models.py:16 -#: terminal/models/session/session.py:29 terminal/models/session/sharing.py:35 +#: terminal/models/session/session.py:29 terminal/models/session/sharing.py:33 #: terminal/notifications.py:156 terminal/notifications.py:205 #: terminal/serializers/command.py:16 #: terminal/templates/terminal/_msg_command_warning.html:6 @@ -748,7 +748,7 @@ msgstr "自動タスク実行履歴" #: accounts/serializers/automations/change_secret.py:155 audits/const.py:53 #: audits/models.py:59 audits/signal_handlers/activity_log.py:33 #: common/const/choices.py:18 ops/const.py:56 ops/serializers/celery.py:40 -#: terminal/const.py:76 terminal/models/session/sharing.py:115 +#: terminal/const.py:76 terminal/models/session/sharing.py:113 #: tickets/views/approve.py:115 msgid "Success" msgstr "成功" @@ -832,7 +832,7 @@ msgstr "レビュー担当者" #: acls/models/base.py:43 authentication/models/access_key.py:17 #: authentication/models/connection_token.py:53 #: authentication/templates/authentication/_access_key_modal.html:32 -#: perms/models/asset_permission.py:76 terminal/models/session/sharing.py:30 +#: perms/models/asset_permission.py:76 terminal/models/session/sharing.py:28 #: tickets/const.py:37 msgid "Active" msgstr "アクティブ" @@ -2061,7 +2061,7 @@ msgid "Job audit log" msgstr "ジョブ監査ログ" #: audits/models.py:51 audits/models.py:95 audits/models.py:166 -#: terminal/models/session/session.py:38 terminal/models/session/sharing.py:107 +#: terminal/models/session/session.py:38 terminal/models/session/sharing.py:105 msgid "Remote addr" msgstr "リモートaddr" @@ -2078,8 +2078,8 @@ msgid "File" msgstr "書類" #: audits/models.py:62 terminal/backends/command/models.py:21 -#: terminal/models/session/replay.py:9 terminal/models/session/sharing.py:21 -#: terminal/models/session/sharing.py:89 +#: terminal/models/session/replay.py:9 terminal/models/session/sharing.py:19 +#: terminal/models/session/sharing.py:87 #: terminal/templates/terminal/_msg_command_alert.html:10 #: terminal/templates/terminal/_msg_command_warning.html:17 #: tickets/models/ticket/command_confirm.py:15 @@ -2940,7 +2940,7 @@ msgid "request new one" msgstr "新しいものを要求する" #: authentication/templates/authentication/_msg_reset_password_code.html:12 -#: terminal/models/session/sharing.py:28 terminal/models/session/sharing.py:91 +#: terminal/models/session/sharing.py:26 terminal/models/session/sharing.py:89 #: terminal/templates/terminal/_msg_session_sharing.html:12 #: users/forms/profile.py:107 users/templates/users/forgot_password.html:66 msgid "Verify code" @@ -3689,7 +3689,7 @@ msgstr "アルグ" #: ops/models/adhoc.py:25 ops/models/base.py:16 ops/models/base.py:53 #: ops/models/job.py:106 ops/models/job.py:192 ops/models/playbook.py:25 -#: terminal/models/session/sharing.py:26 +#: terminal/models/session/sharing.py:24 msgid "Creator" msgstr "作成者" @@ -3730,7 +3730,7 @@ msgstr "タスクモニターを表示できます" msgid "Kwargs" msgstr "クワーグ" -#: ops/models/celery.py:61 terminal/models/session/sharing.py:122 +#: ops/models/celery.py:61 terminal/models/session/sharing.py:120 #: tickets/const.py:25 msgid "Finished" msgstr "終了" @@ -6000,7 +6000,7 @@ msgstr "セッション再生をダウンロードできます" msgid "Account id" msgstr "アカウント ID" -#: terminal/models/session/session.py:36 terminal/models/session/sharing.py:112 +#: terminal/models/session/session.py:36 terminal/models/session/sharing.py:110 msgid "Login from" msgstr "ログイン元" @@ -6032,61 +6032,61 @@ msgstr "セッションを終了できます" msgid "Can validate session action perm" msgstr "セッションアクションのパーマを検証できます" -#: terminal/models/session/sharing.py:33 +#: terminal/models/session/sharing.py:31 msgid "Expired time (min)" msgstr "期限切れ時間 (分)" -#: terminal/models/session/sharing.py:37 terminal/serializers/sharing.py:20 +#: terminal/models/session/sharing.py:35 terminal/serializers/sharing.py:20 #: terminal/serializers/sharing.py:52 msgid "Action permission" msgstr "アクションパーミッション" -#: terminal/models/session/sharing.py:39 +#: terminal/models/session/sharing.py:37 msgid "Origin" -msgstr "" +msgstr "ソース" -#: terminal/models/session/sharing.py:43 terminal/models/session/sharing.py:94 +#: terminal/models/session/sharing.py:41 terminal/models/session/sharing.py:92 #: terminal/notifications.py:261 msgid "Session sharing" msgstr "セッション共有" -#: terminal/models/session/sharing.py:45 +#: terminal/models/session/sharing.py:43 msgid "Can add super session sharing" msgstr "スーパーセッション共有を追加できます" -#: terminal/models/session/sharing.py:77 +#: terminal/models/session/sharing.py:75 msgid "Link not active" msgstr "リンクがアクティブでない" -#: terminal/models/session/sharing.py:79 +#: terminal/models/session/sharing.py:77 msgid "Link expired" msgstr "リンク期限切れ" -#: terminal/models/session/sharing.py:81 +#: terminal/models/session/sharing.py:79 msgid "User not allowed to join" msgstr "ユーザーはセッションに参加できません" -#: terminal/models/session/sharing.py:98 terminal/serializers/sharing.py:71 +#: terminal/models/session/sharing.py:96 terminal/serializers/sharing.py:71 msgid "Joiner" msgstr "ジョイナー" -#: terminal/models/session/sharing.py:101 +#: terminal/models/session/sharing.py:99 msgid "Date joined" msgstr "参加日" -#: terminal/models/session/sharing.py:104 +#: terminal/models/session/sharing.py:102 msgid "Date left" msgstr "日付が残っています" -#: terminal/models/session/sharing.py:127 +#: terminal/models/session/sharing.py:125 msgid "Session join record" msgstr "セッション参加記録" -#: terminal/models/session/sharing.py:143 +#: terminal/models/session/sharing.py:141 msgid "Invalid verification code" msgstr "検証コードが無効" -#: terminal/models/session/sharing.py:150 +#: terminal/models/session/sharing.py:148 msgid "You have already joined this session" msgstr "すでにこのセッションに参加しています" diff --git a/apps/locale/zh/LC_MESSAGES/django.po b/apps/locale/zh/LC_MESSAGES/django.po index 1ee0dc26f..ff4a4c2c3 100644 --- a/apps/locale/zh/LC_MESSAGES/django.po +++ b/apps/locale/zh/LC_MESSAGES/django.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: JumpServer 0.3.3\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2023-07-26 19:14+0800\n" +"POT-Creation-Date: 2023-07-27 11:11+0800\n" "PO-Revision-Date: 2021-05-20 10:54+0800\n" "Last-Translator: ibuler \n" "Language-Team: JumpServer team\n" @@ -315,7 +315,7 @@ msgid "Trigger mode" msgstr "触发模式" #: accounts/models/automations/backup_account.py:97 audits/models.py:194 -#: terminal/models/session/sharing.py:119 xpack/plugins/cloud/models.py:168 +#: terminal/models/session/sharing.py:117 xpack/plugins/cloud/models.py:168 msgid "Reason" msgstr "原因" @@ -653,7 +653,7 @@ msgstr "ID" #: perms/api/user_permission/mixin.py:55 perms/models/asset_permission.py:58 #: perms/serializers/permission.py:30 rbac/builtin.py:123 #: rbac/models/rolebinding.py:49 terminal/backends/command/models.py:16 -#: terminal/models/session/session.py:29 terminal/models/session/sharing.py:35 +#: terminal/models/session/session.py:29 terminal/models/session/sharing.py:33 #: terminal/notifications.py:156 terminal/notifications.py:205 #: terminal/serializers/command.py:16 #: terminal/templates/terminal/_msg_command_warning.html:6 @@ -744,7 +744,7 @@ msgstr "自动化任务执行历史" #: accounts/serializers/automations/change_secret.py:155 audits/const.py:53 #: audits/models.py:59 audits/signal_handlers/activity_log.py:33 #: common/const/choices.py:18 ops/const.py:56 ops/serializers/celery.py:40 -#: terminal/const.py:76 terminal/models/session/sharing.py:115 +#: terminal/const.py:76 terminal/models/session/sharing.py:113 #: tickets/views/approve.py:115 msgid "Success" msgstr "成功" @@ -828,7 +828,7 @@ msgstr "审批人" #: acls/models/base.py:43 authentication/models/access_key.py:17 #: authentication/models/connection_token.py:53 #: authentication/templates/authentication/_access_key_modal.html:32 -#: perms/models/asset_permission.py:76 terminal/models/session/sharing.py:30 +#: perms/models/asset_permission.py:76 terminal/models/session/sharing.py:28 #: tickets/const.py:37 msgid "Active" msgstr "激活中" @@ -2045,7 +2045,7 @@ msgid "Job audit log" msgstr "作业审计日志" #: audits/models.py:51 audits/models.py:95 audits/models.py:166 -#: terminal/models/session/session.py:38 terminal/models/session/sharing.py:107 +#: terminal/models/session/session.py:38 terminal/models/session/sharing.py:105 msgid "Remote addr" msgstr "远端地址" @@ -2062,8 +2062,8 @@ msgid "File" msgstr "文件" #: audits/models.py:62 terminal/backends/command/models.py:21 -#: terminal/models/session/replay.py:9 terminal/models/session/sharing.py:21 -#: terminal/models/session/sharing.py:89 +#: terminal/models/session/replay.py:9 terminal/models/session/sharing.py:19 +#: terminal/models/session/sharing.py:87 #: terminal/templates/terminal/_msg_command_alert.html:10 #: terminal/templates/terminal/_msg_command_warning.html:17 #: tickets/models/ticket/command_confirm.py:15 @@ -2904,7 +2904,7 @@ msgid "request new one" msgstr "重新申请" #: authentication/templates/authentication/_msg_reset_password_code.html:12 -#: terminal/models/session/sharing.py:28 terminal/models/session/sharing.py:91 +#: terminal/models/session/sharing.py:26 terminal/models/session/sharing.py:89 #: terminal/templates/terminal/_msg_session_sharing.html:12 #: users/forms/profile.py:107 users/templates/users/forgot_password.html:66 msgid "Verify code" @@ -3642,7 +3642,7 @@ msgstr "参数" #: ops/models/adhoc.py:25 ops/models/base.py:16 ops/models/base.py:53 #: ops/models/job.py:106 ops/models/job.py:192 ops/models/playbook.py:25 -#: terminal/models/session/sharing.py:26 +#: terminal/models/session/sharing.py:24 msgid "Creator" msgstr "创建者" @@ -3683,7 +3683,7 @@ msgstr "可以查看任务监控" msgid "Kwargs" msgstr "其它参数" -#: ops/models/celery.py:61 terminal/models/session/sharing.py:122 +#: ops/models/celery.py:61 terminal/models/session/sharing.py:120 #: tickets/const.py:25 msgid "Finished" msgstr "结束" @@ -5913,7 +5913,7 @@ msgstr "可以下载会话录像" msgid "Account id" msgstr "账号 ID" -#: terminal/models/session/session.py:36 terminal/models/session/sharing.py:112 +#: terminal/models/session/session.py:36 terminal/models/session/sharing.py:110 msgid "Login from" msgstr "登录来源" @@ -5945,61 +5945,61 @@ msgstr "可以终断会话" msgid "Can validate session action perm" msgstr "可以验证会话动作权限" -#: terminal/models/session/sharing.py:33 +#: terminal/models/session/sharing.py:31 msgid "Expired time (min)" msgstr "过期时间 (分)" -#: terminal/models/session/sharing.py:37 terminal/serializers/sharing.py:20 +#: terminal/models/session/sharing.py:35 terminal/serializers/sharing.py:20 #: terminal/serializers/sharing.py:52 msgid "Action permission" msgstr "操作权限" -#: terminal/models/session/sharing.py:39 +#: terminal/models/session/sharing.py:37 msgid "Origin" -msgstr "" +msgstr "来源" -#: terminal/models/session/sharing.py:43 terminal/models/session/sharing.py:94 +#: terminal/models/session/sharing.py:41 terminal/models/session/sharing.py:92 #: terminal/notifications.py:261 msgid "Session sharing" msgstr "会话分享" -#: terminal/models/session/sharing.py:45 +#: terminal/models/session/sharing.py:43 msgid "Can add super session sharing" msgstr "可以创建超级会话分享" -#: terminal/models/session/sharing.py:77 +#: terminal/models/session/sharing.py:75 msgid "Link not active" msgstr "链接失效" -#: terminal/models/session/sharing.py:79 +#: terminal/models/session/sharing.py:77 msgid "Link expired" msgstr "链接过期" -#: terminal/models/session/sharing.py:81 +#: terminal/models/session/sharing.py:79 msgid "User not allowed to join" msgstr "该用户无权加入会话" -#: terminal/models/session/sharing.py:98 terminal/serializers/sharing.py:71 +#: terminal/models/session/sharing.py:96 terminal/serializers/sharing.py:71 msgid "Joiner" msgstr "加入者" -#: terminal/models/session/sharing.py:101 +#: terminal/models/session/sharing.py:99 msgid "Date joined" msgstr "加入日期" -#: terminal/models/session/sharing.py:104 +#: terminal/models/session/sharing.py:102 msgid "Date left" msgstr "结束日期" -#: terminal/models/session/sharing.py:127 +#: terminal/models/session/sharing.py:125 msgid "Session join record" msgstr "会话加入记录" -#: terminal/models/session/sharing.py:143 +#: terminal/models/session/sharing.py:141 msgid "Invalid verification code" msgstr "验证码不正确" -#: terminal/models/session/sharing.py:150 +#: terminal/models/session/sharing.py:148 msgid "You have already joined this session" msgstr "您已经加入过此会话" diff --git a/apps/terminal/models/session/sharing.py b/apps/terminal/models/session/sharing.py index e2ef06a5f..92a75f9c4 100644 --- a/apps/terminal/models/session/sharing.py +++ b/apps/terminal/models/session/sharing.py @@ -46,6 +46,10 @@ class SessionSharing(JMSBaseModel, OrgModelMixin): def __str__(self): return 'Creator: {}'.format(self.creator) + @cached_property + def url(self): + return '%s/koko/share/%s/' % (self.origin, self.id) + @cached_property def users_display(self): if not self.users: diff --git a/apps/terminal/notifications.py b/apps/terminal/notifications.py index a09f8ccb1..0d2501450 100644 --- a/apps/terminal/notifications.py +++ b/apps/terminal/notifications.py @@ -270,7 +270,7 @@ class SessionSharingMessage(UserMessage): 'asset': instance.session.asset, 'created_by': instance.created_by, 'account': instance.session.account, - 'session_url': '%s/koko/share/%s/' % (instance.origin, instance.id), + 'url': instance.url, 'verify_code': instance.verify_code, 'org': instance.org_name, } diff --git a/apps/terminal/serializers/sharing.py b/apps/terminal/serializers/sharing.py index 42d74318b..c891a70b5 100644 --- a/apps/terminal/serializers/sharing.py +++ b/apps/terminal/serializers/sharing.py @@ -26,7 +26,7 @@ class SessionSharingSerializer(OrgResourceModelSerializerMixin): fields_small = fields_mini + [ 'verify_code', 'is_active', 'expired_time', 'created_by', 'date_created', 'date_updated', 'users', 'users_display', - 'action_permission', 'origin', + 'action_permission', 'origin', 'url', ] fields_fk = ['session', 'creator'] fields = fields_small + fields_fk diff --git a/apps/terminal/templates/terminal/_msg_session_sharing.html b/apps/terminal/templates/terminal/_msg_session_sharing.html index b28129900..d634304e5 100644 --- a/apps/terminal/templates/terminal/_msg_session_sharing.html +++ b/apps/terminal/templates/terminal/_msg_session_sharing.html @@ -7,7 +7,7 @@
{% trans 'Account' %}: {{ account }}
- {% trans 'Session sharing URL' %}: {% trans 'View' %} + {% trans 'Session sharing URL' %}: {% trans 'View' %}
{% trans 'Verify code' %}: {{ verify_code }}
From 1907c795c31b8ab0798bf0286b32ee2572c22f87 Mon Sep 17 00:00:00 2001 From: jiangweidong Date: Fri, 28 Jul 2023 10:40:48 +0800 Subject: [PATCH 4/4] =?UTF-8?q?feat:=20=E7=B3=BB=E7=BB=9F=E5=B7=A5?= =?UTF-8?q?=E5=85=B7=E5=A2=9E=E5=8A=A0=E6=9C=8D=E5=8A=A1=E5=99=A8=E6=97=B6?= =?UTF-8?q?=E9=97=B4=E5=8F=8Anmap=E5=B7=A5=E5=85=B7=20(#11078)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/settings/api/public.py | 13 ++++++- apps/settings/serializers/public.py | 8 +++- apps/settings/urls/api_urls.py | 1 + apps/settings/utils/__init__.py | 3 +- apps/settings/utils/nmap.py | 60 +++++++++++++++++++++++++++++ apps/settings/utils/ping.py | 17 +++++--- apps/settings/utils/telnet.py | 10 ++--- apps/settings/ws.py | 31 +++++++-------- 8 files changed, 115 insertions(+), 28 deletions(-) create mode 100644 apps/settings/utils/nmap.py diff --git a/apps/settings/api/public.py b/apps/settings/api/public.py index ab313cd4f..f2628a5d4 100644 --- a/apps/settings/api/public.py +++ b/apps/settings/api/public.py @@ -4,13 +4,14 @@ from rest_framework.permissions import AllowAny from common.permissions import IsValidUserOrConnectionToken from common.utils import get_logger, lazyproperty +from common.utils.timezone import local_now from jumpserver.utils import has_valid_xpack_license, get_xpack_license_info from .. import serializers from ..utils import get_interface_setting_or_default logger = get_logger(__name__) -__all__ = ['PublicSettingApi', 'OpenPublicSettingApi'] +__all__ = ['PublicSettingApi', 'OpenPublicSettingApi', 'ServerInfoApi'] class OpenPublicSettingApi(generics.RetrieveAPIView): @@ -55,3 +56,13 @@ class PublicSettingApi(OpenPublicSettingApi): # 提前把异常爆出来 values[name] = getattr(settings, name) return values + + +class ServerInfoApi(generics.RetrieveAPIView): + permission_classes = (IsValidUserOrConnectionToken,) + serializer_class = serializers.ServerInfoSerializer + + def get_object(self): + return { + "CURRENT_TIME": local_now(), + } diff --git a/apps/settings/serializers/public.py b/apps/settings/serializers/public.py index 8429ccd48..3d61bd98c 100644 --- a/apps/settings/serializers/public.py +++ b/apps/settings/serializers/public.py @@ -3,7 +3,9 @@ from rest_framework import serializers -__all__ = ['PublicSettingSerializer', 'PrivateSettingSerializer'] +__all__ = [ + 'PublicSettingSerializer', 'PrivateSettingSerializer', 'ServerInfoSerializer' +] class PublicSettingSerializer(serializers.Serializer): @@ -50,3 +52,7 @@ class PrivateSettingSerializer(PublicSettingSerializer): TICKETS_ENABLED = serializers.BooleanField() CONNECTION_TOKEN_REUSABLE = serializers.BooleanField() + + +class ServerInfoSerializer(serializers.Serializer): + CURRENT_TIME = serializers.DateTimeField() diff --git a/apps/settings/urls/api_urls.py b/apps/settings/urls/api_urls.py index 5cfc3bb36..ef94d02ba 100644 --- a/apps/settings/urls/api_urls.py +++ b/apps/settings/urls/api_urls.py @@ -23,4 +23,5 @@ urlpatterns = [ path('logo/', api.SettingsLogoApi.as_view(), name='settings-logo'), path('public/', api.PublicSettingApi.as_view(), name='public-setting'), path('public/open/', api.OpenPublicSettingApi.as_view(), name='open-public-setting'), + path('server-info/', api.ServerInfoApi.as_view(), name='server-info'), ] diff --git a/apps/settings/utils/__init__.py b/apps/settings/utils/__init__.py index 0927bde18..8983df3ad 100644 --- a/apps/settings/utils/__init__.py +++ b/apps/settings/utils/__init__.py @@ -1,7 +1,8 @@ # coding: utf-8 -# +# from .ldap import * from .common import * from .ping import * from .telnet import * +from .nmap import * diff --git a/apps/settings/utils/nmap.py b/apps/settings/utils/nmap.py new file mode 100644 index 000000000..6e4282678 --- /dev/null +++ b/apps/settings/utils/nmap.py @@ -0,0 +1,60 @@ +import time +import nmap + +from IPy import IP + +from common.utils.timezone import local_now_display + + +def generate_ips(ip_string): + # 支持的格式 + # 192.168.1.1-12 | 192.168.1.1-192.168.1.12 | 192.168.1.0/30 | 192.168.1.1 + ip_list = ip_string.split('-') + ips = [] + try: + if len(ip_list) == 2: + start_ip, end_ip = ip_list + if ip_list[1].find('.') == -1: + end_ip = start_ip[:start_ip.rindex('.') + 1] + end_ip + for ip in range(IP(start_ip).int(), IP(end_ip).int() + 1): + ips.extend(IP(ip)) + else: + ips.extend(IP(ip_list[0])) + except Exception: + ips = [] + return ips + + +def once_nmap(nm, ip, ports, timeout, display): + nmap_version = '.'.join(map(lambda x: str(x), nm.nmap_version())) + display(f'Starting Nmap {nmap_version} at {local_now_display()} for {ip}') + try: + is_ok = True + nm.scan(ip, arguments='-sS -sU -F', ports=ports, timeout=timeout) + tcp_port = nm[ip].get('tcp', {}) + udp_port = nm[ip].get('udp', {}) + display(f'PORT\tSTATE\tSERVICE') + for port, info in tcp_port.items(): + display(f"{port}\t{info.get('state', 'unknown')}\t{info.get('name', 'unknown')}") + for port, info in udp_port.items(): + display(f"{port}\t{info.get('state', 'unknown')}\t{info.get('name', 'unknown')}") + except Exception: + is_ok = False + display(f'Nmap scan report for {ip} error.') + return is_ok + + +def verbose_nmap(dest_ip, dest_port=None, timeout=None, display=print): + dest_port = ','.join(list(dest_port)) if dest_port else None + + ips = generate_ips(dest_ip) + nm = nmap.PortScanner() + success_num, start_time = 0, time.time() + display(f'[Summary] Nmap: {len(ips)} IP addresses were scanned') + for ip in ips: + ok = once_nmap(nm, str(ip), dest_port, timeout, display) + if ok: + success_num += 1 + display('') + display(f'[Done] Nmap: {len(ips)} IP addresses ({success_num} hosts up) ' + f'scanned in {round(time.time() - start_time, 2)} seconds') diff --git a/apps/settings/utils/ping.py b/apps/settings/utils/ping.py index 7b4f0a2a4..cb9e5e544 100644 --- a/apps/settings/utils/ping.py +++ b/apps/settings/utils/ping.py @@ -128,30 +128,37 @@ def ping(dest_addr, timeout, psize, flag=0): return delay -def verbose_ping(dest_addr, timeout=2, count=5, psize=64, display=None): +def verbose_ping(dest_ip, timeout=2, count=5, psize=64, display=None): """ Send `count' ping with `psize' size to `dest_addr' with the given `timeout' and display the result. """ - ip = lookup_domain(dest_addr) + ip = lookup_domain(dest_ip) if not ip: return if display is None: display = print - display("PING %s (%s): 56 data bytes" % (dest_addr, ip)) + error_count = 0 + display("PING %s (%s): 56 data bytes" % (dest_ip, ip)) for i in range(count): try: - delay = ping(dest_addr, timeout, psize) + delay = ping(dest_ip, timeout, psize) except socket.gaierror as e: display("failed. (socket error: '%s')" % str(e)) + error_count += 1 break if delay is None: display("Request timeout for icmp_seq %i" % i) + error_count += 1 else: - delay = delay * 1000 + delay *= 1000 display("64 bytes from %s: icmp_seq=0 ttl=115 time=%.3f ms" % (ip, delay)) time.sleep(1) + display(f'--- {dest_ip} ping statistics ---') + display(f'{count} packets transmitted, ' + f'{count - error_count} packets received, ' + f'{(error_count / count) * 100}% packet loss') print() diff --git a/apps/settings/utils/telnet.py b/apps/settings/utils/telnet.py index 22a1cf619..9cb0a2c0b 100644 --- a/apps/settings/utils/telnet.py +++ b/apps/settings/utils/telnet.py @@ -18,21 +18,21 @@ def telnet(dest_addr, port_number=23, timeout=10): return True, output.decode('utf-8', 'ignore') -def verbose_telnet(dest_addr, port_number=23, timeout=10, display=None): +def verbose_telnet(dest_ip, dest_port=23, timeout=10, display=None): if display is None: display = print - ip = lookup_domain(dest_addr) + ip = lookup_domain(dest_ip) if not ip: return - msg = 'Trying %s (%s:%s)' % (dest_addr, ip, port_number) + msg = 'Trying %s (%s:%s)' % (dest_ip, ip, dest_port) display(msg) try: - is_connective, resp = telnet(dest_addr, port_number, timeout) + is_connective, resp = telnet(dest_ip, dest_port, timeout) if is_connective: template = 'Connected to {0} {1}.\r\n{2}Connection closed by foreign host.' else: template = 'telnet: connect to {0} {1} {2}\r\ntelnet: Unable to connect to remote host' - msg = template.format(dest_addr, port_number, resp) + msg = template.format(dest_ip, dest_port, resp) except Exception as e: msg = 'Error: %s' % e display(msg) diff --git a/apps/settings/ws.py b/apps/settings/ws.py index 9e248536f..f5752e2a1 100644 --- a/apps/settings/ws.py +++ b/apps/settings/ws.py @@ -7,7 +7,7 @@ from channels.generic.websocket import JsonWebsocketConsumer from common.db.utils import close_old_connections from common.utils import get_logger -from .utils import verbose_ping, verbose_telnet +from .utils import verbose_ping, verbose_telnet, verbose_nmap logger = get_logger(__name__) @@ -24,27 +24,28 @@ class ToolsWebsocket(JsonWebsocketConsumer): def send_msg(self, msg): self.send_json({'msg': msg + '\r\n'}) - def imitate_ping(self, dest_addr, timeout=3, count=5, psize=64): + def imitate_ping(self, dest_ip, timeout=3, count=5, psize=64): """ - Send `count' ping with `psize' size to `dest_addr' with + Send `count' ping with `psize' size to `dest_ip' with the given `timeout' and display the result. """ - logger.info('receive request ping {}'.format(dest_addr)) - verbose_ping(dest_addr, timeout, count, psize, display=self.send_msg) + logger.info('receive request ping {}'.format(dest_ip)) + verbose_ping(dest_ip, timeout, count, psize, display=self.send_msg) - def imitate_telnet(self, dest_addr, port_num=23, timeout=10): - logger.info('receive request telnet {}'.format(dest_addr)) - verbose_telnet(dest_addr, port_num, timeout, display=self.send_msg) + def imitate_telnet(self, dest_ip, dest_port=23, timeout=10): + logger.info('receive request telnet {}'.format(dest_ip)) + verbose_telnet(dest_ip, dest_port, timeout, display=self.send_msg) + + def imitate_nmap(self, dest_ip, dest_port=None, timeout=None): + logger.info('receive request nmap {}'.format(dest_ip)) + verbose_nmap(dest_ip, dest_port, timeout, display=self.send_msg) def receive(self, text_data=None, bytes_data=None, **kwargs): data = json.loads(text_data) - tool_type = data.get('tool_type', 'Ping') - dest_addr = data.get('dest_addr') - if tool_type == 'Ping': - self.imitate_ping(dest_addr) - else: - port_num = data.get('port_num') - self.imitate_telnet(dest_addr, port_num) + tool_type = data.pop('tool_type', 'Ping') + + tool_func = getattr(self, f'imitate_{tool_type.lower()}') + tool_func(**data) self.close() def disconnect(self, code):