. * * ========================= * * This script returns the log items * * HTTP GET query: * When the header 'Accept' is 'application/json': * It returns the item specified in the GET parameter `id` if specified. The parameter must contain integer value. * Otherwise it returns a list of the log items. The request may have the following GET parameters: * `position` integer The position from which the list will be returned. The default value is 0. * `direction` string The sort direction. Can be one of the following values: `ascent`, `descent'. * The default value is `ascent`. The list will be sorted by Event time. * The data will be returned in json format. * Otherwise: * It returns the content of the index.html file. * Other HTTP methods: * It returns an error. * * @category Web * @package DmarcSrg * @author Aleksey Andreev (liuch) * @license https://www.gnu.org/licenses/gpl-3.0.html GNU/GPLv3 */ namespace Liuch\DmarcSrg; use Liuch\DmarcSrg\ErrorHandler; use Liuch\DmarcSrg\ReportLog\ReportLog; use Liuch\DmarcSrg\ReportLog\ReportLogItem; use Liuch\DmarcSrg\Settings\SettingsList; use Liuch\DmarcSrg\Exception\RuntimeException; require 'init.php'; if (Core::method() == "GET") { if (Core::isJson()) { try { Core::instance()->auth()->isAllowed(); if (isset($_GET['id'])) { return Core::sendJson(ReportLogItem::byId(intval($_GET['id']))->toArray()); } $pos = $_GET['position'] ?? 0; $dir = $_GET['direction'] ?? ''; if (empty($dir)) { $o_set = explode(',', SettingsList::getSettingByName('log-view.sort-list-by')->value()); if ($o_set[0] === 'event_time') { $dir = $o_set[1]; } } if ($dir !== 'ascent') { $dir = 'descent'; } $log = new ReportLog(null, null); $log->setOrder($dir === 'ascent' ? ReportLog::ORDER_ASCENT : ReportLog::ORDER_DESCENT); $res = $log->getList($pos); $res['sorted_by'] = [ 'column' => 'event_time', 'direction' => $dir ]; Core::sendJson($res); return; } catch (RuntimeException $e) { Core::sendJson(ErrorHandler::exceptionResult($e)); return; } } else { Core::sendHtml(); return; } } Core::sendBad();