From a16e15eaefecb7676fe39ff6d3d952577f6ed8d0 Mon Sep 17 00:00:00 2001 From: n1rwana Date: Sat, 5 Aug 2023 14:49:41 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A4=D0=B8=D0=BA=D1=81=20=D0=BF=D1=80=D0=BE?= =?UTF-8?q?=D0=B2=D0=B5=D1=80=D0=BA=D0=B8=20=D0=B7=D0=B0=D0=B1=D0=BB=D0=BE?= =?UTF-8?q?=D0=BA=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=D0=BD=D1=8B=D1=85=20?= =?UTF-8?q?=D1=81=D1=81=D1=8B=D0=BB=D0=BE=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Web/Models/Entities/BannedLink.php | 2 +- Web/Models/Repositories/BannedLinks.php | 9 ++++++--- Web/Presenters/AdminPresenter.php | 4 ++-- Web/Presenters/AwayPresenter.php | 2 +- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/Web/Models/Entities/BannedLink.php b/Web/Models/Entities/BannedLink.php index 09c42e39..bb71f8a8 100644 --- a/Web/Models/Entities/BannedLink.php +++ b/Web/Models/Entities/BannedLink.php @@ -39,7 +39,7 @@ class BannedLink extends RowModel function getRegexpRule(): string { - return addslashes("/" . $this->getDomain() . $this->getRawRegexp() . "/"); + return "/^" . $this->getDomain() . "\/" . $this->getRawRegexp() . "$/i"; } function getRawRegexp(): string diff --git a/Web/Models/Repositories/BannedLinks.php b/Web/Models/Repositories/BannedLinks.php index 8f93e6fd..81803716 100644 --- a/Web/Models/Repositories/BannedLinks.php +++ b/Web/Models/Repositories/BannedLinks.php @@ -3,6 +3,7 @@ namespace openvk\Web\Models\Repositories; use Chandler\Database\DatabaseConnection as DB; use Nette\Database\Table\{ActiveRow, Selection}; use openvk\Web\Models\Entities\BannedLink; +use function Symfony\Component\Translation\t; class BannedLinks { @@ -43,7 +44,7 @@ class BannedLinks function isDomainBanned(string $domain): bool { - return sizeof($this->bannedLinks->where(["link" => $domain, "regexp_rule" => ""])) > 0; + return sizeof($this->bannedLinks->where(["domain" => $domain, "regexp_rule" => ""])) > 0; } function genLinks($rules): \Traversable @@ -57,12 +58,14 @@ class BannedLinks foreach($links as $link) if (preg_match($link->getRegexpRule(), $uri)) yield $link->getId(); + else if ($this->isDomainBanned($link->getDomain())) + yield $link->getId(); } function check(string $url): ?array { - $uri = strstr(str_replace(["https://", "http://"], "", $url), "/", true); - $domain = str_replace("www.", "", $uri); + $uri = str_replace(["https://", "http://"], "", $url); + $domain = explode("/", str_replace("www.", "", $uri))[0]; $rules = $this->getByDomain($domain); if (is_null($rules)) diff --git a/Web/Presenters/AdminPresenter.php b/Web/Presenters/AdminPresenter.php index ff21612b..02f94733 100644 --- a/Web/Presenters/AdminPresenter.php +++ b/Web/Presenters/AdminPresenter.php @@ -429,7 +429,7 @@ final class AdminPresenter extends OpenVKPresenter if ($link) { $link->setDomain($new_domain ?? $this->postParam("link")); $link->setReason($new_reason); - $link->setRegexp_rule($this->postParam("regexp")); + $link->setRegexp_rule(mb_strlen(trim($this->postParam("regexp"))) > 0 ? $this->postParam("regexp") : ""); $link->save(); } else { if (!$new_domain) @@ -438,7 +438,7 @@ final class AdminPresenter extends OpenVKPresenter $link = new BannedLink; $link->setDomain($new_domain); $link->setReason($new_reason); - $link->setRegexp_rule($this->postParam("regexp")); + $link->setRegexp_rule(mb_strlen(trim($this->postParam("regexp"))) > 0 ? $this->postParam("regexp") : ""); $link->setInitiator($this->user->identity->getId()); $link->save(); diff --git a/Web/Presenters/AwayPresenter.php b/Web/Presenters/AwayPresenter.php index 18c7cca7..e1fea17a 100644 --- a/Web/Presenters/AwayPresenter.php +++ b/Web/Presenters/AwayPresenter.php @@ -7,7 +7,7 @@ final class AwayPresenter extends OpenVKPresenter { function renderAway(): void { - $checkBanEntries = (new BannedLinks)->check($this->queryParam("to") . "/"); + $checkBanEntries = (new BannedLinks)->check($this->queryParam("to")); if (OPENVK_ROOT_CONF["openvk"]["preferences"]["susLinks"]["warnings"]) if (sizeof($checkBanEntries) > 0) $this->pass("openvk!Away->view", $checkBanEntries[0]);