mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Show user info about mandatory updates.
This commit is contained in:
89
app/Console/Commands/VerifySecurityAlerts.php
Normal file
89
app/Console/Commands/VerifySecurityAlerts.php
Normal file
@@ -0,0 +1,89 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace FireflyIII\Console\Commands;
|
||||||
|
|
||||||
|
use Illuminate\Console\Command;
|
||||||
|
use Storage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new command instance.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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')) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
$content = $disk->get('alerts.json');
|
||||||
|
$json = json_decode($content, true, 10);
|
||||||
|
|
||||||
|
/** @var array $array */
|
||||||
|
foreach ($json as $array) {
|
||||||
|
// overrule array:
|
||||||
|
if ($version === $array['version'] && true === $array['advisory']) {
|
||||||
|
// 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']) {
|
||||||
|
$this->info($array['message']);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if ('warning' === $array['level']) {
|
||||||
|
$this->warn('------------------------ :o');
|
||||||
|
$this->warn($array['message']);
|
||||||
|
$this->warn('------------------------ :o');
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if ('danger' === $array['level']) {
|
||||||
|
$this->error('------------------------ :-(');
|
||||||
|
$this->error($array['message']);
|
||||||
|
$this->error('------------------------ :-(');
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
@@ -133,5 +133,14 @@ class Range
|
|||||||
{
|
{
|
||||||
$pref = app('preferences')->get('list-length', config('firefly.list_length', 10))->data;
|
$pref = app('preferences')->get('list-length', config('firefly.list_length', 10))->data;
|
||||||
app('view')->share('listLength', $pref);
|
app('view')->share('listLength', $pref);
|
||||||
|
|
||||||
|
// share security message:
|
||||||
|
if (
|
||||||
|
app('fireflyconfig')->has('upgrade_security_message')
|
||||||
|
&& app('fireflyconfig')->has('upgrade_security_level')
|
||||||
|
) {
|
||||||
|
app('view')->share('upgrade_security_message', app('fireflyconfig')->get('upgrade_security_message')->data);
|
||||||
|
app('view')->share('upgrade_security_level', app('fireflyconfig')->get('upgrade_security_level')->data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -46,7 +46,7 @@ class FireflyConfig
|
|||||||
Cache::forget($fullName);
|
Cache::forget($fullName);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
Configuration::where('name', $name)->delete();
|
Configuration::where('name', $name)->forceDelete();
|
||||||
} catch (Exception $e) { // @phpstan-ignore-line
|
} catch (Exception $e) { // @phpstan-ignore-line
|
||||||
// @ignoreException
|
// @ignoreException
|
||||||
}
|
}
|
||||||
@@ -138,7 +138,7 @@ class FireflyConfig
|
|||||||
public function set(string $name, $value): Configuration
|
public function set(string $name, $value): Configuration
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$config = Configuration::whereName($name)->first();
|
$config = Configuration::whereName($name)->whereNull('deleted_at')->first();
|
||||||
} catch (QueryException | Exception $e) { // @phpstan-ignore-line
|
} catch (QueryException | Exception $e) { // @phpstan-ignore-line
|
||||||
$item = new Configuration;
|
$item = new Configuration;
|
||||||
$item->name = $name;
|
$item->name = $name;
|
||||||
@@ -146,12 +146,12 @@ class FireflyConfig
|
|||||||
|
|
||||||
return $item;
|
return $item;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (null === $config) {
|
if (null === $config) {
|
||||||
$item = new Configuration;
|
$item = new Configuration;
|
||||||
$item->name = $name;
|
$item->name = $name;
|
||||||
$item->data = $value;
|
$item->data = $value;
|
||||||
$item->save();
|
$item->save();
|
||||||
|
|
||||||
Cache::forget('ff-config-' . $name);
|
Cache::forget('ff-config-' . $name);
|
||||||
|
|
||||||
return $item;
|
return $item;
|
||||||
|
@@ -94,6 +94,10 @@ return [
|
|||||||
'driver' => 'local',
|
'driver' => 'local',
|
||||||
'root' => base_path('resources/stubs'),
|
'root' => base_path('resources/stubs'),
|
||||||
],
|
],
|
||||||
|
'resources' => [
|
||||||
|
'driver' => 'local',
|
||||||
|
'root' => base_path('resources'),
|
||||||
|
],
|
||||||
|
|
||||||
'public' => [
|
'public' => [
|
||||||
'driver' => 'local',
|
'driver' => 'local',
|
||||||
|
@@ -235,7 +235,6 @@ class CreateSupportTables extends Migration
|
|||||||
$table->softDeletes();
|
$table->softDeletes();
|
||||||
$table->string('name', 50);
|
$table->string('name', 50);
|
||||||
$table->text('data');
|
$table->text('data');
|
||||||
$table->unique(['name']);
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@@ -83,6 +83,7 @@ return [
|
|||||||
'flash_info' => 'Message',
|
'flash_info' => 'Message',
|
||||||
'flash_warning' => 'Warning!',
|
'flash_warning' => 'Warning!',
|
||||||
'flash_error' => 'Error!',
|
'flash_error' => 'Error!',
|
||||||
|
'flash_danger' => 'Danger!',
|
||||||
'flash_info_multiple' => 'There is one message|There are :count messages',
|
'flash_info_multiple' => 'There is one message|There are :count messages',
|
||||||
'flash_error_multiple' => 'There is one error|There are :count errors',
|
'flash_error_multiple' => 'There is one error|There are :count errors',
|
||||||
'net_worth' => 'Net worth',
|
'net_worth' => 'Net worth',
|
||||||
|
@@ -8,6 +8,13 @@
|
|||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
{# MANDATORY UPDATE MESSAGE #}
|
||||||
|
{% if upgrade_security_message and upgrade_security_level %}
|
||||||
|
<div class="alert alert-{{ upgrade_security_level }} alert-dismissible" role="alert">
|
||||||
|
<strong>{{ ('flash_'~upgrade_security_level)|_ }}</strong> <i class="fa fa-exclamation-triangle"></i> {{ upgrade_security_message }}
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
{# SUCCESS MESSAGE (ALWAYS SINGULAR) #}
|
{# SUCCESS MESSAGE (ALWAYS SINGULAR) #}
|
||||||
{% if session_has('success') %}
|
{% if session_has('success') %}
|
||||||
<div class="alert alert-success alert-dismissible" role="alert">
|
<div class="alert alert-success alert-dismissible" role="alert">
|
||||||
|
Reference in New Issue
Block a user