Compare commits

..

1 commit

Author SHA1 Message Date
07385d37c5
Merge f672e5001a into 00b408c299 2025-02-09 14:28:03 +00:00
5 changed files with 15 additions and 15 deletions

View file

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

View file

@ -7,7 +7,6 @@ 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
{ {
@ -49,7 +48,7 @@ class BannedLinks
public function isDomainBanned(string $domain): bool public function isDomainBanned(string $domain): bool
{ {
return sizeof($this->bannedLinks->where(["domain" => $domain, "regexp_rule" => ""])) > 0; return sizeof($this->bannedLinks->where(["link" => $domain, "regexp_rule" => ""])) > 0;
} }
public function genLinks($rules): \Traversable public function genLinks($rules): \Traversable
@ -62,17 +61,16 @@ class BannedLinks
public function genEntries($links, $uri): \Traversable public function genEntries($links, $uri): \Traversable
{ {
foreach ($links as $link) { 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(); yield $link->getId();
}
} }
} }
public function check(string $url): ?array public function check(string $url): ?array
{ {
$uri = str_replace(["https://", "http://"], "", $url); $uri = strstr(str_replace(["https://", "http://"], "", $url), "/", true);
$domain = explode("/", str_replace("www.", "", $uri))[0]; $domain = str_replace("www.", "", $uri);
$rules = $this->getByDomain($domain); $rules = $this->getByDomain($domain);
if (is_null($rules)) { if (is_null($rules)) {

View file

@ -515,7 +515,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(mb_strlen(trim($this->postParam("regexp"))) > 0 ? $this->postParam("regexp") : ""); $link->setRegexp_rule($this->postParam("regexp"));
$link->save(); $link->save();
} else { } else {
if (!$new_domain) { if (!$new_domain) {
@ -525,7 +525,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(mb_strlen(trim($this->postParam("regexp"))) > 0 ? $this->postParam("regexp") : ""); $link->setRegexp_rule($this->postParam("regexp"));
$link->setInitiator($this->user->identity->getId()); $link->setInitiator($this->user->identity->getId());
$link->save(); $link->save();

View file

@ -11,10 +11,12 @@ final class AwayPresenter extends OpenVKPresenter
{ {
public function renderAway(): void public 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]);
}
}
header("HTTP/1.0 302 Found"); header("HTTP/1.0 302 Found");
header("X-Robots-Tag: noindex, nofollow, noarchive"); header("X-Robots-Tag: noindex, nofollow, noarchive");

View file

@ -38,6 +38,7 @@ body.dimmed > .dimmer #absolute_territory {
} }
.ovk-diag-head { .ovk-diag-head {
height: 25%;
padding: 5px; padding: 5px;
background-color: #757575; background-color: #757575;
border-bottom: 1px solid #3e3e3e; border-bottom: 1px solid #3e3e3e;
@ -48,12 +49,11 @@ body.dimmed > .dimmer #absolute_territory {
.ovk-diag-body { .ovk-diag-body {
padding: 20px; padding: 20px;
overflow-y: auto;
max-height: 80vh
} }
.ovk-diag-action { .ovk-diag-action {
padding: 10px; padding: 10px;
height: 25%;
background-color: #d4d4d4; background-color: #d4d4d4;
text-align: right; text-align: right;
} }