**Added**
- Support for clear address request (remove own report for a given IP address)

**Changed**
- internal refactoring
This commit is contained in:
kristuff 2021-01-08 15:51:29 +01:00
commit ed9e4bd8fb
4 changed files with 61 additions and 26 deletions

View file

@ -14,11 +14,11 @@ Features
- IP block check request **✓** - IP block check request **✓**
- Blacklist request **✓** - Blacklist request **✓**
- Single report request **✓** - Single report request **✓**
- Clear address request (remove own reports) **✓**
- Auto cleaning report comment from sensitive data **✓** - Auto cleaning report comment from sensitive data **✓**
TODO **Not implemented:**
- *\[TODO\] clear address request* - *\[TODO\] Bulk report Api request*
- *\[TODO\] Bulk report request*
Requirements Requirements
------------ ------------
@ -34,7 +34,7 @@ Deploy with composer:
```json ```json
... ...
"require": { "require": {
"kristuff/abuseipdb": ">=0.9.4-stable" "kristuff/abuseipdb": ">=0.9.5-stable"
}, },
``` ```

View file

@ -14,7 +14,7 @@
* For the full copyright and license information, please view the LICENSE * For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code. * file that was distributed with this source code.
* *
* @version 0.9.4 * @version 0.9.5
* @copyright 2020-2021 Kristuff * @copyright 2020-2021 Kristuff
*/ */
@ -120,7 +120,18 @@ abstract class ApiDefintion
// Abuse was targeted at an "Internet of Things" type device. Include // Abuse was targeted at an "Internet of Things" type device. Include
// information about what type of device was targeted in the comments. // information about what type of device was targeted in the comments.
['oit' , '23', 'IoT Targeted', true], ['oit' , '23', 'IoT Targeted', true],
]; ];
/**
* Get the list of report categories
*
* @access public
* @return array
*/
public function getCategories()
{
return $this->aipdbApiCategories;
}
/** /**
* Get the category id corresponding to given name * Get the category id corresponding to given name

View file

@ -14,7 +14,7 @@
* For the full copyright and license information, please view the LICENSE * For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code. * file that was distributed with this source code.
* *
* @version 0.9.4 * @version 0.9.5
* @copyright 2020-2021 Kristuff * @copyright 2020-2021 Kristuff
*/ */
@ -86,13 +86,13 @@ class ApiHandler extends ApiDefintion
} }
/** /**
* Get a new instance of ApiManager with config stored in a Json file * Get a new instance of ApiHandler with config stored in a Json file
* *
* @access public * @access public
* @static * @static
* @param string $configPath The configuration file path * @param string $configPath The configuration file path
* *
* @return \Kristuff\AbuseIPDB\ApiManager * @return \Kristuff\AbuseIPDB\ApiHandler
* @throws \InvalidArgumentException If the given file does not exist * @throws \InvalidArgumentException If the given file does not exist
* @throws \Kristuff\AbuseIPDB\InvalidPermissionException If the given file is not readable * @throws \Kristuff\AbuseIPDB\InvalidPermissionException If the given file is not readable
*/ */
@ -123,17 +123,6 @@ class ApiHandler extends ApiDefintion
return $app; return $app;
} }
/**
* Get the list of report categories
*
* @access public
* @return array
*/
public function getCategories()
{
return $this->aipdbApiCategories;
}
/** /**
* Performs a 'report' api request * Performs a 'report' api request
* *
@ -149,7 +138,7 @@ class ApiHandler extends ApiDefintion
* @param string $ip The ip to report * @param string $ip The ip to report
* @param string $categories The report categories * @param string $categories The report categories
* @param string $message The report message * @param string $message The report message
* @param bool $returnArray True to return an indexed array instead of an object. Default is false. * @param bool $returnArray True to return an indexed array instead of object. Default is false.
* *
* @return object|array * @return object|array
* @throws \InvalidArgumentException * @throws \InvalidArgumentException
@ -226,7 +215,7 @@ class ApiHandler extends ApiDefintion
* @access public * @access public
* @param string $network The network to check * @param string $network The network to check
* @param int $maxAge Max age in days * @param int $maxAge Max age in days
* @param bool $returnArray True to return an indexed array instead of an object. Default is false. * @param bool $returnArray True to return an indexed array instead of object. Default is false.
* *
* @return object|array * @return object|array
* @throws \InvalidArgumentException when maxAge is less than 1 or greater than 365, or when network value was not set. * @throws \InvalidArgumentException when maxAge is less than 1 or greater than 365, or when network value was not set.
@ -254,6 +243,42 @@ class ApiHandler extends ApiDefintion
return json_decode($response, $returnArray); return json_decode($response, $returnArray);
} }
/**
* Perform a 'clear-address' api request
*
* Sample response:
*
* {
* "data": {
* "numReportsDeleted": 0
* }
* }
*
*
* @access public
* @param string $ip The ip to check
* @param bool $returnArray True to return an indexed array instead of object. Default is false.
*
* @return object|array
* @throws \InvalidArgumentException When ip value was not set.
*/
public function clear(string $ip = null, bool $returnArray = false)
{
// ip must be set
if (empty($ip)){
throw new \InvalidArgumentException('ip argument must be set (null given)');
}
// minimal data
$data = [
'ipAddress' => $ip,
];
$response = $this->apiRequest('check', $data, 'DELETE', $returnArray) ;
return json_decode($response, $returnArray);
}
/** /**
* Perform a 'check' api request * Perform a 'check' api request
* *
@ -261,7 +286,7 @@ class ApiHandler extends ApiDefintion
* @param string $ip The ip to check * @param string $ip The ip to check
* @param int $maxAge Max age in days * @param int $maxAge Max age in days
* @param bool $verbose True to get the full response. Default is false * @param bool $verbose True to get the full response. Default is false
* @param bool $returnArray True to return an indexed array instead of an object. Default is false. * @param bool $returnArray True to return an indexed array instead of object. Default is false.
* *
* @return object|array * @return object|array
* @throws \InvalidArgumentException when maxAge is less than 1 or greater than 365, or when ip value was not set. * @throws \InvalidArgumentException when maxAge is less than 1 or greater than 365, or when ip value was not set.
@ -289,7 +314,6 @@ class ApiHandler extends ApiDefintion
$data['verbose'] = true; $data['verbose'] = true;
} }
// check AbuseIPDB request
$response = $this->apiRequest('check', $data, 'GET', $returnArray) ; $response = $this->apiRequest('check', $data, 'GET', $returnArray) ;
return json_decode($response, $returnArray); return json_decode($response, $returnArray);
@ -301,7 +325,7 @@ class ApiHandler extends ApiDefintion
* @access public * @access public
* @param int $limit The blacklist limit. Default is TODO (the api default limit) * @param int $limit The blacklist limit. Default is TODO (the api default limit)
* @param bool $plainText True to get the response in plain text list. Default is false * @param bool $plainText True to get the response in plain text list. Default is false
* @param bool $returnArray True to return an indexed array instead of an object (when $plainText is set to false). Default is false. * @param bool $returnArray True to return an indexed array instead of object (when $plainText is set to false). Default is false.
* *
* @return object|array * @return object|array
* @throws \InvalidArgumentException When maxAge is not a numeric value, when maxAge is less than 1 or * @throws \InvalidArgumentException When maxAge is not a numeric value, when maxAge is less than 1 or

View file

@ -14,7 +14,7 @@
* For the full copyright and license information, please view the LICENSE * For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code. * file that was distributed with this source code.
* *
* @version 0.9.4 * @version 0.9.5
* @copyright 2020-2021 Kristuff * @copyright 2020-2021 Kristuff
*/ */