Exemple #1
0
    def check_flag(self, request, pk=None):
        flag = request.GET.get('flag', None)
        container_vul = self.get_object()
        user_info = request.user
        user_id = user_info.id

        operation_args = ContainerVulSerializer(container_vul).data
        request_ip = get_request_ip(request)
        sys_log = SysLog(user_id=user_id,
                         operation_type="容器",
                         operation_name="提交Flag",
                         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:
            return JsonResponse(R.build(msg="Flag不能为空"))
        if flag != container_vul.container_flag:
            return JsonResponse(R.build(msg="flag错误"))
        else:
            if not container_vul.is_check:
                # 更新为通过
                container_vul.is_check_date = timezone.now()
                container_vul.is_check = True
                container_vul.save()
                # 停止 Docker
                tasks.stop_container_task(container_vul=container_vul,
                                          user_info=user_info,
                                          request_ip=get_request_ip(request))
            return JsonResponse(R.ok())
Exemple #2
0
    def check_flag(self, request, pk=None):
        """
        验证Flag是否正确
        :param request:
        :param pk:
        :return:
        """

        request = self.request
        flag = request.GET.get('flag', "")
        container_vul = self.get_object()
        user_info = request.user
        user_id = user_info.id
        operation_args = ContainerVulSerializer(container_vul).data
        request_ip = get_request_ip(request)
        sys_log = SysLog(user_id=user_id,
                         operation_type="容器",
                         operation_name="提交Flag",
                         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:
            return JsonResponse(R.build(msg="Flag不能为空"))
        if flag != container_vul.container_flag:
            return JsonResponse(R.build(msg="flag错误"))
        else:
            if not container_vul.is_check:
                # 更新为通过
                container_vul.is_check_date = timezone.now()
                container_vul.is_check = True
                container_vul.save()
                # 检测是否在时间模式中
                now_time = datetime.datetime.now().timestamp()
                time_moudel_data = TimeMoudel.objects.filter(
                    user_id=user_id, end_time__gte=now_time).first()
                if time_moudel_data:
                    rank = 0
                    time_model_id = time_moudel_data.time_id
                    successful = ContainerVul.objects.filter(
                        is_check=True,
                        user_id=user_id,
                        time_model_id=time_model_id)
                    rd = TimeRank.objects.filter(
                        time_temp_id=time_moudel_data.temp_time_id_id,
                        user_id=user_id).first()
                    for i in successful:
                        rank += i.image_id.rank
                    if rank >= rd.rank:
                        rd.rank = rank
                        rd.save()
                # 停止 Docker
                tasks.stop_container_task(container_vul=container_vul,
                                          user_info=user_info,
                                          request_ip=get_request_ip(request))
            return JsonResponse(R.ok())
Exemple #3
0
 def stop_container(self, request, pk=None):
     """
     停止容器运行
     :param request:
     :param pk:
     :return:
     """
     user_info = request.user
     container_vul = self.get_object()
     task_id = tasks.stop_container_task(container_vul=container_vul, user_info=user_info,
                                         request_ip=get_request_ip(request))
     return JsonResponse(R.ok(task_id))
Exemple #4
0
 def stop_container(self, request, pk=None):
     """
     停止容器运行
     :param request:
     :param pk:
     :return:
     """
     user_info = request.user
     container_vul = self.get_object()
     expire = request.GET.get('expire', "")
     task_id = tasks.stop_container_task(container_vul=container_vul,
                                         user_info=user_info,
                                         request_ip=get_request_ip(request))
     setting_config = get_setting_config()
     del_container = setting_config['del_container']
     if expire != "" and expire == "true":
         if not del_container or del_container == 0 or del_container == '0':
             pass
         else:
             tasks.delete_container_task(container_vul=container_vul,
                                         user_info=user_info,
                                         request_ip=get_request_ip(request))
     return JsonResponse(R.ok(task_id))