From b39dd44143d7334a4d40ec0fe16139928710aecf Mon Sep 17 00:00:00 2001 From: Celestora Date: Wed, 13 Oct 2021 23:41:12 +0300 Subject: [PATCH] Settings: Add configurable shortcode length constraint --- Web/Models/Entities/User.php | 10 ++++++---- openvk-example.yml | 1 + 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Web/Models/Entities/User.php b/Web/Models/Entities/User.php index b6a5a824..6913855d 100644 --- a/Web/Models/Entities/User.php +++ b/Web/Models/Entities/User.php @@ -662,9 +662,11 @@ class User extends RowModel $this->stateChanges("left_menu", $mask); } - function setShortCode(?string $code = NULL): ?bool + function setShortCode(?string $code = NULL, bool $force = false): ?bool { if(!is_null($code)) { + if(strlen($code) < OPENVK_ROOT_CONF["openvk"]["preferences"]["shortcodes"]["minLength"] && !$force) + return false; if(!preg_match("%^[a-z][a-z0-9\\.\\_]{0,30}[a-z0-9]$%", $code)) return false; if(in_array($code, OPENVK_ROOT_CONF["openvk"]["preferences"]["shortcodes"]["forbiddenNames"])) @@ -672,9 +674,9 @@ class User extends RowModel if(\Chandler\MVC\Routing\Router::i()->getMatchingRoute("/$code")[0]->presenter !== "UnknownTextRouteStrategy") return false; - $pClub = DatabaseConnection::i()->getContext()->table("groups")->where("shortcode", $code)->fetch(); - if(!is_null($pClub)) - return false; + $pClub = DatabaseConnection::i()->getContext()->table("groups")->where("shortcode", $code)->fetch(); + if(!is_null($pClub)) + return false; } $this->stateChanges("shortcode", $code); diff --git a/openvk-example.yml b/openvk-example.yml index b644d64d..a39dda14 100644 --- a/openvk-example.yml +++ b/openvk-example.yml @@ -10,6 +10,7 @@ openvk: disableLargeUploads: false mode: "basic" shortcodes: + minLength: 3 # won't affect existing short urls or the ones set via admin panel forbiddenNames: - "index.php" security: