mirror of
https://github.com/Tygs/0bin.git
synced 2023-08-10 21:13:00 +03:00
Added paste size limitation
This commit is contained in:
parent
658149240e
commit
08032470c9
@ -25,4 +25,8 @@ DEV_PORT= "8000"
|
|||||||
# User and group the server should run as. Set to None if it should be the
|
# User and group the server should run as. Set to None if it should be the
|
||||||
# current user
|
# current user
|
||||||
USER = None
|
USER = None
|
||||||
GROUP = None
|
GROUP = None
|
||||||
|
|
||||||
|
# limit size of pasted text in bytes. Be carefull allowing too much size can slow down user's
|
||||||
|
# browser
|
||||||
|
MAX_SIZE = 500 * 1
|
6
start.py
6
start.py
@ -12,6 +12,7 @@ import thread
|
|||||||
import time
|
import time
|
||||||
import tempfile
|
import tempfile
|
||||||
import glob
|
import glob
|
||||||
|
import math
|
||||||
|
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
|
|
||||||
@ -30,11 +31,14 @@ from bottle import (Bottle, route, run, abort,
|
|||||||
|
|
||||||
app = Bottle()
|
app = Bottle()
|
||||||
|
|
||||||
|
import settings
|
||||||
|
|
||||||
|
|
||||||
@app.route('/')
|
@app.route('/')
|
||||||
@view('home')
|
@view('home')
|
||||||
def index():
|
def index():
|
||||||
return {}
|
max_size_kb = int(math.ceil(settings.MAX_SIZE/1024.0))
|
||||||
|
return {'max_size': settings.MAX_SIZE, 'max_size_kb': max_size_kb}
|
||||||
|
|
||||||
|
|
||||||
@app.route('/paste/create', method='POST')
|
@app.route('/paste/create', method='POST')
|
||||||
|
@ -106,6 +106,7 @@ h4#pixels-total {
|
|||||||
clear: both;
|
clear: both;
|
||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
|
margin-top: 40px;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Home */
|
/* Home */
|
||||||
@ -141,7 +142,11 @@ input.hide-upload {
|
|||||||
cursor: hand;
|
cursor: hand;
|
||||||
height: 49px;
|
height: 49px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.max-size-reached {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
/* Paste Page */
|
/* Paste Page */
|
||||||
|
|
||||||
.items {
|
.items {
|
||||||
|
@ -108,6 +108,19 @@ zerobin = {
|
|||||||
content_clone = content_clone + $(this).text() + '\n';
|
content_clone = content_clone + $(this).text() + '\n';
|
||||||
});
|
});
|
||||||
return content_clone;
|
return content_clone;
|
||||||
|
},
|
||||||
|
count: function(text, options) {
|
||||||
|
// Set option defaults
|
||||||
|
var crlf = /(\r?\n|\r)/g;
|
||||||
|
var whitespace = /(\r?\n|\r|\s+)/g;
|
||||||
|
options = options || {};
|
||||||
|
options.lineBreaks = options.lineBreaks || 1;
|
||||||
|
|
||||||
|
var length = text.length,
|
||||||
|
nonAscii = length - text.replace(/[\u0100-\uFFFF]/g, '').length,
|
||||||
|
lineBreaks = length - text.replace(crlf, '').length;
|
||||||
|
|
||||||
|
return length + nonAscii + Math.max(0, options.lineBreaks * (lineBreaks - 1));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -125,22 +138,32 @@ $('button[type=submit]').live("click", function(e){
|
|||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
var paste = $('textarea').val();
|
var paste = $('textarea').val();
|
||||||
|
|
||||||
if (paste.trim()) {
|
var sizebytes = zerobin.count($('#content').val(), { });
|
||||||
var expiration = $('#expiration').val();
|
|
||||||
var key = zerobin.make_key();
|
if (sizebytes > zerobin.max_size ){
|
||||||
var data = {content: zerobin.encrypt(key, paste), expiration: expiration}
|
|
||||||
|
$('.max-size-reached').show();
|
||||||
|
$('.file-size').text(Math.round(sizebytes/1024));
|
||||||
|
|
||||||
|
}else{
|
||||||
|
|
||||||
|
if (paste.trim()) {
|
||||||
|
var expiration = $('#expiration').val();
|
||||||
|
var key = zerobin.make_key();
|
||||||
|
var data = {content: zerobin.encrypt(key, paste), expiration: expiration}
|
||||||
|
|
||||||
|
$.post('/paste/create', data)
|
||||||
|
.error(function(error) {
|
||||||
|
alert('Paste could not be saved. Please try again later.');
|
||||||
|
})
|
||||||
|
.success(function(data) {
|
||||||
|
var paste_url = '/paste/' + data['paste'] + '#' + key;
|
||||||
|
window.location = (paste_url);
|
||||||
|
zerobin.store_paste(paste_url);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
$.post('/paste/create', data)
|
|
||||||
.error(function(error) {
|
|
||||||
alert('Paste could not be saved. Please try again later.');
|
|
||||||
})
|
|
||||||
.success(function(data) {
|
|
||||||
var paste_url = '/paste/' + data['paste'] + '#' + key;
|
|
||||||
window.location = (paste_url);
|
|
||||||
zerobin.store_paste(paste_url);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
/** On the display paste page.
|
/** On the display paste page.
|
||||||
@ -215,6 +238,7 @@ $('#content').live('keyup change', function(){
|
|||||||
$('.paste-option').clone().addClass('down').appendTo('form.well');
|
$('.paste-option').clone().addClass('down').appendTo('form.well');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
/* Display previous pastes */
|
/* Display previous pastes */
|
||||||
@ -265,6 +289,14 @@ $('#file-upload').mouseover(function(){
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
/* Alerts */
|
||||||
|
|
||||||
|
$(".close").click(function(){
|
||||||
|
$(this).parent().fadeOut();
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
@ -22,6 +22,9 @@
|
|||||||
<script src="/static/js/sjcl.js"></script>
|
<script src="/static/js/sjcl.js"></script>
|
||||||
<script src="/static/js/jquery-1.7.2.min.js"></script>
|
<script src="/static/js/jquery-1.7.2.min.js"></script>
|
||||||
<script src="/static/js/behavior.js"></script>
|
<script src="/static/js/behavior.js"></script>
|
||||||
|
<script type="text/javascript">
|
||||||
|
zerobin.max_size = {{ max_size }};
|
||||||
|
</script>
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
@ -81,10 +84,11 @@
|
|||||||
<strong>41,017,923,819</strong> pastes øbinned
|
<strong>41,017,923,819</strong> pastes øbinned
|
||||||
</h4>
|
</h4>
|
||||||
|
|
||||||
</br>
|
</br>
|
||||||
<p class="greetings span12">
|
<p class="greetings span12">
|
||||||
Based on an original idea from
|
Based on an original idea from
|
||||||
<a href="http://sebsauvage.net/paste/">sebsauvage.net</a>
|
<a href="http://sebsauvage.net/paste/">sebsauvage.net</a><br>
|
||||||
|
<a href="http://sametmax.com">Sam & Max</a>
|
||||||
</p>
|
</p>
|
||||||
</footer>
|
</footer>
|
||||||
|
|
||||||
|
@ -1,7 +1,13 @@
|
|||||||
<p class="file-upload">
|
<div class="alert alert-error max-size-reached">
|
||||||
|
<a class="close" data-dismiss="alert" href="#">×</a>
|
||||||
|
<strong>Warning!</strong><br>
|
||||||
|
Your file is <strong class="file-size"></strong>KB You have reached the maximum size limit of {{ max_size_kb }}KB.
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p class="file-upload">
|
||||||
<input type="button" class="btn btn-upload" value="Upload File">
|
<input type="button" class="btn btn-upload" value="Upload File">
|
||||||
<input type="file" class="hide-upload" id="file-upload" >
|
<input type="file" class="hide-upload" id="file-upload" >
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<form class="well" method="post" action="/paste/create">
|
<form class="well" method="post" action="/paste/create">
|
||||||
<p class="paste-option">
|
<p class="paste-option">
|
||||||
@ -22,4 +28,4 @@
|
|||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
|
||||||
%rebase base
|
%rebase base max_size=max_size
|
Loading…
Reference in New Issue
Block a user