mirror of
https://github.com/bitinflow/expose.git
synced 2026-03-17 07:25:54 +00:00
Move port range to config. Throw exception if no free port is available within the range
This commit is contained in:
@@ -5,6 +5,7 @@ namespace App\Server\Connections;
|
|||||||
use App\Contracts\ConnectionManager as ConnectionManagerContract;
|
use App\Contracts\ConnectionManager as ConnectionManagerContract;
|
||||||
use App\Contracts\SubdomainGenerator;
|
use App\Contracts\SubdomainGenerator;
|
||||||
use App\Http\QueryParameters;
|
use App\Http\QueryParameters;
|
||||||
|
use App\Server\Exceptions\NoFreePortAvailable;
|
||||||
use Ratchet\ConnectionInterface;
|
use Ratchet\ConnectionInterface;
|
||||||
use React\EventLoop\LoopInterface;
|
use React\EventLoop\LoopInterface;
|
||||||
use React\Socket\Server;
|
use React\Socket\Server;
|
||||||
@@ -82,8 +83,10 @@ class ConnectionManager implements ConnectionManagerContract
|
|||||||
|
|
||||||
protected function getSharedTcpServer(): Server
|
protected function getSharedTcpServer(): Server
|
||||||
{
|
{
|
||||||
$portRange = [50000, 62000];
|
$portRange = config('expose.admin.tcp_port_range');
|
||||||
$port = $portRange[0];
|
|
||||||
|
$port = $portRange['from'] ?? 50000;
|
||||||
|
$maxPort = $portRange['to'] ?? 60000;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
try {
|
try {
|
||||||
@@ -92,6 +95,10 @@ class ConnectionManager implements ConnectionManagerContract
|
|||||||
} catch (\RuntimeException $exception) {
|
} catch (\RuntimeException $exception) {
|
||||||
$portFound = false;
|
$portFound = false;
|
||||||
$port++;
|
$port++;
|
||||||
|
|
||||||
|
if ($port > $maxPort) {
|
||||||
|
throw new NoFreePortAvailable();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} while (! $portFound);
|
} while (! $portFound);
|
||||||
|
|
||||||
|
|||||||
8
app/Server/Exceptions/NoFreePortAvailable.php
Normal file
8
app/Server/Exceptions/NoFreePortAvailable.php
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Server\Exceptions;
|
||||||
|
|
||||||
|
class NoFreePortAvailable extends \Exception
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
@@ -5,6 +5,7 @@ namespace App\Server\Http\Controllers;
|
|||||||
use App\Contracts\ConnectionManager;
|
use App\Contracts\ConnectionManager;
|
||||||
use App\Contracts\UserRepository;
|
use App\Contracts\UserRepository;
|
||||||
use App\Http\QueryParameters;
|
use App\Http\QueryParameters;
|
||||||
|
use App\Server\Exceptions\NoFreePortAvailable;
|
||||||
use Ratchet\ConnectionInterface;
|
use Ratchet\ConnectionInterface;
|
||||||
use Ratchet\WebSocket\MessageComponentInterface;
|
use Ratchet\WebSocket\MessageComponentInterface;
|
||||||
use React\Promise\Deferred;
|
use React\Promise\Deferred;
|
||||||
@@ -119,7 +120,18 @@ class ControlMessageController implements MessageComponentInterface
|
|||||||
|
|
||||||
protected function handleTcpConnection(ConnectionInterface $connection, $data, $user = null)
|
protected function handleTcpConnection(ConnectionInterface $connection, $data, $user = null)
|
||||||
{
|
{
|
||||||
$connectionInfo = $this->connectionManager->storeTcpConnection($data->port, $connection);
|
try {
|
||||||
|
$connectionInfo = $this->connectionManager->storeTcpConnection($data->port, $connection);
|
||||||
|
} catch (NoFreePortAvailable $exception) {
|
||||||
|
$connection->send(json_encode([
|
||||||
|
'event' => 'authenticationFailed',
|
||||||
|
'data' => [
|
||||||
|
'message' => config('expose.admin.messages.no_free_tcp_port_available'),
|
||||||
|
],
|
||||||
|
]));
|
||||||
|
$connection->close();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$connection->send(json_encode([
|
$connection->send(json_encode([
|
||||||
'event' => 'authenticated',
|
'event' => 'authenticated',
|
||||||
|
|||||||
@@ -151,6 +151,24 @@ return [
|
|||||||
*/
|
*/
|
||||||
'validate_auth_tokens' => false,
|
'validate_auth_tokens' => false,
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| TCP Port Range
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Expose allows you to also share TCP ports, for example when sharing your
|
||||||
|
| local SSH server with the public. This setting allows you to define the
|
||||||
|
| port range that Expose will use to assign new ports to the users.
|
||||||
|
|
|
||||||
|
| Note: Do not use port ranges below 1024, as it might require root
|
||||||
|
| privileges to assign these ports.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
'tcp_port_range' => [
|
||||||
|
'from' => 50000,
|
||||||
|
'to' => 50003
|
||||||
|
],
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
| Maximum connection length
|
| Maximum connection length
|
||||||
@@ -232,6 +250,8 @@ return [
|
|||||||
'subdomain_taken' => 'The chosen subdomain :subdomain is already taken. Please choose a different subdomain.',
|
'subdomain_taken' => 'The chosen subdomain :subdomain is already taken. Please choose a different subdomain.',
|
||||||
|
|
||||||
'custom_subdomain_unauthorized' => 'You are not allowed to specify custom subdomains. Please upgrade to Expose Pro.',
|
'custom_subdomain_unauthorized' => 'You are not allowed to specify custom subdomains. Please upgrade to Expose Pro.',
|
||||||
|
|
||||||
|
'no_free_tcp_port_available' => 'There are no free TCP ports available on this server. Please try again later.'
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|||||||
Reference in New Issue
Block a user