From c892ef5b6e1be5deb133bff33e9e00afd2f46956 Mon Sep 17 00:00:00 2001 From: Roman Date: Fri, 12 Apr 2024 16:10:33 +0200 Subject: [PATCH] removed visitors feature --- Core/API/Stats.class.php | 31 ----- Core/API/VisitorsAPI.class.php | 122 -------------------- Core/Configuration/CreateDatabase.class.php | 6 - Core/Localization/de_DE/admin.php | 1 - Core/Localization/en_US/admin.php | 1 - Core/Objects/Context.class.php | 12 -- index.php | 7 +- react/admin-panel/src/elements/sidebar.js | 4 - react/admin-panel/src/views/overview.js | 38 +----- react/shared/api.js | 5 - 10 files changed, 4 insertions(+), 223 deletions(-) delete mode 100644 Core/API/VisitorsAPI.class.php diff --git a/Core/API/Stats.class.php b/Core/API/Stats.class.php index a85f858..8e82376 100644 --- a/Core/API/Stats.class.php +++ b/Core/API/Stats.class.php @@ -36,40 +36,11 @@ class Stats extends Request { 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([ @@ -96,8 +67,6 @@ class Stats extends Request { "userCount" => $userCount, "pageCount" => $pageCount, "groupCount" => $groupCount, - "visitors" => $visitorStatistics, - "visitorsTotal" => $visitorCount, "errorCount" => $errorCount, "server" => [ "version" => WEBBASE_VERSION, diff --git a/Core/API/VisitorsAPI.class.php b/Core/API/VisitorsAPI.class.php deleted file mode 100644 index 78a160b..0000000 --- a/Core/API/VisitorsAPI.class.php +++ /dev/null @@ -1,122 +0,0 @@ - new StringType("cookie", 26) - )); - $this->isPublic = false; - } - - public function _execute(): bool { - $sql = $this->context->getSQL(); - $cookie = $this->getParam("cookie"); - $day = (new DateTime())->format("Ymd"); - $sql->insert("Visitor", array("cookie", "day")) - ->addRow($cookie, $day) - ->onDuplicateKeyStrategy(new UpdateStrategy( - array("day", "cookie"), - array("count" => new Add("Visitor.count", 1)))) - ->execute(); - - return $this->success; - } - } - - class Stats extends VisitorsAPI { - public function __construct(Context $context, bool $externalCall = false) { - parent::__construct($context, $externalCall, array( - 'type' => new StringType('type', 32), - 'date' => new Parameter('date', Parameter::TYPE_DATE, true, new DateTime()) - )); - } - - private function setConditions(string $type, DateTime $date, Select $query): bool { - if ($type === "yearly") { - $yearStart = $date->format("Y0000"); - $yearEnd = $date->modify("+1 year")->format("Y0000"); - $query->where(new Compare("day", $yearStart, ">=")); - $query->where(new Compare("day", $yearEnd, "<")); - } else if($type === "monthly") { - $monthStart = $date->format("Ym00"); - $monthEnd = $date->modify("+1 month")->format("Ym00"); - $query->where(new Compare("day", $monthStart, ">=")); - $query->where(new Compare("day", $monthEnd, "<")); - } else if($type === "weekly") { - $weekStart = ($date->modify("monday this week"))->format("Ymd"); - $weekEnd = ($date->modify("sunday this week"))->format("Ymd"); - $query->where(new Compare("day", $weekStart, ">=")); - $query->where(new Compare("day", $weekEnd, "<=")); - } else { - return $this->createError("Invalid scope: $type"); - } - - return true; - } - - public function _execute(): bool { - $date = $this->getParam("date"); - $type = $this->getParam("type"); - - $sql = $this->context->getSQL(); - $query = $sql->select(new Count(), "day") - ->from("Visitor") - ->whereGt("count", 1) - ->groupBy("day") - ->orderBy("day") - ->ascending(); - - $this->success = $this->setConditions($type, $date, $query); - if (!$this->success) { - return false; - } - - $res = $query->execute(); - $this->success = ($res !== FALSE); - $this->lastError = $sql->getLastError(); - - if ($this->success) { - $this->result["type"] = $type; - $this->result["visitors"] = array(); - - foreach($res as $row) { - $day = DateTime::createFromFormat("Ymd", $row["day"])->format("Y/m/d"); - $count = $row["count"]; - $this->result["visitors"][$day] = $count; - } - } - - return $this->success; - } - - public static function getDefaultACL(Insert $insert): void { - $insert->addRow(self::getEndpoint(), [Group::ADMIN, Group::SUPPORT], "Allows users to view visitor statistics", true); - } - } -} \ No newline at end of file diff --git a/Core/Configuration/CreateDatabase.class.php b/Core/Configuration/CreateDatabase.class.php index 72e2408..910f696 100644 --- a/Core/Configuration/CreateDatabase.class.php +++ b/Core/Configuration/CreateDatabase.class.php @@ -18,12 +18,6 @@ class CreateDatabase extends DatabaseScript { self::loadEntities($queries, $sql); - $queries[] = $sql->createTable("Visitor") - ->addInt("day") - ->addInt("count", false, 1) - ->addString("cookie", 26) - ->unique("day", "cookie"); - $queries[] = $sql->createTable("Settings") ->addString("name", 32) ->addString("value", 1024, true) diff --git a/Core/Localization/de_DE/admin.php b/Core/Localization/de_DE/admin.php index a150525..5861301 100644 --- a/Core/Localization/de_DE/admin.php +++ b/Core/Localization/de_DE/admin.php @@ -3,7 +3,6 @@ return [ "title" => "Administration", "dashboard" => "Dashboard", - "visitor_statistics" => "Besucherstatistiken", "user_groups" => "Benutzer & Gruppen", "users" => "Benutzer", "groups" => "Gruppen", diff --git a/Core/Localization/en_US/admin.php b/Core/Localization/en_US/admin.php index 28e60e5..ad8b341 100644 --- a/Core/Localization/en_US/admin.php +++ b/Core/Localization/en_US/admin.php @@ -3,7 +3,6 @@ return [ "title" => "Administration", "dashboard" => "Dashboard", - "visitor_statistics" => "Visitor Statistics", "user_groups" => "Users & Groups", "users" => "Users", "groups" => "Groups", diff --git a/Core/Objects/Context.class.php b/Core/Objects/Context.class.php index 3f45338..36ce2dd 100644 --- a/Core/Objects/Context.class.php +++ b/Core/Objects/Context.class.php @@ -139,18 +139,6 @@ class Context { return false; } - public function processVisit(): void { - if (isset($_COOKIE["PHPSESSID"]) && !empty($_COOKIE["PHPSESSID"])) { - if ($this->isBot()) { - return; - } - - $cookie = $_COOKIE["PHPSESSID"]; - $req = new \Core\API\Visitors\ProcessVisit($this); - $req->execute(["cookie" => $cookie]); - } - } - private function isBot(): bool { if (empty($_SERVER["HTTP_USER_AGENT"])) { return false; diff --git a/index.php b/index.php index af26a43..9f1260f 100644 --- a/index.php +++ b/index.php @@ -64,7 +64,7 @@ if ($installation) { } if ($router !== null) { - + $logger = $router->getLogger(); if ((!isset($_GET["site"]) || $_GET["site"] === "/") && isset($_GET["error"]) && is_string($_GET["error"]) && preg_match("/^\d+$/", $_GET["error"])) { $response = $router->returnStatusCode(intval($_GET["error"])); @@ -84,12 +84,13 @@ if ($installation) { } else { $response = $router->returnStatusCode(403, ["message" => $error]); } + $logger->warning("The site was accessed by an untrusted domain: $currentHostName"); } else { $response = $route->call($router, $pathParams); } } catch (\Throwable $e) { http_response_code(500); - $router->getLogger()->error($e->getMessage()); + $logger->error($e->getMessage()); $response = $router->returnStatusCode(500); } } @@ -97,8 +98,6 @@ if ($installation) { http_response_code(500); $response = "Router could not be instantiated."; } - - $context->processVisit(); } $context->sendCookies(); diff --git a/react/admin-panel/src/elements/sidebar.js b/react/admin-panel/src/elements/sidebar.js index e9ca413..0afb672 100644 --- a/react/admin-panel/src/elements/sidebar.js +++ b/react/admin-panel/src/elements/sidebar.js @@ -40,10 +40,6 @@ export default function Sidebar(props) { "name": "admin.dashboard", "icon": "tachometer-alt" }, - "visitors": { - "name": "admin.visitor_statistics", - "icon": "chart-bar", - }, "users": { "name": "admin.users", "icon": "users" diff --git a/react/admin-panel/src/views/overview.js b/react/admin-panel/src/views/overview.js index de5e015..934104c 100644 --- a/react/admin-panel/src/views/overview.js +++ b/react/admin-panel/src/views/overview.js @@ -1,6 +1,5 @@ import * as React from "react"; import {Link} from "react-router-dom"; -import {format, getDaysInMonth} from "date-fns"; import {useCallback, useContext, useEffect, useState} from "react"; import {LocaleContext} from "shared/locale"; import {ArrowCircleRight, BugReport, Groups, LibraryBooks, People} from "@mui/icons-material"; @@ -57,41 +56,6 @@ export default function Overview(props) { onFetchStats(); }, []); - const today = new Date(); - const numDays = getDaysInMonth(today); - - let colors = [ '#ff4444', '#ffbb33', '#00C851', '#33b5e5' ]; - while (colors.length < numDays) { - colors = colors.concat(colors); - } - - let data = new Array(numDays).fill(0); - let visitorCount = 0; - /* - for (let date in this.state.visitors) { - if (this.state.visitors.hasOwnProperty(date)) { - let day = parseInt(date.split("/")[2]) - 1; - if (day >= 0 && day < numDays) { - let count = parseInt(this.state.visitors[date]); - data[day] = count; - visitorCount += count; - } - } - } - */ - - let labels = Array.from(Array(numDays), (_, i) => i + 1); - let chartOptions = {}; - let chartData = { - labels: labels, - datasets: [{ - label: 'Unique Visitors ' + format(today, "MMMM"), - borderWidth: 1, - data: data, - backgroundColor: colors, - }] - }; - /* let loadAvg = this.state.server.load_avg; if (Array.isArray(this.state.server.load_avg)) { @@ -125,7 +89,7 @@ export default function Overview(props) { } - link={"/admin/users"} /> + link={"/admin/groups"} /> } diff --git a/react/shared/api.js b/react/shared/api.js index bb32c43..931ccf4 100644 --- a/react/shared/api.js +++ b/react/shared/api.js @@ -314,11 +314,6 @@ export default class API { return this.apiCall("permission/delete", { method: method }); } - /** VisitorsAPI **/ - async getVisitors(type, date) { - return this.apiCall("visitors/stats", { type: type, date: date }); - } - /** LanguageAPI **/ async getLanguages() { return this.apiCall("language/get");