Add option to ban indifenitely (sort of)

Created on 19 October 2023, about 1 year ago

Problem/Motivation

Sometimes we want to have a more persistent ban alongside the less permanent ones.

Steps to reproduce

Proposed resolution

Add a new button with callback to "Ban indefinitely". The actual ban period is limited to the year 2038 because of the storage limitations, but it should suffice.

Remaining tasks

Discuss proposed solution.

User interface changes

API changes

Data model changes

Feature request
Status

Active

Version

1.0

Component

Code

Created by

🇸🇮Slovenia primsi

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @primsi
  • Status changed to Needs review about 1 year ago
  • 🇸🇮Slovenia primsi

    Initial patch.

  • Status changed to Needs work about 1 year ago
  • 🇨🇭Switzerland berdir Switzerland
    +++ b/auto_unban.module
    @@ -82,3 +90,24 @@ function auto_unban_form_ban_ip_form_alter(array &$form, FormStateInterface $for
    +    $time = \Drupal::time();
    +    // Ban for as much as the db field allows us.
    +    $ip_manager->setBanDurationOverride(2147483647 - $time->getCurrentTime());
    +    $ip_manager->banIp($ip);
    

    I think if we go with a separate submit button then a new method that's banIpIndefinitely() or banIpWithExpire() makes more sense, we don't need to introduce state in the storage then.

  • Status changed to Needs review about 1 year ago
  • 🇸🇮Slovenia primsi

    Thanks. Seems it's fine even with just a new argument (that's what the module is doing anyway with $attempts).

  • 🇸🇮Slovenia primsi

    Few notes for the maintainer:

    1. +++ b/auto_unban.module
      @@ -1,5 +1,6 @@
      +use Drupal\auto_unban\BanIpManager as AutoUnbanBanIpManager;
      

      I aliased this for a bit better code clarity, because the replacement class auto_unban provides has the same name as the one that it substitutes.

    2. +++ b/auto_unban.module
      @@ -15,7 +24,7 @@ function auto_unban_form_ban_ip_form_alter(array &$form, FormStateInterface $for
      +      'data' => t('Ban count'),
      

      We discussed with @Berdir, that just Count is a bit confusing. So we are proposing here a small renaming. Sorry for the scope creep.

  • 🇨🇭Switzerland berdir Switzerland
  • Status changed to RTBC about 1 year ago
  • 🇬🇧United Kingdom andybroomfield

    Have tested this and selecting add indefinatly does ban the IP address with a date set to 2038 (max unix time stamp).

  • 🇺🇸United States douggreen Winchester, VA

    Committed, I wasn't initially a fan of this, but as an option it's certainly valuable.

  • 🇺🇸United States douggreen Winchester, VA
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024