First commit

This commit is contained in:
2020-12-06 17:58:41 +00:00
commit 2ff729b651
8 changed files with 709 additions and 0 deletions

50
src/reporter.php Executable file
View 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);
}