From 1d04a14b29b4b5928693e81a41796e4e3bb6c528 Mon Sep 17 00:00:00 2001 From: seto Date: Thu, 12 Sep 2024 13:41:43 +0900 Subject: [PATCH] =?UTF-8?q?install.php=E3=81=ABSecurity.salt=E3=82=92?= =?UTF-8?q?=E4=BF=9D=E5=AD=98=E3=81=97=E3=81=AA=E3=81=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/test_install.php | 42 ------------------- .../src/Command/InstallCommand.php | 3 +- .../Admin/InstallationsAdminService.php | 7 +--- .../src/Service/InstallationsService.php | 35 +--------------- 4 files changed, 4 insertions(+), 83 deletions(-) delete mode 100644 config/test_install.php diff --git a/config/test_install.php b/config/test_install.php deleted file mode 100644 index f34061f9e8..0000000000 --- a/config/test_install.php +++ /dev/null @@ -1,42 +0,0 @@ - - * Copyright (c) NPO baser foundation - * - * @copyright Copyright (c) NPO baser foundation - * @link https://basercms.net baserCMS Project - * @since 5.0.0 - * @license https://basercms.net/license/index.html MIT License - */ -/** - * ユニットテスト用のインストール設定ファイル - */ -return [ - 'Security.salt' => 'af0aa6bb8bad3bf5f9a39e928c645745cc008d67d82ac4edd16ec17e99539725', - 'Datasources.default' => [ - 'className' => 'Cake\\Database\\Connection', - 'driver' => 'Cake\\Database\\Driver\\Mysql', - 'host' => 'bc-db', - 'port' => '3306', - 'username' => 'root', - 'password' => 'root', - 'database' => 'basercms', - 'prefix' => 'mysite_', - 'schema' => '', - 'encoding' => 'utf8', - 'persistent' => '', - ], - 'Datasources.test' => [ - 'className' => 'Cake\\Database\\Connection', - 'driver' => 'Cake\\Database\\Driver\\Mysql', - 'host' => 'bc-db', - 'port' => '3306', - 'username' => 'root', - 'password' => 'root', - 'database' => 'test_basercms', - 'prefix' => 'mysite_', - 'schema' => '', - 'encoding' => 'utf8', - 'persistent' => '', - ], -]; diff --git a/plugins/bc-installer/src/Command/InstallCommand.php b/plugins/bc-installer/src/Command/InstallCommand.php index 44b9d9f994..5f524218ac 100644 --- a/plugins/bc-installer/src/Command/InstallCommand.php +++ b/plugins/bc-installer/src/Command/InstallCommand.php @@ -168,7 +168,6 @@ public function install(Arguments $args, ConsoleIo $io, array $dbConfig) // Init admin $service->setAdminEmailAndVersion($args->getArgument('adminemail')); $service->setSiteName($args->getOption('sitename')); - $salt = $service->setSecuritySalt(); $service->addDefaultUser([ 'password_1' => $args->getArgument('adminpassword'), 'password_2' => $args->getArgument('adminpassword'), @@ -176,7 +175,7 @@ public function install(Arguments $args, ConsoleIo $io, array $dbConfig) ]); // Init files - $service->createInstallFile($dbConfig, $salt); + $service->createInstallFile($dbConfig); $service->createJwt(); // Init db diff --git a/plugins/bc-installer/src/Service/Admin/InstallationsAdminService.php b/plugins/bc-installer/src/Service/Admin/InstallationsAdminService.php index 65b4dafb3e..a9e887482e 100644 --- a/plugins/bc-installer/src/Service/Admin/InstallationsAdminService.php +++ b/plugins/bc-installer/src/Service/Admin/InstallationsAdminService.php @@ -254,10 +254,6 @@ public function initAdmin(ServerRequest $request): void $this->setAdminEmailAndVersion($request->getData('admin_email')); $this->setSiteName($request->getData('site_name')); - // SecuritySalt設定 - $salt = $this->setSecuritySalt(); - $request->getSession()->write('Installation.salt', $salt); - // 管理ユーザー登録 $user = [ 'password_1' => $request->getData('admin_password'), @@ -283,8 +279,7 @@ public function initAdmin(ServerRequest $request): void public function initFiles(ServerRequest $request): void { // インストールファイルを生成する - $securitySalt = $request->getSession()->read('Installation.salt'); - $this->createInstallFile($this->readDbSetting($request), $securitySalt); + $this->createInstallFile($this->readDbSetting($request)); // JWTキーを作成する $this->createJwt(); // アップロード用初期フォルダを作成する diff --git a/plugins/bc-installer/src/Service/InstallationsService.php b/plugins/bc-installer/src/Service/InstallationsService.php index 31c191990c..330f8daf41 100644 --- a/plugins/bc-installer/src/Service/InstallationsService.php +++ b/plugins/bc-installer/src/Service/InstallationsService.php @@ -283,26 +283,6 @@ public function setAdminEmailAndVersion(string $email) $siteConfigsService->setValue('version', BcUtil::getVersion())); } - /** - * セキュリティ用のキーを生成する - * - * @param int $length - * @return string キー - * @checked - * @noTodo - * @unitTest - */ - public function setSecuritySalt($length = 40): string - { - $keyset = "abcdefghijklmABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; - $randkey = ""; - for($i = 0; $i < $length; $i++) { - $randkey .= substr($keyset, rand(0, strlen($keyset) - 1), 1); - } - Configure::write('Security.salt', $randkey); - return $randkey; - } - /** * 初期ユーザーを登録する * @@ -312,11 +292,8 @@ public function setSecuritySalt($length = 40): string * @checked * @noTodo */ - public function addDefaultUser(array $user, $securitySalt = '') + public function addDefaultUser(array $user) { - if ($securitySalt) { - Configure::write('Security.salt', $securitySalt); - } $user = array_merge([ 'name' => '', 'real_name_1' => preg_replace('/@.+$/', '', $user['email']), @@ -415,12 +392,11 @@ public function installPlugin($name) * インストール設定ファイルを生成する * * @param array $dbConfig - * @param string $securitySalt * @return boolean * @checked * @noTodo */ - public function createInstallFile(array $dbConfig, string $securitySalt): bool + public function createInstallFile(array $dbConfig): bool { if (!is_writable(ROOT . DS . 'config' . DS)) { return false; @@ -443,18 +419,11 @@ public function createInstallFile(array $dbConfig, string $securitySalt): bool $dbConfig[$key] = addcslashes($value, '\'\\'); } - $basicSettings = [ - 'Security.salt' => $securitySalt - ]; - $installCoreData = [ ' $value) { - $installCoreData[] = ' \'' . $key . '\' => \'' . $value . '\','; - } $installCoreData[] = ' \'Datasources.default\' => ['; foreach($dbConfig as $key => $value) { if($key === 'datasource' || $key === 'dataPattern') continue;