Download the PHP package mchev/banhammer without Composer

On this page you can find all versions of the php package mchev/banhammer. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package banhammer

Banhammer, a Model, IP and Country ban package for Laravel

Latest Version on Packagist GitHub Tests Action Status Total Downloads Package for laravel

Banhammer for Laravel offers a very simple way to ban any Model by ID and by IP. It also allows to block requests by IP addresses.

Banned models can have an expiration date and will be automatically unbanned using the Scheduler.

Table of Contents

  1. Introduction
  2. Version Compatibility
  3. Installation
  4. Upgrading To 2.0 from 1.x
  5. Usage
    • Making a Model Bannable
    • Ban / Unban
    • IP
    • Metas
    • Blocking Access from Specific Countries
    • Middleware
    • Scheduler
    • Events
    • Miscellaneous
  6. Testing
  7. Changelog
  8. Roadmap / Todo
  9. Contributing
  10. Security Vulnerabilities
  11. Credits
  12. License

Version Compatibility

Laravel Banhammer
^9.0 1.x, 2.x
^10.0 1.x, 2.x
^11.0 1.x, 2.x

Installation

You can install the package via composer:

Then run the migrations with:

You can publish the config file with:

It is possible to define the table name and the fallback_url in the config/ban.php file.

Upgrading To 2.0 from 1.x

To upgrade to Banhammer version 2.0, follow these simple steps:

  1. Update the package version in your application's composer.json file:

  2. Run the following command in your terminal:

  3. Update the configuration

    1. Update the configuration

      • Backup your previous configuration file located at config/ban.php.
      • Force republish the new configuration using the command:

      • Review the new configuration file and make any necessary edits.

Usage

To make a model bannable, add the Mchev\Banhammer\Traits\Bannable trait to the model:

You can add the Bannable trait on as many models as you want (Team, Group, User, etc.).

Ban / Unban

Simple ban

Without the expired_at attribute specified, the user will be banned forever.

IP Ban

Full

All attributes are optional

Shorthand

Check if model is banned.

You can create custom middlewares using these methods.

List model bans

Filters

Unban

IP

Ban IPs

Unban IPs

List all banned IPs

Metas

Ban IP with metas

Metas usage

Filtering by Meta

Blocking Access from Specific Countries

To enhance the security of your application, you can restrict access from specific countries by enabling the country-blocking feature in the configuration file. Follow these simple steps:

  1. Open your Banhammer configuration file (config/ban.php).

  2. Set the 'block_by_country' configuration option to true to enable country-based blocking.

  3. Specify the list of countries you want to block by adding their country codes to the 'blocked_countries' array.

By configuring these settings, you effectively block access to your application for users originating from the specified countries. This helps improve the security and integrity of your system by preventing unwanted traffic from regions you've identified as potential risks.

Important Notice: The Banhammer package utilizes the free version of ip-api.com for geolocation data. Keep in mind that their endpoints have a rate limit of 45 HTTP requests per minute from a single IP address. If you exceed this limit, your requests will be throttled, and you may receive a 429 HTTP status code until your rate limit window is reset.

Developer Note: While Banhammer currently relies on the free version of ip-api.com for geolocation data, I'm open to exploring better alternatives. If you have suggestions for a more robust or efficient solution, or if you'd like to contribute improvements, please feel free to open an issue or submit a pull request.

Middleware

To prevent banned users from accessing certain parts of your application, simply add the auth.banned middleware on the concerned routes.

To prevent banned ips from accessing certain parts of your application, simply add the ip.banned middleware on the concerned routes.

To block and logout banned Users or IP, add the logout.banned middleware:

If you use the logout.banned middleware, it is not necessary to cumulate the other middlewares.

If you want to block IPs on every HTTP request of your application, list Mchev\Banhammer\Middleware\IPBanned in the $middleware property of your app/Http/Kernel.php class.

Scheduler

⚠ IMPORTANT

In order to be able to automatically delete expired bans, you must have a cron job set up on your server to run the Laravel Scheduled Jobs

Running the scheduler

Configure Scheduler on Forge

Events

If entity is banned Mchev\Banhammer\Events\ModelWasBanned event is fired.

Is entity is unbanned Mchev\Banhammer\Events\ModelWasUnbanned event is fired.

MISC

To manually unban expired bans :

Or you can use the command:

To permanently delete all the expired bans :

Or you can use the command:

Testing

Changelog

Please see CHANGELOG for more information on what has changed recently.

Roadmap / Todo

Contributing

To encourage active collaboration, Banhammer strongly encourages pull requests, not just bug reports. Pull requests will only be reviewed when marked as "ready for review" (not in the "draft" state) and all tests for new features are passing. Lingering, non-active pull requests left in the "draft" state will be closed after a few days.

However, if you file a bug report, your issue should contain a title and a clear description of the issue. You should also include as much relevant information as possible and a code sample that demonstrates the issue. The goal of a bug report is to make it easy for yourself - and others - to replicate the bug and develop a fix.

Remember, bug reports are created in the hope that others with the same problem will be able to collaborate with you on solving it. Do not expect that the bug report will automatically see any activity or that others will jump to fix it.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

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


All versions of banhammer with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package mchev/banhammer contains the following files

Loading the files please wait ....