2017 © Pedro Peláez
 

library laravel-abuseipdb

AbuseIpDb for Laravel 5

image

nickurt/laravel-abuseipdb

AbuseIpDb for Laravel 5

  • Thursday, March 1, 2018
  • by nickurt
  • Repository
  • 1 Watchers
  • 8 Stars
  • 4 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Laravel AbuseIpDb

Build Status Total Downloads Latest Stable Version MIT Licensed, (*1)

Installation

Install this package with composer:, (*2)

composer require nickurt/laravel-abuseipdb

Copy the config files for the AbuseIpDb-plugin, (*3)

php artisan vendor:publish --provider="nickurt\AbuseIpDb\ServiceProvider" --tag="config"

Configuration

The AbuseIpDb information can be set with environment values in the .env file (or directly in the config/abusedbip.php file), (*4)

ABUSEIPDB_APIKEY=MY_UNIQUE_APIKEY

Examples

Validation Rule - IsSpamIp

You can use a hidden-field aip in your Form-Request to validate if the request is valid, (*5)

$validator = validator()->make(['aip' => 'aip'], ['aip' => [new \nickurt\AbuseIpDb\Rules\IsSpamIp(
    request()->ip(), 100
)]]);

The IsSpamIp requires a ip and an optional days parameter to validate the request., (*6)

Manually Usage - IsSpamIp

$isSpamIp = \AbuseIpDb::setIp('8.8.8.8')->isSpamIp();

// Same
$isSpamIp = abuseipdb()->setIp('8.8.8.8')->isSpamIp();
$isSpamIp = abuseipdb()->isSpamIp('8.8.8.8');

// Cache the result for 10 minutes (default 10 seconds)
abuseipdb()->setCacheTTL(600);

// Lower the required abuse confidence score from 100 (max) to 90%
abuseipdb()->setSpamThreshold(90);

// Report an IP in categories 18 (Brute-Force) and 22 (SSH)
// For categories see https://www.abuseipdb.com/categories
$updatedAbuseConfidence = abuseipdb()->reportIp('18,22', '127.0.0.1', 'SSH login attempts with user root.');

// Catch exceptions
try {
    abuseipdb()->isSpamIp('invalid-ip');
} catch(\nickurt\AbuseIpDb\AbuseIpDbException $exception) {
    dd($exception->getMessage());

    // "The ip address must be a valid IPv4 or IPv6 address (e.g. 8.8.8.8 or 2001:4860:4860::8888)."
}

try {
    // Do it twice (happens eg if hacker accesses two invalid urls and each reports this IP)
    // Both commands do the same in just two different ways 

    abuseipdb()->setIp('127.0.0.2')->reportIp('18,22');
    abuseipdb()->reportIp('18,22', '127.0.0.2');
} catch(\nickurt\AbuseIpDb\AbuseIpDbException $exception) {
    dd($exception->getMessage());

    // "You can only report the same IP address (`127.0.0.2`) once in 15 minutes."
}

Events

You can listen to the IsSpamIp event, e.g. if you want to log the IsSpamIp-requests in your application, (*7)

IsSpamIp Event

This event will be fired when the request-ip is above the frequency of sending spam nickurt\AbuseIpDb\Events\IsSpamIp, (*8)

Testing

Run the tests with:, (*9)

composer test

The Versions

01/03 2018

dev-master

9999999-dev

AbuseIpDb for Laravel 5

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel abuseipdb

16/02 2018

1.0

1.0.0.0

AbuseIpDb for Laravel 5

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel abuseipdb