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;
|
2023-02-09 23:55:30 +01:00
|
|
|
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();
|
2023-02-09 23:55:30 +01:00
|
|
|
$sql = $this->context->getSQL();
|
|
|
|
$userCount = User::count($sql);
|
|
|
|
$pageCount = Route::count($sql, new CondBool("active"));
|
2024-03-30 11:22:59 +01:00
|
|
|
$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();
|
|
|
|
}
|
|
|
|
|
2023-01-05 22:47:17 +01:00
|
|
|
$this->result["data"] = [
|
|
|
|
"userCount" => $userCount,
|
|
|
|
"pageCount" => $pageCount,
|
2024-03-30 11:22:59 +01:00
|
|
|
"groupCount" => $groupCount,
|
2024-04-05 17:14:36 +02:00
|
|
|
"errorCount" => $errorCount,
|
2023-01-05 22:47:17 +01:00
|
|
|
"server" => [
|
|
|
|
"version" => WEBBASE_VERSION,
|
|
|
|
"server" => $_SERVER["SERVER_SOFTWARE"] ?? "Unknown",
|
2024-04-24 16:02:16 +02:00
|
|
|
"memoryUsage" => memory_get_usage(),
|
|
|
|
"loadAverage" => $loadAvg,
|
2023-01-05 22:47:17 +01:00
|
|
|
"database" => $this->context->getSQL()->getStatus(),
|
2024-04-23 14:05:29 +02:00
|
|
|
"mail" => $settings->isMailEnabled(),
|
2024-04-24 16:02:16 +02:00
|
|
|
"captcha" => $settings->getCaptchaProvider()?->jsonSerialize(),
|
|
|
|
"rateLimiting" => $settings->isRateLimitingEnabled()
|
2023-01-05 22:47:17 +01:00
|
|
|
],
|
|
|
|
];
|
|
|
|
|
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
|
|
|
}
|