| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
namespace Liuch\DmarcSrg; |
| 24 |
|
| 25 |
use Liuch\DmarcSrg\Users\User; |
| 26 |
use Liuch\DmarcSrg\Domains\Domain; |
| 27 |
use Liuch\DmarcSrg\Report\Report; |
| 28 |
use Liuch\DmarcSrg\Exception\SoftException; |
| 29 |
use Liuch\DmarcSrg\Exception\RuntimeException; |
| 30 |
|
| 31 |
require realpath(__DIR__ . '/..') . '/init.php'; |
| 32 |
|
| 33 |
if (!empty($_GET['org']) && !empty($_GET['time']) && !empty($_GET['domain']) && !empty($_GET['report_id'])) { |
| 34 |
if (Core::isJson()) { |
| 35 |
try { |
| 36 |
$core = Core::instance(); |
| 37 |
$core->auth()->isAllowed(User::LEVEL_USER); |
| 38 |
|
| 39 |
$domain = new Domain($_GET['domain']); |
| 40 |
$dom_ex = $domain->isAssigned($core->getCurrentUser()) ? null : new SoftException('Report not found'); |
| 41 |
|
| 42 |
$ts = null; |
| 43 |
try { |
| 44 |
$ts = new DateTime($_GET['time']); |
| 45 |
} catch (\Exception $e) { |
| 46 |
throw new SoftException('Incorrect timestamp'); |
| 47 |
} |
| 48 |
|
| 49 |
if (Core::requestMethod() == 'GET') { |
| 50 |
if ($dom_ex) { |
| 51 |
throw $dom_ex; |
| 52 |
} |
| 53 |
$rep = new Report( |
| 54 |
[ |
| 55 |
'domain' => $domain, |
| 56 |
'org_name' => $_GET['org'], |
| 57 |
'date' => [ |
| 58 |
'begin' => $ts |
| 59 |
], |
| 60 |
'report_id' => $_GET['report_id'] |
| 61 |
] |
| 62 |
); |
| 63 |
$rep->fetch(); |
| 64 |
Core::sendJson([ 'report' => $rep->toArray() ]); |
| 65 |
return; |
| 66 |
} elseif (Core::requestMethod() == 'POST') { |
| 67 |
if ($_GET['action'] === 'set') { |
| 68 |
$jdata = Core::getJsonData(); |
| 69 |
if ($jdata && isset($jdata['name']) && isset($jdata['value'])) { |
| 70 |
if ($dom_ex) { |
| 71 |
throw $dom_ex; |
| 72 |
} |
| 73 |
$rep = new Report( |
| 74 |
[ |
| 75 |
'domain' => $domain, |
| 76 |
'org_name' => $_GET['org'], |
| 77 |
'date' => [ |
| 78 |
'begin' => $ts |
| 79 |
], |
| 80 |
'report_id' => $_GET['report_id'] |
| 81 |
] |
| 82 |
); |
| 83 |
Core::sendJson($rep->set($jdata['name'], $jdata['value'])); |
| 84 |
return; |
| 85 |
} |
| 86 |
} |
| 87 |
} |
| 88 |
} catch (RuntimeException $e) { |
| 89 |
Core::sendJson(ErrorHandler::exceptionResult($e)); |
| 90 |
return; |
| 91 |
} |
| 92 |
} elseif (Core::requestMethod() == 'GET') { |
| 93 |
Core::instance()->sendHtml(); |
| 94 |
return; |
| 95 |
} |
| 96 |
} |
| 97 |
|
| 98 |
Core::sendBad(); |