mirror of
https://github.com/Tygs/0bin.git
synced 2023-08-10 21:13:00 +03:00
Merge #19 fix
This commit is contained in:
commit
d57595297e
@ -10,7 +10,7 @@
|
||||
import os
|
||||
import sys
|
||||
import thread
|
||||
|
||||
import urlparse
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
# add project dir and libs dir to the PYTHON PATH to ensure they are
|
||||
@ -48,22 +48,28 @@ def faq():
|
||||
|
||||
@app.route('/paste/create', method='POST')
|
||||
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(request.forms.get('content', ''), 'utf8')
|
||||
except UnicodeDecodeError:
|
||||
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 ''
|
||||
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
|
||||
# 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')
|
||||
expiration = body.get('expiration', [u'burn_after_reading'])[0]
|
||||
paste = Paste(expiration=expiration, content=content)
|
||||
paste.save()
|
||||
|
||||
|
@ -452,7 +452,7 @@ $('.btn-primary').live("click", function(e){
|
||||
bar.set('Sending...', '95%');
|
||||
var data = {content: content, expiration: expiration};
|
||||
var sizebytes = zerobin.count(JSON.stringify(data));
|
||||
var oversized = sizebytes > 95000; // 100kb - the others header information
|
||||
var oversized = sizebytes > zerobin.max_size; // 100kb - the others header information
|
||||
var readableFsize = Math.round(sizebytes / 1024);
|
||||
var readableMaxsize = Math.round(zerobin.max_size / 1024);
|
||||
|
||||
@ -461,7 +461,7 @@ $('.btn-primary').live("click", function(e){
|
||||
$form.prop('disabled', false);
|
||||
zerobin.message('error',
|
||||
('The encrypted file was <strong class="file-size">' + readableFsize +
|
||||
'</strong>KB. You have reached the maximum size limit of 93 KB.'),
|
||||
'</strong>KB. You have reached the maximum size limit of '+readableMaxsize+'KB.'),
|
||||
'Warning!', true);
|
||||
return;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user