mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-14 16:04:38 -04:00
Check .env is writeable when updating key
This commit is contained in:
parent
3bc4dd17ae
commit
01bcc71ae1
@ -29,6 +29,11 @@ class UpdateKey extends Command
|
|||||||
{
|
{
|
||||||
$this->info(date('Y-m-d h:i:s') . ' Running UpdateKey...');
|
$this->info(date('Y-m-d h:i:s') . ' Running UpdateKey...');
|
||||||
|
|
||||||
|
if (! env('APP_KEY') || ! env('APP_CIPHER')) {
|
||||||
|
$this->info(date('Y-m-d h:i:s') . ' Error: app key and cipher are not set');
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
// load the current values
|
// load the current values
|
||||||
$gatewayConfigs = [];
|
$gatewayConfigs = [];
|
||||||
$bankUsernames = [];
|
$bankUsernames = [];
|
||||||
@ -41,9 +46,17 @@ class UpdateKey extends Command
|
|||||||
$bankUsernames[$bank->id] = $bank->getUsername();
|
$bankUsernames[$bank->id] = $bank->getUsername();
|
||||||
}
|
}
|
||||||
|
|
||||||
// set the new key and create a new encrypter
|
// check if we can write to the .env file
|
||||||
Artisan::call('key:generate');
|
$envPath = base_path() . '/.env';
|
||||||
$key = base64_decode(str_replace('base64:', '', config('app.key')));
|
$envWriteable = file_exists($envPath) && @fopen($envPath, 'a');
|
||||||
|
|
||||||
|
if ($envWriteable) {
|
||||||
|
Artisan::call('key:generate');
|
||||||
|
$key = base64_decode(str_replace('base64:', '', config('app.key')));
|
||||||
|
} else {
|
||||||
|
$key = str_random(32);
|
||||||
|
}
|
||||||
|
|
||||||
$crypt = new Encrypter($key, config('app.cipher'));
|
$crypt = new Encrypter($key, config('app.cipher'));
|
||||||
|
|
||||||
// update values using the new key/encrypter
|
// update values using the new key/encrypter
|
||||||
@ -59,7 +72,11 @@ class UpdateKey extends Command
|
|||||||
$bank->save();
|
$bank->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->info(date('Y-m-d h:i:s') . ' Successfully updated the application key');
|
if ($envWriteable) {
|
||||||
|
$this->info(date('Y-m-d h:i:s') . ' Successfully update the key');
|
||||||
|
} else {
|
||||||
|
$this->info(date('Y-m-d h:i:s') . ' Successfully update data, make sure to set the new app key: ' . $key);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user