diff --git a/app/Client/Client.php b/app/Client/Client.php index 88b81c2..31fa3cf 100644 --- a/app/Client/Client.php +++ b/app/Client/Client.php @@ -93,17 +93,19 @@ public function connectToServer(string $sharedUrl, $subdomain, $serverHost = nul $exposeVersion = config('app.version'); + $serverPort = $this->configuration->port(); + $wsProtocol = $this->configuration->port() === 443 ? 'wss' : 'ws'; connect($wsProtocol."://{$this->configuration->host()}:{$this->configuration->port()}/expose/control?authToken={$authToken}&version={$exposeVersion}", [], [ 'X-Expose-Control' => 'enabled', ], $this->loop) - ->then(function (WebSocket $clientConnection) use ($sharedUrl, $subdomain, $serverHost, $deferred, $authToken) { + ->then(function (WebSocket $clientConnection) use ($sharedUrl, $subdomain, $serverHost, $serverPort, $deferred, $authToken) { $this->connectionRetries = 0; $connection = ControlConnection::create($clientConnection); - $connection->authenticate($sharedUrl, $subdomain, $serverHost); + $connection->authenticate($sharedUrl, $subdomain, $serverHost, $serverPort); $clientConnection->on('close', function () use ($sharedUrl, $subdomain, $serverHost, $authToken) { $this->logger->error('Connection to server closed.'); diff --git a/app/Client/Connections/ControlConnection.php b/app/Client/Connections/ControlConnection.php index 2d4540e..33386bd 100644 --- a/app/Client/Connections/ControlConnection.php +++ b/app/Client/Connections/ControlConnection.php @@ -57,7 +57,7 @@ public function createTcpProxy($data) $this->proxyManager->createTcpProxy($this->clientId, $data); } - public function authenticate(string $sharedHost, string $subdomain, $serverHost = null) + public function authenticate(string $sharedHost, string $subdomain, $serverHost = null, $serverPort = null) { $this->socket->send(json_encode([ 'event' => 'authenticate', @@ -65,6 +65,7 @@ public function authenticate(string $sharedHost, string $subdomain, $serverHost 'type' => 'http', 'host' => $sharedHost, 'server_host' => $serverHost, + 'server_port' => $serverPort, 'subdomain' => empty($subdomain) ? null : $subdomain, ], ])); diff --git a/app/Contracts/ConnectionManager.php b/app/Contracts/ConnectionManager.php index 2898ded..7c9a5dc 100644 --- a/app/Contracts/ConnectionManager.php +++ b/app/Contracts/ConnectionManager.php @@ -8,7 +8,7 @@ interface ConnectionManager { - public function storeConnection(string $host, ?string $subdomain, ?string $serverHost, ConnectionInterface $connection): ControlConnection; + public function storeConnection(string $host, ?string $subdomain, ?string $serverHost, ?string $serverPort, ConnectionInterface $connection): ControlConnection; public function storeTcpConnection(int $port, ConnectionInterface $connection): ControlConnection; diff --git a/app/Server/Connections/ConnectionManager.php b/app/Server/Connections/ConnectionManager.php index 6ef7dc6..cecc7be 100644 --- a/app/Server/Connections/ConnectionManager.php +++ b/app/Server/Connections/ConnectionManager.php @@ -53,7 +53,7 @@ public function limitConnectionLength(ControlConnection $connection, int $maximu }); } - public function storeConnection(string $host, ?string $subdomain, ?string $serverHost, ConnectionInterface $connection): ControlConnection + public function storeConnection(string $host, ?string $subdomain, ?string $serverHost, ?string $serverPort, ConnectionInterface $connection): ControlConnection { $clientId = (string) uniqid(); @@ -65,6 +65,7 @@ public function storeConnection(string $host, ?string $subdomain, ?string $serve $subdomain ?? $this->subdomainGenerator->generateSubdomain(), $clientId, $serverHost, + $serverPort, $this->getAuthTokenFromConnection($connection) ); diff --git a/app/Server/Connections/ControlConnection.php b/app/Server/Connections/ControlConnection.php index 6d00675..b513a22 100644 --- a/app/Server/Connections/ControlConnection.php +++ b/app/Server/Connections/ControlConnection.php @@ -14,6 +14,7 @@ class ControlConnection public $socket; public $host; public $serverHost; + public $serverPort; public $authToken; public $subdomain; public $client_id; @@ -22,7 +23,7 @@ class ControlConnection public $proxies = []; protected $shared_at; - public function __construct(ConnectionInterface $socket, string $host, string $subdomain, string $clientId, string $serverHost, string $authToken = '') + public function __construct(ConnectionInterface $socket, string $host, string $subdomain, string $clientId, string $serverHost, string $serverPort = '', string $authToken = '') { $this->socket = $socket; $this->host = $host; @@ -30,6 +31,7 @@ public function __construct(ConnectionInterface $socket, string $host, string $s $this->client_id = $clientId; $this->authToken = $authToken; $this->serverHost = $serverHost; + $this->serverPort = $serverPort; $this->shared_at = now()->toDateTimeString(); $this->client_version = QueryParameters::create($socket->httpRequest)->get('version'); } @@ -69,6 +71,7 @@ public function toArray() 'host' => $this->host, 'remote_address' => $this->socket->remoteAddress ?? null, 'server_host' => $this->serverHost, + 'server_port' => $this->serverPort, 'client_id' => $this->client_id, 'client_version' => $this->client_version, 'auth_token' => $this->authToken, diff --git a/app/Server/Http/Controllers/ControlMessageController.php b/app/Server/Http/Controllers/ControlMessageController.php index 0c17a95..bfe9598 100644 --- a/app/Server/Http/Controllers/ControlMessageController.php +++ b/app/Server/Http/Controllers/ControlMessageController.php @@ -183,7 +183,7 @@ protected function handleHttpConnection(ConnectionInterface $connection, $data, $data->subdomain = $subdomain; - $connectionInfo = $this->connectionManager->storeConnection($data->host, $data->subdomain, $data->server_host, $connection); + $connectionInfo = $this->connectionManager->storeConnection($data->host, $data->subdomain, $data->server_host, $data->server_port, $connection); $this->connectionManager->limitConnectionLength($connectionInfo, config('expose.admin.maximum_connection_length')); diff --git a/resources/views/server/sites/index.twig b/resources/views/server/sites/index.twig index afdaf33..96fc7e2 100644 --- a/resources/views/server/sites/index.twig +++ b/resources/views/server/sites/index.twig @@ -29,7 +29,7 @@ @{ site.host }