Skip to content

Commit ff380cb

Browse files
cedric-annetrasher
authored andcommitted
Create security key file on CLI install
1 parent b90c638 commit ff380cb

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

inc/console/database/installcommand.class.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
use Config;
4040
use DBConnection;
4141
use Glpi\Console\Command\ForceNoPluginsOptionCommandInterface;
42+
use GLPIKey;
4243
use Toolbox;
4344

4445
use Symfony\Component\Console\Command\Command;
@@ -95,6 +96,13 @@ class InstallCommand extends Command implements ForceNoPluginsOptionCommandInter
9596
*/
9697
const ERROR_SCHEMA_CREATION_FAILED = 6;
9798

99+
/**
100+
* Error code returned when failing to create encryption key file.
101+
*
102+
* @var integer
103+
*/
104+
const ERROR_CANNOT_CREATE_ENCRYPTION_KEY_FILE = 7;
105+
98106
protected function configure() {
99107
parent::configure();
100108

@@ -234,6 +242,14 @@ protected function execute(InputInterface $input, OutputInterface $output) {
234242
}
235243
}
236244

245+
// Create security key
246+
$glpikey = new GLPIKey();
247+
if (!$glpikey->keyExists() && !$glpikey->generate()) {
248+
$message = __('Security key cannot be generated!');
249+
$output->writeln('<error>' . $message . '</error>', OutputInterface::VERBOSITY_QUIET);
250+
return self::ERROR_CANNOT_CREATE_ENCRYPTION_KEY_FILE;
251+
}
252+
237253
$mysqli = new \mysqli();
238254
if (intval($db_port) > 0) { // Network port
239255
@$mysqli->connect($db_host, $db_user, $db_pass, null, $db_port);

0 commit comments

Comments
 (0)