| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
namespace Liuch\DmarcSrg; |
| 46 |
|
| 47 |
use Liuch\DmarcSrg\Users\User; |
| 48 |
use Liuch\DmarcSrg\ReportLog\ReportLog; |
| 49 |
use Liuch\DmarcSrg\ReportLog\ReportLogItem; |
| 50 |
use Liuch\DmarcSrg\Settings\SettingsList; |
| 51 |
use Liuch\DmarcSrg\Exception\RuntimeException; |
| 52 |
|
| 53 |
require realpath(__DIR__ . '/..') . '/init.php'; |
| 54 |
|
| 55 |
if (Core::requestMethod() == "GET") { |
| 56 |
if (Core::isJson()) { |
| 57 |
try { |
| 58 |
Core::instance()->auth()->isAllowed(User::LEVEL_ADMIN); |
| 59 |
|
| 60 |
if (isset($_GET['id'])) { |
| 61 |
Core::sendJson(ReportLogItem::byId(intval($_GET['id']))->toArray()); |
| 62 |
return; |
| 63 |
} |
| 64 |
|
| 65 |
$pos = $_GET['position'] ?? 0; |
| 66 |
$dir = $_GET['direction'] ?? ''; |
| 67 |
if (empty($dir)) { |
| 68 |
$o_set = explode(',', SettingsList::getSettingByName('log-view.sort-list-by')->value()); |
| 69 |
if ($o_set[0] === 'event_time') { |
| 70 |
$dir = $o_set[1]; |
| 71 |
} |
| 72 |
} |
| 73 |
if ($dir !== 'ascent') { |
| 74 |
$dir = 'descent'; |
| 75 |
} |
| 76 |
|
| 77 |
$log = new ReportLog(); |
| 78 |
if (($filter = Common::getFilter())) { |
| 79 |
if (isset($filter['success'])) { |
| 80 |
$filter['success'] = $filter['success'] === 'true' ? true : false; |
| 81 |
} |
| 82 |
foreach ([ 'from_time', 'till_time' ] as $k) { |
| 83 |
if (isset($filter[$k])) { |
| 84 |
if (($d = DateTime::createFromFormat('!Y-m-d', $filter[$k]))) { |
| 85 |
$filter[$k] = $d; |
| 86 |
} else { |
| 87 |
unset($filter[$k]); |
| 88 |
} |
| 89 |
} |
| 90 |
} |
| 91 |
$log->setFilter($filter); |
| 92 |
} |
| 93 |
$log->setOrder($dir === 'ascent' ? ReportLog::ORDER_ASCENT : ReportLog::ORDER_DESCENT); |
| 94 |
$res = $log->getList($pos); |
| 95 |
$res['sorted_by'] = [ 'column' => 'event_time', 'direction' => $dir ]; |
| 96 |
Core::sendJson($res); |
| 97 |
return; |
| 98 |
} catch (RuntimeException $e) { |
| 99 |
Core::sendJson(ErrorHandler::exceptionResult($e)); |
| 100 |
return; |
| 101 |
} |
| 102 |
} else { |
| 103 |
Core::instance()->sendHtml(); |
| 104 |
return; |
| 105 |
} |
| 106 |
} |
| 107 |
|
| 108 |
Core::sendBad(); |