![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/old/vendor/magento/module-two-factor-auth/Setup/Patch/Data/ |
<?php /** * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ declare(strict_types=1); namespace Magento\TwoFactorAuth\Setup\Patch\Data; use Magento\Framework\App\Config\ConfigResource\ConfigInterface; use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Framework\Setup\ModuleDataSetupInterface; use Magento\Framework\Setup\Patch\DataPatchInterface; use Magento\TwoFactorAuth\Model\Provider\Engine\DuoSecurity; /** * Generate initial duo security key */ class GenerateDuoSecurityKey implements DataPatchInterface { /** * @var ModuleDataSetupInterface */ private $moduleDataSetup; /** * @var ConfigInterface */ private $config; /** * @var ScopeConfigInterface */ private $scopeConfig; /** * @param ModuleDataSetupInterface $moduleDataSetup * @param ConfigInterface $config * @param ScopeConfigInterface $scopeConfig */ public function __construct( ModuleDataSetupInterface $moduleDataSetup, ConfigInterface $config, ScopeConfigInterface $scopeConfig ) { $this->moduleDataSetup = $moduleDataSetup; $this->config = $config; $this->scopeConfig = $scopeConfig; } /** * Create and set the duo key * * @SuppressWarnings(PHPMD.ExcessiveMethodLength) * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) */ public function apply() { $this->moduleDataSetup->startSetup(); if (!$this->scopeConfig->getValue(DuoSecurity::XML_PATH_APPLICATION_KEY)) { // Generate random duo security key $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; $charactersLength = strlen($characters); $randomString = ''; for ($i = 0; $i < 64; $i++) { $randomString .= $characters[random_int(0, $charactersLength - 1)]; } $this->config->saveConfig(DuoSecurity::XML_PATH_APPLICATION_KEY, $randomString, 'default', 0); } $this->moduleDataSetup->endSetup(); return $this; } /** * @inheritdoc */ public static function getDependencies() { return [ CopyConfigFromOldModule::class ]; } /** * @inheritdoc */ public function getAliases() { return []; } }