web-base/Core/API/Stats.class.php

67 lines
1.8 KiB
PHP
Raw Normal View History

2020-06-17 23:50:08 +02:00
<?php
2022-11-18 18:06:46 +01:00
namespace Core\API;
2020-06-17 23:50:08 +02:00
2023-01-16 21:47:23 +01:00
use Core\Objects\DatabaseEntity\Group;
use Core\Objects\DatabaseEntity\Route;
use Core\Objects\DatabaseEntity\User;
2022-11-18 18:06:46 +01:00
use Core\Driver\SQL\Condition\CondBool;
use Core\Objects\Context;
2020-06-17 23:50:08 +02:00
class Stats extends Request {
2022-06-20 19:52:31 +02:00
public function __construct(Context $context, $externalCall = false) {
parent::__construct($context, $externalCall, array());
2020-06-17 23:50:08 +02:00
}
2022-02-21 13:01:03 +01:00
public function _execute(): bool {
2024-04-23 14:05:29 +02:00
$settings = $this->context->getSettings();
$sql = $this->context->getSQL();
$userCount = User::count($sql);
$pageCount = Route::count($sql, new CondBool("active"));
$groupCount = Group::count($sql);
2020-07-18 12:51:36 +02:00
2024-04-05 17:14:36 +02:00
$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";
}
2020-06-24 16:13:54 +02:00
$loadAvg = "Unknown";
if (function_exists("sys_getloadavg")) {
$loadAvg = sys_getloadavg();
}
$this->result["data"] = [
"userCount" => $userCount,
"pageCount" => $pageCount,
"groupCount" => $groupCount,
2024-04-05 17:14:36 +02:00
"errorCount" => $errorCount,
"server" => [
"version" => WEBBASE_VERSION,
"server" => $_SERVER["SERVER_SOFTWARE"] ?? "Unknown",
"memory_usage" => memory_get_usage(),
"load_avg" => $loadAvg,
"database" => $this->context->getSQL()->getStatus(),
2024-04-23 14:05:29 +02:00
"mail" => $settings->isMailEnabled(),
"captcha" => $settings->getCaptchaProvider()?->jsonSerialize()
],
];
2020-06-17 23:50:08 +02:00
return $this->success;
}
2024-04-23 12:14:28 +02:00
public static function getDescription(): string {
return "Allows users to view site statistics";
}
public static function getDefaultPermittedGroups(): array {
return [Group::ADMIN, Group::SUPPORT];
2023-01-16 21:47:23 +01:00
}
2020-06-17 23:50:08 +02:00
}