Debian Codegraph @

classes/Status.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 *
24 * This file contains the class Status
25 *
26 * @category API
27 * @package DmarcSrg
28 * @author Aleksey Andreev (liuch)
29 * @license https://www.gnu.org/licenses/gpl-3.0.html GNU/GPLv3
30 */
31
32 namespace Liuch\DmarcSrg;
33
34 use Liuch\DmarcSrg\Settings\SettingsList;
35
36 /**
37 * This class is designed to get the general state of DmarcSrg
38 */
39 class Status
40 {
41 /** @var Core */
42 private $core = null;
43
44 /**
45 * The constructor
46 *
47 * @param Core $core
48 */
49 public function __construct(object $core)
50 {
51 $this->core = $core;
52 }
53
54 /**
55 * Returns general state of DmarcSrg
56 *
57 * This method returns an array with general state of the modules Admin, Auth
58 * and statistics for the last N days.
59 *
60 * @return array
61 */
62 public function get(): array
63 {
64 $adm_res = $this->core->admin()->state();
65 $res = [
66 'state' => $adm_res['state']
67 ];
68
69 if (isset($adm_res['error_code'])) {
70 $res['error_code'] = $adm_res['error_code'];
71 if (isset($adm_res['message'])) {
72 $res['message'] = $adm_res['message'];
73 }
74 if (isset($adm_res['debug_info'])) {
75 $res['debug_info'] = $adm_res['debug_info'];
76 }
77 } elseif (isset($adm_res['database']['error_code'])) {
78 $res['error_code'] = $adm_res['database']['error_code'];
79 if (isset($adm_res['database']['message'])) {
80 $res['message'] = $adm_res['database']['message'];
81 }
82 if (isset($adm_res['database']['debug_info'])) {
83 $res['debug_info'] = $adm_res['database']['debug_info'];
84 }
85 } elseif (isset($adm_res['message'])) {
86 $res['message'] = $adm_res['message'];
87 } elseif (isset($adm_res['database']['message'])) {
88 $res['message'] = $adm_res['database']['message'];
89 }
90
91 $auth = null;
92 if ($this->core->auth()->isEnabled()) {
93 $res['authenticated'] = $this->core->getCurrentUser() ? 'yes' : 'no';
94 } else {
95 $res['authenticated'] = 'disabled';
96 }
97 $res['auth_type'] = $this->core->auth()->authenticationType();
98 $res['version'] = APP_VERSION;
99 $res['php_version'] = phpversion();
100
101 return $res;
102 }
103 }