removed leftovers from submodule uglifyjs, added credits file,
cleaned up CSS, changed template to output clean XHTML 5, added unit tests for 60% of the code, found a few bugs by doing that and fixed them
This commit is contained in:
@@ -29,7 +29,10 @@ class auto
|
||||
*/
|
||||
public static function loader($class_name)
|
||||
{
|
||||
require_once PATH . 'lib/' . str_replace('_', '/', $class_name) . '.php';
|
||||
$filename = PATH . 'lib/' . str_replace('_', '/', $class_name) . '.php';
|
||||
if(is_readable($filename)) {
|
||||
return include $filename;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -42,12 +42,12 @@ class filter
|
||||
*/
|
||||
public static function size_humanreadable($size)
|
||||
{
|
||||
$i = 0;
|
||||
$iec = array('B', 'kiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB');
|
||||
while ( ( $size / 1024 ) > 1 ) {
|
||||
$i = 0;
|
||||
while ( ( $size / 1024 ) >= 1 ) {
|
||||
$size = $size / 1024;
|
||||
$i++;
|
||||
}
|
||||
return number_format($size, 2, ".", " ") . ' ' . $iec[$i];
|
||||
return number_format($size, ($i ? 2 : 0), '.', ' ') . ' ' . $iec[$i];
|
||||
}
|
||||
}
|
||||
|
||||
13
lib/sjcl.php
13
lib/sjcl.php
@@ -39,18 +39,15 @@ class sjcl
|
||||
// Make sure required fields are present and contain base64 data.
|
||||
foreach($accepted_keys as $k)
|
||||
{
|
||||
if (!array_key_exists($k, $decoded)) return false;
|
||||
if (is_null(base64_decode($decoded[$k], $strict=true))) return false;
|
||||
if (!(
|
||||
array_key_exists($k, $decoded) &&
|
||||
base64_decode($decoded[$k], $strict=true)
|
||||
)) return false;
|
||||
}
|
||||
|
||||
// Make sure no additionnal keys were added.
|
||||
if (
|
||||
count(
|
||||
array_intersect(
|
||||
array_keys($decoded),
|
||||
$accepted_keys
|
||||
)
|
||||
) != 3
|
||||
count(array_keys($decoded)) != count($accepted_keys)
|
||||
) return false;
|
||||
|
||||
// FIXME: Reject data if entropy is too low?
|
||||
|
||||
@@ -92,18 +92,19 @@ class trafficlimiter
|
||||
}
|
||||
|
||||
require $file;
|
||||
$now = time();
|
||||
$tl = $GLOBALS['traffic_limiter'];
|
||||
|
||||
// purge file of expired IPs to keep it small
|
||||
foreach($tl as $key => $time)
|
||||
{
|
||||
if ($time + 10 < time())
|
||||
if ($time + self::$_limit < $now)
|
||||
{
|
||||
unset($tl[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
if (array_key_exists($ip, $tl) && ($tl[$ip] + 10 >= time()))
|
||||
if (array_key_exists($ip, $tl) && ($tl[$ip] + self::$_limit >= $now))
|
||||
{
|
||||
$result = false;
|
||||
} else {
|
||||
|
||||
@@ -397,7 +397,21 @@ class zerobin
|
||||
*/
|
||||
private function _view()
|
||||
{
|
||||
header('Content-Type: text/html; charset=utf-8');
|
||||
// set headers to disable caching and return valid XHTML, if supported
|
||||
$content = (
|
||||
array_key_exists('HTTP_ACCEPT', $_SERVER) &&
|
||||
!empty($_SERVER['HTTP_ACCEPT']) &&
|
||||
stristr($_SERVER['HTTP_ACCEPT'], 'application/xhtml+xml') !== false
|
||||
) ? 'application/xhtml+xml' : 'text/html';
|
||||
$time = gmdate('D, d M Y H:i:s \G\M\T');
|
||||
|
||||
header('Cache-Control: no-store, no-cache, must-revalidate');
|
||||
header('Pragma: no-cache');
|
||||
header('Expires: ' . $time);
|
||||
header('Last-Modified: ' . $time);
|
||||
header('Vary: Accept');
|
||||
header('Content-Type: ' . $content . ';charset=UTF-8');
|
||||
|
||||
$page = new RainTPL;
|
||||
// We escape it here because ENT_NOQUOTES can't be used in RainTPL templates.
|
||||
$page->assign('CIPHERDATA', htmlspecialchars($this->_data, ENT_NOQUOTES));
|
||||
|
||||
@@ -51,7 +51,7 @@ abstract class zerobin_abstract
|
||||
* @static
|
||||
* @return zerobin_abstract
|
||||
*/
|
||||
abstract public static function getInstance($options);
|
||||
public static function getInstance($options) {}
|
||||
|
||||
/**
|
||||
* Create a paste.
|
||||
|
||||
@@ -37,13 +37,13 @@ class zerobin_data extends zerobin_abstract
|
||||
if (
|
||||
is_array($options) &&
|
||||
array_key_exists('dir', $options)
|
||||
) self::$_dir = $options['dir'] . '/';
|
||||
) self::$_dir = $options['dir'] . DIRECTORY_SEPARATOR;
|
||||
// if needed initialize the singleton
|
||||
if(null === parent::$_instance) {
|
||||
parent::$_instance = new self;
|
||||
if(!(self::$_instance instanceof zerobin_data)) {
|
||||
self::$_instance = new self;
|
||||
self::_init();
|
||||
}
|
||||
return parent::$_instance;
|
||||
return self::$_instance;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -59,7 +59,7 @@ class zerobin_data extends zerobin_abstract
|
||||
$storagedir = self::_dataid2path($pasteid);
|
||||
if (is_file($storagedir . $pasteid)) return false;
|
||||
if (!is_dir($storagedir)) mkdir($storagedir, 0705, true);
|
||||
return file_put_contents($storagedir . $pasteid, json_encode($paste));
|
||||
return (bool) file_put_contents($storagedir . $pasteid, json_encode($paste));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -67,13 +67,11 @@ class zerobin_data extends zerobin_abstract
|
||||
*
|
||||
* @access public
|
||||
* @param string $pasteid
|
||||
* @return string
|
||||
* @return stdClass|false
|
||||
*/
|
||||
public function read($pasteid)
|
||||
{
|
||||
if(!$this->exists($pasteid)) return json_decode(
|
||||
'{"data":"","meta":{"burnafterreading":true,"postdate":0}}'
|
||||
);
|
||||
if(!$this->exists($pasteid)) return false;
|
||||
return json_decode(
|
||||
file_get_contents(self::_dataid2path($pasteid) . $pasteid)
|
||||
);
|
||||
@@ -193,7 +191,7 @@ class zerobin_data extends zerobin_abstract
|
||||
{
|
||||
return is_file(
|
||||
self::_dataid2discussionpath($pasteid) .
|
||||
$pasteid . '.' . $dataid . '.' . $parentid
|
||||
$pasteid . '.' . $commentid . '.' . $parentid
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -56,8 +56,8 @@ class zerobin_db extends zerobin_abstract
|
||||
public static function getInstance($options = null)
|
||||
{
|
||||
// if needed initialize the singleton
|
||||
if(null === self::$_instance) {
|
||||
parent::$_instance = new self;
|
||||
if(!(self::$_instance instanceof zerobin_db)) {
|
||||
self::$_instance = new self;
|
||||
}
|
||||
|
||||
if (is_array($options))
|
||||
@@ -175,6 +175,16 @@ class zerobin_db extends zerobin_abstract
|
||||
*/
|
||||
public function create($pasteid, $paste)
|
||||
{
|
||||
if (
|
||||
array_key_exists($pasteid, self::$_cache)
|
||||
) {
|
||||
if(false !== self::$_cache[$pasteid]) {
|
||||
return false;
|
||||
} else {
|
||||
unset(self::$_cache[$pasteid]);
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
!array_key_exists('opendiscussion', $paste['meta'])
|
||||
) $paste['meta']['opendiscussion'] = false;
|
||||
@@ -199,31 +209,36 @@ class zerobin_db extends zerobin_abstract
|
||||
*
|
||||
* @access public
|
||||
* @param string $pasteid
|
||||
* @return string
|
||||
* @return stdClass|false
|
||||
*/
|
||||
public function read($pasteid)
|
||||
{
|
||||
if (
|
||||
!array_key_exists($pasteid, self::$_cache)
|
||||
) self::$_cache[$pasteid] = self::_select(
|
||||
'SELECT * FROM ' . self::$_prefix . 'paste WHERE dataid = ?',
|
||||
array($pasteid), true
|
||||
);
|
||||
) {
|
||||
self::$_cache[$pasteid] = false;
|
||||
$paste = self::_select(
|
||||
'SELECT * FROM ' . self::$_prefix . 'paste WHERE dataid = ?',
|
||||
array($pasteid), true
|
||||
);
|
||||
|
||||
// create object
|
||||
$paste = new stdClass;
|
||||
$paste->data = self::$_cache[$pasteid]['data'];
|
||||
$paste->meta = new stdClass;
|
||||
$paste->meta->postdate = (int) self::$_cache[$pasteid]['postdate'];
|
||||
$paste->meta->expire_date = (int) self::$_cache[$pasteid]['expiredate'];
|
||||
if (
|
||||
self::$_cache[$pasteid]['opendiscussion']
|
||||
) $paste->meta->opendiscussion = true;
|
||||
if (
|
||||
self::$_cache[$pasteid]['burnafterreading']
|
||||
) $paste->meta->burnafterreading = true;
|
||||
if(false !== $paste) {
|
||||
// create object
|
||||
self::$_cache[$pasteid] = new stdClass;
|
||||
self::$_cache[$pasteid]->data = $paste['data'];
|
||||
self::$_cache[$pasteid]->meta = new stdClass;
|
||||
self::$_cache[$pasteid]->meta->postdate = (int) $paste['postdate'];
|
||||
self::$_cache[$pasteid]->meta->expire_date = (int) $paste['expiredate'];
|
||||
if (
|
||||
$paste['opendiscussion']
|
||||
) self::$_cache[$pasteid]->meta->opendiscussion = true;
|
||||
if (
|
||||
$paste['burnafterreading']
|
||||
) self::$_cache[$pasteid]->meta->burnafterreading = true;
|
||||
}
|
||||
}
|
||||
|
||||
return $paste;
|
||||
return self::$_cache[$pasteid];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -243,6 +258,9 @@ class zerobin_db extends zerobin_abstract
|
||||
'DELETE FROM ' . self::$_prefix . 'comment WHERE pasteid = ?',
|
||||
array($pasteid)
|
||||
);
|
||||
if (
|
||||
array_key_exists($pasteid, self::$_cache)
|
||||
) unset(self::$_cache[$pasteid]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -256,10 +274,7 @@ class zerobin_db extends zerobin_abstract
|
||||
{
|
||||
if (
|
||||
!array_key_exists($pasteid, self::$_cache)
|
||||
) self::$_cache[$pasteid] = self::_select(
|
||||
'SELECT * FROM ' . self::$_prefix . 'paste WHERE dataid = ?',
|
||||
array($pasteid), true
|
||||
);
|
||||
) self::$_cache[$pasteid] = $this->read($pasteid);
|
||||
return (bool) self::$_cache[$pasteid];
|
||||
}
|
||||
|
||||
@@ -278,9 +293,9 @@ class zerobin_db extends zerobin_abstract
|
||||
return self::_exec(
|
||||
'INSERT INTO ' . self::$_prefix . 'comment VALUES(?,?,?,?,?,?,?)',
|
||||
array(
|
||||
$commentid,
|
||||
$pasteid,
|
||||
$parentid,
|
||||
$commentid,
|
||||
$comment['data'],
|
||||
$comment['meta']['nickname'],
|
||||
$comment['meta']['vizhash'],
|
||||
|
||||
Reference in New Issue
Block a user