-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Alexander Krasnoyarov
committed
Oct 27, 2016
1 parent
b1e5d95
commit 7f69a57
Showing
7 changed files
with
53 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
namespace WebcrawlerVerifier\DNS; | ||
|
||
use WebcrawlerVerifier\Helper\StringHelper as StringHelper; | ||
|
||
class HostVerifier | ||
{ | ||
public static function verify($host, $allowedHostNames) | ||
{ | ||
return !!array_filter($allowedHostNames, function ($validHost) use ($host) { | ||
return StringHelper::endsWith($validHost, $host) !== false; | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,13 @@ | ||
<?php | ||
namespace WebcrawlerVerifier\DNS; | ||
|
||
use WebcrawlerVerifier\Helper\StringHelper as StringHelper; | ||
|
||
class ReverseVerifier | ||
{ | ||
public static function verify($ip, $allowedHostNames) | ||
{ | ||
$host = gethostbyaddr($ip); | ||
$ipAfterLookup = gethostbyname($host); | ||
|
||
$hostIsValid = !!array_filter($allowedHostNames, function ($validHost) use ($host) { | ||
return StringHelper::endsWith($validHost, $host) !== false; | ||
}); | ||
|
||
return $hostIsValid && $ipAfterLookup === $ip; | ||
return HostVerifier::verify($host, $allowedHostNames) && $ipAfterLookup === $ip; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
namespace WebcrawlerVerifier\Webcrawler; | ||
|
||
use WebcrawlerVerifier\DNS\HostVerifier; | ||
|
||
class BegunWebcrawlerVerifier implements WebcrawlerVerifierInterface | ||
{ | ||
protected $allowedHostNames = ['begun.ru']; | ||
|
||
/** | ||
* Checks whether the given IP address really belongs to a valid host or not | ||
* | ||
* @param $ip string the IP address to check | ||
* @return bool true if the given IP belongs to any of the valid hosts, otherwise false | ||
*/ | ||
public function verify($ip) | ||
{ | ||
return HostVerifier::verify(gethostbyaddr($ip), $this->allowedHostNames); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters