. * * ========================= * * This file contains the class Status * * @category API * @package DmarcSrg * @author Aleksey Andreev (liuch) * @license https://www.gnu.org/licenses/gpl-3.0.html GNU/GPLv3 */ namespace Liuch\DmarcSrg; use Liuch\DmarcSrg\Settings\SettingsList; /** * This class is designed to get the general state of DmarcSrg */ class Status { private $core = null; /** * The constructor * * @param Core $core */ public function __construct(object $core) { $this->core = $core; } /** * Returns general state of DmarcSrg * * This method returns an array with general state of the modules Admin, Auth * and statistics for the last N days. * * @return array */ public function get(): array { $adm_res = $this->core->admin()->state(); $res = [ 'state' => $adm_res['state'] ]; if (isset($adm_res['error_code'])) { $res['error_code'] = $adm_res['error_code']; if (isset($adm_res['message'])) { $res['message'] = $adm_res['message']; } if (isset($adm_res['debug_info'])) { $res['debug_info'] = $adm_res['debug_info']; } } elseif (isset($adm_res['database']['error_code'])) { $res['error_code'] = $adm_res['database']['error_code']; if (isset($adm_res['database']['message'])) { $res['message'] = $adm_res['database']['message']; } if (isset($adm_res['database']['debug_info'])) { $res['debug_info'] = $adm_res['database']['debug_info']; } } elseif (isset($adm_res['message'])) { $res['message'] = $adm_res['message']; } elseif (isset($adm_res['database']['message'])) { $res['message'] = $adm_res['database']['message']; } if (!isset($res['error_code']) || $res['error_code'] === 0) { $days = SettingsList::getSettingByName('status.emails-for-last-n-days')->value(); $stat = Statistics::lastNDays(null, $days); $res['emails'] = $stat->summary()['emails']; $res['emails']['days'] = $days; } $auth = null; if ($this->core->auth()->isEnabled()) { $auth = $this->core->userId() !== false ? 'yes' : 'no'; } else { $auth = 'disabled'; } $res['authenticated'] = $auth; $res['version'] = Core::APP_VERSION; $res['php_version'] = phpversion(); return $res; } }