1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-22 17:31:35 +02:00
invoiceninja/app/Console/Commands/EncryptNinja.php

85 lines
2.0 KiB
PHP
Raw Normal View History

2024-02-09 05:06:34 +01:00
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
2024-04-12 06:15:41 +02:00
* @copyright Copyright (c) 2024. Invoice Ninja LLC (https://invoiceninja.com)
2024-02-09 05:06:34 +01:00
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Storage;
class EncryptNinja extends Command
{
protected $files = [
'resources/views/email/template/admin_premium.blade.php',
'resources/views/email/template/client_premium.blade.php',
];
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'ninja:crypt {--encrypt} {--decrypt}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Encrypt Protected files';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
2024-02-13 05:25:18 +01:00
if($this->option('encrypt')) {
2024-02-09 05:06:34 +01:00
return $this->encryptFiles();
2024-02-13 05:25:18 +01:00
}
2024-02-09 05:06:34 +01:00
if($this->option('decrypt')) {
return $this->decryptFiles();
}
}
private function encryptFiles()
{
foreach ($this->files as $file) {
$contents = Storage::disk('base')->get($file);
$encrypted = encrypt($contents);
Storage::disk('base')->put($file.".enc", $encrypted);
2024-02-13 07:11:40 +01:00
// Storage::disk('base')->delete($file);
2024-02-09 05:06:34 +01:00
}
}
private function decryptFiles()
{
foreach ($this->files as $file) {
$encrypted_file = "{$file}.enc";
$contents = Storage::disk('base')->get($encrypted_file);
$decrypted = decrypt($contents);
Storage::disk('base')->put($file, $decrypted);
}
}
2024-02-13 05:25:18 +01:00
}