zerobin.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734
  1. <?php
  2. /**
  3. * ZeroBin
  4. *
  5. * a zero-knowledge paste bin
  6. *
  7. * @link http://sebsauvage.net/wiki/doku.php?id=php:zerobin
  8. * @copyright 2012 Sébastien SAUVAGE (sebsauvage.net)
  9. * @license http://www.opensource.org/licenses/zlib-license.php The zlib/libpng License
  10. * @version 0.20
  11. */
  12. /**
  13. * zerobin
  14. *
  15. * Controller, puts it all together.
  16. */
  17. class zerobin
  18. {
  19. /**
  20. * version
  21. *
  22. * @const string
  23. */
  24. const VERSION = '0.20';
  25. /**
  26. * show the same error message if the paste expired or does not exist
  27. *
  28. * @const string
  29. */
  30. const GENERIC_ERROR = 'Paste does not exist, has expired or has been deleted.';
  31. /**
  32. * configuration array
  33. *
  34. * @access private
  35. * @var array
  36. */
  37. private $_conf = array(
  38. 'model' => 'zerobin_data',
  39. );
  40. /**
  41. * data
  42. *
  43. * @access private
  44. * @var string
  45. */
  46. private $_data = '';
  47. /**
  48. * formatter
  49. *
  50. * @access private
  51. * @var string
  52. */
  53. private $_formatter = 'plaintext';
  54. /**
  55. * error message
  56. *
  57. * @access private
  58. * @var string
  59. */
  60. private $_error = '';
  61. /**
  62. * status message
  63. *
  64. * @access private
  65. * @var string
  66. */
  67. private $_status = '';
  68. /**
  69. * JSON message
  70. *
  71. * @access private
  72. * @var string
  73. */
  74. private $_json = '';
  75. /**
  76. * data storage model
  77. *
  78. * @access private
  79. * @var zerobin_abstract
  80. */
  81. private $_model;
  82. /**
  83. * constructor
  84. *
  85. * initializes and runs ZeroBin
  86. *
  87. * @access public
  88. * @return void
  89. */
  90. public function __construct()
  91. {
  92. if (version_compare(PHP_VERSION, '5.2.6') < 0)
  93. {
  94. throw new Exception(i18n::_('ZeroBin requires php 5.2.6 or above to work. Sorry.'), 1);
  95. }
  96. // in case stupid admin has left magic_quotes enabled in php.ini
  97. if (get_magic_quotes_gpc())
  98. {
  99. $_POST = array_map('filter::stripslashes_deep', $_POST);
  100. $_GET = array_map('filter::stripslashes_deep', $_GET);
  101. $_COOKIE = array_map('filter::stripslashes_deep', $_COOKIE);
  102. }
  103. // load config from ini file
  104. $this->_init();
  105. // create new paste or comment
  106. if (
  107. (array_key_exists('data', $_POST) && !empty($_POST['data'])) ||
  108. (array_key_exists('attachment', $_POST) && !empty($_POST['attachment']))
  109. )
  110. {
  111. $this->_create();
  112. }
  113. // delete an existing paste
  114. elseif (!empty($_GET['deletetoken']) && !empty($_GET['pasteid']))
  115. {
  116. $this->_delete($_GET['pasteid'], $_GET['deletetoken']);
  117. }
  118. // display an existing paste
  119. elseif (!empty($_SERVER['QUERY_STRING']))
  120. {
  121. $this->_read($_SERVER['QUERY_STRING']);
  122. }
  123. // output JSON or HTML
  124. if (strlen($this->_json))
  125. {
  126. header('Content-type: application/json');
  127. echo $this->_json;
  128. }
  129. else
  130. {
  131. $this->_view();
  132. }
  133. }
  134. /**
  135. * initialize zerobin
  136. *
  137. * @access private
  138. * @return void
  139. */
  140. private function _init()
  141. {
  142. foreach (array('cfg', 'lib') as $dir)
  143. {
  144. if (!is_file(PATH . $dir . DIRECTORY_SEPARATOR . '.htaccess')) file_put_contents(
  145. PATH . $dir . DIRECTORY_SEPARATOR . '.htaccess',
  146. 'Allow from none' . PHP_EOL .
  147. 'Deny from all'. PHP_EOL,
  148. LOCK_EX
  149. );
  150. }
  151. $this->_conf = parse_ini_file(PATH . 'cfg' . DIRECTORY_SEPARATOR . 'conf.ini', true);
  152. foreach (array('main', 'model') as $section) {
  153. if (!array_key_exists($section, $this->_conf)) {
  154. throw new Exception(i18n::_('ZeroBin requires configuration section [%s] to be present in configuration file.', $section), 2);
  155. }
  156. }
  157. $this->_model = $this->_conf['model']['class'];
  158. }
  159. /**
  160. * get the model, create one if needed
  161. *
  162. * @access private
  163. * @return zerobin_abstract
  164. */
  165. private function _model()
  166. {
  167. // if needed, initialize the model
  168. if(is_string($this->_model)) {
  169. $this->_model = forward_static_call(
  170. array($this->_model, 'getInstance'),
  171. $this->_conf['model_options']
  172. );
  173. }
  174. return $this->_model;
  175. }
  176. /**
  177. * Store new paste or comment
  178. *
  179. * POST contains one or both:
  180. * data = json encoded SJCL encrypted text (containing keys: iv,v,iter,ks,ts,mode,adata,cipher,salt,ct)
  181. * attachment = json encoded SJCL encrypted text (containing keys: iv,v,iter,ks,ts,mode,adata,cipher,salt,ct)
  182. *
  183. * All optional data will go to meta information:
  184. * expire (optional) = expiration delay (never,5min,10min,1hour,1day,1week,1month,1year,burn) (default:never)
  185. * formatter (optional) = format to display the paste as (plaintext,syntaxhighlighting,markdown) (default:syntaxhighlighting)
  186. * burnafterreading (optional) = if this paste may only viewed once ? (0/1) (default:0)
  187. * opendiscusssion (optional) = is the discussion allowed on this paste ? (0/1) (default:0)
  188. * nickname (optional) = in discussion, encoded SJCL encrypted text nickname of author of comment (containing keys: iv,v,iter,ks,ts,mode,adata,cipher,salt,ct)
  189. * parentid (optional) = in discussion, which comment this comment replies to.
  190. * pasteid (optional) = in discussion, which paste this comment belongs to.
  191. *
  192. * @access private
  193. * @return string
  194. */
  195. private function _create()
  196. {
  197. $error = false;
  198. $has_attachment = array_key_exists('attachment', $_POST);
  199. $has_attachmentname = $has_attachment && array_key_exists('attachmentname', $_POST) && !empty($_POST['attachmentname']);
  200. $data = array_key_exists('data', $_POST) ? $_POST['data'] : '';
  201. $attachment = $has_attachment ? $_POST['attachment'] : '';
  202. $attachmentname = $has_attachmentname ? $_POST['attachmentname'] : '';
  203. // Make sure last paste from the IP address was more than X seconds ago.
  204. trafficlimiter::setLimit($this->_conf['traffic']['limit']);
  205. trafficlimiter::setPath($this->_conf['traffic']['dir']);
  206. $ipKey = 'REMOTE_ADDR';
  207. if (array_key_exists('header', $this->_conf['traffic']))
  208. {
  209. $header = 'HTTP_' . $this->_conf['traffic']['header'];
  210. if (array_key_exists($header, $_SERVER) && !empty($_SERVER[$header]))
  211. {
  212. $ipKey = $header;
  213. }
  214. }
  215. if (!trafficlimiter::canPass($_SERVER[$ipKey]))
  216. {
  217. $this->_return_message(
  218. 1,
  219. i18n::_(
  220. 'Please wait %d seconds between each post.',
  221. $this->_conf['traffic']['limit']
  222. )
  223. );
  224. return;
  225. }
  226. // Make sure content is not too big.
  227. $sizelimit = (int) $this->_getMainConfig('sizelimit', 2097152);
  228. if (strlen($data) + strlen($attachment) + strlen($attachmentname) > $sizelimit)
  229. {
  230. $this->_return_message(
  231. 1,
  232. i18n::_(
  233. 'Paste is limited to %s of encrypted data.',
  234. filter::size_humanreadable($sizelimit)
  235. )
  236. );
  237. return;
  238. }
  239. // Make sure format is correct.
  240. if (!sjcl::isValid($data)) return $this->_return_message(1, 'Invalid data.');
  241. // Make sure attachments are enabled and format is correct.
  242. if($has_attachment)
  243. {
  244. if (
  245. !$this->_getMainConfig('fileupload', false) ||
  246. !sjcl::isValid($attachment) ||
  247. !($has_attachmentname && sjcl::isValid($attachmentname))
  248. ) $this->_return_message(1, 'Invalid attachment.');
  249. }
  250. // Read additional meta-information.
  251. $meta = array();
  252. // Read expiration date
  253. if (array_key_exists('expire', $_POST) && !empty($_POST['expire']))
  254. {
  255. $selected_expire = (string) $_POST['expire'];
  256. if (array_key_exists($selected_expire, $this->_conf['expire_options']))
  257. {
  258. $expire = $this->_conf['expire_options'][$selected_expire];
  259. }
  260. else
  261. {
  262. $expire = $this->_conf['expire_options'][$this->_conf['expire']['default']];
  263. }
  264. if ($expire > 0) $meta['expire_date'] = time() + $expire;
  265. }
  266. // Destroy the paste when it is read.
  267. if (array_key_exists('burnafterreading', $_POST) && !empty($_POST['burnafterreading']))
  268. {
  269. $burnafterreading = $_POST['burnafterreading'];
  270. if ($burnafterreading !== '0')
  271. {
  272. if ($burnafterreading !== '1') $error = true;
  273. $meta['burnafterreading'] = true;
  274. }
  275. }
  276. // Read open discussion flag.
  277. if (
  278. $this->_getMainConfig('discussion', true) &&
  279. array_key_exists('opendiscussion', $_POST) &&
  280. !empty($_POST['opendiscussion'])
  281. )
  282. {
  283. $opendiscussion = $_POST['opendiscussion'];
  284. if ($opendiscussion !== '0')
  285. {
  286. if ($opendiscussion !== '1') $error = true;
  287. $meta['opendiscussion'] = true;
  288. }
  289. }
  290. // Read formatter flag.
  291. if (array_key_exists('formatter', $_POST) && !empty($_POST['formatter']))
  292. {
  293. $formatter = $_POST['formatter'];
  294. if (!array_key_exists($formatter, $this->_conf['formatter_options']))
  295. {
  296. $formatter = $this->_getMainConfig('defaultformatter', 'syntaxhighlighting');
  297. }
  298. $meta['formatter'] = $formatter;
  299. }
  300. // You can't have an open discussion on a "Burn after reading" paste:
  301. if (isset($meta['burnafterreading'])) unset($meta['opendiscussion']);
  302. // Optional nickname for comments
  303. if (!empty($_POST['nickname']))
  304. {
  305. // Generation of the anonymous avatar (Vizhash):
  306. // If a nickname is provided, we generate a Vizhash.
  307. // (We assume that if the user did not enter a nickname, he/she wants
  308. // to be anonymous and we will not generate the vizhash.)
  309. $nick = $_POST['nickname'];
  310. if (!sjcl::isValid($nick))
  311. {
  312. $error = true;
  313. }
  314. else
  315. {
  316. $meta['nickname'] = $nick;
  317. $vz = new vizhash16x16();
  318. $pngdata = $vz->generate($_SERVER['REMOTE_ADDR']);
  319. if ($pngdata != '')
  320. {
  321. $meta['vizhash'] = 'data:image/png;base64,' . base64_encode($pngdata);
  322. }
  323. // Once the avatar is generated, we do not keep the IP address, nor its hash.
  324. }
  325. }
  326. if ($error)
  327. {
  328. $this->_return_message(1, 'Invalid data.');
  329. return;
  330. }
  331. // Add post date to meta.
  332. $meta['postdate'] = time();
  333. // We just want a small hash to avoid collisions:
  334. // Half-MD5 (64 bits) will do the trick
  335. $dataid = substr(hash('md5', $data), 0, 16);
  336. $storage = array('data' => $data);
  337. // Add meta-information only if necessary.
  338. if (count($meta)) $storage['meta'] = $meta;
  339. // The user posts a comment.
  340. if (
  341. !empty($_POST['parentid']) &&
  342. !empty($_POST['pasteid'])
  343. )
  344. {
  345. $pasteid = (string) $_POST['pasteid'];
  346. $parentid = (string) $_POST['parentid'];
  347. if (
  348. !filter::is_valid_paste_id($pasteid) ||
  349. !filter::is_valid_paste_id($parentid)
  350. )
  351. {
  352. $this->_return_message(1, 'Invalid data.');
  353. return;
  354. }
  355. // Comments do not expire (it's the paste that expires)
  356. unset($storage['expire_date']);
  357. unset($storage['opendiscussion']);
  358. // Make sure paste exists.
  359. if (
  360. !$this->_model()->exists($pasteid)
  361. )
  362. {
  363. $this->_return_message(1, 'Invalid data.');
  364. return;
  365. }
  366. // Make sure the discussion is opened in this paste.
  367. $paste = $this->_model()->read($pasteid);
  368. if (
  369. !$paste->meta->opendiscussion
  370. )
  371. {
  372. $this->_return_message(1, 'Invalid data.');
  373. return;
  374. }
  375. // Check for improbable collision.
  376. if (
  377. $this->_model()->existsComment($pasteid, $parentid, $dataid)
  378. )
  379. {
  380. $this->_return_message(1, 'You are unlucky. Try again.');
  381. return;
  382. }
  383. // New comment
  384. if (
  385. $this->_model()->createComment($pasteid, $parentid, $dataid, $storage) === false
  386. )
  387. {
  388. $this->_return_message(1, 'Error saving comment. Sorry.');
  389. return;
  390. }
  391. // 0 = no error
  392. $this->_return_message(0, $dataid);
  393. return;
  394. }
  395. // The user posts a standard paste.
  396. else
  397. {
  398. // Check for improbable collision.
  399. if (
  400. $this->_model()->exists($dataid)
  401. )
  402. {
  403. $this->_return_message(1, 'You are unlucky. Try again.');
  404. return;
  405. }
  406. // Add attachment and its name, if one was sent
  407. if ($has_attachment) $storage['attachment'] = $attachment;
  408. if ($has_attachmentname) $storage['attachmentname'] = $attachmentname;
  409. // New paste
  410. if (
  411. $this->_model()->create($dataid, $storage) === false
  412. ) {
  413. $this->_return_message(1, 'Error saving paste. Sorry.');
  414. return;
  415. }
  416. // Generate the "delete" token.
  417. // The token is the hmac of the pasteid signed with the server salt.
  418. // The paste can be delete by calling http://example.com/zerobin/?pasteid=<pasteid>&deletetoken=<deletetoken>
  419. $deletetoken = hash_hmac('sha1', $dataid, serversalt::get());
  420. // 0 = no error
  421. $this->_return_message(0, $dataid, array('deletetoken' => $deletetoken));
  422. return;
  423. }
  424. }
  425. /**
  426. * Delete an existing paste
  427. *
  428. * @access private
  429. * @param string $dataid
  430. * @param string $deletetoken
  431. * @return void
  432. */
  433. private function _delete($dataid, $deletetoken)
  434. {
  435. // Is this a valid paste identifier?
  436. if (!filter::is_valid_paste_id($dataid))
  437. {
  438. $this->_error = 'Invalid paste ID.';
  439. return;
  440. }
  441. // Check that paste exists.
  442. if (!$this->_model()->exists($dataid))
  443. {
  444. $this->_error = self::GENERIC_ERROR;
  445. return;
  446. }
  447. // Get the paste itself.
  448. $paste = $this->_model()->read($dataid);
  449. // See if paste has expired.
  450. if (
  451. isset($paste->meta->expire_date) &&
  452. $paste->meta->expire_date < time()
  453. )
  454. {
  455. // Delete the paste
  456. $this->_model()->delete($dataid);
  457. $this->_error = self::GENERIC_ERROR;
  458. return;
  459. }
  460. if ($deletetoken == 'burnafterreading') {
  461. if (
  462. isset($paste->meta->burnafterreading) &&
  463. $paste->meta->burnafterreading
  464. )
  465. {
  466. // Delete the paste
  467. $this->_model()->delete($dataid);
  468. $this->_return_message(0, $dataid);
  469. }
  470. else
  471. {
  472. $this->_return_message(1, 'Paste is not of burn-after-reading type.');
  473. }
  474. return;
  475. }
  476. // Make sure token is valid.
  477. serversalt::setPath($this->_conf['traffic']['dir']);
  478. if (!filter::slow_equals($deletetoken, hash_hmac('sha1', $dataid, serversalt::get())))
  479. {
  480. $this->_error = 'Wrong deletion token. Paste was not deleted.';
  481. return;
  482. }
  483. // Paste exists and deletion token is valid: Delete the paste.
  484. $this->_model()->delete($dataid);
  485. $this->_status = 'Paste was properly deleted.';
  486. }
  487. /**
  488. * Read an existing paste or comment
  489. *
  490. * @access private
  491. * @param string $dataid
  492. * @return void
  493. */
  494. private function _read($dataid)
  495. {
  496. $isJson = false;
  497. if (($pos = strpos($dataid, '&json')) !== false) {
  498. $isJson = true;
  499. $dataid = substr($dataid, 0, $pos);
  500. }
  501. // Is this a valid paste identifier?
  502. if (!filter::is_valid_paste_id($dataid))
  503. {
  504. $this->_error = 'Invalid paste ID.';
  505. return;
  506. }
  507. // Check that paste exists.
  508. if ($this->_model()->exists($dataid))
  509. {
  510. // Get the paste itself.
  511. $paste = $this->_model()->read($dataid);
  512. // See if paste has expired.
  513. if (
  514. isset($paste->meta->expire_date) &&
  515. $paste->meta->expire_date < time()
  516. )
  517. {
  518. // Delete the paste
  519. $this->_model()->delete($dataid);
  520. $this->_error = self::GENERIC_ERROR;
  521. }
  522. // If no error, return the paste.
  523. else
  524. {
  525. // We kindly provide the remaining time before expiration (in seconds)
  526. if (
  527. property_exists($paste->meta, 'expire_date')
  528. ) $paste->meta->remaining_time = $paste->meta->expire_date - time();
  529. // The paste itself is the first in the list of encrypted messages.
  530. $messages = array($paste);
  531. // If it's a discussion, get all comments.
  532. if (
  533. property_exists($paste->meta, 'opendiscussion') &&
  534. $paste->meta->opendiscussion
  535. )
  536. {
  537. $messages = array_merge(
  538. $messages,
  539. $this->_model()->readComments($dataid)
  540. );
  541. }
  542. // set formatter for for the view.
  543. if (!property_exists($paste->meta, 'formatter'))
  544. {
  545. // support < 0.21 syntax highlighting
  546. if (property_exists($paste->meta, 'syntaxcoloring') && $paste->meta->syntaxcoloring === true)
  547. {
  548. $paste->meta->formatter = 'syntaxhighlighting';
  549. }
  550. else
  551. {
  552. $paste->meta->formatter = $this->_getMainConfig('defaultformatter', 'syntaxhighlighting');
  553. }
  554. }
  555. $this->_data = json_encode($messages);
  556. }
  557. }
  558. else
  559. {
  560. $this->_error = self::GENERIC_ERROR;
  561. }
  562. if ($isJson)
  563. {
  564. if (strlen($this->_error))
  565. {
  566. $this->_return_message(1, $this->_error);
  567. }
  568. else
  569. {
  570. $this->_return_message(0, $dataid, array('messages' => $messages));
  571. }
  572. }
  573. }
  574. /**
  575. * Display ZeroBin frontend.
  576. *
  577. * @access private
  578. * @return void
  579. */
  580. private function _view()
  581. {
  582. // set headers to disable caching
  583. $time = gmdate('D, d M Y H:i:s \G\M\T');
  584. header('Cache-Control: no-store, no-cache, must-revalidate');
  585. header('Pragma: no-cache');
  586. header('Expires: ' . $time);
  587. header('Last-Modified: ' . $time);
  588. header('Vary: Accept');
  589. // label all the expiration options
  590. $expire = array();
  591. foreach ($this->_conf['expire_options'] as $time => $seconds)
  592. {
  593. $expire[$time] = ($seconds == 0) ? i18n::_(ucfirst($time)): filter::time_humanreadable($time);
  594. }
  595. // translate all the formatter options
  596. $formatters = array_map(array('i18n', 'translate'), $this->_conf['formatter_options']);
  597. // set language cookie if that functionality was enabled
  598. $languageselection = '';
  599. if ($this->_getMainConfig('languageselection', false))
  600. {
  601. $languageselection = i18n::getLanguage();
  602. setcookie('lang', $languageselection);
  603. }
  604. $page = new RainTPL;
  605. $page::$path_replace = false;
  606. // we escape it here because ENT_NOQUOTES can't be used in RainTPL templates
  607. $page->assign('CIPHERDATA', htmlspecialchars($this->_data, ENT_NOQUOTES));
  608. $page->assign('ERROR', i18n::_($this->_error));
  609. $page->assign('STATUS', i18n::_($this->_status));
  610. $page->assign('VERSION', self::VERSION);
  611. $page->assign('DISCUSSION', $this->_getMainConfig('discussion', true));
  612. $page->assign('OPENDISCUSSION', $this->_getMainConfig('opendiscussion', true));
  613. $page->assign('MARKDOWN', array_key_exists('markdown', $formatters));
  614. $page->assign('SYNTAXHIGHLIGHTING', array_key_exists('syntaxhighlighting', $formatters));
  615. $page->assign('SYNTAXHIGHLIGHTINGTHEME', $this->_getMainConfig('syntaxhighlightingtheme', ''));
  616. $page->assign('FORMATTER', $formatters);
  617. $page->assign('FORMATTERDEFAULT', $this->_getMainConfig('defaultformatter', 'syntaxhighlighting'));
  618. $page->assign('NOTICE', i18n::_($this->_getMainConfig('notice', '')));
  619. $page->assign('BURNAFTERREADINGSELECTED', $this->_getMainConfig('burnafterreadingselected', false));
  620. $page->assign('PASSWORD', $this->_getMainConfig('password', true));
  621. $page->assign('FILEUPLOAD', $this->_getMainConfig('fileupload', false));
  622. $page->assign('BASE64JSVERSION', $this->_getMainConfig('base64version', '2.1.9'));
  623. $page->assign('LANGUAGESELECTION', $languageselection);
  624. $page->assign('LANGUAGES', i18n::getLanguageLabels(i18n::getAvailableLanguages()));
  625. $page->assign('EXPIRE', $expire);
  626. $page->assign('EXPIREDEFAULT', $this->_conf['expire']['default']);
  627. $page->draw($this->_getMainConfig('template', 'page'));
  628. }
  629. /**
  630. * get configuration option from [main] section, optionally set a default
  631. *
  632. * @access private
  633. * @param string $option
  634. * @param mixed $default (optional)
  635. * @return mixed
  636. */
  637. private function _getMainConfig($option, $default = false)
  638. {
  639. return array_key_exists($option, $this->_conf['main']) ?
  640. $this->_conf['main'][$option] :
  641. $default;
  642. }
  643. /**
  644. * return JSON encoded message and exit
  645. *
  646. * @access private
  647. * @param bool $status
  648. * @param string $message
  649. * @param array $other
  650. * @return void
  651. */
  652. private function _return_message($status, $message, $other = array())
  653. {
  654. $result = array('status' => $status);
  655. if ($status)
  656. {
  657. $result['message'] = i18n::_($message);
  658. }
  659. else
  660. {
  661. $result['id'] = $message;
  662. }
  663. $result += $other;
  664. $this->_json = json_encode($result);
  665. }
  666. }