Small bit of code cleanup
This commit is contained in:
parent
45310527cf
commit
fee505f7dd
2 changed files with 9 additions and 27 deletions
|
@ -3,7 +3,6 @@
|
||||||
[][travis]
|
[][travis]
|
||||||
[][coveralls]
|
[][coveralls]
|
||||||
[][packagist]
|
[][packagist]
|
||||||
[][gittip]
|
|
||||||
|
|
||||||
PHP Wrapper for Project Honey Pot. Compatible with PHP 5.3+ and HHVM.
|
PHP Wrapper for Project Honey Pot. Compatible with PHP 5.3+ and HHVM.
|
||||||
|
|
||||||
|
|
|
@ -8,8 +8,8 @@
|
||||||
* Licensed under The MIT License.
|
* Licensed under The MIT License.
|
||||||
* Redistribution of these files must retain the above copyright notice.
|
* Redistribution of these files must retain the above copyright notice.
|
||||||
*
|
*
|
||||||
* @author Josh Sherman <josh@gravityblvd.com>
|
* @author Josh Sherman <hello@joshtronic.com>
|
||||||
* @copyright Copyright 2012-2014, Josh Sherman
|
* @copyright Copyright 2012-2015, Josh Sherman
|
||||||
* @license http://www.opensource.org/licenses/mit-license.html
|
* @license http://www.opensource.org/licenses/mit-license.html
|
||||||
* @link https://github.com/joshtronic/php-projecthoneypot
|
* @link https://github.com/joshtronic/php-projecthoneypot
|
||||||
* @link http://www.projecthoneypot.org/httpbl_configure.php
|
* @link http://www.projecthoneypot.org/httpbl_configure.php
|
||||||
|
@ -37,12 +37,9 @@ class ProjectHoneyPot
|
||||||
*/
|
*/
|
||||||
public function __construct($api_key)
|
public function __construct($api_key)
|
||||||
{
|
{
|
||||||
if (preg_match('/^[a-z]{12}$/', $api_key))
|
if (preg_match('/^[a-z]{12}$/', $api_key)) {
|
||||||
{
|
|
||||||
$this->api_key = $api_key;
|
$this->api_key = $api_key;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
throw new \Exception('You must specify a valid API key.');
|
throw new \Exception('You must specify a valid API key.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -59,8 +56,7 @@ class ProjectHoneyPot
|
||||||
public function query($ip_address)
|
public function query($ip_address)
|
||||||
{
|
{
|
||||||
// Validates the IP format
|
// Validates the IP format
|
||||||
if (filter_var($ip_address, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 | FILTER_FLAG_NO_PRIV_RANGE))
|
if (filter_var($ip_address, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 | FILTER_FLAG_NO_PRIV_RANGE)) {
|
||||||
{
|
|
||||||
// Flips the script, err, IP address
|
// Flips the script, err, IP address
|
||||||
$octets = explode('.', $ip_address);
|
$octets = explode('.', $ip_address);
|
||||||
krsort($octets);
|
krsort($octets);
|
||||||
|
@ -70,12 +66,10 @@ class ProjectHoneyPot
|
||||||
$results = $this->dns_get_record($reversed_ip);
|
$results = $this->dns_get_record($reversed_ip);
|
||||||
|
|
||||||
// Processes the results
|
// Processes the results
|
||||||
if (isset($results[0]['ip']))
|
if (isset($results[0]['ip'])) {
|
||||||
{
|
|
||||||
$results = explode('.', $results[0]['ip']);
|
$results = explode('.', $results[0]['ip']);
|
||||||
|
|
||||||
if ($results[0] == 127)
|
if ($results[0] == 127) {
|
||||||
{
|
|
||||||
$results = array(
|
$results = array(
|
||||||
'last_activity' => $results[1],
|
'last_activity' => $results[1],
|
||||||
'threat_score' => $results[2],
|
'threat_score' => $results[2],
|
||||||
|
@ -83,40 +77,31 @@ class ProjectHoneyPot
|
||||||
);
|
);
|
||||||
|
|
||||||
// Creates an array of categories
|
// Creates an array of categories
|
||||||
switch ($results['categories'])
|
switch ($results['categories']) {
|
||||||
{
|
|
||||||
case 0:
|
case 0:
|
||||||
$categories = array('Search Engine');
|
$categories = array('Search Engine');
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
$categories = array('Suspicious');
|
$categories = array('Suspicious');
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
$categories = array('Harvester');
|
$categories = array('Harvester');
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 3:
|
case 3:
|
||||||
$categories = array('Suspicious', 'Harvester');
|
$categories = array('Suspicious', 'Harvester');
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 4:
|
case 4:
|
||||||
$categories = array('Comment Spammer');
|
$categories = array('Comment Spammer');
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 5:
|
case 5:
|
||||||
$categories = array('Suspicious', 'Comment Spammer');
|
$categories = array('Suspicious', 'Comment Spammer');
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 6:
|
case 6:
|
||||||
$categories = array('Harvester', 'Comment Spammer');
|
$categories = array('Harvester', 'Comment Spammer');
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 7:
|
case 7:
|
||||||
$categories = array('Suspicious', 'Harvester', 'Comment Spammer');
|
$categories = array('Suspicious', 'Harvester', 'Comment Spammer');
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
$categories = array('Reserved for Future Use');
|
$categories = array('Reserved for Future Use');
|
||||||
break;
|
break;
|
||||||
|
@ -127,9 +112,7 @@ class ProjectHoneyPot
|
||||||
return $results;
|
return $results;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
return array('error' => 'Invalid IP address.');
|
return array('error' => 'Invalid IP address.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue