diff --git a/apps/common/permissions.py b/apps/common/permissions.py index 10ef329ed..67154b228 100644 --- a/apps/common/permissions.py +++ b/apps/common/permissions.py @@ -70,6 +70,14 @@ class IsCurrentUserOrReadOnly(permissions.BasePermission): return obj == request.user +class LoginRequiredMixin(UserPassesTestMixin): + def test_func(self): + if self.request.user.is_authenticated: + return True + else: + return False + + class AdminUserRequiredMixin(UserPassesTestMixin): def test_func(self): if not self.request.user.is_authenticated: diff --git a/apps/jumpserver/settings.py b/apps/jumpserver/settings.py index 02e48c3c4..d516c097c 100644 --- a/apps/jumpserver/settings.py +++ b/apps/jumpserver/settings.py @@ -475,6 +475,7 @@ CELERY_WORKER_REDIRECT_STDOUTS = True CELERY_WORKER_REDIRECT_STDOUTS_LEVEL = "INFO" # CELERY_WORKER_HIJACK_ROOT_LOGGER = True CELERY_WORKER_MAX_TASKS_PER_CHILD = 40 +CELERY_TASK_SOFT_TIME_LIMIT = 3600 # Cache use redis CACHES = { diff --git a/apps/locale/zh/LC_MESSAGES/django.mo b/apps/locale/zh/LC_MESSAGES/django.mo index 7196bfa06..3f02ced3b 100644 Binary files a/apps/locale/zh/LC_MESSAGES/django.mo and b/apps/locale/zh/LC_MESSAGES/django.mo differ diff --git a/apps/locale/zh/LC_MESSAGES/django.po b/apps/locale/zh/LC_MESSAGES/django.po index 9c40a44b2..dd120a909 100644 --- a/apps/locale/zh/LC_MESSAGES/django.po +++ b/apps/locale/zh/LC_MESSAGES/django.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: Jumpserver 0.3.3\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-03-22 17:12+0800\n" +"POT-Creation-Date: 2019-03-27 10:57+0800\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: ibuler \n" "Language-Team: Jumpserver team\n" @@ -2434,35 +2434,35 @@ msgstr "任务列表" msgid "Go" msgstr "" -#: ops/templates/ops/command_execution_create.html:144 +#: ops/templates/ops/command_execution_create.html:148 msgid "Selected assets" msgstr "已选择资产" -#: ops/templates/ops/command_execution_create.html:147 +#: ops/templates/ops/command_execution_create.html:151 msgid "In total" msgstr "总共" -#: ops/templates/ops/command_execution_create.html:182 +#: ops/templates/ops/command_execution_create.html:186 msgid "" "Select the left asset, select the running system user, execute command in " "batch" msgstr "选择左侧资产, 选择运行的系统用户,批量执行命令" -#: ops/templates/ops/command_execution_create.html:200 +#: ops/templates/ops/command_execution_create.html:204 msgid "Unselected assets" msgstr "没有选中资产" -#: ops/templates/ops/command_execution_create.html:204 +#: ops/templates/ops/command_execution_create.html:208 msgid "No input command" msgstr "没有输入命令" -#: ops/templates/ops/command_execution_create.html:208 +#: ops/templates/ops/command_execution_create.html:212 msgid "No system user was selected" msgstr "没有选择系统用户" -#: ops/templates/ops/command_execution_create.html:253 +#: ops/templates/ops/command_execution_create.html:257 msgid "Pending" -msgstr "" +msgstr "等待" #: ops/templates/ops/command_execution_list.html:64 msgid "Finished" @@ -2521,7 +2521,7 @@ msgstr "更新任务内容: {}" #: ops/views/adhoc.py:44 ops/views/adhoc.py:69 ops/views/adhoc.py:82 #: ops/views/adhoc.py:95 ops/views/adhoc.py:108 ops/views/adhoc.py:121 -#: ops/views/adhoc.py:134 ops/views/command.py:43 ops/views/command.py:67 +#: ops/views/adhoc.py:134 ops/views/command.py:44 ops/views/command.py:68 msgid "Ops" msgstr "作业中心" @@ -2533,11 +2533,11 @@ msgstr "任务列表" msgid "Task run history" msgstr "执行历史" -#: ops/views/command.py:44 +#: ops/views/command.py:45 msgid "Command execution list" msgstr "命令执行列表" -#: ops/views/command.py:68 templates/_nav_user.html:9 +#: ops/views/command.py:69 templates/_nav_user.html:9 msgid "Command execution" msgstr "命令执行" diff --git a/apps/ops/tasks.py b/apps/ops/tasks.py index 9de1d0437..aef8ea055 100644 --- a/apps/ops/tasks.py +++ b/apps/ops/tasks.py @@ -4,6 +4,7 @@ import subprocess from django.conf import settings from celery import shared_task, subtask +from celery.exceptions import SoftTimeLimitExceeded from django.utils import timezone from common.utils import get_logger, get_object_or_none @@ -38,11 +39,14 @@ def run_ansible_task(tid, callback=None, **kwargs): logger.error("No task found") -@shared_task +@shared_task(soft_time_limit=60) def run_command_execution(cid, **kwargs): execution = get_object_or_none(CommandExecution, id=cid) if execution: - execution.run() + try: + execution.run() + except SoftTimeLimitExceeded: + print("HLLL") else: logger.error("Not found the execution id: {}".format(cid)) diff --git a/apps/ops/templates/ops/command_execution_create.html b/apps/ops/templates/ops/command_execution_create.html index 219fc218d..8352d1607 100644 --- a/apps/ops/templates/ops/command_execution_create.html +++ b/apps/ops/templates/ops/command_execution_create.html @@ -82,6 +82,7 @@