def report_upload(request): try: decompressed = zlib.decompress(request.body) post = QueryDict(decompressed) except zlib.error: # If zlib can't decode it, assume it's an uncompressed POST post = request.POST try: post_time = convert_to_int(post['time']) post_version = convert_to_int(post['version']) if post_time is None or post_version is None: return HttpResponseBadRequest('The "time" or "version" fields are not integers\n', content_type='text/plain') user_id = post['user_id'] generation_date = datetime.datetime.utcfromtimestamp(post_time) data_type = post['type'] data_version = post_version data = post['data'] except KeyError: return HttpResponseBadRequest('Missing required fields.\n', content_type='text/plain') uploader = request.META['REMOTE_ADDR'] # Fix the IP address if running via proxy on localhost if uploader == '127.0.0.1': try: uploader = request.META['HTTP_X_FORWARDED_FOR'].split(',')[0].strip() except KeyError: pass user_id_hash = hashlib.sha1(user_id.encode('utf-8')).hexdigest() report = UserReport( uploader=uploader, user_id_hash=user_id_hash, generation_date=generation_date, data_type=data_type, data_version=data_version, data=data ) report.save() return HttpResponse('OK', content_type='text/plain')
def Upload(request): try: decompressed = zlib.decompress(request.body) except zlib.error: return HttpResponseBadRequest('Invalid POST data.\n', content_type='text/plain') POST = QueryDict(decompressed) try: user_id = POST['user_id'] generation_date = datetime.datetime.utcfromtimestamp(int(POST['time'])) data_type = POST['type'] data_version = int(POST['version']) data = POST['data'] except KeyError as e: return HttpResponseBadRequest('Missing required fields.\n', content_type='text/plain') uploader = request.META['REMOTE_ADDR'] # Fix the IP address if running via proxy on localhost if uploader == '127.0.0.1': try: uploader = request.META['HTTP_X_FORWARDED_FOR']\ .split(',')[0].strip() except KeyError: pass user_id_bytes = user_id.encode('utf-8') user_id_hash = hashlib.sha1(user_id_bytes).hexdigest() report = UserReport( uploader=uploader, user_id_hash=user_id_hash, generation_date=generation_date, data_type=data_type, data_version=data_version, data=data ) report.save() return HttpResponse('OK', content_type='text/plain')
return HttpResponseBadRequest('Missing required fields.\n', content_type = 'text/plain') uploader = request.META['REMOTE_ADDR'] # Fix the IP address if running via proxy on localhost if uploader == '127.0.0.1': try: uploader = request.META['HTTP_X_FORWARDED_FOR'].split(',')[0].strip() except KeyError: pass user_id_hash = hashlib.sha1(user_id).hexdigest() report = UserReport( uploader = uploader, user_id_hash = user_id_hash, generation_date = generation_date, data_type = data_type, data_version = data_version, data = data ) report.save() return HttpResponse('OK', content_type = 'text/plain') def index(request): return render_to_response('index.html') def report_cpu(request): reports = UserReport_hwdetect.objects reports = reports.filter(data_type = 'hwdetect', data_version__gte = 4, data_version__lte = 5)
content_type='text/plain') uploader = request.META['REMOTE_ADDR'] # Fix the IP address if running via proxy on localhost if uploader == '127.0.0.1': try: uploader = request.META['HTTP_X_FORWARDED_FOR'].split( ',')[0].strip() except KeyError: pass user_id_hash = hashlib.sha1(user_id).hexdigest() report = UserReport(uploader=uploader, user_id_hash=user_id_hash, generation_date=generation_date, data_type=data_type, data_version=data_version, data=data) report.save() return HttpResponse('OK', content_type='text/plain') def index(request): return render_to_response('index.html') def report_cpu(request): reports = UserReport_hwdetect.objects reports = reports.filter(data_type='hwdetect', data_version__gte=4,