From edf95ff56d35d29bebc8cfd29098a0f9c7ce9497 Mon Sep 17 00:00:00 2001 From: Simon Rupf Date: Mon, 30 Apr 2012 22:58:08 +0200 Subject: [PATCH] added autoloading, configurable paste size limit, changed JS to calculate localized comment times instead of UTC --- .gitignore | 3 + cfg/conf.ini | 5 +- css/prettify.css | 2 +- index.php | 3 +- js/zerobin.js | 13 +- lib/{rain.tpl.class.php => RainTPL.php} | 0 lib/auto.php | 35 +++++ lib/filter.php | 19 +++ ...traffic_limiter.php => trafficlimiter.php} | 2 +- lib/{vizhash_gd_zero.php => vizhash16x16.php} | 0 lib/zerobin.php | 12 +- lib/zerobin/abstract.php | 124 ++++++++++++++++++ lib/{zerobin_data.php => zerobin/data.php} | 35 +---- lib/{zerobin_db.php => zerobin/db.php} | 45 +------ 14 files changed, 207 insertions(+), 91 deletions(-) rename lib/{rain.tpl.class.php => RainTPL.php} (100%) create mode 100644 lib/auto.php rename lib/{traffic_limiter.php => trafficlimiter.php} (99%) rename lib/{vizhash_gd_zero.php => vizhash16x16.php} (100%) create mode 100644 lib/zerobin/abstract.php rename lib/{zerobin_data.php => zerobin/data.php} (90%) rename lib/{zerobin_db.php => zerobin/db.php} (75%) diff --git a/.gitignore b/.gitignore index fa0fe3f..69808c2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ # Ignore data/ and tmp/ data/ tmp/ +.settings/ +.buildpath +.project diff --git a/cfg/conf.ini b/cfg/conf.ini index 17687e5..cbfdaaf 100644 --- a/cfg/conf.ini +++ b/cfg/conf.ini @@ -7,10 +7,13 @@ ; @license http://www.opensource.org/licenses/zlib-license.php The zlib/libpng License ; @version 0.15 -; timelimit between calls from the same IP address in seconds +; time limit between calls from the same IP address in seconds traffic_limit = 10 traffic_dir = PATH "data" +; size limit per paste or comment in bytes +size_limit = 2000000 + ; name of data model class to load and directory for storage ; the default model "zerobin_data" stores everything in the filesystem model = zerobin_data diff --git a/css/prettify.css b/css/prettify.css index 536b45d..eaa0f86 100644 --- a/css/prettify.css +++ b/css/prettify.css @@ -32,7 +32,7 @@ } /* Put a border around prettyprinted code snippets. */ -pre.prettyprint { padding: 2px; border: 1px solid #888; background-color:white; } +pre.prettyprint { padding: 2px; border: 1px solid #888; background-color:white; white-space:pre-wrap; } /* Specify class=linenums on a pre to get line numbering */ ol.linenums { diff --git a/index.php b/index.php index 6b4835c..42576dc 100644 --- a/index.php +++ b/index.php @@ -12,5 +12,6 @@ // change this, if your php files and data is outside of your webservers document root define('PATH', ''); -require_once PATH . 'lib/zerobin.php'; + +require PATH . 'lib/auto.php'; new zerobin; diff --git a/js/zerobin.js b/js/zerobin.js index 5dc7551..d243dc5 100644 --- a/js/zerobin.js +++ b/js/zerobin.js @@ -1,8 +1,12 @@ /** - * ZeroBin 0.15 + * ZeroBin * - * @link http://sebsauvage.net/wiki/doku.php?id=php:zerobin - * @author sebsauvage + * a zero-knowledge paste bin + * + * @link http://sebsauvage.net/wiki/doku.php?id=php:zerobin + * @copyright 2012 Sébastien SAUVAGE (sebsauvage.net) + * @license http://www.opensource.org/licenses/zlib-license.php The zlib/libpng License + * @version 0.15 */ // Immediately start random number generator collector. @@ -157,7 +161,7 @@ function displayMessages(key, comments) { try { divComment.find('span.nickname').text(zeroDecipher(key, comment.meta.nickname)); } catch(err) { } - divComment.find('span.commentdate').text(' ('+(new Date(comment.meta.postdate*1000).toUTCString())+')').attr('title','CommentID: ' + comment.meta.commentid); + divComment.find('span.commentdate').text(' ('+(new Date(comment.meta.postdate*1000).toString())+')').attr('title','CommentID: ' + comment.meta.commentid); // If an avatar is available, display it. if (comment.meta.vizhash) { @@ -185,7 +189,6 @@ function open_reply(source, commentid) { + '
 
' + ''); $('input#nickname').focus(function() { - $(this).css('color', '#000'); if ($(this).val() == $(this).attr('title')) { $(this).val(''); } diff --git a/lib/rain.tpl.class.php b/lib/RainTPL.php similarity index 100% rename from lib/rain.tpl.class.php rename to lib/RainTPL.php diff --git a/lib/auto.php b/lib/auto.php new file mode 100644 index 0000000..53c62c9 --- /dev/null +++ b/lib/auto.php @@ -0,0 +1,35 @@ + 1 ) { + $size = $size / 1024; + $i++; + } + return number_format($size, 2, ".", " ") . ' ' . $iec[$i]; + } } diff --git a/lib/traffic_limiter.php b/lib/trafficlimiter.php similarity index 99% rename from lib/traffic_limiter.php rename to lib/trafficlimiter.php index dbf7c66..2fcfce4 100644 --- a/lib/traffic_limiter.php +++ b/lib/trafficlimiter.php @@ -15,7 +15,7 @@ * * Handles traffic limiting, so no user does more than one call per 10 seconds. */ -class traffic_limiter +class trafficlimiter { /** * @access private diff --git a/lib/vizhash_gd_zero.php b/lib/vizhash16x16.php similarity index 100% rename from lib/vizhash_gd_zero.php rename to lib/vizhash16x16.php diff --git a/lib/zerobin.php b/lib/zerobin.php index 6492ae4..899948f 100644 --- a/lib/zerobin.php +++ b/lib/zerobin.php @@ -63,7 +63,6 @@ class zerobin // In case stupid admin has left magic_quotes enabled in php.ini. if (get_magic_quotes_gpc()) { - require_once PATH . 'lib/filter.php'; $_POST = array_map('filter::stripslashes_deep', $_POST); $_GET = array_map('filter::stripslashes_deep', $_GET); $_COOKIE = array_map('filter::stripslashes_deep', $_COOKIE); @@ -118,7 +117,6 @@ class zerobin { // if needed, initialize the model if(is_string($this->_model)) { - require_once PATH . 'lib/' . $this->_model . '.php'; $this->_model = forward_static_call(array($this->_model, 'getInstance'), $this->_conf['model_options']); } return $this->_model; @@ -146,11 +144,10 @@ class zerobin $error = false; // Make sure last paste from the IP address was more than 10 seconds ago. - require_once PATH . 'lib/traffic_limiter.php'; - traffic_limiter::setLimit($this->_conf['traffic_limit']); - traffic_limiter::setPath($this->_conf['traffic_dir']); + trafficlimiter::setLimit($this->_conf['traffic_limit']); + trafficlimiter::setPath($this->_conf['traffic_dir']); if ( - !traffic_limiter::canPass($_SERVER['REMOTE_ADDR']) + !trafficlimiter::canPass($_SERVER['REMOTE_ADDR']) ) $this->_return_message(1, 'Please wait 10 seconds between each post.'); // Make sure content is not too big. @@ -160,7 +157,6 @@ class zerobin ) $this->_return_message(1, 'Paste is limited to 2 MB of encrypted data.'); // Make sure format is correct. - require_once PATH . 'lib/sjcl.php'; if (!sjcl::isValid($data)) $this->_return_message(1, 'Invalid data.'); // Read additional meta-information. @@ -219,7 +215,6 @@ class zerobin } else { - require_once PATH . 'lib/vizhash_gd_zero.php'; $meta['nickname'] = $nick; $vz = new vizhash16x16(); $pngdata = $vz->generate($_SERVER['REMOTE_ADDR']); @@ -381,7 +376,6 @@ class zerobin */ private function _view() { - require_once PATH . 'lib/rain.tpl.class.php'; header('Content-Type: text/html; charset=utf-8'); $page = new RainTPL; // We escape it here because ENT_NOQUOTES can't be used in RainTPL templates. diff --git a/lib/zerobin/abstract.php b/lib/zerobin/abstract.php new file mode 100644 index 0000000..89794ef --- /dev/null +++ b/lib/zerobin/abstract.php @@ -0,0 +1,124 @@ +