From 7d0a570d858da8aea394b69ddbe21dc17f5a7412 Mon Sep 17 00:00:00 2001 From: Marcel Pociot Date: Sun, 3 May 2020 21:38:33 +0200 Subject: [PATCH] wip --- app/Client/Client.php | 5 +- app/Client/Connections/ControlConnection.php | 4 +- app/Server/Connections/ControlConnection.php | 6 +- .../Admin/SaveSettingsController.php | 6 ++ .../Controllers/ControlMessageController.php | 7 +- resources/views/server/layouts/app.twig | 2 + resources/views/server/settings/index.twig | 66 +++++++++++++++++-- 7 files changed, 83 insertions(+), 13 deletions(-) diff --git a/app/Client/Client.php b/app/Client/Client.php index 178201e..f0c6616 100644 --- a/app/Client/Client.php +++ b/app/Client/Client.php @@ -65,13 +65,13 @@ class Client }); $connection->on('authenticationFailed', function ($data) use ($deferred) { - $this->logger->error($data->data->message); + $this->logger->error($data->message); $this->exit($deferred); }); $connection->on('subdomainTaken', function ($data) use ($deferred) { - $this->logger->error($data->data->message); + $this->logger->error($data->message); $this->exit($deferred); }); @@ -94,6 +94,7 @@ class Client $host .= ":{$this->configuration->port()}"; } + $this->logger->info($data->message); $this->logger->info("Connected to {$httpProtocol}://{$data->subdomain}.{$host}"); static::$subdomains[] = "$data->subdomain.{$this->configuration->host()}:{$this->configuration->port()}"; diff --git a/app/Client/Connections/ControlConnection.php b/app/Client/Connections/ControlConnection.php index 05c8f50..98f7eda 100644 --- a/app/Client/Connections/ControlConnection.php +++ b/app/Client/Connections/ControlConnection.php @@ -34,10 +34,10 @@ class ControlConnection $this->socket->on('message', function (Message $message) { $decodedEntry = json_decode($message); - $this->emit($decodedEntry->event ?? '', [$decodedEntry]); + $this->emit($decodedEntry->event ?? '', [$decodedEntry->data]); if (method_exists($this, $decodedEntry->event ?? '')) { - call_user_func([$this, $decodedEntry->event], $decodedEntry); + call_user_func([$this, $decodedEntry->event], $decodedEntry->data); } }); } diff --git a/app/Server/Connections/ControlConnection.php b/app/Server/Connections/ControlConnection.php index 310f8fe..c11db09 100644 --- a/app/Server/Connections/ControlConnection.php +++ b/app/Server/Connections/ControlConnection.php @@ -45,8 +45,10 @@ class ControlConnection { $this->socket->send(json_encode([ 'event' => 'createProxy', - 'request_id' => $requestId, - 'client_id' => $this->client_id, + 'data' => [ + 'request_id' => $requestId, + 'client_id' => $this->client_id, + ], ])); } } diff --git a/app/Server/Http/Controllers/Admin/SaveSettingsController.php b/app/Server/Http/Controllers/Admin/SaveSettingsController.php index 1335179..9073bb3 100644 --- a/app/Server/Http/Controllers/Admin/SaveSettingsController.php +++ b/app/Server/Http/Controllers/Admin/SaveSettingsController.php @@ -32,6 +32,12 @@ class SaveSettingsController extends AdminController { config()->set('expose.admin.validate_auth_tokens', $request->has('validate_auth_tokens')); + config()->set('expose.admin.messages.invalid_auth_token', $request->get('invalid_auth_token')); + + config()->set('expose.admin.messages.subdomain_taken', $request->get('subdomain_taken')); + + config()->set('expose.admin.messages.message_of_the_day', $request->get('motd')); + $httpConnection->send(str(new Response(301, [ 'Location' => '/settings' ]))); diff --git a/app/Server/Http/Controllers/ControlMessageController.php b/app/Server/Http/Controllers/ControlMessageController.php index 97eed7e..14c64a8 100644 --- a/app/Server/Http/Controllers/ControlMessageController.php +++ b/app/Server/Http/Controllers/ControlMessageController.php @@ -89,8 +89,11 @@ class ControlMessageController implements MessageComponentInterface $connection->send(json_encode([ 'event' => 'authenticated', - 'subdomain' => $connectionInfo->subdomain, - 'client_id' => $connectionInfo->client_id + 'data' => [ + 'message' => config('expose.admin.messages.message_of_the_day'), + 'subdomain' => $connectionInfo->subdomain, + 'client_id' => $connectionInfo->client_id + ], ])); }, function () use ($connection) { $connection->send(json_encode([ diff --git a/resources/views/server/layouts/app.twig b/resources/views/server/layouts/app.twig index 9dfdef8..c615da0 100644 --- a/resources/views/server/layouts/app.twig +++ b/resources/views/server/layouts/app.twig @@ -1,5 +1,7 @@ + Expose + diff --git a/resources/views/server/settings/index.twig b/resources/views/server/settings/index.twig index e75c942..b81ab61 100644 --- a/resources/views/server/settings/index.twig +++ b/resources/views/server/settings/index.twig @@ -11,7 +11,9 @@
-
+
Authentication
@@ -23,17 +25,71 @@ type="checkbox" name="validate_auth_tokens" value="1" - {% if configuration.validate_auth_tokens %} checked="checked" {% endif %} - class="form-checkbox h-4 w-4 text-indigo-600 transition duration-150 ease-in-out" /> + {% if configuration.validate_auth_tokens %} checked="checked" {% endif %} + class="form-checkbox h-4 w-4 text-indigo-600 transition duration-150 ease-in-out"/>
- -

Only allow connection from clients with valid authentication tokens

+ +

Only allow connection from clients with + valid authentication tokens

+ +
+ +
+
+ +
+

This message will be shown, when a + successful connection can be established.

+
+
+ +
+ +
+
+ +
+

This message will be shown, when a + user tries to connect with an invalid authentication token.

+
+
+ +
+ +
+
+ +
+

This message will be shown, when a + user tries to connect with an already registered subdomain. You can use + :subdomain as + a placeholder.

+
+