cmdbox 0.5.1.2__py3-none-any.whl → 0.5.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of cmdbox might be problematic. Click here for more details.
- cmdbox/app/app.py +4 -2
- cmdbox/app/auth/signin.py +634 -631
- cmdbox/app/client.py +10 -10
- cmdbox/app/common.py +50 -6
- cmdbox/app/commons/convert.py +9 -0
- cmdbox/app/commons/module.py +113 -113
- cmdbox/app/commons/redis_client.py +40 -29
- cmdbox/app/edge.py +4 -4
- cmdbox/app/features/cli/audit_base.py +138 -0
- cmdbox/app/features/cli/cmdbox_audit_createdb.py +224 -0
- cmdbox/app/features/cli/cmdbox_audit_delete.py +308 -0
- cmdbox/app/features/cli/cmdbox_audit_search.py +416 -0
- cmdbox/app/features/cli/cmdbox_audit_write.py +247 -0
- cmdbox/app/features/cli/cmdbox_client_file_copy.py +207 -207
- cmdbox/app/features/cli/cmdbox_client_file_download.py +207 -207
- cmdbox/app/features/cli/cmdbox_client_file_list.py +193 -193
- cmdbox/app/features/cli/cmdbox_client_file_mkdir.py +191 -191
- cmdbox/app/features/cli/cmdbox_client_file_move.py +199 -199
- cmdbox/app/features/cli/cmdbox_client_file_remove.py +190 -190
- cmdbox/app/features/cli/cmdbox_client_file_rmdir.py +190 -190
- cmdbox/app/features/cli/cmdbox_client_file_upload.py +212 -212
- cmdbox/app/features/cli/cmdbox_client_server_info.py +166 -166
- cmdbox/app/features/cli/cmdbox_server_list.py +88 -88
- cmdbox/app/features/cli/cmdbox_server_stop.py +138 -138
- cmdbox/app/features/web/cmdbox_web_audit.py +81 -0
- cmdbox/app/features/web/cmdbox_web_audit_metrics.py +72 -0
- cmdbox/app/features/web/cmdbox_web_del_cmd.py +2 -0
- cmdbox/app/features/web/cmdbox_web_del_pipe.py +1 -0
- cmdbox/app/features/web/cmdbox_web_do_signin.py +12 -2
- cmdbox/app/features/web/cmdbox_web_do_signout.py +1 -0
- cmdbox/app/features/web/cmdbox_web_exec_cmd.py +31 -2
- cmdbox/app/features/web/cmdbox_web_exec_pipe.py +1 -0
- cmdbox/app/features/web/cmdbox_web_filer download.py +43 -42
- cmdbox/app/features/web/cmdbox_web_filer.py +1 -0
- cmdbox/app/features/web/cmdbox_web_filer_upload.py +65 -64
- cmdbox/app/features/web/cmdbox_web_gui.py +166 -165
- cmdbox/app/features/web/cmdbox_web_load_pin.py +43 -43
- cmdbox/app/features/web/cmdbox_web_raw_pipe.py +87 -87
- cmdbox/app/features/web/cmdbox_web_save_cmd.py +1 -0
- cmdbox/app/features/web/cmdbox_web_save_pin.py +42 -42
- cmdbox/app/features/web/cmdbox_web_save_pipe.py +1 -0
- cmdbox/app/features/web/cmdbox_web_user_data.py +58 -0
- cmdbox/app/features/web/cmdbox_web_users.py +12 -0
- cmdbox/app/options.py +788 -601
- cmdbox/app/web.py +7 -1
- cmdbox/extensions/features.yml +23 -0
- cmdbox/extensions/sample_project/sample/app/features/cli/sample_client_time.py +82 -82
- cmdbox/extensions/sample_project/sample/app/features/cli/sample_server_time.py +145 -145
- cmdbox/extensions/user_list.yml +5 -0
- cmdbox/licenses/{LICENSE.Sphinx.8.1.3(BSD License).txt → LICENSE.Sphinx.8.2.3(UNKNOWN).txt} +1 -1
- cmdbox/licenses/LICENSE.argcomplete.3.6.2(Apache Software License).txt +177 -0
- cmdbox/licenses/{LICENSE.babel.2.16.0(BSD License).txt → LICENSE.babel.2.17.0(BSD License).txt } +1 -1
- cmdbox/licenses/{LICENSE.pkginfo.1.10.0(MIT License).txt → LICENSE.charset-normalizer.3.4.1(MIT License).txt } +1 -1
- cmdbox/licenses/LICENSE.gevent.25.4.1(MIT).txt +25 -0
- cmdbox/licenses/LICENSE.greenlet.3.2.0(MIT AND Python-2.0).txt +30 -0
- cmdbox/licenses/LICENSE.gunicorn.23.0.0(MIT License).txt +23 -0
- cmdbox/licenses/LICENSE.importlib_metadata.8.6.1(Apache Software License).txt +202 -0
- cmdbox/licenses/LICENSE.nh3.0.2.21(MIT).txt +21 -0
- cmdbox/licenses/{LICENSE.pillow.11.0.0(CMU License (MIT-CMU)).txt → LICENSE.pillow.11.1.0(CMU License (MIT-CMU)).txt } +27 -40
- cmdbox/licenses/LICENSE.pillow.11.2.1(UNKNOWN).txt +1200 -0
- cmdbox/licenses/LICENSE.plyer.2.1.0(MIT License).txt +19 -0
- cmdbox/licenses/LICENSE.prompt_toolkit.3.0.50(BSD License).txt +27 -0
- cmdbox/licenses/LICENSE.prompt_toolkit.3.0.51(BSD License).txt +27 -0
- cmdbox/licenses/LICENSE.psycopg-binary.3.2.6(GNU Lesser General Public License v3 (LGPLv3)).txt +165 -0
- cmdbox/licenses/LICENSE.psycopg-pool.3.2.6(GNU Lesser General Public License v3 (LGPLv3)).txt +165 -0
- cmdbox/licenses/LICENSE.psycopg.3.2.6(GNU Lesser General Public License v3 (LGPLv3)).txt +165 -0
- cmdbox/licenses/LICENSE.pycryptodome.3.22.0(BSD License; Public Domain).txt +61 -0
- cmdbox/licenses/LICENSE.pydantic.2.11.3(MIT License).txt +21 -0
- cmdbox/licenses/LICENSE.pydantic_core.2.33.1(MIT License).txt +21 -0
- cmdbox/licenses/LICENSE.pystray.0.19.5(GNU Lesser General Public License v3 (LGPLv3)).txt +674 -0
- cmdbox/licenses/LICENSE.questionary.2.1.0(MIT License).txt +19 -0
- cmdbox/licenses/LICENSE.roman-numerals-py.3.1.0(CC0 1.0 Universal (CC0 1.0) Public Domain Dedication; Zero-Clause BSD (0BSD)).txt +146 -0
- cmdbox/licenses/{LICENSE.six.1.16.0(MIT License).txt → LICENSE.six.1.17.0(MIT License).txt } +1 -1
- cmdbox/licenses/LICENSE.starlette.0.46.2(BSD License).txt +27 -0
- cmdbox/licenses/{LICENSE.charset-normalizer.3.4.0(MIT License).txt → LICENSE.typing-inspection.0.4.0(MIT License).txt } +2 -2
- cmdbox/licenses/LICENSE.typing_extensions.4.13.2(UNKNOWN).txt +279 -0
- cmdbox/licenses/LICENSE.tzdata.2025.2(Apache Software License).txt +15 -0
- cmdbox/licenses/LICENSE.urllib3.2.4.0(UNKNOWN).txt +21 -0
- cmdbox/licenses/LICENSE.uvicorn.0.34.1(BSD License).txt +27 -0
- cmdbox/licenses/LICENSE.watchfiles.1.0.5(MIT License).txt +21 -0
- cmdbox/licenses/files.txt +49 -38
- cmdbox/logconf_audit.yml +30 -0
- cmdbox/logconf_cmdbox.yml +30 -0
- cmdbox/version.py +2 -2
- cmdbox/web/assets/apexcharts/apexcharts.css +679 -0
- cmdbox/web/assets/apexcharts/apexcharts.min.js +38 -0
- cmdbox/web/assets/cmdbox/audit.js +340 -0
- cmdbox/web/assets/cmdbox/color_mode.css +520 -0
- cmdbox/web/assets/cmdbox/common.js +416 -24
- cmdbox/web/assets/cmdbox/filer_modal.js +1 -1
- cmdbox/web/assets/cmdbox/list_cmd.js +10 -275
- cmdbox/web/assets/cmdbox/list_pipe.js +3 -3
- cmdbox/web/assets/cmdbox/main.js +2 -2
- cmdbox/web/assets/cmdbox/result.js +2 -2
- cmdbox/web/assets/cmdbox/signin.js +2 -2
- cmdbox/web/assets/cmdbox/users.js +19 -20
- cmdbox/web/assets/cmdbox/view_raw.js +1 -1
- cmdbox/web/assets/cmdbox/view_result.js +11 -13
- cmdbox/web/assets/filer/filer.js +2 -2
- cmdbox/web/assets/filer/main.js +2 -2
- cmdbox/web/assets_license_list.txt +4 -1
- cmdbox/web/audit.html +268 -0
- cmdbox/web/filer.html +37 -12
- cmdbox/web/gui.html +36 -53
- cmdbox/web/result.html +24 -3
- cmdbox/web/signin.html +35 -14
- cmdbox/web/users.html +21 -3
- {cmdbox-0.5.1.2.dist-info → cmdbox-0.5.3.dist-info}/METADATA +28 -5
- {cmdbox-0.5.1.2.dist-info → cmdbox-0.5.3.dist-info}/RECORD +142 -103
- {cmdbox-0.5.1.2.dist-info → cmdbox-0.5.3.dist-info}/entry_points.txt +0 -1
- cmdbox/licenses/LICENSE.nh3.0.2.18(MIT).txt +0 -1
- /cmdbox/licenses/{LICENSE.Jinja2.3.1.4(BSD License).txt → LICENSE.Jinja2.3.1.6(BSD License).txt} +0 -0
- /cmdbox/licenses/{LICENSE.Pygments.2.18.0(BSD License).txt → LICENSE.Pygments.2.19.1(BSD License).txt} +0 -0
- /cmdbox/licenses/{LICENSE.anyio.4.6.2.post1(MIT License).txt → LICENSE.anyio.4.9.0(MIT License).txt} +0 -0
- /cmdbox/licenses/{LICENSE.argcomplete.3.5.1(Apache Software License).txt → LICENSE.argcomplete.3.6.1(Apache Software License).txt} +0 -0
- /cmdbox/licenses/{LICENSE.certifi.2024.8.30(Mozilla Public License 2.0 (MPL 2.0)).txt → LICENSE.certifi.2025.1.31(Mozilla Public License 2.0 (MPL 2.0)).txt} +0 -0
- /cmdbox/licenses/{LICENSE.click.8.1.7(BSD License).txt → LICENSE.click.8.1.8(BSD License).txt} +0 -0
- /cmdbox/licenses/{LICENSE.cryptography.43.0.3(Apache Software License; BSD License).txt → LICENSE.cryptography.44.0.2(Apache Software License; BSD License).txt} +0 -0
- /cmdbox/licenses/{LICENSE.fastapi.0.115.5(MIT License).txt → LICENSE.fastapi.0.115.12(MIT License).txt} +0 -0
- /cmdbox/licenses/{LICENSE.importlib_metadata.8.5.0(Apache Software License).txt → LICENSE.id.1.5.0(Apache Software License).txt} +0 -0
- /cmdbox/licenses/{LICENSE.keyring.25.5.0(MIT License).txt → LICENSE.keyring.25.6.0(MIT License).txt} +0 -0
- /cmdbox/licenses/{LICENSE.more-itertools.10.5.0(MIT License).txt → LICENSE.more-itertools.10.6.0(MIT License).txt} +0 -0
- /cmdbox/licenses/{LICENSE.numpy.2.1.3(BSD License).txt → LICENSE.numpy.2.2.4(BSD License).txt} +0 -0
- /cmdbox/licenses/{LICENSE.prettytable.3.12.0(BSD License).txt → LICENSE.prettytable.3.16.0(UNKNOWN).txt} +0 -0
- /cmdbox/licenses/{LICENSE.pydantic.2.10.2(MIT License).txt → LICENSE.pydantic.2.11.1(MIT License).txt} +0 -0
- /cmdbox/licenses/{LICENSE.pydantic_core.2.27.1(MIT License).txt → LICENSE.pydantic_core.2.33.0(MIT License).txt} +0 -0
- /cmdbox/licenses/{LICENSE.python-dotenv.1.0.1(BSD License).txt → LICENSE.python-dotenv.1.1.0(BSD License).txt} +0 -0
- /cmdbox/licenses/{LICENSE.python-multipart.0.0.17(Apache Software License).txt → LICENSE.python-multipart.0.0.20(Apache Software License).txt} +0 -0
- /cmdbox/licenses/{LICENSE.redis.5.2.0(MIT License).txt → LICENSE.redis.5.2.1(MIT License).txt} +0 -0
- /cmdbox/licenses/{LICENSE.rich.13.9.4(MIT License).txt → LICENSE.rich.14.0.0(MIT License).txt} +0 -0
- /cmdbox/licenses/{LICENSE.sphinx-intl.2.3.0(BSD License).txt → LICENSE.sphinx-intl.2.3.1(BSD License).txt} +0 -0
- /cmdbox/licenses/{LICENSE.starlette.0.41.3(BSD License).txt → LICENSE.starlette.0.46.1(BSD License).txt} +0 -0
- /cmdbox/licenses/{LICENSE.tomli.2.1.0(MIT License).txt → LICENSE.tomli.2.2.1(MIT License).txt} +0 -0
- /cmdbox/licenses/{LICENSE.twine.5.1.1(Apache Software License).txt → LICENSE.twine.6.1.0(Apache Software License).txt} +0 -0
- /cmdbox/licenses/{LICENSE.typing_extensions.4.12.2(Python Software Foundation License).txt → LICENSE.typing_extensions.4.13.0(UNKNOWN).txt} +0 -0
- /cmdbox/licenses/{LICENSE.urllib3.2.2.3(MIT License).txt → LICENSE.urllib3.2.3.0(MIT License).txt} +0 -0
- /cmdbox/licenses/{LICENSE.uvicorn.0.32.1(BSD License).txt → LICENSE.uvicorn.0.34.0(BSD License).txt} +0 -0
- /cmdbox/licenses/{LICENSE.watchfiles.1.0.0(MIT License).txt → LICENSE.watchfiles.1.0.4(MIT License).txt} +0 -0
- /cmdbox/licenses/{LICENSE.websockets.14.1(BSD License).txt → LICENSE.websockets.15.0.1(BSD License).txt} +0 -0
- /cmdbox/licenses/{LICENSE.zope.interface.7.1.1(Zope Public License).txt → LICENSE.zope.interface.7.2(Zope Public License).txt} +0 -0
- {cmdbox-0.5.1.2.dist-info → cmdbox-0.5.3.dist-info}/LICENSE +0 -0
- {cmdbox-0.5.1.2.dist-info → cmdbox-0.5.3.dist-info}/WHEEL +0 -0
- {cmdbox-0.5.1.2.dist-info → cmdbox-0.5.3.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
from cmdbox.app import common, client
|
|
2
|
+
from cmdbox.app.commons import convert, redis_client
|
|
3
|
+
from cmdbox.app.features.cli import audit_base
|
|
4
|
+
from cmdbox.app.options import Options
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
from psycopg.rows import dict_row
|
|
7
|
+
from typing import Dict, Any, Tuple, List, Union
|
|
8
|
+
import argparse
|
|
9
|
+
import logging
|
|
10
|
+
import json
|
|
11
|
+
import sys
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class AuditDelete(audit_base.AuditBase):
|
|
15
|
+
def get_mode(self) -> Union[str, List[str]]:
|
|
16
|
+
"""
|
|
17
|
+
この機能のモードを返します
|
|
18
|
+
|
|
19
|
+
Returns:
|
|
20
|
+
Union[str, List[str]]: モード
|
|
21
|
+
"""
|
|
22
|
+
return 'audit'
|
|
23
|
+
|
|
24
|
+
def get_cmd(self):
|
|
25
|
+
"""
|
|
26
|
+
この機能のコマンドを返します
|
|
27
|
+
|
|
28
|
+
Returns:
|
|
29
|
+
str: コマンド
|
|
30
|
+
"""
|
|
31
|
+
return 'delete'
|
|
32
|
+
|
|
33
|
+
def get_option(self):
|
|
34
|
+
"""
|
|
35
|
+
この機能のオプションを返します
|
|
36
|
+
|
|
37
|
+
Returns:
|
|
38
|
+
Dict[str, Any]: オプション
|
|
39
|
+
"""
|
|
40
|
+
opt = super().get_option()
|
|
41
|
+
opt['discription_ja'] = "監査ログを削除します。"
|
|
42
|
+
opt['discription_en'] = "Delete the audit log."
|
|
43
|
+
opt['choice'] += [
|
|
44
|
+
dict(opt="delete_audit_type", type=Options.T_STR, default=None, required=False, multi=False, hide=False, choice=['']+Options.AUDITS,
|
|
45
|
+
discription_ja="削除条件の監査の種類を指定します。",
|
|
46
|
+
discription_en="Specifies the type of audit for the delete condition."),
|
|
47
|
+
dict(opt="delete_clmsg_id", type=Options.T_STR, default=None, required=False, multi=False, hide=False, choice=None,
|
|
48
|
+
discription_ja="削除条件のクライアントのメッセージIDを指定します。",
|
|
49
|
+
discription_en="Specify the message ID of the client for the delete condition."),
|
|
50
|
+
dict(opt="delete_clmsg_sdate", type=Options.T_DATETIME, default=None, required=False, multi=False, hide=False, choice=None,
|
|
51
|
+
discription_ja="削除条件のクライアントのメッセージ発生日時(開始)を指定します。",
|
|
52
|
+
discription_en="Specify the date and time (start) when the message occurred for the client in the delete condition."),
|
|
53
|
+
dict(opt="delete_clmsg_edate", type=Options.T_DATETIME, default=None, required=False, multi=False, hide=False, choice=None,
|
|
54
|
+
discription_ja="削除条件のクライアントのメッセージ発生日時(終了)を指定します。",
|
|
55
|
+
discription_en="Specify the date and time (end) when the message occurred for the client in the delete condition."),
|
|
56
|
+
dict(opt="delete_clmsg_src", type=Options.T_STR, default=None, required=False, multi=False, hide=False, choice=None,
|
|
57
|
+
discription_ja="削除条件のクライアントのメッセージの発生源を指定します。LIKE検索を行います。",
|
|
58
|
+
discription_en="Specifies the source of the message for the client in the delete condition; performs a LIKE search."),
|
|
59
|
+
dict(opt="delete_clmsg_title", type=Options.T_STR, default=None, required=False, multi=False, hide=False, choice=None,
|
|
60
|
+
discription_ja="削除条件のクライアントのメッセージタイトルを指定します。LIKE検索を行います。",
|
|
61
|
+
discription_en="Specifies the message title of the client for the deletion condition; a LIKE search is performed."),
|
|
62
|
+
dict(opt="delete_clmsg_user", type=Options.T_STR, default=None, required=False, multi=False, hide=False, choice=None,
|
|
63
|
+
discription_ja="削除条件のクライアントのメッセージの発生させたユーザーを指定します。LIKE検索を行います。",
|
|
64
|
+
discription_en="Specifies the user who generated the message for the client in the delete condition; performs a LIKE search."),
|
|
65
|
+
dict(opt="delete_clmsg_body", type=Options.T_DICT, default=None, required=False, multi=True, hide=False, choice=None,
|
|
66
|
+
discription_ja="削除条件のクライアントのメッセージの本文を辞書形式で指定します。LIKE検索を行います。",
|
|
67
|
+
discription_en="Specifies the body of the client's message in the delete condition in dictionary format; performs a LIKE search."),
|
|
68
|
+
dict(opt="delete_clmsg_tag", type=Options.T_STR, default=None, required=False, multi=True, hide=False, choice=None,
|
|
69
|
+
discription_ja="削除条件のクライアントのメッセージのタグを指定します。",
|
|
70
|
+
discription_en="Specifies the tag of the client's message in the delete condition."),
|
|
71
|
+
dict(opt="delete_svmsg_id", type=Options.T_STR, default=None, required=False, multi=False, hide=False, choice=None,
|
|
72
|
+
discription_ja="削除条件のサーバーのメッセージIDを指定します。",
|
|
73
|
+
discription_en="Specify the message ID of the server for the delete condition."),
|
|
74
|
+
dict(opt="delete_svmsg_sdate", type=Options.T_DATETIME, default=None, required=False, multi=False, hide=False, choice=None,
|
|
75
|
+
discription_ja="削除条件のサーバーのメッセージ発生日時(開始)を指定します。",
|
|
76
|
+
discription_en="Specify the date and time (start) when the message occurred for the server in the delete condition."),
|
|
77
|
+
dict(opt="delete_svmsg_edate", type=Options.T_DATETIME, default=None, required=False, multi=False, hide=False, choice=None,
|
|
78
|
+
discription_ja="削除条件のサーバーのメッセージ発生日時(終了)を指定します。",
|
|
79
|
+
discription_en="Specify the date and time (end) when the message occurred for the server in the delete condition."),
|
|
80
|
+
]
|
|
81
|
+
return opt
|
|
82
|
+
|
|
83
|
+
def get_svcmd(self):
|
|
84
|
+
"""
|
|
85
|
+
この機能のサーバー側のコマンドを返します
|
|
86
|
+
|
|
87
|
+
Returns:
|
|
88
|
+
str: サーバー側のコマンド
|
|
89
|
+
"""
|
|
90
|
+
return 'audit_delete'
|
|
91
|
+
|
|
92
|
+
def apprun(self, logger:logging.Logger, args:argparse.Namespace, tm:float, pf:List[Dict[str, float]]=[]) -> Tuple[int, Dict[str, Any], Any]:
|
|
93
|
+
"""
|
|
94
|
+
この機能の実行を行います
|
|
95
|
+
|
|
96
|
+
Args:
|
|
97
|
+
logger (logging.Logger): ロガー
|
|
98
|
+
args (argparse.Namespace): 引数
|
|
99
|
+
tm (float): 実行開始時間
|
|
100
|
+
pf (List[Dict[str, float]]): 呼出元のパフォーマンス情報
|
|
101
|
+
|
|
102
|
+
Returns:
|
|
103
|
+
Tuple[int, Dict[str, Any], Any]: 終了コード, 結果, オブジェクト
|
|
104
|
+
"""
|
|
105
|
+
if args.svname is None:
|
|
106
|
+
msg = dict(warn=f"Please specify the --svname option.")
|
|
107
|
+
common.print_format(msg, args.format, tm, None, False, pf=pf)
|
|
108
|
+
return 1, msg, None
|
|
109
|
+
|
|
110
|
+
delete_audit_type_b64 = convert.str2b64str(args.delete_audit_type)
|
|
111
|
+
delete_clmsg_id_b64 = convert.str2b64str(args.delete_clmsg_id)
|
|
112
|
+
delete_clmsg_sdate = args.delete_clmsg_sdate+common.get_tzoffset_str() if args.delete_clmsg_sdate else None
|
|
113
|
+
delete_clmsg_sdate_b64 = convert.str2b64str(delete_clmsg_sdate)
|
|
114
|
+
delete_clmsg_edate = args.delete_clmsg_edate+common.get_tzoffset_str() if args.delete_clmsg_edate else None
|
|
115
|
+
delete_clmsg_edate_b64 = convert.str2b64str(delete_clmsg_edate)
|
|
116
|
+
delete_clmsg_src_b64 = convert.str2b64str(args.delete_clmsg_src)
|
|
117
|
+
delete_clmsg_title_b64 = convert.str2b64str(args.delete_clmsg_title) if args.delete_clmsg_title else None
|
|
118
|
+
delete_clmsg_user_b64 = convert.str2b64str(args.delete_clmsg_user)
|
|
119
|
+
delete_clmsg_body_str = json.dumps(args.delete_clmsg_body, default=common.default_json_enc, ensure_ascii=False) if args.delete_clmsg_body else '{}'
|
|
120
|
+
delete_clmsg_body_b64 = convert.str2b64str(delete_clmsg_body_str)
|
|
121
|
+
delete_clmsg_tag_str = json.dumps(args.delete_clmsg_tag, default=common.default_json_enc, ensure_ascii=False) if args.delete_clmsg_tag else '[]'
|
|
122
|
+
delete_clmsg_tag_b64 = convert.str2b64str(delete_clmsg_tag_str)
|
|
123
|
+
delete_svmsg_id_b64 = convert.str2b64str(args.delete_svmsg_id)
|
|
124
|
+
delete_svmsg_sdate_b64 = convert.str2b64str(args.delete_svmsg_sdate)
|
|
125
|
+
delete_svmsg_edate_b64 = convert.str2b64str(args.delete_svmsg_edate)
|
|
126
|
+
pg_enabled = args.pg_enabled
|
|
127
|
+
pg_host_b64 = convert.str2b64str(args.pg_host)
|
|
128
|
+
pg_port = args.pg_port if isinstance(args.pg_port, int) else None
|
|
129
|
+
pg_user_b64 = convert.str2b64str(args.pg_user)
|
|
130
|
+
pg_password_b64 = convert.str2b64str(args.pg_password)
|
|
131
|
+
pg_dbname_b64 = convert.str2b64str(args.pg_dbname)
|
|
132
|
+
|
|
133
|
+
cl = client.Client(logger, redis_host=args.host, redis_port=args.port, redis_password=args.password, svname=args.svname)
|
|
134
|
+
ret = cl.redis_cli.send_cmd(self.get_svcmd(),
|
|
135
|
+
[delete_audit_type_b64, delete_clmsg_id_b64, delete_clmsg_sdate_b64, delete_clmsg_edate_b64,
|
|
136
|
+
delete_clmsg_src_b64, delete_clmsg_title_b64, delete_clmsg_user_b64, delete_clmsg_body_b64,
|
|
137
|
+
delete_clmsg_tag_b64, delete_svmsg_id_b64, delete_svmsg_sdate_b64, delete_svmsg_edate_b64,
|
|
138
|
+
pg_enabled, pg_host_b64, pg_port, pg_user_b64, pg_password_b64, pg_dbname_b64],
|
|
139
|
+
retry_count=args.retry_count, retry_interval=args.retry_interval, timeout=args.timeout)
|
|
140
|
+
common.print_format(ret, args.format, tm, None, False, pf=pf)
|
|
141
|
+
|
|
142
|
+
if 'success' not in ret:
|
|
143
|
+
return 1, ret, cl
|
|
144
|
+
|
|
145
|
+
if 'data' in ret['success']:
|
|
146
|
+
for row in ret['success']['data']:
|
|
147
|
+
try:
|
|
148
|
+
row['clmsg_tag'] = json.loads(row['clmsg_tag'])
|
|
149
|
+
except:
|
|
150
|
+
pass
|
|
151
|
+
try:
|
|
152
|
+
row['clmsg_body'] = json.loads(row['clmsg_body'])
|
|
153
|
+
except:
|
|
154
|
+
pass
|
|
155
|
+
|
|
156
|
+
return 0, ret, cl
|
|
157
|
+
|
|
158
|
+
def is_cluster_redirect(self):
|
|
159
|
+
"""
|
|
160
|
+
クラスター宛のメッセージの場合、メッセージを転送するかどうかを返します
|
|
161
|
+
|
|
162
|
+
Returns:
|
|
163
|
+
bool: メッセージを転送する場合はTrue
|
|
164
|
+
"""
|
|
165
|
+
return False
|
|
166
|
+
|
|
167
|
+
def svrun(self, data_dir:Path, logger:logging.Logger, redis_cli:redis_client.RedisClient, msg:List[str],
|
|
168
|
+
sessions:Dict[str, Dict[str, Any]]) -> int:
|
|
169
|
+
"""
|
|
170
|
+
この機能のサーバー側の実行を行います
|
|
171
|
+
|
|
172
|
+
Args:
|
|
173
|
+
data_dir (Path): データディレクトリ
|
|
174
|
+
logger (logging.Logger): ロガー
|
|
175
|
+
redis_cli (redis_client.RedisClient): Redisクライアント
|
|
176
|
+
msg (List[str]): 受信メッセージ
|
|
177
|
+
sessions (Dict[str, Dict[str, Any]]): セッション情報
|
|
178
|
+
|
|
179
|
+
Returns:
|
|
180
|
+
int: 終了コード
|
|
181
|
+
"""
|
|
182
|
+
delete_audit_type = convert.b64str2str(msg[2])
|
|
183
|
+
delete_clmsg_id = convert.b64str2str(msg[3])
|
|
184
|
+
delete_clmsg_sdate = convert.b64str2str(msg[4])
|
|
185
|
+
delete_clmsg_edate = convert.b64str2str(msg[5])
|
|
186
|
+
delete_clmsg_src = convert.b64str2str(msg[6])
|
|
187
|
+
delete_clmsg_title = convert.b64str2str(msg[7])
|
|
188
|
+
delete_clmsg_user = convert.b64str2str(msg[8])
|
|
189
|
+
body = json.loads(convert.b64str2str(msg[9]))
|
|
190
|
+
tags = json.loads(convert.b64str2str(msg[10]))
|
|
191
|
+
delete_svmsg_id = convert.b64str2str(msg[11])
|
|
192
|
+
delete_svmsg_sdate = convert.b64str2str(msg[12])
|
|
193
|
+
delete_svmsg_edate = convert.b64str2str(msg[13])
|
|
194
|
+
pg_enabled = True if msg[14]=='True' else False
|
|
195
|
+
pg_host = convert.b64str2str(msg[15])
|
|
196
|
+
pg_port = int(msg[16]) if msg[16]!='None' else None
|
|
197
|
+
pg_user = convert.b64str2str(msg[17])
|
|
198
|
+
pg_password = convert.b64str2str(msg[18])
|
|
199
|
+
pg_dbname = convert.b64str2str(msg[19])
|
|
200
|
+
st = self.delete(msg[1],
|
|
201
|
+
delete_audit_type, delete_clmsg_id, delete_clmsg_sdate, delete_clmsg_edate,
|
|
202
|
+
delete_clmsg_src, delete_clmsg_title, delete_clmsg_user, body, tags,
|
|
203
|
+
delete_svmsg_id, delete_svmsg_sdate, delete_svmsg_edate,
|
|
204
|
+
pg_enabled, pg_host, pg_port, pg_user, pg_password, pg_dbname,
|
|
205
|
+
data_dir, logger, redis_cli)
|
|
206
|
+
return st
|
|
207
|
+
|
|
208
|
+
def delete(self, reskey:str,
|
|
209
|
+
delete_audit_type:str, delete_clmsg_id:str, delete_clmsg_sdate:str, delete_clmsg_edate:str,
|
|
210
|
+
delete_clmsg_src:str, delete_clmsg_title:str, delete_clmsg_user:str, delete_clmsg_body:Dict[str, Any],
|
|
211
|
+
delete_clmsg_tags:List[str], delete_svmsg_id:str, delete_svmsg_sdate:str, delete_svmsg_edate:str,
|
|
212
|
+
pg_enabled:bool, pg_host:str, pg_port:int, pg_user:str, pg_password:str, pg_dbname:str,
|
|
213
|
+
data_dir:Path, logger:logging.Logger, redis_cli:redis_client.RedisClient) -> int:
|
|
214
|
+
"""
|
|
215
|
+
監査ログを検索する
|
|
216
|
+
|
|
217
|
+
Args:
|
|
218
|
+
reskey (str): レスポンスキー
|
|
219
|
+
delete_audit_type (str): 監査の種類
|
|
220
|
+
delete_clmsg_id (str): クライアントメッセージID
|
|
221
|
+
delete_clmsg_sdate (str): クライアントメッセージ発生日時(開始)
|
|
222
|
+
delete_clmsg_edate (str): クライアントメッセージ発生日時(終了)
|
|
223
|
+
delete_clmsg_src (str): クライアントメッセージの発生源
|
|
224
|
+
delete_clmsg_title (str): クライアントメッセージのタイトル
|
|
225
|
+
delete_clmsg_user (str): クライアントメッセージの発生させたユーザー
|
|
226
|
+
delete_clmsg_body (Dict[str, Any]): クライアントメッセージの本文
|
|
227
|
+
delete_clmsg_tags (List[str]): クライアントメッセージのタグ
|
|
228
|
+
delete_svmsg_id (str): サーバーメッセージID
|
|
229
|
+
delete_svmsg_sdate (str): サーバーメッセージ発生日時(開始)
|
|
230
|
+
delete_svmsg_edate (str): サーバーメッセージ発生日時(終了)
|
|
231
|
+
pg_enabled (bool): PostgreSQLを使用する場合はTrue
|
|
232
|
+
pg_host (str): PostgreSQLホスト
|
|
233
|
+
pg_port (int): PostgreSQLポート
|
|
234
|
+
pg_user (str): PostgreSQLユーザー
|
|
235
|
+
pg_password (str): PostgreSQLパスワード
|
|
236
|
+
pg_dbname (str): PostgreSQLデータベース名
|
|
237
|
+
data_dir (Path): データディレクトリ
|
|
238
|
+
logger (logging.Logger): ロガー
|
|
239
|
+
redis_cli (redis_client.RedisClient): Redisクライアント
|
|
240
|
+
|
|
241
|
+
Returns:
|
|
242
|
+
int: レスポンスコード
|
|
243
|
+
"""
|
|
244
|
+
try:
|
|
245
|
+
with self.initdb(data_dir, logger, pg_enabled, pg_host, pg_port, pg_user, pg_password, pg_dbname) as conn:
|
|
246
|
+
cursor = conn.cursor()
|
|
247
|
+
try:
|
|
248
|
+
sql = f'DELETE FROM audit'
|
|
249
|
+
params = []
|
|
250
|
+
where = []
|
|
251
|
+
if delete_audit_type and delete_audit_type != 'None':
|
|
252
|
+
where.append(f'audit_type={"%s" if pg_enabled else "?"}')
|
|
253
|
+
params.append(delete_audit_type)
|
|
254
|
+
if delete_clmsg_id and delete_clmsg_id != 'None':
|
|
255
|
+
where.append(f'clmsg_id={"%s" if pg_enabled else "?"}')
|
|
256
|
+
params.append(delete_clmsg_id)
|
|
257
|
+
if delete_clmsg_sdate and delete_clmsg_sdate != 'None':
|
|
258
|
+
where.append(f'clmsg_date>={"%s" if pg_enabled else "?"}')
|
|
259
|
+
params.append(delete_clmsg_sdate)
|
|
260
|
+
if delete_clmsg_edate and delete_clmsg_edate != 'None':
|
|
261
|
+
where.append(f'clmsg_date<={"%s" if pg_enabled else "?"}')
|
|
262
|
+
params.append(delete_clmsg_edate)
|
|
263
|
+
if delete_clmsg_src and delete_clmsg_src != 'None':
|
|
264
|
+
where.append(f'clmsg_src LIKE {"%s" if pg_enabled else "?"}')
|
|
265
|
+
params.append(delete_clmsg_src)
|
|
266
|
+
if delete_clmsg_title and delete_clmsg_title != 'None':
|
|
267
|
+
where.append(f'clmsg_title LIKE {"%s" if pg_enabled else "?"}')
|
|
268
|
+
params.append(delete_clmsg_src)
|
|
269
|
+
if delete_clmsg_user and delete_clmsg_user != 'None':
|
|
270
|
+
where.append(f'clmsg_user LIKE {"%s" if pg_enabled else "?"}')
|
|
271
|
+
params.append(delete_clmsg_user)
|
|
272
|
+
if delete_clmsg_body:
|
|
273
|
+
if sys.version_info[0] < 3 or sys.version_info[0] >= 3 and sys.version_info[1] < 10:
|
|
274
|
+
raise RuntimeError("Python 3.10 or later is required for JSON support.")
|
|
275
|
+
for key, value in delete_clmsg_body.items():
|
|
276
|
+
where.append(f"clmsg_body->>'{key}' LIKE {'%s' if pg_enabled else '?'}")
|
|
277
|
+
params.append(value)
|
|
278
|
+
if delete_clmsg_tags:
|
|
279
|
+
for tag in delete_clmsg_tags:
|
|
280
|
+
where.append(f"clmsg_tag like {'%s' if pg_enabled else '?'}")
|
|
281
|
+
params.append(f'%{tag}%')
|
|
282
|
+
if delete_svmsg_id and delete_svmsg_id != 'None':
|
|
283
|
+
where.append(f'svmsg_id={"%s" if pg_enabled else "?"}')
|
|
284
|
+
params.append(delete_svmsg_id)
|
|
285
|
+
if delete_svmsg_sdate and delete_svmsg_sdate != 'None':
|
|
286
|
+
where.append(f'svmsg_date>={"%s" if pg_enabled else "?"}')
|
|
287
|
+
params.append(delete_svmsg_sdate)
|
|
288
|
+
if delete_svmsg_edate and delete_svmsg_edate != 'None':
|
|
289
|
+
where.append(f'svmsg_date<={"%s" if pg_enabled else "?"}')
|
|
290
|
+
params.append(delete_svmsg_edate)
|
|
291
|
+
sql += ' WHERE ' + ' AND '.join(where) if len(where)>0 else ''
|
|
292
|
+
cursor.execute(sql, tuple(params))
|
|
293
|
+
delete_count = cursor.rowcount
|
|
294
|
+
conn.commit()
|
|
295
|
+
if delete_count <= 0:
|
|
296
|
+
rescode, msg = (self.RESP_WARN, dict(warn="No data deleted."))
|
|
297
|
+
redis_cli.rpush(reskey, msg)
|
|
298
|
+
return rescode
|
|
299
|
+
else:
|
|
300
|
+
rescode, msg = (self.RESP_SCCESS, dict(success=dict(msg=f"{delete_count} records deleted.", count=delete_count)))
|
|
301
|
+
redis_cli.rpush(reskey, msg)
|
|
302
|
+
return rescode
|
|
303
|
+
finally:
|
|
304
|
+
cursor.close()
|
|
305
|
+
except Exception as e:
|
|
306
|
+
logger.warning(f"Failed to delete: {e}", exc_info=True)
|
|
307
|
+
redis_cli.rpush(reskey, dict(warn=f"Failed to delete: {e}"))
|
|
308
|
+
return self.RESP_WARN
|