Skip to content
This repository has been archived by the owner on Nov 23, 2020. It is now read-only.

Commit

Permalink
Improved performance
Browse files Browse the repository at this point in the history
  • Loading branch information
hongaar committed Nov 16, 2015
1 parent e1e979c commit 33e0aa9
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 28 deletions.
2 changes: 1 addition & 1 deletion compact/semaltblocker.php

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion scripts/timer.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function mockReferer($referer)
$_SERVER["HTTP_REFERER"] = $referer;
}

$c = 10;
$c = 100;

echo "Testing empty referer : ";
mockReferer('');
Expand Down
16 changes: 9 additions & 7 deletions src/SemaltBlocker/Blocker.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,15 +168,17 @@ public static function isRefererOnBlocklist()
}

$path = Domainparser::getPath($referer);
if (substr_count($blocklist, self::SEPERATOR . $rootDomain . $path . self::SEPERATOR)) {
self::$reason = "Blocking because referer root domain/path (" . $rootDomain . $path . ") is found on blocklist";
if (trim($path, '/')) {
if (substr_count($blocklist, self::SEPERATOR . $rootDomain . $path . self::SEPERATOR)) {
self::$reason = "Blocking because referer root domain/path (" . $rootDomain . $path . ") is found on blocklist";

return true;
}
if (substr_count($blocklist, self::SEPERATOR . $hostname . $path . self::SEPERATOR)) {
self::$reason = "Blocking because referer hostname/path (" . $hostname . $path . ") is found on blocklist";
return true;
}
if (substr_count($blocklist, self::SEPERATOR . $hostname . $path . self::SEPERATOR)) {
self::$reason = "Blocking because referer hostname/path (" . $hostname . $path . ") is found on blocklist";

return true;
return true;
}
}

self::$reason = "Not blocking because referer (" . $referer . ") is not matched against blocklist";
Expand Down
50 changes: 32 additions & 18 deletions src/SemaltBlocker/Domainparser.php

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tests/SemaltTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function testBlocked()
$this->assertTrue(Blocker::blocked(), 'Should block bad referer http://' . $badReferral);

// Referer is a subdomain of blocked domain (only on root domains with no path)
if (($root = Domainparser::getRootDomain($badReferral)) === $badReferral && !Domainparser::getPath($badReferral)) {
if (($root = Domainparser::getRootDomain($badReferral)) === $badReferral && !trim(Domainparser::getPath($badReferral), '/')) {
$this->mockReferer('http://test.' . $badReferral);
$this->assertTrue(Blocker::blocked(), 'Should block bad referer http://test.' . $badReferral);
}
Expand Down

0 comments on commit 33e0aa9

Please sign in to comment.