Compare commits

...

2 commits

Author SHA1 Message Date
n1rwana
3ffb158dd7
Merge a16e15eaef into 89157a832b 2024-09-15 23:59:38 +00:00
n1rwana
a16e15eaef
Фикс проверки заблокированных ссылок 2023-08-05 14:49:41 +03:00
4 changed files with 10 additions and 7 deletions

View file

@ -39,7 +39,7 @@ class BannedLink extends RowModel
function getRegexpRule(): string function getRegexpRule(): string
{ {
return addslashes("/" . $this->getDomain() . $this->getRawRegexp() . "/"); return "/^" . $this->getDomain() . "\/" . $this->getRawRegexp() . "$/i";
} }
function getRawRegexp(): string function getRawRegexp(): string

View file

@ -3,6 +3,7 @@ namespace openvk\Web\Models\Repositories;
use Chandler\Database\DatabaseConnection as DB; use Chandler\Database\DatabaseConnection as DB;
use Nette\Database\Table\{ActiveRow, Selection}; use Nette\Database\Table\{ActiveRow, Selection};
use openvk\Web\Models\Entities\BannedLink; use openvk\Web\Models\Entities\BannedLink;
use function Symfony\Component\Translation\t;
class BannedLinks class BannedLinks
{ {
@ -43,7 +44,7 @@ class BannedLinks
function isDomainBanned(string $domain): bool 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 function genLinks($rules): \Traversable
@ -57,12 +58,14 @@ class BannedLinks
foreach($links as $link) foreach($links as $link)
if (preg_match($link->getRegexpRule(), $uri)) if (preg_match($link->getRegexpRule(), $uri))
yield $link->getId(); yield $link->getId();
else if ($this->isDomainBanned($link->getDomain()))
yield $link->getId();
} }
function check(string $url): ?array function check(string $url): ?array
{ {
$uri = strstr(str_replace(["https://", "http://"], "", $url), "/", true); $uri = str_replace(["https://", "http://"], "", $url);
$domain = str_replace("www.", "", $uri); $domain = explode("/", str_replace("www.", "", $uri))[0];
$rules = $this->getByDomain($domain); $rules = $this->getByDomain($domain);
if (is_null($rules)) if (is_null($rules))

View file

@ -481,7 +481,7 @@ final class AdminPresenter extends OpenVKPresenter
if ($link) { if ($link) {
$link->setDomain($new_domain ?? $this->postParam("link")); $link->setDomain($new_domain ?? $this->postParam("link"));
$link->setReason($new_reason); $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(); $link->save();
} else { } else {
if (!$new_domain) if (!$new_domain)
@ -490,7 +490,7 @@ final class AdminPresenter extends OpenVKPresenter
$link = new BannedLink; $link = new BannedLink;
$link->setDomain($new_domain); $link->setDomain($new_domain);
$link->setReason($new_reason); $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->setInitiator($this->user->identity->getId());
$link->save(); $link->save();

View file

@ -7,7 +7,7 @@ final class AwayPresenter extends OpenVKPresenter
{ {
function renderAway(): void 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 (OPENVK_ROOT_CONF["openvk"]["preferences"]["susLinks"]["warnings"])
if (sizeof($checkBanEntries) > 0) if (sizeof($checkBanEntries) > 0)
$this->pass("openvk!Away->view", $checkBanEntries[0]); $this->pass("openvk!Away->view", $checkBanEntries[0]);