2012-04-29 17:15:06 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2016-07-11 09:58:15 +00:00
|
|
|
* PrivateBin
|
2012-04-29 17:15:06 +00:00
|
|
|
*
|
|
|
|
* a zero-knowledge paste bin
|
|
|
|
*
|
2016-07-11 09:58:15 +00:00
|
|
|
* @link https://github.com/PrivateBin/PrivateBin
|
2012-04-29 17:15:06 +00:00
|
|
|
* @copyright 2012 Sébastien SAUVAGE (sebsauvage.net)
|
2016-07-19 11:56:52 +00:00
|
|
|
* @license https://www.opensource.org/licenses/zlib-license.php The zlib/libpng License
|
2024-02-11 14:31:11 +00:00
|
|
|
* @version 1.7.1
|
2012-04-29 17:15:06 +00:00
|
|
|
*/
|
2016-12-12 17:43:23 +00:00
|
|
|
|
2016-12-12 17:50:00 +00:00
|
|
|
namespace PrivateBin;
|
2016-07-21 15:09:48 +00:00
|
|
|
|
|
|
|
use Exception;
|
2016-10-29 08:24:08 +00:00
|
|
|
use PrivateBin\Persistence\ServerSalt;
|
|
|
|
use PrivateBin\Persistence\TrafficLimiter;
|
2016-07-21 15:09:48 +00:00
|
|
|
|
2012-04-29 17:15:06 +00:00
|
|
|
/**
|
2018-07-29 13:17:35 +00:00
|
|
|
* Controller
|
2012-04-29 17:15:06 +00:00
|
|
|
*
|
2018-07-29 13:17:35 +00:00
|
|
|
* Puts it all together.
|
2012-04-29 17:15:06 +00:00
|
|
|
*/
|
2018-07-29 13:17:35 +00:00
|
|
|
class Controller
|
2012-04-29 17:15:06 +00:00
|
|
|
{
|
2015-08-16 13:55:31 +00:00
|
|
|
/**
|
|
|
|
* version
|
|
|
|
*
|
|
|
|
* @const string
|
2012-04-29 17:15:06 +00:00
|
|
|
*/
|
2024-02-11 14:31:11 +00:00
|
|
|
const VERSION = '1.7.1';
|
2012-04-29 17:15:06 +00:00
|
|
|
|
2017-03-24 18:20:34 +00:00
|
|
|
/**
|
|
|
|
* minimal required PHP version
|
|
|
|
*
|
|
|
|
* @const string
|
|
|
|
*/
|
2023-07-23 08:04:57 +00:00
|
|
|
const MIN_PHP_VERSION = '7.3.0';
|
2017-03-24 18:20:34 +00:00
|
|
|
|
2015-08-31 20:10:41 +00:00
|
|
|
/**
|
|
|
|
* show the same error message if the paste expired or does not exist
|
|
|
|
*
|
|
|
|
* @const string
|
|
|
|
*/
|
|
|
|
const GENERIC_ERROR = 'Paste does not exist, has expired or has been deleted.';
|
|
|
|
|
2012-04-29 17:15:06 +00:00
|
|
|
/**
|
2015-09-22 21:21:31 +00:00
|
|
|
* configuration
|
2015-08-16 13:55:31 +00:00
|
|
|
*
|
2012-04-29 17:15:06 +00:00
|
|
|
* @access private
|
2016-08-09 09:54:42 +00:00
|
|
|
* @var Configuration
|
2012-04-29 17:15:06 +00:00
|
|
|
*/
|
2015-09-22 21:21:31 +00:00
|
|
|
private $_conf;
|
2012-04-29 17:15:06 +00:00
|
|
|
|
|
|
|
/**
|
2015-08-16 13:55:31 +00:00
|
|
|
* error message
|
|
|
|
*
|
2012-04-29 17:15:06 +00:00
|
|
|
* @access private
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
private $_error = '';
|
|
|
|
|
2013-11-01 00:15:14 +00:00
|
|
|
/**
|
2015-08-16 13:55:31 +00:00
|
|
|
* status message
|
|
|
|
*
|
2013-11-01 00:15:14 +00:00
|
|
|
* @access private
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
private $_status = '';
|
|
|
|
|
2015-09-01 20:33:07 +00:00
|
|
|
/**
|
|
|
|
* JSON message
|
|
|
|
*
|
|
|
|
* @access private
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
private $_json = '';
|
|
|
|
|
2012-04-29 17:15:06 +00:00
|
|
|
/**
|
2015-09-27 01:03:55 +00:00
|
|
|
* Factory of instance models
|
2015-08-16 13:55:31 +00:00
|
|
|
*
|
2012-04-29 17:15:06 +00:00
|
|
|
* @access private
|
2015-09-27 01:03:55 +00:00
|
|
|
* @var model
|
2012-04-29 17:15:06 +00:00
|
|
|
*/
|
|
|
|
private $_model;
|
|
|
|
|
2015-09-27 18:34:39 +00:00
|
|
|
/**
|
|
|
|
* request
|
|
|
|
*
|
|
|
|
* @access private
|
|
|
|
* @var request
|
|
|
|
*/
|
|
|
|
private $_request;
|
|
|
|
|
2015-10-18 12:37:58 +00:00
|
|
|
/**
|
|
|
|
* URL base
|
|
|
|
*
|
|
|
|
* @access private
|
|
|
|
* @var string
|
|
|
|
*/
|
2016-08-09 09:54:42 +00:00
|
|
|
private $_urlBase;
|
2015-10-18 12:37:58 +00:00
|
|
|
|
2012-04-29 17:15:06 +00:00
|
|
|
/**
|
|
|
|
* constructor
|
|
|
|
*
|
2016-07-11 09:58:15 +00:00
|
|
|
* initializes and runs PrivateBin
|
2012-04-29 17:15:06 +00:00
|
|
|
*
|
|
|
|
* @access public
|
2016-08-22 07:46:26 +00:00
|
|
|
* @throws Exception
|
2012-04-29 17:15:06 +00:00
|
|
|
*/
|
|
|
|
public function __construct()
|
|
|
|
{
|
2017-03-24 18:20:34 +00:00
|
|
|
if (version_compare(PHP_VERSION, self::MIN_PHP_VERSION) < 0) {
|
2023-12-16 06:38:09 +00:00
|
|
|
error_log(I18n::_('%s requires php %s or above to work. Sorry.', I18n::_('PrivateBin'), self::MIN_PHP_VERSION));
|
|
|
|
return;
|
2015-09-01 20:33:07 +00:00
|
|
|
}
|
2024-04-18 19:36:43 +00:00
|
|
|
if (!empty(PATH) && substr(PATH, -1) !== DIRECTORY_SEPARATOR) {
|
2023-12-16 06:38:09 +00:00
|
|
|
error_log(I18n::_('%s requires the PATH to end in a "%s". Please update the PATH in your index.php.', I18n::_('PrivateBin'), DIRECTORY_SEPARATOR));
|
|
|
|
return;
|
2016-08-22 07:46:26 +00:00
|
|
|
}
|
2012-04-29 17:15:06 +00:00
|
|
|
|
2016-08-09 09:54:42 +00:00
|
|
|
// load config from ini file, initialize required classes
|
2012-04-29 17:15:06 +00:00
|
|
|
$this->_init();
|
|
|
|
|
2016-07-26 06:19:35 +00:00
|
|
|
switch ($this->_request->getOperation()) {
|
2015-09-27 18:34:39 +00:00
|
|
|
case 'create':
|
|
|
|
$this->_create();
|
|
|
|
break;
|
|
|
|
case 'delete':
|
|
|
|
$this->_delete(
|
|
|
|
$this->_request->getParam('pasteid'),
|
|
|
|
$this->_request->getParam('deletetoken')
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
case 'read':
|
|
|
|
$this->_read($this->_request->getParam('pasteid'));
|
|
|
|
break;
|
2015-10-18 12:37:58 +00:00
|
|
|
case 'jsonld':
|
|
|
|
$this->_jsonld($this->_request->getParam('jsonld'));
|
|
|
|
return;
|
2022-10-23 06:10:56 +00:00
|
|
|
case 'yourlsproxy':
|
|
|
|
$this->_yourlsproxy($this->_request->getParam('link'));
|
|
|
|
break;
|
2012-04-29 17:15:06 +00:00
|
|
|
}
|
|
|
|
|
2024-03-09 21:27:19 +00:00
|
|
|
$this->_setCacheHeaders();
|
2024-03-09 21:55:44 +00:00
|
|
|
|
2015-09-01 20:33:07 +00:00
|
|
|
// output JSON or HTML
|
2016-07-26 06:19:35 +00:00
|
|
|
if ($this->_request->isJsonApiCall()) {
|
2016-08-09 09:54:42 +00:00
|
|
|
header('Content-type: ' . Request::MIME_JSON);
|
2015-10-18 12:37:58 +00:00
|
|
|
header('Access-Control-Allow-Origin: *');
|
|
|
|
header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE');
|
|
|
|
header('Access-Control-Allow-Headers: X-Requested-With, Content-Type');
|
2024-03-24 11:07:59 +00:00
|
|
|
header('X-Uncompressed-Content-Length: ' . strlen($this->_json));
|
|
|
|
header('Access-Control-Expose-Headers: X-Uncompressed-Content-Length');
|
2015-09-01 20:33:07 +00:00
|
|
|
echo $this->_json;
|
2016-07-26 06:19:35 +00:00
|
|
|
} else {
|
2015-09-01 20:33:07 +00:00
|
|
|
$this->_view();
|
|
|
|
}
|
2012-04-29 17:15:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-07-29 13:17:35 +00:00
|
|
|
* initialize PrivateBin
|
2012-04-29 17:15:06 +00:00
|
|
|
*
|
|
|
|
* @access private
|
2019-05-13 20:31:52 +00:00
|
|
|
* @throws Exception
|
2012-04-29 17:15:06 +00:00
|
|
|
*/
|
|
|
|
private function _init()
|
|
|
|
{
|
2016-08-15 14:45:47 +00:00
|
|
|
$this->_conf = new Configuration;
|
|
|
|
$this->_model = new Model($this->_conf);
|
2016-08-09 09:54:42 +00:00
|
|
|
$this->_request = new Request;
|
2018-01-06 09:27:58 +00:00
|
|
|
$this->_urlBase = $this->_request->getRequestUri();
|
2015-10-18 18:38:07 +00:00
|
|
|
|
|
|
|
// set default language
|
|
|
|
$lang = $this->_conf->getKey('languagedefault');
|
2016-08-09 09:54:42 +00:00
|
|
|
I18n::setLanguageFallback($lang);
|
2015-10-18 18:38:07 +00:00
|
|
|
// force default language, if language selection is disabled and a default is set
|
2016-07-26 06:19:35 +00:00
|
|
|
if (!$this->_conf->getKey('languageselection') && strlen($lang) == 2) {
|
2015-10-18 18:38:07 +00:00
|
|
|
$_COOKIE['lang'] = $lang;
|
2021-04-16 18:15:12 +00:00
|
|
|
setcookie('lang', $lang, 0, '', '', true);
|
2015-10-18 18:38:07 +00:00
|
|
|
}
|
2012-04-29 17:15:06 +00:00
|
|
|
}
|
2024-03-09 21:55:44 +00:00
|
|
|
|
2024-03-09 21:27:19 +00:00
|
|
|
/**
|
|
|
|
* Turn off browser caching
|
2024-03-09 21:55:44 +00:00
|
|
|
*
|
2024-03-09 21:27:19 +00:00
|
|
|
* @access private
|
|
|
|
*/
|
|
|
|
private function _setCacheHeaders()
|
|
|
|
{
|
|
|
|
// set headers to disable caching
|
|
|
|
$time = gmdate('D, d M Y H:i:s \G\M\T');
|
|
|
|
header('Cache-Control: no-store, no-cache, no-transform, must-revalidate');
|
|
|
|
header('Pragma: no-cache');
|
|
|
|
header('Expires: ' . $time);
|
|
|
|
header('Last-Modified: ' . $time);
|
|
|
|
header('Vary: Accept');
|
|
|
|
}
|
2012-04-29 17:15:06 +00:00
|
|
|
|
|
|
|
/**
|
2013-11-01 00:15:14 +00:00
|
|
|
* Store new paste or comment
|
2012-04-29 17:15:06 +00:00
|
|
|
*
|
2015-09-16 20:51:48 +00:00
|
|
|
* POST contains one or both:
|
2019-05-03 21:03:57 +00:00
|
|
|
* data = json encoded FormatV2 encrypted text (containing keys: iv,v,iter,ks,ts,mode,adata,cipher,salt,ct)
|
|
|
|
* attachment = json encoded FormatV2 encrypted text (containing keys: iv,v,iter,ks,ts,mode,adata,cipher,salt,ct)
|
2012-04-29 17:15:06 +00:00
|
|
|
*
|
|
|
|
* All optional data will go to meta information:
|
2012-05-19 21:59:41 +00:00
|
|
|
* expire (optional) = expiration delay (never,5min,10min,1hour,1day,1week,1month,1year,burn) (default:never)
|
2015-09-16 20:51:48 +00:00
|
|
|
* formatter (optional) = format to display the paste as (plaintext,syntaxhighlighting,markdown) (default:syntaxhighlighting)
|
|
|
|
* burnafterreading (optional) = if this paste may only viewed once ? (0/1) (default:0)
|
2012-04-29 17:15:06 +00:00
|
|
|
* opendiscusssion (optional) = is the discussion allowed on this paste ? (0/1) (default:0)
|
2019-05-03 21:03:57 +00:00
|
|
|
* attachmentname = json encoded FormatV2 encrypted text (containing keys: iv,v,iter,ks,ts,mode,adata,cipher,salt,ct)
|
|
|
|
* nickname (optional) = in discussion, encoded FormatV2 encrypted text nickname of author of comment (containing keys: iv,v,iter,ks,ts,mode,adata,cipher,salt,ct)
|
2012-04-29 17:15:06 +00:00
|
|
|
* parentid (optional) = in discussion, which comment this comment replies to.
|
|
|
|
* pasteid (optional) = in discussion, which paste this comment belongs to.
|
|
|
|
*
|
|
|
|
* @access private
|
2015-08-27 21:58:56 +00:00
|
|
|
* @return string
|
2012-04-29 17:15:06 +00:00
|
|
|
*/
|
2015-09-16 20:51:48 +00:00
|
|
|
private function _create()
|
2012-04-29 17:15:06 +00:00
|
|
|
{
|
2021-06-13 08:44:26 +00:00
|
|
|
// Ensure last paste from visitors IP address was more than configured amount of seconds ago.
|
|
|
|
ServerSalt::setStore($this->_model->getStore());
|
|
|
|
TrafficLimiter::setConfiguration($this->_conf);
|
|
|
|
TrafficLimiter::setStore($this->_model->getStore());
|
2022-02-20 10:25:19 +00:00
|
|
|
try {
|
|
|
|
TrafficLimiter::canPass();
|
|
|
|
} catch (Exception $e) {
|
|
|
|
$this->_return_message(1, $e->getMessage());
|
2019-05-19 07:42:55 +00:00
|
|
|
return;
|
2016-07-26 06:19:35 +00:00
|
|
|
}
|
2012-04-29 17:15:06 +00:00
|
|
|
|
2019-05-08 20:11:21 +00:00
|
|
|
$data = $this->_request->getData();
|
2019-05-10 05:55:39 +00:00
|
|
|
$isComment = array_key_exists('pasteid', $data) &&
|
|
|
|
!empty($data['pasteid']) &&
|
|
|
|
array_key_exists('parentid', $data) &&
|
|
|
|
!empty($data['parentid']);
|
|
|
|
if (!FormatV2::isValid($data, $isComment)) {
|
2019-05-19 07:42:55 +00:00
|
|
|
$this->_return_message(1, I18n::_('Invalid data.'));
|
|
|
|
return;
|
2019-05-10 05:55:39 +00:00
|
|
|
}
|
2015-09-22 21:21:31 +00:00
|
|
|
$sizelimit = $this->_conf->getKey('sizelimit');
|
2019-05-13 20:31:52 +00:00
|
|
|
// Ensure content is not too big.
|
2019-05-08 20:11:21 +00:00
|
|
|
if (strlen($data['ct']) > $sizelimit) {
|
2019-05-19 07:42:55 +00:00
|
|
|
$this->_return_message(
|
2019-05-08 20:11:21 +00:00
|
|
|
1,
|
|
|
|
I18n::_(
|
|
|
|
'Paste is limited to %s of encrypted data.',
|
|
|
|
Filter::formatHumanReadableSize($sizelimit)
|
|
|
|
)
|
|
|
|
);
|
2019-05-19 07:42:55 +00:00
|
|
|
return;
|
2016-07-19 13:26:41 +00:00
|
|
|
}
|
|
|
|
|
2015-09-27 01:03:55 +00:00
|
|
|
// The user posts a comment.
|
2019-05-10 05:55:39 +00:00
|
|
|
if ($isComment) {
|
2019-05-08 20:11:21 +00:00
|
|
|
$paste = $this->_model->getPaste($data['pasteid']);
|
2015-09-27 01:03:55 +00:00
|
|
|
if ($paste->exists()) {
|
|
|
|
try {
|
2019-05-08 20:11:21 +00:00
|
|
|
$comment = $paste->getComment($data['parentid']);
|
2015-09-27 01:03:55 +00:00
|
|
|
$comment->setData($data);
|
|
|
|
$comment->store();
|
2016-07-26 06:19:35 +00:00
|
|
|
} catch (Exception $e) {
|
2019-05-19 07:42:55 +00:00
|
|
|
$this->_return_message(1, $e->getMessage());
|
|
|
|
return;
|
2015-09-27 01:03:55 +00:00
|
|
|
}
|
|
|
|
$this->_return_message(0, $comment->getId());
|
2016-07-26 06:19:35 +00:00
|
|
|
} else {
|
2019-05-15 05:44:03 +00:00
|
|
|
$this->_return_message(1, I18n::_('Invalid data.'));
|
2015-09-12 15:33:16 +00:00
|
|
|
}
|
|
|
|
}
|
2015-09-27 01:03:55 +00:00
|
|
|
// The user posts a standard paste.
|
2016-07-26 06:19:35 +00:00
|
|
|
else {
|
2023-12-16 06:38:09 +00:00
|
|
|
try {
|
|
|
|
$this->_model->purge();
|
|
|
|
} catch (Exception $e) {
|
|
|
|
error_log('Error purging pastes: ' . $e->getMessage() . PHP_EOL .
|
|
|
|
'Use the administration scripts statistics to find ' .
|
|
|
|
'damaged paste IDs and either delete them or restore them ' .
|
|
|
|
'from backup.');
|
|
|
|
}
|
2015-09-27 01:03:55 +00:00
|
|
|
$paste = $this->_model->getPaste();
|
|
|
|
try {
|
2015-10-03 15:54:18 +00:00
|
|
|
$paste->setData($data);
|
2015-09-27 01:03:55 +00:00
|
|
|
$paste->store();
|
|
|
|
} catch (Exception $e) {
|
|
|
|
return $this->_return_message(1, $e->getMessage());
|
|
|
|
}
|
|
|
|
$this->_return_message(0, $paste->getId(), array('deletetoken' => $paste->getDeleteToken()));
|
2012-04-29 17:15:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-24 13:33:51 +00:00
|
|
|
/**
|
|
|
|
* Delete an existing paste
|
|
|
|
*
|
|
|
|
* @access private
|
2013-11-01 00:15:14 +00:00
|
|
|
* @param string $dataid
|
|
|
|
* @param string $deletetoken
|
2013-02-24 13:33:51 +00:00
|
|
|
*/
|
|
|
|
private function _delete($dataid, $deletetoken)
|
|
|
|
{
|
2015-09-27 01:03:55 +00:00
|
|
|
try {
|
|
|
|
$paste = $this->_model->getPaste($dataid);
|
2016-07-26 06:19:35 +00:00
|
|
|
if ($paste->exists()) {
|
2019-05-08 20:11:21 +00:00
|
|
|
// accessing this method ensures that the paste would be
|
2015-09-27 01:03:55 +00:00
|
|
|
// deleted if it has already expired
|
2019-05-08 20:11:21 +00:00
|
|
|
$paste->get();
|
2020-02-05 18:30:14 +00:00
|
|
|
if (hash_equals($paste->getDeleteToken(), $deletetoken)) {
|
2019-05-08 20:11:21 +00:00
|
|
|
// Paste exists and deletion token is valid: Delete the paste.
|
2017-02-22 20:42:14 +00:00
|
|
|
$paste->delete();
|
|
|
|
$this->_status = 'Paste was properly deleted.';
|
2016-07-26 06:19:35 +00:00
|
|
|
} else {
|
2019-05-08 20:11:21 +00:00
|
|
|
$this->_error = 'Wrong deletion token. Paste was not deleted.';
|
2015-09-27 01:03:55 +00:00
|
|
|
}
|
2016-07-26 06:19:35 +00:00
|
|
|
} else {
|
2015-09-27 01:03:55 +00:00
|
|
|
$this->_error = self::GENERIC_ERROR;
|
2015-08-31 20:10:41 +00:00
|
|
|
}
|
2015-09-27 01:03:55 +00:00
|
|
|
} catch (Exception $e) {
|
|
|
|
$this->_error = $e->getMessage();
|
2013-11-01 00:15:14 +00:00
|
|
|
}
|
2017-02-22 20:42:14 +00:00
|
|
|
if ($this->_request->isJsonApiCall()) {
|
2024-04-18 19:36:43 +00:00
|
|
|
if (empty($this->_error)) {
|
2017-02-22 20:42:14 +00:00
|
|
|
$this->_return_message(0, $dataid);
|
2024-04-18 19:36:43 +00:00
|
|
|
} else {
|
|
|
|
$this->_return_message(1, $this->_error);
|
2017-02-22 20:42:14 +00:00
|
|
|
}
|
|
|
|
}
|
2013-11-01 00:15:14 +00:00
|
|
|
}
|
|
|
|
|
2012-04-29 17:15:06 +00:00
|
|
|
/**
|
2018-05-27 12:36:30 +00:00
|
|
|
* Read an existing paste or comment, only allowed via a JSON API call
|
2012-04-29 17:15:06 +00:00
|
|
|
*
|
|
|
|
* @access private
|
2013-11-01 00:15:14 +00:00
|
|
|
* @param string $dataid
|
2012-04-29 17:15:06 +00:00
|
|
|
*/
|
2013-11-01 00:15:14 +00:00
|
|
|
private function _read($dataid)
|
2012-04-29 17:15:06 +00:00
|
|
|
{
|
2018-05-27 12:36:30 +00:00
|
|
|
if (!$this->_request->isJsonApiCall()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-09-27 01:03:55 +00:00
|
|
|
try {
|
|
|
|
$paste = $this->_model->getPaste($dataid);
|
2016-07-26 06:19:35 +00:00
|
|
|
if ($paste->exists()) {
|
2018-05-27 13:05:31 +00:00
|
|
|
$data = $paste->get();
|
2019-05-08 20:11:21 +00:00
|
|
|
if (array_key_exists('salt', $data['meta'])) {
|
|
|
|
unset($data['meta']['salt']);
|
2016-07-26 06:19:35 +00:00
|
|
|
}
|
2018-05-27 12:36:30 +00:00
|
|
|
$this->_return_message(0, $dataid, (array) $data);
|
2016-07-26 06:19:35 +00:00
|
|
|
} else {
|
2018-05-27 12:36:30 +00:00
|
|
|
$this->_return_message(1, self::GENERIC_ERROR);
|
2012-04-29 17:15:06 +00:00
|
|
|
}
|
2015-09-27 01:03:55 +00:00
|
|
|
} catch (Exception $e) {
|
2018-05-27 12:36:30 +00:00
|
|
|
$this->_return_message(1, $e->getMessage());
|
2015-09-01 20:33:07 +00:00
|
|
|
}
|
2012-04-29 17:15:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-07-29 13:17:35 +00:00
|
|
|
* Display frontend.
|
2012-04-29 17:15:06 +00:00
|
|
|
*
|
|
|
|
* @access private
|
|
|
|
*/
|
|
|
|
private function _view()
|
|
|
|
{
|
2016-08-09 12:46:32 +00:00
|
|
|
header('Content-Security-Policy: ' . $this->_conf->getKey('cspheader'));
|
2021-04-16 17:19:11 +00:00
|
|
|
header('Cross-Origin-Resource-Policy: same-origin');
|
|
|
|
header('Cross-Origin-Embedder-Policy: require-corp');
|
2022-08-22 11:25:56 +00:00
|
|
|
// disabled, because it prevents links from a paste to the same site to
|
|
|
|
// be opened. Didn't work with `same-origin-allow-popups` either.
|
|
|
|
// See issue https://github.com/PrivateBin/PrivateBin/issues/970 for details.
|
|
|
|
// header('Cross-Origin-Opener-Policy: same-origin');
|
2022-04-10 09:28:52 +00:00
|
|
|
header('Permissions-Policy: browsing-topics=()');
|
2019-06-27 18:31:10 +00:00
|
|
|
header('Referrer-Policy: no-referrer');
|
2016-09-18 09:29:37 +00:00
|
|
|
header('X-Content-Type-Options: nosniff');
|
2021-04-16 17:19:11 +00:00
|
|
|
header('X-Frame-Options: deny');
|
|
|
|
header('X-XSS-Protection: 1; mode=block');
|
2012-08-25 22:49:11 +00:00
|
|
|
|
2013-10-30 22:54:42 +00:00
|
|
|
// label all the expiration options
|
|
|
|
$expire = array();
|
2016-07-26 06:19:35 +00:00
|
|
|
foreach ($this->_conf->getSection('expire_options') as $time => $seconds) {
|
2016-08-15 14:45:47 +00:00
|
|
|
$expire[$time] = ($seconds == 0) ? I18n::_(ucfirst($time)) : Filter::formatHumanReadableTime($time);
|
2013-10-30 22:54:42 +00:00
|
|
|
}
|
|
|
|
|
2015-09-12 15:33:16 +00:00
|
|
|
// translate all the formatter options
|
2016-08-09 09:54:42 +00:00
|
|
|
$formatters = array_map('PrivateBin\\I18n::_', $this->_conf->getSection('formatter_options'));
|
2015-09-12 15:33:16 +00:00
|
|
|
|
2015-09-19 09:21:13 +00:00
|
|
|
// set language cookie if that functionality was enabled
|
|
|
|
$languageselection = '';
|
2016-07-26 06:19:35 +00:00
|
|
|
if ($this->_conf->getKey('languageselection')) {
|
2016-08-09 09:54:42 +00:00
|
|
|
$languageselection = I18n::getLanguage();
|
2021-04-16 18:15:12 +00:00
|
|
|
setcookie('lang', $languageselection, 0, '', '', true);
|
2015-09-19 09:21:13 +00:00
|
|
|
}
|
|
|
|
|
2022-03-13 16:24:47 +00:00
|
|
|
// strip policies that are unsupported in meta tag
|
|
|
|
$metacspheader = str_replace(
|
|
|
|
array(
|
|
|
|
'frame-ancestors \'none\'; ',
|
|
|
|
'; sandbox allow-same-origin allow-scripts allow-forms allow-popups allow-modals allow-downloads',
|
|
|
|
),
|
|
|
|
'',
|
|
|
|
$this->_conf->getKey('cspheader')
|
|
|
|
);
|
|
|
|
|
2016-08-09 09:54:42 +00:00
|
|
|
$page = new View;
|
2022-10-23 06:10:56 +00:00
|
|
|
$page->assign('CSPHEADER', $metacspheader);
|
|
|
|
$page->assign('ERROR', I18n::_($this->_error));
|
2022-10-23 11:09:54 +00:00
|
|
|
$page->assign('NAME', $this->_conf->getKey('name'));
|
2022-10-23 06:10:56 +00:00
|
|
|
if ($this->_request->getOperation() === 'yourlsproxy') {
|
|
|
|
$page->assign('SHORTURL', $this->_status);
|
|
|
|
$page->draw('yourlsproxy');
|
|
|
|
return;
|
|
|
|
}
|
2020-07-01 17:47:12 +00:00
|
|
|
$page->assign('BASEPATH', I18n::_($this->_conf->getKey('basepath')));
|
2016-08-09 09:54:42 +00:00
|
|
|
$page->assign('STATUS', I18n::_($this->_status));
|
2012-04-29 17:15:06 +00:00
|
|
|
$page->assign('VERSION', self::VERSION);
|
2015-09-22 21:21:31 +00:00
|
|
|
$page->assign('DISCUSSION', $this->_conf->getKey('discussion'));
|
|
|
|
$page->assign('OPENDISCUSSION', $this->_conf->getKey('opendiscussion'));
|
2015-09-12 15:33:16 +00:00
|
|
|
$page->assign('MARKDOWN', array_key_exists('markdown', $formatters));
|
|
|
|
$page->assign('SYNTAXHIGHLIGHTING', array_key_exists('syntaxhighlighting', $formatters));
|
2015-09-22 21:21:31 +00:00
|
|
|
$page->assign('SYNTAXHIGHLIGHTINGTHEME', $this->_conf->getKey('syntaxhighlightingtheme'));
|
2015-09-12 15:33:16 +00:00
|
|
|
$page->assign('FORMATTER', $formatters);
|
2015-09-22 21:21:31 +00:00
|
|
|
$page->assign('FORMATTERDEFAULT', $this->_conf->getKey('defaultformatter'));
|
2020-10-13 05:28:35 +00:00
|
|
|
$page->assign('INFO', I18n::_(str_replace("'", '"', $this->_conf->getKey('info'))));
|
2016-08-09 09:54:42 +00:00
|
|
|
$page->assign('NOTICE', I18n::_($this->_conf->getKey('notice')));
|
2015-09-22 21:21:31 +00:00
|
|
|
$page->assign('BURNAFTERREADINGSELECTED', $this->_conf->getKey('burnafterreadingselected'));
|
|
|
|
$page->assign('PASSWORD', $this->_conf->getKey('password'));
|
|
|
|
$page->assign('FILEUPLOAD', $this->_conf->getKey('fileupload'));
|
2016-08-16 09:11:03 +00:00
|
|
|
$page->assign('ZEROBINCOMPATIBILITY', $this->_conf->getKey('zerobincompatibility'));
|
2015-09-19 09:21:13 +00:00
|
|
|
$page->assign('LANGUAGESELECTION', $languageselection);
|
2016-08-09 09:54:42 +00:00
|
|
|
$page->assign('LANGUAGES', I18n::getLanguageLabels(I18n::getAvailableLanguages()));
|
2013-10-30 22:54:42 +00:00
|
|
|
$page->assign('EXPIRE', $expire);
|
2015-09-22 21:21:31 +00:00
|
|
|
$page->assign('EXPIREDEFAULT', $this->_conf->getKey('default', 'expire'));
|
2016-01-31 08:56:06 +00:00
|
|
|
$page->assign('URLSHORTENER', $this->_conf->getKey('urlshortener'));
|
2017-12-25 13:59:15 +00:00
|
|
|
$page->assign('QRCODE', $this->_conf->getKey('qrcode'));
|
2023-09-09 20:26:11 +00:00
|
|
|
$page->assign('EMAIL', $this->_conf->getKey('email'));
|
2019-06-17 19:40:37 +00:00
|
|
|
$page->assign('HTTPWARNING', $this->_conf->getKey('httpwarning'));
|
2019-09-19 17:14:48 +00:00
|
|
|
$page->assign('HTTPSLINK', 'https://' . $this->_request->getHost() . $this->_request->getRequestUri());
|
2019-06-23 17:45:40 +00:00
|
|
|
$page->assign('COMPRESSION', $this->_conf->getKey('compression'));
|
2015-09-22 21:21:31 +00:00
|
|
|
$page->draw($this->_conf->getKey('template'));
|
2012-04-29 17:15:06 +00:00
|
|
|
}
|
|
|
|
|
2015-10-18 18:38:07 +00:00
|
|
|
/**
|
|
|
|
* outputs requested JSON-LD context
|
|
|
|
*
|
|
|
|
* @access private
|
|
|
|
* @param string $type
|
|
|
|
*/
|
2015-10-18 12:37:58 +00:00
|
|
|
private function _jsonld($type)
|
|
|
|
{
|
2023-01-15 07:04:21 +00:00
|
|
|
if (!in_array($type, array(
|
|
|
|
'comment',
|
|
|
|
'commentmeta',
|
|
|
|
'paste',
|
|
|
|
'pastemeta',
|
|
|
|
'types',
|
|
|
|
))) {
|
2015-10-18 12:37:58 +00:00
|
|
|
$type = '';
|
|
|
|
}
|
|
|
|
$content = '{}';
|
2016-08-15 14:45:47 +00:00
|
|
|
$file = PUBLIC_PATH . DIRECTORY_SEPARATOR . 'js' . DIRECTORY_SEPARATOR . $type . '.jsonld';
|
2016-07-26 06:19:35 +00:00
|
|
|
if (is_readable($file)) {
|
2015-10-18 12:37:58 +00:00
|
|
|
$content = str_replace(
|
|
|
|
'?jsonld=',
|
2016-08-09 09:54:42 +00:00
|
|
|
$this->_urlBase . '?jsonld=',
|
2015-10-18 12:37:58 +00:00
|
|
|
file_get_contents($file)
|
|
|
|
);
|
|
|
|
}
|
2023-01-15 07:04:21 +00:00
|
|
|
if ($type === 'types') {
|
|
|
|
$content = str_replace(
|
2023-01-15 13:45:10 +00:00
|
|
|
implode('", "', array_keys($this->_conf->getDefaults()['expire_options'])),
|
|
|
|
implode('", "', array_keys($this->_conf->getSection('expire_options'))),
|
2023-01-15 07:04:21 +00:00
|
|
|
$content
|
|
|
|
);
|
|
|
|
}
|
2015-10-18 12:37:58 +00:00
|
|
|
|
|
|
|
header('Content-type: application/ld+json');
|
|
|
|
header('Access-Control-Allow-Origin: *');
|
|
|
|
header('Access-Control-Allow-Methods: GET');
|
|
|
|
echo $content;
|
|
|
|
}
|
|
|
|
|
2022-10-23 06:10:56 +00:00
|
|
|
/**
|
|
|
|
* proxies link to YOURLS, updates status or error with response
|
|
|
|
*
|
|
|
|
* @access private
|
|
|
|
* @param string $link
|
|
|
|
*/
|
|
|
|
private function _yourlsproxy($link)
|
|
|
|
{
|
|
|
|
$yourls = new YourlsProxy($this->_conf, $link);
|
|
|
|
if ($yourls->isError()) {
|
|
|
|
$this->_error = $yourls->getError();
|
|
|
|
} else {
|
|
|
|
$this->_status = $yourls->getUrl();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-29 17:15:06 +00:00
|
|
|
/**
|
2015-10-18 18:38:07 +00:00
|
|
|
* prepares JSON encoded status message
|
2012-04-29 17:15:06 +00:00
|
|
|
*
|
|
|
|
* @access private
|
2016-07-06 12:12:14 +00:00
|
|
|
* @param int $status
|
2012-04-29 17:15:06 +00:00
|
|
|
* @param string $message
|
2013-11-01 00:15:14 +00:00
|
|
|
* @param array $other
|
2012-04-29 17:15:06 +00:00
|
|
|
*/
|
2013-11-01 00:15:14 +00:00
|
|
|
private function _return_message($status, $message, $other = array())
|
2012-04-29 17:15:06 +00:00
|
|
|
{
|
|
|
|
$result = array('status' => $status);
|
2016-07-26 06:19:35 +00:00
|
|
|
if ($status) {
|
2016-08-09 09:54:42 +00:00
|
|
|
$result['message'] = I18n::_($message);
|
2016-07-26 06:19:35 +00:00
|
|
|
} else {
|
2016-08-15 14:45:47 +00:00
|
|
|
$result['id'] = $message;
|
2016-08-09 09:54:42 +00:00
|
|
|
$result['url'] = $this->_urlBase . '?' . $message;
|
2012-04-29 17:15:06 +00:00
|
|
|
}
|
2013-11-01 00:15:14 +00:00
|
|
|
$result += $other;
|
2019-05-13 20:31:52 +00:00
|
|
|
$this->_json = Json::encode($result);
|
2012-04-29 17:15:06 +00:00
|
|
|
}
|
|
|
|
}
|