First commit
This commit is contained in:
50
src/reporter.php
Executable file
50
src/reporter.php
Executable file
@@ -0,0 +1,50 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
|
||||
require realpath(__DIR__ . '/../boot/init.php');
|
||||
|
||||
$config = parse_ini_file(__DIR__ . '/../config/app.ini', true);
|
||||
$client = new GuzzleHttp\Client([
|
||||
'base_uri' => 'https://api.abuseipdb.com/api/v2/'
|
||||
]);
|
||||
|
||||
$ipAddress = $argv[1];
|
||||
|
||||
$comment = str_replace('infra', '[expunged]', $argv[2]);
|
||||
$comment = str_replace('\\', '', $comment);
|
||||
|
||||
$categories = $argv[3];
|
||||
|
||||
|
||||
if ($ipAddress == $config['security']['ignoreip'])
|
||||
{
|
||||
$logger->error("REPORTER: Refusing to report $ipAddress! (Reason: added in ignoreip)");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
try {
|
||||
$response = $client->request('POST', 'report', [
|
||||
'query' => [
|
||||
'ip' => $ipAddress,
|
||||
'categories' => $categories,
|
||||
'comment' => $comment
|
||||
],
|
||||
'headers' => [
|
||||
'Accept' => 'application/json',
|
||||
'Key' => $config['auth']['abuseipdb_key']
|
||||
],
|
||||
]);
|
||||
|
||||
$logger->info(sprintf("Reported %s to AbuseIPDB.", $ipAddress), json_decode($response->getBody(), true));
|
||||
|
||||
} catch(GuzzleHttp\Exception\ClientException $e) {
|
||||
|
||||
$body = json_decode($e->getResponse()->getBody()->getContents(), true);
|
||||
$logger->error("REPORTER: Failed to report $ipAddress. Check context for details.", $body);
|
||||
exit(1);
|
||||
} catch(GuzzleHttp\Exception\ServerException $se) {
|
||||
$logger->error("Failed to report $ipAddress due to server error.", ['message' => $se->getMessage()]);
|
||||
exit(1);
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user