Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Encryption is optional (but on by default) and a command to switch from one to the other
James Cole5bbaaece3839
diff --git a/.env.example b/.env.exampleindex 87540a4f1c..04528da7fc 100755--- a/.env.example+++ b/.env.example@@ -43,6 +43,7 @@ CACHE_PREFIX=fireflyGOOGLE_MAPS_API_KEY=ANALYTICS_ID=+USE_ENCRYPTION=truePUSHER_KEY=PUSHER_SECRET=diff --git a/app/Console/Commands/UseEncryption.php b/app/Console/Commands/UseEncryption.phpnew file mode 100644index 0000000000..d3c3e178c0--- /dev/null+++ b/app/Console/Commands/UseEncryption.php@@ -0,0 +1,66 @@+<?php++namespace FireflyIII\Console\Commands;++use Illuminate\Console\Command;+use Illuminate\Support\Str;++class UseEncryption extends Command+{+ /**+ * The console command description.+ *+ * @var string+ */+ protected $description = 'This command will make sure that entries in the database will be encrypted (or not) according to the settings in .env';+ /**+ * The name and signature of the console command.+ *+ * @var string+ */+ protected $signature = 'firefly:use-encryption';++ /**+ * Create a new command instance.+ *+ */+ public function __construct()+ {+ parent::__construct();+ }++ /**+ * Execute the console command.+ */+ public function handle()+ {+ //+ $this->handleObjects('Account', 'name', 'encrypted');+ $this->handleObjects('Bill', 'name', 'name_encrypted');+ $this->handleObjects('Bill', 'match', 'match_encrypted');+ $this->handleObjects('Budget', 'name', 'encrypted');+ $this->handleObjects('Category', 'name', 'encrypted');+ $this->handleObjects('PiggyBank', 'name', 'encrypted');+ $this->handleObjects('TransactionJournal', 'description', 'encrypted');+ }++ /**+ * @param string $class+ * @param string $field+ * @param string $indicator+ */+ public function handleObjects(string $class, string $field, string $indicator)+ {+ $fqn = sprintf('FireflyIII\Models\%s', $class);+ $encrypt = config('firefly.encryption') ? 0 : 1;+ $set = $fqn::where($indicator, $encrypt)->get();++ foreach ($set as $entry) {+ $newName = $entry->$field;+ $entry->$field = $newName;+ $entry->save();+ }++ $this->line(sprintf('Updated %d %s.', $set->count(), strtolower(Str::plural($class))));+ }+}diff --git a/app/Console/Kernel.php b/app/Console/Kernel.phpindex 61537ce4e8..8ea0f88014 100644--- a/app/Console/Kernel.php+++ b/app/Console/Kernel.php@@ -16,10 +16,10 @@ namespace FireflyIII\Console;use FireflyIII\Console\Commands\CreateImport;use FireflyIII\Console\Commands\EncryptFile;use FireflyIII\Console\Commands\Import;-use FireflyIII\Console\Commands\MoveRepository;use FireflyIII\Console\Commands\ScanAttachments;use FireflyIII\Console\Commands\UpgradeDatabase;use FireflyIII\Console\Commands\UpgradeFireflyInstructions;+use FireflyIII\Console\Commands\UseEncryption;use FireflyIII\Console\Commands\VerifyDatabase;use Illuminate\Foundation\Console\Kernel as ConsoleKernel;@@ -63,6 +63,7 @@ class Kernel extends ConsoleKernelEncryptFile::class,ScanAttachments::class,UpgradeDatabase::class,+ UseEncryption::class,];/**diff --git a/app/Models/Account.php b/app/Models/Account.phpindex 4810c6006e..11b337ba10 100644--- a/app/Models/Account.php+++ b/app/Models/Account.php@@ -85,7 +85,7 @@ class Account extends Modelforeach ($search as $name => $value) {$query->where($name, $value);}- $set = $query->get(['accounts.*']);+ $set = $query->get(['accounts.*']);// account must have a name. If not set, use IBAN.if (!isset($fields['name'])) {@@ -93,7 +93,6 @@ class Account extends Model}-/** @var Account $account */foreach ($set as $account) {if ($account->name == $fields['name']) {@@ -316,8 +315,9 @@ class Account extends Model*/public function setNameAttribute($value){- $this->attributes['name'] = $value;- $this->attributes['encrypted'] = false;+ $encrypt = config('firefly.encryption');+ $this->attributes['name'] = $encrypt ? Crypt::encrypt($value) : $value;+ $this->attributes['encrypted'] = $encrypt;}/**diff --git a/app/Models/Bill.php b/app/Models/Bill.phpindex bf67e0f730..54a7429746 100644--- a/app/Models/Bill.php+++ b/app/Models/Bill.php@@ -35,7 +35,7 @@ class Bill extends Model* @var array*/protected $casts- = [+ = ['created_at' => 'date','updated_at' => 'date','deleted_at' => 'date',@@ -47,7 +47,7 @@ class Bill extends Model'match_encrypted' => 'boolean',];/** @var array */- protected $dates = ['created_at', 'updated_at', 'deleted_at'];+ protected $dates = ['created_at', 'updated_at', 'deleted_at'];protected $fillable= ['name', 'match', 'amount_min', 'match_encrypted', 'name_encrypted', 'user_id', 'amount_max', 'date', 'repeat_freq', 'skip','automatch', 'active',];@@ -120,8 +120,9 @@ class Bill extends Model*/public function setMatchAttribute($value){- $this->attributes['match'] = Crypt::encrypt($value);- $this->attributes['match_encrypted'] = true;+ $encrypt = config('firefly.encryption');+ $this->attributes['match'] = $encrypt ? Crypt::encrypt($value) : $value;+ $this->attributes['match_encrypted'] = $encrypt;}/**@@ -129,8 +130,9 @@ class Bill extends Model*/public function setNameAttribute($value){- $this->attributes['name'] = Crypt::encrypt($value);- $this->attributes['name_encrypted'] = true;+ $encrypt = config('firefly.encryption');+ $this->attributes['name'] = $encrypt ? Crypt::encrypt($value) : $value;+ $this->attributes['name_encrypted'] = $encrypt;}/**diff --git a/app/Models/Budget.php b/app/Models/Budget.phpindex d62e195352..504802e05a 100644--- a/app/Models/Budget.php+++ b/app/Models/Budget.php@@ -121,8 +121,9 @@ class Budget extends Model*/public function setNameAttribute($value){- $this->attributes['name'] = $value;- $this->attributes['encrypted'] = false;+ $encrypt = config('firefly.encryption');+ $this->attributes['name'] = $encrypt ? Crypt::encrypt($value) : $value;+ $this->attributes['encrypted'] = $encrypt;}/**diff --git a/app/Models/Category.php b/app/Models/Category.phpindex e8e665bff2..50349e9b44 100644--- a/app/Models/Category.php+++ b/app/Models/Category.php@@ -115,8 +115,9 @@ class Category extends Model*/public function setNameAttribute($value){- $this->attributes['name'] = $value;- $this->attributes['encrypted'] = false;+ $encrypt = config('firefly.encryption');+ $this->attributes['name'] = $encrypt ? Crypt::encrypt($value) : $value;+ $this->attributes['encrypted'] = $encrypt;}/**diff --git a/app/Models/PiggyBank.php b/app/Models/PiggyBank.phpindex 34c742bd7f..d5b2b00187 100644--- a/app/Models/PiggyBank.php+++ b/app/Models/PiggyBank.php@@ -159,8 +159,9 @@ class PiggyBank extends Model*/public function setNameAttribute($value){- $this->attributes['name'] = $value;- $this->attributes['encrypted'] = false;+ $encrypt = config('firefly.encryption');+ $this->attributes['name'] = $encrypt ? Crypt::encrypt($value) : $value;+ $this->attributes['encrypted'] = $encrypt;}/**diff --git a/app/Models/TransactionJournal.php b/app/Models/TransactionJournal.phpindex 1cf5faf17f..1808955271 100644--- a/app/Models/TransactionJournal.php+++ b/app/Models/TransactionJournal.php@@ -371,8 +371,9 @@ class TransactionJournal extends TransactionJournalSupport*/public function setDescriptionAttribute($value){- $this->attributes['description'] = $value;- $this->attributes['encrypted'] = false;+ $encrypt = config('firefly.encryption');+ $this->attributes['description'] = $encrypt ? Crypt::encrypt($value) : $value;+ $this->attributes['encrypted'] = $encrypt;}/**diff --git a/config/firefly.php b/config/firefly.phpindex 73ae9563e8..67f9ccdd15 100644--- a/config/firefly.php+++ b/config/firefly.php@@ -22,6 +22,7 @@ return ['single_user_mode' => true,'is_demo_site' => false,],+ 'encryption' => (is_null(env('USE_ENCRYPTION')) || env('USE_ENCRYPTION') === true),'chart' => 'chartjs','version' => '4.3.2','csv_import_enabled' => true,