mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Fix update key
This commit is contained in:
parent
814e6e1a62
commit
15eb26e855
@ -20,7 +20,7 @@ class UpdateKey extends Command
|
|||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $name = 'ninja:update-key {--database=}';
|
protected $name = 'ninja:update-key {--database=} {--key=} {--legacy=}';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
@ -42,7 +42,7 @@ class UpdateKey extends Command
|
|||||||
|
|
||||||
$legacy = false;
|
$legacy = false;
|
||||||
if ($this->option('legacy') == 'true') {
|
if ($this->option('legacy') == 'true') {
|
||||||
$legacy = new McryptEncrypter(env('APP_KEY'));
|
$legacy = new McryptEncrypter(env('APP_KEY'), env('APP_CIPHER'));
|
||||||
}
|
}
|
||||||
|
|
||||||
// load the current values
|
// load the current values
|
||||||
@ -50,7 +50,7 @@ class UpdateKey extends Command
|
|||||||
$bankUsernames = [];
|
$bankUsernames = [];
|
||||||
$twoFactorSecrets = [];
|
$twoFactorSecrets = [];
|
||||||
|
|
||||||
foreach (AccountGateway::all() as $gateway) {
|
foreach (AccountGateway::withTrashed()->get() as $gateway) {
|
||||||
if ($legacy) {
|
if ($legacy) {
|
||||||
$gatewayConfigs[$gateway->id] = json_decode($legacy->decrypt($gateway->config));
|
$gatewayConfigs[$gateway->id] = json_decode($legacy->decrypt($gateway->config));
|
||||||
} else {
|
} else {
|
||||||
@ -58,7 +58,7 @@ class UpdateKey extends Command
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (BankAccount::all() as $bank) {
|
foreach (BankAccount::withTrashed()->get() as $bank) {
|
||||||
if ($legacy) {
|
if ($legacy) {
|
||||||
$bankUsernames[$bank->id] = $legacy->decrypt($bank->username);
|
$bankUsernames[$bank->id] = $legacy->decrypt($bank->username);
|
||||||
} else {
|
} else {
|
||||||
@ -66,7 +66,7 @@ class UpdateKey extends Command
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (User::where('google_2fa_secret', '!=', '')->get() as $user) {
|
foreach (User::withTrashed()->where('google_2fa_secret', '!=', '')->get() as $user) {
|
||||||
if ($legacy) {
|
if ($legacy) {
|
||||||
$twoFactorSecrets[$user->id] = $legacy->decrypt($user->google_2fa_secret);
|
$twoFactorSecrets[$user->id] = $legacy->decrypt($user->google_2fa_secret);
|
||||||
} else {
|
} else {
|
||||||
@ -78,7 +78,9 @@ class UpdateKey extends Command
|
|||||||
$envPath = base_path() . '/.env';
|
$envPath = base_path() . '/.env';
|
||||||
$envWriteable = file_exists($envPath) && @fopen($envPath, 'a');
|
$envWriteable = file_exists($envPath) && @fopen($envPath, 'a');
|
||||||
|
|
||||||
if ($envWriteable) {
|
if ($key = $this->option('key')) {
|
||||||
|
$key = base64_decode(str_replace('base64:', '', $key));
|
||||||
|
} elseif ($envWriteable) {
|
||||||
Artisan::call('key:generate');
|
Artisan::call('key:generate');
|
||||||
$key = base64_decode(str_replace('base64:', '', config('app.key')));
|
$key = base64_decode(str_replace('base64:', '', config('app.key')));
|
||||||
} else {
|
} else {
|
||||||
@ -89,19 +91,19 @@ class UpdateKey extends Command
|
|||||||
$crypt = new Encrypter($key, $cipher);
|
$crypt = new Encrypter($key, $cipher);
|
||||||
|
|
||||||
// update values using the new key/encrypter
|
// update values using the new key/encrypter
|
||||||
foreach (AccountGateway::all() as $gateway) {
|
foreach (AccountGateway::withTrashed()->get() as $gateway) {
|
||||||
$config = $gatewayConfigs[$gateway->id];
|
$config = $gatewayConfigs[$gateway->id];
|
||||||
$gateway->config = $crypt->encrypt(json_encode($config));
|
$gateway->config = $crypt->encrypt(json_encode($config));
|
||||||
$gateway->save();
|
$gateway->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (BankAccount::all() as $bank) {
|
foreach (BankAccount::withTrashed()->get() as $bank) {
|
||||||
$username = $bankUsernames[$bank->id];
|
$username = $bankUsernames[$bank->id];
|
||||||
$bank->username = $crypt->encrypt($username);
|
$bank->username = $crypt->encrypt($username);
|
||||||
$bank->save();
|
$bank->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (User::where('google_2fa_secret', '!=', '')->get() as $user) {
|
foreach (User::withTrashed()->where('google_2fa_secret', '!=', '')->get() as $user) {
|
||||||
$secret = $twoFactorSecrets[$user->id];
|
$secret = $twoFactorSecrets[$user->id];
|
||||||
$user->google_2fa_secret = $crypt->encrypt($secret);
|
$user->google_2fa_secret = $crypt->encrypt($secret);
|
||||||
$user->save();
|
$user->save();
|
||||||
@ -140,6 +142,7 @@ class UpdateKey extends Command
|
|||||||
return [
|
return [
|
||||||
['legacy', null, InputOption::VALUE_OPTIONAL, 'Legacy', null],
|
['legacy', null, InputOption::VALUE_OPTIONAL, 'Legacy', null],
|
||||||
['database', null, InputOption::VALUE_OPTIONAL, 'Database', null],
|
['database', null, InputOption::VALUE_OPTIONAL, 'Database', null],
|
||||||
|
['key', null, InputOption::VALUE_OPTIONAL, 'Key', null],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user