def get_ip(req): body={} token = req.POST.get('private_token', None) reset = req.POST.get('reset', False) if token is None: body['msg'] = 'missing required parameter: private_token' return HttpResponse(encodejson(7, body), content_type="application/json") p_user_list = ProxyUser.objects.filter(token=token) if not p_user_list.exists(): body['msg'] = 'invalid private_token' return HttpResponse(encodejson(6, body), content_type="application/json") user = p_user_list[0] ip_list = Proxy.objects.all() ip_count = ip_list.count() req_list = [] reqed = user.record.split(',') for i in range(0, 5): r_num = random.randint(1, ip_count) proxy = ip_list[(r_num - 1)] if str(proxy.id) in reqed: r_num = random.randint(1, ip_count) proxy = ip_list[(r_num - 1)] ip_body={} ip_body['ip'] = proxy.ip ip_body['id'] = proxy.id ip_body['create_time'] = datetime_to_string(proxy.create_time) ip_body['modify_time'] = datetime_to_string(proxy.modify_time) req_list.append(copy.copy(ip_body)) if str(proxy.id) not in reqed: user.record = user.record + str(proxy.id) + ',' user.save() body['proxy_list'] = req_list return HttpResponse(encodejson(1, body), content_type="application/json")
def get_chart_message(req): body = {} now = timezone.now() start = now - datetime.timedelta(hours=23, minutes=59, seconds=59) record_list = ReqRecord.objects.filter( create_time__gt=start).values('uri').distinct() day_rec_list = [] day_rec_count = [] for itm in record_list: rec_count = ReqRecord.objects.filter(create_time__gt=start, uri=itm['uri']).count() day_rec_list.append(copy.copy(itm['uri'])) day_rec_count.append(copy.copy(rec_count)) body['req_rec'] = day_rec_list body['req_count'] = day_rec_count record_list = ReqRecord.objects.filter( create_time__gt=start).values('ip').distinct() day_ip_list = [] day_ip_count = [] for itm in record_list: ip_count = ReqRecord.objects.filter(create_time__gt=start, ip=itm['ip']).count() tip = AccIP.objects.get(id=itm['ip']).ip day_ip_list.append(copy.copy(tip)) day_ip_count.append(copy.copy(ip_count)) body['ip_rec'] = day_ip_list body['ip_count'] = day_ip_count return HttpResponse(encodejson(1, body), content_type="application/json")
def create_permission(req): body={} ip = req.META['REMOTE_ADDR'] token = create_token() new_user = ProxyUser(token=token, ip=ip) new_user.save() body['private_token'] = token return HttpResponse(encodejson(1, body), content_type="application/json")
def get_lab_info(req): body={} now = timezone.now() start = now - datetime.timedelta(hours=23, minutes=59, seconds=59) total_use = ProxyUser.objects.all().count() day_req = ReqRecord.objects.filter(uri='/lab/get_proxy/', create_time__gt=start).count() api_control = ReqRecord.objects.filter(create_time__gt=start).count() proxy_count = Proxy.objects.all().count() back_log = BackLog.objects.all() if back_log.exists(): back_log = back_log.order_by('-create_time') new_time = datetime_to_string(back_log[0].create_time) else: new_time = '未更新' body['api_control'] = api_control body['api_status'] = True body['total_user'] = total_use body['req_times'] = day_req body['proxy_num'] = proxy_count body['update_time'] = new_time return HttpResponse(encodejson(1, body), content_type="application/json")
def get_lab_info(req): body = {} now = timezone.now() start = now - datetime.timedelta(hours=23, minutes=59, seconds=59) total_use = ProxyUser.objects.all().count() day_req = ReqRecord.objects.filter(uri='/lab/get_proxy/', create_time__gt=start).count() api_control = ReqRecord.objects.filter(create_time__gt=start).count() proxy_count = Proxy.objects.all().count() back_log = BackLog.objects.all() if back_log.exists(): back_log = back_log.order_by('-create_time') new_time = datetime_to_string(back_log[0].create_time) else: new_time = '未更新' body['api_control'] = api_control body['api_status'] = True body['total_user'] = total_use body['req_times'] = day_req body['proxy_num'] = proxy_count body['update_time'] = new_time return HttpResponse(encodejson(1, body), content_type="application/json")
def get_chart_message(req): body = {} now = timezone.now() start = now - datetime.timedelta(hours=23, minutes=59, seconds=59) record_list = ReqRecord.objects.filter(create_time__gt=start).values('uri').distinct() day_rec_list = [] day_rec_count = [] for itm in record_list: rec_count = ReqRecord.objects.filter(create_time__gt=start, uri=itm['uri']).count() day_rec_list.append(copy.copy(itm['uri'])) day_rec_count.append(copy.copy(rec_count)) body['req_rec'] = day_rec_list body['req_count'] = day_rec_count record_list = ReqRecord.objects.filter(create_time__gt=start).values('ip').distinct() day_ip_list = [] day_ip_count = [] for itm in record_list: ip_count = ReqRecord.objects.filter(create_time__gt=start, ip=itm['ip']).count() tip = AccIP.objects.get(id=itm['ip']).ip day_ip_list.append(copy.copy(tip)) day_ip_count.append(copy.copy(ip_count)) body['ip_rec'] = day_ip_list body['ip_count'] = day_ip_count return HttpResponse(encodejson(1, body), content_type="application/json")