Block malicious scripts using botscout.com protection for your laravel app

Overview

Laravel BotScout

Latest Version on Packagist Build Status SensioLabsInsight Quality Score Total Downloads

bs_logo_full

Protect your website against automated scripts using the botscout.com API.

Installation

You can install the package via composer:

composer require nicolasbeauvais/laravel-botscout

Next, you must install the service provider:

// config/app.php
'providers' => [
    ...
    NicolasBeauvais\LaravelBotScout\BotScoutServiceProvider::class,
];

Add your botscout.com api key to the .env file:

BOTSCOUT_SECRET=your-api-key  

If needed you can also publish the config file:

php artisan vendor:publish --provider="NicolasBeauvais\LaravelBotScout\BotScoutServiceProvider" --tag="config"

If you want to make use of the facade you must install it as well:

// config/app.php
'aliases' => [
    ...
    'BotScout' => NicolasBeauvais\LaravelBotScout\BotScoutFacade::class,
];

Usage

You are highly advised to read the BotScout.com API guide to understand the meaning of each method.

Validator

You can easily use botscout in your existing validators:

// Validate name
$validator = Validator::make(['name' => 'John Doe'], [
  'name' => 'required|botscout_name'
]);

// Validate email
$validator = Validator::make(['email' => '[email protected]'], [
  'email' => 'required|botscout_mail'
]);

// Validate ip
$validator = Validator::make(['ip' => '127.0.0.1'], [
  'ip' => 'required|botscout_ip'
]);

Note that you will need to create the validation message by yourself, as described in the Laravel documentation.

Facade

You can use the BotScout facade anywhere in your app:

BotScout::multi('John Doe', '[email protected]', '127.0.0.1')->isValid();

BotScout::all('John Doe')->isValid();

BotScout::name('John Doe')->isValid();

BotScout::mail('[email protected]')->isValid();

BotScout::ip('127.0.0.1')->isValid();

// We also include a quick way of testing a user with integrated exception catch
BotScout::check('John Doe', '[email protected]', '127.0.0.1'); // true or false

Real life example using the check method

The check method is the recommended way to validate a register form:

The check method is a wrapper to the multimethod that catch any http error / timeout. If the botscout api is not responding, the method will return false.

// Create a classic validation 
$validator = Validator::make($request->all(), [
    'email' => 'required|email|unique:users',
    'name' => 'required|max:20',
]);

$validator->after(function ($validator) {
    if (!BotScout::check($request->get('name'), $request->get('email'), $request->ip())) {
        $validator->errors()->add('email', 'Sorry, it looks like your a bot!');
    }
});

Changelog

Please see CHANGELOG for more information what has changed recently.

Testing

$ composer test

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

You might also like...
One-file composer scripts

Melody - One-file composer scripts Create a file named test.php: ?php CONFIG packages: - "symfony/finder: ~2.8" CONFIG; $finder = Symfony\Com

Magento Deployment Scripts

Magento Deployment Scripts Author: Fabrizio Branca This is a collection of scripts used to build/package, deploy and install Magento projects. Import

Magento-bulk - Bulk Import/Export helper scripts and CLI utilities for Magento Commerce

Magento Bulk Bulk operations for Magento. Configuration Copy config.php.sample to config.php and edit it. Product Attribute Management List All Attrib

A set of PHP scripts which leverage MySQL INFORMATION_SCHEMA to create log tables and insert / update triggers

mysql-logtable-php mysql-logtable-php is a set of PHP scripts which leverage MySQL INFORMATION_SCHEMA to create log tables and insert / update trigger

A lot of scripts and packages in modern PHP demand one or more configuration classes

A lot of scripts and packages in modern PHP demand one or more configuration classes. Mostly, those are a set of properties that can be set, changed or retrieved. However, some of the configurations have a peculiar behaviour - such as boolean properties.

Pug Renderer - a (heavily based on the PhpRenderer) renderer for rendering Pug view scripts into a PSR-7 Response object

Pug Renderer This is a (heavily based on the PhpRenderer) renderer for rendering Pug view scripts into a PSR-7 Response object. It works well with Sli

Moodle plugin to limit the access to course content according to the user level in Block Game.

Moodle plugin to limit the access to course content according to the user level in Block Game.

A PocketMine/Altay Plugin to morph yourself into a block
A PocketMine/Altay Plugin to morph yourself into a block

BlockMorph A PocketMine/Altay Plugin to morph yourself into a block Command To morph yourself into a block use this command: /blockmorph [BlockID|Bloc

PHP OOP interface for writing Slack Block Kit messages and modals
PHP OOP interface for writing Slack Block Kit messages and modals

Slack Block Kit for PHP 👉 For formatting messages and modals for Slack using their Block Kit syntax via an OOP interface 👈 By Jeremy Lindblom (@jere

Comments
  • Problem with laravel 5.6.3

    Problem with laravel 5.6.3

    Hi,

    Thanks for creating this package! I tried to install it on Laravel 5.6.3 but got this error:

    `nicolasbeauvais/laravel-botscout 1.1.0 requires illuminate/contracts ~5.1.0|~5.2.0|~5.3.0|~5.4.0|~5.5.0 -> satisfiable by illuminate/contracts[v5.1.1, v5.1.13, v5.1.16

    • Installation request for laravel/framework (locked at v5.6.3, required as 5.6.*) -> satisfiable by laravel/framework[v5.6.3].`

    Any ideas?

    opened by brusselsregular 1
Releases(v1.2.0)
Owner
Nicolas Beauvais
Full stack developer, PHP / Python / JavaScript - Marathon runner
Nicolas Beauvais
A collection of command line scripts for Magento 2 code generation, and a PHP module system for organizing command line scripts.

What is Pestle? Pestle is A PHP Framework for creating and organizing command line programs An experiment in implementing python style module imports

Alan Storm 526 Dec 5, 2022
A complete anti-cheat to defend the server from malicious users.

Advanced Anti-Cheat vAlpha An Anti-Cheat plugin with various preventions and support for apis ≤ 2.0.0. ?? Features Options that are not checked will s

null 11 Dec 3, 2022
Patches that prevent malicious Minecraft plugins from saturating host internet resources for DDoS.

Minecraft Host DoS Botnet Patches Patches that prevent malicious Minecraft plugins from saturating host internet resources for DDoS. In recent events,

Riley Nevins 4 Jul 16, 2022
Adds a "spam protection" field to SilverStripe userforms using Cloudflare's Turnstile service.

Turnstile for Silverstripe Adds a "spam protection" field to SilverStripe userforms using Cloudflare's Turnstile service. Maintainer Contact Ed Chipma

Webbuilders Group 3 Dec 15, 2022
The simplest way to create a dynamic sitemap for your self-coded website which you have made by using PHP/HTML/CSS/Js etc... Scripts.

Sitemap_index.xml The simplest way to create a dynamic sitemap for your self-coded website which you have made by using PHP/HTML/CSS/Js etc... Scripts

Tanish Raj 1 Oct 16, 2021
An alternative Redis session handler for PHP featuring per-session locking and session fixation protection

RedisSessionHandler An alternative Redis session handler featuring session locking and session fixation protection. News phpredis v4.1.0 (released on

Marcel Hernandez 117 Oct 19, 2022
Plot and protection plugin for PocketMine-MP

MyPlot Create, manage, and build in protected plots. Keep your builds safe from griefers! Official MyPlot precompiled builds can be found on Poggit at

Jason 101 Oct 28, 2022
Run PHP scripts on the fly at runtime on a PocketMine-MP server (useful for debugging)

Scripter Run PHP scripts on the fly at runtime on a PocketMine-MP server. This is useful for runtime debugging, when you don't want to restart the ser

Dylan's PocketMine-MP Plugins 15 Jul 28, 2022
Composer plugin replacing placeholders in the scripts section by dynamic values

Composer Substitution Plugin The Composer Substitution plugin replaces placeholders in the scripts section by dynamic values. It also permits to cache

Fabien Villepinte 49 Jan 8, 2022
Scripts-dev directive for composer

scriptsdev for Composer It's like require-dev, but for scripts Installation Just run composer require neronmoon/scriptsdev --dev Usage After installin

Vitaliy Krasnoperov 67 May 18, 2022