context); $this->success = $req->execute(array("key" => "^(mail_enabled|recaptcha_enabled)$")); $this->lastError = $req->getLastError(); if ($this->success) { $settings = $req->getResult()["settings"]; $this->mailConfigured = ($settings["mail_enabled"] ?? "0") === "1"; $this->recaptchaConfigured = ($settings["recaptcha_enabled"] ?? "0") === "1"; } return $this->success; } private function getVisitorCount() { $sql = $this->context->getSQL(); $date = new DateTime(); $monthStart = $date->format("Ym00"); $monthEnd = $date->modify("+1 month")->format("Ym00"); $res = $sql->select(new Count(new Distinct("cookie"))) ->from("Visitor") ->where(new Compare("day", $monthStart, ">=")) ->where(new Compare("day", $monthEnd, "<")) ->where(new Compare("count", 2, ">=")) ->execute(); $this->success = ($res !== false); $this->lastError = $sql->getLastError(); return ($this->success ? $res[0]["count"] : $this->success); } public function _execute(): bool { $sql = $this->context->getSQL(); $userCount = User::count($sql); $pageCount = Route::count($sql, new CondBool("active")); $groupCount = Group::count($sql); $req = new \Core\API\Visitors\Stats($this->context); $this->success = $req->execute(array("type"=>"monthly")); $this->lastError = $req->getLastError(); if (!$this->success) { return false; } $visitorStatistics = $req->getResult()["visitors"]; $visitorCount = $this->getVisitorCount(); if (!$this->success) { return false; } $req = new \Core\API\Logs\Get($this->context, false); $success = $req->execute([ "since" => (new \DateTime())->modify("-48 hours"), "severity" => "error" ]); if ($success) { $errorCount = $req->getResult()["pagination"]["total"]; } else { $errorCount = "Unknown"; } $loadAvg = "Unknown"; if (function_exists("sys_getloadavg")) { $loadAvg = sys_getloadavg(); } if (!$this->checkSettings()) { return false; } $this->result["data"] = [ "userCount" => $userCount, "pageCount" => $pageCount, "groupCount" => $groupCount, "visitors" => $visitorStatistics, "visitorsTotal" => $visitorCount, "errorCount" => $errorCount, "server" => [ "version" => WEBBASE_VERSION, "server" => $_SERVER["SERVER_SOFTWARE"] ?? "Unknown", "memory_usage" => memory_get_usage(), "load_avg" => $loadAvg, "database" => $this->context->getSQL()->getStatus(), "mail" => $this->mailConfigured, "reCaptcha" => $this->recaptchaConfigured ], ]; return $this->success; } public static function getDefaultACL(Insert $insert): void { $insert->addRow(self::getEndpoint(), [Group::ADMIN, Group::SUPPORT], "Allows users to view site statistics", true); } }