diff --git a/config.inc.php b/config.inc.php
new file mode 100644
index 00000000..e921a1ce
--- /dev/null
+++ b/config.inc.php
@@ -0,0 +1,80 @@
+
\ No newline at end of file
diff --git a/index.php b/index.php
index 274c2c10..fe25d95a 100644
--- a/index.php
+++ b/index.php
@@ -5,6 +5,7 @@
*/
$VERSION='Alpha 0.19';
if (version_compare(PHP_VERSION, '5.2.6') < 0) die('ZeroBin requires php 5.2.6 or above to work. Sorry.');
+require_once "config.inc.php";
require_once "lib/serversalt.php";
require_once "lib/vizhash_gd_zero.php";
@@ -21,6 +22,12 @@ function stripslashes_deep($value) { $value = is_array($value) ? array_map('stri
// Will return false if IP address made a call less than 10 seconds ago.
function trafic_limiter_canPass($ip)
{
+ global $cfg;
+ $timeBetweenPosts = $cfg["timeBetweenPosts"];
+ // -1: no rate limiting
+ if($timeBetweenPosts == -1) {
+ return true;
+ }
$tfilename='./data/trafic_limiter.php';
if (!is_file($tfilename))
{
@@ -29,7 +36,7 @@ function trafic_limiter_canPass($ip)
}
require $tfilename;
$tl=$GLOBALS['trafic_limiter'];
- if (!empty($tl[$ip]) && ($tl[$ip]+10>=time()))
+ if (!empty($tl[$ip]) && ($tl[$ip] + $timeBetweenPosts >=time()))
{
return false;
// FIXME: purge file of expired IPs to keep it small
@@ -144,13 +151,17 @@ function deletePaste($pasteid)
}
// Make sure last paste from the IP address was more than 10 seconds ago.
- if (!trafic_limiter_canPass($_SERVER['REMOTE_ADDR']))
- { echo json_encode(array('status'=>1,'message'=>'Please wait 10 seconds between each post.')); exit; }
+ if (!trafic_limiter_canPass($_SERVER['REMOTE_ADDR'])) {
+ $timeBetweenPosts = $cfg['timeBetweenPosts'];
+ echo json_encode(array('status'=>1,'message'=>"Please wait $timeBetweenPosts seconds between each post."));
+ exit;
+ }
// Make sure content is not too big.
$data = $_POST['data'];
- if (strlen($data)>2000000)
- { echo json_encode(array('status'=>1,'message'=>'Paste is limited to 2 Mb of encrypted data.')); exit; }
+ $maxPostSize = $cfg["maxPostSize"];
+ if (strlen($data) > $maxPostSize)
+ { echo json_encode(array('status'=>1,'message'=>"Paste is limited to $maxPostSize bytes of encrypted data.")); exit; }
// Make sure format is correct.
if (!validSJCL($data))
@@ -160,16 +171,20 @@ function deletePaste($pasteid)
$meta=array();
// Read expiration date
- if (!empty($_POST['expire']))
- {
- $expire=$_POST['expire'];
- if ($expire=='5min') $meta['expire_date']=time()+5*60;
- elseif ($expire=='10min') $meta['expire_date']=time()+10*60;
- elseif ($expire=='1hour') $meta['expire_date']=time()+60*60;
- elseif ($expire=='1day') $meta['expire_date']=time()+24*60*60;
- elseif ($expire=='1week') $meta['expire_date']=time()+7*24*60*60;
- elseif ($expire=='1month') $meta['expire_date']=time()+30*24*60*60; // Well this is not *exactly* one month, it's 30 days.
- elseif ($expire=='1year') $meta['expire_date']=time()+365*24*60*60;
+ $expire=$_POST['expire'];
+ if(array_key_exists($expire, $cfg["expire"])) {
+ // Valid expiration info
+ $expireDelay = $cfg["expire"][$expire];
+ if($expireDelay != -1) { // -1 means never
+ $meta['expire_date'] = time() + $expireDelay;
+ }
+ } else {
+ // Use default for an invalid POST expire name.
+ // Will also be executed for empty keys
+ $expireDelay = $cfg["expire"][$cfg["expireDefault"]];
+ if($expireDelay != -1) { // -1 means never
+ $meta['expire_date'] = time() + $expireDelay;
+ }
}
// Destroy the paste when it is read.
@@ -181,7 +196,7 @@ function deletePaste($pasteid)
}
// Read open discussion flag
- if (!empty($_POST['opendiscussion']))
+ if (!empty($_POST['opendiscussion']) && $cfg["enableDiscussionSystem"])
{
$opendiscussion = $_POST['opendiscussion'];
if ($opendiscussion!='0' && $opendiscussion!='1') { $error=true; }
@@ -189,7 +204,7 @@ function deletePaste($pasteid)
}
// Should we use syntax coloring when displaying ?
- if (!empty($_POST['syntaxcoloring']))
+ if (!empty($_POST['syntaxcoloring']) && $cfg["enableSyntaxHighlighting"])
{
$syntaxcoloring = $_POST['syntaxcoloring'];
if ($syntaxcoloring!='0' && $syntaxcoloring!='1') { $error=true; }
@@ -287,7 +302,7 @@ function deletePaste($pasteid)
// The paste can be delete by calling http://myserver.com/zerobin/?pasteid=