diff --git a/Web/Models/Entities/BannedLink.php b/Web/Models/Entities/BannedLink.php index c658225a..70793f9e 100644 --- a/Web/Models/Entities/BannedLink.php +++ b/Web/Models/Entities/BannedLink.php @@ -43,7 +43,7 @@ class BannedLink extends RowModel public function getRegexpRule(): string { - return addslashes("/" . $this->getDomain() . $this->getRawRegexp() . "/"); + return "/^" . $this->getDomain() . "\/" . $this->getRawRegexp() . "$/i"; } public function getRawRegexp(): string diff --git a/Web/Models/Repositories/BannedLinks.php b/Web/Models/Repositories/BannedLinks.php index e048c526..7a44d99d 100644 --- a/Web/Models/Repositories/BannedLinks.php +++ b/Web/Models/Repositories/BannedLinks.php @@ -7,6 +7,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 { @@ -48,7 +49,7 @@ class BannedLinks public 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; } public function genLinks($rules): \Traversable @@ -61,16 +62,17 @@ class BannedLinks public function genEntries($links, $uri): \Traversable { foreach ($links as $link) { - if (preg_match($link->getRegexpRule(), $uri)) { + if (preg_match($link->getRegexpRule(), $uri)) + yield $link->getId(); + else if ($this->isDomainBanned($link->getDomain())) yield $link->getId(); - } } } public 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 ac3aa267..f0f2b04d 100644 --- a/Web/Presenters/AdminPresenter.php +++ b/Web/Presenters/AdminPresenter.php @@ -515,7 +515,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) { @@ -525,7 +525,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 08025100..c24cb032 100644 --- a/Web/Presenters/AwayPresenter.php +++ b/Web/Presenters/AwayPresenter.php @@ -11,12 +11,10 @@ final class AwayPresenter extends OpenVKPresenter { public function renderAway(): void { - $checkBanEntries = (new BannedLinks())->check($this->queryParam("to") . "/"); - if (OPENVK_ROOT_CONF["openvk"]["preferences"]["susLinks"]["warnings"]) { - if (sizeof($checkBanEntries) > 0) { + $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]); - } - } header("HTTP/1.0 302 Found"); header("X-Robots-Tag: noindex, nofollow, noarchive");