Apply fixes from StyleCI

This commit is contained in:
Manish Verma
2021-02-26 09:00:06 +00:00
committed by StyleCI Bot
parent 2c3a417e80
commit 72d6529157
2 changed files with 35 additions and 34 deletions

View File

@@ -1,17 +1,18 @@
<?php
namespace App\Console\Commands;
//classes
use Illuminate\Console\Command;
use Exception;
use Hash;
use Artisan;
use File;
use Illuminate\Support\Str;
use Illuminate\Encryption\Encrypter;
//Models
use App\User;
use App\Model\helpdesk\Email\Emails;
use App\User;
use Artisan;
use Exception;
use File;
use Hash;
use Illuminate\Console\Command;
//Models
use Illuminate\Encryption\Encrypter;
use Illuminate\Support\Str;
class SecureFaveoAPPKey extends Command
{
@@ -30,7 +31,6 @@ class SecureFaveoAPPKey extends Command
protected $description = 'Command updates the APP_KEY of the system keeping encrypted data intact with new key to make it easy for users to secure their app for old sahred key. Admin credentials are required to run this command successfully.';
/**
*
* @var array
*/
private $email = [];
@@ -54,30 +54,30 @@ class SecureFaveoAPPKey extends Command
{
$username = $this->ask('Enter admin account username');
$password = $this->secret('Enter admin account password');
if(!$username || !$password) {
throw new Exception("Username and password are required.", 1);
if (!$username || !$password) {
throw new Exception('Username and password are required.', 1);
}
if(!Hash::check($password, User::where('user_name', $username)->value('password'))) {
throw new Exception('We do not recognize you, make sure the username or password you provided are correct.',1);
if (!Hash::check($password, User::where('user_name', $username)->value('password'))) {
throw new Exception('We do not recognize you, make sure the username or password you provided are correct.', 1);
}
if ($this->confirm('This will update APP_KEY in your environment which may invalidate all your encrypted URLs, such URLs will no longer work and result in 404. Do you wish to continue?', true)) {
$this->info('That\'s a smart choice');
$file = base_path().DIRECTORY_SEPARATOR.'.env';
if(file_exists($file)) {
if (file_exists($file)) {
$datacontent = File::get($file);
$this->updateAppKey($file, $datacontent);
}
$this->line("\r\nAPP_KEY has been updated in the environment.");
$this->line("\r\nNext you might want to check if your configured email is working fine or not. If it has any problem you can update the password and restart your queue workers if you are processing mail jobs in queue.\r\n");
exit();
exit();
}
$this->info('Alright, calm down we did not make any changes to your environment. But if you think your APP_KEY was compromised or you were using Faveo without generating APP_KEY explicitly(for version v1.10.* or older) we recommend you to run this command on priority basis.');
}
/**
* Function adds APP_KEY and generate new application key if does not
* exist in .env
* exist in .env.
*
* This method also updates the email passwords after new key generation
* so that the imap/smtp does not stop working after update
@@ -85,15 +85,15 @@ class SecureFaveoAPPKey extends Command
* This method also updates the LDAP passwords after new key generation
* so that the LDAP plugin does not stop working after update
*
* @param string $file
* @param string $datacontent
* @param string $file
* @param string $datacontent
*
* @return voif
*/
private function updateAppKey(string $file, string $datacontent) :void
private function updateAppKey(string $file, string $datacontent): void
{
$this->fetchAndStoreEmailPassword();
if(!$this->doesEnvVaribaleExists($datacontent, 'APP_KEY')) {
if (!$this->doesEnvVaribaleExists($datacontent, 'APP_KEY')) {
$datacontent = $datacontent."\r\nAPP_KEY=base64:h3KjrHeVxyE+j6c8whTAs2YI+7goylGZ/e2vElgXT6I=";
File::put($file, $datacontent);
}
@@ -110,38 +110,38 @@ class SecureFaveoAPPKey extends Command
}
/**
* Function checks if given $key exist in $envContent string
* Function checks if given $key exist in $envContent string.
*
* @param string $envContent
* @param string $key
* @param string $envContent
* @param string $key
*
* @return bool true if given key exist otherwise false
* @return bool true if given key exist otherwise false
*/
private function doesEnvVaribaleExists(string $envContent, string $key):bool
private function doesEnvVaribaleExists(string $envContent, string $key): bool
{
return !(strpos($envContent, $key) === false);
}
/**
* Function stores all emails and their passwords as key => value in $emails prop
* Function stores all emails and their passwords as key => value in $emails prop.
*
* @return void
*/
private function fetchAndStoreEmailPassword():void
private function fetchAndStoreEmailPassword(): void
{
$this->emails = Emails::all()->pluck('password', 'email_address')->toArray();
}
/**
* Function updates all emails's password
* Function updates all emails's password.
*
* @return void
*/
private function updateEmailsPasswordWithNewKey($encrypter):void
private function updateEmailsPasswordWithNewKey($encrypter): void
{
foreach ($this->emails as $email => $password) {
Emails::where('email_address', $email)->update([
'password' => $encrypter->encrypt($password)
'password' => $encrypter->encrypt($password),
]);
}
}
@@ -149,10 +149,11 @@ class SecureFaveoAPPKey extends Command
/**
* Extract the encryption key from the given configuration.
*
* @param array $config
* @return string
* @param array $config
*
* @throws \RuntimeException
*
* @return string
*/
private function key()
{

View File

@@ -23,7 +23,7 @@ class Kernel extends ConsoleKernel
\App\Console\Commands\Install::class,
\App\Console\Commands\InstallDB::class,
\App\Console\Commands\SetupTestEnv::class,
\App\Console\Commands\SecureFaveoAPPKey::class
\App\Console\Commands\SecureFaveoAPPKey::class,
];
/**