From 5ba1ac9c924a281b4efc949cb3bd20c0c545924e Mon Sep 17 00:00:00 2001 From: "Harry (hjbdev)" Date: Sun, 30 Mar 2025 12:37:34 +0000 Subject: [PATCH] provision script fixes, flash the server creds to the user on server create --- app/Http/Controllers/ServerController.php | 4 ++++ app/Http/Middleware/HandleInertiaRequests.php | 5 +++++ provision.sh | 3 ++- resources/js/pages/servers/Show.vue | 7 +++++++ routes/web.php | 3 +++ 5 files changed, 21 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/ServerController.php b/app/Http/Controllers/ServerController.php index 04e157a..453c87c 100644 --- a/app/Http/Controllers/ServerController.php +++ b/app/Http/Controllers/ServerController.php @@ -94,6 +94,10 @@ class ServerController extends Controller sudoPassword: $sudoPassword, ))->delay(now()->addSeconds(30)); + session()->flash('server-credentials', [ + 'sudo_password' => $sudoPassword, + ]); + return redirect()->route('servers.show', ['organisation' => $organisation->id, 'server' => $server->id]); } diff --git a/app/Http/Middleware/HandleInertiaRequests.php b/app/Http/Middleware/HandleInertiaRequests.php index e99242c..99d17a2 100644 --- a/app/Http/Middleware/HandleInertiaRequests.php +++ b/app/Http/Middleware/HandleInertiaRequests.php @@ -31,6 +31,11 @@ class HandleInertiaRequests extends Middleware 'name' => config('app.name'), 'organisation' => $request->route('organisation') ? Organisation::with('applications')->findOrFail($request->route('organisation')) : null, 'application' => $request->route('application') ? Application::with('environments')->findOrFail($request->route('application')) : null, + 'flash' => [ + 'server_credentials' => $request->session()->has('sudo_password') ? [ + 'sudo_password' => $request->session()->get('sudo_password'), + ] : null, + ], 'auth' => [ 'user' => $request->user()?->load('organisations'), ], diff --git a/provision.sh b/provision.sh index 7f23bc2..3ede187 100644 --- a/provision.sh +++ b/provision.sh @@ -2,6 +2,7 @@ # [!hostname!] - server hostname # [!sudo_password!] - the sudo password to set # [!server_id!] - the servers id +# [!keystonepublickey!] - keystone's public key apt_wait() { while fuser /var/lib/dpkg/lock >/dev/null 2>&1; do @@ -74,7 +75,7 @@ usermod --password $PASSWORD keystone # Build Formatted Keys & Copy Keys To Keystone cat >/root/.ssh/authorized_keys <
{{ server }} + +
+
+ WILL NOT BE SHOWN AGAIN: + {{ $page.props.flash.server_credentials }} +
+
diff --git a/routes/web.php b/routes/web.php index f740c54..fd70820 100644 --- a/routes/web.php +++ b/routes/web.php @@ -46,9 +46,12 @@ Route::get('/provision-script', function (Request $request) { $script = file_get_contents(base_path('provision.sh')); + $keystonePublicKey = file_get_contents(storage_path('app/private/ssh/id_ed25519.pub')); + $script = str_replace('[!hostname!]', $validated['hostname'], $script); $script = str_replace('[!sudo_password!]', $validated['sudo_password'], $script); $script = str_replace('[!server_id!]', $validated['server_id'], $script); + $script = str_replace('[!keystonepublickey!]', $keystonePublicKey, $script); return response($script) ->header('Content-Type', 'text/plain');