Esempio n. 1
0
    def getuserinfo(self, request):
        user = request.user
        user_obj = User.objects.get(username=user)

        data = get_menus_by_user(user)

        if len(data) > 0:
            topmenuid = data[0].parent_id
            if not topmenuid:
                topmenuid = data[0].id

        menus = set_menu(data, topmenuid)

        ip = request.META.get("HTTP_X_FORWARDED_FOR", "")
        if not ip:
            ip = request.META.get('REMOTE_ADDR', "")

        data = {
            'menus': menus,
            'username': user_obj.username,
            'avatar': user_obj.avatar,
            'memo': user_obj.memo,
            'ip': ip,
            'user_id': user_obj.id
        }
        return JsonResponse(
            OrderedDict([('results', data)], code=status.HTTP_200_OK))
Esempio n. 2
0
    def send(self, request, *args, **kwargs):
        self.watch_audit_log(request)
        data = {'code': 20000, 'msg': 'null'}
        type = request.GET['type']
        if type == 'mail':
            bot_name = request.GET['bot_name']
            bot_obj = MailBot.objects.get(name=bot_name)
            subject = "{}".format(request.form['subject'])
            mail_to = bot_obj.to
            mail_host = bot_obj.host
            mail_user = '******'.format(bot_obj.user, bot_obj.host)
            mail_pass = bot_obj.pasword
            content = request.data.get('content', 'Hello Pornhub')
            send_mail.delay(subject, mail_to, mail_host, mail_user, mail_pass,
                            content)
        elif type == 'telegram':
            bot_name = request.GET['bot_name']
            content = request.data.get('content', 'Hello Pornhub')
            bot_obj = TelegramBot.objects.get(name=bot_name)
            send_telegram.delay(chat_id=bot_obj.chat_id, text=content)
        else:
            pass

        return JsonResponse(
            OrderedDict([('results', data)], code=status.HTTP_200_OK))
Esempio n. 3
0
    def send(self, request, *args, **kwargs):
        self.watch_audit_log(request)
        data = {'code': 20000, 'msg': 'null'}
        type = request.GET['type']
        if type == 'mail':
            import smtplib
            from email.mime.text import MIMEText

            bot_name = request.GET['bot_name']
            bot_obj = MailBot.objects.get(name=bot_name)
            mail_user = '******'.format(bot_obj.user, bot_obj.host)

            tos = bot_obj.to
            content = request.data.get('content', 'Hello Pornhub')
            message = MIMEText(content, 'plain', 'utf-8')
            message['Subject'] = "{}".format(request.form['subject'])
            message['From'] = mail_user
            message['To'] = tos[0:]

            try:
                smtpObj = smtplib.SMTP_SSL(bot_obj.host)
                smtpObj.login(mail_user, bot_obj.pasword)
                smtpObj.sendmail(mail_user, tos, message.as_string())
                smtpObj.quit()
            except smtplib.SMTPException as e:
                print(e)
                data['msg'] = 'error'
        else:
            pass

        return JsonResponse(
            OrderedDict([('results', data)], code=status.HTTP_200_OK))
Esempio n. 4
0
    def flush(self, request, *args, **kwargs):
        tasks = TaskLog.objects.filter(Q(status=1) | Q(status=2))
        for j in tasks:
            job = jj.get_job(j.code)
            try:
                job_build = job.get_build(int(j.build_id))
                j_status = job_build.is_running()
                if j_status is None:
                    j.status = 2
                    j.save()
                    continue
                if j_status:
                    j.status = 2
                    j.save()
                else:
                    if job_build.is_good:
                        j.status = 3
                    else:
                        j.status = 4
                    j.save()
            except:
                j.status = 2
                j.save()

        data = {'code': 20000, 'count': len(tasks)}
        return JsonResponse(OrderedDict([
            ('results', data)
        ], code=status.HTTP_200_OK))
Esempio n. 5
0
    def post(self, request, *args, **kwargs):
        serializer = self.get_serializer(data=request.data)

        if serializer.is_valid():
            user = serializer.object.get('user') or request.user
            token = serializer.object.get('token')
            response_data = jwt_response_payload_handler(token, user, request)
            response = JsonResponse(
                OrderedDict([('results', response_data)],
                            code=status.HTTP_200_OK))
            if api_settings.JWT_AUTH_COOKIE:
                expiration = (datetime.utcnow() +
                              api_settings.JWT_EXPIRATION_DELTA)
                response.set_cookie(api_settings.JWT_AUTH_COOKIE,
                                    token,
                                    expires=expiration,
                                    httponly=True)
            return response

        return JsonResponse(
            OrderedDict([('results', serializer.errors)],
                        code=status.HTTP_500_INTERNAL_SERVER_ERROR))
Esempio n. 6
0
 def ping(self, request, *args, **kwargs):
     self.watch_audit_log(request)
     job_name = 'ping'
     num = request.data['num']
     job = jj.get_job(job_name)
     build_id = job.get_next_build_number()
     params = {"num": num}
     job.invoke(build_params=params)
     TaskLog.objects.create(name='ping测试', code=job_name, build_id=build_id, params=params)
     data = {'code': 20000, 'build_id': build_id}
     return JsonResponse(OrderedDict([
         ('results', data)
     ], code=status.HTTP_200_OK))
Esempio n. 7
0
 def stop(self, request, *args, **kwargs):
     self.watch_audit_log(request)
     job_name = request.data['code']
     build_id = request.data['build_id']
     job = jj.get_job(job_name)
     job_build = job.get_build(int(build_id))
     s = job_build.stop()
     print(s)
     j = TaskLog.objects.get(code=job_name, build_id=build_id)
     j.status = 4
     j.save()
     data = {'code': 20000, 'build_id': build_id}
     return JsonResponse(OrderedDict([
         ('results', data)
     ], code=status.HTTP_200_OK))
Esempio n. 8
0
    def getmenubutons(self, request):
        user = request.user
        user_obj = User.objects.get(username=user)
        buttons = []

        if user_obj.is_admin:
            buttons = ['add', 'del', 'update', 'view']
        else:
            menucode = request.GET['menucode']

            match_menu = Menu.objects.get(code=menucode)

            data = get_menus_by_user(user)
            for item in data:
                if item.parent_id == match_menu.id:
                    buttons.append(item.operate)
        data = buttons
        return JsonResponse(
            OrderedDict([('results', data)], code=status.HTTP_200_OK))
Esempio n. 9
0
    def post(self, request, *args, **kwargs):

        data = request.data
        serializer = self.get_serializer(data=data)
        serializer.is_valid(raise_exception=True)
        validated_data = serializer.validated_data

        search_text = validated_data['search_text']
        video_amount = validated_data['video_amount']
        project_id = self.kwargs['project_id']
        yt_filters = validated_data['yt_filters']
        vimeo_filters = validated_data['vimeo_filters']
        vimeo_client = TsdVimeoClient(video_amount)
        vimeo_result = vimeo_client.search(search_text, **vimeo_filters)
        yt_client = TsdYoutubeClient(video_amount)
        yt_result = yt_client.search(search_text, **yt_filters)
        #data_out = self.make_output_data(vimeo_result, None)
        self.save_data_to_db(project_id, vimeo_result, yt_result)
        data_out = {}
        print(data_out)
        return JsonResponse(data_out)