diff --git a/README.md b/README.md index 1e02bba8f42ac40ef3fda8d135da3cf993f50d14..137741bd98cb797d975ca3d0a549330d91cc9c8c 100644 --- a/README.md +++ b/README.md @@ -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 1/0` + ### Modules that expand on restrict IP 1. [IP-based Determination of a Visitor's Country](https://www.drupal.org/project/ip2country) diff --git a/restrict_ip.services.yml b/restrict_ip.services.yml index a027553129520723ffffd8f799a042b8934198e0..ba9191c90cdbdb901f493f4eda43f7248116580a 100644 --- a/restrict_ip.services.yml +++ b/restrict_ip.services.yml @@ -4,6 +4,11 @@ parameters: restrict_ip.event_subscriber.class: Drupal\restrict_ip\EventSubscriber\RestrictIpEventSubscriber services: + restrict_ip.commands: + class: \Drupal\restrict_ip\Drush\Commands\RestrictIpCommands + tags: + - { name: drush.command } + restrict_ip.mapper: class: Drupal\restrict_ip\Mapper\RestrictIpMapper arguments: diff --git a/src/Drush/Commands/RestrictIpCommands.php b/src/Drush/Commands/RestrictIpCommands.php new file mode 100644 index 0000000000000000000000000000000000000000..77cc60a9861ba19368dfbc1d0a80013c0a7741b9 --- /dev/null +++ b/src/Drush/Commands/RestrictIpCommands.php @@ -0,0 +1,28 @@ +<?php + +namespace Drupal\restrict_ip\Drush\Commands; + +use Drush\Commands\DrushCommands; + +final class RestrictIpCommands extends DrushCommands { + + /** + * Disable/Enable restrict_ip. + * + * @param string $disable + * 1/0 + * + * @command restrict_ip:disable + * @aliases ripd + * @usage restrict_ip:disable off + */ + public function ipRestrictDisable(string $disable): void { + $configF = \Drupal::configFactory(); + $edit = $configF->getEditable('restrict_ip.settings'); + $edit->set('enable', (boolean) $disable); + $edit->save(); + $disableString = $disable ? 'enable' : 'disable'; + $this->logger()->success(t('restrict_ip ' . $disableString)); + } + +} \ No newline at end of file