diff --git a/app/Console/Commands/CheckData.php b/app/Console/Commands/CheckData.php index fd3f8543df..4935371bed 100644 --- a/app/Console/Commands/CheckData.php +++ b/app/Console/Commands/CheckData.php @@ -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]); diff --git a/app/Console/Commands/UpdateKey.php b/app/Console/Commands/UpdateKey.php new file mode 100644 index 0000000000..d2c1b2f209 --- /dev/null +++ b/app/Console/Commands/UpdateKey.php @@ -0,0 +1,80 @@ +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 []; + } +} diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 46ab045be1..f43e8fafaa 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -29,6 +29,7 @@ class Kernel extends ConsoleKernel 'App\Console\Commands\MakeClass', 'App\Console\Commands\InitLookup', 'App\Console\Commands\CalculatePayouts', + 'App\Console\Commands\UpdateKey', ]; /** diff --git a/app/Listeners/HandleUserLoggedIn.php b/app/Listeners/HandleUserLoggedIn.php index d25fe5fcaf..2e0e058e51 100644 --- a/app/Listeners/HandleUserLoggedIn.php +++ b/app/Listeners/HandleUserLoggedIn.php @@ -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')); } - */ } } } diff --git a/app/Models/BankAccount.php b/app/Models/BankAccount.php index 2cd4a65646..a5365ee9f8 100644 --- a/app/Models/BankAccount.php +++ b/app/Models/BankAccount.php @@ -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 */ diff --git a/resources/lang/en/texts.php b/resources/lang/en/texts.php index d10b981163..f1042d9844 100644 --- a/resources/lang/en/texts.php +++ b/resources/lang/en/texts.php @@ -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 php artisan ninja:update-key', 'charge_late_fee' => 'Charge Late Fee', 'late_fee_amount' => 'Late Fee Amount', 'late_fee_percent' => 'Late Fee Percent',