mirror of
https://github.com/bitinflow/expose.git
synced 2026-03-13 13:35:54 +00:00
Add ability to expose TCP connections (#123)
This commit is contained in:
@@ -49,6 +49,11 @@ class Client
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function sharePort(int $port)
|
||||||
|
{
|
||||||
|
$this->connectToServerAndShareTcp($port, config('expose.auth_token'));
|
||||||
|
}
|
||||||
|
|
||||||
protected function prepareSharedUrl(string $sharedUrl): string
|
protected function prepareSharedUrl(string $sharedUrl): string
|
||||||
{
|
{
|
||||||
if (! $parsedUrl = parse_url($sharedUrl)) {
|
if (! $parsedUrl = parse_url($sharedUrl)) {
|
||||||
@@ -87,14 +92,12 @@ class Client
|
|||||||
$clientConnection->on('close', function () use ($sharedUrl, $subdomain, $authToken) {
|
$clientConnection->on('close', function () use ($sharedUrl, $subdomain, $authToken) {
|
||||||
$this->logger->error('Connection to server closed.');
|
$this->logger->error('Connection to server closed.');
|
||||||
|
|
||||||
$this->retryConnectionOrExit($sharedUrl, $subdomain, $authToken);
|
$this->retryConnectionOrExit(function () use ($sharedUrl, $subdomain, $authToken) {
|
||||||
|
$this->connectToServer($sharedUrl, $subdomain, $authToken);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
$connection->on('authenticationFailed', function ($data) use ($deferred) {
|
$this->attachCommonConnectionListeners($connection, $deferred);
|
||||||
$this->logger->error($data->message);
|
|
||||||
|
|
||||||
$this->exit($deferred);
|
|
||||||
});
|
|
||||||
|
|
||||||
$connection->on('subdomainTaken', function ($data) use ($deferred) {
|
$connection->on('subdomainTaken', function ($data) use ($deferred) {
|
||||||
$this->logger->error($data->message);
|
$this->logger->error($data->message);
|
||||||
@@ -102,20 +105,6 @@ class Client
|
|||||||
$this->exit($deferred);
|
$this->exit($deferred);
|
||||||
});
|
});
|
||||||
|
|
||||||
$connection->on('setMaximumConnectionLength', function ($data) {
|
|
||||||
$timeoutSection = $this->logger->getOutput()->section();
|
|
||||||
|
|
||||||
$this->loop->addPeriodicTimer(1, function () use ($data, $timeoutSection) {
|
|
||||||
$this->timeConnected++;
|
|
||||||
|
|
||||||
$secondsRemaining = $data->length * 60 - $this->timeConnected;
|
|
||||||
$remaining = Carbon::now()->diff(Carbon::now()->addSeconds($secondsRemaining));
|
|
||||||
|
|
||||||
$timeoutSection->clear();
|
|
||||||
$timeoutSection->writeln('Remaining time: '.$remaining->format('%H:%I:%S'));
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
$connection->on('authenticated', function ($data) use ($deferred, $sharedUrl) {
|
$connection->on('authenticated', function ($data) use ($deferred, $sharedUrl) {
|
||||||
$httpProtocol = $this->configuration->port() === 443 ? 'https' : 'http';
|
$httpProtocol = $this->configuration->port() === 443 ? 'https' : 'http';
|
||||||
$host = $this->configuration->host();
|
$host = $this->configuration->host();
|
||||||
@@ -136,7 +125,9 @@ class Client
|
|||||||
});
|
});
|
||||||
}, function (\Exception $e) use ($deferred, $sharedUrl, $subdomain, $authToken) {
|
}, function (\Exception $e) use ($deferred, $sharedUrl, $subdomain, $authToken) {
|
||||||
if ($this->connectionRetries > 0) {
|
if ($this->connectionRetries > 0) {
|
||||||
$this->retryConnectionOrExit($sharedUrl, $subdomain, $authToken);
|
$this->retryConnectionOrExit(function () use ($sharedUrl, $subdomain, $authToken) {
|
||||||
|
$this->connectToServer($sharedUrl, $subdomain, $authToken);
|
||||||
|
});
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -149,6 +140,84 @@ class Client
|
|||||||
return $promise;
|
return $promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function connectToServerAndShareTcp(int $port, $authToken = ''): PromiseInterface
|
||||||
|
{
|
||||||
|
$deferred = new Deferred();
|
||||||
|
$promise = $deferred->promise();
|
||||||
|
|
||||||
|
$wsProtocol = $this->configuration->port() === 443 ? 'wss' : 'ws';
|
||||||
|
|
||||||
|
connect($wsProtocol."://{$this->configuration->host()}:{$this->configuration->port()}/expose/control?authToken={$authToken}", [], [
|
||||||
|
'X-Expose-Control' => 'enabled',
|
||||||
|
], $this->loop)
|
||||||
|
->then(function (WebSocket $clientConnection) use ($port, $deferred, $authToken) {
|
||||||
|
$this->connectionRetries = 0;
|
||||||
|
|
||||||
|
$connection = ControlConnection::create($clientConnection);
|
||||||
|
|
||||||
|
$connection->authenticateTcp($port);
|
||||||
|
|
||||||
|
$this->attachCommonConnectionListeners($connection, $deferred);
|
||||||
|
|
||||||
|
$clientConnection->on('close', function () use ($port, $authToken) {
|
||||||
|
$this->logger->error('Connection to server closed.');
|
||||||
|
|
||||||
|
$this->retryConnectionOrExit(function () use ($port, $authToken) {
|
||||||
|
$this->connectToServerAndShareTcp($port, $authToken);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
$connection->on('authenticated', function ($data) use ($deferred, $port) {
|
||||||
|
$host = $this->configuration->host();
|
||||||
|
|
||||||
|
$this->logger->info($data->message);
|
||||||
|
$this->logger->info("Local-Port:\t\t{$port}");
|
||||||
|
$this->logger->info("Shared-Port:\t\t{$data->shared_port}");
|
||||||
|
$this->logger->info("Expose-URL:\t\ttcp://{$host}:{$data->shared_port}.");
|
||||||
|
$this->logger->line('');
|
||||||
|
|
||||||
|
$deferred->resolve($data);
|
||||||
|
});
|
||||||
|
}, function (\Exception $e) use ($deferred, $port, $authToken) {
|
||||||
|
if ($this->connectionRetries > 0) {
|
||||||
|
$this->retryConnectionOrExit(function () use ($port, $authToken) {
|
||||||
|
$this->connectToServerAndShareTcp($port, $authToken);
|
||||||
|
});
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$this->logger->error('Could not connect to the server.');
|
||||||
|
$this->logger->error($e->getMessage());
|
||||||
|
|
||||||
|
$this->exit($deferred);
|
||||||
|
});
|
||||||
|
|
||||||
|
return $promise;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function attachCommonConnectionListeners(ControlConnection $connection, Deferred $deferred)
|
||||||
|
{
|
||||||
|
$connection->on('authenticationFailed', function ($data) use ($deferred) {
|
||||||
|
$this->logger->error($data->message);
|
||||||
|
|
||||||
|
$this->exit($deferred);
|
||||||
|
});
|
||||||
|
|
||||||
|
$connection->on('setMaximumConnectionLength', function ($data) {
|
||||||
|
$timeoutSection = $this->logger->getOutput()->section();
|
||||||
|
|
||||||
|
$this->loop->addPeriodicTimer(1, function () use ($data, $timeoutSection) {
|
||||||
|
$this->timeConnected++;
|
||||||
|
|
||||||
|
$secondsRemaining = $data->length * 60 - $this->timeConnected;
|
||||||
|
$remaining = Carbon::now()->diff(Carbon::now()->addSeconds($secondsRemaining));
|
||||||
|
|
||||||
|
$timeoutSection->clear();
|
||||||
|
$timeoutSection->writeln('Remaining time: '.$remaining->format('%H:%I:%S'));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
protected function exit(Deferred $deferred)
|
protected function exit(Deferred $deferred)
|
||||||
{
|
{
|
||||||
$deferred->reject();
|
$deferred->reject();
|
||||||
@@ -158,15 +227,15 @@ class Client
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function retryConnectionOrExit(string $sharedUrl, $subdomain, $authToken = '')
|
protected function retryConnectionOrExit(callable $retry)
|
||||||
{
|
{
|
||||||
$this->connectionRetries++;
|
$this->connectionRetries++;
|
||||||
|
|
||||||
if ($this->connectionRetries <= static::MAX_CONNECTION_RETRIES) {
|
if ($this->connectionRetries <= static::MAX_CONNECTION_RETRIES) {
|
||||||
$this->loop->addTimer($this->connectionRetries, function () use ($sharedUrl, $subdomain, $authToken) {
|
$this->loop->addTimer($this->connectionRetries, function () use ($retry) {
|
||||||
$this->logger->info("Retrying connection ({$this->connectionRetries}/".static::MAX_CONNECTION_RETRIES.')');
|
$this->logger->info("Retrying connection ({$this->connectionRetries}/".static::MAX_CONNECTION_RETRIES.')');
|
||||||
|
|
||||||
$this->connectToServer($sharedUrl, $subdomain, $authToken);
|
$retry();
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
exit(1);
|
exit(1);
|
||||||
|
|||||||
@@ -52,17 +52,34 @@ class ControlConnection
|
|||||||
$this->proxyManager->createProxy($this->clientId, $data);
|
$this->proxyManager->createProxy($this->clientId, $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function createTcpProxy($data)
|
||||||
|
{
|
||||||
|
$this->proxyManager->createTcpProxy($this->clientId, $data);
|
||||||
|
}
|
||||||
|
|
||||||
public function authenticate(string $sharedHost, string $subdomain)
|
public function authenticate(string $sharedHost, string $subdomain)
|
||||||
{
|
{
|
||||||
$this->socket->send(json_encode([
|
$this->socket->send(json_encode([
|
||||||
'event' => 'authenticate',
|
'event' => 'authenticate',
|
||||||
'data' => [
|
'data' => [
|
||||||
|
'type' => 'http',
|
||||||
'host' => $sharedHost,
|
'host' => $sharedHost,
|
||||||
'subdomain' => empty($subdomain) ? null : $subdomain,
|
'subdomain' => empty($subdomain) ? null : $subdomain,
|
||||||
],
|
],
|
||||||
]));
|
]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function authenticateTcp(int $port)
|
||||||
|
{
|
||||||
|
$this->socket->send(json_encode([
|
||||||
|
'event' => 'authenticate',
|
||||||
|
'data' => [
|
||||||
|
'type' => 'tcp',
|
||||||
|
'port' => $port,
|
||||||
|
],
|
||||||
|
]));
|
||||||
|
}
|
||||||
|
|
||||||
public function ping()
|
public function ping()
|
||||||
{
|
{
|
||||||
$this->socket->send(json_encode([
|
$this->socket->send(json_encode([
|
||||||
|
|||||||
@@ -109,6 +109,13 @@ class Factory
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function sharePort(int $port)
|
||||||
|
{
|
||||||
|
app('expose.client')->sharePort($port);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
protected function addRoutes()
|
protected function addRoutes()
|
||||||
{
|
{
|
||||||
$this->router->get('/', DashboardController::class);
|
$this->router->get('/', DashboardController::class);
|
||||||
|
|||||||
@@ -5,7 +5,9 @@ namespace App\Client;
|
|||||||
use App\Client\Http\HttpClient;
|
use App\Client\Http\HttpClient;
|
||||||
use function Ratchet\Client\connect;
|
use function Ratchet\Client\connect;
|
||||||
use Ratchet\Client\WebSocket;
|
use Ratchet\Client\WebSocket;
|
||||||
|
use Ratchet\RFC6455\Messaging\Frame;
|
||||||
use React\EventLoop\LoopInterface;
|
use React\EventLoop\LoopInterface;
|
||||||
|
use React\Socket\Connector;
|
||||||
|
|
||||||
class ProxyManager
|
class ProxyManager
|
||||||
{
|
{
|
||||||
@@ -43,6 +45,37 @@ class ProxyManager
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function createTcpProxy(string $clientId, $connectionData)
|
||||||
|
{
|
||||||
|
$protocol = $this->configuration->port() === 443 ? 'wss' : 'ws';
|
||||||
|
|
||||||
|
connect($protocol."://{$this->configuration->host()}:{$this->configuration->port()}/expose/control", [], [
|
||||||
|
'X-Expose-Control' => 'enabled',
|
||||||
|
], $this->loop)
|
||||||
|
->then(function (WebSocket $proxyConnection) use ($clientId, $connectionData) {
|
||||||
|
$connector = new Connector($this->loop);
|
||||||
|
|
||||||
|
$connector->connect('127.0.0.1:'.$connectionData->port)->then(function ($connection) use ($proxyConnection) {
|
||||||
|
$connection->on('data', function ($data) use ($proxyConnection) {
|
||||||
|
$binaryMsg = new Frame($data, true, Frame::OP_BINARY);
|
||||||
|
$proxyConnection->send($binaryMsg);
|
||||||
|
});
|
||||||
|
|
||||||
|
$proxyConnection->on('message', function ($message) use ($connection) {
|
||||||
|
$connection->write($message);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
$proxyConnection->send(json_encode([
|
||||||
|
'event' => 'registerTcpProxy',
|
||||||
|
'data' => [
|
||||||
|
'tcp_request_id' => $connectionData->tcp_request_id ?? null,
|
||||||
|
'client_id' => $clientId,
|
||||||
|
],
|
||||||
|
]));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
protected function performRequest(WebSocket $proxyConnection, $requestId, string $requestData)
|
protected function performRequest(WebSocket $proxyConnection, $requestId, string $requestData)
|
||||||
{
|
{
|
||||||
app(HttpClient::class)->performRequest((string) $requestData, $proxyConnection, $requestId);
|
app(HttpClient::class)->performRequest((string) $requestData, $proxyConnection, $requestId);
|
||||||
|
|||||||
40
app/Commands/SharePortCommand.php
Normal file
40
app/Commands/SharePortCommand.php
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Commands;
|
||||||
|
|
||||||
|
use App\Client\Factory;
|
||||||
|
use App\Logger\CliRequestLogger;
|
||||||
|
use LaravelZero\Framework\Commands\Command;
|
||||||
|
use React\EventLoop\LoopInterface;
|
||||||
|
use Symfony\Component\Console\Output\ConsoleOutput;
|
||||||
|
|
||||||
|
class SharePortCommand extends Command
|
||||||
|
{
|
||||||
|
protected $signature = 'share-port {port} {--auth=}';
|
||||||
|
|
||||||
|
protected $description = 'Share a local port with a remote expose server';
|
||||||
|
|
||||||
|
protected function configureConnectionLogger()
|
||||||
|
{
|
||||||
|
app()->bind(CliRequestLogger::class, function () {
|
||||||
|
return new CliRequestLogger(new ConsoleOutput());
|
||||||
|
});
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function handle()
|
||||||
|
{
|
||||||
|
$this->configureConnectionLogger();
|
||||||
|
|
||||||
|
(new Factory())
|
||||||
|
->setLoop(app(LoopInterface::class))
|
||||||
|
->setHost(config('expose.host', 'localhost'))
|
||||||
|
->setPort(config('expose.port', 8080))
|
||||||
|
->setAuth($this->option('auth'))
|
||||||
|
->createClient()
|
||||||
|
->sharePort($this->argument('port'))
|
||||||
|
->createHttpServer()
|
||||||
|
->run();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,6 +10,8 @@ interface ConnectionManager
|
|||||||
{
|
{
|
||||||
public function storeConnection(string $host, ?string $subdomain, ConnectionInterface $connection): ControlConnection;
|
public function storeConnection(string $host, ?string $subdomain, ConnectionInterface $connection): ControlConnection;
|
||||||
|
|
||||||
|
public function storeTcpConnection(int $port, ConnectionInterface $connection): ControlConnection;
|
||||||
|
|
||||||
public function limitConnectionLength(ControlConnection $connection, int $maximumConnectionLength);
|
public function limitConnectionLength(ControlConnection $connection, int $maximumConnectionLength);
|
||||||
|
|
||||||
public function storeHttpConnection(ConnectionInterface $httpConnection, $requestId): HttpConnection;
|
public function storeHttpConnection(ConnectionInterface $httpConnection, $requestId): HttpConnection;
|
||||||
@@ -25,4 +27,6 @@ interface ConnectionManager
|
|||||||
public function getConnections(): array;
|
public function getConnections(): array;
|
||||||
|
|
||||||
public function getConnectionsForAuthToken(string $authToken): array;
|
public function getConnectionsForAuthToken(string $authToken): array;
|
||||||
|
|
||||||
|
public function getTcpConnectionsForAuthToken(string $authToken): array;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,8 +5,10 @@ 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;
|
||||||
|
|
||||||
class ConnectionManager implements ConnectionManagerContract
|
class ConnectionManager implements ConnectionManagerContract
|
||||||
{
|
{
|
||||||
@@ -60,6 +62,49 @@ class ConnectionManager implements ConnectionManagerContract
|
|||||||
return $storedConnection;
|
return $storedConnection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function storeTcpConnection(int $port, ConnectionInterface $connection): ControlConnection
|
||||||
|
{
|
||||||
|
$clientId = (string) uniqid();
|
||||||
|
|
||||||
|
$connection->client_id = $clientId;
|
||||||
|
|
||||||
|
$storedConnection = new TcpControlConnection(
|
||||||
|
$connection,
|
||||||
|
$port,
|
||||||
|
$this->getSharedTcpServer(),
|
||||||
|
$clientId,
|
||||||
|
$this->getAuthTokenFromConnection($connection)
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->connections[] = $storedConnection;
|
||||||
|
|
||||||
|
return $storedConnection;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getSharedTcpServer(): Server
|
||||||
|
{
|
||||||
|
$portRange = config('expose.admin.tcp_port_range');
|
||||||
|
|
||||||
|
$port = $portRange['from'] ?? 50000;
|
||||||
|
$maxPort = $portRange['to'] ?? 60000;
|
||||||
|
|
||||||
|
do {
|
||||||
|
try {
|
||||||
|
$portFound = true;
|
||||||
|
$server = new Server('0.0.0.0:'.$port, $this->loop);
|
||||||
|
} catch (\RuntimeException $exception) {
|
||||||
|
$portFound = false;
|
||||||
|
$port++;
|
||||||
|
|
||||||
|
if ($port > $maxPort) {
|
||||||
|
throw new NoFreePortAvailable();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} while (! $portFound);
|
||||||
|
|
||||||
|
return $server;
|
||||||
|
}
|
||||||
|
|
||||||
public function storeHttpConnection(ConnectionInterface $httpConnection, $requestId): HttpConnection
|
public function storeHttpConnection(ConnectionInterface $httpConnection, $requestId): HttpConnection
|
||||||
{
|
{
|
||||||
$this->httpConnections[$requestId] = new HttpConnection($httpConnection);
|
$this->httpConnections[$requestId] = new HttpConnection($httpConnection);
|
||||||
@@ -82,6 +127,16 @@ class ConnectionManager implements ConnectionManagerContract
|
|||||||
|
|
||||||
if (isset($connection->client_id)) {
|
if (isset($connection->client_id)) {
|
||||||
$clientId = $connection->client_id;
|
$clientId = $connection->client_id;
|
||||||
|
|
||||||
|
$controlConnection = collect($this->connections)->first(function ($connection) use ($clientId) {
|
||||||
|
return $connection->client_id == $clientId;
|
||||||
|
});
|
||||||
|
|
||||||
|
if ($controlConnection instanceof TcpControlConnection) {
|
||||||
|
$controlConnection->stop();
|
||||||
|
$controlConnection = null;
|
||||||
|
}
|
||||||
|
|
||||||
$this->connections = collect($this->connections)->reject(function ($connection) use ($clientId) {
|
$this->connections = collect($this->connections)->reject(function ($connection) use ($clientId) {
|
||||||
return $connection->client_id == $clientId;
|
return $connection->client_id == $clientId;
|
||||||
})->toArray();
|
})->toArray();
|
||||||
@@ -118,9 +173,29 @@ class ConnectionManager implements ConnectionManagerContract
|
|||||||
->filter(function ($connection) use ($authToken) {
|
->filter(function ($connection) use ($authToken) {
|
||||||
return $connection->authToken === $authToken;
|
return $connection->authToken === $authToken;
|
||||||
})
|
})
|
||||||
|
->filter(function ($connection) {
|
||||||
|
return get_class($connection) === ControlConnection::class;
|
||||||
|
})
|
||||||
->map(function ($connection) {
|
->map(function ($connection) {
|
||||||
return $connection->toArray();
|
return $connection->toArray();
|
||||||
})
|
})
|
||||||
|
->values()
|
||||||
|
->toArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTcpConnectionsForAuthToken(string $authToken): array
|
||||||
|
{
|
||||||
|
return collect($this->connections)
|
||||||
|
->filter(function ($connection) use ($authToken) {
|
||||||
|
return $connection->authToken === $authToken;
|
||||||
|
})
|
||||||
|
->filter(function ($connection) {
|
||||||
|
return get_class($connection) === TcpControlConnection::class;
|
||||||
|
})
|
||||||
|
->map(function ($connection) {
|
||||||
|
return $connection->toArray();
|
||||||
|
})
|
||||||
|
->values()
|
||||||
->toArray();
|
->toArray();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,6 +57,7 @@ class ControlConnection
|
|||||||
public function toArray()
|
public function toArray()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
'type' => 'http',
|
||||||
'host' => $this->host,
|
'host' => $this->host,
|
||||||
'client_id' => $this->client_id,
|
'client_id' => $this->client_id,
|
||||||
'auth_token' => $this->authToken,
|
'auth_token' => $this->authToken,
|
||||||
|
|||||||
107
app/Server/Connections/TcpControlConnection.php
Normal file
107
app/Server/Connections/TcpControlConnection.php
Normal file
@@ -0,0 +1,107 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Server\Connections;
|
||||||
|
|
||||||
|
use Ratchet\ConnectionInterface;
|
||||||
|
use Ratchet\RFC6455\Messaging\Frame;
|
||||||
|
use React\Socket\Server;
|
||||||
|
|
||||||
|
class TcpControlConnection extends ControlConnection
|
||||||
|
{
|
||||||
|
public $proxy;
|
||||||
|
public $proxyConnection;
|
||||||
|
public $port;
|
||||||
|
public $shared_port;
|
||||||
|
public $shared_server;
|
||||||
|
|
||||||
|
public function __construct(ConnectionInterface $socket, int $port, Server $sharedServer, string $clientId, string $authToken = '')
|
||||||
|
{
|
||||||
|
$this->socket = $socket;
|
||||||
|
$this->client_id = $clientId;
|
||||||
|
$this->shared_server = $sharedServer;
|
||||||
|
$this->port = $port;
|
||||||
|
$this->shared_at = now()->toDateTimeString();
|
||||||
|
$this->shared_port = parse_url($sharedServer->getAddress(), PHP_URL_PORT);
|
||||||
|
$this->authToken = $authToken;
|
||||||
|
|
||||||
|
$this->configureServer($sharedServer);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setMaximumConnectionLength(int $maximumConnectionLength)
|
||||||
|
{
|
||||||
|
$this->socket->send(json_encode([
|
||||||
|
'event' => 'setMaximumConnectionLength',
|
||||||
|
'data' => [
|
||||||
|
'length' => $maximumConnectionLength,
|
||||||
|
],
|
||||||
|
]));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function registerProxy($requestId)
|
||||||
|
{
|
||||||
|
$this->socket->send(json_encode([
|
||||||
|
'event' => 'createProxy',
|
||||||
|
'data' => [
|
||||||
|
'request_id' => $requestId,
|
||||||
|
'client_id' => $this->client_id,
|
||||||
|
],
|
||||||
|
]));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function registerTcpProxy($requestId)
|
||||||
|
{
|
||||||
|
$this->socket->send(json_encode([
|
||||||
|
'event' => 'createTcpProxy',
|
||||||
|
'data' => [
|
||||||
|
'port' => $this->port,
|
||||||
|
'tcp_request_id' => $requestId,
|
||||||
|
'client_id' => $this->client_id,
|
||||||
|
],
|
||||||
|
]));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function stop()
|
||||||
|
{
|
||||||
|
$this->shared_server->close();
|
||||||
|
$this->shared_server = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function close()
|
||||||
|
{
|
||||||
|
$this->socket->close();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function toArray()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'type' => 'tcp',
|
||||||
|
'port' => $this->port,
|
||||||
|
'client_id' => $this->client_id,
|
||||||
|
'shared_port' => $this->shared_port,
|
||||||
|
'shared_at' => $this->shared_at,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function configureServer(Server $sharedServer)
|
||||||
|
{
|
||||||
|
$requestId = uniqid();
|
||||||
|
|
||||||
|
$sharedServer->on('connection', function (\React\Socket\ConnectionInterface $connection) use ($requestId) {
|
||||||
|
$this->proxyConnection = $connection;
|
||||||
|
|
||||||
|
$this->once('tcp_proxy_ready_'.$requestId, function (ConnectionInterface $proxy) use ($connection) {
|
||||||
|
$this->proxy = $proxy;
|
||||||
|
|
||||||
|
$connection->on('data', function ($data) use ($proxy) {
|
||||||
|
$binaryMsg = new Frame($data, true, Frame::OP_BINARY);
|
||||||
|
$proxy->send($binaryMsg);
|
||||||
|
});
|
||||||
|
|
||||||
|
$connection->resume();
|
||||||
|
});
|
||||||
|
|
||||||
|
$connection->pause();
|
||||||
|
$this->registerTcpProxy($requestId);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
7
app/Server/Exceptions/NoFreePortAvailable.php
Normal file
7
app/Server/Exceptions/NoFreePortAvailable.php
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Server\Exceptions;
|
||||||
|
|
||||||
|
class NoFreePortAvailable extends \Exception
|
||||||
|
{
|
||||||
|
}
|
||||||
@@ -10,11 +10,14 @@ use App\Http\Server as HttpServer;
|
|||||||
use App\Server\Connections\ConnectionManager;
|
use App\Server\Connections\ConnectionManager;
|
||||||
use App\Server\Http\Controllers\Admin\DeleteUsersController;
|
use App\Server\Http\Controllers\Admin\DeleteUsersController;
|
||||||
use App\Server\Http\Controllers\Admin\DisconnectSiteController;
|
use App\Server\Http\Controllers\Admin\DisconnectSiteController;
|
||||||
|
use App\Server\Http\Controllers\Admin\DisconnectTcpConnectionController;
|
||||||
use App\Server\Http\Controllers\Admin\GetSettingsController;
|
use App\Server\Http\Controllers\Admin\GetSettingsController;
|
||||||
use App\Server\Http\Controllers\Admin\GetSitesController;
|
use App\Server\Http\Controllers\Admin\GetSitesController;
|
||||||
|
use App\Server\Http\Controllers\Admin\GetTcpConnectionsController;
|
||||||
use App\Server\Http\Controllers\Admin\GetUserDetailsController;
|
use App\Server\Http\Controllers\Admin\GetUserDetailsController;
|
||||||
use App\Server\Http\Controllers\Admin\GetUsersController;
|
use App\Server\Http\Controllers\Admin\GetUsersController;
|
||||||
use App\Server\Http\Controllers\Admin\ListSitesController;
|
use App\Server\Http\Controllers\Admin\ListSitesController;
|
||||||
|
use App\Server\Http\Controllers\Admin\ListTcpConnectionsController;
|
||||||
use App\Server\Http\Controllers\Admin\ListUsersController;
|
use App\Server\Http\Controllers\Admin\ListUsersController;
|
||||||
use App\Server\Http\Controllers\Admin\RedirectToUsersController;
|
use App\Server\Http\Controllers\Admin\RedirectToUsersController;
|
||||||
use App\Server\Http\Controllers\Admin\ShowSettingsController;
|
use App\Server\Http\Controllers\Admin\ShowSettingsController;
|
||||||
@@ -120,6 +123,7 @@ class Factory
|
|||||||
$this->router->get('/users', ListUsersController::class, $adminCondition);
|
$this->router->get('/users', ListUsersController::class, $adminCondition);
|
||||||
$this->router->get('/settings', ShowSettingsController::class, $adminCondition);
|
$this->router->get('/settings', ShowSettingsController::class, $adminCondition);
|
||||||
$this->router->get('/sites', ListSitesController::class, $adminCondition);
|
$this->router->get('/sites', ListSitesController::class, $adminCondition);
|
||||||
|
$this->router->get('/tcp', ListTcpConnectionsController::class, $adminCondition);
|
||||||
|
|
||||||
$this->router->get('/api/settings', GetSettingsController::class, $adminCondition);
|
$this->router->get('/api/settings', GetSettingsController::class, $adminCondition);
|
||||||
$this->router->post('/api/settings', StoreSettingsController::class, $adminCondition);
|
$this->router->post('/api/settings', StoreSettingsController::class, $adminCondition);
|
||||||
@@ -129,6 +133,8 @@ class Factory
|
|||||||
$this->router->delete('/api/users/{id}', DeleteUsersController::class, $adminCondition);
|
$this->router->delete('/api/users/{id}', DeleteUsersController::class, $adminCondition);
|
||||||
$this->router->get('/api/sites', GetSitesController::class, $adminCondition);
|
$this->router->get('/api/sites', GetSitesController::class, $adminCondition);
|
||||||
$this->router->delete('/api/sites/{id}', DisconnectSiteController::class, $adminCondition);
|
$this->router->delete('/api/sites/{id}', DisconnectSiteController::class, $adminCondition);
|
||||||
|
$this->router->get('/api/tcp', GetTcpConnectionsController::class, $adminCondition);
|
||||||
|
$this->router->delete('/api/tcp/{id}', DisconnectTcpConnectionController::class, $adminCondition);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function bindConfiguration()
|
protected function bindConfiguration()
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Server\Http\Controllers\Admin;
|
||||||
|
|
||||||
|
use App\Contracts\ConnectionManager;
|
||||||
|
use App\Server\Configuration;
|
||||||
|
use App\Server\Connections\TcpControlConnection;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Ratchet\ConnectionInterface;
|
||||||
|
|
||||||
|
class DisconnectTcpConnectionController extends AdminController
|
||||||
|
{
|
||||||
|
/** @var ConnectionManager */
|
||||||
|
protected $connectionManager;
|
||||||
|
|
||||||
|
/** @var Configuration */
|
||||||
|
protected $configuration;
|
||||||
|
|
||||||
|
public function __construct(ConnectionManager $connectionManager)
|
||||||
|
{
|
||||||
|
$this->connectionManager = $connectionManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function handle(Request $request, ConnectionInterface $httpConnection)
|
||||||
|
{
|
||||||
|
$connection = $this->connectionManager->findControlConnectionForClientId($request->get('id'));
|
||||||
|
|
||||||
|
if (! is_null($connection)) {
|
||||||
|
$connection->close();
|
||||||
|
|
||||||
|
$this->connectionManager->removeControlConnection($connection);
|
||||||
|
}
|
||||||
|
|
||||||
|
$httpConnection->send(respond_json([
|
||||||
|
'tcp_connections' => collect($this->connectionManager->getConnections())
|
||||||
|
->filter(function ($connection) {
|
||||||
|
return get_class($connection) === TcpControlConnection::class;
|
||||||
|
})
|
||||||
|
->values(),
|
||||||
|
]));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,6 +4,7 @@ namespace App\Server\Http\Controllers\Admin;
|
|||||||
|
|
||||||
use App\Contracts\ConnectionManager;
|
use App\Contracts\ConnectionManager;
|
||||||
use App\Server\Configuration;
|
use App\Server\Configuration;
|
||||||
|
use App\Server\Connections\ControlConnection;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Ratchet\ConnectionInterface;
|
use Ratchet\ConnectionInterface;
|
||||||
|
|
||||||
@@ -23,7 +24,11 @@ class GetSitesController extends AdminController
|
|||||||
{
|
{
|
||||||
$httpConnection->send(
|
$httpConnection->send(
|
||||||
respond_json([
|
respond_json([
|
||||||
'sites' => collect($this->connectionManager->getConnections())->map(function ($site, $siteId) {
|
'sites' => collect($this->connectionManager->getConnections())
|
||||||
|
->filter(function ($connection) {
|
||||||
|
return get_class($connection) === ControlConnection::class;
|
||||||
|
})
|
||||||
|
->map(function ($site, $siteId) {
|
||||||
$site = $site->toArray();
|
$site = $site->toArray();
|
||||||
$site['id'] = $siteId;
|
$site['id'] = $siteId;
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,41 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Server\Http\Controllers\Admin;
|
||||||
|
|
||||||
|
use App\Contracts\ConnectionManager;
|
||||||
|
use App\Server\Configuration;
|
||||||
|
use App\Server\Connections\TcpControlConnection;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Ratchet\ConnectionInterface;
|
||||||
|
|
||||||
|
class GetTcpConnectionsController extends AdminController
|
||||||
|
{
|
||||||
|
/** @var ConnectionManager */
|
||||||
|
protected $connectionManager;
|
||||||
|
/** @var Configuration */
|
||||||
|
protected $configuration;
|
||||||
|
|
||||||
|
public function __construct(ConnectionManager $connectionManager, Configuration $configuration)
|
||||||
|
{
|
||||||
|
$this->connectionManager = $connectionManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function handle(Request $request, ConnectionInterface $httpConnection)
|
||||||
|
{
|
||||||
|
$httpConnection->send(
|
||||||
|
respond_json([
|
||||||
|
'tcp_connections' => collect($this->connectionManager->getConnections())
|
||||||
|
->filter(function ($connection) {
|
||||||
|
return get_class($connection) === TcpControlConnection::class;
|
||||||
|
})
|
||||||
|
->map(function ($site, $siteId) {
|
||||||
|
$site = $site->toArray();
|
||||||
|
$site['id'] = $siteId;
|
||||||
|
|
||||||
|
return $site;
|
||||||
|
})
|
||||||
|
->values(),
|
||||||
|
])
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,6 +4,7 @@ namespace App\Server\Http\Controllers\Admin;
|
|||||||
|
|
||||||
use App\Contracts\ConnectionManager;
|
use App\Contracts\ConnectionManager;
|
||||||
use App\Server\Configuration;
|
use App\Server\Configuration;
|
||||||
|
use App\Server\Connections\ControlConnection;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Ratchet\ConnectionInterface;
|
use Ratchet\ConnectionInterface;
|
||||||
|
|
||||||
@@ -25,12 +26,17 @@ class ListSitesController extends AdminController
|
|||||||
$sites = $this->getView($httpConnection, 'server.sites.index', [
|
$sites = $this->getView($httpConnection, 'server.sites.index', [
|
||||||
'scheme' => $this->configuration->port() === 443 ? 'https' : 'http',
|
'scheme' => $this->configuration->port() === 443 ? 'https' : 'http',
|
||||||
'configuration' => $this->configuration,
|
'configuration' => $this->configuration,
|
||||||
'sites' => collect($this->connectionManager->getConnections())->map(function ($site, $siteId) {
|
'sites' => collect($this->connectionManager->getConnections())
|
||||||
|
->filter(function ($connection) {
|
||||||
|
return get_class($connection) === ControlConnection::class;
|
||||||
|
})
|
||||||
|
->map(function ($site, $siteId) {
|
||||||
$site = $site->toArray();
|
$site = $site->toArray();
|
||||||
$site['id'] = $siteId;
|
$site['id'] = $siteId;
|
||||||
|
|
||||||
return $site;
|
return $site;
|
||||||
})->values(),
|
})
|
||||||
|
->values(),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$httpConnection->send(
|
$httpConnection->send(
|
||||||
|
|||||||
@@ -0,0 +1,46 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Server\Http\Controllers\Admin;
|
||||||
|
|
||||||
|
use App\Contracts\ConnectionManager;
|
||||||
|
use App\Server\Configuration;
|
||||||
|
use App\Server\Connections\TcpControlConnection;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Ratchet\ConnectionInterface;
|
||||||
|
|
||||||
|
class ListTcpConnectionsController extends AdminController
|
||||||
|
{
|
||||||
|
/** @var ConnectionManager */
|
||||||
|
protected $connectionManager;
|
||||||
|
/** @var Configuration */
|
||||||
|
protected $configuration;
|
||||||
|
|
||||||
|
public function __construct(ConnectionManager $connectionManager, Configuration $configuration)
|
||||||
|
{
|
||||||
|
$this->connectionManager = $connectionManager;
|
||||||
|
$this->configuration = $configuration;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function handle(Request $request, ConnectionInterface $httpConnection)
|
||||||
|
{
|
||||||
|
$sites = $this->getView($httpConnection, 'server.tcp.index', [
|
||||||
|
'scheme' => $this->configuration->port() === 443 ? 'https' : 'http',
|
||||||
|
'configuration' => $this->configuration,
|
||||||
|
'connections' => collect($this->connectionManager->getConnections())
|
||||||
|
->filter(function ($connection) {
|
||||||
|
return get_class($connection) === TcpControlConnection::class;
|
||||||
|
})
|
||||||
|
->map(function ($connection, $connectionId) {
|
||||||
|
$connection = $connection->toArray();
|
||||||
|
$connection['id'] = $connectionId;
|
||||||
|
|
||||||
|
return $connection;
|
||||||
|
})
|
||||||
|
->values(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
$httpConnection->send(
|
||||||
|
respond_html($sites)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -40,6 +40,7 @@ class StoreUsersController extends AdminController
|
|||||||
'name' => $request->get('name'),
|
'name' => $request->get('name'),
|
||||||
'auth_token' => (string) Str::uuid(),
|
'auth_token' => (string) Str::uuid(),
|
||||||
'can_specify_subdomains' => (int) $request->get('can_specify_subdomains'),
|
'can_specify_subdomains' => (int) $request->get('can_specify_subdomains'),
|
||||||
|
'can_share_tcp_ports' => (int) $request->get('can_share_tcp_ports'),
|
||||||
];
|
];
|
||||||
|
|
||||||
$this->userRepository
|
$this->userRepository
|
||||||
|
|||||||
@@ -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;
|
||||||
@@ -53,6 +54,10 @@ class ControlMessageController implements MessageComponentInterface
|
|||||||
if (isset($connection->request_id)) {
|
if (isset($connection->request_id)) {
|
||||||
return $this->sendResponseToHttpConnection($connection->request_id, $msg);
|
return $this->sendResponseToHttpConnection($connection->request_id, $msg);
|
||||||
}
|
}
|
||||||
|
if (isset($connection->tcp_request_id)) {
|
||||||
|
$connectionInfo = $this->connectionManager->findControlConnectionForClientId($connection->tcp_client_id);
|
||||||
|
$connectionInfo->proxyConnection->write($msg);
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$payload = json_decode($msg);
|
$payload = json_decode($msg);
|
||||||
@@ -77,6 +82,24 @@ class ControlMessageController implements MessageComponentInterface
|
|||||||
{
|
{
|
||||||
$this->verifyAuthToken($connection)
|
$this->verifyAuthToken($connection)
|
||||||
->then(function ($user) use ($connection, $data) {
|
->then(function ($user) use ($connection, $data) {
|
||||||
|
if ($data->type === 'http') {
|
||||||
|
$this->handleHttpConnection($connection, $data, $user);
|
||||||
|
} elseif ($data->type === 'tcp') {
|
||||||
|
$this->handleTcpConnection($connection, $data, $user);
|
||||||
|
}
|
||||||
|
}, function () use ($connection) {
|
||||||
|
$connection->send(json_encode([
|
||||||
|
'event' => 'authenticationFailed',
|
||||||
|
'data' => [
|
||||||
|
'message' => config('expose.admin.messages.invalid_auth_token'),
|
||||||
|
],
|
||||||
|
]));
|
||||||
|
$connection->close();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function handleHttpConnection(ConnectionInterface $connection, $data, $user = null)
|
||||||
|
{
|
||||||
if (! $this->hasValidSubdomain($connection, $data->subdomain, $user)) {
|
if (! $this->hasValidSubdomain($connection, $data->subdomain, $user)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -93,15 +116,37 @@ class ControlMessageController implements MessageComponentInterface
|
|||||||
'client_id' => $connectionInfo->client_id,
|
'client_id' => $connectionInfo->client_id,
|
||||||
],
|
],
|
||||||
]));
|
]));
|
||||||
}, function () use ($connection) {
|
}
|
||||||
|
|
||||||
|
protected function handleTcpConnection(ConnectionInterface $connection, $data, $user = null)
|
||||||
|
{
|
||||||
|
if (! $this->canShareTcpPorts($connection, $data, $user)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$connectionInfo = $this->connectionManager->storeTcpConnection($data->port, $connection);
|
||||||
|
} catch (NoFreePortAvailable $exception) {
|
||||||
$connection->send(json_encode([
|
$connection->send(json_encode([
|
||||||
'event' => 'authenticationFailed',
|
'event' => 'authenticationFailed',
|
||||||
'data' => [
|
'data' => [
|
||||||
'message' => config('expose.admin.messages.invalid_auth_token'),
|
'message' => config('expose.admin.messages.no_free_tcp_port_available'),
|
||||||
],
|
],
|
||||||
]));
|
]));
|
||||||
$connection->close();
|
$connection->close();
|
||||||
});
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$connection->send(json_encode([
|
||||||
|
'event' => 'authenticated',
|
||||||
|
'data' => [
|
||||||
|
'message' => config('expose.admin.messages.message_of_the_day'),
|
||||||
|
'port' => $connectionInfo->port,
|
||||||
|
'shared_port' => $connectionInfo->shared_port,
|
||||||
|
'client_id' => $connectionInfo->client_id,
|
||||||
|
],
|
||||||
|
]));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function registerProxy(ConnectionInterface $connection, $data)
|
protected function registerProxy(ConnectionInterface $connection, $data)
|
||||||
@@ -115,6 +160,18 @@ class ControlMessageController implements MessageComponentInterface
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function registerTcpProxy(ConnectionInterface $connection, $data)
|
||||||
|
{
|
||||||
|
$connection->tcp_client_id = $data->client_id;
|
||||||
|
$connection->tcp_request_id = $data->tcp_request_id;
|
||||||
|
|
||||||
|
$connectionInfo = $this->connectionManager->findControlConnectionForClientId($data->client_id);
|
||||||
|
|
||||||
|
$connectionInfo->emit('tcp_proxy_ready_'.$data->tcp_request_id, [
|
||||||
|
$connection,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
@@ -180,4 +237,21 @@ class ControlMessageController implements MessageComponentInterface
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function canShareTcpPorts(ConnectionInterface $connection, $data, $user)
|
||||||
|
{
|
||||||
|
if (! is_null($user) && $user['can_share_tcp_ports'] === 0) {
|
||||||
|
$connection->send(json_encode([
|
||||||
|
'event' => 'authenticationFailed',
|
||||||
|
'data' => [
|
||||||
|
'message' => config('expose.admin.messages.custom_subdomain_unauthorized'),
|
||||||
|
],
|
||||||
|
]));
|
||||||
|
$connection->close();
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -72,6 +72,7 @@ class DatabaseUserRepository implements UserRepository
|
|||||||
protected function getUserDetails(array $user)
|
protected function getUserDetails(array $user)
|
||||||
{
|
{
|
||||||
$user['sites'] = $user['auth_token'] !== '' ? $this->connectionManager->getConnectionsForAuthToken($user['auth_token']) : [];
|
$user['sites'] = $user['auth_token'] !== '' ? $this->connectionManager->getConnectionsForAuthToken($user['auth_token']) : [];
|
||||||
|
$user['tcp_connections'] = $user['auth_token'] !== '' ? $this->connectionManager->getTcpConnectionsForAuthToken($user['auth_token']) : [];
|
||||||
|
|
||||||
return $user;
|
return $user;
|
||||||
}
|
}
|
||||||
@@ -113,8 +114,8 @@ class DatabaseUserRepository implements UserRepository
|
|||||||
$deferred = new Deferred();
|
$deferred = new Deferred();
|
||||||
|
|
||||||
$this->database->query("
|
$this->database->query("
|
||||||
INSERT INTO users (name, auth_token, can_specify_subdomains, created_at)
|
INSERT INTO users (name, auth_token, can_specify_subdomains, can_share_tcp_ports, created_at)
|
||||||
VALUES (:name, :auth_token, :can_specify_subdomains, DATETIME('now'))
|
VALUES (:name, :auth_token, :can_specify_subdomains, :can_share_tcp_ports, DATETIME('now'))
|
||||||
", $data)
|
", $data)
|
||||||
->then(function (Result $result) use ($deferred) {
|
->then(function (Result $result) use ($deferred) {
|
||||||
$this->database->query('SELECT * FROM users WHERE id = :id', ['id' => $result->insertId])
|
$this->database->query('SELECT * FROM users WHERE id = :id', ['id' => $result->insertId])
|
||||||
|
|||||||
BIN
builds/expose
BIN
builds/expose
Binary file not shown.
@@ -38,7 +38,7 @@
|
|||||||
"phpunit/phpunit": "^8.5",
|
"phpunit/phpunit": "^8.5",
|
||||||
"ratchet/pawl": "^0.3.4",
|
"ratchet/pawl": "^0.3.4",
|
||||||
"react/http": "^0.8.6",
|
"react/http": "^0.8.6",
|
||||||
"react/socket": "dev-master as 1.1",
|
"react/socket": "^1.6",
|
||||||
"react/stream": "^1.1.1",
|
"react/stream": "^1.1.1",
|
||||||
"riverline/multipart-parser": "^2.0",
|
"riverline/multipart-parser": "^2.0",
|
||||||
"symfony/expression-language": "^5.0",
|
"symfony/expression-language": "^5.0",
|
||||||
|
|||||||
1653
composer.lock
generated
1653
composer.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -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' => 60000,
|
||||||
|
],
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
| 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.',
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
ALTER TABLE users ADD can_share_tcp_ports BOOLEAN DEFAULT 1;
|
||||||
@@ -27,6 +27,12 @@
|
|||||||
ml-8 inline-flex items-center px-1 pt-1 border-b-2 text-sm font-medium leading-5 focus:outline-none transition duration-150 ease-in-out">
|
ml-8 inline-flex items-center px-1 pt-1 border-b-2 text-sm font-medium leading-5 focus:outline-none transition duration-150 ease-in-out">
|
||||||
Shared sites
|
Shared sites
|
||||||
</a>
|
</a>
|
||||||
|
<a href="/tcp"
|
||||||
|
class="
|
||||||
|
{% if request.is('tcp') %} border-indigo-500 focus:border-indigo-700 text-gray-900 {% else %} border-transparent text-gray-500 hover:text-gray-700 hover:border-gray-300 focus:text-gray-700 focus:border-gray-300{% endif %}
|
||||||
|
ml-8 inline-flex items-center px-1 pt-1 border-b-2 text-sm font-medium leading-5 focus:outline-none transition duration-150 ease-in-out">
|
||||||
|
TCP connections
|
||||||
|
</a>
|
||||||
<a href="/settings"
|
<a href="/settings"
|
||||||
class="
|
class="
|
||||||
{% if request.is('settings') %} border-indigo-500 focus:border-indigo-700 text-gray-900 {% else %} border-transparent text-gray-500 hover:text-gray-700 hover:border-gray-300 focus:text-gray-700 focus:border-gray-300{% endif %}
|
{% if request.is('settings') %} border-indigo-500 focus:border-indigo-700 text-gray-900 {% else %} border-transparent text-gray-500 hover:text-gray-700 hover:border-gray-300 focus:text-gray-700 focus:border-gray-300{% endif %}
|
||||||
|
|||||||
73
resources/views/server/tcp/index.twig
Normal file
73
resources/views/server/tcp/index.twig
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
{% extends "app" %}
|
||||||
|
{% block title %}TCP Connections{% endblock %}
|
||||||
|
{% block content %}
|
||||||
|
<div class="flex flex-col py-8">
|
||||||
|
<div class="-my-2 py-2 overflow-x-auto sm:-mx-6 sm:px-6 lg:-mx-8 lg:px-8">
|
||||||
|
<div
|
||||||
|
class="align-middle inline-block min-w-full shadow overflow-hidden sm:rounded-lg border-b border-gray-200">
|
||||||
|
<table class="min-w-full" v-if="connections.length > 0">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th class="px-6 py-3 border-b border-gray-200 bg-gray-50 text-left text-xs leading-4 font-medium text-gray-500 uppercase tracking-wider">
|
||||||
|
Local Port
|
||||||
|
</th>
|
||||||
|
<th class="px-6 py-3 border-b border-gray-200 bg-gray-50 text-left text-xs leading-4 font-medium text-gray-500 uppercase tracking-wider">
|
||||||
|
Expose Port
|
||||||
|
</th>
|
||||||
|
<th class="px-6 py-3 border-b border-gray-200 bg-gray-50 text-left text-xs leading-4 font-medium text-gray-500 uppercase tracking-wider">
|
||||||
|
Shared At
|
||||||
|
</th>
|
||||||
|
<th class="px-6 py-3 border-b border-gray-200 bg-gray-50"></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody class="bg-white">
|
||||||
|
<tr v-for="connection in connections">
|
||||||
|
<td class="px-6 py-4 whitespace-no-wrap border-b border-gray-200 text-sm leading-5 font-medium text-gray-900">
|
||||||
|
@{ connection.port }
|
||||||
|
</td>
|
||||||
|
<td class="px-6 py-4 whitespace-no-wrap border-b border-gray-200 text-sm leading-5 text-gray-500">
|
||||||
|
@{ connection.shared_port }
|
||||||
|
</td>
|
||||||
|
<td class="px-6 py-4 whitespace-no-wrap border-b border-gray-200 text-sm leading-5 text-gray-500">
|
||||||
|
@{ connection.shared_at }
|
||||||
|
</td>
|
||||||
|
<td class="px-6 py-4 whitespace-no-wrap text-right border-b border-gray-200 text-sm leading-5 font-medium">
|
||||||
|
<a href="#"
|
||||||
|
@click.prevent="disconnectConnection(connection.client_id)"
|
||||||
|
class="pl-2 text-red-600 hover:text-red-900">Disconnect</a>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<div class="flex items-center justify-center text-gray-900 p-4" v-else>
|
||||||
|
<span class="text-xl">There are no TCP connections shared with this server yet.</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
|
{% block scripts %}
|
||||||
|
<script>
|
||||||
|
new Vue({
|
||||||
|
el: '#app',
|
||||||
|
|
||||||
|
delimiters: ['@{', '}'],
|
||||||
|
|
||||||
|
data: {
|
||||||
|
connections: {{ connections|json_encode|raw }}
|
||||||
|
},
|
||||||
|
|
||||||
|
methods: {
|
||||||
|
disconnectConnection(id) {
|
||||||
|
fetch('/api/tcp/' + id, {
|
||||||
|
method: 'DELETE',
|
||||||
|
}).then((response) => {
|
||||||
|
return response.json();
|
||||||
|
}).then((data) => {
|
||||||
|
this.connections = data.connections;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
{% endblock %}
|
||||||
@@ -43,6 +43,25 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="sm:grid sm:grid-cols-3 sm:gap-4 sm:items-start sm:pt-5">
|
||||||
|
<label for="can_share_tcp_ports"
|
||||||
|
class="block text-sm font-medium leading-5 text-gray-700 sm:mt-px sm:pt-2">
|
||||||
|
Can share TCP ports
|
||||||
|
</label>
|
||||||
|
<div class="mt-1 sm:mt-0 sm:col-span-2">
|
||||||
|
<div class="mt-2 flex items-center justify-between">
|
||||||
|
<div class="flex items-center">
|
||||||
|
<input id="can_share_tcp_ports"
|
||||||
|
v-model="userForm.can_share_tcp_ports"
|
||||||
|
name="can_share_tcp_ports"
|
||||||
|
value="1" type="checkbox" class="form-checkbox h-4 w-4 text-indigo-600 transition duration-150 ease-in-out" />
|
||||||
|
<label for="can_share_tcp_ports" class="ml-2 block text-sm leading-5 text-gray-900">
|
||||||
|
Yes
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="mt-8 border-t border-gray-200 pt-5">
|
<div class="mt-8 border-t border-gray-200 pt-5">
|
||||||
<div class="flex justify-end">
|
<div class="flex justify-end">
|
||||||
@@ -73,6 +92,9 @@
|
|||||||
<th class="px-6 py-3 border-b border-gray-200 bg-gray-50 text-left text-xs leading-4 font-medium text-gray-500 uppercase tracking-wider">
|
<th class="px-6 py-3 border-b border-gray-200 bg-gray-50 text-left text-xs leading-4 font-medium text-gray-500 uppercase tracking-wider">
|
||||||
Custom Subdomains
|
Custom Subdomains
|
||||||
</th>
|
</th>
|
||||||
|
<th class="px-6 py-3 border-b border-gray-200 bg-gray-50 text-left text-xs leading-4 font-medium text-gray-500 uppercase tracking-wider">
|
||||||
|
TCP ports
|
||||||
|
</th>
|
||||||
<th class="px-6 py-3 border-b border-gray-200 bg-gray-50 text-left text-xs leading-4 font-medium text-gray-500 uppercase tracking-wider">
|
<th class="px-6 py-3 border-b border-gray-200 bg-gray-50 text-left text-xs leading-4 font-medium text-gray-500 uppercase tracking-wider">
|
||||||
Created At
|
Created At
|
||||||
</th>
|
</th>
|
||||||
@@ -95,6 +117,14 @@
|
|||||||
Yes
|
Yes
|
||||||
</span>
|
</span>
|
||||||
</td>
|
</td>
|
||||||
|
<td class="px-6 py-4 whitespace-no-wrap border-b border-gray-200 text-sm leading-5 text-gray-500">
|
||||||
|
<span v-if="user.can_share_tcp_ports === 0">
|
||||||
|
No
|
||||||
|
</span>
|
||||||
|
<span v-else>
|
||||||
|
Yes
|
||||||
|
</span>
|
||||||
|
</td>
|
||||||
<td class="px-6 py-4 whitespace-no-wrap border-b border-gray-200 text-sm leading-5 text-gray-500">
|
<td class="px-6 py-4 whitespace-no-wrap border-b border-gray-200 text-sm leading-5 text-gray-500">
|
||||||
@{ user.created_at }
|
@{ user.created_at }
|
||||||
</td>
|
</td>
|
||||||
@@ -144,6 +174,7 @@
|
|||||||
userForm: {
|
userForm: {
|
||||||
name: '',
|
name: '',
|
||||||
can_specify_subdomains: true,
|
can_specify_subdomains: true,
|
||||||
|
can_share_tcp_ports: true,
|
||||||
errors: {},
|
errors: {},
|
||||||
},
|
},
|
||||||
paginated: {{ paginated|json_encode|raw }}
|
paginated: {{ paginated|json_encode|raw }}
|
||||||
@@ -186,7 +217,8 @@
|
|||||||
}).then((data) => {
|
}).then((data) => {
|
||||||
if (data.user) {
|
if (data.user) {
|
||||||
this.userForm.name = '';
|
this.userForm.name = '';
|
||||||
this.userForm.can_specify_subdomains = 0;
|
this.userForm.can_specify_subdomains = true;
|
||||||
|
this.userForm.can_share_tcp_ports = true;
|
||||||
this.userForm.errors = {};
|
this.userForm.errors = {};
|
||||||
this.users.unshift(data.user);
|
this.users.unshift(data.user);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -88,6 +88,7 @@ class ApiTest extends TestCase
|
|||||||
|
|
||||||
$this->assertSame('Marcel', $user->name);
|
$this->assertSame('Marcel', $user->name);
|
||||||
$this->assertSame([], $user->sites);
|
$this->assertSame([], $user->sites);
|
||||||
|
$this->assertSame([], $user->tcp_connections);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @test */
|
/** @test */
|
||||||
@@ -115,6 +116,10 @@ class ApiTest extends TestCase
|
|||||||
$connection->httpRequest = new Request('GET', '/?authToken=some-other-token');
|
$connection->httpRequest = new Request('GET', '/?authToken=some-other-token');
|
||||||
$connectionManager->storeConnection('some-different-host.test', 'different-subdomain', $connection);
|
$connectionManager->storeConnection('some-different-host.test', 'different-subdomain', $connection);
|
||||||
|
|
||||||
|
$connection = \Mockery::mock(IoConnection::class);
|
||||||
|
$connection->httpRequest = new Request('GET', '/?authToken='.$createdUser->auth_token);
|
||||||
|
$connectionManager->storeTcpConnection(2525, $connection);
|
||||||
|
|
||||||
/** @var Response $response */
|
/** @var Response $response */
|
||||||
$response = $this->await($this->browser->get('http://127.0.0.1:8080/api/users', [
|
$response = $this->await($this->browser->get('http://127.0.0.1:8080/api/users', [
|
||||||
'Host' => 'expose.localhost',
|
'Host' => 'expose.localhost',
|
||||||
@@ -126,6 +131,7 @@ class ApiTest extends TestCase
|
|||||||
$users = $body->paginated->users;
|
$users = $body->paginated->users;
|
||||||
|
|
||||||
$this->assertCount(1, $users[0]->sites);
|
$this->assertCount(1, $users[0]->sites);
|
||||||
|
$this->assertCount(1, $users[0]->tcp_connections);
|
||||||
$this->assertSame('some-host.test', $users[0]->sites[0]->host);
|
$this->assertSame('some-host.test', $users[0]->sites[0]->host);
|
||||||
$this->assertSame('fixed-subdomain', $users[0]->sites[0]->subdomain);
|
$this->assertSame('fixed-subdomain', $users[0]->sites[0]->subdomain);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ use Clue\React\Buzz\Message\ResponseException;
|
|||||||
use GuzzleHttp\Psr7\Response;
|
use GuzzleHttp\Psr7\Response;
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
use React\Http\Server;
|
use React\Http\Server;
|
||||||
|
use React\Socket\Connection;
|
||||||
use Tests\Feature\TestCase;
|
use Tests\Feature\TestCase;
|
||||||
|
|
||||||
class TunnelTest extends TestCase
|
class TunnelTest extends TestCase
|
||||||
@@ -22,6 +23,9 @@ class TunnelTest extends TestCase
|
|||||||
/** @var \React\Socket\Server */
|
/** @var \React\Socket\Server */
|
||||||
protected $testHttpServer;
|
protected $testHttpServer;
|
||||||
|
|
||||||
|
/** @var \React\Socket\Server */
|
||||||
|
protected $testTcpServer;
|
||||||
|
|
||||||
public function setUp(): void
|
public function setUp(): void
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
@@ -42,6 +46,10 @@ class TunnelTest extends TestCase
|
|||||||
$this->testHttpServer->close();
|
$this->testHttpServer->close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isset($this->testTcpServer)) {
|
||||||
|
$this->testTcpServer->close();
|
||||||
|
}
|
||||||
|
|
||||||
parent::tearDown();
|
parent::tearDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,6 +89,93 @@ class TunnelTest extends TestCase
|
|||||||
$this->assertSame('Hello World!', $response->getBody()->getContents());
|
$this->assertSame('Hello World!', $response->getBody()->getContents());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @test */
|
||||||
|
public function it_sends_incoming_requests_to_the_connected_client_via_tcp()
|
||||||
|
{
|
||||||
|
$this->createTestTcpServer();
|
||||||
|
|
||||||
|
$this->app['config']['expose.admin.validate_auth_tokens'] = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* We create an expose client that connects to our server and shares
|
||||||
|
* the created test HTTP server.
|
||||||
|
*/
|
||||||
|
$client = $this->createClient();
|
||||||
|
$response = $this->await($client->connectToServerAndShareTcp(8085));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Once the client is connected, we connect to the
|
||||||
|
* created tunnel.
|
||||||
|
*/
|
||||||
|
$connector = new \React\Socket\Connector($this->loop);
|
||||||
|
$connection = $this->await($connector->connect('127.0.0.1:'.$response->shared_port));
|
||||||
|
|
||||||
|
$this->assertInstanceOf(Connection::class, $connection);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @test */
|
||||||
|
public function it_rejects_tcp_sharing_if_forbidden()
|
||||||
|
{
|
||||||
|
$this->createTestTcpServer();
|
||||||
|
|
||||||
|
$this->app['config']['expose.admin.validate_auth_tokens'] = true;
|
||||||
|
|
||||||
|
$response = $this->await($this->browser->post('http://127.0.0.1:8080/api/users', [
|
||||||
|
'Host' => 'expose.localhost',
|
||||||
|
'Authorization' => base64_encode('username:secret'),
|
||||||
|
'Content-Type' => 'application/json',
|
||||||
|
], json_encode([
|
||||||
|
'name' => 'Marcel',
|
||||||
|
'can_share_tcp_ports' => 0,
|
||||||
|
])));
|
||||||
|
|
||||||
|
$user = json_decode($response->getBody()->getContents())->user;
|
||||||
|
|
||||||
|
$this->expectException(\UnexpectedValueException::class);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* We create an expose client that connects to our server and shares
|
||||||
|
* the created test HTTP server.
|
||||||
|
*/
|
||||||
|
$client = $this->createClient();
|
||||||
|
$this->await($client->connectToServerAndShareTcp(8085, $user->auth_token));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @test */
|
||||||
|
public function it_allows_tcp_sharing_if_enabled_for_user()
|
||||||
|
{
|
||||||
|
$this->createTestTcpServer();
|
||||||
|
|
||||||
|
$this->app['config']['expose.admin.validate_auth_tokens'] = true;
|
||||||
|
|
||||||
|
$response = $this->await($this->browser->post('http://127.0.0.1:8080/api/users', [
|
||||||
|
'Host' => 'expose.localhost',
|
||||||
|
'Authorization' => base64_encode('username:secret'),
|
||||||
|
'Content-Type' => 'application/json',
|
||||||
|
], json_encode([
|
||||||
|
'name' => 'Marcel',
|
||||||
|
'can_share_tcp_ports' => 1,
|
||||||
|
])));
|
||||||
|
|
||||||
|
$user = json_decode($response->getBody()->getContents())->user;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* We create an expose client that connects to our server and shares
|
||||||
|
* the created test HTTP server.
|
||||||
|
*/
|
||||||
|
$client = $this->createClient();
|
||||||
|
$response = $this->await($client->connectToServerAndShareTcp(8085, $user->auth_token));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Once the client is connected, we connect to the
|
||||||
|
* created tunnel.
|
||||||
|
*/
|
||||||
|
$connector = new \React\Socket\Connector($this->loop);
|
||||||
|
$connection = $this->await($connector->connect('127.0.0.1:'.$response->shared_port));
|
||||||
|
|
||||||
|
$this->assertInstanceOf(Connection::class, $connection);
|
||||||
|
}
|
||||||
|
|
||||||
/** @test */
|
/** @test */
|
||||||
public function it_rejects_clients_with_invalid_auth_tokens()
|
public function it_rejects_clients_with_invalid_auth_tokens()
|
||||||
{
|
{
|
||||||
@@ -221,4 +316,15 @@ class TunnelTest extends TestCase
|
|||||||
$this->testHttpServer = new \React\Socket\Server(8085, $this->loop);
|
$this->testHttpServer = new \React\Socket\Server(8085, $this->loop);
|
||||||
$server->listen($this->testHttpServer);
|
$server->listen($this->testHttpServer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function createTestTcpServer()
|
||||||
|
{
|
||||||
|
$this->testTcpServer = new \React\Socket\Server(8085, $this->loop);
|
||||||
|
|
||||||
|
$this->testTcpServer->on('connection', function (\React\Socket\ConnectionInterface $connection) {
|
||||||
|
$connection->write('Hello '.$connection->getRemoteAddress()."!\n");
|
||||||
|
|
||||||
|
$connection->pipe($connection);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user