Merge pull request #54 from Sobak/coding-style

Coding style
This commit is contained in:
El RIDO 2016-08-04 15:58:46 +02:00 committed by GitHub
commit 9bde729cb5
55 changed files with 990 additions and 911 deletions

1
.gitignore vendored
View file

@ -1,5 +1,6 @@
# Ignore data/, tmp/ and vendor/ # Ignore data/, tmp/ and vendor/
data/ data/
!lib/data/
tmp/ tmp/
vendor/ vendor/
# Ignore for safety # Ignore for safety

View file

@ -9,7 +9,7 @@ instance.
### Requirements ### Requirements
- PHP version 5.2.6 or above - PHP version 5.3.0 or above
- GD extension - GD extension
- mcrypt extension (recommended) - mcrypt extension (recommended)
- some disk space or (optional) a database supported by PDO - some disk space or (optional) a database supported by PDO

View file

@ -23,5 +23,10 @@
"require-dev": { "require-dev": {
"codacy/coverage": "dev-master", "codacy/coverage": "dev-master",
"codeclimate/php-test-reporter": "dev-master" "codeclimate/php-test-reporter": "dev-master"
},
"autoload": {
"psr-4": {
"PrivateBin\\": "lib/"
}
} }
} }

View file

@ -2,8 +2,8 @@
"en": "de", "en": "de",
"Paste does not exist, has expired or has been deleted.": "Paste does not exist, has expired or has been deleted.":
"Diesen Text gibt es nicht, er ist abgelaufen oder wurde gelöscht.", "Diesen Text gibt es nicht, er ist abgelaufen oder wurde gelöscht.",
"PrivateBin requires php 5.2.6 or above to work. Sorry.": "PrivateBin requires php 5.3.0 or above to work. Sorry.":
"PrivateBin benötigt PHP 5.2.6 oder höher, um zu funktionieren. Sorry.", "PrivateBin benötigt PHP 5.3.0 oder höher, um zu funktionieren. Sorry.",
"PrivateBin requires configuration section [%s] to be present in configuration file.": "PrivateBin requires configuration section [%s] to be present in configuration file.":
"PrivateBin benötigt den Konfigurationsabschnitt [%s] in der Konfigurationsdatei um zu funktionieren.", "PrivateBin benötigt den Konfigurationsabschnitt [%s] in der Konfigurationsdatei um zu funktionieren.",
"Please wait %d seconds between each post.": "Please wait %d seconds between each post.":

View file

@ -2,8 +2,8 @@
"en": "fr", "en": "fr",
"Paste does not exist, has expired or has been deleted.": "Paste does not exist, has expired or has been deleted.":
"Le paste n'existe pas, a expiré, ou a été supprimé.", "Le paste n'existe pas, a expiré, ou a été supprimé.",
"PrivateBin requires php 5.2.6 or above to work. Sorry.": "PrivateBin requires php 5.3.0 or above to work. Sorry.":
"Désolé, PrivateBin nécessite php 5.2.6 ou supérieur pour fonctionner.", "Désolé, PrivateBin nécessite php 5.3.0 ou supérieur pour fonctionner.",
"PrivateBin requires configuration section [%s] to be present in configuration file.": "PrivateBin requires configuration section [%s] to be present in configuration file.":
"PrivateBin a besoin de la section de configuration [%s] dans le fichier de configuration pour fonctionner.", "PrivateBin a besoin de la section de configuration [%s] dans le fichier de configuration pour fonctionner.",
"Please wait %d seconds between each post.": "Please wait %d seconds between each post.":

View file

@ -2,8 +2,8 @@
"en": "pl", "en": "pl",
"Paste does not exist, has expired or has been deleted.": "Paste does not exist, has expired or has been deleted.":
"Wklejka nie istnieje, wygasła albo została usunięta.", "Wklejka nie istnieje, wygasła albo została usunięta.",
"PrivateBin requires php 5.2.6 or above to work. Sorry.": "PrivateBin requires php 5.3.0 or above to work. Sorry.":
"PrivateBin wymaga PHP w wersji 5.2.6 lub nowszej, sorry.", "PrivateBin wymaga PHP w wersji 5.3.0 lub nowszej, sorry.",
"PrivateBin requires configuration section [%s] to be present in configuration file.": "PrivateBin requires configuration section [%s] to be present in configuration file.":
"PrivateBin wymaga obecności sekcji [%s] w pliku konfiguracyjnym.", "PrivateBin wymaga obecności sekcji [%s] w pliku konfiguracyjnym.",
"Please wait %d seconds between each post.": "Please wait %d seconds between each post.":

View file

@ -2,8 +2,8 @@
"en": "sl", "en": "sl",
"Paste does not exist, has expired or has been deleted.": "Paste does not exist, has expired or has been deleted.":
"Prilepek ne obstaja, mu je potekla življenjska doba, ali pa je izbrisan.", "Prilepek ne obstaja, mu je potekla življenjska doba, ali pa je izbrisan.",
"PrivateBin requires php 5.2.6 or above to work. Sorry.": "PrivateBin requires php 5.3.0 or above to work. Sorry.":
"Oprosti, PrivateBin za delovanje potrebuje vsaj php 5.2.6.", "Oprosti, PrivateBin za delovanje potrebuje vsaj php 5.3.0.",
"PrivateBin requires configuration section [%s] to be present in configuration file.": "PrivateBin requires configuration section [%s] to be present in configuration file.":
"PrivateBin potrebuje sekcijo konfiguracij [%s] v konfiguracijski datoteki.", "PrivateBin potrebuje sekcijo konfiguracij [%s] v konfiguracijski datoteki.",
"Please wait %d seconds between each post.": "Please wait %d seconds between each post.":

View file

@ -2,8 +2,8 @@
"en": "zh", "en": "zh",
"Paste does not exist, has expired or has been deleted.": "Paste does not exist, has expired or has been deleted.":
"粘贴不存在,已过期或者已被删除。", "粘贴不存在,已过期或者已被删除。",
"PrivateBin requires php 5.2.6 or above to work. Sorry.": "PrivateBin requires php 5.3.0 or above to work. Sorry.":
"PrivateBin需要工作于PHP 5.2.6及以上版本,抱歉。", "PrivateBin需要工作于PHP 5.3.0及以上版本,抱歉。",
"PrivateBin requires configuration section [%s] to be present in configuration file.": "PrivateBin requires configuration section [%s] to be present in configuration file.":
"PrivateBin需要设置配置文件中 [%s] 的部分。", "PrivateBin需要设置配置文件中 [%s] 的部分。",
"Please wait %d seconds between each post.": "Please wait %d seconds between each post.":

View file

@ -14,5 +14,5 @@
define('PATH', ''); define('PATH', '');
define('PUBLIC_PATH', dirname(__FILE__)); define('PUBLIC_PATH', dirname(__FILE__));
require PATH . 'lib/auto.php'; require __DIR__ . '/vendor/autoload.php';
new privatebin; new PrivateBin\privatebin;

View file

@ -1,38 +0,0 @@
<?php
/**
* PrivateBin
*
* a zero-knowledge paste bin
*
* @link https://github.com/PrivateBin/PrivateBin
* @copyright 2012 Sébastien SAUVAGE (sebsauvage.net)
* @license https://www.opensource.org/licenses/zlib-license.php The zlib/libpng License
* @version 0.22
*/
spl_autoload_register('auto::loader');
/**
* auto
*
* provides autoloading functionality
*/
class auto
{
/**
* includes file for given class name
*
* @access public
* @static
* @param string $class_name
* @return mixed
*/
public static function loader($class_name)
{
$filename = PATH . 'lib/' . str_replace('_', '/', $class_name) . '.php';
if(is_readable($filename)) {
return include $filename;
}
return false;
}
}

View file

@ -10,6 +10,11 @@
* @version 0.22 * @version 0.22
*/ */
namespace PrivateBin;
use Exception;
use PDO;
/** /**
* configuration * configuration
* *
@ -77,7 +82,7 @@ class configuration
'dir' => 'data', 'dir' => 'data',
), ),
'model' => array( 'model' => array(
'class' => 'privatebin_data', 'class' => 'PrivateBin\data\data',
), ),
'model_options' => array( 'model_options' => array(
'dir' => 'data', 'dir' => 'data',
@ -93,8 +98,7 @@ class configuration
{ {
$config = array(); $config = array();
$configFile = PATH . 'cfg' . DIRECTORY_SEPARATOR . 'conf.ini'; $configFile = PATH . 'cfg' . DIRECTORY_SEPARATOR . 'conf.ini';
if (is_readable($configFile)) if (is_readable($configFile)) {
{
$config = parse_ini_file($configFile, true); $config = parse_ini_file($configFile, true);
foreach (array('main', 'model', 'model_options') as $section) { foreach (array('main', 'model', 'model_options') as $section) {
if (!array_key_exists($section, $config)) { if (!array_key_exists($section, $config)) {
@ -103,14 +107,11 @@ class configuration
} }
} }
$opts = '_options'; $opts = '_options';
foreach (self::getDefaults() as $section => $values) foreach (self::getDefaults() as $section => $values) {
{
// fill missing sections with default values // fill missing sections with default values
if (!array_key_exists($section, $config) || count($config[$section]) == 0) if (!array_key_exists($section, $config) || count($config[$section]) == 0) {
{
$this->_configuration[$section] = $values; $this->_configuration[$section] = $values;
if (array_key_exists('dir', $this->_configuration[$section])) if (array_key_exists('dir', $this->_configuration[$section])) {
{
$this->_configuration[$section]['dir'] = PATH . $this->_configuration[$section]['dir']; $this->_configuration[$section]['dir'] = PATH . $this->_configuration[$section]['dir'];
} }
continue; continue;
@ -121,8 +122,7 @@ class configuration
$this->_configuration['model']['class'], $this->_configuration['model']['class'],
array('privatebin_db', 'zerobin_db') array('privatebin_db', 'zerobin_db')
) )
) ) {
{
$values = array( $values = array(
'dsn' => 'sqlite:' . PATH . 'data/db.sq3', 'dsn' => 'sqlite:' . PATH . 'data/db.sq3',
'tbl' => null, 'tbl' => null,
@ -137,52 +137,34 @@ class configuration
$section !== 'model_options' && $section !== 'model_options' &&
($from = strlen($section) - strlen($opts)) >= 0 && ($from = strlen($section) - strlen($opts)) >= 0 &&
strpos($section, $opts, $from) !== false strpos($section, $opts, $from) !== false
) ) {
{ if (is_int(current($values))) {
if (is_int(current($values)))
{
$config[$section] = array_map('intval', $config[$section]); $config[$section] = array_map('intval', $config[$section]);
} }
$this->_configuration[$section] = $config[$section]; $this->_configuration[$section] = $config[$section];
} }
// check for missing keys and set defaults if necessary // check for missing keys and set defaults if necessary
else else {
{ foreach ($values as $key => $val) {
foreach ($values as $key => $val) if ($key == 'dir') {
{
if ($key == 'dir')
{
$val = PATH . $val; $val = PATH . $val;
} }
$result = $val; $result = $val;
if (array_key_exists($key, $config[$section])) if (array_key_exists($key, $config[$section])) {
{ if ($val === null) {
if ($val === null)
{
$result = $config[$section][$key]; $result = $config[$section][$key];
} } elseif (is_bool($val)) {
elseif (is_bool($val))
{
$val = strtolower($config[$section][$key]); $val = strtolower($config[$section][$key]);
if (in_array($val, array('true', 'yes', 'on'))) if (in_array($val, array('true', 'yes', 'on'))) {
{
$result = true; $result = true;
} } elseif (in_array($val, array('false', 'no', 'off'))) {
elseif (in_array($val, array('false', 'no', 'off')))
{
$result = false; $result = false;
} } else {
else
{
$result = (bool) $config[$section][$key]; $result = (bool) $config[$section][$key];
} }
} } elseif (is_int($val)) {
elseif (is_int($val))
{
$result = (int) $config[$section][$key]; $result = (int) $config[$section][$key];
} } elseif (is_string($val) && !empty($config[$section][$key])) {
elseif (is_string($val) && !empty($config[$section][$key]))
{
$result = (string) $config[$section][$key]; $result = (string) $config[$section][$key];
} }
} }
@ -191,15 +173,20 @@ class configuration
} }
} }
// support for old config file format, before the fork was renamed // support for old config file format, before the fork was renamed and PSR-4 introduced
$this->_configuration['model']['class'] = str_replace( $this->_configuration['model']['class'] = str_replace(
'zerobin_', 'privatebin_', 'zerobin_', 'privatebin_',
$this->_configuration['model']['class'] $this->_configuration['model']['class']
); );
$this->_configuration['model']['class'] = str_replace(
array('privatebin_data', 'privatebin_db'),
array('PrivateBin\\data\\data', 'PrivateBin\\data\\db'),
$this->_configuration['model']['class']
);
// ensure a valid expire default key is set // ensure a valid expire default key is set
if (!array_key_exists($this->_configuration['expire']['default'], $this->_configuration['expire_options'])) if (!array_key_exists($this->_configuration['expire']['default'], $this->_configuration['expire_options'])) {
{
$this->_configuration['expire']['default'] = key($this->_configuration['expire_options']); $this->_configuration['expire']['default'] = key($this->_configuration['expire_options']);
} }
} }
@ -235,8 +222,7 @@ class configuration
public function getKey($key, $section = 'main') public function getKey($key, $section = 'main')
{ {
$options = $this->getSection($section); $options = $this->getSection($section);
if (!array_key_exists($key, $options)) if (!array_key_exists($key, $options)) {
{
throw new Exception(i18n::_('Invalid data.') . " $section / $key", 4); throw new Exception(i18n::_('Invalid data.') . " $section / $key", 4);
} }
return $this->_configuration[$section][$key]; return $this->_configuration[$section][$key];
@ -251,8 +237,7 @@ class configuration
*/ */
public function getSection($section) public function getSection($section)
{ {
if (!array_key_exists($section, $this->_configuration)) if (!array_key_exists($section, $this->_configuration)) {
{
throw new Exception(i18n::_('PrivateBin requires configuration section [%s] to be present in configuration file.', $section), 3); throw new Exception(i18n::_('PrivateBin requires configuration section [%s] to be present in configuration file.', $section), 3);
} }
return $this->_configuration[$section]; return $this->_configuration[$section];

View file

@ -10,12 +10,14 @@
* @version 0.22 * @version 0.22
*/ */
namespace PrivateBin\data;
/** /**
* privatebin_abstract * privatebin_abstract
* *
* Abstract model for PrivateBin data access, implemented as a singleton. * Abstract model for PrivateBin data access, implemented as a singleton.
*/ */
abstract class privatebin_abstract abstract class AbstractData
{ {
/** /**
* singleton instance * singleton instance
@ -33,7 +35,9 @@ abstract class privatebin_abstract
* *
* @access protected * @access protected
*/ */
protected function __construct() {} protected function __construct()
{
}
/** /**
* enforce singleton, disable cloning * enforce singleton, disable cloning
@ -42,7 +46,9 @@ abstract class privatebin_abstract
* *
* @access private * @access private
*/ */
private function __clone() {} private function __clone()
{
}
/** /**
* get instance of singleton * get instance of singleton
@ -52,7 +58,9 @@ abstract class privatebin_abstract
* @param array $options * @param array $options
* @return privatebin_abstract * @return privatebin_abstract
*/ */
public static function getInstance($options) {} public static function getInstance($options)
{
}
/** /**
* Create a paste. * Create a paste.
@ -141,12 +149,12 @@ abstract class privatebin_abstract
*/ */
public function purge($batchsize) public function purge($batchsize)
{ {
if ($batchsize < 1) return; if ($batchsize < 1) {
return;
}
$pastes = $this->_getExpiredPastes($batchsize); $pastes = $this->_getExpiredPastes($batchsize);
if (count($pastes)) if (count($pastes)) {
{ foreach ($pastes as $pasteid) {
foreach ($pastes as $pasteid)
{
$this->delete($pasteid); $this->delete($pasteid);
} }
} }
@ -162,10 +170,11 @@ abstract class privatebin_abstract
*/ */
protected function getOpenSlot(&$comments, $postdate) protected function getOpenSlot(&$comments, $postdate)
{ {
if (array_key_exists($postdate, $comments)) if (array_key_exists($postdate, $comments)) {
{
$parts = explode('.', $postdate, 2); $parts = explode('.', $postdate, 2);
if (!array_key_exists(1, $parts)) $parts[1] = 0; if (!array_key_exists(1, $parts)) {
$parts[1] = 0;
}
++$parts[1]; ++$parts[1];
return $this->getOpenSlot($comments, implode('.', $parts)); return $this->getOpenSlot($comments, implode('.', $parts));
} }

View file

@ -10,12 +10,14 @@
* @version 0.22 * @version 0.22
*/ */
namespace PrivateBin\data;
/** /**
* privatebin_data * privatebin_data
* *
* Model for data access, implemented as a singleton. * Model for data access, implemented as a singleton.
*/ */
class privatebin_data extends privatebin_abstract class data extends AbstractData
{ {
/** /**
* directory where data is stored * directory where data is stored
@ -40,7 +42,9 @@ class privatebin_data extends privatebin_abstract
if ( if (
is_array($options) && is_array($options) &&
array_key_exists('dir', $options) array_key_exists('dir', $options)
) self::$_dir = $options['dir'] . DIRECTORY_SEPARATOR; ) {
self::$_dir = $options['dir'] . DIRECTORY_SEPARATOR;
}
// if needed initialize the singleton // if needed initialize the singleton
if (!(self::$_instance instanceof privatebin_data)) { if (!(self::$_instance instanceof privatebin_data)) {
self::$_instance = new self; self::$_instance = new self;
@ -60,8 +64,12 @@ class privatebin_data extends privatebin_abstract
public function create($pasteid, $paste) public function create($pasteid, $paste)
{ {
$storagedir = self::_dataid2path($pasteid); $storagedir = self::_dataid2path($pasteid);
if (is_file($storagedir . $pasteid)) return false; if (is_file($storagedir . $pasteid)) {
if (!is_dir($storagedir)) mkdir($storagedir, 0705, true); return false;
}
if (!is_dir($storagedir)) {
mkdir($storagedir, 0705, true);
}
return (bool) @file_put_contents($storagedir . $pasteid, json_encode($paste)); return (bool) @file_put_contents($storagedir . $pasteid, json_encode($paste));
} }
@ -74,16 +82,16 @@ class privatebin_data extends privatebin_abstract
*/ */
public function read($pasteid) public function read($pasteid)
{ {
if (!$this->exists($pasteid)) return false; if (!$this->exists($pasteid)) {
return false;
}
$paste = json_decode( $paste = json_decode(
file_get_contents(self::_dataid2path($pasteid) . $pasteid) file_get_contents(self::_dataid2path($pasteid) . $pasteid)
); );
if (property_exists($paste->meta, 'attachment')) if (property_exists($paste->meta, 'attachment')) {
{
$paste->attachment = $paste->meta->attachment; $paste->attachment = $paste->meta->attachment;
unset($paste->meta->attachment); unset($paste->meta->attachment);
if (property_exists($paste->meta, 'attachmentname')) if (property_exists($paste->meta, 'attachmentname')) {
{
$paste->attachmentname = $paste->meta->attachmentname; $paste->attachmentname = $paste->meta->attachmentname;
unset($paste->meta->attachmentname); unset($paste->meta->attachmentname);
} }
@ -105,13 +113,13 @@ class privatebin_data extends privatebin_abstract
// Delete discussion if it exists. // Delete discussion if it exists.
$discdir = self::_dataid2discussionpath($pasteid); $discdir = self::_dataid2discussionpath($pasteid);
if (is_dir($discdir)) if (is_dir($discdir)) {
{
// Delete all files in discussion directory // Delete all files in discussion directory
$dir = dir($discdir); $dir = dir($discdir);
while (false !== ($filename = $dir->read())) while (false !== ($filename = $dir->read())) {
{ if (is_file($discdir . $filename)) {
if (is_file($discdir . $filename)) @unlink($discdir . $filename); @unlink($discdir . $filename);
}
} }
$dir->close(); $dir->close();
@ -146,8 +154,12 @@ class privatebin_data extends privatebin_abstract
{ {
$storagedir = self::_dataid2discussionpath($pasteid); $storagedir = self::_dataid2discussionpath($pasteid);
$filename = $pasteid . '.' . $commentid . '.' . $parentid; $filename = $pasteid . '.' . $commentid . '.' . $parentid;
if (is_file($storagedir . $filename)) return false; if (is_file($storagedir . $filename)) {
if (!is_dir($storagedir)) mkdir($storagedir, 0705, true); return false;
}
if (!is_dir($storagedir)) {
mkdir($storagedir, 0705, true);
}
return (bool) @file_put_contents($storagedir . $filename, json_encode($comment)); return (bool) @file_put_contents($storagedir . $filename, json_encode($comment));
} }
@ -162,18 +174,15 @@ class privatebin_data extends privatebin_abstract
{ {
$comments = array(); $comments = array();
$discdir = self::_dataid2discussionpath($pasteid); $discdir = self::_dataid2discussionpath($pasteid);
if (is_dir($discdir)) if (is_dir($discdir)) {
{
// Delete all files in discussion directory // Delete all files in discussion directory
$dir = dir($discdir); $dir = dir($discdir);
while (false !== ($filename = $dir->read())) while (false !== ($filename = $dir->read())) {
{
// Filename is in the form pasteid.commentid.parentid: // Filename is in the form pasteid.commentid.parentid:
// - pasteid is the paste this reply belongs to. // - pasteid is the paste this reply belongs to.
// - commentid is the comment identifier itself. // - commentid is the comment identifier itself.
// - parentid is the comment this comment replies to (It can be pasteid) // - parentid is the comment this comment replies to (It can be pasteid)
if (is_file($discdir . $filename)) if (is_file($discdir . $filename)) {
{
$comment = json_decode(file_get_contents($discdir . $filename)); $comment = json_decode(file_get_contents($discdir . $filename));
$items = explode('.', $filename); $items = explode('.', $filename);
// Add some meta information not contained in file. // Add some meta information not contained in file.
@ -224,11 +233,9 @@ class privatebin_data extends privatebin_abstract
scandir(self::$_dir), scandir(self::$_dir),
array('self', '_isFirstLevelDir') array('self', '_isFirstLevelDir')
); );
if (count($firstLevel) > 0) if (count($firstLevel) > 0) {
{
// try at most 10 times the $batchsize pastes before giving up // try at most 10 times the $batchsize pastes before giving up
for ($i = 0, $max = $batchsize * 10; $i < $max; ++$i) for ($i = 0, $max = $batchsize * 10; $i < $max; ++$i) {
{
$firstKey = array_rand($firstLevel); $firstKey = array_rand($firstLevel);
$secondLevel = array_filter( $secondLevel = array_filter(
scandir(self::$_dir . $firstLevel[$firstKey]), scandir(self::$_dir . $firstLevel[$firstKey]),
@ -236,8 +243,7 @@ class privatebin_data extends privatebin_abstract
); );
// skip this folder in the next checks if it is empty // skip this folder in the next checks if it is empty
if (count($secondLevel) == 0) if (count($secondLevel) == 0) {
{
unset($firstLevel[$firstKey]); unset($firstLevel[$firstKey]);
continue; continue;
} }
@ -245,26 +251,32 @@ class privatebin_data extends privatebin_abstract
$secondKey = array_rand($secondLevel); $secondKey = array_rand($secondLevel);
$path = self::$_dir . $firstLevel[$firstKey] . $path = self::$_dir . $firstLevel[$firstKey] .
DIRECTORY_SEPARATOR . $secondLevel[$secondKey]; DIRECTORY_SEPARATOR . $secondLevel[$secondKey];
if (!is_dir($path)) continue; if (!is_dir($path)) {
continue;
}
$thirdLevel = array_filter( $thirdLevel = array_filter(
scandir($path), scandir($path),
array('model_paste', 'isValidId') array('PrivateBin\\model\\paste', 'isValidId')
); );
if (count($thirdLevel) == 0) continue; if (count($thirdLevel) == 0) {
continue;
}
$thirdKey = array_rand($thirdLevel); $thirdKey = array_rand($thirdLevel);
$pasteid = $thirdLevel[$thirdKey]; $pasteid = $thirdLevel[$thirdKey];
if (in_array($pasteid, $pastes)) continue; if (in_array($pasteid, $pastes)) {
continue;
}
if ($this->exists($pasteid)) if ($this->exists($pasteid)) {
{
$data = $this->read($pasteid); $data = $this->read($pasteid);
if ( if (
property_exists($data->meta, 'expire_date') && property_exists($data->meta, 'expire_date') &&
$data->meta->expire_date < time() $data->meta->expire_date < time()
) ) {
{
$pastes[] = $pasteid; $pastes[] = $pasteid;
if (count($pastes) >= $batchsize) break; if (count($pastes) >= $batchsize) {
break;
}
} }
} }
} }
@ -282,10 +294,11 @@ class privatebin_data extends privatebin_abstract
private static function _init() private static function _init()
{ {
// Create storage directory if it does not exist. // Create storage directory if it does not exist.
if (!is_dir(self::$_dir)) mkdir(self::$_dir, 0705); if (!is_dir(self::$_dir)) {
mkdir(self::$_dir, 0705);
}
// Create .htaccess file if it does not exist. // Create .htaccess file if it does not exist.
if (!is_file(self::$_dir . '.htaccess')) if (!is_file(self::$_dir . '.htaccess')) {
{
file_put_contents( file_put_contents(
self::$_dir . '.htaccess', self::$_dir . '.htaccess',
'Allow from none' . PHP_EOL . 'Allow from none' . PHP_EOL .

View file

@ -10,12 +10,20 @@
* @version 0.22 * @version 0.22
*/ */
namespace PrivateBin\data;
use Exception;
use PDO;
use PDOException;
use PrivateBin\privatebin;
use stdClass;
/** /**
* privatebin_db * privatebin_db
* *
* Model for DB access, implemented as a singleton. * Model for DB access, implemented as a singleton.
*/ */
class privatebin_db extends privatebin_abstract class db extends AbstractData
{ {
/** /**
* cache for select queries * cache for select queries
@ -63,14 +71,15 @@ class privatebin_db extends privatebin_abstract
public static function getInstance($options = null) public static function getInstance($options = null)
{ {
// if needed initialize the singleton // if needed initialize the singleton
if(!(self::$_instance instanceof privatebin_db)) { if (!(self::$_instance instanceof privatebin_db)) {
self::$_instance = new self; self::$_instance = new self;
} }
if (is_array($options)) if (is_array($options)) {
{
// set table prefix if given // set table prefix if given
if (array_key_exists('tbl', $options)) self::$_prefix = $options['tbl']; if (array_key_exists('tbl', $options)) {
self::$_prefix = $options['tbl'];
}
// initialize the db connection with new options // initialize the db connection with new options
if ( if (
@ -78,8 +87,7 @@ class privatebin_db extends privatebin_abstract
array_key_exists('usr', $options) && array_key_exists('usr', $options) &&
array_key_exists('pwd', $options) && array_key_exists('pwd', $options) &&
array_key_exists('opt', $options) array_key_exists('opt', $options)
) ) {
{
// set default options // set default options
$options['opt'][PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION; $options['opt'][PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION;
$options['opt'][PDO::ATTR_EMULATE_PREPARES] = false; $options['opt'][PDO::ATTR_EMULATE_PREPARES] = false;
@ -102,40 +110,34 @@ class privatebin_db extends privatebin_abstract
$tables = self::$_db->query($tableQuery)->fetchAll(PDO::FETCH_COLUMN, 0); $tables = self::$_db->query($tableQuery)->fetchAll(PDO::FETCH_COLUMN, 0);
// create paste table if necessary // create paste table if necessary
if (!in_array(self::_sanitizeIdentifier('paste'), $tables)) if (!in_array(self::_sanitizeIdentifier('paste'), $tables)) {
{
self::_createPasteTable(); self::_createPasteTable();
$db_tables_exist = false; $db_tables_exist = false;
} }
// create comment table if necessary // create comment table if necessary
if (!in_array(self::_sanitizeIdentifier('comment'), $tables)) if (!in_array(self::_sanitizeIdentifier('comment'), $tables)) {
{
self::_createCommentTable(); self::_createCommentTable();
$db_tables_exist = false; $db_tables_exist = false;
} }
// create config table if necessary // create config table if necessary
$db_version = privatebin::VERSION; $db_version = privatebin::VERSION;
if (!in_array(self::_sanitizeIdentifier('config'), $tables)) if (!in_array(self::_sanitizeIdentifier('config'), $tables)) {
{
self::_createConfigTable(); self::_createConfigTable();
// if we only needed to create the config table, the DB is older then 0.22 // if we only needed to create the config table, the DB is older then 0.22
if ($db_tables_exist) $db_version = '0.21'; if ($db_tables_exist) {
} $db_version = '0.21';
else }
{ } else {
$db_version = self::_getConfig('VERSION'); $db_version = self::_getConfig('VERSION');
} }
// update database structure if necessary // update database structure if necessary
if (version_compare($db_version, privatebin::VERSION, '<')) if (version_compare($db_version, privatebin::VERSION, '<')) {
{
self::_upgradeDatabase($db_version); self::_upgradeDatabase($db_version);
} }
} } else {
else
{
throw new Exception( throw new Exception(
'Missing configuration for key dsn, usr, pwd or opt in the section model_options, please check your configuration file', 6 'Missing configuration for key dsn, usr, pwd or opt in the section model_options, please check your configuration file', 6
); );
@ -158,7 +160,7 @@ class privatebin_db extends privatebin_abstract
if ( if (
array_key_exists($pasteid, self::$_cache) array_key_exists($pasteid, self::$_cache)
) { ) {
if(false !== self::$_cache[$pasteid]) { if (false !== self::$_cache[$pasteid]) {
return false; return false;
} else { } else {
unset(self::$_cache[$pasteid]); unset(self::$_cache[$pasteid]);
@ -170,28 +172,23 @@ class privatebin_db extends privatebin_abstract
$meta = $paste['meta']; $meta = $paste['meta'];
unset($meta['postdate']); unset($meta['postdate']);
$expire_date = 0; $expire_date = 0;
if (array_key_exists('expire_date', $paste['meta'])) if (array_key_exists('expire_date', $paste['meta'])) {
{
$expire_date = (int) $paste['meta']['expire_date']; $expire_date = (int) $paste['meta']['expire_date'];
unset($meta['expire_date']); unset($meta['expire_date']);
} }
if (array_key_exists('opendiscussion', $paste['meta'])) if (array_key_exists('opendiscussion', $paste['meta'])) {
{
$opendiscussion = (bool) $paste['meta']['opendiscussion']; $opendiscussion = (bool) $paste['meta']['opendiscussion'];
unset($meta['opendiscussion']); unset($meta['opendiscussion']);
} }
if (array_key_exists('burnafterreading', $paste['meta'])) if (array_key_exists('burnafterreading', $paste['meta'])) {
{
$burnafterreading = (bool) $paste['meta']['burnafterreading']; $burnafterreading = (bool) $paste['meta']['burnafterreading'];
unset($meta['burnafterreading']); unset($meta['burnafterreading']);
} }
if (array_key_exists('attachment', $paste['meta'])) if (array_key_exists('attachment', $paste['meta'])) {
{
$attachment = $paste['meta']['attachment']; $attachment = $paste['meta']['attachment'];
unset($meta['attachment']); unset($meta['attachment']);
} }
if (array_key_exists('attachmentname', $paste['meta'])) if (array_key_exists('attachmentname', $paste['meta'])) {
{
$attachmentname = $paste['meta']['attachmentname']; $attachmentname = $paste['meta']['attachmentname'];
unset($meta['attachmentname']); unset($meta['attachmentname']);
} }
@ -230,31 +227,29 @@ class privatebin_db extends privatebin_abstract
' WHERE dataid = ?', array($pasteid), true ' WHERE dataid = ?', array($pasteid), true
); );
if(false !== $paste) { if (false !== $paste) {
// create object // create object
self::$_cache[$pasteid] = new stdClass; self::$_cache[$pasteid] = new stdClass;
self::$_cache[$pasteid]->data = $paste['data']; self::$_cache[$pasteid]->data = $paste['data'];
$meta = json_decode($paste['meta']); $meta = json_decode($paste['meta']);
if (!is_object($meta)) $meta = new stdClass; if (!is_object($meta)) {
$meta = new stdClass;
}
// support older attachments // support older attachments
if (property_exists($meta, 'attachment')) if (property_exists($meta, 'attachment')) {
{
self::$_cache[$pasteid]->attachment = $meta->attachment; self::$_cache[$pasteid]->attachment = $meta->attachment;
unset($meta->attachment); unset($meta->attachment);
if (property_exists($meta, 'attachmentname')) if (property_exists($meta, 'attachmentname')) {
{
self::$_cache[$pasteid]->attachmentname = $meta->attachmentname; self::$_cache[$pasteid]->attachmentname = $meta->attachmentname;
unset($meta->attachmentname); unset($meta->attachmentname);
} }
} }
// support current attachments // support current attachments
elseif (array_key_exists('attachment', $paste) && strlen($paste['attachment'])) elseif (array_key_exists('attachment', $paste) && strlen($paste['attachment'])) {
{
self::$_cache[$pasteid]->attachment = $paste['attachment']; self::$_cache[$pasteid]->attachment = $paste['attachment'];
if (array_key_exists('attachmentname', $paste) && strlen($paste['attachmentname'])) if (array_key_exists('attachmentname', $paste) && strlen($paste['attachmentname'])) {
{
self::$_cache[$pasteid]->attachmentname = $paste['attachmentname']; self::$_cache[$pasteid]->attachmentname = $paste['attachmentname'];
} }
} }
@ -263,13 +258,19 @@ class privatebin_db extends privatebin_abstract
$expire_date = (int) $paste['expiredate']; $expire_date = (int) $paste['expiredate'];
if ( if (
$expire_date > 0 $expire_date > 0
) self::$_cache[$pasteid]->meta->expire_date = $expire_date; ) {
self::$_cache[$pasteid]->meta->expire_date = $expire_date;
}
if ( if (
$paste['opendiscussion'] $paste['opendiscussion']
) self::$_cache[$pasteid]->meta->opendiscussion = true; ) {
self::$_cache[$pasteid]->meta->opendiscussion = true;
}
if ( if (
$paste['burnafterreading'] $paste['burnafterreading']
) self::$_cache[$pasteid]->meta->burnafterreading = true; ) {
self::$_cache[$pasteid]->meta->burnafterreading = true;
}
} }
} }
@ -295,7 +296,9 @@ class privatebin_db extends privatebin_abstract
); );
if ( if (
array_key_exists($pasteid, self::$_cache) array_key_exists($pasteid, self::$_cache)
) unset(self::$_cache[$pasteid]); ) {
unset(self::$_cache[$pasteid]);
}
} }
/** /**
@ -309,7 +312,9 @@ class privatebin_db extends privatebin_abstract
{ {
if ( if (
!array_key_exists($pasteid, self::$_cache) !array_key_exists($pasteid, self::$_cache)
) self::$_cache[$pasteid] = $this->read($pasteid); ) {
self::$_cache[$pasteid] = $this->read($pasteid);
}
return (bool) self::$_cache[$pasteid]; return (bool) self::$_cache[$pasteid];
} }
@ -325,10 +330,8 @@ class privatebin_db extends privatebin_abstract
*/ */
public function createComment($pasteid, $parentid, $commentid, $comment) public function createComment($pasteid, $parentid, $commentid, $comment)
{ {
foreach (array('nickname', 'vizhash') as $key) foreach (array('nickname', 'vizhash') as $key) {
{ if (!array_key_exists($key, $comment['meta'])) {
if (!array_key_exists($key, $comment['meta']))
{
$comment['meta'][$key] = null; $comment['meta'][$key] = null;
} }
} }
@ -363,10 +366,8 @@ class privatebin_db extends privatebin_abstract
// create comment list // create comment list
$comments = array(); $comments = array();
if (count($rows)) if (count($rows)) {
{ foreach ($rows as $row) {
foreach ($rows as $row)
{
$i = $this->getOpenSlot($comments, (int) $row['postdate']); $i = $this->getOpenSlot($comments, (int) $row['postdate']);
$comments[$i] = new stdClass; $comments[$i] = new stdClass;
$comments[$i]->id = $row['dataid']; $comments[$i]->id = $row['dataid'];
@ -374,10 +375,12 @@ class privatebin_db extends privatebin_abstract
$comments[$i]->data = $row['data']; $comments[$i]->data = $row['data'];
$comments[$i]->meta = new stdClass; $comments[$i]->meta = new stdClass;
$comments[$i]->meta->postdate = (int) $row['postdate']; $comments[$i]->meta->postdate = (int) $row['postdate'];
if (array_key_exists('nickname', $row) && !empty($row['nickname'])) if (array_key_exists('nickname', $row) && !empty($row['nickname'])) {
$comments[$i]->meta->nickname = $row['nickname']; $comments[$i]->meta->nickname = $row['nickname'];
if (array_key_exists('vizhash', $row) && !empty($row['vizhash'])) }
if (array_key_exists('vizhash', $row) && !empty($row['vizhash'])) {
$comments[$i]->meta->vizhash = $row['vizhash']; $comments[$i]->meta->vizhash = $row['vizhash'];
}
} }
ksort($comments); ksort($comments);
} }
@ -416,10 +419,8 @@ class privatebin_db extends privatebin_abstract
'SELECT dataid FROM ' . self::_sanitizeIdentifier('paste') . 'SELECT dataid FROM ' . self::_sanitizeIdentifier('paste') .
' WHERE expiredate < ? LIMIT ?', array(time(), $batchsize) ' WHERE expiredate < ? LIMIT ?', array(time(), $batchsize)
); );
if (count($rows)) if (count($rows)) {
{ foreach ($rows as $row) {
foreach ($rows as $row)
{
$pastes[] = $row['dataid']; $pastes[] = $row['dataid'];
} }
} }
@ -477,8 +478,7 @@ class privatebin_db extends privatebin_abstract
*/ */
private static function _getTableQuery($type) private static function _getTableQuery($type)
{ {
switch($type) switch ($type) {
{
case 'ibm': case 'ibm':
$sql = 'SELECT tabname FROM SYSCAT.TABLES '; $sql = 'SELECT tabname FROM SYSCAT.TABLES ';
break; break;
@ -551,12 +551,9 @@ class privatebin_db extends privatebin_abstract
private static function _getPrimaryKeyClauses($key = 'dataid') private static function _getPrimaryKeyClauses($key = 'dataid')
{ {
$main_key = $after_key = ''; $main_key = $after_key = '';
if (self::$_type === 'mysql') if (self::$_type === 'mysql') {
{
$after_key = ", PRIMARY KEY ($key)"; $after_key = ", PRIMARY KEY ($key)";
} } else {
else
{
$main_key = ' PRIMARY KEY'; $main_key = ' PRIMARY KEY';
} }
return array($main_key, $after_key); return array($main_key, $after_key);
@ -659,8 +656,7 @@ class privatebin_db extends privatebin_abstract
private static function _upgradeDatabase($oldversion) private static function _upgradeDatabase($oldversion)
{ {
$dataType = self::$_type === 'pgsql' ? 'TEXT' : 'BLOB'; $dataType = self::$_type === 'pgsql' ? 'TEXT' : 'BLOB';
switch ($oldversion) switch ($oldversion) {
{
case '0.21': case '0.21':
// create the meta column if necessary (pre 0.21 change) // create the meta column if necessary (pre 0.21 change)
try { try {
@ -679,8 +675,7 @@ class privatebin_db extends privatebin_abstract
); );
// SQLite doesn't support MODIFY, but it allows TEXT of similar // SQLite doesn't support MODIFY, but it allows TEXT of similar
// size as BLOB, so there is no need to change it there // size as BLOB, so there is no need to change it there
if (self::$_type !== 'sqlite') if (self::$_type !== 'sqlite') {
{
self::$_db->exec( self::$_db->exec(
'ALTER TABLE ' . self::_sanitizeIdentifier('paste') . 'ALTER TABLE ' . self::_sanitizeIdentifier('paste') .
' ADD PRIMARY KEY (dataid), MODIFY COLUMN data $dataType;' ' ADD PRIMARY KEY (dataid), MODIFY COLUMN data $dataType;'
@ -690,9 +685,7 @@ class privatebin_db extends privatebin_abstract
" ADD PRIMARY KEY (dataid), MODIFY COLUMN data $dataType, " . " ADD PRIMARY KEY (dataid), MODIFY COLUMN data $dataType, " .
"MODIFY COLUMN nickname $dataType, MODIFY COLUMN vizhash $dataType;" "MODIFY COLUMN nickname $dataType, MODIFY COLUMN vizhash $dataType;"
); );
} } else {
else
{
self::$_db->exec( self::$_db->exec(
'CREATE UNIQUE INDEX IF NOT EXISTS paste_dataid ON ' . 'CREATE UNIQUE INDEX IF NOT EXISTS paste_dataid ON ' .
self::_sanitizeIdentifier('paste') . '(dataid);' self::_sanitizeIdentifier('paste') . '(dataid);'

View file

@ -10,6 +10,11 @@
* @version 0.22 * @version 0.22
*/ */
namespace PrivateBin;
use Exception;
use PrivateBin\i18n;
/** /**
* filter * filter
* *
@ -28,7 +33,7 @@ class filter
public static function stripslashes_deep($value) public static function stripslashes_deep($value)
{ {
return is_array($value) ? return is_array($value) ?
array_map('filter::stripslashes_deep', $value) : array_map('PrivateBin\\filter::stripslashes_deep', $value) :
stripslashes($value); stripslashes($value);
} }
@ -73,9 +78,9 @@ class filter
{ {
$iec = array('B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB'); $iec = array('B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB');
$i = 0; $i = 0;
while ( ( $size / 1024 ) >= 1 ) { while (($size / 1024) >= 1) {
$size = $size / 1024; $size = $size / 1024;
$i++; $i++;
} }
return number_format($size, ($i ? 2 : 0), '.', ' ') . ' ' . i18n::_($iec[$i]); return number_format($size, ($i ? 2 : 0), '.', ' ') . ' ' . i18n::_($iec[$i]);
} }
@ -93,10 +98,9 @@ class filter
public static function slow_equals($a, $b) public static function slow_equals($a, $b)
{ {
$diff = strlen($a) ^ strlen($b); $diff = strlen($a) ^ strlen($b);
for($i = 0; $i < strlen($a) && $i < strlen($b); $i++) for ($i = 0; $i < strlen($a) && $i < strlen($b); $i++) {
{
$diff |= ord($a[$i]) ^ ord($b[$i]); $diff |= ord($a[$i]) ^ ord($b[$i]);
} }
return $diff === 0; return $diff === 0;
} }
} }

View file

@ -10,6 +10,8 @@
* @version 0.22 * @version 0.22
*/ */
namespace PrivateBin;
/** /**
* i18n * i18n
* *
@ -82,7 +84,7 @@ class i18n
*/ */
public static function _($messageId) public static function _($messageId)
{ {
return call_user_func_array(array('i18n', 'translate'), func_get_args()); return call_user_func_array(array('self', 'translate'), func_get_args());
} }
/** /**
@ -96,30 +98,31 @@ class i18n
*/ */
public static function translate($messageId) public static function translate($messageId)
{ {
if (empty($messageId)) return $messageId; if (empty($messageId)) {
if (count(self::$_translations) === 0) self::loadTranslations(); return $messageId;
}
if (count(self::$_translations) === 0) {
self::loadTranslations();
}
$messages = $messageId; $messages = $messageId;
if (is_array($messageId)) if (is_array($messageId)) {
{
$messageId = count($messageId) > 1 ? $messageId[1] : $messageId[0]; $messageId = count($messageId) > 1 ? $messageId[1] : $messageId[0];
} }
if (!array_key_exists($messageId, self::$_translations)) if (!array_key_exists($messageId, self::$_translations)) {
{
self::$_translations[$messageId] = $messages; self::$_translations[$messageId] = $messages;
} }
$args = func_get_args(); $args = func_get_args();
if (is_array(self::$_translations[$messageId])) if (is_array(self::$_translations[$messageId])) {
{
$number = (int) $args[1]; $number = (int) $args[1];
$key = self::_getPluralForm($number); $key = self::_getPluralForm($number);
$max = count(self::$_translations[$messageId]) - 1; $max = count(self::$_translations[$messageId]) - 1;
if ($key > $max) $key = $max; if ($key > $max) {
$key = $max;
}
$args[0] = self::$_translations[$messageId][$key]; $args[0] = self::$_translations[$messageId][$key];
$args[1] = $number; $args[1] = $number;
} } else {
else
{
$args[0] = self::$_translations[$messageId]; $args[0] = self::$_translations[$messageId];
} }
return call_user_func_array('sprintf', $args); return call_user_func_array('sprintf', $args);
@ -139,13 +142,11 @@ class i18n
$availableLanguages = self::getAvailableLanguages(); $availableLanguages = self::getAvailableLanguages();
// check if the lang cookie was set and that language exists // check if the lang cookie was set and that language exists
if (array_key_exists('lang', $_COOKIE) && in_array($_COOKIE['lang'], $availableLanguages)) if (array_key_exists('lang', $_COOKIE) && in_array($_COOKIE['lang'], $availableLanguages)) {
{
$match = $availableLanguages[array_search($_COOKIE['lang'], $availableLanguages)]; $match = $availableLanguages[array_search($_COOKIE['lang'], $availableLanguages)];
} }
// find a translation file matching the browsers language preferences // find a translation file matching the browsers language preferences
else else {
{
$match = self::_getMatchingLanguage( $match = self::_getMatchingLanguage(
self::getBrowserLanguages(), $availableLanguages self::getBrowserLanguages(), $availableLanguages
); );
@ -168,13 +169,10 @@ class i18n
*/ */
public static function getAvailableLanguages() public static function getAvailableLanguages()
{ {
if (count(self::$_availableLanguages) == 0) if (count(self::$_availableLanguages) == 0) {
{
$i18n = dir(self::_getPath()); $i18n = dir(self::_getPath());
while (false !== ($file = $i18n->read())) while (false !== ($file = $i18n->read())) {
{ if (preg_match('/^([a-z]{2}).json$/', $file, $match) === 1) {
if (preg_match('/^([a-z]{2}).json$/', $file, $match) === 1)
{
self::$_availableLanguages[] = $match[1]; self::$_availableLanguages[] = $match[1];
} }
} }
@ -195,26 +193,19 @@ class i18n
public static function getBrowserLanguages() public static function getBrowserLanguages()
{ {
$languages = array(); $languages = array();
if (array_key_exists('HTTP_ACCEPT_LANGUAGE', $_SERVER)) if (array_key_exists('HTTP_ACCEPT_LANGUAGE', $_SERVER)) {
{
$languageRanges = explode(',', trim($_SERVER['HTTP_ACCEPT_LANGUAGE'])); $languageRanges = explode(',', trim($_SERVER['HTTP_ACCEPT_LANGUAGE']));
foreach ($languageRanges as $languageRange) foreach ($languageRanges as $languageRange) {
{
if (preg_match( if (preg_match(
'/(\*|[a-zA-Z0-9]{1,8}(?:-[a-zA-Z0-9]{1,8})*)(?:\s*;\s*q\s*=\s*(0(?:\.\d{0,3})|1(?:\.0{0,3})))?/', '/(\*|[a-zA-Z0-9]{1,8}(?:-[a-zA-Z0-9]{1,8})*)(?:\s*;\s*q\s*=\s*(0(?:\.\d{0,3})|1(?:\.0{0,3})))?/',
trim($languageRange), $match trim($languageRange), $match
)) )) {
{ if (!isset($match[2])) {
if (!isset($match[2]))
{
$match[2] = '1.0'; $match[2] = '1.0';
} } else {
else
{
$match[2] = (string) floatval($match[2]); $match[2] = (string) floatval($match[2]);
} }
if (!isset($languages[$match[2]])) if (!isset($languages[$match[2]])) {
{
$languages[$match[2]] = array(); $languages[$match[2]] = array();
} }
$languages[$match[2]][] = strtolower($match[1]); $languages[$match[2]][] = strtolower($match[1]);
@ -250,11 +241,12 @@ class i18n
public static function getLanguageLabels($languages = array()) public static function getLanguageLabels($languages = array())
{ {
$file = self::_getPath('languages.json'); $file = self::_getPath('languages.json');
if (count(self::$_languageLabels) == 0 && is_readable($file)) if (count(self::$_languageLabels) == 0 && is_readable($file)) {
{
self::$_languageLabels = json_decode(file_get_contents($file), true); self::$_languageLabels = json_decode(file_get_contents($file), true);
} }
if (count($languages) == 0) return self::$_languageLabels; if (count($languages) == 0) {
return self::$_languageLabels;
}
return array_intersect_key(self::$_languageLabels, array_flip($languages)); return array_intersect_key(self::$_languageLabels, array_flip($languages));
} }
@ -268,8 +260,9 @@ class i18n
*/ */
public static function setLanguageFallback($lang) public static function setLanguageFallback($lang)
{ {
if (in_array($lang, self::getAvailableLanguages())) if (in_array($lang, self::getAvailableLanguages())) {
self::$_languageFallback = $lang; self::$_languageFallback = $lang;
}
} }
/** /**
@ -282,8 +275,7 @@ class i18n
*/ */
protected static function _getPath($file = '') protected static function _getPath($file = '')
{ {
if (strlen(self::$_path) == 0) if (strlen(self::$_path) == 0) {
{
self::$_path = PUBLIC_PATH . DIRECTORY_SEPARATOR . 'i18n'; self::$_path = PUBLIC_PATH . DIRECTORY_SEPARATOR . 'i18n';
} }
return self::$_path . (strlen($file) ? DIRECTORY_SEPARATOR . $file : ''); return self::$_path . (strlen($file) ? DIRECTORY_SEPARATOR . $file : '');
@ -324,47 +316,40 @@ class i18n
* @param array $availableLanguages * @param array $availableLanguages
* @return string * @return string
*/ */
protected static function _getMatchingLanguage($acceptedLanguages, $availableLanguages) { protected static function _getMatchingLanguage($acceptedLanguages, $availableLanguages)
{
$matches = array(); $matches = array();
$any = false; $any = false;
foreach ($acceptedLanguages as $acceptedQuality => $acceptedValues) foreach ($acceptedLanguages as $acceptedQuality => $acceptedValues) {
{
$acceptedQuality = floatval($acceptedQuality); $acceptedQuality = floatval($acceptedQuality);
if ($acceptedQuality === 0.0) continue; if ($acceptedQuality === 0.0) {
foreach ($availableLanguages as $availableValue) continue;
{ }
foreach ($availableLanguages as $availableValue) {
$availableQuality = 1.0; $availableQuality = 1.0;
foreach ($acceptedValues as $acceptedValue) foreach ($acceptedValues as $acceptedValue) {
{ if ($acceptedValue === '*') {
if ($acceptedValue === '*')
{
$any = true; $any = true;
} }
$matchingGrade = self::_matchLanguage($acceptedValue, $availableValue); $matchingGrade = self::_matchLanguage($acceptedValue, $availableValue);
if ($matchingGrade > 0) if ($matchingGrade > 0) {
{
$q = (string) ($acceptedQuality * $availableQuality * $matchingGrade); $q = (string) ($acceptedQuality * $availableQuality * $matchingGrade);
if (!isset($matches[$q])) if (!isset($matches[$q])) {
{
$matches[$q] = array(); $matches[$q] = array();
} }
if (!in_array($availableValue, $matches[$q])) if (!in_array($availableValue, $matches[$q])) {
{
$matches[$q][] = $availableValue; $matches[$q][] = $availableValue;
} }
} }
} }
} }
} }
if (count($matches) === 0 && $any) if (count($matches) === 0 && $any) {
{ if (count($availableLanguages) > 0) {
if (count($availableLanguages) > 0)
{
$matches['1.0'] = $availableLanguages; $matches['1.0'] = $availableLanguages;
} }
} }
if (count($matches) === 0) if (count($matches) === 0) {
{
return self::$_languageFallback; return self::$_languageFallback;
} }
krsort($matches); krsort($matches);
@ -383,12 +368,14 @@ class i18n
* @param string $b * @param string $b
* @return float * @return float
*/ */
protected static function _matchLanguage($a, $b) { protected static function _matchLanguage($a, $b)
{
$a = explode('-', $a); $a = explode('-', $a);
$b = explode('-', $b); $b = explode('-', $b);
for ($i=0, $n = min(count($a), count($b)); $i < $n; ++$i) for ($i=0, $n = min(count($a), count($b)); $i < $n; ++$i) {
{ if ($a[$i] !== $b[$i]) {
if ($a[$i] !== $b[$i]) break; break;
}
} }
return $i === 0 ? 0 : (float) $i / count($a); return $i === 0 ? 0 : (float) $i / count($a);
} }

View file

@ -10,6 +10,10 @@
* @version 0.22 * @version 0.22
*/ */
namespace PrivateBin;
use PrivateBin\model\paste;
/** /**
* model * model
* *
@ -50,8 +54,10 @@ class model
*/ */
public function getPaste($pasteId = null) public function getPaste($pasteId = null)
{ {
$paste = new model_paste($this->_conf, $this->_getStore()); $paste = new paste($this->_conf, $this->_getStore());
if ($pasteId !== null) $paste->setId($pasteId); if ($pasteId !== null) {
$paste->setId($pasteId);
}
return $paste; return $paste;
} }
@ -63,8 +69,7 @@ class model
public function purge() public function purge()
{ {
purgelimiter::setConfiguration($this->_conf); purgelimiter::setConfiguration($this->_conf);
if (purgelimiter::canPurge()) if (purgelimiter::canPurge()) {
{
$this->_getStore()->purge($this->_conf->getKey('batchsize', 'purge')); $this->_getStore()->purge($this->_conf->getKey('batchsize', 'purge'));
} }
} }
@ -76,8 +81,7 @@ class model
*/ */
private function _getStore() private function _getStore()
{ {
if ($this->_store === null) if ($this->_store === null) {
{
$this->_store = forward_static_call( $this->_store = forward_static_call(
array($this->_conf->getKey('class', 'model'), 'getInstance'), array($this->_conf->getKey('class', 'model'), 'getInstance'),
$this->_conf->getSection('model_options') $this->_conf->getSection('model_options')

View file

@ -10,12 +10,20 @@
* @version 0.22 * @version 0.22
*/ */
namespace PrivateBin\Model;
use Exception;
use PrivateBin\configuration;
use PrivateBin\data\AbstractData;
use PrivateBin\sjcl;
use stdClass;
/** /**
* model_abstract * model_abstract
* *
* Abstract model for PrivateBin objects. * Abstract model for PrivateBin objects.
*/ */
abstract class model_abstract abstract class AbstractModel
{ {
/** /**
* Instance ID. * Instance ID.
@ -57,7 +65,7 @@ abstract class model_abstract
* @param privatebin_abstract $storage * @param privatebin_abstract $storage
* @return void * @return void
*/ */
public function __construct(configuration $configuration, privatebin_abstract $storage) public function __construct(configuration $configuration, AbstractData $storage)
{ {
$this->_conf = $configuration; $this->_conf = $configuration;
$this->_store = $storage; $this->_store = $storage;
@ -86,7 +94,9 @@ abstract class model_abstract
*/ */
public function setId($id) public function setId($id)
{ {
if (!self::isValidId($id)) throw new Exception('Invalid paste ID.', 60); if (!self::isValidId($id)) {
throw new Exception('Invalid paste ID.', 60);
}
$this->_id = $id; $this->_id = $id;
} }
@ -100,7 +110,9 @@ abstract class model_abstract
*/ */
public function setData($data) public function setData($data)
{ {
if (!sjcl::isValid($data)) throw new Exception('Invalid data.', 61); if (!sjcl::isValid($data)) {
throw new Exception('Invalid data.', 61);
}
$this->_data->data = $data; $this->_data->data = $data;
// We just want a small hash to avoid collisions: // We just want a small hash to avoid collisions:

View file

@ -10,12 +10,19 @@
* @version 0.22 * @version 0.22
*/ */
namespace PrivateBin\model;
use Exception;
use PrivateBin\sjcl;
use PrivateBin\trafficlimiter;
use PrivateBin\vizhash16x16;
/** /**
* model_comment * model_comment
* *
* Model of a PrivateBin comment. * Model of a PrivateBin comment.
*/ */
class model_comment extends model_abstract class comment extends AbstractModel
{ {
/** /**
* Instance's parent. * Instance's parent.
@ -59,16 +66,19 @@ class model_comment extends model_abstract
{ {
// Make sure paste exists. // Make sure paste exists.
$pasteid = $this->getPaste()->getId(); $pasteid = $this->getPaste()->getId();
if (!$this->getPaste()->exists()) if (!$this->getPaste()->exists()) {
throw new Exception('Invalid data.', 67); throw new Exception('Invalid data.', 67);
}
// Make sure the discussion is opened in this paste and in configuration. // Make sure the discussion is opened in this paste and in configuration.
if (!$this->getPaste()->isOpendiscussion() || !$this->_conf->getKey('discussion')) if (!$this->getPaste()->isOpendiscussion() || !$this->_conf->getKey('discussion')) {
throw new Exception('Invalid data.', 68); throw new Exception('Invalid data.', 68);
}
// Check for improbable collision. // Check for improbable collision.
if ($this->exists()) if ($this->exists()) {
throw new Exception('You are unlucky. Try again.', 69); throw new Exception('You are unlucky. Try again.', 69);
}
$this->_data->meta->postdate = time(); $this->_data->meta->postdate = time();
@ -80,7 +90,9 @@ class model_comment extends model_abstract
$this->getId(), $this->getId(),
json_decode(json_encode($this->_data), true) json_decode(json_encode($this->_data), true)
) === false ) === false
) throw new Exception('Error saving comment. Sorry.', 70); ) {
throw new Exception('Error saving comment. Sorry.', 70);
}
} }
/** /**
@ -118,7 +130,7 @@ class model_comment extends model_abstract
* @throws Exception * @throws Exception
* @return void * @return void
*/ */
public function setPaste(model_paste $paste) public function setPaste(paste $paste)
{ {
$this->_paste = $paste; $this->_paste = $paste;
$this->_data->meta->pasteid = $paste->getId(); $this->_data->meta->pasteid = $paste->getId();
@ -145,7 +157,9 @@ class model_comment extends model_abstract
*/ */
public function setParentId($id) public function setParentId($id)
{ {
if (!self::isValidId($id)) throw new Exception('Invalid paste ID.', 65); if (!self::isValidId($id)) {
throw new Exception('Invalid paste ID.', 65);
}
$this->_data->meta->parentid = $id; $this->_data->meta->parentid = $id;
} }
@ -157,7 +171,9 @@ class model_comment extends model_abstract
*/ */
public function getParentId() public function getParentId()
{ {
if (!property_exists($this->_data->meta, 'parentid')) $this->_data->meta->parentid = ''; if (!property_exists($this->_data->meta, 'parentid')) {
$this->_data->meta->parentid = '';
}
return $this->_data->meta->parentid; return $this->_data->meta->parentid;
} }
@ -171,19 +187,19 @@ class model_comment extends model_abstract
*/ */
public function setNickname($nickname) public function setNickname($nickname)
{ {
if (!sjcl::isValid($nickname)) throw new Exception('Invalid data.', 66); if (!sjcl::isValid($nickname)) {
throw new Exception('Invalid data.', 66);
}
$this->_data->meta->nickname = $nickname; $this->_data->meta->nickname = $nickname;
if ($this->_conf->getKey('vizhash')) if ($this->_conf->getKey('vizhash')) {
{
// Generation of the anonymous avatar (Vizhash): // Generation of the anonymous avatar (Vizhash):
// If a nickname is provided, we generate a Vizhash. // If a nickname is provided, we generate a Vizhash.
// (We assume that if the user did not enter a nickname, he/she wants // (We assume that if the user did not enter a nickname, he/she wants
// to be anonymous and we will not generate the vizhash.) // to be anonymous and we will not generate the vizhash.)
$vh = new vizhash16x16(); $vh = new vizhash16x16();
$pngdata = $vh->generate(trafficlimiter::getIp()); $pngdata = $vh->generate(trafficlimiter::getIp());
if ($pngdata != '') if ($pngdata != '') {
{
$this->_data->meta->vizhash = 'data:image/png;base64,' . base64_encode($pngdata); $this->_data->meta->vizhash = 'data:image/png;base64,' . base64_encode($pngdata);
} }
// Once the avatar is generated, we do not keep the IP address, nor its hash. // Once the avatar is generated, we do not keep the IP address, nor its hash.

View file

@ -10,12 +10,19 @@
* @version 0.22 * @version 0.22
*/ */
namespace PrivateBin\model;
use Exception;
use PrivateBin\privatebin;
use PrivateBin\serversalt;
use PrivateBin\sjcl;
/** /**
* model_paste * model_paste
* *
* Model of a PrivateBin paste. * Model of a PrivateBin paste.
*/ */
class model_paste extends model_abstract class paste extends AbstractModel
{ {
/** /**
* Get paste data. * Get paste data.
@ -27,13 +34,13 @@ class model_paste extends model_abstract
public function get() public function get()
{ {
$this->_data = $this->_store->read($this->getId()); $this->_data = $this->_store->read($this->getId());
if ($this->_data === false) throw new Exception(privatebin::GENERIC_ERROR, 64); if ($this->_data === false) {
throw new Exception(privatebin::GENERIC_ERROR, 64);
}
// check if paste has expired and delete it if neccessary. // check if paste has expired and delete it if neccessary.
if (property_exists($this->_data->meta, 'expire_date')) if (property_exists($this->_data->meta, 'expire_date')) {
{ if ($this->_data->meta->expire_date < time()) {
if ($this->_data->meta->expire_date < time())
{
$this->delete(); $this->delete();
throw new Exception(privatebin::GENERIC_ERROR, 63); throw new Exception(privatebin::GENERIC_ERROR, 63);
} }
@ -42,22 +49,17 @@ class model_paste extends model_abstract
} }
// set formatter for for the view. // set formatter for for the view.
if (!property_exists($this->_data->meta, 'formatter')) if (!property_exists($this->_data->meta, 'formatter')) {
{
// support < 0.21 syntax highlighting // support < 0.21 syntax highlighting
if (property_exists($this->_data->meta, 'syntaxcoloring') && $this->_data->meta->syntaxcoloring === true) if (property_exists($this->_data->meta, 'syntaxcoloring') && $this->_data->meta->syntaxcoloring === true) {
{
$this->_data->meta->formatter = 'syntaxhighlighting'; $this->_data->meta->formatter = 'syntaxhighlighting';
} } else {
else
{
$this->_data->meta->formatter = $this->_conf->getKey('defaultformatter'); $this->_data->meta->formatter = $this->_conf->getKey('defaultformatter');
} }
} }
// support old paste format with server wide salt // support old paste format with server wide salt
if (!property_exists($this->_data->meta, 'salt')) if (!property_exists($this->_data->meta, 'salt')) {
{
$this->_data->meta->salt = serversalt::get(); $this->_data->meta->salt = serversalt::get();
} }
$this->_data->comments = array_values($this->getComments()); $this->_data->comments = array_values($this->getComments());
@ -77,8 +79,9 @@ class model_paste extends model_abstract
public function store() public function store()
{ {
// Check for improbable collision. // Check for improbable collision.
if ($this->exists()) if ($this->exists()) {
throw new Exception('You are unlucky. Try again.', 75); throw new Exception('You are unlucky. Try again.', 75);
}
$this->_data->meta->postdate = time(); $this->_data->meta->postdate = time();
$this->_data->meta->salt = serversalt::generate(); $this->_data->meta->salt = serversalt::generate();
@ -89,7 +92,9 @@ class model_paste extends model_abstract
$this->getId(), $this->getId(),
json_decode(json_encode($this->_data), true) json_decode(json_encode($this->_data), true)
) === false ) === false
) throw new Exception('Error saving paste. Sorry.', 76); ) {
throw new Exception('Error saving paste. Sorry.', 76);
}
} }
/** /**
@ -126,14 +131,15 @@ class model_paste extends model_abstract
*/ */
public function getComment($parentId, $commentId = null) public function getComment($parentId, $commentId = null)
{ {
if (!$this->exists()) if (!$this->exists()) {
{
throw new Exception('Invalid data.', 62); throw new Exception('Invalid data.', 62);
} }
$comment = new model_comment($this->_conf, $this->_store); $comment = new comment($this->_conf, $this->_store);
$comment->setPaste($this); $comment->setPaste($this);
$comment->setParentId($parentId); $comment->setParentId($parentId);
if ($commentId !== null) $comment->setId($commentId); if ($commentId !== null) {
$comment->setId($commentId);
}
return $comment; return $comment;
} }
@ -160,7 +166,9 @@ class model_paste extends model_abstract
*/ */
public function getDeleteToken() public function getDeleteToken()
{ {
if (!property_exists($this->_data->meta, 'salt')) $this->get(); if (!property_exists($this->_data->meta, 'salt')) {
$this->get();
}
return hash_hmac( return hash_hmac(
$this->_conf->getKey('zerobincompatibility') ? 'sha1' : 'sha256', $this->_conf->getKey('zerobincompatibility') ? 'sha1' : 'sha256',
$this->getId(), $this->getId(),
@ -178,8 +186,9 @@ class model_paste extends model_abstract
*/ */
public function setAttachment($attachment) public function setAttachment($attachment)
{ {
if (!$this->_conf->getKey('fileupload') || !sjcl::isValid($attachment)) if (!$this->_conf->getKey('fileupload') || !sjcl::isValid($attachment)) {
throw new Exception('Invalid attachment.', 71); throw new Exception('Invalid attachment.', 71);
}
$this->_data->meta->attachment = $attachment; $this->_data->meta->attachment = $attachment;
} }
@ -193,8 +202,9 @@ class model_paste extends model_abstract
*/ */
public function setAttachmentName($attachmentname) public function setAttachmentName($attachmentname)
{ {
if (!$this->_conf->getKey('fileupload') || !sjcl::isValid($attachmentname)) if (!$this->_conf->getKey('fileupload') || !sjcl::isValid($attachmentname)) {
throw new Exception('Invalid attachment.', 72); throw new Exception('Invalid attachment.', 72);
}
$this->_data->meta->attachmentname = $attachmentname; $this->_data->meta->attachmentname = $attachmentname;
} }
@ -208,16 +218,15 @@ class model_paste extends model_abstract
public function setExpiration($expiration) public function setExpiration($expiration)
{ {
$expire_options = $this->_conf->getSection('expire_options'); $expire_options = $this->_conf->getSection('expire_options');
if (array_key_exists($expiration, $expire_options)) if (array_key_exists($expiration, $expire_options)) {
{
$expire = $expire_options[$expiration]; $expire = $expire_options[$expiration];
} } else {
else
{
// using getKey() to ensure a default value is present // using getKey() to ensure a default value is present
$expire = $this->_conf->getKey($this->_conf->getKey('default', 'expire'), 'expire_options'); $expire = $this->_conf->getKey($this->_conf->getKey('default', 'expire'), 'expire_options');
} }
if ($expire > 0) $this->_data->meta->expire_date = time() + $expire; if ($expire > 0) {
$this->_data->meta->expire_date = time() + $expire;
}
} }
/** /**
@ -230,14 +239,12 @@ class model_paste extends model_abstract
*/ */
public function setBurnafterreading($burnafterreading = '1') public function setBurnafterreading($burnafterreading = '1')
{ {
if ($burnafterreading === '0') if ($burnafterreading === '0') {
{
$this->_data->meta->burnafterreading = false; $this->_data->meta->burnafterreading = false;
} } else {
else if ($burnafterreading !== '1') {
{
if ($burnafterreading !== '1')
throw new Exception('Invalid data.', 73); throw new Exception('Invalid data.', 73);
}
$this->_data->meta->burnafterreading = true; $this->_data->meta->burnafterreading = true;
$this->_data->meta->opendiscussion = false; $this->_data->meta->opendiscussion = false;
} }
@ -257,14 +264,12 @@ class model_paste extends model_abstract
!$this->_conf->getKey('discussion') || !$this->_conf->getKey('discussion') ||
$this->isBurnafterreading() || $this->isBurnafterreading() ||
$opendiscussion === '0' $opendiscussion === '0'
) ) {
{
$this->_data->meta->opendiscussion = false; $this->_data->meta->opendiscussion = false;
} } else {
else if ($opendiscussion !== '1') {
{
if ($opendiscussion !== '1')
throw new Exception('Invalid data.', 74); throw new Exception('Invalid data.', 74);
}
$this->_data->meta->opendiscussion = true; $this->_data->meta->opendiscussion = true;
} }
} }
@ -279,8 +284,7 @@ class model_paste extends model_abstract
*/ */
public function setFormatter($format) public function setFormatter($format)
{ {
if (!array_key_exists($format, $this->_conf->getSection('formatter_options'))) if (!array_key_exists($format, $this->_conf->getSection('formatter_options'))) {
{
$format = $this->_conf->getKey('defaultformatter'); $format = $this->_conf->getKey('defaultformatter');
} }
$this->_data->meta->formatter = $format; $this->_data->meta->formatter = $format;
@ -295,7 +299,9 @@ class model_paste extends model_abstract
*/ */
public function isBurnafterreading() public function isBurnafterreading()
{ {
if (!property_exists($this->_data, 'data')) $this->get(); if (!property_exists($this->_data, 'data')) {
$this->get();
}
return property_exists($this->_data->meta, 'burnafterreading') && return property_exists($this->_data->meta, 'burnafterreading') &&
$this->_data->meta->burnafterreading === true; $this->_data->meta->burnafterreading === true;
} }
@ -310,7 +316,9 @@ class model_paste extends model_abstract
*/ */
public function isOpendiscussion() public function isOpendiscussion()
{ {
if (!property_exists($this->_data, 'data')) $this->get(); if (!property_exists($this->_data, 'data')) {
$this->get();
}
return property_exists($this->_data->meta, 'opendiscussion') && return property_exists($this->_data->meta, 'opendiscussion') &&
$this->_data->meta->opendiscussion === true; $this->_data->meta->opendiscussion === true;
} }

View file

@ -10,6 +10,10 @@
* @version 0.22 * @version 0.22
*/ */
namespace PrivateBin;
use Exception;
/** /**
* persistence * persistence
* *
@ -49,12 +53,9 @@ abstract class persistence
*/ */
public static function getPath($filename = null) public static function getPath($filename = null)
{ {
if (strlen($filename)) if (strlen($filename)) {
{
return self::$_path . DIRECTORY_SEPARATOR . $filename; return self::$_path . DIRECTORY_SEPARATOR . $filename;
} } else {
else
{
return self::$_path; return self::$_path;
} }
} }
@ -84,14 +85,15 @@ abstract class persistence
protected static function _initialize() protected static function _initialize()
{ {
// Create storage directory if it does not exist. // Create storage directory if it does not exist.
if (!is_dir(self::$_path)) if (!is_dir(self::$_path)) {
if (!@mkdir(self::$_path)) if (!@mkdir(self::$_path)) {
throw new Exception('unable to create directory ' . self::$_path, 10); throw new Exception('unable to create directory ' . self::$_path, 10);
}
}
// Create .htaccess file if it does not exist. // Create .htaccess file if it does not exist.
$file = self::$_path . DIRECTORY_SEPARATOR . '.htaccess'; $file = self::$_path . DIRECTORY_SEPARATOR . '.htaccess';
if (!is_file($file)) if (!is_file($file)) {
{
$writtenBytes = @file_put_contents( $writtenBytes = @file_put_contents(
$file, $file,
'Allow from none' . PHP_EOL . 'Allow from none' . PHP_EOL .
@ -119,8 +121,7 @@ abstract class persistence
self::_initialize(); self::_initialize();
$file = self::$_path . DIRECTORY_SEPARATOR . $filename; $file = self::$_path . DIRECTORY_SEPARATOR . $filename;
$writtenBytes = @file_put_contents($file, $data, LOCK_EX); $writtenBytes = @file_put_contents($file, $data, LOCK_EX);
if ($writtenBytes === false || $writtenBytes < strlen($data)) if ($writtenBytes === false || $writtenBytes < strlen($data)) {
{
throw new Exception('unable to write to file ' . $file, 13); throw new Exception('unable to write to file ' . $file, 13);
} }
@chmod($file, 0640); // protect file access @chmod($file, 0640); // protect file access

View file

@ -10,6 +10,10 @@
* @version 0.22 * @version 0.22
*/ */
namespace PrivateBin;
use Exception;
/** /**
* privatebin * privatebin
* *
@ -113,16 +117,14 @@ class privatebin
*/ */
public function __construct() public function __construct()
{ {
if (version_compare(PHP_VERSION, '5.2.6') < 0) if (version_compare(PHP_VERSION, '5.3.0') < 0) {
{ throw new Exception(i18n::_('PrivateBin requires php 5.3.0 or above to work. Sorry.'), 1);
throw new Exception(i18n::_('PrivateBin requires php 5.2.6 or above to work. Sorry.'), 1);
} }
// load config from ini file // load config from ini file
$this->_init(); $this->_init();
switch ($this->_request->getOperation()) switch ($this->_request->getOperation()) {
{
case 'create': case 'create':
$this->_create(); $this->_create();
break; break;
@ -141,16 +143,13 @@ class privatebin
} }
// output JSON or HTML // output JSON or HTML
if ($this->_request->isJsonApiCall()) if ($this->_request->isJsonApiCall()) {
{
header('Content-type: ' . request::MIME_JSON); header('Content-type: ' . request::MIME_JSON);
header('Access-Control-Allow-Origin: *'); header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE'); header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE');
header('Access-Control-Allow-Headers: X-Requested-With, Content-Type'); header('Access-Control-Allow-Headers: X-Requested-With, Content-Type');
echo $this->_json; echo $this->_json;
} } else {
else
{
$this->_view(); $this->_view();
} }
} }
@ -163,14 +162,15 @@ class privatebin
*/ */
private function _init() private function _init()
{ {
foreach (array('cfg', 'lib') as $dir) foreach (array('cfg', 'lib') as $dir) {
{ if (!is_file(PATH . $dir . DIRECTORY_SEPARATOR . '.htaccess')) {
if (!is_file(PATH . $dir . DIRECTORY_SEPARATOR . '.htaccess')) file_put_contents( file_put_contents(
PATH . $dir . DIRECTORY_SEPARATOR . '.htaccess', PATH . $dir . DIRECTORY_SEPARATOR . '.htaccess',
'Allow from none' . PHP_EOL . 'Allow from none' . PHP_EOL .
'Deny from all'. PHP_EOL, 'Deny from all'. PHP_EOL,
LOCK_EX LOCK_EX
); );
}
} }
$this->_conf = new configuration; $this->_conf = new configuration;
@ -183,8 +183,7 @@ class privatebin
$lang = $this->_conf->getKey('languagedefault'); $lang = $this->_conf->getKey('languagedefault');
i18n::setLanguageFallback($lang); i18n::setLanguageFallback($lang);
// force default language, if language selection is disabled and a default is set // force default language, if language selection is disabled and a default is set
if (!$this->_conf->getKey('languageselection') && strlen($lang) == 2) if (!$this->_conf->getKey('languageselection') && strlen($lang) == 2) {
{
$_COOKIE['lang'] = $lang; $_COOKIE['lang'] = $lang;
setcookie('lang', $lang); setcookie('lang', $lang);
} }
@ -214,12 +213,14 @@ class privatebin
{ {
// Ensure last paste from visitors IP address was more than configured amount of seconds ago. // Ensure last paste from visitors IP address was more than configured amount of seconds ago.
trafficlimiter::setConfiguration($this->_conf); trafficlimiter::setConfiguration($this->_conf);
if (!trafficlimiter::canPass()) return $this->_return_message( if (!trafficlimiter::canPass()) {
return $this->_return_message(
1, i18n::_( 1, i18n::_(
'Please wait %d seconds between each post.', 'Please wait %d seconds between each post.',
$this->_conf->getKey('limit', 'traffic') $this->_conf->getKey('limit', 'traffic')
) )
); );
}
$data = $this->_request->getParam('data'); $data = $this->_request->getParam('data');
$attachment = $this->_request->getParam('attachment'); $attachment = $this->_request->getParam('attachment');
@ -229,71 +230,78 @@ class privatebin
$sizelimit = $this->_conf->getKey('sizelimit'); $sizelimit = $this->_conf->getKey('sizelimit');
if ( if (
strlen($data) + strlen($attachment) + strlen($attachmentname) > $sizelimit strlen($data) + strlen($attachment) + strlen($attachmentname) > $sizelimit
) return $this->_return_message( ) {
return $this->_return_message(
1, 1,
i18n::_( i18n::_(
'Paste is limited to %s of encrypted data.', 'Paste is limited to %s of encrypted data.',
filter::size_humanreadable($sizelimit) filter::size_humanreadable($sizelimit)
) )
); );
}
// Ensure attachment did not get lost due to webserver limits or Suhosin // Ensure attachment did not get lost due to webserver limits or Suhosin
if (strlen($attachmentname) > 0 && strlen($attachment) == 0) if (strlen($attachmentname) > 0 && strlen($attachment) == 0) {
{
return $this->_return_message(1, 'Attachment missing in data received by server. Please check your webserver or suhosin configuration for maximum POST parameter limitations.'); return $this->_return_message(1, 'Attachment missing in data received by server. Please check your webserver or suhosin configuration for maximum POST parameter limitations.');
} }
// The user posts a comment. // The user posts a comment.
$pasteid = $this->_request->getParam('pasteid'); $pasteid = $this->_request->getParam('pasteid');
$parentid = $this->_request->getParam('parentid'); $parentid = $this->_request->getParam('parentid');
if (!empty($pasteid) && !empty($parentid)) if (!empty($pasteid) && !empty($parentid)) {
{
$paste = $this->_model->getPaste($pasteid); $paste = $this->_model->getPaste($pasteid);
if ($paste->exists()) { if ($paste->exists()) {
try { try {
$comment = $paste->getComment($parentid); $comment = $paste->getComment($parentid);
$nickname = $this->_request->getParam('nickname'); $nickname = $this->_request->getParam('nickname');
if (!empty($nickname)) $comment->setNickname($nickname); if (!empty($nickname)) {
$comment->setNickname($nickname);
}
$comment->setData($data); $comment->setData($data);
$comment->store(); $comment->store();
} catch(Exception $e) { } catch (Exception $e) {
return $this->_return_message(1, $e->getMessage()); return $this->_return_message(1, $e->getMessage());
} }
$this->_return_message(0, $comment->getId()); $this->_return_message(0, $comment->getId());
} } else {
else
{
$this->_return_message(1, 'Invalid data.'); $this->_return_message(1, 'Invalid data.');
} }
} }
// The user posts a standard paste. // The user posts a standard paste.
else else {
{
$this->_model->purge(); $this->_model->purge();
$paste = $this->_model->getPaste(); $paste = $this->_model->getPaste();
try { try {
$paste->setData($data); $paste->setData($data);
if (!empty($attachment)) if (!empty($attachment)) {
{
$paste->setAttachment($attachment); $paste->setAttachment($attachment);
if (!empty($attachmentname)) if (!empty($attachmentname)) {
$paste->setAttachmentName($attachmentname); $paste->setAttachmentName($attachmentname);
}
} }
$expire = $this->_request->getParam('expire'); $expire = $this->_request->getParam('expire');
if (!empty($expire)) $paste->setExpiration($expire); if (!empty($expire)) {
$paste->setExpiration($expire);
}
$burnafterreading = $this->_request->getParam('burnafterreading'); $burnafterreading = $this->_request->getParam('burnafterreading');
if (!empty($burnafterreading)) $paste->setBurnafterreading($burnafterreading); if (!empty($burnafterreading)) {
$paste->setBurnafterreading($burnafterreading);
}
$opendiscussion = $this->_request->getParam('opendiscussion'); $opendiscussion = $this->_request->getParam('opendiscussion');
if (!empty($opendiscussion)) $paste->setOpendiscussion($opendiscussion); if (!empty($opendiscussion)) {
$paste->setOpendiscussion($opendiscussion);
}
$formatter = $this->_request->getParam('formatter'); $formatter = $this->_request->getParam('formatter');
if (!empty($formatter)) $paste->setFormatter($formatter); if (!empty($formatter)) {
$paste->setFormatter($formatter);
}
$paste->store(); $paste->store();
} catch (Exception $e) { } catch (Exception $e) {
@ -315,40 +323,28 @@ class privatebin
{ {
try { try {
$paste = $this->_model->getPaste($dataid); $paste = $this->_model->getPaste($dataid);
if ($paste->exists()) if ($paste->exists()) {
{
// accessing this property ensures that the paste would be // accessing this property ensures that the paste would be
// deleted if it has already expired // deleted if it has already expired
$burnafterreading = $paste->isBurnafterreading(); $burnafterreading = $paste->isBurnafterreading();
if ($deletetoken == 'burnafterreading') if ($deletetoken == 'burnafterreading') {
{ if ($burnafterreading) {
if ($burnafterreading)
{
$paste->delete(); $paste->delete();
$this->_return_message(0, $dataid); $this->_return_message(0, $dataid);
} } else {
else
{
$this->_return_message(1, 'Paste is not of burn-after-reading type.'); $this->_return_message(1, 'Paste is not of burn-after-reading type.');
} }
} } else {
else
{
// Make sure the token is valid. // Make sure the token is valid.
if (filter::slow_equals($deletetoken, $paste->getDeleteToken())) if (filter::slow_equals($deletetoken, $paste->getDeleteToken())) {
{
// Paste exists and deletion token is valid: Delete the paste. // Paste exists and deletion token is valid: Delete the paste.
$paste->delete(); $paste->delete();
$this->_status = 'Paste was properly deleted.'; $this->_status = 'Paste was properly deleted.';
} } else {
else
{
$this->_error = 'Wrong deletion token. Paste was not deleted.'; $this->_error = 'Wrong deletion token. Paste was not deleted.';
} }
} }
} } else {
else
{
$this->_error = self::GENERIC_ERROR; $this->_error = self::GENERIC_ERROR;
} }
} catch (Exception $e) { } catch (Exception $e) {
@ -367,29 +363,24 @@ class privatebin
{ {
try { try {
$paste = $this->_model->getPaste($dataid); $paste = $this->_model->getPaste($dataid);
if ($paste->exists()) if ($paste->exists()) {
{
$data = $paste->get(); $data = $paste->get();
$this->_doesExpire = property_exists($data, 'meta') && property_exists($data->meta, 'expire_date'); $this->_doesExpire = property_exists($data, 'meta') && property_exists($data->meta, 'expire_date');
if (property_exists($data->meta, 'salt')) unset($data->meta->salt); if (property_exists($data->meta, 'salt')) {
unset($data->meta->salt);
}
$this->_data = json_encode($data); $this->_data = json_encode($data);
} } else {
else
{
$this->_error = self::GENERIC_ERROR; $this->_error = self::GENERIC_ERROR;
} }
} catch (Exception $e) { } catch (Exception $e) {
$this->_error = $e->getMessage(); $this->_error = $e->getMessage();
} }
if ($this->_request->isJsonApiCall()) if ($this->_request->isJsonApiCall()) {
{ if (strlen($this->_error)) {
if (strlen($this->_error))
{
$this->_return_message(1, $this->_error); $this->_return_message(1, $this->_error);
} } else {
else
{
$this->_return_message(0, $dataid, json_decode($this->_data, true)); $this->_return_message(0, $dataid, json_decode($this->_data, true));
} }
} }
@ -413,18 +404,16 @@ class privatebin
// label all the expiration options // label all the expiration options
$expire = array(); $expire = array();
foreach ($this->_conf->getSection('expire_options') as $time => $seconds) foreach ($this->_conf->getSection('expire_options') as $time => $seconds) {
{
$expire[$time] = ($seconds == 0) ? i18n::_(ucfirst($time)): filter::time_humanreadable($time); $expire[$time] = ($seconds == 0) ? i18n::_(ucfirst($time)): filter::time_humanreadable($time);
} }
// translate all the formatter options // translate all the formatter options
$formatters = array_map(array('i18n', 'translate'), $this->_conf->getSection('formatter_options')); $formatters = array_map(array('PrivateBin\\i18n', 'translate'), $this->_conf->getSection('formatter_options'));
// set language cookie if that functionality was enabled // set language cookie if that functionality was enabled
$languageselection = ''; $languageselection = '';
if ($this->_conf->getKey('languageselection')) if ($this->_conf->getKey('languageselection')) {
{
$languageselection = i18n::getLanguage(); $languageselection = i18n::getLanguage();
setcookie('lang', $languageselection); setcookie('lang', $languageselection);
} }
@ -467,14 +456,12 @@ class privatebin
if ( if (
$type !== 'paste' && $type !== 'comment' && $type !== 'paste' && $type !== 'comment' &&
$type !== 'pastemeta' && $type !== 'commentmeta' $type !== 'pastemeta' && $type !== 'commentmeta'
) ) {
{
$type = ''; $type = '';
} }
$content = '{}'; $content = '{}';
$file = PUBLIC_PATH . DIRECTORY_SEPARATOR . 'js' . DIRECTORY_SEPARATOR . $type . '.jsonld'; $file = PUBLIC_PATH . DIRECTORY_SEPARATOR . 'js' . DIRECTORY_SEPARATOR . $type . '.jsonld';
if (is_readable($file)) if (is_readable($file)) {
{
$content = str_replace( $content = str_replace(
'?jsonld=', '?jsonld=',
$this->_urlbase . '?jsonld=', $this->_urlbase . '?jsonld=',
@ -500,12 +487,9 @@ class privatebin
private function _return_message($status, $message, $other = array()) private function _return_message($status, $message, $other = array())
{ {
$result = array('status' => $status); $result = array('status' => $status);
if ($status) if ($status) {
{
$result['message'] = i18n::_($message); $result['message'] = i18n::_($message);
} } else {
else
{
$result['id'] = $message; $result['id'] = $message;
$result['url'] = $this->_urlbase . '?' . $message; $result['url'] = $this->_urlbase . '?' . $message;
} }

View file

@ -10,6 +10,8 @@
* @version 0.22 * @version 0.22
*/ */
namespace PrivateBin;
/** /**
* purgelimiter * purgelimiter
* *
@ -64,12 +66,13 @@ class purgelimiter extends persistence
public static function canPurge() public static function canPurge()
{ {
// disable limits if set to less then 1 // disable limits if set to less then 1
if (self::$_limit < 1) return true; if (self::$_limit < 1) {
return true;
}
$file = 'purge_limiter.php'; $file = 'purge_limiter.php';
$now = time(); $now = time();
if (!self::_exists($file)) if (!self::_exists($file)) {
{
self::_store( self::_store(
$file, $file,
'<?php' . PHP_EOL . '<?php' . PHP_EOL .
@ -81,12 +84,9 @@ class purgelimiter extends persistence
require $path; require $path;
$pl = $GLOBALS['purge_limiter']; $pl = $GLOBALS['purge_limiter'];
if ($pl + self::$_limit >= $now) if ($pl + self::$_limit >= $now) {
{
$result = false; $result = false;
} } else {
else
{
$result = true; $result = true;
self::_store( self::_store(
$file, $file,

View file

@ -10,6 +10,8 @@
* @version 0.22 * @version 0.22
*/ */
namespace PrivateBin;
/** /**
* request * request
* *
@ -79,8 +81,7 @@ class request
public function __construct() public function __construct()
{ {
// in case stupid admin has left magic_quotes enabled in php.ini (for PHP < 5.4) // in case stupid admin has left magic_quotes enabled in php.ini (for PHP < 5.4)
if (function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc()) if (function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc()) {
{
$_POST = array_map('filter::stripslashes_deep', $_POST); $_POST = array_map('filter::stripslashes_deep', $_POST);
$_GET = array_map('filter::stripslashes_deep', $_GET); $_GET = array_map('filter::stripslashes_deep', $_GET);
$_COOKIE = array_map('filter::stripslashes_deep', $_COOKIE); $_COOKIE = array_map('filter::stripslashes_deep', $_COOKIE);
@ -90,8 +91,7 @@ class request
$this->_isJsonApi = $this->_detectJsonRequest(); $this->_isJsonApi = $this->_detectJsonRequest();
// parse parameters, depending on request type // parse parameters, depending on request type
switch (array_key_exists('REQUEST_METHOD', $_SERVER) ? $_SERVER['REQUEST_METHOD'] : 'GET') switch (array_key_exists('REQUEST_METHOD', $_SERVER) ? $_SERVER['REQUEST_METHOD'] : 'GET') {
{
case 'DELETE': case 'DELETE':
case 'PUT': case 'PUT':
parse_str(file_get_contents(self::$_inputStream), $this->_params); parse_str(file_get_contents(self::$_inputStream), $this->_params);
@ -107,8 +107,7 @@ class request
!array_key_exists('jsonld', $this->_params) && !array_key_exists('jsonld', $this->_params) &&
array_key_exists('QUERY_STRING', $_SERVER) && array_key_exists('QUERY_STRING', $_SERVER) &&
!empty($_SERVER['QUERY_STRING']) !empty($_SERVER['QUERY_STRING'])
) ) {
{
$this->_params['pasteid'] = $_SERVER['QUERY_STRING']; $this->_params['pasteid'] = $_SERVER['QUERY_STRING'];
} }
@ -116,23 +115,15 @@ class request
if ( if (
(array_key_exists('data', $this->_params) && !empty($this->_params['data'])) || (array_key_exists('data', $this->_params) && !empty($this->_params['data'])) ||
(array_key_exists('attachment', $this->_params) && !empty($this->_params['attachment'])) (array_key_exists('attachment', $this->_params) && !empty($this->_params['attachment']))
) ) {
{
$this->_operation = 'create'; $this->_operation = 'create';
} } elseif (array_key_exists('pasteid', $this->_params) && !empty($this->_params['pasteid'])) {
elseif (array_key_exists('pasteid', $this->_params) && !empty($this->_params['pasteid'])) if (array_key_exists('deletetoken', $this->_params) && !empty($this->_params['deletetoken'])) {
{
if (array_key_exists('deletetoken', $this->_params) && !empty($this->_params['deletetoken']))
{
$this->_operation = 'delete'; $this->_operation = 'delete';
} } else {
else
{
$this->_operation = 'read'; $this->_operation = 'read';
} }
} } elseif (array_key_exists('jsonld', $this->_params) && !empty($this->_params['jsonld'])) {
elseif (array_key_exists('jsonld', $this->_params) && !empty($this->_params['jsonld']))
{
$this->_operation = 'jsonld'; $this->_operation = 'jsonld';
} }
} }
@ -203,53 +194,42 @@ class request
strpos($acceptHeader, self::MIME_JSON) !== false && strpos($acceptHeader, self::MIME_JSON) !== false &&
strpos($acceptHeader, self::MIME_HTML) === false && strpos($acceptHeader, self::MIME_HTML) === false &&
strpos($acceptHeader, self::MIME_XHTML) === false) strpos($acceptHeader, self::MIME_XHTML) === false)
) ) {
{
return true; return true;
} }
// advanced case: media type negotiation // advanced case: media type negotiation
$mediaTypes = array(); $mediaTypes = array();
if ($hasAcceptHeader) if ($hasAcceptHeader) {
{
$mediaTypeRanges = explode(',', trim($acceptHeader)); $mediaTypeRanges = explode(',', trim($acceptHeader));
foreach ($mediaTypeRanges as $mediaTypeRange) foreach ($mediaTypeRanges as $mediaTypeRange) {
{
if (preg_match( if (preg_match(
'#(\*/\*|[a-z\-]+/[a-z\-+*]+(?:\s*;\s*[^q]\S*)*)(?:\s*;\s*q\s*=\s*(0(?:\.\d{0,3})|1(?:\.0{0,3})))?#', '#(\*/\*|[a-z\-]+/[a-z\-+*]+(?:\s*;\s*[^q]\S*)*)(?:\s*;\s*q\s*=\s*(0(?:\.\d{0,3})|1(?:\.0{0,3})))?#',
trim($mediaTypeRange), $match trim($mediaTypeRange), $match
)) )) {
{ if (!isset($match[2])) {
if (!isset($match[2]))
{
$match[2] = '1.0'; $match[2] = '1.0';
} } else {
else
{
$match[2] = (string) floatval($match[2]); $match[2] = (string) floatval($match[2]);
} }
if (!isset($mediaTypes[$match[2]])) if (!isset($mediaTypes[$match[2]])) {
{
$mediaTypes[$match[2]] = array(); $mediaTypes[$match[2]] = array();
} }
$mediaTypes[$match[2]][] = strtolower($match[1]); $mediaTypes[$match[2]][] = strtolower($match[1]);
} }
} }
krsort($mediaTypes); krsort($mediaTypes);
foreach ($mediaTypes as $acceptedQuality => $acceptedValues) foreach ($mediaTypes as $acceptedQuality => $acceptedValues) {
{ if ($acceptedQuality === 0.0) {
if ($acceptedQuality === 0.0) continue; continue;
foreach ($acceptedValues as $acceptedValue) }
{ foreach ($acceptedValues as $acceptedValue) {
if ( if (
strpos($acceptedValue, self::MIME_HTML) === 0 || strpos($acceptedValue, self::MIME_HTML) === 0 ||
strpos($acceptedValue, self::MIME_XHTML) === 0 strpos($acceptedValue, self::MIME_XHTML) === 0
) ) {
{
return false; return false;
} } elseif (strpos($acceptedValue, self::MIME_JSON) === 0) {
elseif (strpos($acceptedValue, self::MIME_JSON) === 0)
{
return true; return true;
} }
} }

View file

@ -10,6 +10,10 @@
* @version 0.22 * @version 0.22
*/ */
namespace PrivateBin;
use Exception;
/** /**
* serversalt * serversalt
* *
@ -41,13 +45,12 @@ class serversalt extends persistence
public static function generate() public static function generate()
{ {
$randomSalt = ''; $randomSalt = '';
if (function_exists('mcrypt_create_iv')) if (function_exists('mcrypt_create_iv')) {
{
$randomSalt = bin2hex(mcrypt_create_iv(256, MCRYPT_DEV_URANDOM)); $randomSalt = bin2hex(mcrypt_create_iv(256, MCRYPT_DEV_URANDOM));
} } else {
else // fallback to mt_rand() // fallback to mt_rand()
{
for($i = 0; $i < 256; ++$i) { for ($i = 0; $i < 256; ++$i) {
$randomSalt .= base_convert(mt_rand(), 10, 16); $randomSalt .= base_convert(mt_rand(), 10, 16);
} }
} }
@ -64,7 +67,9 @@ class serversalt extends persistence
*/ */
public static function get() public static function get()
{ {
if (strlen(self::$_salt)) return self::$_salt; if (strlen(self::$_salt)) {
return self::$_salt;
}
$file = 'salt.php'; $file = 'salt.php';
if (self::_exists($file)) { if (self::_exists($file)) {
@ -93,7 +98,7 @@ class serversalt extends persistence
*/ */
public static function setPath($path) public static function setPath($path)
{ {
self::$_salt = ''; self::$_salt = '';
parent::setPath($path); parent::setPath($path);
} }
} }

View file

@ -10,6 +10,8 @@
* @version 0.22 * @version 0.22
*/ */
namespace PrivateBin;
/** /**
* sjcl * sjcl
* *
@ -33,39 +35,68 @@ class sjcl
// Make sure content is valid json // Make sure content is valid json
$decoded = json_decode($encoded); $decoded = json_decode($encoded);
if (is_null($decoded)) return false; if (is_null($decoded)) {
return false;
}
$decoded = (array) $decoded; $decoded = (array) $decoded;
// Make sure no additionnal keys were added. // Make sure no additionnal keys were added.
if ( if (
count(array_keys($decoded)) != count($accepted_keys) count(array_keys($decoded)) != count($accepted_keys)
) return false; ) {
return false;
}
// Make sure required fields are present and contain base64 data. // Make sure required fields are present and contain base64 data.
foreach($accepted_keys as $k) foreach ($accepted_keys as $k) {
{ if (!array_key_exists($k, $decoded)) {
if (!array_key_exists($k, $decoded)) return false; return false;
}
} }
// Make sure some fields are base64 data. // Make sure some fields are base64 data.
if (!base64_decode($decoded['iv'], true)) return false; if (!base64_decode($decoded['iv'], true)) {
if (!base64_decode($decoded['salt'], true)) return false; return false;
if (!($ct = base64_decode($decoded['ct'], true))) return false; }
if (!base64_decode($decoded['salt'], true)) {
return false;
}
if (!($ct = base64_decode($decoded['ct'], true))) {
return false;
}
// Make sure some fields have a reasonable size. // Make sure some fields have a reasonable size.
if (strlen($decoded['iv']) > 24) return false; if (strlen($decoded['iv']) > 24) {
if (strlen($decoded['salt']) > 14) return false; return false;
}
if (strlen($decoded['salt']) > 14) {
return false;
}
// Make sure some fields contain no unsupported values. // Make sure some fields contain no unsupported values.
if (!(is_int($decoded['v']) || is_float($decoded['v'])) || (float) $decoded['v'] < 1) return false; if (!(is_int($decoded['v']) || is_float($decoded['v'])) || (float) $decoded['v'] < 1) {
if (!is_int($decoded['iter']) || $decoded['iter'] <= 100) return false; return false;
if (!in_array($decoded['ks'], array(128, 192, 256), true)) return false; }
if (!in_array($decoded['ts'], array(64, 96, 128), true)) return false; if (!is_int($decoded['iter']) || $decoded['iter'] <= 100) {
if (!in_array($decoded['mode'], array('ccm', 'ocb2', 'gcm'), true)) return false; return false;
if ($decoded['cipher'] !== 'aes') return false; }
if (!in_array($decoded['ks'], array(128, 192, 256), true)) {
return false;
}
if (!in_array($decoded['ts'], array(64, 96, 128), true)) {
return false;
}
if (!in_array($decoded['mode'], array('ccm', 'ocb2', 'gcm'), true)) {
return false;
}
if ($decoded['cipher'] !== 'aes') {
return false;
}
// Reject data if entropy is too low // Reject data if entropy is too low
if (strlen($ct) > strlen(gzdeflate($ct))) return false; if (strlen($ct) > strlen(gzdeflate($ct))) {
return false;
}
return true; return true;
} }

View file

@ -10,6 +10,8 @@
* @version 0.22 * @version 0.22
*/ */
namespace PrivateBin;
/** /**
* trafficlimiter * trafficlimiter
* *
@ -60,11 +62,9 @@ class trafficlimiter extends persistence
{ {
self::setLimit($conf->getKey('limit', 'traffic')); self::setLimit($conf->getKey('limit', 'traffic'));
self::setPath($conf->getKey('dir', 'traffic')); self::setPath($conf->getKey('dir', 'traffic'));
if (($option = $conf->getKey('header', 'traffic')) !== null) if (($option = $conf->getKey('header', 'traffic')) !== null) {
{
$httpHeader = 'HTTP_' . $option; $httpHeader = 'HTTP_' . $option;
if (array_key_exists($httpHeader, $_SERVER) && !empty($_SERVER[$httpHeader])) if (array_key_exists($httpHeader, $_SERVER) && !empty($_SERVER[$httpHeader])) {
{
self::$_ipKey = $httpHeader; self::$_ipKey = $httpHeader;
} }
} }
@ -95,13 +95,14 @@ class trafficlimiter extends persistence
public static function canPass() public static function canPass()
{ {
// disable limits if set to less then 1 // disable limits if set to less then 1
if (self::$_limit < 1) return true; if (self::$_limit < 1) {
return true;
}
$ip = hash_hmac('sha256', self::getIp(), serversalt::get()); $ip = hash_hmac('sha256', self::getIp(), serversalt::get());
$file = 'traffic_limiter.php'; $file = 'traffic_limiter.php';
if (!self::_exists($file)) if (!self::_exists($file)) {
{
self::_store( self::_store(
$file, $file,
'<?php' . PHP_EOL . '<?php' . PHP_EOL .
@ -115,16 +116,13 @@ class trafficlimiter extends persistence
$tl = $GLOBALS['traffic_limiter']; $tl = $GLOBALS['traffic_limiter'];
// purge file of expired IPs to keep it small // purge file of expired IPs to keep it small
foreach ($tl as $key => $time) foreach ($tl as $key => $time) {
{ if ($time + self::$_limit < $now) {
if ($time + self::$_limit < $now)
{
unset($tl[$key]); unset($tl[$key]);
} }
} }
if (array_key_exists($ip, $tl) && ($tl[$ip] + self::$_limit >= $now)) if (array_key_exists($ip, $tl) && ($tl[$ip] + self::$_limit >= $now)) {
{
$result = false; $result = false;
} else { } else {
$tl[$ip] = time(); $tl[$ip] = time();

View file

@ -10,6 +10,10 @@
* @version 0.22 * @version 0.22
*/ */
namespace PrivateBin;
use Exception;
/** /**
* view * view
* *
@ -49,8 +53,7 @@ class view
public function draw($template) public function draw($template)
{ {
$path = PATH . 'tpl' . DIRECTORY_SEPARATOR . $template . '.php'; $path = PATH . 'tpl' . DIRECTORY_SEPARATOR . $template . '.php';
if (!file_exists($path)) if (!file_exists($path)) {
{
throw new Exception('Template ' . $template . ' not found!', 80); throw new Exception('Template ' . $template . ' not found!', 80);
} }
extract($this->_variables); extract($this->_variables);

View file

@ -11,6 +11,8 @@
* @version 0.0.4 beta PrivateBin 0.22 * @version 0.0.4 beta PrivateBin 0.22
*/ */
namespace PrivateBin;
/** /**
* vizhash16x16 * vizhash16x16
* *
@ -86,42 +88,53 @@ class vizhash16x16
*/ */
public function generate($text) public function generate($text)
{ {
if (!function_exists('gd_info')) return ''; if (!function_exists('gd_info')) {
return '';
}
// We hash the input string. // We hash the input string.
$hash=hash('sha1',$text.$this->salt).hash('md5',$text.$this->salt); $hash=hash('sha1', $text.$this->salt).hash('md5', $text.$this->salt);
$hash=$hash.strrev($hash); # more data to make graphics $hash=$hash.strrev($hash); # more data to make graphics
$hashlen=strlen($hash); $hashlen=strlen($hash);
// We convert the hash into an array of integers. // We convert the hash into an array of integers.
$this->VALUES=array(); $this->VALUES=array();
for($i=0; $i<$hashlen; $i=$i+2){ array_push($this->VALUES,hexdec(substr($hash,$i,2))); } for ($i=0; $i<$hashlen; $i=$i+2) {
array_push($this->VALUES, hexdec(substr($hash, $i, 2)));
}
$this->VALUES_INDEX=0; // to walk the array. $this->VALUES_INDEX=0; // to walk the array.
// Then use these integers to drive the creation of an image. // Then use these integers to drive the creation of an image.
$image = imagecreatetruecolor($this->width,$this->height); $image = imagecreatetruecolor($this->width, $this->height);
$r0 = $this->getInt();$r=$r0; $r0 = $this->getInt();
$g0 = $this->getInt();$g=$g0; $r=$r0;
$b0 = $this->getInt();$b=$b0; $g0 = $this->getInt();
$g=$g0;
$b0 = $this->getInt();
$b=$b0;
// First, create an image with a specific gradient background. // First, create an image with a specific gradient background.
$op='v'; if (($this->getInt()%2)==0) { $op='h'; }; $op='v';
$image = $this->degrade($image,$op,array($r0,$g0,$b0),array(0,0,0)); if (($this->getInt()%2)==0) {
$op='h';
};
$image = $this->degrade($image, $op, array($r0, $g0, $b0), array(0, 0, 0));
for($i=0; $i<7; $i=$i+1) for ($i=0; $i<7; $i=$i+1) {
{
$action=$this->getInt(); $action=$this->getInt();
$color = imagecolorallocate($image, $r,$g,$b); $color = imagecolorallocate($image, $r, $g, $b);
$r = ($r0 + $this->getInt()/25)%256; $r = ($r0 + $this->getInt()/25)%256;
$g = ($g0 + $this->getInt()/25)%256; $g = ($g0 + $this->getInt()/25)%256;
$b = ($b0 + $this->getInt()/25)%256; $b = ($b0 + $this->getInt()/25)%256;
$r0=$r; $g0=$g; $b0=$b; $r0=$r;
$this->drawshape($image,$action,$color); $g0=$g;
$b0=$b;
$this->drawshape($image, $action, $color);
} }
$color = imagecolorallocate($image,$this->getInt(),$this->getInt(),$this->getInt()); $color = imagecolorallocate($image, $this->getInt(), $this->getInt(), $this->getInt());
$this->drawshape($image,$this->getInt(),$color); $this->drawshape($image, $this->getInt(), $color);
ob_start(); ob_start();
imagepng($image); imagepng($image);
$imagedata = ob_get_contents(); $imagedata = ob_get_contents();
@ -180,24 +193,31 @@ class vizhash16x16
* @param array $color2 * @param array $color2
* @return resource * @return resource
*/ */
private function degrade($img,$direction,$color1,$color2) private function degrade($img, $direction, $color1, $color2)
{ {
if($direction=='h') { $size = imagesx($img); $sizeinv = imagesy($img); } if ($direction=='h') {
else { $size = imagesy($img); $sizeinv = imagesx($img);} $size = imagesx($img);
$diffs = array( $sizeinv = imagesy($img);
} else {
$size = imagesy($img);
$sizeinv = imagesx($img);
}
$diffs = array(
(($color2[0]-$color1[0])/$size), (($color2[0]-$color1[0])/$size),
(($color2[1]-$color1[1])/$size), (($color2[1]-$color1[1])/$size),
(($color2[2]-$color1[2])/$size) (($color2[2]-$color1[2])/$size)
); );
for($i=0;$i<$size;$i++) for ($i=0;$i<$size;$i++) {
{ $r = $color1[0]+($diffs[0]*$i);
$r = $color1[0]+($diffs[0]*$i); $g = $color1[1]+($diffs[1]*$i);
$g = $color1[1]+($diffs[1]*$i); $b = $color1[2]+($diffs[2]*$i);
$b = $color1[2]+($diffs[2]*$i); if ($direction=='h') {
if($direction=='h') { imageline($img,$i,0,$i,$sizeinv,imagecolorallocate($img,$r,$g,$b)); } imageline($img, $i, 0, $i, $sizeinv, imagecolorallocate($img, $r, $g, $b));
else { imageline($img,0,$i,$sizeinv,$i,imagecolorallocate($img,$r,$g,$b)); } } else {
imageline($img, 0, $i, $sizeinv, $i, imagecolorallocate($img, $r, $g, $b));
} }
return $img; }
return $img;
} }
/** /**
@ -209,24 +229,23 @@ class vizhash16x16
* @param int $color * @param int $color
* @return void * @return void
*/ */
private function drawshape($image,$action,$color) private function drawshape($image, $action, $color)
{ {
switch($action%7) switch ($action%7) {
{
case 0: case 0:
ImageFilledRectangle ($image,$this->getX(),$this->getY(),$this->getX(),$this->getY(),$color); ImageFilledRectangle($image, $this->getX(), $this->getY(), $this->getX(), $this->getY(), $color);
break; break;
case 1: case 1:
case 2: case 2:
ImageFilledEllipse ($image, $this->getX(), $this->getY(), $this->getX(), $this->getY(), $color); ImageFilledEllipse($image, $this->getX(), $this->getY(), $this->getX(), $this->getY(), $color);
break; break;
case 3: case 3:
$points = array($this->getX(), $this->getY(), $this->getX(), $this->getY(), $this->getX(), $this->getY(),$this->getX(), $this->getY()); $points = array($this->getX(), $this->getY(), $this->getX(), $this->getY(), $this->getX(), $this->getY(),$this->getX(), $this->getY());
ImageFilledPolygon ($image, $points, 4, $color); ImageFilledPolygon($image, $points, 4, $color);
break; break;
default: default:
$start=$this->getInt()*360/256; $end=$start+$this->getInt()*180/256; $start=$this->getInt()*360/256; $end=$start+$this->getInt()*180/256;
ImageFilledArc ($image, $this->getX(), $this->getY(), $this->getX(), $this->getY(),$start,$end,$color,IMG_ARC_PIE); ImageFilledArc($image, $this->getX(), $this->getY(), $this->getX(), $this->getY(), $start, $end, $color, IMG_ARC_PIE);
} }
} }
} }

View file

@ -5,15 +5,15 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="robots" content="noindex" /> <meta name="robots" content="noindex" />
<title><?php echo i18n::_('PrivateBin'); ?></title> <title><?php echo PrivateBin\i18n::_('PrivateBin'); ?></title>
<link type="text/css" rel="stylesheet" href="css/bootstrap/bootstrap-3.3.5.css" /> <link type="text/css" rel="stylesheet" href="css/bootstrap/bootstrap-3.3.5.css" />
<link type="text/css" rel="stylesheet" href="css/bootstrap/bootstrap-theme-3.3.5.css" /> <link type="text/css" rel="stylesheet" href="css/bootstrap/bootstrap-theme-3.3.5.css" />
<link type="text/css" rel="stylesheet" href="css/bootstrap/privatebin.css?<?php echo rawurlencode($VERSION); ?>" /><?php <link type="text/css" rel="stylesheet" href="css/bootstrap/privatebin.css?<?php echo rawurlencode($VERSION); ?>" /><?php
if ($SYNTAXHIGHLIGHTING): ?> if ($SYNTAXHIGHLIGHTING): ?>
<link type="text/css" rel="stylesheet" href="css/prettify/prettify.css?<?php echo rawurlencode($VERSION); ?>" /><?php <link type="text/css" rel="stylesheet" href="css/prettify/prettify.css?<?php echo rawurlencode($VERSION); ?>" /><?php
if (strlen($SYNTAXHIGHLIGHTINGTHEME)): ?> if (strlen($SYNTAXHIGHLIGHTINGTHEME)): ?>
<link type="text/css" rel="stylesheet" href="css/prettify/<?php echo rawurlencode($SYNTAXHIGHLIGHTINGTHEME); ?>.css?<?php echo rawurlencode($VERSION); ?>" /><?php <link type="text/css" rel="stylesheet" href="css/prettify/<?php echo rawurlencode($SYNTAXHIGHLIGHTINGTHEME); ?>.css?<?php echo rawurlencode($VERSION); ?>" /><?php
endif; endif;
endif; ?> endif; ?>
<script type="text/javascript" src="js/jquery-1.11.3.js"></script> <script type="text/javascript" src="js/jquery-1.11.3.js"></script>
<script type="text/javascript" src="js/sjcl-1.0.4.js"></script> <script type="text/javascript" src="js/sjcl-1.0.4.js"></script>
@ -45,39 +45,39 @@ endif; ?>
<div class="container"> <div class="container">
<div class="navbar-header"> <div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar"> <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only"><?php echo i18n::_('Toggle navigation'); ?></span> <span class="sr-only"><?php echo PrivateBin\i18n::_('Toggle navigation'); ?></span>
<span class="icon-bar"></span> <span class="icon-bar"></span>
<span class="icon-bar"></span> <span class="icon-bar"></span>
<span class="icon-bar"></span> <span class="icon-bar"></span>
</button> </button>
<a class="reloadlink navbar-brand" href="/"> <a class="reloadlink navbar-brand" href="/">
<img alt="<?php echo i18n::_('PrivateBin'); ?>" src="img/icon.svg" width="20" /> <img alt="<?php echo PrivateBin\i18n::_('PrivateBin'); ?>" src="img/icon.svg" width="20" />
</a> </a>
</div> </div>
<div id="navbar" class="navbar-collapse collapse"> <div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav"> <ul class="nav navbar-nav">
<li> <li>
<button id="sendbutton" type="button" class="hidden btn btn-default navbar-btn"> <button id="sendbutton" type="button" class="hidden btn btn-default navbar-btn">
<span class="glyphicon glyphicon-upload" aria-hidden="true"></span> <?php echo i18n::_('Send'); ?> <span class="glyphicon glyphicon-upload" aria-hidden="true"></span> <?php echo PrivateBin\i18n::_('Send'); ?>
</button><?php </button><?php
if ($EXPIRECLONE): ?> if ($EXPIRECLONE): ?>
<button id="clonebutton" type="button" class="hidden btn btn-default navbar-btn"> <button id="clonebutton" type="button" class="hidden btn btn-default navbar-btn">
<span class="glyphicon glyphicon-duplicate" aria-hidden="true"></span> <?php echo i18n::_('Clone'); ?> <span class="glyphicon glyphicon-duplicate" aria-hidden="true"></span> <?php echo PrivateBin\i18n::_('Clone'); ?>
</button><?php </button><?php
endif; ?> endif; ?>
<button id="rawtextbutton" type="button" class="hidden btn btn-default navbar-btn"> <button id="rawtextbutton" type="button" class="hidden btn btn-default navbar-btn">
<span class="glyphicon glyphicon-text-background" aria-hidden="true"></span> <?php echo i18n::_('Raw text'); ?> <span class="glyphicon glyphicon-text-background" aria-hidden="true"></span> <?php echo PrivateBin\i18n::_('Raw text'); ?>
</button> </button>
</li> </li>
<li class="dropdown"> <li class="dropdown">
<select id="pasteExpiration" name="pasteExpiration" class="hidden"><?php <select id="pasteExpiration" name="pasteExpiration" class="hidden"><?php
foreach ($EXPIRE as $key => $value): ?> foreach ($EXPIRE as $key => $value): ?>
<option value="<?php echo $key; ?>"<?php <option value="<?php echo $key; ?>"<?php
if ($key == $EXPIREDEFAULT): ?> selected="selected"<?php if ($key == $EXPIREDEFAULT): ?> selected="selected"<?php
endif; ?>><?php echo $value; ?></option><?php endif; ?>><?php echo $value; ?></option><?php
endforeach; ?> endforeach; ?>
</select> </select>
<a id="expiration" href="#" class="hidden dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><?php echo i18n::_('Expires'); ?>: <span id="pasteExpirationDisplay"><?php echo $EXPIRE[$EXPIREDEFAULT]; ?></span> <span class="caret"></span></a> <a id="expiration" href="#" class="hidden dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><?php echo PrivateBin\i18n::_('Expires'); ?>: <span id="pasteExpirationDisplay"><?php echo $EXPIRE[$EXPIREDEFAULT]; ?></span> <span class="caret"></span></a>
<ul class="dropdown-menu"><?php <ul class="dropdown-menu"><?php
foreach ($EXPIRE as $key => $value): ?> foreach ($EXPIRE as $key => $value): ?>
<li> <li>
@ -89,30 +89,30 @@ endforeach; ?>
</ul> </ul>
</li> </li>
<li id="formatter" class="dropdown"> <li id="formatter" class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><?php echo i18n::_('Options'); ?> <span class="caret"></span></a> <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><?php echo PrivateBin\i18n::_('Options'); ?> <span class="caret"></span></a>
<ul class="dropdown-menu"> <ul class="dropdown-menu">
<li id="burnafterreadingoption" class="checkbox hidden"> <li id="burnafterreadingoption" class="checkbox hidden">
<label> <label>
<input type="checkbox" id="burnafterreading" name="burnafterreading" <?php <input type="checkbox" id="burnafterreading" name="burnafterreading" <?php
if ($BURNAFTERREADINGSELECTED): ?> checked="checked"<?php if ($BURNAFTERREADINGSELECTED): ?> checked="checked"<?php
endif; ?> /> endif; ?> />
<?php echo i18n::_('Burn after reading'); ?> <?php echo PrivateBin\i18n::_('Burn after reading'); ?>
</label> </label>
</li><?php </li><?php
if ($DISCUSSION): ?> if ($DISCUSSION): ?>
<li id="opendisc" class="checkbox hidden"> <li id="opendisc" class="checkbox hidden">
<label> <label>
<input type="checkbox" id="opendiscussion" name="opendiscussion" <?php <input type="checkbox" id="opendiscussion" name="opendiscussion" <?php
if ($OPENDISCUSSION): ?> checked="checked"<?php if ($OPENDISCUSSION): ?> checked="checked"<?php
endif; ?> /> endif; ?> />
<?php echo i18n::_('Open discussion'); ?> <?php echo PrivateBin\i18n::_('Open discussion'); ?>
</label> </label>
</li><?php </li><?php
endif; ?> endif; ?>
<li role="separator" class="divider"></li> <li role="separator" class="divider"></li>
<li> <li>
<div> <div>
<?php echo i18n::_('Format'); ?>: <span id="pasteFormatterDisplay"><?php echo $FORMATTER[$FORMATTERDEFAULT]; ?></span> <span class="caret"></span> <?php echo PrivateBin\i18n::_('Format'); ?>: <span id="pasteFormatterDisplay"><?php echo $FORMATTER[$FORMATTERDEFAULT]; ?></span> <span class="caret"></span>
</div> </div>
</li><?php </li><?php
foreach ($FORMATTER as $key => $value): ?> foreach ($FORMATTER as $key => $value): ?>
@ -126,21 +126,21 @@ endforeach; ?>
<select id="pasteFormatter" name="pasteFormatter" class="hidden"><?php <select id="pasteFormatter" name="pasteFormatter" class="hidden"><?php
foreach ($FORMATTER as $key => $value): ?> foreach ($FORMATTER as $key => $value): ?>
<option value="<?php echo $key; ?>"<?php <option value="<?php echo $key; ?>"<?php
if ($key == $FORMATTERDEFAULT): ?> selected="selected"<?php if ($key == $FORMATTERDEFAULT): ?> selected="selected"<?php
endif; ?>><?php echo $value; ?></option><?php endif; ?>><?php echo $value; ?></option><?php
endforeach; ?> endforeach; ?>
</select> </select>
</li><?php </li><?php
if ($PASSWORD): ?> if ($PASSWORD): ?>
<li> <li>
<div id="password" class="navbar-form hidden"> <div id="password" class="navbar-form hidden">
<input type="password" id="passwordinput" placeholder="<?php echo i18n::_('Password (recommended)'); ?>" class="form-control" size="19"/> <input type="password" id="passwordinput" placeholder="<?php echo PrivateBin\i18n::_('Password (recommended)'); ?>" class="form-control" size="19"/>
</div> </div>
</li><?php </li><?php
endif; endif;
if ($FILEUPLOAD): ?> if ($FILEUPLOAD): ?>
<li id="attach" class="hidden dropdown"> <li id="attach" class="hidden dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><?php echo i18n::_('Attach a file'); ?> <span class="caret"></span></a> <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><?php echo PrivateBin\i18n::_('Attach a file'); ?> <span class="caret"></span></a>
<ul class="dropdown-menu"> <ul class="dropdown-menu">
<li id="filewrap"> <li id="filewrap">
<div> <div>
@ -149,7 +149,7 @@ if ($FILEUPLOAD): ?>
</li> </li>
<li> <li>
<a id="fileremovebutton" href="#"> <a id="fileremovebutton" href="#">
<?php echo i18n::_('Remove attachment'); ?> <?php echo PrivateBin\i18n::_('Remove attachment'); ?>
</a> </a>
</li> </li>
</ul> </ul>
@ -161,19 +161,19 @@ if (strlen($LANGUAGESELECTION)): ?>
<li id="language" class="dropdown"> <li id="language" class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><span class="glyphicon glyphicon-flag" aria-hidden="true"></span> <?php echo $LANGUAGES[$LANGUAGESELECTION][0]; ?> <span class="caret"></span></a> <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><span class="glyphicon glyphicon-flag" aria-hidden="true"></span> <?php echo $LANGUAGES[$LANGUAGESELECTION][0]; ?> <span class="caret"></span></a>
<ul class="dropdown-menu"><?php <ul class="dropdown-menu"><?php
foreach ($LANGUAGES as $key => $value): ?> foreach ($LANGUAGES as $key => $value): ?>
<li> <li>
<a href="#" class="reloadlink" onclick="document.cookie='lang={$key}';"> <a href="#" class="reloadlink" onclick="document.cookie='lang={$key}';">
<?php echo $value[0]; ?> (<?php echo $value[1]; ?>) <?php echo $value[0]; ?> (<?php echo $value[1]; ?>)
</a> </a>
</li><?php </li><?php
endforeach; ?> endforeach; ?>
</ul> </ul>
</li><?php </li><?php
endif; ?> endif; ?>
<li> <li>
<button id="newbutton" type="button" class="reloadlink hidden btn btn-default navbar-btn"> <button id="newbutton" type="button" class="reloadlink hidden btn btn-default navbar-btn">
<span class="glyphicon glyphicon-file" aria-hidden="true"></span> <?php echo i18n::_('New'); ?> <span class="glyphicon glyphicon-file" aria-hidden="true"></span> <?php echo PrivateBin\i18n::_('New'); ?>
</button> </button>
</li> </li>
</ul> </ul>
@ -191,7 +191,7 @@ endif; ?>
</div><?php </div><?php
if ($FILEUPLOAD): ?> if ($FILEUPLOAD): ?>
<div id="attachment" role="alert" class="hidden alert alert-info"> <div id="attachment" role="alert" class="hidden alert alert-info">
<span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span> <a><?php echo i18n::_('Download attachment'); ?></a> <span id="clonedfile" class="hidden"><?php echo i18n::_('Cloned file attached.'); ?></span> <span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span> <a><?php echo PrivateBin\i18n::_('Download attachment'); ?></a> <span id="clonedfile" class="hidden"><?php echo PrivateBin\i18n::_('Cloned file attached.'); ?></span>
</div><?php </div><?php
endif; endif;
if (strlen($STATUS)): ?> if (strlen($STATUS)): ?>
@ -202,9 +202,9 @@ endif; ?>
<div id="errormessage" role="alert" class="<?php <div id="errormessage" role="alert" class="<?php
if (!strlen($ERROR)): ?>hidden <?php if (!strlen($ERROR)): ?>hidden <?php
endif; ?>alert alert-danger"><span class="glyphicon glyphicon-alert" aria-hidden="true"></span> <?php echo htmlspecialchars($ERROR); ?></div> endif; ?>alert alert-danger"><span class="glyphicon glyphicon-alert" aria-hidden="true"></span> <?php echo htmlspecialchars($ERROR); ?></div>
<noscript><div id="noscript" role="alert" class="nonworking alert alert-warning"><span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span> <?php echo i18n::_('Javascript is required for PrivateBin to work.<br />Sorry for the inconvenience.'); ?></div></noscript> <noscript><div id="noscript" role="alert" class="nonworking alert alert-warning"><span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span> <?php echo PrivateBin\i18n::_('Javascript is required for PrivateBin to work.<br />Sorry for the inconvenience.'); ?></div></noscript>
<div id="oldienotice" role="alert" class="hidden nonworking alert alert-danger"><span class="glyphicon glyphicon-alert" aria-hidden="true"></span> <?php echo i18n::_('PrivateBin requires a modern browser to work.'); ?></div> <div id="oldienotice" role="alert" class="hidden nonworking alert alert-danger"><span class="glyphicon glyphicon-alert" aria-hidden="true"></span> <?php echo PrivateBin\i18n::_('PrivateBin requires a modern browser to work.'); ?></div>
<div id="ienotice" role="alert" class="hidden alert alert-warning"><span class="glyphicon glyphicon-question-sign" aria-hidden="true"></span> <?php echo i18n::_('Still using Internet Explorer? Do yourself a favor, switch to a modern browser:'); ?> <div id="ienotice" role="alert" class="hidden alert alert-warning"><span class="glyphicon glyphicon-question-sign" aria-hidden="true"></span> <?php echo PrivateBin\i18n::_('Still using Internet Explorer? Do yourself a favor, switch to a modern browser:'); ?>
<a href="https://www.mozilla.org/firefox/">Firefox</a>, <a href="https://www.mozilla.org/firefox/">Firefox</a>,
<a href="https://www.opera.com/">Opera</a>, <a href="https://www.opera.com/">Opera</a>,
<a href="https://www.google.com/chrome">Chrome</a>, <a href="https://www.google.com/chrome">Chrome</a>,
@ -216,14 +216,14 @@ endif; ?>alert alert-danger"><span class="glyphicon glyphicon-alert" aria-hidden
<div id="pastelink"><?php <div id="pastelink"><?php
if (strlen($URLSHORTENER)): ?> if (strlen($URLSHORTENER)): ?>
<button id="shortenbutton" data-shortener="<?php echo htmlspecialchars($URLSHORTENER); ?>" type="button" class="btn btn-primary"> <button id="shortenbutton" data-shortener="<?php echo htmlspecialchars($URLSHORTENER); ?>" type="button" class="btn btn-primary">
<span class="glyphicon glyphicon-send" aria-hidden="true"></span> <?php echo i18n::_('Shorten URL'); ?> <span class="glyphicon glyphicon-send" aria-hidden="true"></span> <?php echo PrivateBin\i18n::_('Shorten URL'); ?>
</button><?php </button><?php
endif; ?> endif; ?>
</div> </div>
</div> </div>
<ul id="preview" class="nav nav-tabs hidden"> <ul id="preview" class="nav nav-tabs hidden">
<li role="presentation" class="active"><a id="messageedit" href="#"><?php echo i18n::_('Editor'); ?></a></li> <li role="presentation" class="active"><a id="messageedit" href="#"><?php echo PrivateBin\i18n::_('Editor'); ?></a></li>
<li role="presentation"><a id="messagepreview" href="#"><?php echo i18n::_('Preview'); ?></a></li> <li role="presentation"><a id="messagepreview" href="#"><?php echo PrivateBin\i18n::_('Preview'); ?></a></li>
</ul> </ul>
</header> </header>
<section class="container"> <section class="container">
@ -238,16 +238,16 @@ endif; ?>
</section> </section>
<section class="container"> <section class="container">
<div id="discussion" class="hidden"> <div id="discussion" class="hidden">
<h4><?php echo i18n::_('Discussion'); ?></h4> <h4><?php echo PrivateBin\i18n::_('Discussion'); ?></h4>
<div id="comments"></div> <div id="comments"></div>
</div> </div>
</section> </section>
<footer class="container"> <footer class="container">
<div class="row"> <div class="row">
<h4 class="col-md-5 col-xs-8"><?php echo i18n::_('PrivateBin'); ?> <small>- <?php echo i18n::_('Because ignorance is bliss'); ?></small></h4> <h4 class="col-md-5 col-xs-8"><?php echo PrivateBin\i18n::_('PrivateBin'); ?> <small>- <?php echo PrivateBin\i18n::_('Because ignorance is bliss'); ?></small></h4>
<p class="col-md-1 col-xs-4 text-center"><?php echo $VERSION; ?></p> <p class="col-md-1 col-xs-4 text-center"><?php echo $VERSION; ?></p>
<p id="aboutbox" class="col-md-6 col-xs-12"> <p id="aboutbox" class="col-md-6 col-xs-12">
<?php echo i18n::_('PrivateBin is a minimalist, open source online pastebin where the server has zero knowledge of pasted data. Data is encrypted/decrypted <i>in the browser</i> using 256 bits AES. More information on the <a href="https://github.com/PrivateBin/PrivateBin/wiki">project page</a>.'); ?> <?php echo PrivateBin\i18n::_('PrivateBin is a minimalist, open source online pastebin where the server has zero knowledge of pasted data. Data is encrypted/decrypted <i>in the browser</i> using 256 bits AES. More information on the <a href="https://github.com/PrivateBin/PrivateBin/wiki">project page</a>.'); ?>
</p> </p>
</div> </div>
</footer> </footer>

View file

@ -5,15 +5,15 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="robots" content="noindex" /> <meta name="robots" content="noindex" />
<title><?php echo i18n::_('PrivateBin'); ?></title> <title><?php echo PrivateBin\i18n::_('PrivateBin'); ?></title>
<link type="text/css" rel="stylesheet" href="css/bootstrap/bootstrap-theme-3.3.5.css" /> <link type="text/css" rel="stylesheet" href="css/bootstrap/bootstrap-theme-3.3.5.css" />
<link type="text/css" rel="stylesheet" href="css/bootstrap/darkstrap-0.9.3.css" /> <link type="text/css" rel="stylesheet" href="css/bootstrap/darkstrap-0.9.3.css" />
<link type="text/css" rel="stylesheet" href="css/bootstrap/privatebin.css?<?php echo rawurlencode($VERSION); ?>" /><?php <link type="text/css" rel="stylesheet" href="css/bootstrap/privatebin.css?<?php echo rawurlencode($VERSION); ?>" /><?php
if ($SYNTAXHIGHLIGHTING): ?> if ($SYNTAXHIGHLIGHTING): ?>
<link type="text/css" rel="stylesheet" href="css/prettify/prettify.css?<?php echo rawurlencode($VERSION); ?>" /><?php <link type="text/css" rel="stylesheet" href="css/prettify/prettify.css?<?php echo rawurlencode($VERSION); ?>" /><?php
if (strlen($SYNTAXHIGHLIGHTINGTHEME)): ?> if (strlen($SYNTAXHIGHLIGHTINGTHEME)): ?>
<link type="text/css" rel="stylesheet" href="css/prettify/<?php echo rawurlencode($SYNTAXHIGHLIGHTINGTHEME); ?>.css?<?php echo rawurlencode($VERSION); ?>" /><?php <link type="text/css" rel="stylesheet" href="css/prettify/<?php echo rawurlencode($SYNTAXHIGHLIGHTINGTHEME); ?>.css?<?php echo rawurlencode($VERSION); ?>" /><?php
endif; endif;
endif; ?> endif; ?>
<script type="text/javascript" src="js/jquery-1.11.3.js"></script> <script type="text/javascript" src="js/jquery-1.11.3.js"></script>
<script type="text/javascript" src="js/sjcl-1.0.4.js"></script> <script type="text/javascript" src="js/sjcl-1.0.4.js"></script>
@ -44,39 +44,39 @@ endif; ?>
<nav class="navbar navbar-inverse navbar-static-top"> <nav class="navbar navbar-inverse navbar-static-top">
<div class="navbar-header"> <div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar"> <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only"><?php echo i18n::_('Toggle navigation'); ?></span> <span class="sr-only"><?php echo PrivateBin\i18n::_('Toggle navigation'); ?></span>
<span class="icon-bar"></span> <span class="icon-bar"></span>
<span class="icon-bar"></span> <span class="icon-bar"></span>
<span class="icon-bar"></span> <span class="icon-bar"></span>
</button> </button>
<a class="reloadlink navbar-brand" href="/"> <a class="reloadlink navbar-brand" href="/">
<img alt="<?php echo i18n::_('PrivateBin'); ?>" src="img/icon.svg" width="20" /> <img alt="<?php echo PrivateBin\i18n::_('PrivateBin'); ?>" src="img/icon.svg" width="20" />
</a> </a>
</div> </div>
<div id="navbar" class="navbar-collapse collapse"> <div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav"> <ul class="nav navbar-nav">
<li> <li>
<button id="sendbutton" type="button" class="hidden btn btn-warning navbar-btn"> <button id="sendbutton" type="button" class="hidden btn btn-warning navbar-btn">
<span class="glyphicon glyphicon-upload" aria-hidden="true"></span> <?php echo i18n::_('Send'); ?> <span class="glyphicon glyphicon-upload" aria-hidden="true"></span> <?php echo PrivateBin\i18n::_('Send'); ?>
</button><?php </button><?php
if ($EXPIRECLONE): ?> if ($EXPIRECLONE): ?>
<button id="clonebutton" type="button" class="hidden btn btn-warning navbar-btn"> <button id="clonebutton" type="button" class="hidden btn btn-warning navbar-btn">
<span class="glyphicon glyphicon-duplicate" aria-hidden="true"></span> <?php echo i18n::_('Clone'); ?> <span class="glyphicon glyphicon-duplicate" aria-hidden="true"></span> <?php echo PrivateBin\i18n::_('Clone'); ?>
</button><?php </button><?php
endif; ?> endif; ?>
<button id="rawtextbutton" type="button" class="hidden btn btn-warning navbar-btn"> <button id="rawtextbutton" type="button" class="hidden btn btn-warning navbar-btn">
<span class="glyphicon glyphicon-text-background" aria-hidden="true"></span> <?php echo i18n::_('Raw text'); ?> <span class="glyphicon glyphicon-text-background" aria-hidden="true"></span> <?php echo PrivateBin\i18n::_('Raw text'); ?>
</button> </button>
</li> </li>
<li class="dropdown"> <li class="dropdown">
<select id="pasteExpiration" name="pasteExpiration" class="hidden"><?php <select id="pasteExpiration" name="pasteExpiration" class="hidden"><?php
foreach ($EXPIRE as $key => $value): ?> foreach ($EXPIRE as $key => $value): ?>
<option value="<?php echo $key; ?>"<?php <option value="<?php echo $key; ?>"<?php
if ($key == $EXPIREDEFAULT): ?> selected="selected"<?php if ($key == $EXPIREDEFAULT): ?> selected="selected"<?php
endif; ?>><?php echo $value; ?></option><?php endif; ?>><?php echo $value; ?></option><?php
endforeach; ?> endforeach; ?>
</select> </select>
<a id="expiration" href="#" class="hidden dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><?php echo i18n::_('Expires'); ?>: <span id="pasteExpirationDisplay"><?php echo $EXPIRE[$EXPIREDEFAULT]; ?></span> <span class="caret"></span></a> <a id="expiration" href="#" class="hidden dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><?php echo PrivateBin\i18n::_('Expires'); ?>: <span id="pasteExpirationDisplay"><?php echo $EXPIRE[$EXPIREDEFAULT]; ?></span> <span class="caret"></span></a>
<ul class="dropdown-menu"><?php <ul class="dropdown-menu"><?php
foreach ($EXPIRE as $key => $value): ?> foreach ($EXPIRE as $key => $value): ?>
<li> <li>
@ -93,7 +93,7 @@ endforeach; ?>
<input type="checkbox" id="burnafterreading" name="burnafterreading" <?php <input type="checkbox" id="burnafterreading" name="burnafterreading" <?php
if ($BURNAFTERREADINGSELECTED): ?> checked="checked"<?php if ($BURNAFTERREADINGSELECTED): ?> checked="checked"<?php
endif; ?> /> endif; ?> />
<?php echo i18n::_('Burn after reading'); ?> <?php echo PrivateBin\i18n::_('Burn after reading'); ?>
</label> </label>
</div> </div>
</li><?php </li><?php
@ -102,9 +102,9 @@ if ($DISCUSSION): ?>
<div id="opendisc" class="navbar-text checkbox hidden"> <div id="opendisc" class="navbar-text checkbox hidden">
<label> <label>
<input type="checkbox" id="opendiscussion" name="opendiscussion" <?php <input type="checkbox" id="opendiscussion" name="opendiscussion" <?php
if ($OPENDISCUSSION): ?> checked="checked"<?php if ($OPENDISCUSSION): ?> checked="checked"<?php
endif; ?> /> endif; ?> />
<?php echo i18n::_('Open discussion'); ?> <?php echo PrivateBin\i18n::_('Open discussion'); ?>
</label> </label>
</div> </div>
</li><?php </li><?php
@ -112,13 +112,13 @@ endif;
if ($PASSWORD): ?> if ($PASSWORD): ?>
<li> <li>
<div id="password" class="navbar-form hidden"> <div id="password" class="navbar-form hidden">
<input type="password" id="passwordinput" placeholder="<?php echo i18n::_('Password (recommended)'); ?>" class="form-control" size="19" /> <input type="password" id="passwordinput" placeholder="<?php echo PrivateBin\i18n::_('Password (recommended)'); ?>" class="form-control" size="19" />
</div> </div>
</li><?php </li><?php
endif; endif;
if ($FILEUPLOAD): ?> if ($FILEUPLOAD): ?>
<li id="attach" class="hidden dropdown"> <li id="attach" class="hidden dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><?php echo i18n::_('Attach a file'); ?> <span class="caret"></span></a> <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><?php echo PrivateBin\i18n::_('Attach a file'); ?> <span class="caret"></span></a>
<ul class="dropdown-menu"> <ul class="dropdown-menu">
<li id="filewrap"> <li id="filewrap">
<div> <div>
@ -127,7 +127,7 @@ if ($FILEUPLOAD): ?>
</li> </li>
<li> <li>
<a id="fileremovebutton" href="#"> <a id="fileremovebutton" href="#">
<?php echo i18n::_('Remove attachment'); ?> <?php echo PrivateBin\i18n::_('Remove attachment'); ?>
</a> </a>
</li> </li>
</ul> </ul>
@ -137,11 +137,11 @@ endif; ?>
<select id="pasteFormatter" name="pasteFormatter" class="hidden"><?php <select id="pasteFormatter" name="pasteFormatter" class="hidden"><?php
foreach ($FORMATTER as $key => $value): ?> foreach ($FORMATTER as $key => $value): ?>
<option value="<?php echo $key; ?>"<?php <option value="<?php echo $key; ?>"<?php
if ($key == $FORMATTERDEFAULT): ?> selected="selected"<?php if ($key == $FORMATTERDEFAULT): ?> selected="selected"<?php
endif; ?>><?php echo $value; ?></option><?php endif; ?>><?php echo $value; ?></option><?php
endforeach; ?> endforeach; ?>
</select> </select>
<a id="formatter" href="#" class="hidden dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><?php echo i18n::_('Format'); ?>: <span id="pasteFormatterDisplay"><?php echo $FORMATTER[$FORMATTERDEFAULT]; ?></span> <span class="caret"></span></a> <a id="formatter" href="#" class="hidden dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><?php echo PrivateBin\i18n::_('Format'); ?>: <span id="pasteFormatterDisplay"><?php echo $FORMATTER[$FORMATTERDEFAULT]; ?></span> <span class="caret"></span></a>
<ul class="dropdown-menu"><?php <ul class="dropdown-menu"><?php
foreach ($FORMATTER as $key => $value): ?> foreach ($FORMATTER as $key => $value): ?>
<li> <li>
@ -158,19 +158,19 @@ if (strlen($LANGUAGESELECTION)): ?>
<li id="language" class="dropdown"> <li id="language" class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><span class="glyphicon glyphicon-flag" aria-hidden="true"></span> <?php echo $LANGUAGES[$LANGUAGESELECTION][0]; ?> <span class="caret"></span></a> <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><span class="glyphicon glyphicon-flag" aria-hidden="true"></span> <?php echo $LANGUAGES[$LANGUAGESELECTION][0]; ?> <span class="caret"></span></a>
<ul class="dropdown-menu"><?php <ul class="dropdown-menu"><?php
foreach ($LANGUAGES as $key => $value): ?> foreach ($LANGUAGES as $key => $value): ?>
<li> <li>
<a href="#" class="reloadlink" onclick="document.cookie='lang=<?php echo $key; ?>';"> <a href="#" class="reloadlink" onclick="document.cookie='lang=<?php echo $key; ?>';">
<?php echo $value[0]; ?> (<?php echo $value[1]; ?>) <?php echo $value[0]; ?> (<?php echo $value[1]; ?>)
</a> </a>
</li><?php </li><?php
endforeach; ?> endforeach; ?>
</ul> </ul>
</li><?php </li><?php
endif; ?> endif; ?>
<li> <li>
<button id="newbutton" type="button" class="reloadlink hidden btn btn-warning navbar-btn"> <button id="newbutton" type="button" class="reloadlink hidden btn btn-warning navbar-btn">
<span class="glyphicon glyphicon-file" aria-hidden="true"></span> <?php echo i18n::_('New'); ?> <span class="glyphicon glyphicon-file" aria-hidden="true"></span> <?php echo PrivateBin\i18n::_('New'); ?>
</button> </button>
</li> </li>
</ul> </ul>
@ -187,7 +187,7 @@ endif; ?>
</div><?php </div><?php
if ($FILEUPLOAD): ?> if ($FILEUPLOAD): ?>
<div id="attachment" role="alert" class="hidden alert alert-info"> <div id="attachment" role="alert" class="hidden alert alert-info">
<span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span> <a><?php echo i18n::_('Download attachment'); ?></a> <span id="clonedfile" class="hidden"><?php echo i18n::_('Cloned file attached.'); ?></span> <span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span> <a><?php echo PrivateBin\i18n::_('Download attachment'); ?></a> <span id="clonedfile" class="hidden"><?php echo PrivateBin\i18n::_('Cloned file attached.'); ?></span>
</div><?php </div><?php
endif; endif;
if (strlen($STATUS)): ?> if (strlen($STATUS)): ?>
@ -198,9 +198,9 @@ endif; ?>
<div id="errormessage" role="alert" class="<?php <div id="errormessage" role="alert" class="<?php
if (!strlen($ERROR)): ?>hidden <?php if (!strlen($ERROR)): ?>hidden <?php
endif; ?>alert alert-danger"><span class="glyphicon glyphicon-alert" aria-hidden="true"></span> <?php echo htmlspecialchars($ERROR); ?></div> endif; ?>alert alert-danger"><span class="glyphicon glyphicon-alert" aria-hidden="true"></span> <?php echo htmlspecialchars($ERROR); ?></div>
<noscript><div id="noscript" role="alert" class="nonworking alert alert-error"><span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span> <?php echo i18n::_('Javascript is required for PrivateBin to work.<br />Sorry for the inconvenience.'); ?></div></noscript> <noscript><div id="noscript" role="alert" class="nonworking alert alert-error"><span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span> <?php echo PrivateBin\i18n::_('Javascript is required for PrivateBin to work.<br />Sorry for the inconvenience.'); ?></div></noscript>
<div id="oldienotice" role="alert" class="hidden nonworking alert alert-danger"><span class="glyphicon glyphicon-alert" aria-hidden="true"></span> <?php echo i18n::_('PrivateBin requires a modern browser to work.'); ?></div> <div id="oldienotice" role="alert" class="hidden nonworking alert alert-danger"><span class="glyphicon glyphicon-alert" aria-hidden="true"></span> <?php echo PrivateBin\i18n::_('PrivateBin requires a modern browser to work.'); ?></div>
<div id="ienotice" role="alert" class="hidden alert alert-error"><span class="glyphicon glyphicon-question-sign" aria-hidden="true"></span> <?php echo i18n::_('Still using Internet Explorer? Do yourself a favor, switch to a modern browser:'); ?> <div id="ienotice" role="alert" class="hidden alert alert-error"><span class="glyphicon glyphicon-question-sign" aria-hidden="true"></span> <?php echo PrivateBin\i18n::_('Still using Internet Explorer? Do yourself a favor, switch to a modern browser:'); ?>
<a href="https://www.mozilla.org/firefox/">Firefox</a>, <a href="https://www.mozilla.org/firefox/">Firefox</a>,
<a href="https://www.opera.com/">Opera</a>, <a href="https://www.opera.com/">Opera</a>,
<a href="https://www.google.com/chrome">Chrome</a>, <a href="https://www.google.com/chrome">Chrome</a>,
@ -212,14 +212,14 @@ endif; ?>alert alert-danger"><span class="glyphicon glyphicon-alert" aria-hidden
<div id="pastelink"><?php <div id="pastelink"><?php
if (strlen($URLSHORTENER)): ?> if (strlen($URLSHORTENER)): ?>
<button id="shortenbutton" data-shortener="<?php echo htmlspecialchars($URLSHORTENER); ?>" type="button" class="btn btn-warning"> <button id="shortenbutton" data-shortener="<?php echo htmlspecialchars($URLSHORTENER); ?>" type="button" class="btn btn-warning">
<span class="glyphicon glyphicon-send" aria-hidden="true"></span> <?php echo i18n::_('Shorten URL'); ?> <span class="glyphicon glyphicon-send" aria-hidden="true"></span> <?php echo PrivateBin\i18n::_('Shorten URL'); ?>
</button><?php </button><?php
endif; ?> endif; ?>
</div> </div>
</div> </div>
<ul id="preview" class="nav nav-tabs hidden"> <ul id="preview" class="nav nav-tabs hidden">
<li role="presentation" class="active"><a id="messageedit" href="#"><?php echo i18n::_('Editor'); ?></a></li> <li role="presentation" class="active"><a id="messageedit" href="#"><?php echo PrivateBin\i18n::_('Editor'); ?></a></li>
<li role="presentation"><a id="messagepreview" href="#"><?php echo i18n::_('Preview'); ?></a></li> <li role="presentation"><a id="messagepreview" href="#"><?php echo PrivateBin\i18n::_('Preview'); ?></a></li>
</ul> </ul>
</header> </header>
<section class="container"> <section class="container">
@ -234,16 +234,16 @@ endif; ?>
</section> </section>
<section class="container"> <section class="container">
<div id="discussion" class="hidden"> <div id="discussion" class="hidden">
<h4><?php echo i18n::_('Discussion'); ?></h4> <h4><?php echo PrivateBin\i18n::_('Discussion'); ?></h4>
<div id="comments"></div> <div id="comments"></div>
</div> </div>
</section> </section>
<footer class="container"> <footer class="container">
<div class="row"> <div class="row">
<h4 class="col-md-5 col-xs-8"><?php echo i18n::_('PrivateBin'); ?> <small>- <?php echo i18n::_('Because ignorance is bliss'); ?></small></h4> <h4 class="col-md-5 col-xs-8"><?php echo PrivateBin\i18n::_('PrivateBin'); ?> <small>- <?php echo PrivateBin\i18n::_('Because ignorance is bliss'); ?></small></h4>
<p class="col-md-1 col-xs-4 text-center"><?php echo $VERSION; ?></p> <p class="col-md-1 col-xs-4 text-center"><?php echo $VERSION; ?></p>
<p id="aboutbox" class="col-md-6 col-xs-12"> <p id="aboutbox" class="col-md-6 col-xs-12">
<?php echo i18n::_('PrivateBin is a minimalist, open source online pastebin where the server has zero knowledge of pasted data. Data is encrypted/decrypted <i>in the browser</i> using 256 bits AES. More information on the <a href="https://github.com/PrivateBin/PrivateBin/wiki">project page</a>.'); ?> <?php echo PrivateBin\i18n::_('PrivateBin is a minimalist, open source online pastebin where the server has zero knowledge of pasted data. Data is encrypted/decrypted <i>in the browser</i> using 256 bits AES. More information on the <a href="https://github.com/PrivateBin/PrivateBin/wiki">project page</a>.'); ?>
</p> </p>
</div> </div>
</footer> </footer>

View file

@ -5,15 +5,15 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="robots" content="noindex" /> <meta name="robots" content="noindex" />
<title><?php echo i18n::_('PrivateBin'); ?></title> <title><?php echo PrivateBin\i18n::_('PrivateBin'); ?></title>
<link type="text/css" rel="stylesheet" href="css/bootstrap/bootstrap-theme-3.3.5.css" /> <link type="text/css" rel="stylesheet" href="css/bootstrap/bootstrap-theme-3.3.5.css" />
<link type="text/css" rel="stylesheet" href="css/bootstrap/darkstrap-0.9.3.css" /> <link type="text/css" rel="stylesheet" href="css/bootstrap/darkstrap-0.9.3.css" />
<link type="text/css" rel="stylesheet" href="css/bootstrap/privatebin.css?<?php echo rawurlencode($VERSION); ?>" /><?php <link type="text/css" rel="stylesheet" href="css/bootstrap/privatebin.css?<?php echo rawurlencode($VERSION); ?>" /><?php
if ($SYNTAXHIGHLIGHTING): ?> if ($SYNTAXHIGHLIGHTING): ?>
<link type="text/css" rel="stylesheet" href="css/prettify/prettify.css?<?php echo rawurlencode($VERSION); ?>" /><?php <link type="text/css" rel="stylesheet" href="css/prettify/prettify.css?<?php echo rawurlencode($VERSION); ?>" /><?php
if (strlen($SYNTAXHIGHLIGHTINGTHEME)): ?> if (strlen($SYNTAXHIGHLIGHTINGTHEME)): ?>
<link type="text/css" rel="stylesheet" href="css/prettify/<?php echo rawurlencode($SYNTAXHIGHLIGHTINGTHEME); ?>.css?<?php echo rawurlencode($VERSION); ?>" /><?php <link type="text/css" rel="stylesheet" href="css/prettify/<?php echo rawurlencode($SYNTAXHIGHLIGHTINGTHEME); ?>.css?<?php echo rawurlencode($VERSION); ?>" /><?php
endif; endif;
endif; ?> endif; ?>
<script type="text/javascript" src="js/jquery-1.11.3.js"></script> <script type="text/javascript" src="js/jquery-1.11.3.js"></script>
<script type="text/javascript" src="js/sjcl-1.0.4.js"></script> <script type="text/javascript" src="js/sjcl-1.0.4.js"></script>
@ -44,39 +44,39 @@ endif; ?>
<nav class="navbar navbar-inverse navbar-static-top"> <nav class="navbar navbar-inverse navbar-static-top">
<div class="navbar-header"> <div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar"> <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only"><?php echo i18n::_('Toggle navigation'); ?></span> <span class="sr-only"><?php echo PrivateBin\i18n::_('Toggle navigation'); ?></span>
<span class="icon-bar"></span> <span class="icon-bar"></span>
<span class="icon-bar"></span> <span class="icon-bar"></span>
<span class="icon-bar"></span> <span class="icon-bar"></span>
</button> </button>
<a class="reloadlink navbar-brand" href="/"> <a class="reloadlink navbar-brand" href="/">
<img alt="<?php echo i18n::_('PrivateBin'); ?>" src="img/icon.svg" width="20" /> <img alt="<?php echo PrivateBin\i18n::_('PrivateBin'); ?>" src="img/icon.svg" width="20" />
</a> </a>
</div> </div>
<div id="navbar" class="navbar-collapse collapse"> <div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav"> <ul class="nav navbar-nav">
<li> <li>
<button id="newbutton" type="button" class="reloadlink hidden btn btn-warning navbar-btn"> <button id="newbutton" type="button" class="reloadlink hidden btn btn-warning navbar-btn">
<span class="glyphicon glyphicon-file" aria-hidden="true"></span> <?php echo i18n::_('New'); ?> <span class="glyphicon glyphicon-file" aria-hidden="true"></span> <?php echo PrivateBin\i18n::_('New'); ?>
</button><?php </button><?php
if ($EXPIRECLONE): ?> if ($EXPIRECLONE): ?>
<button id="clonebutton" type="button" class="hidden btn btn-warning navbar-btn"> <button id="clonebutton" type="button" class="hidden btn btn-warning navbar-btn">
<span class="glyphicon glyphicon-duplicate" aria-hidden="true"></span> <?php echo i18n::_('Clone'); ?> <span class="glyphicon glyphicon-duplicate" aria-hidden="true"></span> <?php echo PrivateBin\i18n::_('Clone'); ?>
</button><?php </button><?php
endif; ?> endif; ?>
<button id="rawtextbutton" type="button" class="hidden btn btn-warning navbar-btn"> <button id="rawtextbutton" type="button" class="hidden btn btn-warning navbar-btn">
<span class="glyphicon glyphicon-text-background" aria-hidden="true"></span> <?php echo i18n::_('Raw text'); ?> <span class="glyphicon glyphicon-text-background" aria-hidden="true"></span> <?php echo PrivateBin\i18n::_('Raw text'); ?>
</button> </button>
</li> </li>
<li class="dropdown"> <li class="dropdown">
<select id="pasteExpiration" name="pasteExpiration" class="hidden"><?php <select id="pasteExpiration" name="pasteExpiration" class="hidden"><?php
foreach ($EXPIRE as $key => $value): ?> foreach ($EXPIRE as $key => $value): ?>
<option value="<?php echo $key; ?>"<?php <option value="<?php echo $key; ?>"<?php
if ($key == $EXPIREDEFAULT): ?> selected="selected"<?php if ($key == $EXPIREDEFAULT): ?> selected="selected"<?php
endif; ?>><?php echo $value; ?></option><?php endif; ?>><?php echo $value; ?></option><?php
endforeach; ?> endforeach; ?>
</select> </select>
<a id="expiration" href="#" class="hidden dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><?php echo i18n::_('Expires'); ?>: <span id="pasteExpirationDisplay"><?php echo $EXPIRE[$EXPIREDEFAULT]; ?></span> <span class="caret"></span></a> <a id="expiration" href="#" class="hidden dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><?php echo PrivateBin\i18n::_('Expires'); ?>: <span id="pasteExpirationDisplay"><?php echo $EXPIRE[$EXPIREDEFAULT]; ?></span> <span class="caret"></span></a>
<ul class="dropdown-menu"><?php <ul class="dropdown-menu"><?php
foreach ($EXPIRE as $key => $value): ?> foreach ($EXPIRE as $key => $value): ?>
<li> <li>
@ -93,7 +93,7 @@ endforeach; ?>
<input type="checkbox" id="burnafterreading" name="burnafterreading" <?php <input type="checkbox" id="burnafterreading" name="burnafterreading" <?php
if ($BURNAFTERREADINGSELECTED): ?> checked="checked"<?php if ($BURNAFTERREADINGSELECTED): ?> checked="checked"<?php
endif; ?> /> endif; ?> />
<?php echo i18n::_('Burn after reading'); ?> <?php echo PrivateBin\i18n::_('Burn after reading'); ?>
</label> </label>
</div> </div>
</li><?php </li><?php
@ -102,9 +102,9 @@ if ($DISCUSSION): ?>
<div id="opendisc" class="navbar-text checkbox hidden"> <div id="opendisc" class="navbar-text checkbox hidden">
<label> <label>
<input type="checkbox" id="opendiscussion" name="opendiscussion" <?php <input type="checkbox" id="opendiscussion" name="opendiscussion" <?php
if ($OPENDISCUSSION): ?> checked="checked"<?php if ($OPENDISCUSSION): ?> checked="checked"<?php
endif; ?> /> endif; ?> />
<?php echo i18n::_('Open discussion'); ?> <?php echo PrivateBin\i18n::_('Open discussion'); ?>
</label> </label>
</div> </div>
</li><?php </li><?php
@ -112,13 +112,13 @@ endif;
if ($PASSWORD): ?> if ($PASSWORD): ?>
<li> <li>
<div id="password" class="navbar-form hidden"> <div id="password" class="navbar-form hidden">
<input type="password" id="passwordinput" placeholder="<?php echo i18n::_('Password (recommended)'); ?>" class="form-control" size="19" /> <input type="password" id="passwordinput" placeholder="<?php echo PrivateBin\i18n::_('Password (recommended)'); ?>" class="form-control" size="19" />
</div> </div>
</li><?php </li><?php
endif; endif;
if ($FILEUPLOAD): ?> if ($FILEUPLOAD): ?>
<li id="attach" class="hidden dropdown"> <li id="attach" class="hidden dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><?php echo i18n::_('Attach a file'); ?> <span class="caret"></span></a> <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><?php echo PrivateBin\i18n::_('Attach a file'); ?> <span class="caret"></span></a>
<ul class="dropdown-menu"> <ul class="dropdown-menu">
<li id="filewrap"> <li id="filewrap">
<div> <div>
@ -127,7 +127,7 @@ if ($FILEUPLOAD): ?>
</li> </li>
<li> <li>
<a id="fileremovebutton" href="#"> <a id="fileremovebutton" href="#">
<?php echo i18n::_('Remove attachment'); ?> <?php echo PrivateBin\i18n::_('Remove attachment'); ?>
</a> </a>
</li> </li>
</ul> </ul>
@ -137,11 +137,11 @@ endif; ?>
<select id="pasteFormatter" name="pasteFormatter" class="hidden"><?php <select id="pasteFormatter" name="pasteFormatter" class="hidden"><?php
foreach ($FORMATTER as $key => $value): ?> foreach ($FORMATTER as $key => $value): ?>
<option value="<?php echo $key; ?>"<?php <option value="<?php echo $key; ?>"<?php
if ($key == $FORMATTERDEFAULT): ?> selected="selected"<?php if ($key == $FORMATTERDEFAULT): ?> selected="selected"<?php
endif; ?>><?php echo $value; ?></option><?php endif; ?>><?php echo $value; ?></option><?php
endforeach; ?> endforeach; ?>
</select> </select>
<a id="formatter" href="#" class="hidden dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><?php echo i18n::_('Format'); ?>: <span id="pasteFormatterDisplay"><?php echo $FORMATTER[$FORMATTERDEFAULT]; ?></span> <span class="caret"></span></a> <a id="formatter" href="#" class="hidden dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><?php echo PrivateBin\i18n::_('Format'); ?>: <span id="pasteFormatterDisplay"><?php echo $FORMATTER[$FORMATTERDEFAULT]; ?></span> <span class="caret"></span></a>
<ul class="dropdown-menu"><?php <ul class="dropdown-menu"><?php
foreach ($FORMATTER as $key => $value): ?> foreach ($FORMATTER as $key => $value): ?>
<li> <li>
@ -158,19 +158,19 @@ if (strlen($LANGUAGESELECTION)): ?>
<li id="language" class="dropdown"> <li id="language" class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><span class="glyphicon glyphicon-flag" aria-hidden="true"></span> <?php echo $LANGUAGES[$LANGUAGESELECTION][0]; ?> <span class="caret"></span></a> <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><span class="glyphicon glyphicon-flag" aria-hidden="true"></span> <?php echo $LANGUAGES[$LANGUAGESELECTION][0]; ?> <span class="caret"></span></a>
<ul class="dropdown-menu"><?php <ul class="dropdown-menu"><?php
foreach ($LANGUAGES as $key => $value): ?> foreach ($LANGUAGES as $key => $value): ?>
<li> <li>
<a href="#" class="reloadlink" onclick="document.cookie='lang=<?php echo $key; ?>';"> <a href="#" class="reloadlink" onclick="document.cookie='lang=<?php echo $key; ?>';">
<?php echo $value[0]; ?> (<?php echo $value[1]; ?>) <?php echo $value[0]; ?> (<?php echo $value[1]; ?>)
</a> </a>
</li><?php </li><?php
endforeach; ?> endforeach; ?>
</ul> </ul>
</li><?php </li><?php
endif; ?> endif; ?>
<li> <li>
<button id="sendbutton" type="button" class="hidden btn btn-warning navbar-btn"> <button id="sendbutton" type="button" class="hidden btn btn-warning navbar-btn">
<span class="glyphicon glyphicon-upload" aria-hidden="true"></span> <?php echo i18n::_('Send'); ?> <span class="glyphicon glyphicon-upload" aria-hidden="true"></span> <?php echo PrivateBin\i18n::_('Send'); ?>
</button> </button>
</li> </li>
</ul> </ul>
@ -187,7 +187,7 @@ endif; ?>
</div><?php </div><?php
if ($FILEUPLOAD): ?> if ($FILEUPLOAD): ?>
<div id="attachment" role="alert" class="hidden alert alert-info"> <div id="attachment" role="alert" class="hidden alert alert-info">
<span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span> <a><?php echo i18n::_('Download attachment'); ?></a> <span id="clonedfile" class="hidden"><?php echo i18n::_('Cloned file attached.'); ?></span> <span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span> <a><?php echo PrivateBin\i18n::_('Download attachment'); ?></a> <span id="clonedfile" class="hidden"><?php echo PrivateBin\i18n::_('Cloned file attached.'); ?></span>
</div><?php </div><?php
endif; endif;
if (strlen($STATUS)): ?> if (strlen($STATUS)): ?>
@ -198,9 +198,9 @@ endif; ?>
<div id="errormessage" role="alert" class="<?php <div id="errormessage" role="alert" class="<?php
if (!strlen($ERROR)): ?>hidden <?php if (!strlen($ERROR)): ?>hidden <?php
endif; ?>alert alert-danger"><span class="glyphicon glyphicon-alert" aria-hidden="true"></span> <?php echo htmlspecialchars($ERROR); ?></div> endif; ?>alert alert-danger"><span class="glyphicon glyphicon-alert" aria-hidden="true"></span> <?php echo htmlspecialchars($ERROR); ?></div>
<noscript><div id="noscript" role="alert" class="nonworking alert alert-error"><span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span> <?php echo i18n::_('Javascript is required for PrivateBin to work.<br />Sorry for the inconvenience.'); ?></div></noscript> <noscript><div id="noscript" role="alert" class="nonworking alert alert-error"><span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span> <?php echo PrivateBin\i18n::_('Javascript is required for PrivateBin to work.<br />Sorry for the inconvenience.'); ?></div></noscript>
<div id="oldienotice" role="alert" class="hidden nonworking alert alert-danger"><span class="glyphicon glyphicon-alert" aria-hidden="true"></span> <?php echo i18n::_('PrivateBin requires a modern browser to work.'); ?></div> <div id="oldienotice" role="alert" class="hidden nonworking alert alert-danger"><span class="glyphicon glyphicon-alert" aria-hidden="true"></span> <?php echo PrivateBin\i18n::_('PrivateBin requires a modern browser to work.'); ?></div>
<div id="ienotice" role="alert" class="hidden alert alert-error"><span class="glyphicon glyphicon-question-sign" aria-hidden="true"></span> <?php echo i18n::_('Still using Internet Explorer? Do yourself a favor, switch to a modern browser:'); ?> <div id="ienotice" role="alert" class="hidden alert alert-error"><span class="glyphicon glyphicon-question-sign" aria-hidden="true"></span> <?php echo PrivateBin\i18n::_('Still using Internet Explorer? Do yourself a favor, switch to a modern browser:'); ?>
<a href="https://www.mozilla.org/firefox/">Firefox</a>, <a href="https://www.mozilla.org/firefox/">Firefox</a>,
<a href="https://www.opera.com/">Opera</a>, <a href="https://www.opera.com/">Opera</a>,
<a href="https://www.google.com/chrome">Chrome</a>, <a href="https://www.google.com/chrome">Chrome</a>,
@ -212,14 +212,14 @@ endif; ?>alert alert-danger"><span class="glyphicon glyphicon-alert" aria-hidden
<div id="pastelink"><?php <div id="pastelink"><?php
if (strlen($URLSHORTENER)): ?> if (strlen($URLSHORTENER)): ?>
<button id="shortenbutton" data-shortener="<?php echo htmlspecialchars($URLSHORTENER); ?>" type="button" class="btn btn-warning"> <button id="shortenbutton" data-shortener="<?php echo htmlspecialchars($URLSHORTENER); ?>" type="button" class="btn btn-warning">
<span class="glyphicon glyphicon-send" aria-hidden="true"></span> <?php echo i18n::_('Shorten URL'); ?> <span class="glyphicon glyphicon-send" aria-hidden="true"></span> <?php echo PrivateBin\i18n::_('Shorten URL'); ?>
</button><?php </button><?php
endif; ?> endif; ?>
</div> </div>
</div> </div>
<ul id="preview" class="nav nav-tabs hidden"> <ul id="preview" class="nav nav-tabs hidden">
<li role="presentation" class="active"><a id="messageedit" href="#"><?php echo i18n::_('Editor'); ?></a></li> <li role="presentation" class="active"><a id="messageedit" href="#"><?php echo PrivateBin\i18n::_('Editor'); ?></a></li>
<li role="presentation"><a id="messagepreview" href="#"><?php echo i18n::_('Preview'); ?></a></li> <li role="presentation"><a id="messagepreview" href="#"><?php echo PrivateBin\i18n::_('Preview'); ?></a></li>
</ul> </ul>
</header> </header>
<section class="container"> <section class="container">
@ -234,16 +234,16 @@ endif; ?>
</section> </section>
<section class="container"> <section class="container">
<div id="discussion" class="hidden"> <div id="discussion" class="hidden">
<h4><?php echo i18n::_('Discussion'); ?></h4> <h4><?php echo PrivateBin\i18n::_('Discussion'); ?></h4>
<div id="comments"></div> <div id="comments"></div>
</div> </div>
</section> </section>
<footer class="container"> <footer class="container">
<div class="row"> <div class="row">
<h4 class="col-md-5 col-xs-8"><?php echo i18n::_('PrivateBin'); ?> <small>- <?php echo i18n::_('Because ignorance is bliss'); ?></small></h4> <h4 class="col-md-5 col-xs-8"><?php echo PrivateBin\i18n::_('PrivateBin'); ?> <small>- <?php echo PrivateBin\i18n::_('Because ignorance is bliss'); ?></small></h4>
<p class="col-md-1 col-xs-4 text-center"><?php echo $VERSION; ?></p> <p class="col-md-1 col-xs-4 text-center"><?php echo $VERSION; ?></p>
<p id="aboutbox" class="col-md-6 col-xs-12"> <p id="aboutbox" class="col-md-6 col-xs-12">
<?php echo i18n::_('PrivateBin is a minimalist, open source online pastebin where the server has zero knowledge of pasted data. Data is encrypted/decrypted <i>in the browser</i> using 256 bits AES. More information on the <a href="https://github.com/PrivateBin/PrivateBin/wiki">project page</a>.'); ?> <?php echo PrivateBin\i18n::_('PrivateBin is a minimalist, open source online pastebin where the server has zero knowledge of pasted data. Data is encrypted/decrypted <i>in the browser</i> using 256 bits AES. More information on the <a href="https://github.com/PrivateBin/PrivateBin/wiki">project page</a>.'); ?>
</p> </p>
</div> </div>
</footer> </footer>

View file

@ -5,15 +5,15 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="robots" content="noindex" /> <meta name="robots" content="noindex" />
<title><?php echo i18n::_('PrivateBin'); ?></title> <title><?php echo PrivateBin\i18n::_('PrivateBin'); ?></title>
<link type="text/css" rel="stylesheet" href="css/bootstrap/bootstrap-3.3.5.css" /> <link type="text/css" rel="stylesheet" href="css/bootstrap/bootstrap-3.3.5.css" />
<link type="text/css" rel="stylesheet" href="css/bootstrap/bootstrap-theme-3.3.5.css" /> <link type="text/css" rel="stylesheet" href="css/bootstrap/bootstrap-theme-3.3.5.css" />
<link type="text/css" rel="stylesheet" href="css/bootstrap/privatebin.css?<?php echo rawurlencode($VERSION); ?>" /><?php <link type="text/css" rel="stylesheet" href="css/bootstrap/privatebin.css?<?php echo rawurlencode($VERSION); ?>" /><?php
if ($SYNTAXHIGHLIGHTING): ?> if ($SYNTAXHIGHLIGHTING): ?>
<link type="text/css" rel="stylesheet" href="css/prettify/prettify.css?<?php echo rawurlencode($VERSION); ?>" /><?php <link type="text/css" rel="stylesheet" href="css/prettify/prettify.css?<?php echo rawurlencode($VERSION); ?>" /><?php
if (strlen($SYNTAXHIGHLIGHTINGTHEME)): ?> if (strlen($SYNTAXHIGHLIGHTINGTHEME)): ?>
<link type="text/css" rel="stylesheet" href="css/prettify/<?php echo rawurlencode($SYNTAXHIGHLIGHTINGTHEME); ?>.css?<?php echo rawurlencode($VERSION); ?>" /><?php <link type="text/css" rel="stylesheet" href="css/prettify/<?php echo rawurlencode($SYNTAXHIGHLIGHTINGTHEME); ?>.css?<?php echo rawurlencode($VERSION); ?>" /><?php
endif; endif;
endif; ?> endif; ?>
<script type="text/javascript" src="js/jquery-1.11.3.js"></script> <script type="text/javascript" src="js/jquery-1.11.3.js"></script>
<script type="text/javascript" src="js/sjcl-1.0.4.js"></script> <script type="text/javascript" src="js/sjcl-1.0.4.js"></script>
@ -44,39 +44,39 @@ endif; ?>
<nav class="navbar navbar-default navbar-static-top"> <nav class="navbar navbar-default navbar-static-top">
<div class="navbar-header"> <div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar"> <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only"><?php echo i18n::_('Toggle navigation'); ?></span> <span class="sr-only"><?php echo PrivateBin\i18n::_('Toggle navigation'); ?></span>
<span class="icon-bar"></span> <span class="icon-bar"></span>
<span class="icon-bar"></span> <span class="icon-bar"></span>
<span class="icon-bar"></span> <span class="icon-bar"></span>
</button> </button>
<a class="reloadlink navbar-brand" href="/"> <a class="reloadlink navbar-brand" href="/">
<img alt="<?php echo i18n::_('PrivateBin'); ?>" src="img/icon.svg" width="20" /> <img alt="<?php echo PrivateBin\i18n::_('PrivateBin'); ?>" src="img/icon.svg" width="20" />
</a> </a>
</div> </div>
<div id="navbar" class="navbar-collapse collapse"> <div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav"> <ul class="nav navbar-nav">
<li> <li>
<button id="sendbutton" type="button" class="hidden btn btn-primary navbar-btn"> <button id="sendbutton" type="button" class="hidden btn btn-primary navbar-btn">
<span class="glyphicon glyphicon-upload" aria-hidden="true"></span> <?php echo i18n::_('Send'); ?> <span class="glyphicon glyphicon-upload" aria-hidden="true"></span> <?php echo PrivateBin\i18n::_('Send'); ?>
</button><?php </button><?php
if ($EXPIRECLONE): ?> if ($EXPIRECLONE): ?>
<button id="clonebutton" type="button" class="hidden btn btn-default navbar-btn"> <button id="clonebutton" type="button" class="hidden btn btn-default navbar-btn">
<span class="glyphicon glyphicon-duplicate" aria-hidden="true"></span> <?php echo i18n::_('Clone'); ?> <span class="glyphicon glyphicon-duplicate" aria-hidden="true"></span> <?php echo PrivateBin\i18n::_('Clone'); ?>
</button><?php </button><?php
endif; ?> endif; ?>
<button id="rawtextbutton" type="button" class="hidden btn btn-default navbar-btn"> <button id="rawtextbutton" type="button" class="hidden btn btn-default navbar-btn">
<span class="glyphicon glyphicon-text-background" aria-hidden="true"></span> <?php echo i18n::_('Raw text'); ?> <span class="glyphicon glyphicon-text-background" aria-hidden="true"></span> <?php echo PrivateBin\i18n::_('Raw text'); ?>
</button> </button>
</li> </li>
<li class="dropdown"> <li class="dropdown">
<select id="pasteExpiration" name="pasteExpiration" class="hidden"><?php <select id="pasteExpiration" name="pasteExpiration" class="hidden"><?php
foreach ($EXPIRE as $key => $value): ?> foreach ($EXPIRE as $key => $value): ?>
<option value="<?php echo $key; ?>"<?php <option value="<?php echo $key; ?>"<?php
if ($key == $EXPIREDEFAULT): ?> selected="selected"<?php if ($key == $EXPIREDEFAULT): ?> selected="selected"<?php
endif; ?>><?php echo $value; ?></option><?php endif; ?>><?php echo $value; ?></option><?php
endforeach; ?> endforeach; ?>
</select> </select>
<a id="expiration" href="#" class="hidden dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><?php echo i18n::_('Expires'); ?>: <span id="pasteExpirationDisplay"><?php echo $EXPIRE[$EXPIREDEFAULT]; ?></span> <span class="caret"></span></a> <a id="expiration" href="#" class="hidden dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><?php echo PrivateBin\i18n::_('Expires'); ?>: <span id="pasteExpirationDisplay"><?php echo $EXPIRE[$EXPIREDEFAULT]; ?></span> <span class="caret"></span></a>
<ul class="dropdown-menu"><?php <ul class="dropdown-menu"><?php
foreach ($EXPIRE as $key => $value): ?> foreach ($EXPIRE as $key => $value): ?>
<li> <li>
@ -93,7 +93,7 @@ endforeach; ?>
<input type="checkbox" id="burnafterreading" name="burnafterreading" <?php <input type="checkbox" id="burnafterreading" name="burnafterreading" <?php
if ($BURNAFTERREADINGSELECTED): ?> checked="checked"<?php if ($BURNAFTERREADINGSELECTED): ?> checked="checked"<?php
endif; ?> /> endif; ?> />
<?php echo i18n::_('Burn after reading'); ?> <?php echo PrivateBin\i18n::_('Burn after reading'); ?>
</label> </label>
</div> </div>
</li><?php </li><?php
@ -102,9 +102,9 @@ if ($DISCUSSION): ?>
<div id="opendisc" class="navbar-text checkbox hidden"> <div id="opendisc" class="navbar-text checkbox hidden">
<label> <label>
<input type="checkbox" id="opendiscussion" name="opendiscussion" <?php <input type="checkbox" id="opendiscussion" name="opendiscussion" <?php
if ($OPENDISCUSSION): ?> checked="checked"<?php if ($OPENDISCUSSION): ?> checked="checked"<?php
endif; ?> /> endif; ?> />
<?php echo i18n::_('Open discussion'); ?> <?php echo PrivateBin\i18n::_('Open discussion'); ?>
</label> </label>
</div> </div>
</li><?php </li><?php
@ -112,13 +112,13 @@ endif;
if ($PASSWORD): ?> if ($PASSWORD): ?>
<li> <li>
<div id="password" class="navbar-form hidden"> <div id="password" class="navbar-form hidden">
<input type="password" id="passwordinput" placeholder="<?php echo i18n::_('Password (recommended)'); ?>" class="form-control" size="19" /> <input type="password" id="passwordinput" placeholder="<?php echo PrivateBin\i18n::_('Password (recommended)'); ?>" class="form-control" size="19" />
</div> </div>
</li><?php </li><?php
endif; endif;
if ($FILEUPLOAD): ?> if ($FILEUPLOAD): ?>
<li id="attach" class="hidden dropdown"> <li id="attach" class="hidden dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><?php echo i18n::_('Attach a file'); ?> <span class="caret"></span></a> <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><?php echo PrivateBin\i18n::_('Attach a file'); ?> <span class="caret"></span></a>
<ul class="dropdown-menu"> <ul class="dropdown-menu">
<li id="filewrap"> <li id="filewrap">
<div> <div>
@ -127,7 +127,7 @@ if ($FILEUPLOAD): ?>
</li> </li>
<li> <li>
<a id="fileremovebutton" href="#"> <a id="fileremovebutton" href="#">
<?php echo i18n::_('Remove attachment'); ?> <?php echo PrivateBin\i18n::_('Remove attachment'); ?>
</a> </a>
</li> </li>
</ul> </ul>
@ -137,11 +137,11 @@ endif; ?>
<select id="pasteFormatter" name="pasteFormatter" class="hidden"><?php <select id="pasteFormatter" name="pasteFormatter" class="hidden"><?php
foreach ($FORMATTER as $key => $value): ?> foreach ($FORMATTER as $key => $value): ?>
<option value="<?php echo $key; ?>"<?php <option value="<?php echo $key; ?>"<?php
if ($key == $FORMATTERDEFAULT): ?> selected="selected"<?php if ($key == $FORMATTERDEFAULT): ?> selected="selected"<?php
endif; ?>><?php echo $value; ?></option><?php endif; ?>><?php echo $value; ?></option><?php
endforeach; ?> endforeach; ?>
</select> </select>
<a id="formatter" href="#" class="hidden dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><?php echo i18n::_('Format'); ?>: <span id="pasteFormatterDisplay"><?php echo $FORMATTER[$FORMATTERDEFAULT]; ?></span> <span class="caret"></span></a> <a id="formatter" href="#" class="hidden dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><?php echo PrivateBin\i18n::_('Format'); ?>: <span id="pasteFormatterDisplay"><?php echo $FORMATTER[$FORMATTERDEFAULT]; ?></span> <span class="caret"></span></a>
<ul class="dropdown-menu"><?php <ul class="dropdown-menu"><?php
foreach ($FORMATTER as $key => $value): ?> foreach ($FORMATTER as $key => $value): ?>
<li> <li>
@ -158,19 +158,19 @@ if (strlen($LANGUAGESELECTION)): ?>
<li id="language" class="dropdown"> <li id="language" class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><span class="glyphicon glyphicon-flag" aria-hidden="true"></span> <?php echo $LANGUAGES[$LANGUAGESELECTION][0]; ?> <span class="caret"></span></a> <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><span class="glyphicon glyphicon-flag" aria-hidden="true"></span> <?php echo $LANGUAGES[$LANGUAGESELECTION][0]; ?> <span class="caret"></span></a>
<ul class="dropdown-menu"><?php <ul class="dropdown-menu"><?php
foreach ($LANGUAGES as $key => $value): ?> foreach ($LANGUAGES as $key => $value): ?>
<li> <li>
<a href="#" class="reloadlink" onclick="document.cookie='lang=<?php echo $key; ?>';"> <a href="#" class="reloadlink" onclick="document.cookie='lang=<?php echo $key; ?>';">
<?php echo $value[0]; ?> (<?php echo $value[1]; ?>) <?php echo $value[0]; ?> (<?php echo $value[1]; ?>)
</a> </a>
</li><?php </li><?php
endforeach; ?> endforeach; ?>
</ul> </ul>
</li><?php </li><?php
endif; ?> endif; ?>
<li> <li>
<button id="newbutton" type="button" class="reloadlink hidden btn btn-default navbar-btn"> <button id="newbutton" type="button" class="reloadlink hidden btn btn-default navbar-btn">
<span class="glyphicon glyphicon-file" aria-hidden="true"></span> <?php echo i18n::_('New'); ?> <span class="glyphicon glyphicon-file" aria-hidden="true"></span> <?php echo PrivateBin\i18n::_('New'); ?>
</button> </button>
</li> </li>
</ul> </ul>
@ -187,7 +187,7 @@ endif; ?>
</div><?php </div><?php
if ($FILEUPLOAD): ?> if ($FILEUPLOAD): ?>
<div id="attachment" role="alert" class="hidden alert alert-info"> <div id="attachment" role="alert" class="hidden alert alert-info">
<span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span> <a><?php echo i18n::_('Download attachment'); ?></a> <span id="clonedfile" class="hidden"><?php echo i18n::_('Cloned file attached.'); ?></span> <span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span> <a><?php echo PrivateBin\i18n::_('Download attachment'); ?></a> <span id="clonedfile" class="hidden"><?php echo PrivateBin\i18n::_('Cloned file attached.'); ?></span>
</div><?php </div><?php
endif; endif;
if (strlen($STATUS)): ?> if (strlen($STATUS)): ?>
@ -198,9 +198,9 @@ endif; ?>
<div id="errormessage" role="alert" class="<?php <div id="errormessage" role="alert" class="<?php
if (!strlen($ERROR)): ?>hidden <?php if (!strlen($ERROR)): ?>hidden <?php
endif; ?>alert alert-danger"><span class="glyphicon glyphicon-alert" aria-hidden="true"></span> <?php echo htmlspecialchars($ERROR); ?></div> endif; ?>alert alert-danger"><span class="glyphicon glyphicon-alert" aria-hidden="true"></span> <?php echo htmlspecialchars($ERROR); ?></div>
<noscript><div id="noscript" role="alert" class="nonworking alert alert-warning"><span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span> <?php echo i18n::_('Javascript is required for PrivateBin to work.<br />Sorry for the inconvenience.'); ?></div></noscript> <noscript><div id="noscript" role="alert" class="nonworking alert alert-warning"><span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span> <?php echo PrivateBin\i18n::_('Javascript is required for PrivateBin to work.<br />Sorry for the inconvenience.'); ?></div></noscript>
<div id="oldienotice" role="alert" class="hidden nonworking alert alert-danger"><span class="glyphicon glyphicon-alert" aria-hidden="true"></span> <?php echo i18n::_('PrivateBin requires a modern browser to work.'); ?></div> <div id="oldienotice" role="alert" class="hidden nonworking alert alert-danger"><span class="glyphicon glyphicon-alert" aria-hidden="true"></span> <?php echo PrivateBin\i18n::_('PrivateBin requires a modern browser to work.'); ?></div>
<div id="ienotice" role="alert" class="hidden alert alert-warning"><span class="glyphicon glyphicon-question-sign" aria-hidden="true"></span> <?php echo i18n::_('Still using Internet Explorer? Do yourself a favor, switch to a modern browser:'); ?> <div id="ienotice" role="alert" class="hidden alert alert-warning"><span class="glyphicon glyphicon-question-sign" aria-hidden="true"></span> <?php echo PrivateBin\i18n::_('Still using Internet Explorer? Do yourself a favor, switch to a modern browser:'); ?>
<a href="https://www.mozilla.org/firefox/">Firefox</a>, <a href="https://www.mozilla.org/firefox/">Firefox</a>,
<a href="https://www.opera.com/">Opera</a>, <a href="https://www.opera.com/">Opera</a>,
<a href="https://www.google.com/chrome">Chrome</a>, <a href="https://www.google.com/chrome">Chrome</a>,
@ -212,14 +212,14 @@ endif; ?>alert alert-danger"><span class="glyphicon glyphicon-alert" aria-hidden
<div id="pastelink"><?php <div id="pastelink"><?php
if (strlen($URLSHORTENER)): ?> if (strlen($URLSHORTENER)): ?>
<button id="shortenbutton" data-shortener="<?php echo htmlspecialchars($URLSHORTENER); ?>" type="button" class="btn btn-primary"> <button id="shortenbutton" data-shortener="<?php echo htmlspecialchars($URLSHORTENER); ?>" type="button" class="btn btn-primary">
<span class="glyphicon glyphicon-send" aria-hidden="true"></span> <?php echo i18n::_('Shorten URL'); ?> <span class="glyphicon glyphicon-send" aria-hidden="true"></span> <?php echo PrivateBin\i18n::_('Shorten URL'); ?>
</button><?php </button><?php
endif; ?> endif; ?>
</div> </div>
</div> </div>
<ul id="preview" class="nav nav-tabs hidden"> <ul id="preview" class="nav nav-tabs hidden">
<li role="presentation" class="active"><a id="messageedit" href="#"><?php echo i18n::_('Editor'); ?></a></li> <li role="presentation" class="active"><a id="messageedit" href="#"><?php echo PrivateBin\i18n::_('Editor'); ?></a></li>
<li role="presentation"><a id="messagepreview" href="#"><?php echo i18n::_('Preview'); ?></a></li> <li role="presentation"><a id="messagepreview" href="#"><?php echo PrivateBin\i18n::_('Preview'); ?></a></li>
</ul> </ul>
</header> </header>
<section class="container"> <section class="container">
@ -234,16 +234,16 @@ endif; ?>
</section> </section>
<section class="container"> <section class="container">
<div id="discussion" class="hidden"> <div id="discussion" class="hidden">
<h4><?php echo i18n::_('Discussion'); ?></h4> <h4><?php echo PrivateBin\i18n::_('Discussion'); ?></h4>
<div id="comments"></div> <div id="comments"></div>
</div> </div>
</section> </section>
<footer class="container"> <footer class="container">
<div class="row"> <div class="row">
<h4 class="col-md-5 col-xs-8"><?php echo i18n::_('PrivateBin'); ?> <small>- <?php echo i18n::_('Because ignorance is bliss'); ?></small></h4> <h4 class="col-md-5 col-xs-8"><?php echo PrivateBin\i18n::_('PrivateBin'); ?> <small>- <?php echo PrivateBin\i18n::_('Because ignorance is bliss'); ?></small></h4>
<p class="col-md-1 col-xs-4 text-center"><?php echo $VERSION; ?></p> <p class="col-md-1 col-xs-4 text-center"><?php echo $VERSION; ?></p>
<p id="aboutbox" class="col-md-6 col-xs-12"> <p id="aboutbox" class="col-md-6 col-xs-12">
<?php echo i18n::_('PrivateBin is a minimalist, open source online pastebin where the server has zero knowledge of pasted data. Data is encrypted/decrypted <i>in the browser</i> using 256 bits AES. More information on the <a href="https://github.com/PrivateBin/PrivateBin/wiki">project page</a>.'); ?> <?php echo PrivateBin\i18n::_('PrivateBin is a minimalist, open source online pastebin where the server has zero knowledge of pasted data. Data is encrypted/decrypted <i>in the browser</i> using 256 bits AES. More information on the <a href="https://github.com/PrivateBin/PrivateBin/wiki">project page</a>.'); ?>
</p> </p>
</div> </div>
</footer> </footer>

View file

@ -5,15 +5,15 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="robots" content="noindex" /> <meta name="robots" content="noindex" />
<title><?php echo i18n::_('PrivateBin'); ?></title> <title><?php echo PrivateBin\i18n::_('PrivateBin'); ?></title>
<link type="text/css" rel="stylesheet" href="css/bootstrap/bootstrap-3.3.5.css" /> <link type="text/css" rel="stylesheet" href="css/bootstrap/bootstrap-3.3.5.css" />
<link type="text/css" rel="stylesheet" href="css/bootstrap/bootstrap-theme-3.3.5.css" /> <link type="text/css" rel="stylesheet" href="css/bootstrap/bootstrap-theme-3.3.5.css" />
<link type="text/css" rel="stylesheet" href="css/bootstrap/privatebin.css?<?php echo rawurlencode($VERSION); ?>" /><?php <link type="text/css" rel="stylesheet" href="css/bootstrap/privatebin.css?<?php echo rawurlencode($VERSION); ?>" /><?php
if ($SYNTAXHIGHLIGHTING): ?> if ($SYNTAXHIGHLIGHTING): ?>
<link type="text/css" rel="stylesheet" href="css/prettify/prettify.css?<?php echo rawurlencode($VERSION); ?>" /><?php <link type="text/css" rel="stylesheet" href="css/prettify/prettify.css?<?php echo rawurlencode($VERSION); ?>" /><?php
if (strlen($SYNTAXHIGHLIGHTINGTHEME)): ?> if (strlen($SYNTAXHIGHLIGHTINGTHEME)): ?>
<link type="text/css" rel="stylesheet" href="css/prettify/<?php echo rawurlencode($SYNTAXHIGHLIGHTINGTHEME); ?>.css?<?php echo rawurlencode($VERSION); ?>" /><?php <link type="text/css" rel="stylesheet" href="css/prettify/<?php echo rawurlencode($SYNTAXHIGHLIGHTINGTHEME); ?>.css?<?php echo rawurlencode($VERSION); ?>" /><?php
endif; endif;
endif; ?> endif; ?>
<script type="text/javascript" src="js/jquery-1.11.3.js"></script> <script type="text/javascript" src="js/jquery-1.11.3.js"></script>
<script type="text/javascript" src="js/sjcl-1.0.4.js"></script> <script type="text/javascript" src="js/sjcl-1.0.4.js"></script>
@ -44,39 +44,39 @@ endif; ?>
<nav class="navbar navbar-default navbar-static-top"> <nav class="navbar navbar-default navbar-static-top">
<div class="navbar-header"> <div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar"> <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only"><?php echo i18n::_('Toggle navigation'); ?></span> <span class="sr-only"><?php echo PrivateBin\i18n::_('Toggle navigation'); ?></span>
<span class="icon-bar"></span> <span class="icon-bar"></span>
<span class="icon-bar"></span> <span class="icon-bar"></span>
<span class="icon-bar"></span> <span class="icon-bar"></span>
</button> </button>
<a class="reloadlink navbar-brand" href="/"> <a class="reloadlink navbar-brand" href="/">
<img alt="<?php echo i18n::_('PrivateBin'); ?>" src="img/icon.svg" width="20" /> <img alt="<?php echo PrivateBin\i18n::_('PrivateBin'); ?>" src="img/icon.svg" width="20" />
</a> </a>
</div> </div>
<div id="navbar" class="navbar-collapse collapse"> <div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav"> <ul class="nav navbar-nav">
<li> <li>
<button id="newbutton" type="button" class="reloadlink hidden btn btn-default navbar-btn"> <button id="newbutton" type="button" class="reloadlink hidden btn btn-default navbar-btn">
<span class="glyphicon glyphicon-file" aria-hidden="true"></span> <?php echo i18n::_('New'); ?> <span class="glyphicon glyphicon-file" aria-hidden="true"></span> <?php echo PrivateBin\i18n::_('New'); ?>
</button><?php </button><?php
if ($EXPIRECLONE): ?> if ($EXPIRECLONE): ?>
<button id="clonebutton" type="button" class="hidden btn btn-default navbar-btn"> <button id="clonebutton" type="button" class="hidden btn btn-default navbar-btn">
<span class="glyphicon glyphicon-duplicate" aria-hidden="true"></span> <?php echo i18n::_('Clone'); ?> <span class="glyphicon glyphicon-duplicate" aria-hidden="true"></span> <?php echo PrivateBin\i18n::_('Clone'); ?>
</button><?php </button><?php
endif; ?> endif; ?>
<button id="rawtextbutton" type="button" class="hidden btn btn-default navbar-btn"> <button id="rawtextbutton" type="button" class="hidden btn btn-default navbar-btn">
<span class="glyphicon glyphicon-text-background" aria-hidden="true"></span> <?php echo i18n::_('Raw text'); ?> <span class="glyphicon glyphicon-text-background" aria-hidden="true"></span> <?php echo PrivateBin\i18n::_('Raw text'); ?>
</button> </button>
</li> </li>
<li class="dropdown"> <li class="dropdown">
<select id="pasteExpiration" name="pasteExpiration" class="hidden"><?php <select id="pasteExpiration" name="pasteExpiration" class="hidden"><?php
foreach ($EXPIRE as $key => $value): ?> foreach ($EXPIRE as $key => $value): ?>
<option value="<?php echo $key; ?>"<?php <option value="<?php echo $key; ?>"<?php
if ($key == $EXPIREDEFAULT): ?> selected="selected"<?php if ($key == $EXPIREDEFAULT): ?> selected="selected"<?php
endif; ?>><?php echo $value; ?></option><?php endif; ?>><?php echo $value; ?></option><?php
endforeach; ?> endforeach; ?>
</select> </select>
<a id="expiration" href="#" class="hidden dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><?php echo i18n::_('Expires'); ?>: <span id="pasteExpirationDisplay"><?php echo $EXPIRE[$EXPIREDEFAULT]; ?></span> <span class="caret"></span></a> <a id="expiration" href="#" class="hidden dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><?php echo PrivateBin\i18n::_('Expires'); ?>: <span id="pasteExpirationDisplay"><?php echo $EXPIRE[$EXPIREDEFAULT]; ?></span> <span class="caret"></span></a>
<ul class="dropdown-menu"><?php <ul class="dropdown-menu"><?php
foreach ($EXPIRE as $key => $value): ?> foreach ($EXPIRE as $key => $value): ?>
<li> <li>
@ -93,7 +93,7 @@ endforeach; ?>
<input type="checkbox" id="burnafterreading" name="burnafterreading" <?php <input type="checkbox" id="burnafterreading" name="burnafterreading" <?php
if ($BURNAFTERREADINGSELECTED): ?> checked="checked"<?php if ($BURNAFTERREADINGSELECTED): ?> checked="checked"<?php
endif; ?> /> endif; ?> />
<?php echo i18n::_('Burn after reading'); ?> <?php echo PrivateBin\i18n::_('Burn after reading'); ?>
</label> </label>
</div> </div>
</li><?php </li><?php
@ -102,9 +102,9 @@ if ($DISCUSSION): ?>
<div id="opendisc" class="navbar-text checkbox hidden"> <div id="opendisc" class="navbar-text checkbox hidden">
<label> <label>
<input type="checkbox" id="opendiscussion" name="opendiscussion" <?php <input type="checkbox" id="opendiscussion" name="opendiscussion" <?php
if ($OPENDISCUSSION): ?> checked="checked"<?php if ($OPENDISCUSSION): ?> checked="checked"<?php
endif; ?> /> endif; ?> />
<?php echo i18n::_('Open discussion'); ?> <?php echo PrivateBin\i18n::_('Open discussion'); ?>
</label> </label>
</div> </div>
</li><?php </li><?php
@ -112,13 +112,13 @@ endif;
if ($PASSWORD): ?> if ($PASSWORD): ?>
<li> <li>
<div id="password" class="navbar-form hidden"> <div id="password" class="navbar-form hidden">
<input type="password" id="passwordinput" placeholder="<?php echo i18n::_('Password (recommended)'); ?>" class="form-control" size="19" /> <input type="password" id="passwordinput" placeholder="<?php echo PrivateBin\i18n::_('Password (recommended)'); ?>" class="form-control" size="19" />
</div> </div>
</li><?php </li><?php
endif; endif;
if ($FILEUPLOAD): ?> if ($FILEUPLOAD): ?>
<li id="attach" class="hidden dropdown"> <li id="attach" class="hidden dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><?php echo i18n::_('Attach a file'); ?> <span class="caret"></span></a> <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><?php echo PrivateBin\i18n::_('Attach a file'); ?> <span class="caret"></span></a>
<ul class="dropdown-menu"> <ul class="dropdown-menu">
<li id="filewrap"> <li id="filewrap">
<div> <div>
@ -127,7 +127,7 @@ if ($FILEUPLOAD): ?>
</li> </li>
<li> <li>
<a id="fileremovebutton" href="#"> <a id="fileremovebutton" href="#">
<?php echo i18n::_('Remove attachment'); ?> <?php echo PrivateBin\i18n::_('Remove attachment'); ?>
</a> </a>
</li> </li>
</ul> </ul>
@ -137,11 +137,11 @@ endif; ?>
<select id="pasteFormatter" name="pasteFormatter" class="hidden"><?php <select id="pasteFormatter" name="pasteFormatter" class="hidden"><?php
foreach ($FORMATTER as $key => $value): ?> foreach ($FORMATTER as $key => $value): ?>
<option value="<?php echo $key; ?>"<?php <option value="<?php echo $key; ?>"<?php
if ($key == $FORMATTERDEFAULT): ?> selected="selected"<?php if ($key == $FORMATTERDEFAULT): ?> selected="selected"<?php
endif; ?>><?php echo $value; ?></option><?php endif; ?>><?php echo $value; ?></option><?php
endforeach; ?> endforeach; ?>
</select> </select>
<a id="formatter" href="#" class="hidden dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><?php echo i18n::_('Format'); ?>: <span id="pasteFormatterDisplay"><?php echo $FORMATTER[$FORMATTERDEFAULT]; ?></span> <span class="caret"></span></a> <a id="formatter" href="#" class="hidden dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><?php echo PrivateBin\i18n::_('Format'); ?>: <span id="pasteFormatterDisplay"><?php echo $FORMATTER[$FORMATTERDEFAULT]; ?></span> <span class="caret"></span></a>
<ul class="dropdown-menu"><?php <ul class="dropdown-menu"><?php
foreach ($FORMATTER as $key => $value): ?> foreach ($FORMATTER as $key => $value): ?>
<li> <li>
@ -158,19 +158,19 @@ if (strlen($LANGUAGESELECTION)): ?>
<li id="language" class="dropdown"> <li id="language" class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><span class="glyphicon glyphicon-flag" aria-hidden="true"></span> <?php echo $LANGUAGES[$LANGUAGESELECTION][0]; ?> <span class="caret"></span></a> <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><span class="glyphicon glyphicon-flag" aria-hidden="true"></span> <?php echo $LANGUAGES[$LANGUAGESELECTION][0]; ?> <span class="caret"></span></a>
<ul class="dropdown-menu"><?php <ul class="dropdown-menu"><?php
foreach ($LANGUAGES as $key => $value): ?> foreach ($LANGUAGES as $key => $value): ?>
<li> <li>
<a href="#" class="reloadlink" onclick="document.cookie='lang=<?php echo $key; ?>';"> <a href="#" class="reloadlink" onclick="document.cookie='lang=<?php echo $key; ?>';">
<?php echo $value[0]; ?> (<?php echo $value[1]; ?>) <?php echo $value[0]; ?> (<?php echo $value[1]; ?>)
</a> </a>
</li><?php </li><?php
endforeach; ?> endforeach; ?>
</ul> </ul>
</li><?php </li><?php
endif; ?> endif; ?>
<li> <li>
<button id="sendbutton" type="button" class="hidden btn btn-primary navbar-btn"> <button id="sendbutton" type="button" class="hidden btn btn-primary navbar-btn">
<span class="glyphicon glyphicon-upload" aria-hidden="true"></span> <?php echo i18n::_('Send'); ?> <span class="glyphicon glyphicon-upload" aria-hidden="true"></span> <?php echo PrivateBin\i18n::_('Send'); ?>
</button> </button>
</li> </li>
</ul> </ul>
@ -187,7 +187,7 @@ endif; ?>
</div><?php </div><?php
if ($FILEUPLOAD): ?> if ($FILEUPLOAD): ?>
<div id="attachment" role="alert" class="hidden alert alert-info"> <div id="attachment" role="alert" class="hidden alert alert-info">
<span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span> <a><?php echo i18n::_('Download attachment'); ?></a> <span id="clonedfile" class="hidden"><?php echo i18n::_('Cloned file attached.'); ?></span> <span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span> <a><?php echo PrivateBin\i18n::_('Download attachment'); ?></a> <span id="clonedfile" class="hidden"><?php echo PrivateBin\i18n::_('Cloned file attached.'); ?></span>
</div><?php </div><?php
endif; endif;
if (strlen($STATUS)): ?> if (strlen($STATUS)): ?>
@ -198,9 +198,9 @@ endif; ?>
<div id="errormessage" role="alert" class="<?php <div id="errormessage" role="alert" class="<?php
if (!strlen($ERROR)): ?>hidden <?php if (!strlen($ERROR)): ?>hidden <?php
endif; ?>alert alert-danger"><span class="glyphicon glyphicon-alert" aria-hidden="true"></span> <?php echo htmlspecialchars($ERROR); ?></div> endif; ?>alert alert-danger"><span class="glyphicon glyphicon-alert" aria-hidden="true"></span> <?php echo htmlspecialchars($ERROR); ?></div>
<noscript><div id="noscript" role="alert" class="nonworking alert alert-warning"><span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span> <?php echo i18n::_('Javascript is required for PrivateBin to work.<br />Sorry for the inconvenience.'); ?></div></noscript> <noscript><div id="noscript" role="alert" class="nonworking alert alert-warning"><span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span> <?php echo PrivateBin\i18n::_('Javascript is required for PrivateBin to work.<br />Sorry for the inconvenience.'); ?></div></noscript>
<div id="oldienotice" role="alert" class="hidden nonworking alert alert-danger"><span class="glyphicon glyphicon-alert" aria-hidden="true"></span> <?php echo i18n::_('PrivateBin requires a modern browser to work.'); ?></div> <div id="oldienotice" role="alert" class="hidden nonworking alert alert-danger"><span class="glyphicon glyphicon-alert" aria-hidden="true"></span> <?php echo PrivateBin\i18n::_('PrivateBin requires a modern browser to work.'); ?></div>
<div id="ienotice" role="alert" class="hidden alert alert-warning"><span class="glyphicon glyphicon-question-sign" aria-hidden="true"></span> <?php echo i18n::_('Still using Internet Explorer? Do yourself a favor, switch to a modern browser:'); ?> <div id="ienotice" role="alert" class="hidden alert alert-warning"><span class="glyphicon glyphicon-question-sign" aria-hidden="true"></span> <?php echo PrivateBin\i18n::_('Still using Internet Explorer? Do yourself a favor, switch to a modern browser:'); ?>
<a href="https://www.mozilla.org/firefox/">Firefox</a>, <a href="https://www.mozilla.org/firefox/">Firefox</a>,
<a href="https://www.opera.com/">Opera</a>, <a href="https://www.opera.com/">Opera</a>,
<a href="https://www.google.com/chrome">Chrome</a>, <a href="https://www.google.com/chrome">Chrome</a>,
@ -212,14 +212,14 @@ endif; ?>alert alert-danger"><span class="glyphicon glyphicon-alert" aria-hidden
<div id="pastelink"><?php <div id="pastelink"><?php
if (strlen($URLSHORTENER)): ?> if (strlen($URLSHORTENER)): ?>
<button id="shortenbutton" data-shortener="<?php echo htmlspecialchars($URLSHORTENER); ?>" type="button" class="btn btn-primary"> <button id="shortenbutton" data-shortener="<?php echo htmlspecialchars($URLSHORTENER); ?>" type="button" class="btn btn-primary">
<span class="glyphicon glyphicon-send" aria-hidden="true"></span> <?php echo i18n::_('Shorten URL'); ?> <span class="glyphicon glyphicon-send" aria-hidden="true"></span> <?php echo PrivateBin\i18n::_('Shorten URL'); ?>
</button><?php </button><?php
endif; ?> endif; ?>
</div> </div>
</div> </div>
<ul id="preview" class="nav nav-tabs hidden"> <ul id="preview" class="nav nav-tabs hidden">
<li role="presentation" class="active"><a id="messageedit" href="#"><?php echo i18n::_('Editor'); ?></a></li> <li role="presentation" class="active"><a id="messageedit" href="#"><?php echo PrivateBin\i18n::_('Editor'); ?></a></li>
<li role="presentation"><a id="messagepreview" href="#"><?php echo i18n::_('Preview'); ?></a></li> <li role="presentation"><a id="messagepreview" href="#"><?php echo PrivateBin\i18n::_('Preview'); ?></a></li>
</ul> </ul>
</header> </header>
<section class="container"> <section class="container">
@ -234,16 +234,16 @@ endif; ?>
</section> </section>
<section class="container"> <section class="container">
<div id="discussion" class="hidden"> <div id="discussion" class="hidden">
<h4><?php echo i18n::_('Discussion'); ?></h4> <h4><?php echo PrivateBin\i18n::_('Discussion'); ?></h4>
<div id="comments"></div> <div id="comments"></div>
</div> </div>
</section> </section>
<footer class="container"> <footer class="container">
<div class="row"> <div class="row">
<h4 class="col-md-5 col-xs-8"><?php echo i18n::_('PrivateBin'); ?> <small>- <?php echo i18n::_('Because ignorance is bliss'); ?></small></h4> <h4 class="col-md-5 col-xs-8"><?php echo PrivateBin\i18n::_('PrivateBin'); ?> <small>- <?php echo PrivateBin\i18n::_('Because ignorance is bliss'); ?></small></h4>
<p class="col-md-1 col-xs-4 text-center"><?php echo $VERSION; ?></p> <p class="col-md-1 col-xs-4 text-center"><?php echo $VERSION; ?></p>
<p id="aboutbox" class="col-md-6 col-xs-12"> <p id="aboutbox" class="col-md-6 col-xs-12">
<?php echo i18n::_('PrivateBin is a minimalist, open source online pastebin where the server has zero knowledge of pasted data. Data is encrypted/decrypted <i>in the browser</i> using 256 bits AES. More information on the <a href="https://github.com/PrivateBin/PrivateBin/wiki">project page</a>.'); ?> <?php echo PrivateBin\i18n::_('PrivateBin is a minimalist, open source online pastebin where the server has zero knowledge of pasted data. Data is encrypted/decrypted <i>in the browser</i> using 256 bits AES. More information on the <a href="https://github.com/PrivateBin/PrivateBin/wiki">project page</a>.'); ?>
</p> </p>
</div> </div>
</footer> </footer>

View file

@ -3,13 +3,13 @@
<head> <head>
<meta charset="utf-8" /> <meta charset="utf-8" />
<meta name="robots" content="noindex" /> <meta name="robots" content="noindex" />
<title><?php echo i18n::_('PrivateBin'); ?></title> <title><?php echo PrivateBin\i18n::_('PrivateBin'); ?></title>
<link type="text/css" rel="stylesheet" href="css/privatebin.css?<?php echo rawurlencode($VERSION); ?>" /><?php <link type="text/css" rel="stylesheet" href="css/privatebin.css?<?php echo rawurlencode($VERSION); ?>" /><?php
if ($SYNTAXHIGHLIGHTING): ?> if ($SYNTAXHIGHLIGHTING): ?>
<link type="text/css" rel="stylesheet" href="css/prettify/prettify.css?<?php echo rawurlencode($VERSION); ?>" /><?php <link type="text/css" rel="stylesheet" href="css/prettify/prettify.css?<?php echo rawurlencode($VERSION); ?>" /><?php
if (strlen($SYNTAXHIGHLIGHTINGTHEME)): ?> if (strlen($SYNTAXHIGHLIGHTINGTHEME)): ?>
<link type="text/css" rel="stylesheet" href="css/prettify/<?php echo rawurlencode($SYNTAXHIGHLIGHTINGTHEME); ?>.css?<?php echo rawurlencode($VERSION); ?>" /><?php <link type="text/css" rel="stylesheet" href="css/prettify/<?php echo rawurlencode($SYNTAXHIGHLIGHTINGTHEME); ?>.css?<?php echo rawurlencode($VERSION); ?>" /><?php
endif; endif;
endif; ?> endif; ?>
<script type="text/javascript" src="js/jquery-1.11.3.js"></script> <script type="text/javascript" src="js/jquery-1.11.3.js"></script>
<script type="text/javascript" src="js/sjcl-1.0.4.js"></script> <script type="text/javascript" src="js/sjcl-1.0.4.js"></script>
@ -38,17 +38,17 @@ endif; ?>
<body> <body>
<header> <header>
<div id="aboutbox"> <div id="aboutbox">
<?php echo i18n::_('PrivateBin is a minimalist, open source online pastebin where the server has zero knowledge of pasted data. Data is encrypted/decrypted <i>in the browser</i> using 256 bits AES. More information on the <a href="https://github.com/PrivateBin/PrivateBin/wiki">project page</a>.'); ?><br /><?php <?php echo PrivateBin\i18n::_('PrivateBin is a minimalist, open source online pastebin where the server has zero knowledge of pasted data. Data is encrypted/decrypted <i>in the browser</i> using 256 bits AES. More information on the <a href="https://github.com/PrivateBin/PrivateBin/wiki">project page</a>.'); ?><br /><?php
if (strlen($NOTICE)): ?> if (strlen($NOTICE)): ?>
<span class="blink"></span> <?php echo htmlspecialchars($NOTICE); <span class="blink"></span> <?php echo htmlspecialchars($NOTICE);
endif; ?> endif; ?>
</div> </div>
<h1 class="title reloadlink"><?php echo i18n::_('PrivateBin'); ?></h1><br /> <h1 class="title reloadlink"><?php echo PrivateBin\i18n::_('PrivateBin'); ?></h1><br />
<h2 class="title"><?php echo i18n::_('Because ignorance is bliss'); ?></h2><br /> <h2 class="title"><?php echo PrivateBin\i18n::_('Because ignorance is bliss'); ?></h2><br />
<h3 class="title"><?php echo $VERSION; ?></h3> <h3 class="title"><?php echo $VERSION; ?></h3>
<noscript><div id="noscript" class="nonworking"><?php echo i18n::_('Javascript is required for PrivateBin to work.<br />Sorry for the inconvenience.'); ?></div></noscript> <noscript><div id="noscript" class="nonworking"><?php echo PrivateBin\i18n::_('Javascript is required for PrivateBin to work.<br />Sorry for the inconvenience.'); ?></div></noscript>
<div id="oldienotice" class="nonworking"><?php echo i18n::_('PrivateBin requires a modern browser to work.'); ?></div> <div id="oldienotice" class="nonworking"><?php echo PrivateBin\i18n::_('PrivateBin requires a modern browser to work.'); ?></div>
<div id="ienotice"><?php echo i18n::_('Still using Internet Explorer? Do yourself a favor, switch to a modern browser:'); ?> <div id="ienotice"><?php echo PrivateBin\i18n::_('Still using Internet Explorer? Do yourself a favor, switch to a modern browser:'); ?>
<a href="https://www.mozilla.org/firefox/">Firefox</a>, <a href="https://www.mozilla.org/firefox/">Firefox</a>,
<a href="https://www.opera.com/">Opera</a>, <a href="https://www.opera.com/">Opera</a>,
<a href="https://www.google.com/chrome">Chrome</a>, <a href="https://www.google.com/chrome">Chrome</a>,
@ -60,18 +60,18 @@ endif; ?>
<div id="status"><?php echo htmlspecialchars($STATUS); ?></div> <div id="status"><?php echo htmlspecialchars($STATUS); ?></div>
<div id="errormessage" class="hidden"><?php echo htmlspecialchars($ERROR); ?></div> <div id="errormessage" class="hidden"><?php echo htmlspecialchars($ERROR); ?></div>
<div id="toolbar"> <div id="toolbar">
<button id="newbutton" class="reloadlink hidden"><img src="img/icon_new.png" width="11" height="15" alt="" /><?php echo i18n::_('New'); ?></button> <button id="newbutton" class="reloadlink hidden"><img src="img/icon_new.png" width="11" height="15" alt="" /><?php echo PrivateBin\i18n::_('New'); ?></button>
<button id="sendbutton" class="hidden"><img src="img/icon_send.png" width="18" height="15" alt="" /><?php echo i18n::_('Send'); ?></button><?php <button id="sendbutton" class="hidden"><img src="img/icon_send.png" width="18" height="15" alt="" /><?php echo PrivateBin\i18n::_('Send'); ?></button><?php
if ($EXPIRECLONE): ?> if ($EXPIRECLONE): ?>
<button id="clonebutton" class="hidden"><img src="img/icon_clone.png" width="15" height="17" alt="" /><?php echo i18n::_('Clone'); ?></button><?php <button id="clonebutton" class="hidden"><img src="img/icon_clone.png" width="15" height="17" alt="" /><?php echo PrivateBin\i18n::_('Clone'); ?></button><?php
endif; ?> endif; ?>
<button id="rawtextbutton" class="hidden"><img src="img/icon_raw.png" width="15" height="15" alt="" /><?php echo i18n::_('Raw text'); ?></button> <button id="rawtextbutton" class="hidden"><img src="img/icon_raw.png" width="15" height="15" alt="" /><?php echo PrivateBin\i18n::_('Raw text'); ?></button>
<div id="expiration" class="hidden button"><?php echo i18n::_('Expires'); ?>: <div id="expiration" class="hidden button"><?php echo PrivateBin\i18n::_('Expires'); ?>:
<select id="pasteExpiration" name="pasteExpiration"><?php <select id="pasteExpiration" name="pasteExpiration"><?php
foreach ($EXPIRE as $key => $value): ?> foreach ($EXPIRE as $key => $value): ?>
<option value="<?php echo $key; ?>"<?php <option value="<?php echo $key; ?>"<?php
if ($key == $EXPIREDEFAULT): ?> selected="selected"<?php if ($key == $EXPIREDEFAULT): ?> selected="selected"<?php
endif; ?>><?php echo $value; ?></option><?php endif; ?>><?php echo $value; ?></option><?php
endforeach; ?> endforeach; ?>
</select> </select>
</div> </div>
@ -80,40 +80,40 @@ endforeach; ?>
<input type="checkbox" id="burnafterreading" name="burnafterreading" <?php <input type="checkbox" id="burnafterreading" name="burnafterreading" <?php
if ($BURNAFTERREADINGSELECTED): ?> checked="checked"<?php if ($BURNAFTERREADINGSELECTED): ?> checked="checked"<?php
endif; ?> /> endif; ?> />
<label for="burnafterreading"><?php echo i18n::_('Burn after reading'); ?></label> <label for="burnafterreading"><?php echo PrivateBin\i18n::_('Burn after reading'); ?></label>
</div><?php </div><?php
if ($DISCUSSION): ?> if ($DISCUSSION): ?>
<div id="opendisc" class="button hidden"> <div id="opendisc" class="button hidden">
<input type="checkbox" id="opendiscussion" name="opendiscussion" <?php <input type="checkbox" id="opendiscussion" name="opendiscussion" <?php
if ($OPENDISCUSSION): ?> checked="checked"<?php if ($OPENDISCUSSION): ?> checked="checked"<?php
endif; ?> /> endif; ?> />
<label for="opendiscussion" <?php <label for="opendiscussion" <?php
if (!$OPENDISCUSSION): ?> style="color: #BBBBBB;"<?php if (!$OPENDISCUSSION): ?> style="color: #BBBBBB;"<?php
endif; ?>><?php echo i18n::_('Open discussion'); ?></label> endif; ?>><?php echo PrivateBin\i18n::_('Open discussion'); ?></label>
</div><?php </div><?php
endif; endif;
if ($PASSWORD): ?> if ($PASSWORD): ?>
<div id="password" class="hidden"> <div id="password" class="hidden">
<input type="password" id="passwordinput" placeholder="<?php echo i18n::_('Password (recommended)'); ?>" size="32" /> <input type="password" id="passwordinput" placeholder="<?php echo PrivateBin\i18n::_('Password (recommended)'); ?>" size="32" />
</div><?php </div><?php
endif; ?> endif; ?>
<div id="formatter" class="button hidden"><?php echo i18n::_('Format'); ?>: <div id="formatter" class="button hidden"><?php echo PrivateBin\i18n::_('Format'); ?>:
<select id="pasteFormatter" name="pasteFormatter"><?php <select id="pasteFormatter" name="pasteFormatter"><?php
foreach ($FORMATTER as $key => $value): ?> foreach ($FORMATTER as $key => $value): ?>
<option value="<?php echo $key; ?>"<?php <option value="<?php echo $key; ?>"<?php
if ($key == $FORMATTERDEFAULT): ?> selected="selected"<?php if ($key == $FORMATTERDEFAULT): ?> selected="selected"<?php
endif; ?>><?php echo $value; ?></option><?php endif; ?>><?php echo $value; ?></option><?php
endforeach; ?> endforeach; ?>
</select> </select>
</div><?php </div><?php
if (strlen($LANGUAGESELECTION)): ?> if (strlen($LANGUAGESELECTION)): ?>
<div id="language" class="button"> <div id="language" class="button">
<select name="lang"><?php <select name="lang"><?php
foreach ($LANGUAGES as $key => $value): ?> foreach ($LANGUAGES as $key => $value): ?>
<option class="reloadlink" onclick="document.cookie='lang=<?php echo $key; ?>';" value="<?php echo $key; ?>"<?php <option class="reloadlink" onclick="document.cookie='lang=<?php echo $key; ?>';" value="<?php echo $key; ?>"<?php
if ($key == $LANGUAGESELECTION): ?> selected="selected"<?php if ($key == $LANGUAGESELECTION): ?> selected="selected"<?php
endif; ?>><?php echo $value[0]; ?> (<?php echo $value[1]; ?>)</option><?php endif; ?>><?php echo $value[0]; ?> (<?php echo $value[1]; ?>)</option><?php
endforeach; ?> endforeach; ?>
</select> </select>
</div><?php </div><?php
endif; ?> endif; ?>
@ -122,21 +122,21 @@ endif; ?>
<div id="deletelink"></div> <div id="deletelink"></div>
<div id="pastelink"><?php <div id="pastelink"><?php
if (strlen($URLSHORTENER)): ?> if (strlen($URLSHORTENER)): ?>
<button id="shortenbutton" data-shortener="<?php echo htmlspecialchars($URLSHORTENER); ?>"><img src="img/icon_shorten.png" width="13" height="15" /><?php echo i18n::_('Shorten URL'); ?></button><?php <button id="shortenbutton" data-shortener="<?php echo htmlspecialchars($URLSHORTENER); ?>"><img src="img/icon_shorten.png" width="13" height="15" /><?php echo PrivateBin\i18n::_('Shorten URL'); ?></button><?php
endif; ?> endif; ?>
</div> </div>
</div><?php </div><?php
if ($FILEUPLOAD): ?> if ($FILEUPLOAD): ?>
<div id="attachment" class="hidden"><a><?php echo i18n::_('Download attachment'); ?></a></div> <div id="attachment" class="hidden"><a><?php echo PrivateBin\i18n::_('Download attachment'); ?></a></div>
<div id="attach" class="hidden"> <div id="attach" class="hidden">
<span id="clonedfile" class="hidden"><?php echo i18n::_('Cloned file attached.'); ?></span> <span id="clonedfile" class="hidden"><?php echo PrivateBin\i18n::_('Cloned file attached.'); ?></span>
<span id="filewrap"><?php echo i18n::_('Attach a file'); ?>: <input type="file" id="file" name="file" /></span> <span id="filewrap"><?php echo PrivateBin\i18n::_('Attach a file'); ?>: <input type="file" id="file" name="file" /></span>
<button id="fileremovebutton"><?php echo i18n::_('Remove attachment'); ?></button> <button id="fileremovebutton"><?php echo PrivateBin\i18n::_('Remove attachment'); ?></button>
</div><?php </div><?php
endif; ?> endif; ?>
<div id="preview" class="hidden"> <div id="preview" class="hidden">
<button id="messageedit"><?php echo i18n::_('Editor'); ?></button> <button id="messageedit"><?php echo PrivateBin\i18n::_('Editor'); ?></button>
<button id="messagepreview"><?php echo i18n::_('Preview'); ?></button> <button id="messagepreview"><?php echo PrivateBin\i18n::_('Preview'); ?></button>
</div> </div>
<div id="image" class="hidden"></div> <div id="image" class="hidden"></div>
<div id="prettymessage" class="hidden"> <div id="prettymessage" class="hidden">
@ -148,7 +148,7 @@ endif; ?>
</section> </section>
<section> <section>
<div id="discussion" class="hidden"> <div id="discussion" class="hidden">
<h4 class="title"><?php echo i18n::_('Discussion'); ?></h4> <h4 class="title"><?php echo PrivateBin\i18n::_('Discussion'); ?></h4>
<div id="comments"></div> <div id="comments"></div>
</div> </div>
</section> </section>

View file

@ -1,8 +0,0 @@
<?php
class autoTest extends PHPUnit_Framework_TestCase
{
public function testAutoloaderReturnsFalseWhenCallingNonExistingClass()
{
$this->assertFalse(auto::loader('foo2501bar42'), 'calling non existent class');
}
}

View file

@ -1,13 +1,24 @@
<?php <?php
error_reporting( E_ALL | E_STRICT );
use PrivateBin\serversalt;
error_reporting(E_ALL | E_STRICT);
// change this, if your php files and data is outside of your webservers document root // change this, if your php files and data is outside of your webservers document root
if (!defined('PUBLIC_PATH')) define('PUBLIC_PATH', '..'); if (!defined('PUBLIC_PATH')) {
if (!defined('PATH')) define('PATH', '..' . DIRECTORY_SEPARATOR); define('PUBLIC_PATH', '..');
if (!defined('CONF')) define('CONF', PATH . 'cfg' . DIRECTORY_SEPARATOR . 'conf.ini'); }
if (!is_file(CONF)) copy(CONF . '.sample', CONF); if (!defined('PATH')) {
define('PATH', '..' . DIRECTORY_SEPARATOR);
}
if (!defined('CONF')) {
define('CONF', PATH . 'cfg' . DIRECTORY_SEPARATOR . 'conf.ini');
}
if (!is_file(CONF)) {
copy(CONF . '.sample', CONF);
}
require PATH . 'lib/auto.php'; require PATH . 'vendor/autoload.php';
class helper class helper
{ {
@ -100,8 +111,9 @@ class helper
$example = self::getPaste(); $example = self::getPaste();
// the JSON shouldn't contain the salt // the JSON shouldn't contain the salt
unset($example['meta']['salt']); unset($example['meta']['salt']);
if (count($meta)) if (count($meta)) {
$example['meta'] = $meta; $example['meta'] = $meta;
}
$example['comments'] = array(); $example['comments'] = array();
$example['comment_count'] = 0; $example['comment_count'] = 0;
$example['comment_offset'] = 0; $example['comment_offset'] = 0;
@ -154,19 +166,19 @@ class helper
{ {
$path .= DIRECTORY_SEPARATOR; $path .= DIRECTORY_SEPARATOR;
$dir = dir($path); $dir = dir($path);
while(false !== ($file = $dir->read())) { while (false !== ($file = $dir->read())) {
if($file != '.' && $file != '..') { if ($file != '.' && $file != '..') {
if(is_dir($path . $file)) { if (is_dir($path . $file)) {
self::rmdir($path . $file); self::rmdir($path . $file);
} elseif(is_file($path . $file)) { } elseif (is_file($path . $file)) {
if(!@unlink($path . $file)) { if (!@unlink($path . $file)) {
throw new Exception('Error deleting file "' . $path . $file . '".'); throw new Exception('Error deleting file "' . $path . $file . '".');
} }
} }
} }
} }
$dir->close(); $dir->close();
if(!@rmdir($path)) { if (!@rmdir($path)) {
throw new Exception('Error deleting directory "' . $path . '".'); throw new Exception('Error deleting directory "' . $path . '".');
} }
} }
@ -178,8 +190,9 @@ class helper
*/ */
public static function confBackup() public static function confBackup()
{ {
if (!is_file(CONF . '.bak') && is_file(CONF)) if (!is_file(CONF . '.bak') && is_file(CONF)) {
rename(CONF, CONF . '.bak'); rename(CONF, CONF . '.bak');
}
} }
/** /**
@ -189,8 +202,9 @@ class helper
*/ */
public static function confRestore() public static function confRestore()
{ {
if (is_file(CONF . '.bak')) if (is_file(CONF . '.bak')) {
rename(CONF . '.bak', CONF); rename(CONF . '.bak', CONF);
}
} }
/** /**
@ -206,7 +220,7 @@ class helper
$ini = fopen($pathToFile, 'a'); $ini = fopen($pathToFile, 'a');
foreach ($values as $section => $options) { foreach ($values as $section => $options) {
fwrite($ini, "[$section]" . PHP_EOL); fwrite($ini, "[$section]" . PHP_EOL);
foreach($options as $option => $setting) { foreach ($options as $option => $setting) {
if (is_null($setting)) { if (is_null($setting)) {
continue; continue;
} elseif (is_string($setting)) { } elseif (is_string($setting)) {

View file

@ -388,7 +388,8 @@ class configurationTestGenerator
* constructor, generates the configuration test * constructor, generates the configuration test
* @param array $options * @param array $options
*/ */
public function __construct($options) { public function __construct($options)
{
$this->_options = $options; $this->_options = $options;
// generate all possible combinations of options: options^settings // generate all possible combinations of options: options^settings
$this->_generateConfigurations(); $this->_generateConfigurations();
@ -418,7 +419,7 @@ class configurationTestGenerator
while (list($path, $setting) = each($test['conditions'])) { while (list($path, $setting) = each($test['conditions'])) {
if ($path == 'steps' && !in_array($step, $setting)) { if ($path == 'steps' && !in_array($step, $setting)) {
continue 2; continue 2;
} elseif($path != 'steps') { } elseif ($path != 'steps') {
list($section, $option) = explode('/', $path); list($section, $option) = explode('/', $path);
if ($fullOptions[$section][$option] !== $setting) { if ($fullOptions[$section][$option] !== $setting) {
continue 2; continue 2;
@ -653,7 +654,8 @@ EOT;
* @throws Exception * @throws Exception
* @return array * @return array
*/ */
private function _addSetting(&$configuration, &$setting, &$section, &$option) { private function _addSetting(&$configuration, &$setting, &$section, &$option)
{
if (++$this->_iterationCount > self::MAX_ITERATIONS) { if (++$this->_iterationCount > self::MAX_ITERATIONS) {
echo 'max iterations reached, stopping', PHP_EOL; echo 'max iterations reached, stopping', PHP_EOL;
return $configuration; return $configuration;

View file

@ -1,4 +1,7 @@
<?php <?php
use PrivateBin\configuration;
class configurationTest extends PHPUnit_Framework_TestCase class configurationTest extends PHPUnit_Framework_TestCase
{ {
private $_options; private $_options;
@ -125,12 +128,11 @@ class configurationTest extends PHPUnit_Framework_TestCase
$options['model']['class'] = 'zerobin_data'; $options['model']['class'] = 'zerobin_data';
helper::createIniFile(CONF, $options); helper::createIniFile(CONF, $options);
$conf = new configuration; $conf = new configuration;
$this->assertEquals('privatebin_data', $conf->getKey('class', 'model'), 'old data class gets renamed'); $this->assertEquals('PrivateBin\data\data', $conf->getKey('class', 'model'), 'old data class gets renamed');
$options['model']['class'] = 'zerobin_db'; $options['model']['class'] = 'zerobin_db';
helper::createIniFile(CONF, $options); helper::createIniFile(CONF, $options);
$conf = new configuration; $conf = new configuration;
$this->assertEquals('privatebin_db', $conf->getKey('class', 'model'), 'old db class gets renamed'); $this->assertEquals('PrivateBin\data\db', $conf->getKey('class', 'model'), 'old db class gets renamed');
} }
} }

View file

@ -1,4 +1,7 @@
<?php <?php
use PrivateBin\filter;
class filterTest extends PHPUnit_Framework_TestCase class filterTest extends PHPUnit_Framework_TestCase
{ {
public function testFilterStripsSlashesDeeply() public function testFilterStripsSlashesDeeply()

View file

@ -1,4 +1,7 @@
<?php <?php
use PrivateBin\i18n;
class i18nTest extends PHPUnit_Framework_TestCase class i18nTest extends PHPUnit_Framework_TestCase
{ {
private $_translations = array(); private $_translations = array();

View file

@ -1,4 +1,10 @@
<?php <?php
use PrivateBin\data\data;
use PrivateBin\privatebin;
use PrivateBin\request;
use PrivateBin\serversalt;
class jsonApiTest extends PHPUnit_Framework_TestCase class jsonApiTest extends PHPUnit_Framework_TestCase
{ {
protected $_model; protected $_model;
@ -6,7 +12,7 @@ class jsonApiTest extends PHPUnit_Framework_TestCase
public function setUp() public function setUp()
{ {
/* Setup Routine */ /* Setup Routine */
$this->_model = privatebin_data::getInstance(array('dir' => PATH . 'data')); $this->_model = data::getInstance(array('dir' => PATH . 'data'));
serversalt::setPath(PATH . 'data'); serversalt::setPath(PATH . 'data');
$this->reset(); $this->reset();
} }
@ -22,8 +28,9 @@ class jsonApiTest extends PHPUnit_Framework_TestCase
$_POST = array(); $_POST = array();
$_GET = array(); $_GET = array();
$_SERVER = array(); $_SERVER = array();
if ($this->_model->exists(helper::getPasteId())) if ($this->_model->exists(helper::getPasteId())) {
$this->_model->delete(helper::getPasteId()); $this->_model->delete(helper::getPasteId());
}
helper::confRestore(); helper::confRestore();
} }
@ -267,5 +274,4 @@ class jsonApiTest extends PHPUnit_Framework_TestCase
ob_end_clean(); ob_end_clean();
$this->assertEquals('{}', $content, 'does not output nasty data'); $this->assertEquals('{}', $content, 'does not output nasty data');
} }
} }

View file

@ -1,4 +1,11 @@
<?php <?php
use PrivateBin\configuration;
use PrivateBin\data\db;
use PrivateBin\model;
use PrivateBin\model\paste;
use PrivateBin\vizhash16x16;
class modelTest extends PHPUnit_Framework_TestCase class modelTest extends PHPUnit_Framework_TestCase
{ {
private $_conf; private $_conf;
@ -165,9 +172,9 @@ class modelTest extends PHPUnit_Framework_TestCase
public function testPasteIdValidation() public function testPasteIdValidation()
{ {
$this->assertTrue(model_paste::isValidId('a242ab7bdfb2581a'), 'valid paste id'); $this->assertTrue(paste::isValidId('a242ab7bdfb2581a'), 'valid paste id');
$this->assertFalse(model_paste::isValidId('foo'), 'invalid hex values'); $this->assertFalse(paste::isValidId('foo'), 'invalid hex values');
$this->assertFalse(model_paste::isValidId('../bar/baz'), 'path attack'); $this->assertFalse(paste::isValidId('../bar/baz'), 'path attack');
} }
/** /**
@ -214,37 +221,29 @@ class modelTest extends PHPUnit_Framework_TestCase
public function testPurge() public function testPurge()
{ {
$conf = new configuration; $conf = new configuration;
$store = privatebin_db::getInstance($conf->getSection('model_options')); $store = db::getInstance($conf->getSection('model_options'));
$store->delete(helper::getPasteId()); $store->delete(helper::getPasteId());
$expired = helper::getPaste(array('expire_date' => 1344803344)); $expired = helper::getPaste(array('expire_date' => 1344803344));
$paste = helper::getPaste(array('expire_date' => time() + 3600)); $paste = helper::getPaste(array('expire_date' => time() + 3600));
$keys = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'x', 'y', 'z'); $keys = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'x', 'y', 'z');
$ids = array(); $ids = array();
foreach ($keys as $key) foreach ($keys as $key) {
{
$ids[$key] = substr(md5($key), 0, 16); $ids[$key] = substr(md5($key), 0, 16);
$store->delete($ids[$key]); $store->delete($ids[$key]);
$this->assertFalse($store->exists($ids[$key]), "paste $key does not yet exist"); $this->assertFalse($store->exists($ids[$key]), "paste $key does not yet exist");
if (in_array($key, array('x', 'y', 'z'))) if (in_array($key, array('x', 'y', 'z'))) {
{
$this->assertTrue($store->create($ids[$key], $paste), "store $key paste"); $this->assertTrue($store->create($ids[$key], $paste), "store $key paste");
} } else {
else
{
$this->assertTrue($store->create($ids[$key], $expired), "store $key paste"); $this->assertTrue($store->create($ids[$key], $expired), "store $key paste");
} }
$this->assertTrue($store->exists($ids[$key]), "paste $key exists after storing it"); $this->assertTrue($store->exists($ids[$key]), "paste $key exists after storing it");
} }
$this->_model->purge(10); $this->_model->purge(10);
foreach ($ids as $key => $id) foreach ($ids as $key => $id) {
{ if (in_array($key, array('x', 'y', 'z'))) {
if (in_array($key, array('x', 'y', 'z')))
{
$this->assertTrue($this->_model->getPaste($id)->exists(), "paste $key exists after purge"); $this->assertTrue($this->_model->getPaste($id)->exists(), "paste $key exists after purge");
$this->_model->getPaste($id)->delete(); $this->_model->getPaste($id)->delete();
} } else {
else
{
$this->assertFalse($this->_model->getPaste($id)->exists(), "paste $key was purged"); $this->assertFalse($this->_model->getPaste($id)->exists(), "paste $key was purged");
} }
} }

View file

@ -7,7 +7,7 @@
<whitelist> <whitelist>
<directory suffix=".php">../lib</directory> <directory suffix=".php">../lib</directory>
<exclude> <exclude>
<file>../lib/privatebin/abstract.php</file> <file>../lib/data/AbstractData.php</file>
</exclude> </exclude>
</whitelist> </whitelist>
</filter> </filter>

View file

@ -1,4 +1,10 @@
<?php <?php
use PrivateBin\data\data;
use PrivateBin\privatebin;
use PrivateBin\serversalt;
use PrivateBin\trafficlimiter;
class privatebinTest extends PHPUnit_Framework_TestCase class privatebinTest extends PHPUnit_Framework_TestCase
{ {
protected $_model; protected $_model;
@ -6,7 +12,7 @@ class privatebinTest extends PHPUnit_Framework_TestCase
public function setUp() public function setUp()
{ {
/* Setup Routine */ /* Setup Routine */
$this->_model = privatebin_data::getInstance(array('dir' => PATH . 'data')); $this->_model = data::getInstance(array('dir' => PATH . 'data'));
$this->reset(); $this->reset();
} }
@ -21,8 +27,9 @@ class privatebinTest extends PHPUnit_Framework_TestCase
$_POST = array(); $_POST = array();
$_GET = array(); $_GET = array();
$_SERVER = array(); $_SERVER = array();
if ($this->_model->exists(helper::getPasteId())) if ($this->_model->exists(helper::getPasteId())) {
$this->_model->delete(helper::getPasteId()); $this->_model->delete(helper::getPasteId());
}
helper::confRestore(); helper::confRestore();
} }

View file

@ -1,4 +1,7 @@
<?php <?php
use PrivateBin\data\data;
class privatebin_dataTest extends PHPUnit_Framework_TestCase class privatebin_dataTest extends PHPUnit_Framework_TestCase
{ {
private $_model; private $_model;
@ -9,7 +12,7 @@ class privatebin_dataTest extends PHPUnit_Framework_TestCase
{ {
/* Setup Routine */ /* Setup Routine */
$this->_path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'privatebin_data'; $this->_path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'privatebin_data';
$this->_model = privatebin_data::getInstance(array('dir' => $this->_path)); $this->_model = data::getInstance(array('dir' => $this->_path));
} }
public function tearDown() public function tearDown()
@ -70,30 +73,22 @@ class privatebin_dataTest extends PHPUnit_Framework_TestCase
$paste = helper::getPaste(array('expire_date' => time() + 3600)); $paste = helper::getPaste(array('expire_date' => time() + 3600));
$keys = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'x', 'y', 'z'); $keys = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'x', 'y', 'z');
$ids = array(); $ids = array();
foreach ($keys as $key) foreach ($keys as $key) {
{
$ids[$key] = substr(md5($key), 0, 16); $ids[$key] = substr(md5($key), 0, 16);
$this->assertFalse($this->_model->exists($ids[$key]), "paste $key does not yet exist"); $this->assertFalse($this->_model->exists($ids[$key]), "paste $key does not yet exist");
if (in_array($key, array('x', 'y', 'z'))) if (in_array($key, array('x', 'y', 'z'))) {
{
$this->assertTrue($this->_model->create($ids[$key], $paste), "store $key paste"); $this->assertTrue($this->_model->create($ids[$key], $paste), "store $key paste");
} } else {
else
{
$this->assertTrue($this->_model->create($ids[$key], $expired), "store $key paste"); $this->assertTrue($this->_model->create($ids[$key], $expired), "store $key paste");
} }
$this->assertTrue($this->_model->exists($ids[$key]), "paste $key exists after storing it"); $this->assertTrue($this->_model->exists($ids[$key]), "paste $key exists after storing it");
} }
$this->_model->purge(10); $this->_model->purge(10);
foreach ($ids as $key => $id) foreach ($ids as $key => $id) {
{ if (in_array($key, array('x', 'y', 'z'))) {
if (in_array($key, array('x', 'y', 'z')))
{
$this->assertTrue($this->_model->exists($id), "paste $key exists after purge"); $this->assertTrue($this->_model->exists($id), "paste $key exists after purge");
$this->_model->delete($id); $this->_model->delete($id);
} } else {
else
{
$this->assertFalse($this->_model->exists($id), "paste $key was purged"); $this->assertFalse($this->_model->exists($id), "paste $key was purged");
} }
} }

View file

@ -1,4 +1,7 @@
<?php <?php
use PrivateBin\data\db;
class privatebin_dbTest extends PHPUnit_Framework_TestCase class privatebin_dbTest extends PHPUnit_Framework_TestCase
{ {
private $_model; private $_model;
@ -13,13 +16,15 @@ class privatebin_dbTest extends PHPUnit_Framework_TestCase
public function setUp() public function setUp()
{ {
/* Setup Routine */ /* Setup Routine */
$this->_model = privatebin_db::getInstance($this->_options); $this->_model = db::getInstance($this->_options);
} }
public function tearDown() public function tearDown()
{ {
/* Tear Down Routine */ /* Tear Down Routine */
if (is_dir(PATH . 'data')) helper::rmdir(PATH . 'data'); if (is_dir(PATH . 'data')) {
helper::rmdir(PATH . 'data');
}
} }
public function testDatabaseBasedDataStoreWorks() public function testDatabaseBasedDataStoreWorks()
@ -75,31 +80,23 @@ class privatebin_dbTest extends PHPUnit_Framework_TestCase
$paste = helper::getPaste(array('expire_date' => time() + 3600)); $paste = helper::getPaste(array('expire_date' => time() + 3600));
$keys = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'x', 'y', 'z'); $keys = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'x', 'y', 'z');
$ids = array(); $ids = array();
foreach ($keys as $key) foreach ($keys as $key) {
{
$ids[$key] = substr(md5($key), 0, 16); $ids[$key] = substr(md5($key), 0, 16);
$this->_model->delete($ids[$key]); $this->_model->delete($ids[$key]);
$this->assertFalse($this->_model->exists($ids[$key]), "paste $key does not yet exist"); $this->assertFalse($this->_model->exists($ids[$key]), "paste $key does not yet exist");
if (in_array($key, array('x', 'y', 'z'))) if (in_array($key, array('x', 'y', 'z'))) {
{
$this->assertTrue($this->_model->create($ids[$key], $paste), "store $key paste"); $this->assertTrue($this->_model->create($ids[$key], $paste), "store $key paste");
} } else {
else
{
$this->assertTrue($this->_model->create($ids[$key], $expired), "store $key paste"); $this->assertTrue($this->_model->create($ids[$key], $expired), "store $key paste");
} }
$this->assertTrue($this->_model->exists($ids[$key]), "paste $key exists after storing it"); $this->assertTrue($this->_model->exists($ids[$key]), "paste $key exists after storing it");
} }
$this->_model->purge(10); $this->_model->purge(10);
foreach ($ids as $key => $id) foreach ($ids as $key => $id) {
{ if (in_array($key, array('x', 'y', 'z'))) {
if (in_array($key, array('x', 'y', 'z')))
{
$this->assertTrue($this->_model->exists($id), "paste $key exists after purge"); $this->assertTrue($this->_model->exists($id), "paste $key exists after purge");
$this->_model->delete($id); $this->_model->delete($id);
} } else {
else
{
$this->assertFalse($this->_model->exists($id), "paste $key was purged"); $this->assertFalse($this->_model->exists($id), "paste $key was purged");
} }
} }
@ -110,7 +107,7 @@ class privatebin_dbTest extends PHPUnit_Framework_TestCase
*/ */
public function testGetIbmInstance() public function testGetIbmInstance()
{ {
privatebin_db::getInstance(array( db::getInstance(array(
'dsn' => 'ibm:', 'usr' => null, 'pwd' => null, 'dsn' => 'ibm:', 'usr' => null, 'pwd' => null,
'opt' => array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION) 'opt' => array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION)
)); ));
@ -121,7 +118,7 @@ class privatebin_dbTest extends PHPUnit_Framework_TestCase
*/ */
public function testGetInformixInstance() public function testGetInformixInstance()
{ {
privatebin_db::getInstance(array( db::getInstance(array(
'dsn' => 'informix:', 'usr' => null, 'pwd' => null, 'dsn' => 'informix:', 'usr' => null, 'pwd' => null,
'opt' => array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION) 'opt' => array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION)
)); ));
@ -132,7 +129,7 @@ class privatebin_dbTest extends PHPUnit_Framework_TestCase
*/ */
public function testGetMssqlInstance() public function testGetMssqlInstance()
{ {
privatebin_db::getInstance(array( db::getInstance(array(
'dsn' => 'mssql:', 'usr' => null, 'pwd' => null, 'dsn' => 'mssql:', 'usr' => null, 'pwd' => null,
'opt' => array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION) 'opt' => array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION)
)); ));
@ -143,7 +140,7 @@ class privatebin_dbTest extends PHPUnit_Framework_TestCase
*/ */
public function testGetMysqlInstance() public function testGetMysqlInstance()
{ {
privatebin_db::getInstance(array( db::getInstance(array(
'dsn' => 'mysql:', 'usr' => null, 'pwd' => null, 'dsn' => 'mysql:', 'usr' => null, 'pwd' => null,
'opt' => array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION) 'opt' => array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION)
)); ));
@ -154,7 +151,7 @@ class privatebin_dbTest extends PHPUnit_Framework_TestCase
*/ */
public function testGetOciInstance() public function testGetOciInstance()
{ {
privatebin_db::getInstance(array( db::getInstance(array(
'dsn' => 'oci:', 'usr' => null, 'pwd' => null, 'dsn' => 'oci:', 'usr' => null, 'pwd' => null,
'opt' => array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION) 'opt' => array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION)
)); ));
@ -165,7 +162,7 @@ class privatebin_dbTest extends PHPUnit_Framework_TestCase
*/ */
public function testGetPgsqlInstance() public function testGetPgsqlInstance()
{ {
privatebin_db::getInstance(array( db::getInstance(array(
'dsn' => 'pgsql:', 'usr' => null, 'pwd' => null, 'dsn' => 'pgsql:', 'usr' => null, 'pwd' => null,
'opt' => array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION) 'opt' => array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION)
)); ));
@ -177,7 +174,7 @@ class privatebin_dbTest extends PHPUnit_Framework_TestCase
*/ */
public function testGetFooInstance() public function testGetFooInstance()
{ {
privatebin_db::getInstance(array( db::getInstance(array(
'dsn' => 'foo:', 'usr' => null, 'pwd' => null, 'opt' => null 'dsn' => 'foo:', 'usr' => null, 'pwd' => null, 'opt' => null
)); ));
} }
@ -190,7 +187,7 @@ class privatebin_dbTest extends PHPUnit_Framework_TestCase
{ {
$options = $this->_options; $options = $this->_options;
unset($options['dsn']); unset($options['dsn']);
privatebin_db::getInstance($options); db::getInstance($options);
} }
/** /**
@ -201,7 +198,7 @@ class privatebin_dbTest extends PHPUnit_Framework_TestCase
{ {
$options = $this->_options; $options = $this->_options;
unset($options['usr']); unset($options['usr']);
privatebin_db::getInstance($options); db::getInstance($options);
} }
/** /**
@ -212,7 +209,7 @@ class privatebin_dbTest extends PHPUnit_Framework_TestCase
{ {
$options = $this->_options; $options = $this->_options;
unset($options['pwd']); unset($options['pwd']);
privatebin_db::getInstance($options); db::getInstance($options);
} }
/** /**
@ -223,7 +220,7 @@ class privatebin_dbTest extends PHPUnit_Framework_TestCase
{ {
$options = $this->_options; $options = $this->_options;
unset($options['opt']); unset($options['opt']);
privatebin_db::getInstance($options); db::getInstance($options);
} }
public function testOldAttachments() public function testOldAttachments()
@ -233,7 +230,7 @@ class privatebin_dbTest extends PHPUnit_Framework_TestCase
@unlink($path); @unlink($path);
$this->_options['dsn'] = 'sqlite:' . $path; $this->_options['dsn'] = 'sqlite:' . $path;
$this->_options['tbl'] = 'bar_'; $this->_options['tbl'] = 'bar_';
$model = privatebin_db::getInstance($this->_options); $model = db::getInstance($this->_options);
$original = $paste = helper::getPasteWithAttachment(array('expire_date' => 1344803344)); $original = $paste = helper::getPasteWithAttachment(array('expire_date' => 1344803344));
$paste['meta']['attachment'] = $paste['attachment']; $paste['meta']['attachment'] = $paste['attachment'];
@ -301,7 +298,7 @@ class privatebin_dbTest extends PHPUnit_Framework_TestCase
'vizhash BLOB, ' . 'vizhash BLOB, ' .
"postdate INT );" "postdate INT );"
); );
privatebin_db::getInstance($this->_options); db::getInstance($this->_options);
helper::rmdir(PATH . 'data'); helper::rmdir(PATH . 'data');
} }
} }

View file

@ -1,4 +1,10 @@
<?php <?php
use PrivateBin\data\db;
use PrivateBin\privatebin;
use PrivateBin\serversalt;
use PrivateBin\trafficlimiter;
require_once 'privatebin.php'; require_once 'privatebin.php';
class privatebinWithDbTest extends privatebinTest class privatebinWithDbTest extends privatebinTest
@ -18,9 +24,11 @@ class privatebinWithDbTest extends privatebinTest
{ {
/* Setup Routine */ /* Setup Routine */
$this->_path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'privatebin_data'; $this->_path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'privatebin_data';
if(!is_dir($this->_path)) mkdir($this->_path); if (!is_dir($this->_path)) {
mkdir($this->_path);
}
$this->_options['dsn'] = 'sqlite:' . $this->_path . DIRECTORY_SEPARATOR . 'tst.sq3'; $this->_options['dsn'] = 'sqlite:' . $this->_path . DIRECTORY_SEPARATOR . 'tst.sq3';
$this->_model = privatebin_db::getInstance($this->_options); $this->_model = db::getInstance($this->_options);
$this->reset(); $this->reset();
} }

View file

@ -1,4 +1,7 @@
<?php <?php
use PrivateBin\purgelimiter;
class purgelimiterTest extends PHPUnit_Framework_TestCase class purgelimiterTest extends PHPUnit_Framework_TestCase
{ {
private $_path; private $_path;
@ -7,7 +10,9 @@ class purgelimiterTest extends PHPUnit_Framework_TestCase
{ {
/* Setup Routine */ /* Setup Routine */
$this->_path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'privatebin_data'; $this->_path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'privatebin_data';
if(!is_dir($this->_path)) mkdir($this->_path); if (!is_dir($this->_path)) {
mkdir($this->_path);
}
purgelimiter::setPath($this->_path); purgelimiter::setPath($this->_path);
} }

View file

@ -1,4 +1,7 @@
<?php <?php
use PrivateBin\request;
class requestTest extends PHPUnit_Framework_TestCase class requestTest extends PHPUnit_Framework_TestCase
{ {
public function setUp() public function setUp()

View file

@ -1,4 +1,7 @@
<?php <?php
use PrivateBin\serversalt;
class serversaltTest extends PHPUnit_Framework_TestCase class serversaltTest extends PHPUnit_Framework_TestCase
{ {
private $_path; private $_path;
@ -13,13 +16,17 @@ class serversaltTest extends PHPUnit_Framework_TestCase
{ {
/* Setup Routine */ /* Setup Routine */
$this->_path = PATH . 'data'; $this->_path = PATH . 'data';
if(!is_dir($this->_path)) mkdir($this->_path); if (!is_dir($this->_path)) {
mkdir($this->_path);
}
serversalt::setPath($this->_path); serversalt::setPath($this->_path);
$this->_otherPath = $this->_path . DIRECTORY_SEPARATOR . 'foo'; $this->_otherPath = $this->_path . DIRECTORY_SEPARATOR . 'foo';
$this->_invalidPath = $this->_path . DIRECTORY_SEPARATOR . 'bar'; $this->_invalidPath = $this->_path . DIRECTORY_SEPARATOR . 'bar';
if(!is_dir($this->_invalidPath)) mkdir($this->_invalidPath); if (!is_dir($this->_invalidPath)) {
mkdir($this->_invalidPath);
}
$this->_invalidFile = $this->_invalidPath . DIRECTORY_SEPARATOR . 'salt.php'; $this->_invalidFile = $this->_invalidPath . DIRECTORY_SEPARATOR . 'salt.php';
} }
@ -37,18 +44,18 @@ class serversaltTest extends PHPUnit_Framework_TestCase
$salt = serversalt::get(); $salt = serversalt::get();
// mcrypt mock // mcrypt mock
if (!function_exists('mcrypt_create_iv')) if (!function_exists('mcrypt_create_iv')) {
{ if (!defined('MCRYPT_DEV_URANDOM')) {
if (!defined('MCRYPT_DEV_URANDOM')) define('MCRYPT_DEV_URANDOM', 1); define('MCRYPT_DEV_URANDOM', 1);
}
function mcrypt_create_iv($int, $flag) function mcrypt_create_iv($int, $flag)
{ {
$randomSalt = ''; $randomSalt = '';
for($i = 0; $i < $int; ++$i) { for ($i = 0; $i < $int; ++$i) {
$randomSalt .= base_convert(mt_rand(), 10, 16); $randomSalt .= base_convert(mt_rand(), 10, 16);
} }
// hex2bin requires an even length, pad if necessary // hex2bin requires an even length, pad if necessary
if (strlen($randomSalt) % 2) if (strlen($randomSalt) % 2) {
{
$randomSalt = '0' . $randomSalt; $randomSalt = '0' . $randomSalt;
} }
return hex2bin($randomSalt); return hex2bin($randomSalt);

View file

@ -1,4 +1,7 @@
<?php <?php
use PrivateBin\sjcl;
class sjclTest extends PHPUnit_Framework_TestCase class sjclTest extends PHPUnit_Framework_TestCase
{ {
public function testSjclValidatorValidatesCorrectly() public function testSjclValidatorValidatesCorrectly()

View file

@ -1,4 +1,7 @@
<?php <?php
use PrivateBin\trafficlimiter;
class trafficlimiterTest extends PHPUnit_Framework_TestCase class trafficlimiterTest extends PHPUnit_Framework_TestCase
{ {
private $_path; private $_path;

View file

@ -1,4 +1,8 @@
<?php <?php
use PrivateBin\i18n;
use PrivateBin\view;
class viewTest extends PHPUnit_Framework_TestCase class viewTest extends PHPUnit_Framework_TestCase
{ {
private static $error = 'foo bar'; private static $error = 'foo bar';

View file

@ -1,4 +1,8 @@
<?php <?php
use PrivateBin\serversalt;
use PrivateBin\vizhash16x16;
class vizhash16x16Test extends PHPUnit_Framework_TestCase class vizhash16x16Test extends PHPUnit_Framework_TestCase
{ {
private $_file; private $_file;
@ -9,7 +13,9 @@ class vizhash16x16Test extends PHPUnit_Framework_TestCase
{ {
/* Setup Routine */ /* Setup Routine */
$this->_path = PATH . 'data'; $this->_path = PATH . 'data';
if(!is_dir($this->_path)) mkdir($this->_path); if (!is_dir($this->_path)) {
mkdir($this->_path);
}
$this->_file = $this->_path . DIRECTORY_SEPARATOR . 'vizhash.png'; $this->_file = $this->_path . DIRECTORY_SEPARATOR . 'vizhash.png';
serversalt::setPath($this->_path); serversalt::setPath($this->_path);
} }
@ -18,7 +24,7 @@ class vizhash16x16Test extends PHPUnit_Framework_TestCase
{ {
/* Tear Down Routine */ /* Tear Down Routine */
chmod($this->_path, 0700); chmod($this->_path, 0700);
if(!@unlink($this->_file)) { if (!@unlink($this->_file)) {
throw new Exception('Error deleting file "' . $this->_file . '".'); throw new Exception('Error deleting file "' . $this->_file . '".');
} }
helper::rmdir($this->_path); helper::rmdir($this->_path);