Debian Codegraph @

public/report.php

raw symbols SCIP
1 <?php
2
3 /**
4 * dmarc-srg - A php parser, viewer and summary report generator for incoming DMARC reports.
5 * Copyright (C) 2020-2025 Aleksey Andreev (liuch)
6 *
7 * Available at:
8 * https://github.com/liuch/dmarc-srg
9 *
10 * This program is free software: you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the Free
12 * Software Foundation, either version 3 of the License.
13 *
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17 * more details.
18 *
19 * You should have received a copy of the GNU General Public License along with
20 * this program. If not, see <http://www.gnu.org/licenses/>.
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();