From 630e16c4a052d19fe328dfe1e23c2a224b74a4b5 Mon Sep 17 00:00:00 2001 From: Simon Rupf Date: Wed, 30 Oct 2013 23:54:42 +0100 Subject: [PATCH] =?UTF-8?q?Added=20more=20configuration=20options,=20based?= =?UTF-8?q?=20on=20patch=20by=20Uli=20K=C3=B6hler?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cfg/conf.ini | 40 ++++++++++++++++++++++++++++++++++- lib/trafficlimiter.php | 3 +++ lib/zerobin.php | 48 ++++++++++++++++++------------------------ tpl/page.html | 11 ++-------- tst/RainTPL.php | 16 +++++++++++++- 5 files changed, 80 insertions(+), 38 deletions(-) diff --git a/cfg/conf.ini b/cfg/conf.ini index 74acb0f..77c43ec 100644 --- a/cfg/conf.ini +++ b/cfg/conf.ini @@ -11,11 +11,49 @@ ; enable or disable discussions opendiscussion = true -; size limit per paste or comment in bytes +; enable or disable syntax highlighting +syntaxhighlighting = true + +; preselect the burn-after-reading feature by default +burnafterreadingselected = false + +; size limit per paste or comment in bytes, default is 2 Mibibytes sizelimit = 2097152 +[expire] +; expire value that is selected per default +; make sure the value exists in [expire_options] +default = "1month" + +[expire_options] +; Set each one of these to the number of seconds in the expiration period, +; or 0 if it should never expire +5min = 300 +10min = 600 +1hour = 3600 +1day = 86400 +1week = 604800 +; Well this is not *exactly* one month, it's 30 days: +1month = 2592000 +1year = 31536000 +never = 0 + +[expire_labels] +; descriptive labels for the expiration times +; must match those in [expire_options] +5min = "5 minutes" +10min = "10 minutes" +1hour = "1 hour" +1day = "1 day" +1week = "1 week" +1month = "1 month" +1year = "1 year" +never = "Never" + + [traffic] ; time limit between calls from the same IP address in seconds +; Set this to 0 to disable rate limiting. limit = 10 dir = PATH "data" diff --git a/lib/trafficlimiter.php b/lib/trafficlimiter.php index 3a2e8cd..9764fc1 100644 --- a/lib/trafficlimiter.php +++ b/lib/trafficlimiter.php @@ -69,6 +69,9 @@ class trafficlimiter */ public static function canPass($ip) { + // disable limits if set to less then 1 + if (self::$_limit < 1) return true; + // Create storage directory if it does not exist. if (!is_dir(self::$_path)) mkdir(self::$_path, 0705); // Create .htaccess file if it does not exist. diff --git a/lib/zerobin.php b/lib/zerobin.php index 754a7d1..1e57fbb 100644 --- a/lib/zerobin.php +++ b/lib/zerobin.php @@ -180,32 +180,14 @@ class zerobin // Read expiration date if (!empty($_POST['expire'])) { - switch ($_POST['expire']) - { - case 'burn': - $meta['burnafterreading'] = true; - break; - case '5min': - $meta['expire_date'] = time()+5*60; - break; - case '10min': - $meta['expire_date'] = time()+10*60; - break; - case '1hour': - $meta['expire_date'] = time()+60*60; - break; - case '1day': - $meta['expire_date'] = time()+24*60*60; - break; - case '1week': - $meta['expire_date'] = time()+7*24*60*60; - break; - case '1month': - $meta['expire_date'] = strtotime('+1 month'); - break; - case '1year': - $meta['expire_date'] = strtotime('+1 year'); + if ($_POST['expire'] == 'burn') { + $meta['burnafterreading'] = true; + } elseif (array_key_exists($_POST['expire'], $this->_conf['expire_options'])) { + $expire = $this->_conf['expire_options'][$_POST['expire']]; + } else { + $expire = $this->_conf['expire_options'][$this->_conf['expire']['default']]; } + if ($expire > 0) $meta['expire_date'] = time() + $expire; } // Read open discussion flag. @@ -405,12 +387,24 @@ class zerobin header('Last-Modified: ' . $time); header('Vary: Accept'); + // label all the expiration options + $expire = array(); + foreach ($this->_conf['expire_options'] as $key => $value) { + $expire[$key] = array_key_exists($key, $this->_conf['expire_labels']) ? + $this->_conf['expire_labels'][$key] : + $key; + } + $page = new RainTPL; - // We escape it here because ENT_NOQUOTES can't be used in RainTPL templates. + // we escape it here because ENT_NOQUOTES can't be used in RainTPL templates $page->assign('CIPHERDATA', htmlspecialchars($this->_data, ENT_NOQUOTES)); $page->assign('ERRORMESSAGE', $this->_error); - $page->assign('OPENDISCUSSION', $this->_conf['main']['opendiscussion']); $page->assign('VERSION', self::VERSION); + $page->assign('BURNAFTERREADINGSELECTED', $this->_conf['main']['burnafterreadingselected']); + $page->assign('OPENDISCUSSION', $this->_conf['main']['opendiscussion']); + $page->assign('SYNTAXHIGHLIGHTING', $this->_conf['main']['syntaxhighlighting']); + $page->assign('EXPIRE', $expire); + $page->assign('EXPIREDEFAULT', $this->_conf['expire']['default']); $page->draw('page'); } diff --git a/tpl/page.html b/tpl/page.html index a11721c..652e6d4 100644 --- a/tpl/page.html +++ b/tpl/page.html @@ -51,15 +51,8 @@ diff --git a/tst/RainTPL.php b/tst/RainTPL.php index bbea6f6..fb9a293 100644 --- a/tst/RainTPL.php +++ b/tst/RainTPL.php @@ -5,6 +5,14 @@ class RainTPLTest extends PHPUnit_Framework_TestCase private static $error = 'foo bar'; + private static $expire = array( + '5min' => '5 minutes', + '1hour' => '1 hour', + 'never' => 'Never', + ); + + private static $expire_default = '1hour'; + private static $version = 'Version 1.2.3'; private $_content; @@ -14,11 +22,17 @@ class RainTPLTest extends PHPUnit_Framework_TestCase /* Setup Routine */ $page = new RainTPL; $page::configure(array('cache_dir' => 'tmp/')); + + $page = new RainTPL; // We escape it here because ENT_NOQUOTES can't be used in RainTPL templates. $page->assign('CIPHERDATA', htmlspecialchars(self::$data, ENT_NOQUOTES)); $page->assign('ERRORMESSAGE', self::$error); - $page->assign('OPENDISCUSSION', false); $page->assign('VERSION', self::$version); + $page->assign('BURNAFTERREADINGSELECTED', false); + $page->assign('OPENDISCUSSION', false); + $page->assign('SYNTAXHIGHLIGHTING', true); + $page->assign('EXPIRE', self::$expire); + $page->assign('EXPIREDEFAULT', self::$expire_default); ob_start(); $page->draw('page'); $this->_content = ob_get_contents();