1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* _ ___ ___ ___ ___ |
5
|
|
|
* __ _| |__ _ _ ___ ___|_ _| _ \ \| _ ) |
6
|
|
|
* / _` | '_ \ || (_-</ -_)| || _/ |) | _ \ |
7
|
|
|
* \__,_|_.__/\_,_/__/\___|___|_| |___/|___/ |
8
|
|
|
* |
9
|
|
|
* This file is part of Kristuff\AbuseIPDB. |
10
|
|
|
* |
11
|
|
|
* (c) Kristuff <[email protected]> |
12
|
|
|
* |
13
|
|
|
* For the full copyright and license information, please view the LICENSE |
14
|
|
|
* file that was distributed with this source code. |
15
|
|
|
* |
16
|
|
|
* @version 1.1 |
17
|
|
|
* @copyright 2020-2022 Kristuff |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
namespace Kristuff\AbuseIPDB; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Class QuietApiHandler |
24
|
|
|
* |
25
|
|
|
* Overwrite ApiHandler with Exception handling |
26
|
|
|
* Instead of Exception, all methods return an ApiResponse that may |
27
|
|
|
* contains errors from the AbuseIPDB API, or internal errors |
28
|
|
|
*/ |
29
|
|
|
class QuietApiHandler extends ApiHandler |
30
|
|
|
{ |
31
|
|
|
/** |
32
|
|
|
* Performs a 'report' api request, with Exception handling |
33
|
|
|
* |
34
|
|
|
* @access public |
35
|
|
|
* @param string $ip The ip to report |
36
|
|
|
* @param string $categories The report category(es) |
37
|
|
|
* @param string $message The report message |
38
|
|
|
* |
39
|
|
|
* @return ApiResponse |
40
|
|
|
*/ |
41
|
|
|
public function report(string $ip, string $categories, string $message): ApiResponse |
42
|
|
|
{ |
43
|
|
|
try { |
44
|
|
|
return parent::report($ip,$categories,$message); |
45
|
|
|
} catch (\Exception $e) { |
46
|
|
|
return ApiResponse::createErrorResponse($e->getMessage()); |
47
|
|
|
} |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Performs a 'bulk-report' api request, with Exception handling |
52
|
|
|
* |
53
|
|
|
* @access public |
54
|
|
|
* @param string $filePath The CSV file path. Could be an absolute or relative path. |
55
|
|
|
* |
56
|
|
|
* @return ApiResponse |
57
|
|
|
*/ |
58
|
|
|
public function bulkReport(string $filePath): ApiResponse |
59
|
|
|
{ |
60
|
|
|
try { |
61
|
|
|
return parent::bulkReport($filePath); |
62
|
|
|
} catch (\Exception $e) { |
63
|
|
|
return ApiResponse::createErrorResponse($e->getMessage()); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Perform a 'clear-address' api request, with Exception handling |
69
|
|
|
* |
70
|
|
|
* @access public |
71
|
|
|
* @param string $ip The IP to clear reports |
72
|
|
|
* |
73
|
|
|
* @return ApiResponse |
74
|
|
|
*/ |
75
|
|
|
public function clearAddress(string $ip): ApiResponse |
76
|
|
|
{ |
77
|
|
|
try { |
78
|
|
|
return parent::clearAddress($ip); |
79
|
|
|
} catch (\Exception $e) { |
80
|
|
|
return ApiResponse::createErrorResponse($e->getMessage()); |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Perform a 'check' api request, with Exception handling |
86
|
|
|
* |
87
|
|
|
* @access public |
88
|
|
|
* @param string $ip The ip to check |
89
|
|
|
* @param int $maxAgeInDays Max age in days. Default is 30. |
90
|
|
|
* @param bool $verbose True to get the full response (last reports and countryName). Default is false |
91
|
|
|
* |
92
|
|
|
* @return ApiResponse |
93
|
|
|
*/ |
94
|
|
|
public function check(string $ip, int $maxAgeInDays = 30, bool $verbose = false): ApiResponse |
95
|
|
|
{ |
96
|
|
|
try { |
97
|
|
|
return parent::check($ip, $maxAgeInDays, $verbose); |
98
|
|
|
} catch (\Exception $e) { |
99
|
|
|
return ApiResponse::createErrorResponse($e->getMessage()); |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Perform a 'check-block' api request, with Exception handling |
105
|
|
|
* |
106
|
|
|
* @access public |
107
|
|
|
* @param string $network The network to check |
108
|
|
|
* @param int $maxAgeInDays The Max age in days, must |
109
|
|
|
* |
110
|
|
|
* @return ApiResponse |
111
|
|
|
*/ |
112
|
|
|
public function checkBlock(string $network, int $maxAgeInDays = 30): ApiResponse |
113
|
|
|
{ |
114
|
|
|
try { |
115
|
|
|
return parent::checkBlock($network, $maxAgeInDays); |
116
|
|
|
} catch (\Exception $e) { |
117
|
|
|
return ApiResponse::createErrorResponse($e->getMessage()); |
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* Perform a 'blacklist' api request, with Exception handling |
123
|
|
|
* |
124
|
|
|
* @access public |
125
|
|
|
* @param int $limit The blacklist limit. Default is 10000 (the api default limit) |
126
|
|
|
* @param bool $plainText True to get the response in plaintext list. Default is false |
127
|
|
|
* @param int $confidenceMinimum The abuse confidence score minimum (subscribers feature). Default is 100. |
128
|
|
|
* The confidence minimum must be between 25 and 100. |
129
|
|
|
* This parameter is a subscriber feature (not honored otherwise). |
130
|
|
|
* |
131
|
|
|
* @return ApiResponse |
132
|
|
|
*/ |
133
|
|
|
public function blacklist(int $limit = 10000, bool $plainText = false, int $confidenceMinimum = 100): ApiResponse |
134
|
|
|
{ |
135
|
|
|
try { |
136
|
|
|
return parent::blacklist($limit, $plainText, $confidenceMinimum); |
137
|
|
|
} catch (\Exception $e) { |
138
|
|
|
return ApiResponse::createErrorResponse($e->getMessage()); |
139
|
|
|
} |
140
|
|
|
} |
141
|
|
|
} |