From 07679b29058fb03b0fd8ac0591f139a385731d2c Mon Sep 17 00:00:00 2001 From: Liiuliu <9923434696@qq.com> Date: Mon, 26 Apr 2021 14:29:23 +0800 Subject: [PATCH 01/12] page refresh --- vulfocus-frontend/src/App.vue | 23 +++++++++++++++++-- .../src/views/dashboard/index.vue | 4 ++++ 2 files changed, 25 insertions(+), 2 deletions(-) mode change 100644 => 100755 vulfocus-frontend/src/App.vue mode change 100644 => 100755 vulfocus-frontend/src/views/dashboard/index.vue diff --git a/vulfocus-frontend/src/App.vue b/vulfocus-frontend/src/App.vue old mode 100644 new mode 100755 index ec9032c1..472ec95a --- a/vulfocus-frontend/src/App.vue +++ b/vulfocus-frontend/src/App.vue @@ -1,11 +1,30 @@ + diff --git a/vulfocus-frontend/src/views/dashboard/index.vue b/vulfocus-frontend/src/views/dashboard/index.vue old mode 100644 new mode 100755 index 8adac728..99bbb2f3 --- a/vulfocus-frontend/src/views/dashboard/index.vue +++ b/vulfocus-frontend/src/views/dashboard/index.vue @@ -133,6 +133,9 @@ export default { created() { this.listData(1) }, + mounted(){ + this.reload() + }, methods:{ listData() { ImgList().then(response => { @@ -240,6 +243,7 @@ export default { }) } this.centerDialogVisible = false + this.reload() this.item_raw_data.status.status = 'stop' }) }, From d7a00e084db2e3936a93ac644ee166d27bc250ae Mon Sep 17 00:00:00 2001 From: Liiuliu <992343696@qq.com> Date: Mon, 26 Apr 2021 18:43:14 +0800 Subject: [PATCH 02/12] update dashboard & Container expiration problem & Page layout bug --- vulfocus-api/tasks/tasks.py | 2 +- vulfocus-frontend/src/views/dashboard/index.vue | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) mode change 100644 => 100755 vulfocus-api/tasks/tasks.py diff --git a/vulfocus-api/tasks/tasks.py b/vulfocus-api/tasks/tasks.py old mode 100644 new mode 100755 index d71e0260..22eb547f --- a/vulfocus-api/tasks/tasks.py +++ b/vulfocus-api/tasks/tasks.py @@ -153,7 +153,7 @@ def create_container_task(container_vul, user_info, request_ip): except: countdown = int(DEFAULT_CONFIG["time"]) if countdown == 0: - run_container.delay(container_vul.container_id, user_id, task_id) + run_container.delay(container_vul.container_id, user_id, task_id, countdown) elif countdown != 0 and countdown > 60: # run_container(container_vul.container_id, user_id, task_id, countdown) add_chain_sig = chain(run_container.s(container_vul.container_id, user_id, task_id, countdown) | diff --git a/vulfocus-frontend/src/views/dashboard/index.vue b/vulfocus-frontend/src/views/dashboard/index.vue index 99bbb2f3..15edb88d 100755 --- a/vulfocus-frontend/src/views/dashboard/index.vue +++ b/vulfocus-frontend/src/views/dashboard/index.vue @@ -103,6 +103,7 @@ import { ImgList,SubFlag,ContainerSTART,ContainerDelete,ContainerStop } from '@/ import { getTask } from '@/api/tasks' import CountDown from 'vue2-countdown' export default { + inject: ['reload'], name: 'Dashboard', components: { CountDown @@ -133,9 +134,6 @@ export default { created() { this.listData(1) }, - mounted(){ - this.reload() - }, methods:{ listData() { ImgList().then(response => { @@ -411,6 +409,11 @@ export default { margin-block-end: 0em; } +.el-row { + display: flex; + flex-wrap: wrap; +} + /*p {*/ /* height: 20px;*/ /* line-height: 20px;*/ From 90a509c7e0ab055adab682c58e8ab3a1eab01072 Mon Sep 17 00:00:00 2001 From: Liiuliu <992343696@qq.com> Date: Wed, 28 Apr 2021 14:20:53 +0800 Subject: [PATCH 03/12] update logmodels & Add log query function --- vulfocus-api/dockerapi/models.py | 0 vulfocus-api/dockerapi/views.py | 7 +++++-- vulfocus-frontend/src/api/log.js | 9 ++++++--- vulfocus-frontend/src/views/manager/log.vue | 16 ++++++++++++++-- 4 files changed, 25 insertions(+), 7 deletions(-) mode change 100644 => 100755 vulfocus-api/dockerapi/models.py mode change 100644 => 100755 vulfocus-api/dockerapi/views.py mode change 100644 => 100755 vulfocus-frontend/src/api/log.js mode change 100644 => 100755 vulfocus-frontend/src/views/manager/log.vue diff --git a/vulfocus-api/dockerapi/models.py b/vulfocus-api/dockerapi/models.py old mode 100644 new mode 100755 diff --git a/vulfocus-api/dockerapi/views.py b/vulfocus-api/dockerapi/views.py old mode 100644 new mode 100755 index 8793b501..2b6704dd --- a/vulfocus-api/dockerapi/views.py +++ b/vulfocus-api/dockerapi/views.py @@ -16,7 +16,7 @@ from tasks.models import TaskInfo import re from rest_framework.decorators import api_view - +import time def get_request_ip(request): """ @@ -400,8 +400,11 @@ class SysLogSet(viewsets.ModelViewSet): def get_queryset(self): request = self.request user = request.user + query = self.request.GET.get("query", "") if user.is_superuser: - return SysLog.objects.all().order_by('-create_date') + return SysLog.objects.filter(Q(operation_args__contains=query) | Q(operation_name__contains=query) + | Q(operation_type__contains=query) | Q(ip__contains=query) + | Q(operation_value__contains=query )).order_by('-create_date') else: return [] diff --git a/vulfocus-frontend/src/api/log.js b/vulfocus-frontend/src/api/log.js old mode 100644 new mode 100755 index 4f414230..37ae3d6a --- a/vulfocus-frontend/src/api/log.js +++ b/vulfocus-frontend/src/api/log.js @@ -1,11 +1,14 @@ import request from '@/utils/request' -export function LogList(page) { - if(page === undefined || page === null){ +export function LogList(data, page) { + if (data === undefined){ + data = "" + } + if (page === undefined){ page = 1 } return request({ - url: '/syslog/?page='+page, + url: '/syslog/?query='+data+"&page="+page, method: 'get' }) } diff --git a/vulfocus-frontend/src/views/manager/log.vue b/vulfocus-frontend/src/views/manager/log.vue old mode 100644 new mode 100755 index 6d0a312e..0e191e24 --- a/vulfocus-frontend/src/views/manager/log.vue +++ b/vulfocus-frontend/src/views/manager/log.vue @@ -1,5 +1,11 @@ + + diff --git a/vulfocus-frontend/src/views/rank/index.vue b/vulfocus-frontend/src/views/rank/index.vue new file mode 100644 index 00000000..f06b42df --- /dev/null +++ b/vulfocus-frontend/src/views/rank/index.vue @@ -0,0 +1,78 @@ + + + + + diff --git a/vulfocus-frontend/src/views/time/index.vue b/vulfocus-frontend/src/views/time/index.vue new file mode 100644 index 00000000..d8e9ee9f --- /dev/null +++ b/vulfocus-frontend/src/views/time/index.vue @@ -0,0 +1,178 @@ + + + + + + From e86f77cd11d139f1a48e54b8b34b785ff9d423bc Mon Sep 17 00:00:00 2001 From: Liiuliu <992343696@qq.com> Date: Thu, 27 May 2021 21:36:08 +0800 Subject: [PATCH 07/12] Modify the page, perfect timing mode --- vulfocus-api/dockerapi/models.py | 1 + vulfocus-api/dockerapi/serializers.py | 5 + vulfocus-api/dockerapi/views.py | 92 +++++----- vulfocus-frontend/src/api/timemoudel.js | 85 +++++++++ vulfocus-frontend/src/router/index.js | 45 +++-- .../src/views/dashboard/index.vue | 36 ++-- .../src/views/manager/timetemp.vue | 160 +++++++++++++---- vulfocus-frontend/src/views/scene/list.vue | 167 +++++++++++++++++- 8 files changed, 479 insertions(+), 112 deletions(-) create mode 100644 vulfocus-frontend/src/api/timemoudel.js mode change 100644 => 100755 vulfocus-frontend/src/views/scene/list.vue diff --git a/vulfocus-api/dockerapi/models.py b/vulfocus-api/dockerapi/models.py index b8b6395b..13dfe526 100755 --- a/vulfocus-api/dockerapi/models.py +++ b/vulfocus-api/dockerapi/models.py @@ -11,6 +11,7 @@ class TimeTemp(models.Model): temp_id = models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True) user_id = models.IntegerField(verbose_name='用户ID') time_range = models.IntegerField(verbose_name='计时模式时间') + image_name = models.TextField(null=False, default="", verbose_name="图片名称") time_desc = models.TextField(verbose_name='计时模版描述', null=True) flag_status = models.BooleanField(verbose_name='用于判断', default=False) diff --git a/vulfocus-api/dockerapi/serializers.py b/vulfocus-api/dockerapi/serializers.py index 9c51fe23..b860d820 100755 --- a/vulfocus-api/dockerapi/serializers.py +++ b/vulfocus-api/dockerapi/serializers.py @@ -10,6 +10,7 @@ from dockerapi.common import get_setting_config import redis import time +import datetime r = redis.Redis(connection_pool=REDIS_POOL) @@ -68,7 +69,11 @@ def statusck(self, obj): ''' 检测是否在时间模式中 ''' + now_time = datetime.datetime.now().timestamp() + time_moudel_data = TimeMoudel.objects.filter(user_id=id, end_time__gte=now_time).first() time_model_id = '' + if time_moudel_data: + time_model_id = time_moudel_data.time_id # 排出已经删除数据 Q(docker_container_id__isnull=False), ~Q(docker_container_id=''), data = ContainerVul.objects.all().filter(user_id=id, image_id=obj.image_id, time_model_id=time_model_id).first() status["status"] = "" diff --git a/vulfocus-api/dockerapi/views.py b/vulfocus-api/dockerapi/views.py index beee5856..78a11144 100755 --- a/vulfocus-api/dockerapi/views.py +++ b/vulfocus-api/dockerapi/views.py @@ -41,23 +41,12 @@ class CreateTimeTemplate(viewsets.ModelViewSet): serializer_class = TimeTempSerializer def get_queryset(self, *args, **kwargs): + request = self.request + r_ip = get_request_ip(request) user_id = request.user.id now_time = datetime.datetime.now().timestamp() - flag = self.request.GET.get("flag", "") - data = TimeMoudel.objects.filter(user_id=user_id, end_time__gte=now_time).first() - if data: - if flag and flag=="flag": - return TimeTemp.objects.all() - else: - data_list = TimeTemp.objects.filter(temp_id=data.temp_time_id_id) - print(data_list) - data_l = [{'temp_id': data_list[0].temp_id, 'time_desc':data_list[0].time_desc, - 'time_range': data_list[0].time_range, 'user_id': data_list[0].user_id, - 'flag_status': True}] - return data_l - else: - return TimeTemp.objects.all() + return TimeTemp.objects.all() # 创建计时模式模版 @@ -70,24 +59,41 @@ def create(self, request, *args, **kwargs): "message": "时间范围必须是整数,并且是30的倍数", } return JsonResponse(data=data) + time_data = TimeTemp.objects.filter(time_range=int(request.data['time_range'])).first() + if time_data: + data = { + "code": 2001, + "message": "该时间模式已经创建", + } + return JsonResponse(data=data) try: time_range = request.data['time_range'] except Exception as e: return JsonResponse(data={"code": 2001, "message": "时间范围不能为空"}) - timetemp_info = TimeTemp(user_id=user_id, time_range=int(time_range), time_desc=time_desc) + img = request.data['imageName'] + timetemp_info = TimeTemp(user_id=user_id, time_range=int(time_range), time_desc=time_desc, image_name=img) timetemp_info.save() data = self.serializer_class(timetemp_info).data return JsonResponse(R.ok(data=data)) def destroy(self, request, *args, **kwargs): user = request.user + now_time = datetime.datetime.now().timestamp() if not user.is_superuser: return JsonResponse(R.build(msg="权限不足")) - temp = self.get_object() - temp_id = self.get_serializer(temp).data['temp_id'] - try: + request = self.request + if "id" in request.data: + temp_id = request.data['id'] + else: + temp = self.get_object() + temp_id = self.get_serializer(temp).data['temp_id'] + data = TimeMoudel.objects.filter(temp_time_id_id=temp_id,end_time__gte=now_time).first() + if data: + return JsonResponse({"code": 2001, "message": "删除失败,该模版计时模式已启动"}) + try: temp = TimeTemp.objects.filter(temp_id=temp_id).first() + temp.delete() except Exception as e: return JsonResponse({"code": 2001, "message": "删除失败"}) return JsonResponse({"code": 200, "message": "删除成功"}) @@ -120,8 +126,10 @@ def delete(self, request, *args, **kwargs): user_id = request.user.id now_time = datetime.datetime.now().timestamp() try: + data = TimeMoudel.objects.filter(user_id=user_id, end_time__gte=now_time).first() + time_id = data.time_id TimeMoudel.objects.filter(user_id=user_id, end_time__gte=now_time).delete() - container_vul_list = ContainerVul.objects.filter(user_id=user_id) + container_vul_list = ContainerVul.objects.filter(user_id=user_id, time_model_id=time_id) for container_vul in container_vul_list: try: docker_container_id = container_vul.docker_container_id @@ -133,6 +141,7 @@ def delete(self, request, *args, **kwargs): container_vul.delete() return JsonResponse({"code": "2000", "msg": "成功"}, status=201) except Exception as e: + print(e) return JsonResponse({"code": "2001", "msg": str(e)}) ''' @@ -195,23 +204,7 @@ def check(self, request, pk=None): def create(self, request, *args, **kwargs): user_id = request.user.id now_time = datetime.datetime.now().timestamp() - if "type" in request.data: - dasdata = TimeMoudel.objects.filter(user_id=user_id, end_time__gte=now_time).first() - if dasdata: - tm1 = TimeMoudel.objects.filter(user_id=user_id, status=True ).all() - print(tm1) - tm = TimeMoudel.objects.filter(user_id=user_id, status=True ).first() - tm_moudel_info = TimeMoudelSerializer(tm) - data = tm_moudel_info.data - data["start_date"] = int(time.time()) - onetime = time.strptime(data["end_date"], "%Y-%m-%d %H:%M:%S") - data["end_date"] = int(time.mktime(onetime)) - print(data) - return JsonResponse({"code": "2002", "msg": "时间未到", "data": data}) - else: - return JsonResponse({"code": "20000", "msg": "响应成功", "data": ""}) - if "time_range" in request.data: - time_minute = request.data['time_range'] + time_minute = request.data['time_range'] data = TimeMoudel.objects.filter(user_id=user_id, end_time__gte=now_time).first() if data: return JsonResponse({"code": "2001", "msg": "时间未到", "data": ""}) @@ -234,9 +227,6 @@ def create(self, request, *args, **kwargs): time_moudel.save() time_moudel_info = TimeMoudelSerializer(time_moudel) data = time_moudel_info.data - data["start_date"] = int(time.time()) - onetime = time.strptime(data["end_date"], "%Y-%m-%d %H:%M:%S") - data["end_date"] = int(time.mktime(onetime)) return JsonResponse({"code": "200", "msg": "OK", "data": data}, status=201) @@ -491,13 +481,18 @@ def start_container(self, request, pk=None): user = request.user image_id = img_info.image_id user_id = user.id - container_vul = ContainerVul.objects.filter(user_id=user_id, image_id=image_id, time_model_id="").first() + now_time = datetime.datetime.now().timestamp() + time_moudel_data = TimeMoudel.objects.filter(user_id=user_id, end_time__gte=now_time).first() + time_model_id = '' + if time_moudel_data: + time_model_id = time_moudel_data.time_id + container_vul = ContainerVul.objects.filter(user_id=user_id, image_id=image_id, time_model_id=time_model_id).first() if not container_vul: container_vul = ContainerVul(image_id=img_info, user_id=user_id, vul_host="", container_status="stop", docker_container_id="", vul_port="", container_port="", - time_model_id="", + time_model_id=time_model_id, create_date=django.utils.timezone.now(), container_flag="") container_vul.save() @@ -514,13 +509,21 @@ def get_queryset(self): user = request.user flag = request.GET.get("flag", "") image_id = request.GET.get("image_id", "") + ''' + 检测是否在时间模式中 + ''' + now_time = datetime.datetime.now().timestamp() + time_moudel_data = TimeMoudel.objects.filter(user_id=user.id, end_time__gte=now_time).first() + time_model_id = '' + if time_moudel_data: + time_model_id = time_moudel_data.time_id if flag == 'list' and user.is_superuser: if image_id: container_vul_list = ContainerVul.objects.filter(image_id=image_id).order_by('-create_date') else: container_vul_list = ContainerVul.objects.all().order_by('-create_date') else: - container_vul_list = ContainerVul.objects.filter(user_id=self.request.user.id, time_model_id="") + container_vul_list = ContainerVul.objects.filter(user_id=user.id, time_model_id=time_model_id) return container_vul_list @action(methods=["get"], detail=True, url_path='start') @@ -579,7 +582,9 @@ def check_flag(self, request, pk=None): :param pk: :return: """ - flag = request.GET.get('flag', None) + + request = self.request + flag = request.GET.get('flag', "") container_vul = self.get_object() user_info = request.user user_id = user_info.id @@ -589,7 +594,6 @@ def check_flag(self, request, pk=None): operation_value=operation_args["vul_name"], operation_args={"flag": flag}, ip=request_ip) sys_log.save() - if user_id != container_vul.user_id: return JsonResponse(R.build(msg="Flag 与用户不匹配")) if not flag: diff --git a/vulfocus-frontend/src/api/timemoudel.js b/vulfocus-frontend/src/api/timemoudel.js new file mode 100644 index 00000000..e38d440f --- /dev/null +++ b/vulfocus-frontend/src/api/timemoudel.js @@ -0,0 +1,85 @@ +import request from '@/utils/request' + +const baseUrl = "/time/" + +/** + * 创建时间模式 + * 时间模式信息 + */ +export function start(data) { + return request({ + url: "/time/", + method: 'post', + data + }) +} + +export function stoptimetemp() { + return request({ + url: "/time/", + method: 'delete' + }) +} + +export function gettimetemp() { + return request({ + url: "/time/", + method: 'get' + }) +} + +export function timetempadd(data) { + return request({ + url: "/timetemp/", + method: 'post', + data + }) +} + +export function timetemplist(flag) { + + let paramFlag = "" + if(flag === true){ + paramFlag = "flag" + } + if(flag === "temp"){ + paramFlag = "temp" + } + let url = "/timetemp/?query="+"&flag="+paramFlag + return request({ + url: url, + method: 'get', + }) +} + +export function timetempdelete(id) { + return request({ + url: "/timetemp/" + id + "/", + method: 'delete', + data:{"id":id} + }) +} + +export function userranklist(page) { + return request({ + url: '/user/?page='+ page, + method: 'get' + }) +} + +export function timeranklist(value) { + return request({ + url: '/timerank/?value=' + value, + method: 'get' + }) +} +const publicMethod = { + + getTimestamp(time) { //把时间日期转成时间戳 + return (new Date(time)).getTime() / 1000 + } + +} +export { + publicMethod +} diff --git a/vulfocus-frontend/src/router/index.js b/vulfocus-frontend/src/router/index.js index 5f0a1bbe..fb04d8c1 100755 --- a/vulfocus-frontend/src/router/index.js +++ b/vulfocus-frontend/src/router/index.js @@ -84,30 +84,43 @@ export const constantRoutes = [ }] }, { - path: '/', + path: '/time', component: Layout, - redirect: '/', - meta: {title: "情景模式", icon: 'form'}, + redirect: '/time', children: [{ path: 'time', affix: true, - name: 'time', + name: 'list', + hidden: true, component: () => import('@/views/time/index'), - meta: { title: '计时模式', icon: 'form' } - }, - { - path: '/scene/list', - component: () => import('@/views/scene/list'), - name: 'List', - meta: { title: '场景', icon: 'table', noCache: true } - }, + meta: { title: '场景模式', icon: 'form' } + }] + }, + { + path: '/', + component: Layout, + redirect: '/', + children: [{ + path: '/scene/list', + name: 'List', + component: () => import('@/views/scene/list'), + meta: { title: '场景', icon: 'table', noCache: true } + }] + }, + { + path: '/', + component: Layout, + redirect: '/', + meta: {title: "场景模式", icon: 'form'}, + hidden: true, + children: [ { path: '/scene/index', component: () => import('@/views/scene/index'), name: 'Index', hidden: true, meta: { title: '场景', icon: 'table', noCache: true } - }] + },] }, ] @@ -152,7 +165,7 @@ export const asyncRoutes = [ path: '/layout', component: Layout, redirect: '/layout', - meta: {role: ['admin'], title: "情景模式管理", icon: "barrage_fill"}, + meta: {role: ['admin'], title: "场景管理", icon: "barrage_fill"}, children: [{ path: 'network', affix: true, @@ -175,9 +188,9 @@ export const asyncRoutes = [ meta: { title: '创建', icon: 'barrage_fill' , role: ['admin']} }, { - path: 'time', + path: 'timetemp', affix: true, - name: 'time', + name: 'timetemp', component: () => import("@/views/manager/timetemp"), meta: { title: '计时模版管理', icon: 'setting' , role: ['admin']} }, diff --git a/vulfocus-frontend/src/views/dashboard/index.vue b/vulfocus-frontend/src/views/dashboard/index.vue index 82e1daa6..875dfbe1 100755 --- a/vulfocus-frontend/src/views/dashboard/index.vue +++ b/vulfocus-frontend/src/views/dashboard/index.vue @@ -100,7 +100,8 @@ diff --git a/vulfocus-frontend/src/views/manager/timetemp.vue b/vulfocus-frontend/src/views/manager/timetemp.vue index eea6c66a..e1082568 100755 --- a/vulfocus-frontend/src/views/manager/timetemp.vue +++ b/vulfocus-frontend/src/views/manager/timetemp.vue @@ -1,37 +1,46 @@