diff --git a/app/Console/Commands/GenerateKeysCommand.php b/app/Console/Commands/GenerateKeysCommand.php new file mode 100644 index 0000000..a4d30ab --- /dev/null +++ b/app/Console/Commands/GenerateKeysCommand.php @@ -0,0 +1,33 @@ +option('force')) { + $this->error('Keys already exist. Use --force to overwrite.'); + return; + } + + exec('openssl genpkey -algorithm RSA -out ' . $privateKeyPath); + exec('chmod 600 ' . $privateKeyPath); + exec('ssh-keygen -y -f ' . $privateKeyPath . ' > ' . $publicKeyPath); + exec('chown -R ' . get_current_user() . ':' . get_current_user() . ' ' . $privateKeyPath); + exec('chown -R ' . get_current_user() . ':' . get_current_user() . ' ' . $publicKeyPath); + + $this->info('Keys generated successfully.'); + } +} diff --git a/app/Support/helpers.php b/app/Support/helpers.php index 7b1a05c..ab5a41b 100755 --- a/app/Support/helpers.php +++ b/app/Support/helpers.php @@ -5,6 +5,7 @@ use Filament\Notifications\Actions\Action; use Filament\Notifications\Notification; use Illuminate\Http\Request; +use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\Route; function generate_public_key($privateKeyPath, $publicKeyPath): void @@ -56,6 +57,10 @@ function convert_time_format($string): string function get_public_key_content(): string { + if (! file_exists(storage_path(config('core.ssh_public_key_name')))) { + Artisan::call('ssh-key:generate --force'); + } + return str(file_get_contents(storage_path(config('core.ssh_public_key_name')))) ->replace("\n", '') ->toString();