def create_paste(): try: body = urlparse.parse_qs( request.body.read(int(settings.MAX_SIZE * 1.1))) except ValueError: return {'status': 'error', 'message': u"Wrong data payload."} try: content = unicode(''.join(body['content']), 'utf8') except (UnicodeDecodeError, KeyError): return { 'status': 'error', 'message': u"Encoding error: the paste couldn't be saved." } if '{"iv":' not in content: # reject silently non encrypted content return {'status': 'error', 'message': u"Wrong data payload."} if content: # check size of the paste. if more than settings return error # without saving paste. prevent from unusual use of the # system. need to be improved if len(content) < settings.MAX_SIZE: expiration = body.get('expiration', [u'burn_after_reading'])[0] paste = Paste(expiration=expiration, content=content, uuid_length=settings.PASTE_ID_LENGTH) paste.save() # display counter if settings.DISPLAY_COUNTER: #increment paste counter paste.increment_counter() # if refresh time elapsed pick up new counter value now = datetime.now() timeout = (GLOBAL_CONTEXT['refresh_counter'] + timedelta(seconds=settings.REFRESH_COUNTER)) if timeout < now: GLOBAL_CONTEXT['pastes_count'] = Paste.get_pastes_count() GLOBAL_CONTEXT['refresh_counter'] = now return {'status': 'ok', 'paste': paste.uuid} return { 'status': 'error', 'message': u"Serveur error: the paste couldn't be saved. " u"Please try later." }
def callback(ch, method, properties, body): """ This function will be triggered when an element enter the pastebin_downloader queue. Paste object will be create in order to save the content of the Paste in a text file stored at "tmp/pastebin/<filename>". Then the filename is sent to the queue "pastebin_parser". """ msg = f"Data {body} received from queue {lc.DOWNLOADER_QUEUE}" if gc.DEBUG: log_info('downloader', msg) time.sleep(lc.DOWNLOADING_SLEEP + random.choice(lc.DOWNLOADING_DELAY)) scrape_url = json.loads(body)['scrape_url'] r = requests.get(url=scrape_url) if r.status_code != 200: msg = f"Connection error: GET:{scrape_url}, Status:{r.status_code}" log_info('downloader', msg) return file = Paste(metadata=body, data=r.text) filename = file.save() ch.basic_ack(delivery_tag=method.delivery_tag) publish(module='downloader', channel=ch, data=filename, queue=lc.PARSER_QUEUE)
def create_paste(): try: body = urlparse.parse_qs(request.body.read(int(settings.MAX_SIZE * 1.1))) except ValueError: return {'status': 'error', 'message': u"Wrong data payload."} try: content = unicode(''.join(body['content']), 'utf8') except (UnicodeDecodeError, KeyError): return {'status': 'error', 'message': u"Encoding error: the paste couldn't be saved."} if '{"iv":' not in content: # reject silently non encrypted content return {'status': 'error', 'message': u"Wrong data payload."} if content: # check size of the paste. if more than settings return error # without saving paste. prevent from unusual use of the # system. need to be improved if len(content) < settings.MAX_SIZE: expiration = body.get('expiration', [u'burn_after_reading'])[0] paste = Paste(expiration=expiration, content=content, uuid_length=settings.PASTE_ID_LENGTH) paste.save() # display counter if settings.DISPLAY_COUNTER: #increment paste counter paste.increment_counter() # if refresh time elapsed pick up new counter value now = datetime.now() timeout = (GLOBAL_CONTEXT['refresh_counter'] + timedelta(seconds=settings.REFRESH_COUNTER)) if timeout < now: GLOBAL_CONTEXT['pastes_count'] = Paste.get_pastes_count() GLOBAL_CONTEXT['refresh_counter'] = now return {'status': 'ok', 'paste': paste.uuid} return {'status': 'error', 'message': u"Serveur error: the paste couldn't be saved. " u"Please try later."}
def create_paste(): try: content = unicode(request.forms.get('content', ''), 'utf8') except UnicodeDecodeError: return {'status': 'error', 'message': u"Encoding error: the paste couldn't be saved."} if '{"iv":' not in content: # reject silently non encrypted content return '' if content: # check size of the paste. if more than settings return error without saving paste. # prevent from unusual use of the system. # need to be improved if len(content) < settings.MAX_SIZE: expiration = request.forms.get('expiration', u'burn_after_reading') paste = Paste(expiration=expiration, content=content) paste.save() # display counter if settings.DISPLAY_COUNTER: #increment paste counter paste.increment_counter() # if refresh time elapsed pick up new counter value now = datetime.now() timeout = (GLOBAL_CONTEXT['refresh_counter'] + timedelta(seconds=settings.REFRESH_COUNTER)) if timeout < now: GLOBAL_CONTEXT['pastes_count'] = Paste.get_pastes_count() GLOBAL_CONTEXT['refresh_counter'] = now return {'status': 'ok', 'paste': paste.uuid} return {'status': 'error', 'message': u"Serveur error: the paste couldn't be saved. Please try later."}
def create_paste(): try: body = urlparse.parse_qs(request.body.read(int(settings.MAX_SIZE * 1.1))) except ValueError: return {"status": "error", "message": u"Wrong data payload."} try: content = unicode("".join(body["content"]), "utf8") except (UnicodeDecodeError, KeyError): return {"status": "error", "message": u"Encoding error: the paste couldn't be saved."} if '{"iv":' not in content: # reject silently non encrypted content return {"status": "error", "message": u"Wrong data payload."} if content: # check size of the paste. if more than settings return error # without saving paste. prevent from unusual use of the # system. need to be improved if len(content) < settings.MAX_SIZE: expiration = body.get("expiration", [u"burn_after_reading"])[0] paste = Paste(expiration=expiration, content=content) paste.save() # display counter if settings.DISPLAY_COUNTER: # increment paste counter paste.increment_counter() # if refresh time elapsed pick up new counter value now = datetime.now() timeout = GLOBAL_CONTEXT["refresh_counter"] + timedelta(seconds=settings.REFRESH_COUNTER) if timeout < now: GLOBAL_CONTEXT["pastes_count"] = Paste.get_pastes_count() GLOBAL_CONTEXT["refresh_counter"] = now return {"status": "ok", "paste": paste.uuid} return {"status": "error", "message": u"Serveur error: the paste couldn't be saved. " u"Please try later."}
def create_paste(): try: content = unicode(request.forms.get('content', ''), 'utf8') except UnicodeDecodeError: return {'status': 'error', 'message': u"Encoding error: the paste couldn't be saved."} if '{"iv":' not in content: # reject silently non encrypted content return '' if content: # check size of the paste. if more than settings return error without saving paste. # prevent from unusual use of the system. # need to be improved if len(content) < settings.MAX_SIZE: expiration = request.forms.get('expiration', u'burn_after_reading') paste = Paste(expiration=expiration, content=content) paste.save() return {'status': 'ok', 'paste': paste.uuid} return {'status': 'error', 'message': u"Serveur error: the paste couldn't be saved. Please try later."}