@@ -2,8 +2,8 @@
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class UpdateServerSettingsDefaultTimezone extends Migration
|
||||
{
|
||||
|
||||
@@ -1,19 +1,25 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Crypt;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class EncryptExistingPrivateKeys extends Migration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
DB::table('private_keys')->chunkById(100, function ($keys) {
|
||||
foreach ($keys as $key) {
|
||||
DB::table('private_keys')
|
||||
->where('id', $key->id)
|
||||
->update(['private_key' => Crypt::encryptString($key->private_key)]);
|
||||
}
|
||||
});
|
||||
try {
|
||||
DB::table('private_keys')->chunkById(100, function ($keys) {
|
||||
foreach ($keys as $key) {
|
||||
DB::table('private_keys')
|
||||
->where('id', $key->id)
|
||||
->update(['private_key' => Crypt::encryptString($key->private_key)]);
|
||||
}
|
||||
});
|
||||
} catch (\Exception $e) {
|
||||
echo 'Encrypting private keys failed.';
|
||||
echo $e->getMessage();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
<?php
|
||||
|
||||
use App\Models\PrivateKey;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class PopulateSshKeysAndClearMuxDirectory extends Migration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
// Storage::disk('ssh-keys')->deleteDirectory('');
|
||||
// Storage::disk('ssh-keys')->makeDirectory('');
|
||||
|
||||
// Storage::disk('ssh-mux')->deleteDirectory('');
|
||||
// Storage::disk('ssh-mux')->makeDirectory('');
|
||||
// PrivateKey::chunk(100, function ($keys) {
|
||||
// foreach ($keys as $key) {
|
||||
// $key->storeInFileSystem();
|
||||
// if ($key->id === 0) {
|
||||
// Storage::disk('ssh-keys')->put('id.root@host.docker.internal', $key->private_key);
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@
|
||||
use App\Models\PrivateKey;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddSshKeyFingerprintToPrivateKeysTable extends Migration
|
||||
@@ -13,13 +14,20 @@ class AddSshKeyFingerprintToPrivateKeysTable extends Migration
|
||||
$table->string('fingerprint')->after('private_key')->nullable();
|
||||
});
|
||||
|
||||
PrivateKey::whereNull('fingerprint')->each(function ($key) {
|
||||
$fingerprint = PrivateKey::generateFingerprint($key->private_key);
|
||||
if ($fingerprint) {
|
||||
$key->fingerprint = $fingerprint;
|
||||
$key->save();
|
||||
}
|
||||
});
|
||||
try {
|
||||
DB::table('private_keys')->chunkById(100, function ($keys) {
|
||||
foreach ($keys as $key) {
|
||||
$fingerprint = PrivateKey::generateFingerprint($key->private_key);
|
||||
if ($fingerprint) {
|
||||
$key->fingerprint = $fingerprint;
|
||||
$key->save();
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch (\Exception $e) {
|
||||
echo 'Generating fingerprints failed.';
|
||||
echo $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
public function down()
|
||||
|
||||
@@ -11,19 +11,30 @@ class PopulateSshKeysDirectorySeeder extends Seeder
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
Storage::disk('ssh-keys')->deleteDirectory('');
|
||||
Storage::disk('ssh-keys')->makeDirectory('');
|
||||
Storage::disk('ssh-mux')->deleteDirectory('');
|
||||
Storage::disk('ssh-mux')->makeDirectory('');
|
||||
try {
|
||||
Storage::disk('ssh-keys')->deleteDirectory('');
|
||||
Storage::disk('ssh-keys')->makeDirectory('');
|
||||
Storage::disk('ssh-mux')->deleteDirectory('');
|
||||
Storage::disk('ssh-mux')->makeDirectory('');
|
||||
|
||||
PrivateKey::chunk(100, function ($keys) {
|
||||
foreach ($keys as $key) {
|
||||
echo 'Storing key: '.$key->name."\n";
|
||||
$key->storeInFileSystem();
|
||||
PrivateKey::chunk(100, function ($keys) {
|
||||
foreach ($keys as $key) {
|
||||
echo 'Storing key: '.$key->name."\n";
|
||||
$key->storeInFileSystem();
|
||||
}
|
||||
});
|
||||
|
||||
if (isDev()) {
|
||||
$user = env('PUID').':'.env('PGID');
|
||||
Process::run("chown -R $user ".storage_path('app/ssh/keys'));
|
||||
Process::run("chown -R $user ".storage_path('app/ssh/mux'));
|
||||
} else {
|
||||
Process::run('chown -R 9999:root '.storage_path('app/ssh/keys'));
|
||||
Process::run('chown -R 9999:root '.storage_path('app/ssh/mux'));
|
||||
}
|
||||
});
|
||||
|
||||
Process::run('chown -R 9999:9999 '.storage_path('app/ssh/keys'));
|
||||
Process::run('chown -R 9999:9999 '.storage_path('app/ssh/mux'));
|
||||
} catch (\Throwable $e) {
|
||||
echo "Error: {$e->getMessage()}\n";
|
||||
ray($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Enums\ProxyStatus;
|
||||
use App\Enums\ProxyTypes;
|
||||
use App\Models\Server;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
@@ -16,6 +18,10 @@ class ServerSeeder extends Seeder
|
||||
'ip' => 'coolify-testing-host',
|
||||
'team_id' => 0,
|
||||
'private_key_id' => 1,
|
||||
'proxy' => [
|
||||
'type' => ProxyTypes::TRAEFIK->value,
|
||||
'status' => ProxyStatus::EXITED->value,
|
||||
],
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user