2021-06-08 12:19:56 -05:00
|
|
|
<?php
|
2021-08-10 12:31:55 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
* VerifySecurityAlerts.php
|
|
|
|
* Copyright (c) 2021 james@firefly-iii.org
|
|
|
|
*
|
|
|
|
* This file is part of Firefly III (https://github.com/firefly-iii).
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program 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 Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2021-07-03 05:32:02 -05:00
|
|
|
declare(strict_types=1);
|
2021-06-08 12:19:56 -05:00
|
|
|
|
|
|
|
namespace FireflyIII\Console\Commands;
|
|
|
|
|
|
|
|
use Illuminate\Console\Command;
|
|
|
|
use Storage;
|
2021-06-11 13:19:59 -05:00
|
|
|
use Log;
|
2021-06-08 12:19:56 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Class VerifySecurityAlerts
|
|
|
|
*/
|
|
|
|
class VerifySecurityAlerts extends Command
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* The name and signature of the console command.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $signature = 'firefly-iii:verify-security-alerts';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The console command description.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $description = 'Verify security alerts';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Execute the console command.
|
|
|
|
*
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
public function handle(): int
|
|
|
|
{
|
|
|
|
// remove old advisory
|
|
|
|
app('fireflyconfig')->delete('upgrade_security_message');
|
|
|
|
app('fireflyconfig')->delete('upgrade_security_level');
|
|
|
|
|
|
|
|
// check for security advisories.
|
|
|
|
$version = config('firefly.version');
|
|
|
|
$disk = Storage::disk('resources');
|
|
|
|
if (!$disk->has('alerts.json')) {
|
2021-06-11 13:19:59 -05:00
|
|
|
Log::debug('No alerts.json file present.');
|
2021-06-08 12:19:56 -05:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
$content = $disk->get('alerts.json');
|
|
|
|
$json = json_decode($content, true, 10);
|
|
|
|
|
|
|
|
/** @var array $array */
|
|
|
|
foreach ($json as $array) {
|
|
|
|
if ($version === $array['version'] && true === $array['advisory']) {
|
2021-06-11 13:19:59 -05:00
|
|
|
Log::debug(sprintf('Version %s has an alert!', $array['version']));
|
2021-06-08 12:19:56 -05:00
|
|
|
// add advisory to configuration.
|
|
|
|
app('fireflyconfig')->set('upgrade_security_message', $array['message']);
|
|
|
|
app('fireflyconfig')->set('upgrade_security_level', $array['level']);
|
|
|
|
|
|
|
|
// depends on level
|
|
|
|
if ('info' === $array['level']) {
|
2021-06-11 13:19:59 -05:00
|
|
|
Log::debug('INFO level alert');
|
2021-06-08 12:19:56 -05:00
|
|
|
$this->info($array['message']);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if ('warning' === $array['level']) {
|
2021-06-11 13:19:59 -05:00
|
|
|
Log::debug('WARNING level alert');
|
2021-06-08 12:19:56 -05:00
|
|
|
$this->warn('------------------------ :o');
|
|
|
|
$this->warn($array['message']);
|
|
|
|
$this->warn('------------------------ :o');
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if ('danger' === $array['level']) {
|
2021-06-11 13:19:59 -05:00
|
|
|
Log::debug('DANGER level alert');
|
2021-06-08 12:19:56 -05:00
|
|
|
$this->error('------------------------ :-(');
|
|
|
|
$this->error($array['message']);
|
|
|
|
$this->error('------------------------ :-(');
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2021-06-11 13:19:59 -05:00
|
|
|
Log::debug('This version is not mentioned.');
|
2021-06-08 12:19:56 -05:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|