1<?php
2if(!defined('DOKU_INC')) define('DOKU_INC',dirname(__FILE__).'/../../../');
3
4require_once(DOKU_INC.'inc/init.php');
5session_write_close();  //close session
6
7try {
8    /** @var \helper_plugin_telleveryone_db $db_helper */
9    $db_helper = plugin_load('helper', 'telleveryone_db');
10    $sqlite = $db_helper->getDB();
11} catch (Exception $e) {
12    http_response_code(500);
13    exit;
14}
15
16$res = $sqlite->query("SELECT value FROM config WHERE key='token'");
17if ($sqlite->res2single($res) != $INPUT->str('token')) {
18    http_response_code(403);
19    exit;
20}
21
22$res = $sqlite->query('SELECT id, timestamp, user, message_html FROM log
23                                ORDER BY timestamp DESC LIMIT ?', $INPUT->int('limit', -1));
24$arr = $sqlite->res2arr($res);
25
26echo json_encode($arr);
27