mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-09 20:52:56 +01:00
Added Artisan command to update the app key
This commit is contained in:
parent
2da217fc2f
commit
d7426705d5
@ -64,7 +64,7 @@ class CheckData extends Command
|
||||
|
||||
public function fire()
|
||||
{
|
||||
$this->logMessage(date('Y-m-d') . ' Running CheckData...');
|
||||
$this->logMessage(date('Y-m-d h:i:s') . ' Running CheckData...');
|
||||
|
||||
if ($database = $this->option('database')) {
|
||||
config(['database.default' => $database]);
|
||||
|
80
app/Console/Commands/UpdateKey.php
Normal file
80
app/Console/Commands/UpdateKey.php
Normal file
@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use App\Models\AccountGateway;
|
||||
use App\Models\BankAccount;
|
||||
use Artisan;
|
||||
use Crypt;
|
||||
use Illuminate\Encryption\Encrypter;
|
||||
|
||||
/**
|
||||
* Class PruneData.
|
||||
*/
|
||||
class UpdateKey extends Command
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'ninja:update-key';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Update application key';
|
||||
|
||||
public function fire()
|
||||
{
|
||||
$this->info(date('Y-m-d h:i:s') . ' Running UpdateKey...');
|
||||
|
||||
// load the current values
|
||||
$gatewayConfigs = [];
|
||||
$bankUsernames = [];
|
||||
|
||||
foreach (AccountGateway::all() as $gateway) {
|
||||
$gatewayConfigs[$gateway->id] = $gateway->getConfig();
|
||||
}
|
||||
|
||||
foreach (BankAccount::all() as $bank) {
|
||||
$bankUsernames[$bank->id] = $bank->getUsername();
|
||||
}
|
||||
|
||||
// set the new key and create a new encrypter
|
||||
Artisan::call('key:generate');
|
||||
$key = base64_decode(str_replace('base64:', '', config('app.key')));
|
||||
$crypt = new Encrypter($key, config('app.cipher'));
|
||||
|
||||
// update values using the new key/encrypter
|
||||
foreach (AccountGateway::all() as $gateway) {
|
||||
$config = $gatewayConfigs[$gateway->id];
|
||||
$gateway->config = $crypt->encrypt(json_encode($config));
|
||||
$gateway->save();
|
||||
}
|
||||
|
||||
foreach (BankAccount::all() as $bank) {
|
||||
$username = $bankUsernames[$bank->id];
|
||||
$bank->username = $crypt->encrypt($username);
|
||||
$bank->save();
|
||||
}
|
||||
|
||||
$this->info(date('Y-m-d h:i:s') . ' Successfully updated the application key');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function getArguments()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function getOptions()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
@ -29,6 +29,7 @@ class Kernel extends ConsoleKernel
|
||||
'App\Console\Commands\MakeClass',
|
||||
'App\Console\Commands\InitLookup',
|
||||
'App\Console\Commands\CalculatePayouts',
|
||||
'App\Console\Commands\UpdateKey',
|
||||
];
|
||||
|
||||
/**
|
||||
|
@ -71,19 +71,24 @@ class HandleUserLoggedIn
|
||||
Session::flash('warning', trans('texts.logo_too_large', ['size' => $account->getLogoSize() . 'KB']));
|
||||
}
|
||||
|
||||
// check custom gateway id is correct
|
||||
if (! Utils::isNinja()) {
|
||||
// check custom gateway id is correct
|
||||
$gateway = Gateway::find(GATEWAY_CUSTOM);
|
||||
if (! $gateway || $gateway->name !== 'Custom') {
|
||||
Session::flash('error', trans('texts.error_incorrect_gateway_ids'));
|
||||
}
|
||||
/*
|
||||
|
||||
// if APP_KEY isn't set use the default
|
||||
if (! env('APP_KEY')) {
|
||||
Session::flash('error', trans('texts.error_app_key_not_set'));
|
||||
} elseif (in_array(, ['SomeRandomString', 'SomeRandomStringSomeRandomString', 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'])) {
|
||||
$fp = fopen(base_path().'/.env', 'a');
|
||||
fwrite($fp, "\nAPP_KEY=" . config('app.key'));
|
||||
fclose($fp);
|
||||
}
|
||||
|
||||
// warn if using the default app key
|
||||
if (in_array(config('app.key'), ['SomeRandomString', 'SomeRandomStringSomeRandomString', 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'])) {
|
||||
Session::flash('error', trans('texts.error_app_key_set_to_default'));
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Crypt;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
/**
|
||||
@ -33,6 +34,22 @@ class BankAccount extends EntityModel
|
||||
return ENTITY_BANK_ACCOUNT;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getUsername()
|
||||
{
|
||||
return Crypt::decrypt($this->username);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $config
|
||||
*/
|
||||
public function setUsername($value)
|
||||
{
|
||||
$this->username = Crypt::encrypt($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
|
@ -2302,8 +2302,7 @@ $LANG = array(
|
||||
'app_version' => 'App Version',
|
||||
'ofx_version' => 'OFX Version',
|
||||
'gateway_help_23' => ':link to get your Stripe API keys.',
|
||||
'error_app_key_not_set' => 'Error: the APP_KEY value is not set in the .env file.',
|
||||
'error_app_key_set_to_default' => 'Error: the APP_KEY value is set to the default in the .env file.',
|
||||
'error_app_key_set_to_default' => 'Error: APP_KEY is set to a default value, to update it backup your database and then run <code>php artisan ninja:update-key</code>',
|
||||
'charge_late_fee' => 'Charge Late Fee',
|
||||
'late_fee_amount' => 'Late Fee Amount',
|
||||
'late_fee_percent' => 'Late Fee Percent',
|
||||
|
Loading…
Reference in New Issue
Block a user