mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-15 16:57:09 +00:00
Code for #2616
This commit is contained in:
@@ -92,6 +92,7 @@ php artisan firefly-iii:fix-long-descriptions
|
|||||||
# report commands
|
# report commands
|
||||||
php artisan firefly-iii:report-empty-objects
|
php artisan firefly-iii:report-empty-objects
|
||||||
php artisan firefly-iii:report-sum
|
php artisan firefly-iii:report-sum
|
||||||
|
php artisan firefly-iii:restore-oauth-keys
|
||||||
|
|
||||||
php artisan passport:install
|
php artisan passport:install
|
||||||
php artisan cache:clear
|
php artisan cache:clear
|
||||||
|
@@ -71,7 +71,8 @@ class CorrectDatabase extends Command
|
|||||||
'firefly-iii:fix-account-types',
|
'firefly-iii:fix-account-types',
|
||||||
'firefly-iii:rename-meta-fields',
|
'firefly-iii:rename-meta-fields',
|
||||||
'firefly-iii:fix-ob-currencies',
|
'firefly-iii:fix-ob-currencies',
|
||||||
'firefly-iii:fix-long-descriptions'
|
'firefly-iii:fix-long-descriptions',
|
||||||
|
'firefly-iii:restore-oauth-keys'
|
||||||
];
|
];
|
||||||
foreach ($commands as $command) {
|
foreach ($commands as $command) {
|
||||||
$this->line(sprintf('Now executing %s', $command));
|
$this->line(sprintf('Now executing %s', $command));
|
||||||
|
@@ -51,6 +51,7 @@ class FixLongDescriptions extends Command
|
|||||||
*/
|
*/
|
||||||
public function handle(): int
|
public function handle(): int
|
||||||
{
|
{
|
||||||
|
$start = microtime(true);
|
||||||
$journals = TransactionJournal::get(['id', 'description']);
|
$journals = TransactionJournal::get(['id', 'description']);
|
||||||
/** @var TransactionJournal $journal */
|
/** @var TransactionJournal $journal */
|
||||||
foreach ($journals as $journal) {
|
foreach ($journals as $journal) {
|
||||||
@@ -70,7 +71,8 @@ class FixLongDescriptions extends Command
|
|||||||
$this->line(sprintf('Truncated description of transaction group #%d', $group->id));
|
$this->line(sprintf('Truncated description of transaction group #%d', $group->id));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
$end = round(microtime(true) - $start, 2);
|
||||||
|
$this->info(sprintf('Verified all transaction group and journal title lengths in %s seconds.', $end));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
137
app/Console/Commands/Integrity/RestoreOAuthKeys.php
Normal file
137
app/Console/Commands/Integrity/RestoreOAuthKeys.php
Normal file
@@ -0,0 +1,137 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* RestoreOAuthKeys.php
|
||||||
|
* Copyright (c) 2019 thegrumpydictator@gmail.com
|
||||||
|
*
|
||||||
|
* This file is part of Firefly III.
|
||||||
|
*
|
||||||
|
* Firefly III is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Firefly III is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace FireflyIII\Console\Commands\Integrity;
|
||||||
|
|
||||||
|
use Artisan;
|
||||||
|
use Crypt;
|
||||||
|
use Illuminate\Console\Command;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class RestoreOAuthKeys
|
||||||
|
*/
|
||||||
|
class RestoreOAuthKeys extends Command
|
||||||
|
{
|
||||||
|
private const PRIVATE_KEY = 'oauth_private_key';
|
||||||
|
private const PUBLIC_KEY = 'oauth_public_key';
|
||||||
|
/**
|
||||||
|
* The console command description.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $description = 'Will restore the OAuth keys generated for the system.';
|
||||||
|
/**
|
||||||
|
* The name and signature of the console command.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $signature = 'firefly-iii:restore-oauth-keys';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the console command.
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function handle(): int
|
||||||
|
{
|
||||||
|
$this->restoreOAuthKeys();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private function generateKeys(): void
|
||||||
|
{
|
||||||
|
Artisan::call('passport:keys');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
private function keysInDatabase(): bool
|
||||||
|
{
|
||||||
|
return app('fireflyconfig')->has(self::PRIVATE_KEY) && app('fireflyconfig')->has(self::PUBLIC_KEY);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
private function keysOnDrive(): bool
|
||||||
|
{
|
||||||
|
$private = storage_path('oauth-private.key');
|
||||||
|
$public = storage_path('oauth-public.key');
|
||||||
|
|
||||||
|
return file_exists($private) && file_exists($public);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private function restoreKeysFromDB(): void
|
||||||
|
{
|
||||||
|
$privateContent = Crypt::decrypt(app('fireflyconfig')->get(self::PRIVATE_KEY)->data);
|
||||||
|
$publicContent = Crypt::decrypt(app('fireflyconfig')->get(self::PUBLIC_KEY)->data);
|
||||||
|
$private = storage_path('oauth-private.key');
|
||||||
|
$public = storage_path('oauth-public.key');
|
||||||
|
file_put_contents($private, $privateContent);
|
||||||
|
file_put_contents($public, $publicContent);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private function restoreOAuthKeys(): void
|
||||||
|
{
|
||||||
|
if (!$this->keysInDatabase() && !$this->keysOnDrive()) {
|
||||||
|
$this->generateKeys();
|
||||||
|
$this->storeKeysInDB();
|
||||||
|
$this->line('Generated and stored new keys.');
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if ($this->keysInDatabase() && !$this->keysOnDrive()) {
|
||||||
|
$this->restoreKeysFromDB();
|
||||||
|
$this->line('Restored OAuth keys from database.');
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!$this->keysInDatabase() && $this->keysOnDrive()) {
|
||||||
|
$this->storeKeysInDB();
|
||||||
|
$this->line('Stored OAuth keys in database.');
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$this->line('OAuth keys are OK');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private function storeKeysInDB(): void
|
||||||
|
{
|
||||||
|
$private = storage_path('oauth-private.key');
|
||||||
|
$public = storage_path('oauth-public.key');
|
||||||
|
app('fireflyconfig')->set(self::PRIVATE_KEY, Crypt::encrypt(file_get_contents($private)));
|
||||||
|
app('fireflyconfig')->set(self::PUBLIC_KEY, Crypt::encrypt(file_get_contents($public)));
|
||||||
|
}
|
||||||
|
}
|
@@ -93,6 +93,7 @@ class UpgradeDatabase extends Command
|
|||||||
// two report commands
|
// two report commands
|
||||||
'firefly-iii:report-empty-objects',
|
'firefly-iii:report-empty-objects',
|
||||||
'firefly-iii:report-sum',
|
'firefly-iii:report-sum',
|
||||||
|
'firefly-iii:restore-oauth-keys',
|
||||||
|
|
||||||
// instructions
|
// instructions
|
||||||
'firefly:instructions update',
|
'firefly:instructions update',
|
||||||
|
@@ -100,7 +100,8 @@ class InstallController extends Controller
|
|||||||
'firefly-iii:fix-account-types' => [],
|
'firefly-iii:fix-account-types' => [],
|
||||||
'firefly-iii:rename-meta-fields' => [],
|
'firefly-iii:rename-meta-fields' => [],
|
||||||
'firefly-iii:fix-ob-currencies' => [],
|
'firefly-iii:fix-ob-currencies' => [],
|
||||||
'firefly-iii:fix-long-descriptions' => [],
|
'firefly-iii:fix-long-descriptions' => [],
|
||||||
|
'firefly-iii:restore-oauth-keys' => [],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -54,6 +54,16 @@ class FireflyConfig
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $name
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function has(string $name): bool
|
||||||
|
{
|
||||||
|
return Configuration::where('name', $name)->count() === 1;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @param mixed $default
|
* @param mixed $default
|
||||||
|
@@ -167,6 +167,7 @@
|
|||||||
|
|
||||||
"@php artisan firefly-iii:report-empty-objects",
|
"@php artisan firefly-iii:report-empty-objects",
|
||||||
"@php artisan firefly-iii:report-sum",
|
"@php artisan firefly-iii:report-sum",
|
||||||
|
"@php artisan firefly-iii:restore-oauth-keys",
|
||||||
|
|
||||||
"@php artisan firefly:instructions update",
|
"@php artisan firefly:instructions update",
|
||||||
"@php artisan passport:install"
|
"@php artisan passport:install"
|
||||||
|
Reference in New Issue
Block a user