Skip to content

An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.

feat: encrypt instance email settings

peaklabs-devb17a61a043cb
diff --git a/database/migrations/2024_12_10_122142_encrypt_instance_settings_email_columns.php b/database/migrations/2024_12_10_122142_encrypt_instance_settings_email_columns.php
new file mode 100644
index 0000000000..618b8df90d
--- /dev/null
+++ b/database/migrations/2024_12_10_122142_encrypt_instance_settings_email_columns.php
@@ -0,0 +1,64 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Crypt;
+use Illuminate\Support\Facades\DB;
+use Illuminate\Support\Facades\Schema;
+
+return new class extends Migration
+{
+ /**
+ * Run the migrations.
+ */
+ public function up(): void
+ {
+ if (DB::table('instance_settings')->exists()) {
+ Schema::table('instance_settings', function (Blueprint $table) {
+ $table->text('smtp_from_address')->change();
+ $table->text('smtp_from_name')->change();
+ $table->text('smtp_recipients')->change();
+ $table->text('smtp_host')->change();
+ $table->text('smtp_username')->change();
+ });
+
+ $settings = DB::table('instance_settings')->get();
+ foreach ($settings as $setting) {
+ DB::table('instance_settings')->where('id', $setting->id)->update([
+ 'smtp_from_address' => Crypt::encryptString($setting->smtp_from_address),
+ 'smtp_from_name' => Crypt::encryptString($setting->smtp_from_name),
+ 'smtp_recipients' => Crypt::encryptString($setting->smtp_recipients),
+ 'smtp_host' => Crypt::encryptString($setting->smtp_host),
+ 'smtp_username' => Crypt::encryptString($setting->smtp_username),
+ ]);
+ }
+ }
+ }
+
+ /**
+ * Reverse the migrations.
+ */
+ public function down(): void
+ {
+ Schema::table('instance_settings', function (Blueprint $table) {
+ $table->string('smtp_from_address')->change();
+ $table->string('smtp_from_name')->change();
+ $table->string('smtp_recipients')->change();
+ $table->string('smtp_host')->change();
+ $table->string('smtp_username')->change();
+ });
+
+ if (DB::table('instance_settings')->exists()) {
+ $settings = DB::table('instance_settings')->get();
+ foreach ($settings as $setting) {
+ DB::table('instance_settings')->where('id', $setting->id)->update([
+ 'smtp_from_address' => Crypt::decryptString($setting->smtp_from_address),
+ 'smtp_from_name' => Crypt::decryptString($setting->smtp_from_name),
+ 'smtp_recipients' => Crypt::decryptString($setting->smtp_recipients),
+ 'smtp_host' => Crypt::decryptString($setting->smtp_host),
+ 'smtp_username' => Crypt::decryptString($setting->smtp_username),
+ ]);
+ }
+ }
+ }
+};