Project cleanup
Getting all my ducks in a row before submitting this to Packagist
This commit is contained in:
parent
4069d2ddb9
commit
6dd3b9d26b
3 changed files with 161 additions and 96 deletions
21
LICENSE
Normal file
21
LICENSE
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright (c) 2012-2014 Josh Sherman
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
|
@ -1,96 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Project Honey Pot Class
|
|
||||||
*
|
|
||||||
* @author Josh Sherman
|
|
||||||
* @link http://github.com/joshtronic/php-projecthoneypot
|
|
||||||
* @link http://www.projecthoneypot.org/httpbl_configure.php
|
|
||||||
*/
|
|
||||||
class ProjectHoneyPot
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* API Key
|
|
||||||
*
|
|
||||||
* @access private
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
private $api_key = '';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructor
|
|
||||||
*
|
|
||||||
* @param string $api_key PHP API Key (12 characters)
|
|
||||||
*/
|
|
||||||
public function __construct($api_key)
|
|
||||||
{
|
|
||||||
if (preg_match('/^[a-z]{12}$/', $api_key))
|
|
||||||
{
|
|
||||||
$this->api_key = $api_key;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw new Exception('Y U No Supply Valid API Key?!');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Query API
|
|
||||||
*
|
|
||||||
* @param string $ip_address IPv4 address to check
|
|
||||||
* @return array results from query
|
|
||||||
*/
|
|
||||||
public function query($ip_address)
|
|
||||||
{
|
|
||||||
// Validate the IP format
|
|
||||||
if (filter_var($ip_address, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 | FILTER_FLAG_NO_PRIV_RANGE))
|
|
||||||
{
|
|
||||||
// Flip tha script
|
|
||||||
$octets = explode('.', $ip_address);
|
|
||||||
krsort($octets);
|
|
||||||
$reversed_ip = implode('.', $octets);
|
|
||||||
|
|
||||||
// Perform the query
|
|
||||||
$results = dns_get_record($this->api_key . '.' . $reversed_ip . '.dnsbl.httpbl.org', DNS_A);
|
|
||||||
|
|
||||||
// Process the results
|
|
||||||
if (isset($results[0]['ip']))
|
|
||||||
{
|
|
||||||
$results = explode('.', $results[0]['ip']);
|
|
||||||
|
|
||||||
if ($results[0] == 127)
|
|
||||||
{
|
|
||||||
$results = array(
|
|
||||||
'last_activity' => $results[1],
|
|
||||||
'threat_score' => $results[2],
|
|
||||||
'categories' => $results[3],
|
|
||||||
);
|
|
||||||
|
|
||||||
// Creates an array of categories
|
|
||||||
switch ($results['categories'])
|
|
||||||
{
|
|
||||||
case 0: $results['categories'] = array('Search Engine'); break;
|
|
||||||
case 1: $results['categories'] = array('Suspicious'); break;
|
|
||||||
case 2: $results['categories'] = array('Harvester'); break;
|
|
||||||
case 3: $results['categories'] = array('Suspicious', 'Harvester'); break;
|
|
||||||
case 4: $results['categories'] = array('Comment Spammer'); break;
|
|
||||||
case 5: $results['categories'] = array('Suspicious', 'Comment Spammer'); break;
|
|
||||||
case 6: $results['categories'] = array('Harvester', 'Comment Spammer'); break;
|
|
||||||
case 7: $results['categories'] = array('Suspicious', 'Harvester', 'Comment Spammer'); break;
|
|
||||||
default: $results['categories'] = array('Reserved for Future Use'); break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $results;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return array('error' => 'Invalid IP Address');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
?>
|
|
140
src/ProjectHoneyPot.php
Normal file
140
src/ProjectHoneyPot.php
Normal file
|
@ -0,0 +1,140 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Project Honey Pot Interface
|
||||||
|
*
|
||||||
|
* PHP version 5.3+
|
||||||
|
*
|
||||||
|
* Licensed under The MIT License.
|
||||||
|
* Redistribution of these files must retain the above copyright notice.
|
||||||
|
*
|
||||||
|
* @author Josh Sherman <josh@gravityblvd.com>
|
||||||
|
* @copyright Copyright 2012-2014, Josh Sherman
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.html
|
||||||
|
* @link https://github.com/joshtronic/php-projecthoneypot
|
||||||
|
* @link http://www.projecthoneypot.org/httpbl_configure.php
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace joshtronic;
|
||||||
|
|
||||||
|
class ProjectHoneyPot
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* API Key
|
||||||
|
*
|
||||||
|
* @access private
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $api_key = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
*
|
||||||
|
* Adds the specified API key to the object.
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @param string $api_key PHP API Key (12 characters)
|
||||||
|
*/
|
||||||
|
public function __construct($api_key)
|
||||||
|
{
|
||||||
|
if (preg_match('/^[a-z]{12}$/', $api_key))
|
||||||
|
{
|
||||||
|
$this->api_key = $api_key;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new Exception('You must specify a valid API key.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Query
|
||||||
|
*
|
||||||
|
* Performs a DNS lookup to obtain information about the IP address.
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @param string $ip_address IPv4 address to check
|
||||||
|
* @return array results from query
|
||||||
|
*/
|
||||||
|
public function query($ip_address)
|
||||||
|
{
|
||||||
|
// Validates the IP format
|
||||||
|
if (filter_var($ip_address, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 | FILTER_FLAG_NO_PRIV_RANGE))
|
||||||
|
{
|
||||||
|
// Flips the script, err, IP address
|
||||||
|
$octets = explode('.', $ip_address);
|
||||||
|
krsort($octets);
|
||||||
|
$reversed_ip = implode('.', $octets);
|
||||||
|
|
||||||
|
// Performs the query
|
||||||
|
$results = dns_get_record($this->api_key . '.' . $reversed_ip . '.dnsbl.httpbl.org', DNS_A);
|
||||||
|
|
||||||
|
// Processes the results
|
||||||
|
if (isset($results[0]['ip']))
|
||||||
|
{
|
||||||
|
$results = explode('.', $results[0]['ip']);
|
||||||
|
|
||||||
|
if ($results[0] == 127)
|
||||||
|
{
|
||||||
|
$results = array(
|
||||||
|
'last_activity' => $results[1],
|
||||||
|
'threat_score' => $results[2],
|
||||||
|
'categories' => $results[3],
|
||||||
|
);
|
||||||
|
|
||||||
|
// Creates an array of categories
|
||||||
|
switch ($results['categories'])
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
$categories = array('Search Engine');
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 1:
|
||||||
|
$categories = array('Suspicious');
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 2:
|
||||||
|
$categories = array('Harvester');
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 3:
|
||||||
|
$categories = array('Suspicious', 'Harvester');
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 4:
|
||||||
|
$categories = array('Comment Spammer');
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 5:
|
||||||
|
$categories = array('Suspicious', 'Comment Spammer');
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 6:
|
||||||
|
$categories = array('Harvester', 'Comment Spammer');
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 7:
|
||||||
|
$categories = array('Suspicious', 'Harvester', 'Comment Spammer');
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
$categories = array('Reserved for Future Use');
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
$results['categories'] = $categories;
|
||||||
|
|
||||||
|
return $results;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return array('error' => 'Invalid IP address.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
Loading…
Add table
Add a link
Reference in a new issue