Skip to content

Commit

Permalink
v0.9.17
Browse files Browse the repository at this point in the history
**Changes**
- **New** **timeout** option for cURL requests.
A default value can be defined in configuration file (`timout` key in `[common]` section), and can be overwritten in command line (`-t` | `--timeout` options available in all API request commands). Timeout is expressed in **milliseconds**.
- **New** man page and changelog now available in `.deb` package
- Formatting
  • Loading branch information
kristuff authored Dec 7, 2021
2 parents 66be91c + b369ee7 commit 54ba876
Show file tree
Hide file tree
Showing 17 changed files with 211 additions and 29 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ More infos
----------
- [Project website](https://kristuff.fr/projects/abuseipdbcli)
- [Api documentation](https://kristuff.fr/projects/abuseipdbcli/doc)
- [Config/Install guide](https://kristuff.fr/projects/abuseipdbcli/technical#configuration)
- [Install](https://kristuff.fr/projects/abuseipdbcli/technical#install)
- [Config guide](https://kristuff.fr/projects/abuseipdbcli/technical#configuration)
- [Fail2ban integration](https://kristuff.fr/projects/abuseipdbcli/technical#fail2ban)

Screenshots
Expand Down
2 changes: 1 addition & 1 deletion bin/abuseipdb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @version 0.9.16
* @version 0.9.17
* @copyright 2020-2021 Kristuff
*/

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"require": {
"php": ">=7.1",
"kristuff/mishell": "^1.5-stable",
"kristuff/abuseipdb": "^0.9.13-stable"
"kristuff/abuseipdb": "^0.9.14-stable"
},
"autoload": {
"psr-4": {
Expand Down
14 changes: 7 additions & 7 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion config/conf.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
; \__,_|_.__/\_,_/__/\___|___|_| |___/|___/
;
; Kristuff\AbuseIPDB-client configuration file.
; v0.9.16 | (c) Kristuff <[email protected]>
; v0.9.17 | (c) Kristuff <[email protected]>

; -----------------------------------------------------------
; WARNING: In most of the cases you should not modify this
Expand All @@ -23,6 +23,13 @@
; api_key= "1234"
api_key=

; timeout:
; The maximum number of milliseconds to allow cURL functions to execute. If libcurl is
; built to use the standard system name resolver, that portion of the connect will still
; use full-second resolution for timeouts with a minimum timeout allowed of one second.
; Default is 0 (no timeout)
timeout=0

[report]
; self_ips:
; Represents the ips or domain list to exclude from report messages (email address are already removed)
Expand Down
6 changes: 6 additions & 0 deletions create_package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ rm -rf debian
mkdir -p debian/DEBIAN
mkdir -p debian/usr/lib/abuseipdb-client
mkdir -p debian/usr/share/doc/abuseipdb-client
mkdir -p debian/usr/share/man/man1
mkdir -p debian/etc/abuseipdb-client

# populate the debian directory
Expand All @@ -16,11 +17,16 @@ cp deb/postinst.sh debian/DEBIAN/postinst
cp deb/prerm.sh debian/DEBIAN/prerm
cp config/conf.ini debian/etc/abuseipdb-client
cp deb/copyright debian/usr/share/doc/abuseipdb-client
cp deb/changelog debian/usr/share/doc/abuseipdb-client/changelog.Debian
gzip -9 -n debian/usr/share/doc/abuseipdb-client/changelog.Debian
cp LICENSE debian/usr/lib/abuseipdb-client
cp -R bin debian/usr/lib/abuseipdb-client
cp -R src debian/usr/lib/abuseipdb-client
cp -R vendor debian/usr/lib/abuseipdb-client

# convert and deploy man page
/usr/bin/pandoc --standalone --to man deb/man.md -o debian/usr/share/man/man1/abuseipdb.1

# Packages should't be updated manually, but keep all source code..
cp composer.json debian/usr/lib/abuseipdb-client
cp composer.lock debian/usr/lib/abuseipdb-client
Expand Down
30 changes: 30 additions & 0 deletions deb/changelog
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
abuseipdb-client (0.9.17) unstable; urgency=low

* New feature: timeout for all cURL request can be defined in conf.ini
or from command line using the -t | --timeout option. Timeout is expressed
in milliseconds.
* A man page is now available

-- kristuff <[email protected]> Tue, 07 Dec 2021 19:00:00 +0100

abuseipdb-client (0.9.16) unstable; urgency=low

* Fix php doc, typo, formatting in source code
* Include composer.json and composer.lock in .deb package

-- kristuff <[email protected]> Sun, 28 Nov 2021 19:00:00 +0100

abuseipdb-client (0.9.15) unstable; urgency=low

* Break change Configuration is now in INI format and located in a conf.ini file
(with possible override in a local.ini file) instead of json files.
* The save-key command has been removed.
* When installing the .deb package, config is now located in /etc/abuseipdb-client/

-- kristuff <[email protected]> Tue, 23 Nov 2021 19:00:00 +0100

abuseipdb-client (0.9.14) unstable; urgency=low

* Initial release

-- kristuff <[email protected]> Wed, 10 Nov 2021 19:00:00 +0100
4 changes: 2 additions & 2 deletions deb/control
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: abuseipdb-client
Version: 0.9.16
Version: 0.9.17
Maintainer: kristuff <[email protected]>
Architecture: all
Depends: php, php-curl
Description: CLI tool to check, report IP address, download blacklists with AbuseIPDB API v2
Description: AbuseIPDB APIv2 client: check, report IP address, download blacklist
Priority: optional
Section: utils
98 changes: 98 additions & 0 deletions deb/man.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
% ABUSEIPDB(1) Abuseipdb Client User Manuals
% Kristuff
% December 7, 2021

# NAME

abuseipdb - check, report IP addresses download blacklist with AbuseIPDB API v2.

# SYNOPSIS

abuseipdb COMMANDE [*OPTIONS*]...

# DESCRIPTION

**abuseipdb** is a client for AbuseIPDB API v2. You can use it to check IP addresses or subnet,
report IP addressess, clear your report for a given IP, or download blacklist.

# COMMANDES

-h, \--help
: Displays a short-help text and exits.

-G, \--config
: Displays the current config and exits.

-L, \--list
: Displays the list report categories and exits.

-C *IP*, \--check *IP*
: Performs a check request for the given IP address. A valid IPv4 or IPv6 address is required.

-R *IP*, \--report *IP*
: Performs a report request for the given IP address. A valid IPv4 or IPv6 address is required.

-V *FILE*, \--bulk-report FILE
: Performs a bulk-report request sending a csv file. A valid file name or full path is required.

-E *IP*, \--clear *IP*
: Remove own reports for the given IP address. A valid IPv4 or IPv6 address is required.

-K *NETWORK*, \--checkblock *NETWORK*
: Performs a check-block request for the given network. A valid subnet (v4 or v6) denoted with
CIDR notation is required.

-B, \--blacklist
: Performs a blacklist request: get a list of reported IPs.

\---version
: Prints the current version.


# OPTIONS

-d *DAYS*, \--days *DAYS*
: For a check or check-block request, defines the maxAgeDays. Min is 1, max is 365, default is 30.

-c *CATEGORIES*, \--categories *CATEGORIES*
: For a report request, defines the report category(ies). Categories must be separate by a comma.
Some catgeries cannot be used alone. A category can be represented by its shortname or by its id.
Use abuseipdb -L to print the categories list.

-m *MESSAGE*, \--message *MESSAGE*
: For a report request, defines the message to send with report. Message is required for all report
requests.

-l *LIMIT*, \--limit *LIMIT*
: For a blacklist request, defines the limit (default is 1000). For a check request with verbose flag,
sets the max number of last reports displayed (default is 10). For a check-block request, sets the
max number of IPs displayed (default is 0 mean no limit).

-o *FORMAT*, \--output *FORMAT*
: Defines the output format for API requests. Default is a colorized report, possible formats are
json or plaintext. Plaintext option prints partial response (blacklist: IPs list, check or report:
confidence score only, check-block: reported IP list with confidence score, bulk-report:
number of saved reports, clear: number of deleted reports).

-s *SCORE*, \--score *SCORE*
: For a blacklist request, sets the confidence score minimum. The confidence minimum must be between
25 and 100. This parameter is subscriber feature (not honored otherwise, allways 100).

-t *TIMEOUT*, \--timeout *TIMEOUT*
: Define the timeout in API request and overwrite the value defined in conf.ini or local.ini.
Timeout is expressed in milliseconds.

-v, \--verbose
: For a check request, display additional fields like the x last reports. Max number of last reports
is defined in config. This increases request time and response size.

# BUGS

Submit bug reports online at: <https://github.com/kristuff/abuseipdb-cli/issues>

# SEE ALSO

Source code at: <https://github.com/kristuff/abuseipdb-cli>

Full documentation at: <https://kristuff.fr/projects/abuseipdbcli/doc>

50 changes: 43 additions & 7 deletions src/AbstractClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @version 0.9.16
* @version 0.9.17
* @copyright 2020-2021 Kristuff
*/
namespace Kristuff\AbuseIPDB;
Expand All @@ -31,17 +31,17 @@ abstract class AbstractClient extends ShellErrorHandler
/**
* @var string
*/
const SHORT_ARGUMENTS = "o:GLBK:C:d:R:c:m:l:E:V:hvs:";
const SHORT_ARGUMENTS = "o:GLBK:C:d:R:c:m:l:E:V:hvs:t:";

/**
* @var string
*/
const LONG_ARGUMENTS = ['output:', 'config', 'list', 'blacklist', 'check:', 'check-block:', 'days:', 'report:', 'categories:', 'message:', 'limit:', 'clear:',' bulk-report:', 'help', 'verbose', 'score:', 'version'];
const LONG_ARGUMENTS = ['output:', 'config', 'list', 'blacklist', 'check:', 'check-block:', 'days:', 'report:', 'categories:', 'message:', 'limit:', 'clear:',' bulk-report:', 'help', 'verbose', 'score:', 'version', 'timeout:'];

/**
* @var string
*/
const VERSION = 'v0.9.16';
const VERSION = 'v0.9.17';

/**
* @var QuietApiHandler
Expand Down Expand Up @@ -94,7 +94,7 @@ protected static function parseCommand(array $arguments): bool
}
foreach(self::$mainCommands as $cmd){
if (self::inArguments($arguments, $cmd[0], $cmd[1])){
self::createHandler();
self::createHandler($arguments);
self::setOutputFormat($arguments);
call_user_func(__NAMESPACE__.'\AbuseIPDBClient::'.$cmd[2], $arguments);
return true;
Expand Down Expand Up @@ -125,10 +125,11 @@ protected static function setOutputFormat(array $arguments): void
*
* @access protected
* @static
* @param array $arguments
*
* @return void
*/
protected static function createHandler(): void
protected static function createHandler(array $arguments): void
{
try {
$mainConfPath = self::$configPath . DIRECTORY_SEPARATOR . 'conf.ini';
Expand All @@ -141,8 +142,18 @@ protected static function createHandler(): void

$selfIps = self::extractSelfIpsFromConf($mainConfigArray, $localConfigArray);
$apiKey = self::extractApiKeyFromConf($mainConfigArray, $localConfigArray);
$timeout = self::extractNumericFromConf('timeout',$mainConfigArray, $localConfigArray, 0);

self::$api = new QuietApiHandler($apiKey, $selfIps);
// look into arguments for possible overwrite for timeout
if (self::inArguments($arguments, 't', 'timeout')){
$timeout = self::getArgumentValue($arguments, 't', 'timeout');
}

if (!is_numeric($timeout)){
throw new \RuntimeException('Invalid timeout argument, must be numeric.');
}

self::$api = new QuietApiHandler($apiKey, $selfIps, intval($timeout));
} catch (\Exception $e) {
self::error($e->getMessage());
self::printFooter();
Expand Down Expand Up @@ -201,6 +212,31 @@ protected static function extractApiKeyFromConf(array $conf, array $localConf):
return $key;
}

/**
* Extract numeric value from configuration array
*
* @access protected
* @static
* @param string $key The config key
* @param array $conf The main configuration array
* @param array $localConf The local configuration array
* @param int $default The default value if empty
*
* @return int
*/
protected static function extractNumericFromConf(string $key, array $conf, array $localConf, int $default): int
{
if (array_key_exists($key, $localConf) && is_numeric($localConf[$key])){
return intval($localConf[$key]);
}

if (array_key_exists($key, $conf) && is_numeric($conf[$key])){
return intval($conf[$key]);
}

return $default;
}

/**
* Load a config file
*
Expand Down
7 changes: 6 additions & 1 deletion src/AbuseIPDBClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @version 0.9.16
* @version 0.9.17
* @copyright 2020-2021 Kristuff
*/
namespace Kristuff\AbuseIPDB;
Expand Down Expand Up @@ -176,6 +176,10 @@ protected static function printHelp(): void
Console::log(' For a blacklist request, sets the confidence score minimum. The confidence minimum ', 'lightgray');
Console::log(' must be between 25 and 100. This parameter is subscriber feature (not honored otherwise, allways 100).', 'lightgray');
Console::log();
Console::log(Console::text(' -t, --timeout ', 'white'). Console::text('TIMEOUT', 'yellow', 'underline'));
Console::log(' Define the timeout in API request and overwrite the value defined in conf.ini or local.ini.', 'lightgray');
Console::log(' Timeout is expressed in milliseconds.', 'lightgray');
Console::log();
Console::log(Console::text(' -v, --verbose ', 'white'));
Console::log(' For a check request, display additional fields like the x last reports. This increases ', 'lightgray');
Console::log(Console::text(' request time and response size. Max number of last reports displayed can be changed with the ', 'lightgray'));
Expand All @@ -202,6 +206,7 @@ protected static function printConfig(): void
self::printTitle(Console::text(' ► Current configuration ', 'darkgray'));

Console::log(Console::text(' api_key:[', 'white') . Console::text($conf['apiKey'], 'green') . Console::text(']', 'white'));
Console::log(Console::text(' timeout:[', 'white') . Console::text($conf['timeout'], 'green') . Console::text(']', 'white'));
Console::log(Console::text(' self_ips:', 'white'));

foreach ($conf['selfIps'] as $ip) {
Expand Down
2 changes: 1 addition & 1 deletion src/BulkReportTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @version 0.9.16
* @version 0.9.17
* @copyright 2020-2021 Kristuff
*/
namespace Kristuff\AbuseIPDB;
Expand Down
Loading

0 comments on commit 54ba876

Please sign in to comment.