diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..40bd5c4 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2022 Magenable + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/Plugin/IsCaptchaEnabledPlugin.php b/Plugin/IsCaptchaEnabledPlugin.php new file mode 100644 index 0000000..3743959 --- /dev/null +++ b/Plugin/IsCaptchaEnabledPlugin.php @@ -0,0 +1,92 @@ +httpHeader = $httpHeader; + $this->remoteAddress = $remoteAddress; + $this->scopeConfig = $scopeConfig; + } + + public function afterIsCaptchaEnabledFor( + IsCaptchaEnabled $subject, + bool $result + ) { + if (!$this->scopeConfig->getValue('magenable_captcha_bypass/general/enabled', ScopeInterface::SCOPE_STORE)) { + return $result; + } + + $ipWhitelisted = $this->scopeConfig->getValue( + 'magenable_captcha_bypass/general/ip_whitelist', + ScopeInterface::SCOPE_STORE + ); + $userAgentWhitelisted = $this->scopeConfig->getValue( + 'magenable_captcha_bypass/general/user_agent_whitelist', + ScopeInterface::SCOPE_STORE + ); + if (!$ipWhitelisted && !$userAgentWhitelisted) { + return $result; + } + + $checkIp = false; + if ($ipWhitelisted) { + $ipWhitelisted = explode(',', $ipWhitelisted); + $remoteIp = $this->remoteAddress->getRemoteAddress(); + foreach ($ipWhitelisted as $ipWhite) { + if ($remoteIp === trim($ipWhite)) { + $checkIp = true; + break; + } + } + } + + $checkUserAgent = false; + if ($userAgentWhitelisted) { + $userAgent = $this->httpHeader->getHttpUserAgent(); + if ($userAgent === $userAgentWhitelisted) { + $checkUserAgent = true; + } + } + + if ($checkIp || $checkUserAgent) { + return false; + } + + return $result; + } +} diff --git a/README.md b/README.md new file mode 100644 index 0000000..e68cfe3 --- /dev/null +++ b/README.md @@ -0,0 +1,34 @@ +# Magenable Captcha Bypass + +The extension allows you to disable recaptcha on the site for certain ip-addresses or a specific browser User-Agent, this can be useful in time during automatic testing of the site. + +## Installation + +### Composer: + +Run the following command in Magento 2 root folder + +``` +composer require magenable/module-captcha-bypass +bin/magento module:enable Magenable_CaptchaBypass +bin/magento setup:upgrade +``` +## Upgrade + +### Composer: + +Run the following command in Magento 2 root folder + +``` +composer update magenable/module-captcha-bypass +bin/magento setup:upgrade +``` + +## Extension Settings + +- In the menu of admin panel select **Stores** -> **Settings** -> **Configuration** +- Select **Magenable Extensions** and click on **Captcha Bypass** +- In group **General** in field **Enabled** select **Yes** +- In field **Whitelisted IP addresses** specify one or few ip-addresses separated by comma +- Or in field **Whitelisted User-Agent** specify User-Agent +- If one of this condition (from previous two fields) will meet the recaptcha will be disabled. diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..0b27618 --- /dev/null +++ b/composer.json @@ -0,0 +1,30 @@ +{ + "name": "magenable/module-captcha-bypass", + "description": "A Magento 2 captcha bypass module for testing purposes", + "require": { + "magento/framework": ">=102.0", + "magenable/module-base": "*" + }, + "type": "magento2-module", + "version": "1.0.0", + "license": "MIT", + "authors": [ + { + "name": "Magenable", + "homepage": "https://magenable.com.au" + } + ], + "keywords": [ + "magento 2 captcha bypass", + "captcha workaround", + "recaptcha bypass" + ], + "autoload": { + "files": [ + "registration.php" + ], + "psr-4": { + "Magenable\\CaptchaBypass\\": "" + } + } +} diff --git a/etc/acl.xml b/etc/acl.xml new file mode 100644 index 0000000..6aef106 --- /dev/null +++ b/etc/acl.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml new file mode 100644 index 0000000..e47f91d --- /dev/null +++ b/etc/adminhtml/system.xml @@ -0,0 +1,30 @@ + + + +
+ + magenable + Magenable_CaptchaBypass::config + + + + + Magento\Config\Model\Config\Source\Yesno + + + + Comma separated, no spaces. + + + + + +
+
+
diff --git a/etc/config.xml b/etc/config.xml new file mode 100644 index 0000000..2025f4f --- /dev/null +++ b/etc/config.xml @@ -0,0 +1,11 @@ + + + + + + 0 + + + + diff --git a/etc/di.xml b/etc/di.xml new file mode 100644 index 0000000..6f91417 --- /dev/null +++ b/etc/di.xml @@ -0,0 +1,8 @@ + + + + + + diff --git a/etc/module.xml b/etc/module.xml new file mode 100644 index 0000000..4faf6a6 --- /dev/null +++ b/etc/module.xml @@ -0,0 +1,10 @@ + + + + + + + + + diff --git a/registration.php b/registration.php new file mode 100644 index 0000000..1a399d7 --- /dev/null +++ b/registration.php @@ -0,0 +1,9 @@ +