From 28c9222b98cf2562481f6ff32cf35b1d5ffc638f Mon Sep 17 00:00:00 2001 From: Roman Date: Mon, 21 Feb 2022 13:01:03 +0100 Subject: [PATCH] API refactor + CLI docker --- cli.php | 14 +++- core/Api/ApiKeyAPI.class.php | 25 +----- core/Api/ContactAPI.class.php | 24 +----- core/Api/GroupsAPI.class.php | 18 +--- core/Api/LanguageAPI.class.php | 12 +-- core/Api/MailAPI.class.php | 20 +---- core/Api/NewsAPI.class.php | 23 +----- core/Api/NotificationsAPI.class.php | 17 +--- core/Api/PermissionAPI.class.php | 15 +--- core/Api/Request.class.php | 16 +++- core/Api/RoutesAPI.class.php | 43 ++-------- core/Api/SettingsAPI.class.php | 12 +-- core/Api/Stats.class.php | 7 +- core/Api/Swagger.class.php | 6 +- core/Api/TemplateAPI.class.php | 6 +- core/Api/TfaAPI.class.php | 30 ++----- core/Api/UserAPI.class.php | 115 ++++++-------------------- core/Api/VerifyCaptcha.class.php | 6 +- core/Api/VisitorsAPI.class.php | 20 ++--- core/Documents/Install.class.php | 1 + core/Objects/ConnectionData.class.php | 14 ++-- core/core.php | 2 +- 22 files changed, 111 insertions(+), 335 deletions(-) diff --git a/cli.php b/cli.php index 8a56acc..2a16074 100644 --- a/cli.php +++ b/cli.php @@ -39,8 +39,20 @@ function getDatabaseConfig(): ConnectionData { return new $configClass(); } +$config = new Configuration(); +$database = $config->getDatabase(); +if ($database !== null && $database->getProperty("isDocker", false) && !is_file("/.dockerenv")) { + $command = array_merge(["docker", "exec", "-it", "php", "php"], /*array_map(function ($arg) { return escapeshellarg($arg); }, */$argv); + var_dump(implode(" ", $command)); + $proc = proc_open($command, [1 => STDOUT, 2 => STDERR], $pipes, "/application"); + sleep(1); + /*var_dump(stream_get_contents($pipes[1])); + var_dump(stream_get_contents($pipes[2]));*/ + exit(proc_close($proc)); +} + function getUser(): ?User { - $config = new Configuration(); + global $config; $user = new User($config); if (!$user->getSQL() || !$user->getSQL()->isConnected()) { printLine("Could not establish database connection"); diff --git a/core/Api/ApiKeyAPI.class.php b/core/Api/ApiKeyAPI.class.php index cf2e7f1..a7328de 100644 --- a/core/Api/ApiKeyAPI.class.php +++ b/core/Api/ApiKeyAPI.class.php @@ -45,12 +45,7 @@ namespace Api\ApiKey { $this->loginRequired = true; } - public function execute($values = array()): bool { - - if(!parent::execute($values)) { - return false; - } - + public function _execute(): bool { $apiKey = generateRandomString(64); $sql = $this->user->getSQL(); $validUntil = (new \DateTime())->modify("+30 DAY"); @@ -83,11 +78,7 @@ namespace Api\ApiKey { $this->loginRequired = true; } - public function execute($values = array()): bool { - if(!parent::execute($values)) { - return false; - } - + public function _execute(): bool { $sql = $this->user->getSQL(); $query = $sql->select("uid", "api_key", "valid_until", "active") ->from("ApiKey") @@ -129,11 +120,7 @@ namespace Api\ApiKey { $this->loginRequired = true; } - public function execute($values = array()): bool { - if(!parent::execute($values)) { - return false; - } - + public function _execute(): bool { $id = $this->getParam("id"); if(!$this->apiKeyExists($id)) return false; @@ -164,11 +151,7 @@ namespace Api\ApiKey { $this->loginRequired = true; } - public function execute($values = array()): bool { - if(!parent::execute($values)) { - return false; - } - + public function _execute(): bool { $id = $this->getParam("id"); if (!$this->apiKeyExists($id)) return false; diff --git a/core/Api/ContactAPI.class.php b/core/Api/ContactAPI.class.php index 21ca2e7..eed1bbe 100644 --- a/core/Api/ContactAPI.class.php +++ b/core/Api/ContactAPI.class.php @@ -64,11 +64,7 @@ namespace Api\Contact { parent::__construct($user, $externalCall, $parameters); } - public function execute($values = array()): bool { - if (!parent::execute($values)) { - return false; - } - + public function _execute(): bool { $settings = $this->user->getConfiguration()->getSettings(); if ($settings->isRecaptchaEnabled()) { $captcha = $this->getParam("captcha"); @@ -184,11 +180,7 @@ namespace Api\Contact { ->execute(); } - public function execute($values = array()): bool { - if (!parent::execute($values)) { - return false; - } - + public function _execute(): bool { $message = $this->getParam("message"); $senderMail = $this->getSenderMail(); if (!$this->success) { @@ -219,11 +211,7 @@ namespace Api\Contact { $this->csrfTokenRequired = false; } - public function execute($values = array()): bool { - if (!parent::execute($values)) { - return false; - } - + public function _execute(): bool { $sql = $this->user->getSQL(); $res = $sql->select("ContactRequest.uid", "from_name", "from_email", "from_name", new Sum(new CaseWhen(new CondNot("ContactMessage.read"), 1, 0), "unread")) @@ -270,11 +258,7 @@ namespace Api\Contact { ->execute(); } - public function execute($values = array()): bool { - if (!parent::execute($values)) { - return false; - } - + public function _execute(): bool { $requestId = $this->getParam("requestId"); $sql = $this->user->getSQL(); diff --git a/core/Api/GroupsAPI.class.php b/core/Api/GroupsAPI.class.php index 5b7a5f2..1cdf484 100644 --- a/core/Api/GroupsAPI.class.php +++ b/core/Api/GroupsAPI.class.php @@ -54,11 +54,7 @@ namespace Api\Groups { return $this->success; } - public function execute($values = array()): bool { - if(!parent::execute($values)) { - return false; - } - + public function _execute(): bool { $page = $this->getParam("page"); if($page < 1) { return $this->createError("Invalid page count"); @@ -116,11 +112,7 @@ namespace Api\Groups { )); } - public function execute($values = array()): bool { - if (!parent::execute($values)) { - return false; - } - + public function _execute(): bool { $name = $this->getParam("name"); if (preg_match("/^[a-zA-Z][a-zA-Z0-9_-]*$/", $name) !== 1) { return $this->createError("Invalid name"); @@ -162,11 +154,7 @@ namespace Api\Groups { )); } - public function execute($values = array()): bool { - if (!parent::execute($values)) { - return false; - } - + public function _execute(): bool { $id = $this->getParam("uid"); if (in_array($id, DEFAULT_GROUPS)) { return $this->createError("You cannot delete a default group."); diff --git a/core/Api/LanguageAPI.class.php b/core/Api/LanguageAPI.class.php index e61165e..fab8d17 100644 --- a/core/Api/LanguageAPI.class.php +++ b/core/Api/LanguageAPI.class.php @@ -23,11 +23,7 @@ namespace Api\Language { parent::__construct($user, $externalCall, array()); } - public function execute($values = array()): bool { - if(!parent::execute($values)) { - return false; - } - + public function _execute(): bool { $sql = $this->user->getSQL(); $res = $sql->select("uid", "code", "name") ->from("Language") @@ -108,11 +104,7 @@ namespace Api\Language { return $this->success; } - public function execute($values = array()): bool { - if(!parent::execute($values)) { - return false; - } - + public function _execute(): bool { if(!$this->checkLanguage()) return false; diff --git a/core/Api/MailAPI.class.php b/core/Api/MailAPI.class.php index 04f5f0f..9c9ab26 100644 --- a/core/Api/MailAPI.class.php +++ b/core/Api/MailAPI.class.php @@ -59,10 +59,7 @@ namespace Api\Mail { )); } - public function execute($values = array()): bool { - if (!parent::execute($values)) { - return false; - } + public function _execute(): bool { $receiver = $this->getParam("receiver"); $req = new \Api\Mail\Send($this->user); @@ -94,10 +91,7 @@ namespace Api\Mail { $this->isPublic = false; } - public function execute($values = array()): bool { - if (!parent::execute($values)) { - return false; - } + public function _execute(): bool { $mailConfig = $this->getMailConfig(); if (!$this->success) { @@ -402,10 +396,7 @@ namespace Api\Mail { return true; } - public function execute($values = array()): bool { - if (!parent::execute($values)) { - return false; - } + public function _execute(): bool { if (!function_exists("imap_open")) { return $this->createError("IMAP is not enabled. Enable it inside the php config. For more information visit: https://www.php.net/manual/en/imap.setup.php"); @@ -473,10 +464,7 @@ namespace Api\Mail { $this->isPublic = false; } - public function execute($values = array()): bool { - if (!parent::execute($values)) { - return false; - } + public function _execute(): bool { $debug = $this->getParam("debug"); $startTime = time(); diff --git a/core/Api/NewsAPI.class.php b/core/Api/NewsAPI.class.php index 9a0189e..b3e6a4c 100644 --- a/core/Api/NewsAPI.class.php +++ b/core/Api/NewsAPI.class.php @@ -29,11 +29,7 @@ namespace Api\News { ]); } - public function execute($values = array()): bool { - if (!parent::execute($values)) { - return false; - } - + public function _execute(): bool { $sql = $this->user->getSQL(); $query = $sql->select("News.uid", "title", "text", "publishedAt", "User.uid as publisherId", "User.name as publisherName", "User.fullName as publisherFullName") @@ -88,11 +84,7 @@ namespace Api\News { ]); } - public function execute($values = array()): bool { - if (!parent::execute($values)) { - return false; - } - + public function _execute(): bool { $sql = $this->user->getSQL(); $title = $this->getParam("title"); $text = $this->getParam("text"); @@ -120,11 +112,7 @@ namespace Api\News { ]); } - public function execute($values = array()): bool { - if (!parent::execute($values)) { - return false; - } - + public function _execute(): bool { $sql = $this->user->getSQL(); $id = $this->getParam("id"); $res = $sql->select("publishedBy") @@ -161,10 +149,7 @@ namespace Api\News { ]); } - public function execute($values = array()): bool { - if (!parent::execute($values)) { - return false; - } + public function _execute(): bool { $sql = $this->user->getSQL(); $id = $this->getParam("id"); diff --git a/core/Api/NotificationsAPI.class.php b/core/Api/NotificationsAPI.class.php index f16c033..8e3c19f 100644 --- a/core/Api/NotificationsAPI.class.php +++ b/core/Api/NotificationsAPI.class.php @@ -108,11 +108,7 @@ namespace Api\Notifications { return $this->success; } - public function execute($values = array()): bool { - if(!parent::execute($values)) { - return false; - } - + public function _execute(): bool { $userId = $this->getParam("userId"); $groupId = $this->getParam("groupId"); $title = $this->getParam("title"); @@ -214,11 +210,7 @@ namespace Api\Notifications { return $this->success; } - public function execute($values = array()): bool { - if(!parent::execute($values)) { - return false; - } - + public function _execute(): bool { $this->notifications = array(); $this->notificationids = array(); if ($this->fetchUserNotifications() && $this->fetchGroupNotifications()) { @@ -236,10 +228,7 @@ namespace Api\Notifications { $this->loginRequired = true; } - public function execute($values = array()): bool { - if (!parent::execute($values)) { - return false; - } + public function _execute(): bool { $sql = $this->user->getSQL(); $res = $sql->update("UserNotification") diff --git a/core/Api/PermissionAPI.class.php b/core/Api/PermissionAPI.class.php index 77e3798..5081207 100644 --- a/core/Api/PermissionAPI.class.php +++ b/core/Api/PermissionAPI.class.php @@ -36,10 +36,7 @@ namespace Api\Permission { $this->isPublic = false; } - public function execute($values = array()): bool { - if (!parent::execute($values)) { - return false; - } + public function _execute(): bool { $method = $this->getParam("method"); $sql = $this->user->getSQL(); @@ -104,10 +101,7 @@ namespace Api\Permission { return $this->success; } - public function execute($values = array()): bool { - if (!parent::execute($values)) { - return false; - } + public function _execute(): bool { if (!$this->fetchGroups()) { return false; @@ -149,10 +143,7 @@ namespace Api\Permission { )); } - public function execute($values = array()): bool { - if (!parent::execute($values)) { - return false; - } + public function _execute(): bool { if (!$this->checkStaticPermission()) { return false; diff --git a/core/Api/Request.class.php b/core/Api/Request.class.php index 114b577..ef4ab86 100644 --- a/core/Api/Request.class.php +++ b/core/Api/Request.class.php @@ -6,7 +6,7 @@ use Api\Parameter\Parameter; use Objects\User; use PhpMqtt\Client\MqttClient; -class Request { +abstract class Request { protected User $user; protected array $params; @@ -107,7 +107,9 @@ class Request { die($data); } - public function execute($values = array()): bool { + protected abstract function _execute(): bool; + + public final function execute($values = array()): bool { $this->params = array_merge([], $this->defaultParams); $this->success = false; @@ -223,9 +225,15 @@ class Request { return false; } + $success = $this->_execute(); + if ($this->success !== $success) { + // _execute returns a different value then it set for $this->success + // this should actually not occur, how to handle this case? + $this->success = $success; + } + $this->user->getSQL()->setLastError(''); - $this->success = true; - return true; + return $this->success; } protected function createError($err): bool { diff --git a/core/Api/RoutesAPI.class.php b/core/Api/RoutesAPI.class.php index 8086ab2..84534dc 100644 --- a/core/Api/RoutesAPI.class.php +++ b/core/Api/RoutesAPI.class.php @@ -74,11 +74,7 @@ namespace Api\Routes { parent::__construct($user, $externalCall, array()); } - public function execute($values = array()): bool { - if(!parent::execute($values)) { - return false; - } - + public function _execute(): bool { $sql = $this->user->getSQL(); $res = $sql @@ -121,11 +117,7 @@ namespace Api\Routes { $this->isPublic = false; } - public function execute($values = array()): bool { - if(!parent::execute($values)) { - return false; - } - + public function _execute(): bool { $request = $this->getParam('request'); if (!startsWith($request, '/')) { $request = "/$request"; @@ -174,11 +166,7 @@ namespace Api\Routes { )); } - public function execute($values = array()): bool { - if(!parent::execute($values)) { - return false; - } - + public function _execute(): bool { if (!$this->validateRoutes()) { return false; } @@ -263,10 +251,7 @@ namespace Api\Routes { $this->isPublic = false; } - public function execute($values = array()): bool { - if (!parent::execute($values)) { - return false; - } + public function _execute(): bool { $request = $this->formatRegex($this->getParam("request"), true); $action = $this->getParam("action"); @@ -299,10 +284,7 @@ namespace Api\Routes { $this->isPublic = false; } - public function execute($values = array()): bool { - if (!parent::execute($values)) { - return false; - } + public function _execute(): bool { $uid = $this->getParam("uid"); if (!$this->routeExists($uid)) { @@ -339,10 +321,7 @@ namespace Api\Routes { $this->isPublic = false; } - public function execute($values = array()): bool { - if (!parent::execute($values)) { - return false; - } + public function _execute(): bool { $uid = $this->getParam("uid"); if (!$this->routeExists($uid)) { @@ -367,10 +346,7 @@ namespace Api\Routes { $this->isPublic = false; } - public function execute($values = array()): bool { - if (!parent::execute($values)) { - return false; - } + public function _execute(): bool { $uid = $this->getParam("uid"); return $this->toggleRoute($uid, true); @@ -385,10 +361,7 @@ namespace Api\Routes { $this->isPublic = false; } - public function execute($values = array()): bool { - if (!parent::execute($values)) { - return false; - } + public function _execute(): bool { $uid = $this->getParam("uid"); return $this->toggleRoute($uid, false); diff --git a/core/Api/SettingsAPI.class.php b/core/Api/SettingsAPI.class.php index be9d313..0338f64 100644 --- a/core/Api/SettingsAPI.class.php +++ b/core/Api/SettingsAPI.class.php @@ -29,11 +29,7 @@ namespace Api\Settings { )); } - public function execute($values = array()): bool { - if(!parent::execute($values)) { - return false; - } - + public function _execute(): bool { $key = $this->getParam("key"); $sql = $this->user->getSQL(); @@ -72,11 +68,7 @@ namespace Api\Settings { )); } - public function execute($values = array()): bool { - if (!parent::execute($values)) { - return false; - } - + public function _execute(): bool { $values = $this->getParam("settings"); if (empty($values)) { return $this->createError("No values given."); diff --git a/core/Api/Stats.class.php b/core/Api/Stats.class.php index 8bb1cb7..815611a 100644 --- a/core/Api/Stats.class.php +++ b/core/Api/Stats.class.php @@ -66,11 +66,7 @@ class Stats extends Request { return ($this->success ? $res[0]["count"] : $this->success); } - public function execute($values = array()): bool { - if(!parent::execute($values)) { - return false; - } - + public function _execute(): bool { $userCount = $this->getUserCount(); $pageCount = $this->getPageCount(); $req = new \Api\Visitors\Stats($this->user); @@ -108,7 +104,6 @@ class Stats extends Request { "mail" => $this->mailConfigured, "reCaptcha" => $this->recaptchaConfigured ); - return $this->success; } diff --git a/core/Api/Swagger.class.php b/core/Api/Swagger.class.php index 57309f5..e35226a 100644 --- a/core/Api/Swagger.class.php +++ b/core/Api/Swagger.class.php @@ -12,11 +12,7 @@ class Swagger extends Request { $this->csrfTokenRequired = false; } - public function execute($values = array()): bool { - if (!parent::execute($values)) { - return false; - } - + public function _execute(): bool { header("Content-Type: application/x-yaml"); header("Access-Control-Allow-Origin: *"); die($this->getDocumentation()); diff --git a/core/Api/TemplateAPI.class.php b/core/Api/TemplateAPI.class.php index 6a10687..b0064af 100644 --- a/core/Api/TemplateAPI.class.php +++ b/core/Api/TemplateAPI.class.php @@ -35,11 +35,7 @@ namespace Api\Template { ]); } - public function execute($values = array()): bool { - if (!parent::execute($values)) { - return false; - } - + public function _execute(): bool { $templateFile = $this->getParam("file"); $parameters = $this->getParam("parameters"); $extension = pathinfo($templateFile, PATHINFO_EXTENSION); diff --git a/core/Api/TfaAPI.class.php b/core/Api/TfaAPI.class.php index a2c1961..b37f9ee 100644 --- a/core/Api/TfaAPI.class.php +++ b/core/Api/TfaAPI.class.php @@ -72,10 +72,7 @@ namespace Api\TFA { ]); } - public function execute($values = array()): bool { - if (!parent::execute($values)) { - return false; - } + public function _execute(): bool { $token = $this->user->getTwoFactorToken(); if (!$token) { @@ -148,10 +145,7 @@ namespace Api\TFA { $this->csrfTokenRequired = false; } - public function execute($values = array()): bool { - if (!parent::execute($values)) { - return false; - } + public function _execute(): bool { $twoFactorToken = $this->user->getTwoFactorToken(); if ($twoFactorToken && $twoFactorToken->isConfirmed()) { @@ -188,10 +182,7 @@ namespace Api\TFA { $this->loginRequired = true; } - public function execute($values = array()): bool { - if (!parent::execute($values)) { - return false; - } + public function _execute(): bool { $twoFactorToken = $this->user->getTwoFactorToken(); if ($twoFactorToken->isConfirmed()) { @@ -218,10 +209,7 @@ namespace Api\TFA { $this->csrfTokenRequired = false; } - public function execute($values = array()): bool { - if (!parent::execute($values)) { - return false; - } + public function _execute(): bool { $session = $this->user->getSession(); if (!$session) { @@ -254,10 +242,7 @@ namespace Api\TFA { ]); } - public function execute($values = array()): bool { - if (!parent::execute($values)) { - return false; - } + public function _execute(): bool { $clientDataJSON = json_decode($this->getParam("clientDataJSON"), true); $attestationObjectRaw = base64_decode($this->getParam("attestationObject")); @@ -358,10 +343,7 @@ namespace Api\TFA { $this->csrfTokenRequired = false; } - public function execute($values = array()): bool { - if (!parent::execute($values)) { - return false; - } + public function _execute(): bool { $session = $this->user->getSession(); if (!$session) { diff --git a/core/Api/UserAPI.class.php b/core/Api/UserAPI.class.php index 14d6b9c..4601bb3 100644 --- a/core/Api/UserAPI.class.php +++ b/core/Api/UserAPI.class.php @@ -173,10 +173,7 @@ namespace Api\User { $this->loginRequired = true; } - public function execute($values = array()): bool { - if (!parent::execute($values)) { - return false; - } + public function _execute(): bool { $username = $this->getParam('username'); $email = $this->getParam('email'); @@ -250,10 +247,7 @@ namespace Api\User { return false; } - public function execute($values = array()): bool { - if (!parent::execute($values)) { - return false; - } + public function _execute(): bool { $page = $this->getParam("page"); if ($page < 1) { @@ -343,10 +337,7 @@ namespace Api\User { $this->loginRequired = true; } - public function execute($values = array()): bool { - if (!parent::execute($values)) { - return false; - } + public function _execute(): bool { $sql = $this->user->getSQL(); $userId = $this->getParam("id"); @@ -435,10 +426,7 @@ namespace Api\User { $this->csrfTokenRequired = false; } - public function execute($values = array()): bool { - if (!parent::execute($values)) { - return false; - } + public function _execute(): bool { if (!$this->user->isLoggedIn()) { $this->result["loggedIn"] = false; @@ -479,10 +467,7 @@ namespace Api\User { $this->loginRequired = true; } - public function execute($values = array()): bool { - if (!parent::execute($values)) { - return false; - } + public function _execute(): bool { $username = $this->getParam('username'); $email = $this->getParam('email'); @@ -572,10 +557,7 @@ namespace Api\User { return $this->success; } - public function execute($values = array()): bool { - if (!parent::execute($values)) { - return false; - } + public function _execute(): bool { if ($this->user->isLoggedIn()) { return $this->createError("You are already logged in."); @@ -637,10 +619,7 @@ namespace Api\User { return $this->success; } - public function execute($values = array()): bool { - if (!parent::execute($values)) { - return false; - } + public function _execute(): bool { if ($this->user->isLoggedIn()) { return $this->createError("You are already logged in."); @@ -689,10 +668,7 @@ namespace Api\User { return $this->createError(L('Wrong username or password')); } - public function execute($values = array()): bool { - if (!parent::execute($values)) { - return false; - } + public function _execute(): bool { if ($this->user->isLoggedIn()) { $this->lastError = L('You are already logged in'); @@ -765,10 +741,7 @@ namespace Api\User { $this->forbidMethod("GET"); } - public function execute($values = array()): bool { - if (!parent::execute($values)) { - return false; - } + public function _execute(): bool { if (!$this->user->isLoggedIn()) { return $this->createError("You are not logged in."); @@ -802,10 +775,7 @@ namespace Api\User { $this->csrfTokenRequired = false; } - public function execute($values = array()): bool { - if (!parent::execute($values)) { - return false; - } + public function _execute(): bool { if ($this->user->isLoggedIn()) { return $this->createError(L('You are already logged in')); @@ -916,10 +886,7 @@ namespace Api\User { return array(); } - public function execute($values = array()): bool { - if (!parent::execute($values)) { - return false; - } + public function _execute(): bool { $token = $this->getParam('token'); $tokenEntry = $this->checkToken($token); @@ -961,10 +928,7 @@ namespace Api\User { $this->forbidMethod("GET"); } - public function execute($values = array()): bool { - if (!parent::execute($values)) { - return false; - } + public function _execute(): bool { $id = $this->getParam("id"); $user = $this->getUser($id); @@ -1062,10 +1026,7 @@ namespace Api\User { $this->loginRequired = true; } - public function execute($values = array()): bool { - if (!parent::execute($values)) { - return false; - } + public function _execute(): bool { $id = $this->getParam("id"); if ($id === $this->user->getId()) { @@ -1103,10 +1064,7 @@ namespace Api\User { parent::__construct($user, $externalCall, $parameters); } - public function execute($values = array()): bool { - if (!parent::execute($values)) { - return false; - } + public function _execute(): bool { if ($this->user->isLoggedIn()) { return $this->createError("You already logged in."); @@ -1208,10 +1166,7 @@ namespace Api\User { parent::__construct($user, $externalCall, $parameters); } - public function execute($values = array()): bool { - if (!parent::execute($values)) { - return false; - } + public function _execute(): bool { if ($this->user->isLoggedIn()) { return $this->createError("You already logged in."); @@ -1324,10 +1279,7 @@ namespace Api\User { return $this->success; } - public function execute($values = array()): bool { - if (!parent::execute($values)) { - return false; - } + public function _execute(): bool { if ($this->user->isLoggedIn()) { return $this->createError("You are already logged in."); @@ -1373,10 +1325,7 @@ namespace Api\User { $this->forbidMethod("GET"); } - public function execute($values = array()): bool { - if (!parent::execute($values)) { - return false; - } + public function _execute(): bool { $newUsername = $this->getParam("username"); $oldPassword = $this->getParam("oldPassword"); @@ -1463,10 +1412,7 @@ namespace Api\User { } } - public function execute($values = array()): bool { - if (!parent::execute($values)) { - return false; - } + public function _execute(): bool { $gpgKey = $this->user->getGPG(); if ($gpgKey) { @@ -1569,10 +1515,7 @@ namespace Api\User { $this->forbidMethod("GET"); } - public function execute($values = array()): bool { - if (!parent::execute($values)) { - return false; - } + public function _execute(): bool { $gpgKey = $this->user->getGPG(); if (!$gpgKey) { @@ -1618,10 +1561,7 @@ namespace Api\User { $this->loginRequired = true; } - public function execute($values = array()): bool { - if (!parent::execute($values)) { - return false; - } + public function _execute(): bool { $gpgKey = $this->user->getGPG(); if (!$gpgKey) { @@ -1683,10 +1623,7 @@ namespace Api\User { $this->csrfTokenRequired = false; } - public function execute($values = array()): bool { - if (!parent::execute($values)) { - return false; - } + public function _execute(): bool { $allowedFormats = ["json", "ascii", "gpg"]; $format = $this->getParam("format"); @@ -1824,10 +1761,7 @@ namespace Api\User { return $fileName; } - public function execute($values = array()): bool { - if (!parent::execute($values)) { - return false; - } + public function _execute(): bool { $userId = $this->user->getId(); $uploadDir = WEBROOT . "/img/uploads/user/$userId"; @@ -1865,10 +1799,7 @@ namespace Api\User { $this->loginRequired = true; } - public function execute($values = array()): bool { - if (!parent::execute($values)) { - return false; - } + public function _execute(): bool { $pfp = $this->user->getProfilePicture(); if (!$pfp) { diff --git a/core/Api/VerifyCaptcha.class.php b/core/Api/VerifyCaptcha.class.php index 07f2a44..f702d2c 100644 --- a/core/Api/VerifyCaptcha.class.php +++ b/core/Api/VerifyCaptcha.class.php @@ -16,11 +16,7 @@ class VerifyCaptcha extends Request { $this->isPublic = false; } - public function execute($values = array()): bool { - if(!parent::execute($values)) { - return false; - } - + public function _execute(): bool { $settings = $this->user->getConfiguration()->getSettings(); if (!$settings->isRecaptchaEnabled()) { return $this->createError("Google reCaptcha is not enabled."); diff --git a/core/Api/VisitorsAPI.class.php b/core/Api/VisitorsAPI.class.php index 7e876e8..62a6be0 100644 --- a/core/Api/VisitorsAPI.class.php +++ b/core/Api/VisitorsAPI.class.php @@ -31,11 +31,7 @@ namespace Api\Visitors { $this->isPublic = false; } - public function execute($values = array()): bool { - if (!parent::execute($values)) { - return false; - } - + public function _execute(): bool { $sql = $this->user->getSQL(); $cookie = $this->getParam("cookie"); $day = (new DateTime())->format("Ymd"); @@ -58,7 +54,7 @@ namespace Api\Visitors { )); } - private function setConditions(string $type, DateTime $date, Select $query) { + private function setConditions(string $type, DateTime $date, Select $query): bool { if ($type === "yearly") { $yearStart = $date->format("Y0000"); $yearEnd = $date->modify("+1 year")->format("Y0000"); @@ -75,15 +71,13 @@ namespace Api\Visitors { $query->where(new Compare("day", $weekStart, ">=")); $query->where(new Compare("day", $weekEnd, "<=")); } else { - $this->createError("Invalid scope: $type"); + return $this->createError("Invalid scope: $type"); } + + return true; } - public function execute($values = array()): bool { - if (!parent::execute($values)) { - return false; - } - + public function _execute(): bool { $date = $this->getParam("date"); $type = $this->getParam("type"); @@ -95,7 +89,7 @@ namespace Api\Visitors { ->orderBy("day") ->ascending(); - $this->setConditions($type, $date, $query); + $this->success = $this->setConditions($type, $date, $query); if (!$this->success) { return false; } diff --git a/core/Documents/Install.class.php b/core/Documents/Install.class.php index 45a5480..0adbcb3 100644 --- a/core/Documents/Install.class.php +++ b/core/Documents/Install.class.php @@ -325,6 +325,7 @@ namespace Documents\Install { $connectionData->setProperty('database', $database); $connectionData->setProperty('encoding', $encoding); $connectionData->setProperty('type', $type); + $connectionData->setProperty('isDocker', $this->isDocker()); $sql = SQL::createConnection($connectionData); $success = false; if (is_string($sql)) { diff --git a/core/Objects/ConnectionData.class.php b/core/Objects/ConnectionData.class.php index 0523aba..30b10dc 100644 --- a/core/Objects/ConnectionData.class.php +++ b/core/Objects/ConnectionData.class.php @@ -18,7 +18,7 @@ class ConnectionData { $this->properties = array(); } - public function getProperties() { + public function getProperties(): array { return $this->properties; } @@ -26,8 +26,8 @@ class ConnectionData { return $this->properties[$key] ?? $defaultValue; } - public function setProperty($key, $val) { - if(!is_string($val)) { + public function setProperty($key, $val): bool { + if (!is_scalar($val)) { return false; } @@ -35,8 +35,8 @@ class ConnectionData { return true; } - public function getHost() { return $this->host; } - public function getPort() { return $this->port; } - public function getLogin() { return $this->login; } - public function getPassword() { return $this->password; } + public function getHost(): string { return $this->host; } + public function getPort(): int { return $this->port; } + public function getLogin(): string { return $this->login; } + public function getPassword(): string { return $this->password; } } \ No newline at end of file diff --git a/core/core.php b/core/core.php index c8c99e5..a3a3774 100644 --- a/core/core.php +++ b/core/core.php @@ -5,7 +5,7 @@ if (is_file($autoLoad)) { require_once $autoLoad; } -define("WEBBASE_VERSION", "1.4.3"); +define("WEBBASE_VERSION", "1.4.4"); spl_autoload_extensions(".php"); spl_autoload_register(function($class) {