Skip to content

Commit

Permalink
install.phpにSecurity.saltを保存しない
Browse files Browse the repository at this point in the history
  • Loading branch information
seto1 committed Sep 12, 2024
1 parent bc42c5f commit 1d04a14
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 83 deletions.
42 changes: 0 additions & 42 deletions config/test_install.php

This file was deleted.

3 changes: 1 addition & 2 deletions plugins/bc-installer/src/Command/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,15 +168,14 @@ 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'),
'email' => $args->getArgument('adminemail')
]);

// Init files
$service->createInstallFile($dbConfig, $salt);
$service->createInstallFile($dbConfig);
$service->createJwt();

// Init db
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand All @@ -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();
// アップロード用初期フォルダを作成する
Expand Down
35 changes: 2 additions & 33 deletions plugins/bc-installer/src/Service/InstallationsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
* 初期ユーザーを登録する
*
Expand All @@ -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']),
Expand Down Expand Up @@ -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;
Expand All @@ -443,18 +419,11 @@ public function createInstallFile(array $dbConfig, string $securitySalt): bool
$dbConfig[$key] = addcslashes($value, '\'\\');
}

$basicSettings = [
'Security.salt' => $securitySalt
];

$installCoreData = [
'<?php',
'// created by BcInstaller',
'return ['
];
foreach($basicSettings as $key => $value) {
$installCoreData[] = ' \'' . $key . '\' => \'' . $value . '\',';
}
$installCoreData[] = ' \'Datasources.default\' => [';
foreach($dbConfig as $key => $value) {
if($key === 'datasource' || $key === 'dataPattern') continue;
Expand Down

0 comments on commit 1d04a14

Please sign in to comment.