Skip to content
Snippets Groups Projects
Commit 77d1f623 authored by Stephen Mustgrave's avatar Stephen Mustgrave
Browse files

Issue #3391850 by paul_leclerc, anybody: Drush command to disable restrict_ip

parent 16e00c4b
No related branches found
No related tags found
1 merge request!28Issue #3391850 by paul_leclerc, anybody: Drush command to disable restrict_ip
Pipeline #378112 passed with warnings
......@@ -4,6 +4,8 @@
* About
* Installation
* Configuration
* Drush commands
* Modules that expand on restrict IP
* Questions and Answers
* Support
......@@ -34,6 +36,12 @@ $config['restrict_ip.settings']['ip_whitelist'] = [
'111.111.111.2',
];
### Drush commands
If you don't have access/permissions on settings files, you can also use a restrict_ip drush command :
`drush ripd [enable or disable]`
### Modules that expand on restrict IP
1. [IP-based Determination of a Visitor's Country](https://www.drupal.org/project/ip2country)
......
......@@ -6,7 +6,7 @@ restrict_ip.settings:
type: boolean
label: 'Enable module'
mail_address:
type: string
type: email
label: 'Contact mail address to show to blocked users'
dblog:
type: boolean
......@@ -17,12 +17,26 @@ restrict_ip.settings:
bypass_action:
type: string
label: 'Action to perform for blocked users when bypassing by role is enabled'
constraints:
Choice:
- provide_link_login_page
- redirect_login_page
white_black_list:
type: integer
label: 'Whether to use a path whitelist, blacklist, or check all pages'
constraints:
Choice:
- 0
- 1
- 2
country_white_black_list:
type: integer
label: 'Whether to use a whitelist, blacklist, or neither for countries'
constraints:
Choice:
- 0
- 1
- 2
country_list:
type: string
label: 'A colon separated list of countries that should be white/black listed'
services:
restrict_ip.commands:
class: \Drupal\restrict_ip\Drush\Commands\RestrictIpCommands
arguments: ['@config.factory']
tags:
- { name: drush.command }
<?php
namespace Drupal\restrict_ip\Drush\Commands;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drush\Commands\DrushCommands;
/**
* Drush command to enable/disable restrict IP.
*/
final class RestrictIpCommands extends DrushCommands {
use StringTranslationTrait;
/**
* Creates an instance of the RestrictIpCommands class.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $configFactory
* The Config Factory service.
*/
public function __construct(
protected ConfigFactoryInterface $configFactory,
) {
parent::__construct();
}
/**
* Disable/Enable restrict_ip.
*
* @param string $value
* Value enable or disable.
*
* @command restrict_ip:disable
* @aliases ripd
* @usage restrict_ip:disable off
*/
public function ipRestrictDisable(string $value): void {
$edit = $this->configFactory->getEditable('restrict_ip.settings');
$edit->set('enable', $value === 'enable');
$edit->save();
$this->logger()->success($this->t('restrict_ip @value', [
'@value' => $value,
]));
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment