From 42c65b44a106c605f4a0f177b1f3ac7f2180e16b Mon Sep 17 00:00:00 2001 From: ngfchl Date: Wed, 4 Jan 2023 17:03:29 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=AE=80=E6=98=93shell?= =?UTF-8?q?=E7=BB=88=E7=AB=AF,=E5=B9=B6=E5=86=85=E7=BD=AE=E9=83=A8?= =?UTF-8?q?=E5=88=86=E5=91=BD=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- auto_pt/urls.py | 2 + auto_pt/views.py | 14 +++- ptools/settings.py | 4 ++ templates/auto_pt/shell.html | 120 +++++++++++++++++++++++++++++++++++ 4 files changed, 139 insertions(+), 1 deletion(-) create mode 100644 templates/auto_pt/shell.html diff --git a/auto_pt/urls.py b/auto_pt/urls.py index b00f810..2872dbf 100644 --- a/auto_pt/urls.py +++ b/auto_pt/urls.py @@ -43,4 +43,6 @@ urlpatterns = [ path(r'get_helper_license', views.get_helper_license, name='get_helper_license'), path(r'downloading_status', views.downloading_status, name='downloading_status'), path(r'do_sql', views.do_sql, name='do_sql'), + path(r'exec_shell_command', views.exec_shell_command, name='exec_shell_command'), + path(r'exec_shell_command', views.exec_shell_command, name='exec_shell_command'), ] diff --git a/auto_pt/views.py b/auto_pt/views.py index 9d24dfe..2799aec 100644 --- a/auto_pt/views.py +++ b/auto_pt/views.py @@ -1132,7 +1132,19 @@ def save_config_api(request): msg='配置文件保存成功!' ).to_dict(), safe=False) except Exception as e: - raise return JsonResponse(data=CommonResponse.error( msg='获取配置文件信息失败!' ).to_dict(), safe=False) + + +def exec_shell_command(request): + if request.method == 'GET': + return render(request, 'auto_pt/shell.html') + else: + content = json.loads(request.body) + logger.info(content) + p = subprocess.getoutput(content.get('shell')) + logger.info(p) + return JsonResponse(data=CommonResponse.success( + data=p + ).to_dict(), safe=False) diff --git a/ptools/settings.py b/ptools/settings.py index 9fdccf0..79723e2 100644 --- a/ptools/settings.py +++ b/ptools/settings.py @@ -292,6 +292,10 @@ SIMPLEUI_CONFIG = { 'name': '日志查看', 'icon': 'fab fa-blogger', 'url': '/tasks/show_log_list' + }, { + 'name': '简易终端', + 'icon': 'fa fa-terminal', + 'url': '/tasks/exec_shell_command' }, ] }] } diff --git a/templates/auto_pt/shell.html b/templates/auto_pt/shell.html new file mode 100644 index 0000000..8869183 --- /dev/null +++ b/templates/auto_pt/shell.html @@ -0,0 +1,120 @@ +{% load static %} + + + + + + + Title + {% include 'admin/includes/css-part.html' %} + + + +
+
+ + + + 发送 + + 更新代码 + 更新依赖 + 初始化代码 + 初始化xpath + + +
+
+

+    
+
+{% include 'admin/includes/js-part.html' %} + + + + \ No newline at end of file