mirror of
https://github.com/bitinflow/expose.git
synced 2026-03-14 05:55:54 +00:00
Compare commits
26 Commits
custom-hos
...
tcp
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a71fea398e | ||
|
|
ab3fc0f2ab | ||
|
|
4bfa384f1b | ||
|
|
c57758f08f | ||
|
|
ce932cf937 | ||
|
|
d68dcddf2b | ||
|
|
077be1cee3 | ||
|
|
1fc277fd5e | ||
|
|
790d33d548 | ||
|
|
54495fd4a8 | ||
|
|
9fde919bbe | ||
|
|
51c6749adf | ||
|
|
f9339c0049 | ||
|
|
e8842f33f0 | ||
|
|
256ba609f5 | ||
|
|
cfc0ad92a5 | ||
|
|
da8757744a | ||
|
|
fb45d40684 | ||
|
|
827ca9a13e | ||
|
|
b9ca7e9e48 | ||
|
|
1d7555f58c | ||
|
|
3a3dc85e72 | ||
|
|
c086d0a77e | ||
|
|
32fd4ba8ea | ||
|
|
e857de8498 | ||
|
|
12f08db391 |
@@ -21,4 +21,3 @@ ENV password=password
|
||||
ENV exposeConfigPath=/src/config/expose.php
|
||||
|
||||
CMD sed -i "s|username|${username}|g" ${exposeConfigPath} && sed -i "s|password|${password}|g" ${exposeConfigPath} && php expose serve ${domain} --port ${port} --validateAuthTokens
|
||||
ENTRYPOINT ["/src/expose"]
|
||||
|
||||
@@ -40,12 +40,12 @@ class Client
|
||||
$this->logger = $logger;
|
||||
}
|
||||
|
||||
public function share(string $sharedUrl, array $subdomains = [], string $hostname = '')
|
||||
public function share(string $sharedUrl, array $subdomains = [])
|
||||
{
|
||||
$sharedUrl = $this->prepareSharedUrl($sharedUrl);
|
||||
|
||||
foreach ($subdomains as $subdomain) {
|
||||
$this->connectToServer($sharedUrl, $subdomain, $hostname, config('expose.auth_token'));
|
||||
$this->connectToServer($sharedUrl, $subdomain, config('expose.auth_token'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ class Client
|
||||
return $url;
|
||||
}
|
||||
|
||||
public function connectToServer(string $sharedUrl, $subdomain, $hostname = '', $authToken = ''): PromiseInterface
|
||||
public function connectToServer(string $sharedUrl, $subdomain, $authToken = ''): PromiseInterface
|
||||
{
|
||||
$deferred = new Deferred();
|
||||
$promise = $deferred->promise();
|
||||
@@ -82,18 +82,18 @@ class Client
|
||||
connect($wsProtocol."://{$this->configuration->host()}:{$this->configuration->port()}/expose/control?authToken={$authToken}", [], [
|
||||
'X-Expose-Control' => 'enabled',
|
||||
], $this->loop)
|
||||
->then(function (WebSocket $clientConnection) use ($sharedUrl, $subdomain, $hostname, $deferred, $authToken) {
|
||||
->then(function (WebSocket $clientConnection) use ($sharedUrl, $subdomain, $deferred, $authToken) {
|
||||
$this->connectionRetries = 0;
|
||||
|
||||
$connection = ControlConnection::create($clientConnection);
|
||||
|
||||
$connection->authenticate($sharedUrl, $subdomain, $hostname);
|
||||
$connection->authenticate($sharedUrl, $subdomain);
|
||||
|
||||
$clientConnection->on('close', function () use ($sharedUrl, $subdomain, $hostname, $authToken) {
|
||||
$clientConnection->on('close', function () use ($sharedUrl, $subdomain, $authToken) {
|
||||
$this->logger->error('Connection to server closed.');
|
||||
|
||||
$this->retryConnectionOrExit(function () use ($sharedUrl, $subdomain, $hostname, $authToken) {
|
||||
$this->connectToServer($sharedUrl, $subdomain, $hostname, $authToken);
|
||||
$this->retryConnectionOrExit(function () use ($sharedUrl, $subdomain, $authToken) {
|
||||
$this->connectToServer($sharedUrl, $subdomain, $authToken);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -113,16 +113,10 @@ class Client
|
||||
$host .= ":{$this->configuration->port()}";
|
||||
}
|
||||
|
||||
if ($data->hostname !== '' && ! is_null($data->hostname)) {
|
||||
$exposeUrl = "{$httpProtocol}://{$data->hostname}";
|
||||
} else {
|
||||
$exposeUrl = "{$httpProtocol}://{$data->subdomain}.{$host}";
|
||||
}
|
||||
|
||||
$this->logger->info($data->message);
|
||||
$this->logger->info("Local-URL:\t\t{$sharedUrl}");
|
||||
$this->logger->info("Dashboard-URL:\t\thttp://127.0.0.1:".config()->get('expose.dashboard_port'));
|
||||
$this->logger->info("Expose-URL:\t\t{$exposeUrl}");
|
||||
$this->logger->info("Expose-URL:\t\t{$httpProtocol}://{$data->subdomain}.{$host}");
|
||||
$this->logger->line('');
|
||||
|
||||
static::$subdomains[] = "{$httpProtocol}://{$data->subdomain}.{$host}";
|
||||
@@ -203,14 +197,6 @@ class Client
|
||||
|
||||
protected function attachCommonConnectionListeners(ControlConnection $connection, Deferred $deferred)
|
||||
{
|
||||
$connection->on('info', function ($data) {
|
||||
$this->logger->info($data->message);
|
||||
});
|
||||
|
||||
$connection->on('error', function ($data) {
|
||||
$this->logger->error($data->message);
|
||||
});
|
||||
|
||||
$connection->on('authenticationFailed', function ($data) use ($deferred) {
|
||||
$this->logger->error($data->message);
|
||||
|
||||
|
||||
@@ -36,16 +36,4 @@ class Configuration
|
||||
{
|
||||
return intval($this->port);
|
||||
}
|
||||
|
||||
public function getUrl(string $subdomain): string
|
||||
{
|
||||
$httpProtocol = $this->port() === 443 ? 'https' : 'http';
|
||||
$host = $this->host();
|
||||
|
||||
if ($httpProtocol !== 'https') {
|
||||
$host .= ":{$this->port()}";
|
||||
}
|
||||
|
||||
return "{$subdomain}.{$host}";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ class ControlConnection
|
||||
$this->proxyManager->createTcpProxy($this->clientId, $data);
|
||||
}
|
||||
|
||||
public function authenticate(string $sharedHost, ?string $subdomain, ?string $hostname)
|
||||
public function authenticate(string $sharedHost, string $subdomain)
|
||||
{
|
||||
$this->socket->send(json_encode([
|
||||
'event' => 'authenticate',
|
||||
@@ -65,7 +65,6 @@ class ControlConnection
|
||||
'type' => 'http',
|
||||
'host' => $sharedHost,
|
||||
'subdomain' => empty($subdomain) ? null : $subdomain,
|
||||
'hostname' => empty($hostname) ? null : $hostname,
|
||||
],
|
||||
]));
|
||||
}
|
||||
|
||||
@@ -102,9 +102,9 @@ class Factory
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function share($sharedUrl, $subdomain = null, $hostname = null)
|
||||
public function share($sharedUrl, $subdomain = null)
|
||||
{
|
||||
app('expose.client')->share($sharedUrl, $subdomain, $hostname);
|
||||
app('expose.client')->share($sharedUrl, $subdomain);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace App\Client\Http;
|
||||
|
||||
use App\Client\Configuration;
|
||||
use App\Client\Http\Modifiers\CheckBasicAuthentication;
|
||||
use App\Logger\RequestLogger;
|
||||
use Clue\React\Buzz\Browser;
|
||||
@@ -27,26 +26,19 @@ class HttpClient
|
||||
/** @var Request */
|
||||
protected $request;
|
||||
|
||||
protected $connectionData;
|
||||
|
||||
/** @var array */
|
||||
protected $modifiers = [
|
||||
CheckBasicAuthentication::class,
|
||||
];
|
||||
/** @var Configuration */
|
||||
protected $configuration;
|
||||
|
||||
public function __construct(LoopInterface $loop, RequestLogger $logger, Configuration $configuration)
|
||||
public function __construct(LoopInterface $loop, RequestLogger $logger)
|
||||
{
|
||||
$this->loop = $loop;
|
||||
$this->logger = $logger;
|
||||
$this->configuration = $configuration;
|
||||
}
|
||||
|
||||
public function performRequest(string $requestData, WebSocket $proxyConnection = null, $connectionData = null)
|
||||
public function performRequest(string $requestData, WebSocket $proxyConnection = null, string $requestId = null)
|
||||
{
|
||||
$this->connectionData = $connectionData;
|
||||
|
||||
$this->request = $this->parseRequest($requestData);
|
||||
|
||||
$this->logger->logRequest($requestData, $this->request);
|
||||
@@ -93,8 +85,6 @@ class HttpClient
|
||||
->send($request)
|
||||
->then(function (ResponseInterface $response) use ($proxyConnection) {
|
||||
if (! isset($response->buffer)) {
|
||||
$response = $this->rewriteResponseHeaders($response);
|
||||
|
||||
$response->buffer = str($response);
|
||||
}
|
||||
|
||||
@@ -136,25 +126,4 @@ class HttpClient
|
||||
{
|
||||
return Request::fromString($data);
|
||||
}
|
||||
|
||||
protected function rewriteResponseHeaders(ResponseInterface $response)
|
||||
{
|
||||
if (! $response->hasHeader('Location')) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
$location = $response->getHeaderLine('Location');
|
||||
|
||||
if (! strstr($location, $this->connectionData->host)) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
$location = str_replace(
|
||||
$this->connectionData->host,
|
||||
$this->configuration->getUrl($this->connectionData->subdomain),
|
||||
$location
|
||||
);
|
||||
|
||||
return $response->withHeader('Location', $location);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ class ProxyManager
|
||||
], $this->loop)
|
||||
->then(function (WebSocket $proxyConnection) use ($clientId, $connectionData) {
|
||||
$proxyConnection->on('message', function ($message) use ($proxyConnection, $connectionData) {
|
||||
$this->performRequest($proxyConnection, (string) $message, $connectionData);
|
||||
$this->performRequest($proxyConnection, $connectionData->request_id, (string) $message);
|
||||
});
|
||||
|
||||
$proxyConnection->send(json_encode([
|
||||
@@ -76,8 +76,8 @@ class ProxyManager
|
||||
});
|
||||
}
|
||||
|
||||
protected function performRequest(WebSocket $proxyConnection, string $requestData, $connectionData)
|
||||
protected function performRequest(WebSocket $proxyConnection, $requestId, string $requestData)
|
||||
{
|
||||
app(HttpClient::class)->performRequest((string) $requestData, $proxyConnection, $connectionData);
|
||||
app(HttpClient::class)->performRequest((string) $requestData, $proxyConnection, $requestId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ use Symfony\Component\Console\Output\ConsoleOutput;
|
||||
|
||||
class ShareCommand extends Command
|
||||
{
|
||||
protected $signature = 'share {host} {--hostname=} {--subdomain=} {--auth=}';
|
||||
protected $signature = 'share {host} {--subdomain=} {--auth=}';
|
||||
|
||||
protected $description = 'Share a local url with a remote expose server';
|
||||
|
||||
@@ -25,12 +25,6 @@ class ShareCommand extends Command
|
||||
|
||||
public function handle()
|
||||
{
|
||||
if (! empty($this->option('hostname')) && ! empty($this->option('subdomain'))) {
|
||||
$this->error('You can only specify one. Either a custom hostname or a subdomain.');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->configureConnectionLogger();
|
||||
|
||||
(new Factory())
|
||||
@@ -39,11 +33,7 @@ class ShareCommand extends Command
|
||||
->setPort(config('expose.port', 8080))
|
||||
->setAuth($this->option('auth'))
|
||||
->createClient()
|
||||
->share(
|
||||
$this->argument('host'),
|
||||
explode(',', $this->option('subdomain')),
|
||||
$this->option('hostname')
|
||||
)
|
||||
->share($this->argument('host'), explode(',', $this->option('subdomain')))
|
||||
->createHttpServer()
|
||||
->run();
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ namespace App\Commands;
|
||||
|
||||
class ShareCurrentWorkingDirectoryCommand extends ShareCommand
|
||||
{
|
||||
protected $signature = 'share-cwd {host?} {--hostname=} {--subdomain=} {--auth=}';
|
||||
protected $signature = 'share-cwd {host?} {--subdomain=} {--auth=}';
|
||||
|
||||
public function handle()
|
||||
{
|
||||
@@ -13,7 +13,7 @@ class ShareCurrentWorkingDirectoryCommand extends ShareCommand
|
||||
|
||||
$this->input->setArgument('host', $host);
|
||||
|
||||
if (! $this->option('subdomain') && ! $this->option('hostname')) {
|
||||
if (! $this->option('subdomain')) {
|
||||
$this->input->setOption('subdomain', $subdomain);
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ use Ratchet\ConnectionInterface;
|
||||
|
||||
interface ConnectionManager
|
||||
{
|
||||
public function storeConnection(string $host, ?string $subdomain, ?string $hostname, ConnectionInterface $connection): ControlConnection;
|
||||
public function storeConnection(string $host, ?string $subdomain, ConnectionInterface $connection): ControlConnection;
|
||||
|
||||
public function storeTcpConnection(int $port, ConnectionInterface $connection): ControlConnection;
|
||||
|
||||
@@ -22,8 +22,6 @@ interface ConnectionManager
|
||||
|
||||
public function findControlConnectionForSubdomain($subdomain): ?ControlConnection;
|
||||
|
||||
public function findControlConnectionForHostname(string $hostname): ?ControlConnection;
|
||||
|
||||
public function findControlConnectionForClientId(string $clientId): ?ControlConnection;
|
||||
|
||||
public function getConnections(): array;
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Contracts;
|
||||
|
||||
use React\Promise\PromiseInterface;
|
||||
|
||||
interface HostnameRepository
|
||||
{
|
||||
public function getHostnames(): PromiseInterface;
|
||||
|
||||
public function getHostnameById($id): PromiseInterface;
|
||||
|
||||
public function getHostnameByName(string $name): PromiseInterface;
|
||||
|
||||
public function getHostnamesByUserId($id): PromiseInterface;
|
||||
|
||||
public function getHostnamesByUserIdAndName($id, $name): PromiseInterface;
|
||||
|
||||
public function deleteHostnameForUserId($userId, $hostnameId): PromiseInterface;
|
||||
|
||||
public function storeHostname(array $data): PromiseInterface;
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Contracts;
|
||||
|
||||
use React\Promise\PromiseInterface;
|
||||
|
||||
interface SubdomainRepository
|
||||
{
|
||||
public function getSubdomains(): PromiseInterface;
|
||||
|
||||
public function getSubdomainById($id): PromiseInterface;
|
||||
|
||||
public function getSubdomainByName(string $name): PromiseInterface;
|
||||
|
||||
public function getSubdomainsByUserId($id): PromiseInterface;
|
||||
|
||||
public function getSubdomainsByUserIdAndName($id, $name): PromiseInterface;
|
||||
|
||||
public function deleteSubdomainForUserId($userId, $subdomainId): PromiseInterface;
|
||||
|
||||
public function storeSubdomain(array $data): PromiseInterface;
|
||||
}
|
||||
@@ -19,8 +19,11 @@ class LoggedRequest implements \JsonSerializable
|
||||
/** @var Request */
|
||||
protected $parsedRequest;
|
||||
|
||||
/** @var LoggedResponse */
|
||||
protected $response;
|
||||
/** @var string */
|
||||
protected $rawResponse;
|
||||
|
||||
/** @var Response */
|
||||
protected $parsedResponse;
|
||||
|
||||
/** @var string */
|
||||
protected $id;
|
||||
@@ -68,8 +71,22 @@ class LoggedRequest implements \JsonSerializable
|
||||
],
|
||||
];
|
||||
|
||||
if ($this->response) {
|
||||
$data['response'] = $this->response->toArray();
|
||||
if ($this->parsedResponse) {
|
||||
$logBody = $this->shouldReturnBody();
|
||||
|
||||
try {
|
||||
$body = $logBody ? $this->parsedResponse->getBody() : '';
|
||||
} catch (\Exception $e) {
|
||||
$body = '';
|
||||
}
|
||||
|
||||
$data['response'] = [
|
||||
'raw' => $logBody ? $this->rawResponse : 'SKIPPED BY CONFIG OR BINARY RESPONSE',
|
||||
'status' => $this->parsedResponse->getStatusCode(),
|
||||
'headers' => $this->parsedResponse->getHeaders()->toArray(),
|
||||
'reason' => $this->parsedResponse->getReasonPhrase(),
|
||||
'body' => $logBody ? $body : 'SKIPPED BY CONFIG OR BINARY RESPONSE',
|
||||
];
|
||||
}
|
||||
|
||||
return $data;
|
||||
@@ -90,6 +107,96 @@ class LoggedRequest implements \JsonSerializable
|
||||
return preg_match('~[^\x20-\x7E\t\r\n]~', $string) > 0;
|
||||
}
|
||||
|
||||
protected function shouldReturnBody(): bool
|
||||
{
|
||||
if ($this->skipByStatus()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($this->skipByContentType()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($this->skipByExtension()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($this->skipBySize()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$header = $this->parsedResponse->getHeaders()->get('Content-Type');
|
||||
$contentType = $header ? $header->getMediaType() : '';
|
||||
$patterns = [
|
||||
'application/json',
|
||||
'text/*',
|
||||
'*javascript*',
|
||||
];
|
||||
|
||||
return Str::is($patterns, $contentType);
|
||||
}
|
||||
|
||||
protected function skipByStatus(): bool
|
||||
{
|
||||
if (empty(config()->get('expose.skip_body_log.status'))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return Str::is(config()->get('expose.skip_body_log.status'), $this->parsedResponse->getStatusCode());
|
||||
}
|
||||
|
||||
protected function skipByContentType(): bool
|
||||
{
|
||||
if (empty(config()->get('expose.skip_body_log.content_type'))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$header = $this->parsedResponse->getHeaders()->get('Content-Type');
|
||||
$contentType = $header ? $header->getMediaType() : '';
|
||||
|
||||
return Str::is(config()->get('expose.skip_body_log.content_type'), $contentType);
|
||||
}
|
||||
|
||||
protected function skipByExtension(): bool
|
||||
{
|
||||
if (empty(config()->get('expose.skip_body_log.extension'))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return Str::is(config()->get('expose.skip_body_log.extension'), $this->parsedRequest->getUri()->getPath());
|
||||
}
|
||||
|
||||
protected function skipBySize(): bool
|
||||
{
|
||||
$configSize = $this->getConfigSize(config()->get('expose.skip_body_log.size', '1MB'));
|
||||
$contentLength = $this->parsedResponse->getHeaders()->get('Content-Length');
|
||||
|
||||
if (! $contentLength) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$contentSize = $contentLength->getFieldValue() ?? 0;
|
||||
|
||||
return $contentSize > $configSize;
|
||||
}
|
||||
|
||||
protected function getConfigSize(string $size): int
|
||||
{
|
||||
$units = ['B', 'KB', 'MB', 'GB'];
|
||||
$number = substr($size, 0, -2);
|
||||
$suffix = strtoupper(substr($size, -2));
|
||||
|
||||
// B or no suffix
|
||||
if (is_numeric(substr($suffix, 0, 1))) {
|
||||
return preg_replace('/[^\d]/', '', $size);
|
||||
}
|
||||
|
||||
// if we have an error in the input, default to GB
|
||||
$exponent = array_flip($units)[$suffix] ?? 5;
|
||||
|
||||
return $number * (1024 ** $exponent);
|
||||
}
|
||||
|
||||
public function getRequest()
|
||||
{
|
||||
return $this->parsedRequest;
|
||||
@@ -97,7 +204,9 @@ class LoggedRequest implements \JsonSerializable
|
||||
|
||||
public function setResponse(string $rawResponse, Response $response)
|
||||
{
|
||||
$this->response = new LoggedResponse($rawResponse, $response, $this->getRequest());
|
||||
$this->parsedResponse = $response;
|
||||
|
||||
$this->rawResponse = $rawResponse;
|
||||
|
||||
if (is_null($this->stopTime)) {
|
||||
$this->stopTime = now();
|
||||
@@ -114,9 +223,9 @@ class LoggedRequest implements \JsonSerializable
|
||||
return $this->rawRequest;
|
||||
}
|
||||
|
||||
public function getResponse(): ?LoggedResponse
|
||||
public function getResponse(): ?Response
|
||||
{
|
||||
return $this->response;
|
||||
return $this->parsedResponse;
|
||||
}
|
||||
|
||||
public function getPostData()
|
||||
|
||||
@@ -1,160 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Logger;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
use Laminas\Http\Request;
|
||||
use Laminas\Http\Response;
|
||||
|
||||
class LoggedResponse
|
||||
{
|
||||
/** @var string */
|
||||
protected $rawResponse;
|
||||
|
||||
/** @var Response */
|
||||
protected $response;
|
||||
|
||||
/** @var Request */
|
||||
protected $request;
|
||||
|
||||
protected $reasonPhrase;
|
||||
protected $body;
|
||||
protected $statusCode;
|
||||
protected $headers;
|
||||
|
||||
public function __construct(string $rawResponse, Response $response, Request $request)
|
||||
{
|
||||
$this->rawResponse = $rawResponse;
|
||||
$this->response = $response;
|
||||
$this->request = $request;
|
||||
|
||||
if (! $this->shouldReturnBody()) {
|
||||
$this->rawResponse = 'SKIPPED BY CONFIG OR BINARY RESPONSE';
|
||||
$this->body = 'SKIPPED BY CONFIG OR BINARY RESPONSE';
|
||||
} else {
|
||||
try {
|
||||
$this->body = $response->getBody();
|
||||
} catch (\Exception $e) {
|
||||
$this->body = '';
|
||||
}
|
||||
}
|
||||
|
||||
$this->statusCode = $response->getStatusCode();
|
||||
$this->reasonPhrase = $response->getReasonPhrase();
|
||||
$this->headers = $response->getHeaders()->toArray();
|
||||
|
||||
$this->response = null;
|
||||
$this->request = null;
|
||||
}
|
||||
|
||||
protected function shouldReturnBody(): bool
|
||||
{
|
||||
if ($this->skipByStatus()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($this->skipByContentType()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($this->skipByExtension()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($this->skipBySize()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$header = $this->response->getHeaders()->get('Content-Type');
|
||||
$contentType = $header ? $header->getMediaType() : '';
|
||||
$patterns = [
|
||||
'application/json',
|
||||
'text/*',
|
||||
'*javascript*',
|
||||
];
|
||||
|
||||
return Str::is($patterns, $contentType);
|
||||
}
|
||||
|
||||
protected function skipByStatus(): bool
|
||||
{
|
||||
if (empty(config()->get('expose.skip_body_log.status'))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return Str::is(config()->get('expose.skip_body_log.status'), $this->response->getStatusCode());
|
||||
}
|
||||
|
||||
protected function skipByContentType(): bool
|
||||
{
|
||||
if (empty(config()->get('expose.skip_body_log.content_type'))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$header = $this->response->getHeaders()->get('Content-Type');
|
||||
$contentType = $header ? $header->getMediaType() : '';
|
||||
|
||||
return Str::is(config()->get('expose.skip_body_log.content_type'), $contentType);
|
||||
}
|
||||
|
||||
protected function skipByExtension(): bool
|
||||
{
|
||||
if (empty(config()->get('expose.skip_body_log.extension'))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return Str::is(config()->get('expose.skip_body_log.extension'), $this->request->getUri()->getPath());
|
||||
}
|
||||
|
||||
protected function skipBySize(): bool
|
||||
{
|
||||
$configSize = $this->getConfigSize(config()->get('expose.skip_body_log.size', '1MB'));
|
||||
$contentLength = $this->response->getHeaders()->get('Content-Length');
|
||||
|
||||
if (! $contentLength) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$contentSize = $contentLength->getFieldValue() ?? 0;
|
||||
|
||||
return $contentSize > $configSize;
|
||||
}
|
||||
|
||||
protected function getConfigSize(string $size): int
|
||||
{
|
||||
$units = ['B', 'KB', 'MB', 'GB'];
|
||||
$number = substr($size, 0, -2);
|
||||
$suffix = strtoupper(substr($size, -2));
|
||||
|
||||
// B or no suffix
|
||||
if (is_numeric(substr($suffix, 0, 1))) {
|
||||
return preg_replace('/[^\d]/', '', $size);
|
||||
}
|
||||
|
||||
// if we have an error in the input, default to GB
|
||||
$exponent = array_flip($units)[$suffix] ?? 5;
|
||||
|
||||
return $number * (1024 ** $exponent);
|
||||
}
|
||||
|
||||
public function getStatusCode()
|
||||
{
|
||||
return $this->statusCode;
|
||||
}
|
||||
|
||||
public function getReasonPhrase()
|
||||
{
|
||||
return $this->reasonPhrase;
|
||||
}
|
||||
|
||||
public function toArray()
|
||||
{
|
||||
return [
|
||||
'raw' => $this->rawResponse,
|
||||
'status' => $this->statusCode,
|
||||
'headers' => $this->headers,
|
||||
'reason' => $this->reasonPhrase,
|
||||
'body' => $this->body,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Server\Connections;
|
||||
|
||||
class ConnectionConfiguration
|
||||
{
|
||||
protected $hostname;
|
||||
protected $subdomain;
|
||||
|
||||
private function __construct($subdomain, $hostname)
|
||||
{
|
||||
$this->subdomain = $subdomain;
|
||||
$this->hostname = $hostname;
|
||||
}
|
||||
|
||||
public static function withSubdomain($subdomain)
|
||||
{
|
||||
return new static($subdomain, null);
|
||||
}
|
||||
|
||||
public static function withHostname($hostname)
|
||||
{
|
||||
return new static(null, $hostname);
|
||||
}
|
||||
|
||||
public function getSubdomain()
|
||||
{
|
||||
return $this->subdomain;
|
||||
}
|
||||
|
||||
public function getHostname()
|
||||
{
|
||||
return $this->hostname;
|
||||
}
|
||||
}
|
||||
@@ -43,23 +43,16 @@ class ConnectionManager implements ConnectionManagerContract
|
||||
});
|
||||
}
|
||||
|
||||
public function storeConnection(string $host, ?string $subdomain, ?string $hostname, ConnectionInterface $connection): ControlConnection
|
||||
public function storeConnection(string $host, ?string $subdomain, ConnectionInterface $connection): ControlConnection
|
||||
{
|
||||
$clientId = (string) uniqid();
|
||||
|
||||
$connection->client_id = $clientId;
|
||||
|
||||
if (! is_null($hostname) && $hostname !== '') {
|
||||
$subdomain = '';
|
||||
} else {
|
||||
$subdomain = $subdomain ?? $this->subdomainGenerator->generateSubdomain();
|
||||
}
|
||||
|
||||
$storedConnection = new ControlConnection(
|
||||
$connection,
|
||||
$host,
|
||||
$subdomain,
|
||||
$hostname,
|
||||
$subdomain ?? $this->subdomainGenerator->generateSubdomain(),
|
||||
$clientId,
|
||||
$this->getAuthTokenFromConnection($connection)
|
||||
);
|
||||
@@ -157,13 +150,6 @@ class ConnectionManager implements ConnectionManagerContract
|
||||
});
|
||||
}
|
||||
|
||||
public function findControlConnectionForHostname($hostname): ?ControlConnection
|
||||
{
|
||||
return collect($this->connections)->last(function ($connection) use ($hostname) {
|
||||
return $connection->hostname == $hostname;
|
||||
});
|
||||
}
|
||||
|
||||
public function findControlConnectionForClientId(string $clientId): ?ControlConnection
|
||||
{
|
||||
return collect($this->connections)->last(function ($connection) use ($clientId) {
|
||||
|
||||
@@ -14,17 +14,15 @@ class ControlConnection
|
||||
public $host;
|
||||
public $authToken;
|
||||
public $subdomain;
|
||||
public $hostname;
|
||||
public $client_id;
|
||||
public $proxies = [];
|
||||
protected $shared_at;
|
||||
|
||||
public function __construct(ConnectionInterface $socket, string $host, string $subdomain, ?string $hostname, string $clientId, string $authToken = '')
|
||||
public function __construct(ConnectionInterface $socket, string $host, string $subdomain, string $clientId, string $authToken = '')
|
||||
{
|
||||
$this->socket = $socket;
|
||||
$this->host = $host;
|
||||
$this->subdomain = $subdomain;
|
||||
$this->hostname = $hostname;
|
||||
$this->client_id = $clientId;
|
||||
$this->authToken = $authToken;
|
||||
$this->shared_at = now()->toDateTimeString();
|
||||
@@ -45,8 +43,6 @@ class ControlConnection
|
||||
$this->socket->send(json_encode([
|
||||
'event' => 'createProxy',
|
||||
'data' => [
|
||||
'host' => $this->host,
|
||||
'subdomain' => $this->subdomain,
|
||||
'request_id' => $requestId,
|
||||
'client_id' => $this->client_id,
|
||||
],
|
||||
@@ -66,7 +62,6 @@ class ControlConnection
|
||||
'client_id' => $this->client_id,
|
||||
'auth_token' => $this->authToken,
|
||||
'subdomain' => $this->subdomain,
|
||||
'hostname' => $this->hostname,
|
||||
'shared_at' => $this->shared_at,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -3,15 +3,11 @@
|
||||
namespace App\Server;
|
||||
|
||||
use App\Contracts\ConnectionManager as ConnectionManagerContract;
|
||||
use App\Contracts\HostnameRepository;
|
||||
use App\Contracts\SubdomainGenerator;
|
||||
use App\Contracts\SubdomainRepository;
|
||||
use App\Contracts\UserRepository;
|
||||
use App\Http\RouteGenerator;
|
||||
use App\Http\Server as HttpServer;
|
||||
use App\Server\Connections\ConnectionManager;
|
||||
use App\Server\Http\Controllers\Admin\DeleteHostnameController;
|
||||
use App\Server\Http\Controllers\Admin\DeleteSubdomainController;
|
||||
use App\Server\Http\Controllers\Admin\DeleteUsersController;
|
||||
use App\Server\Http\Controllers\Admin\DisconnectSiteController;
|
||||
use App\Server\Http\Controllers\Admin\DisconnectTcpConnectionController;
|
||||
@@ -25,9 +21,7 @@ use App\Server\Http\Controllers\Admin\ListTcpConnectionsController;
|
||||
use App\Server\Http\Controllers\Admin\ListUsersController;
|
||||
use App\Server\Http\Controllers\Admin\RedirectToUsersController;
|
||||
use App\Server\Http\Controllers\Admin\ShowSettingsController;
|
||||
use App\Server\Http\Controllers\Admin\StoreHostnameController;
|
||||
use App\Server\Http\Controllers\Admin\StoreSettingsController;
|
||||
use App\Server\Http\Controllers\Admin\StoreSubdomainController;
|
||||
use App\Server\Http\Controllers\Admin\StoreUsersController;
|
||||
use App\Server\Http\Controllers\ControlMessageController;
|
||||
use App\Server\Http\Controllers\TunnelMessageController;
|
||||
@@ -136,10 +130,6 @@ class Factory
|
||||
$this->router->get('/api/users', GetUsersController::class, $adminCondition);
|
||||
$this->router->post('/api/users', StoreUsersController::class, $adminCondition);
|
||||
$this->router->get('/api/users/{id}', GetUserDetailsController::class, $adminCondition);
|
||||
$this->router->post('/api/subdomains', StoreSubdomainController::class, $adminCondition);
|
||||
$this->router->delete('/api/subdomains/{subdomain}', DeleteSubdomainController::class, $adminCondition);
|
||||
$this->router->post('/api/hostnames', StoreHostnameController::class, $adminCondition);
|
||||
$this->router->delete('/api/hostnames/{hostname}', DeleteHostnameController::class, $adminCondition);
|
||||
$this->router->delete('/api/users/{id}', DeleteUsersController::class, $adminCondition);
|
||||
$this->router->get('/api/sites', GetSitesController::class, $adminCondition);
|
||||
$this->router->delete('/api/sites/{id}', DisconnectSiteController::class, $adminCondition);
|
||||
@@ -181,8 +171,6 @@ class Factory
|
||||
$this->bindConfiguration()
|
||||
->bindSubdomainGenerator()
|
||||
->bindUserRepository()
|
||||
->bindSubdomainRepository()
|
||||
->bindHostnameRepository()
|
||||
->bindDatabase()
|
||||
->ensureDatabaseIsInitialized()
|
||||
->bindConnectionManager()
|
||||
@@ -219,24 +207,6 @@ class Factory
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function bindSubdomainRepository()
|
||||
{
|
||||
app()->singleton(SubdomainRepository::class, function () {
|
||||
return app(config('expose.admin.subdomain_repository'));
|
||||
});
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function bindHostnameRepository()
|
||||
{
|
||||
app()->singleton(HostnameRepository::class, function () {
|
||||
return app(config('expose.admin.hostname_repository'));
|
||||
});
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function bindDatabase()
|
||||
{
|
||||
app()->singleton(DatabaseInterface::class, function () {
|
||||
@@ -263,7 +233,6 @@ class Factory
|
||||
->files()
|
||||
->ignoreDotFiles(true)
|
||||
->in(database_path('migrations'))
|
||||
->sortByName()
|
||||
->name('*.sql');
|
||||
|
||||
/** @var SplFileInfo $migration */
|
||||
|
||||
@@ -1,132 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Server\HostnameRepository;
|
||||
|
||||
use App\Contracts\HostnameRepository;
|
||||
use Clue\React\SQLite\DatabaseInterface;
|
||||
use Clue\React\SQLite\Result;
|
||||
use React\Promise\Deferred;
|
||||
use React\Promise\PromiseInterface;
|
||||
|
||||
class DatabaseHostnameRepository implements HostnameRepository
|
||||
{
|
||||
/** @var DatabaseInterface */
|
||||
protected $database;
|
||||
|
||||
public function __construct(DatabaseInterface $database)
|
||||
{
|
||||
$this->database = $database;
|
||||
}
|
||||
|
||||
public function getHostnames(): PromiseInterface
|
||||
{
|
||||
$deferred = new Deferred();
|
||||
|
||||
$this->database
|
||||
->query('SELECT * FROM hostnames ORDER by created_at DESC')
|
||||
->then(function (Result $result) use ($deferred) {
|
||||
$deferred->resolve($result->rows);
|
||||
});
|
||||
|
||||
return $deferred->promise();
|
||||
}
|
||||
|
||||
public function getHostnameById($id): PromiseInterface
|
||||
{
|
||||
$deferred = new Deferred();
|
||||
|
||||
$this->database
|
||||
->query('SELECT * FROM hostnames WHERE id = :id', ['id' => $id])
|
||||
->then(function (Result $result) use ($deferred) {
|
||||
$deferred->resolve($result->rows[0] ?? null);
|
||||
});
|
||||
|
||||
return $deferred->promise();
|
||||
}
|
||||
|
||||
public function getHostnameByName(string $name): PromiseInterface
|
||||
{
|
||||
$deferred = new Deferred();
|
||||
|
||||
$this->database
|
||||
->query('SELECT * FROM hostnames WHERE hostname = :name', ['name' => $name])
|
||||
->then(function (Result $result) use ($deferred) {
|
||||
$deferred->resolve($result->rows[0] ?? null);
|
||||
});
|
||||
|
||||
return $deferred->promise();
|
||||
}
|
||||
|
||||
public function getHostnamesByUserId($id): PromiseInterface
|
||||
{
|
||||
$deferred = new Deferred();
|
||||
|
||||
$this->database
|
||||
->query('SELECT * FROM hostnames WHERE user_id = :user_id ORDER by created_at DESC', [
|
||||
'user_id' => $id,
|
||||
])
|
||||
->then(function (Result $result) use ($deferred) {
|
||||
$deferred->resolve($result->rows);
|
||||
});
|
||||
|
||||
return $deferred->promise();
|
||||
}
|
||||
|
||||
public function storeHostname(array $data): PromiseInterface
|
||||
{
|
||||
$deferred = new Deferred();
|
||||
|
||||
$this->getHostnameByName($data['hostname'])
|
||||
->then(function ($registeredHostname) use ($data, $deferred) {
|
||||
if (! is_null($registeredHostname)) {
|
||||
$deferred->resolve(null);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->database->query("
|
||||
INSERT INTO hostnames (user_id, hostname, created_at)
|
||||
VALUES (:user_id, :hostname, DATETIME('now'))
|
||||
", $data)
|
||||
->then(function (Result $result) use ($deferred) {
|
||||
$this->database->query('SELECT * FROM hostnames WHERE id = :id', ['id' => $result->insertId])
|
||||
->then(function (Result $result) use ($deferred) {
|
||||
$deferred->resolve($result->rows[0]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
return $deferred->promise();
|
||||
}
|
||||
|
||||
public function getHostnamesByUserIdAndName($id, $name): PromiseInterface
|
||||
{
|
||||
$deferred = new Deferred();
|
||||
|
||||
$this->database
|
||||
->query('SELECT * FROM hostnames WHERE user_id = :user_id AND hostname = :name ORDER by created_at DESC', [
|
||||
'user_id' => $id,
|
||||
'name' => $name,
|
||||
])
|
||||
->then(function (Result $result) use ($deferred) {
|
||||
$deferred->resolve($result->rows);
|
||||
});
|
||||
|
||||
return $deferred->promise();
|
||||
}
|
||||
|
||||
public function deleteHostnameForUserId($userId, $hostnameId): PromiseInterface
|
||||
{
|
||||
$deferred = new Deferred();
|
||||
|
||||
$this->database->query('DELETE FROM hostnames WHERE id = :id AND user_id = :user_id', [
|
||||
'id' => $hostnameId,
|
||||
'user_id' => $userId,
|
||||
])
|
||||
->then(function (Result $result) use ($deferred) {
|
||||
$deferred->resolve($result);
|
||||
});
|
||||
|
||||
return $deferred->promise();
|
||||
}
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Server\Http\Controllers\Admin;
|
||||
|
||||
use App\Contracts\HostnameRepository;
|
||||
use App\Contracts\UserRepository;
|
||||
use Illuminate\Http\Request;
|
||||
use Ratchet\ConnectionInterface;
|
||||
|
||||
class DeleteHostnameController extends AdminController
|
||||
{
|
||||
protected $keepConnectionOpen = true;
|
||||
|
||||
/** @var HostnameRepository */
|
||||
protected $hostnameRepository;
|
||||
|
||||
/** @var UserRepository */
|
||||
protected $userRepository;
|
||||
|
||||
public function __construct(UserRepository $userRepository, HostnameRepository $hostnameRepository)
|
||||
{
|
||||
$this->userRepository = $userRepository;
|
||||
$this->hostnameRepository = $hostnameRepository;
|
||||
}
|
||||
|
||||
public function handle(Request $request, ConnectionInterface $httpConnection)
|
||||
{
|
||||
$this->userRepository->getUserByToken($request->get('auth_token', ''))
|
||||
->then(function ($user) use ($request, $httpConnection) {
|
||||
if (is_null($user)) {
|
||||
$httpConnection->send(respond_json(['error' => 'The user does not exist'], 404));
|
||||
$httpConnection->close();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->hostnameRepository->deleteHostnameForUserId($user['id'], $request->get('hostname'))
|
||||
->then(function ($deleted) use ($httpConnection) {
|
||||
$httpConnection->send(respond_json(['deleted' => $deleted], 200));
|
||||
$httpConnection->close();
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Server\Http\Controllers\Admin;
|
||||
|
||||
use App\Contracts\SubdomainRepository;
|
||||
use App\Contracts\UserRepository;
|
||||
use Illuminate\Http\Request;
|
||||
use Ratchet\ConnectionInterface;
|
||||
|
||||
class DeleteSubdomainController extends AdminController
|
||||
{
|
||||
protected $keepConnectionOpen = true;
|
||||
|
||||
/** @var SubdomainRepository */
|
||||
protected $subdomainRepository;
|
||||
|
||||
/** @var UserRepository */
|
||||
protected $userRepository;
|
||||
|
||||
public function __construct(UserRepository $userRepository, SubdomainRepository $subdomainRepository)
|
||||
{
|
||||
$this->userRepository = $userRepository;
|
||||
$this->subdomainRepository = $subdomainRepository;
|
||||
}
|
||||
|
||||
public function handle(Request $request, ConnectionInterface $httpConnection)
|
||||
{
|
||||
$this->userRepository->getUserByToken($request->get('auth_token', ''))
|
||||
->then(function ($user) use ($request, $httpConnection) {
|
||||
if (is_null($user)) {
|
||||
$httpConnection->send(respond_json(['error' => 'The user does not exist'], 404));
|
||||
$httpConnection->close();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->subdomainRepository->deleteSubdomainForUserId($user['id'], $request->get('subdomain'))
|
||||
->then(function ($deleted) use ($httpConnection) {
|
||||
$httpConnection->send(respond_json(['deleted' => $deleted], 200));
|
||||
$httpConnection->close();
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -2,8 +2,6 @@
|
||||
|
||||
namespace App\Server\Http\Controllers\Admin;
|
||||
|
||||
use App\Contracts\HostnameRepository;
|
||||
use App\Contracts\SubdomainRepository;
|
||||
use App\Contracts\UserRepository;
|
||||
use Illuminate\Http\Request;
|
||||
use Ratchet\ConnectionInterface;
|
||||
@@ -15,39 +13,21 @@ class GetUserDetailsController extends AdminController
|
||||
/** @var UserRepository */
|
||||
protected $userRepository;
|
||||
|
||||
/** @var SubdomainRepository */
|
||||
protected $subdomainRepository;
|
||||
|
||||
/** @var HostnameRepository */
|
||||
protected $hostnameRepository;
|
||||
|
||||
public function __construct(UserRepository $userRepository, SubdomainRepository $subdomainRepository, HostnameRepository $hostnameRepository)
|
||||
public function __construct(UserRepository $userRepository)
|
||||
{
|
||||
$this->userRepository = $userRepository;
|
||||
$this->subdomainRepository = $subdomainRepository;
|
||||
$this->hostnameRepository = $hostnameRepository;
|
||||
}
|
||||
|
||||
public function handle(Request $request, ConnectionInterface $httpConnection)
|
||||
{
|
||||
$this->userRepository
|
||||
->getUserById($request->get('id'))
|
||||
->then(function ($user) use ($httpConnection, $request) {
|
||||
$this->subdomainRepository->getSubdomainsByUserId($request->get('id'))
|
||||
->then(function ($subdomains) use ($httpConnection, $user, $request) {
|
||||
$this->hostnameRepository->getHostnamesByUserId($request->get('id'))
|
||||
->then(function ($hostnames) use ($httpConnection, $user, $subdomains) {
|
||||
$httpConnection->send(
|
||||
respond_json([
|
||||
'user' => $user,
|
||||
'subdomains' => $subdomains,
|
||||
'hostnames' => $hostnames,
|
||||
])
|
||||
);
|
||||
->then(function ($user) use ($httpConnection) {
|
||||
$httpConnection->send(
|
||||
respond_json(['user' => $user])
|
||||
);
|
||||
|
||||
$httpConnection->close();
|
||||
});
|
||||
});
|
||||
$httpConnection->close();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,77 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Server\Http\Controllers\Admin;
|
||||
|
||||
use App\Contracts\HostnameRepository;
|
||||
use App\Contracts\UserRepository;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Ratchet\ConnectionInterface;
|
||||
|
||||
class StoreHostnameController extends AdminController
|
||||
{
|
||||
protected $keepConnectionOpen = true;
|
||||
|
||||
/** @var HostnameRepository */
|
||||
protected $hostnameRepository;
|
||||
|
||||
/** @var UserRepository */
|
||||
protected $userRepository;
|
||||
|
||||
public function __construct(UserRepository $userRepository, HostnameRepository $hostnameRepository)
|
||||
{
|
||||
$this->userRepository = $userRepository;
|
||||
$this->hostnameRepository = $hostnameRepository;
|
||||
}
|
||||
|
||||
public function handle(Request $request, ConnectionInterface $httpConnection)
|
||||
{
|
||||
$validator = Validator::make($request->all(), [
|
||||
'hostname' => 'required',
|
||||
], [
|
||||
'required' => 'The :attribute field is required.',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
$httpConnection->send(respond_json(['errors' => $validator->getMessageBag()], 401));
|
||||
$httpConnection->close();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->userRepository->getUserByToken($request->get('auth_token', ''))
|
||||
->then(function ($user) use ($httpConnection, $request) {
|
||||
if (is_null($user)) {
|
||||
$httpConnection->send(respond_json(['error' => 'The user does not exist'], 404));
|
||||
$httpConnection->close();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ($user['can_specify_hostnames'] === 0) {
|
||||
$httpConnection->send(respond_json(['error' => 'The user is not allowed to reserve hostnames.'], 401));
|
||||
$httpConnection->close();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$insertData = [
|
||||
'user_id' => $user['id'],
|
||||
'hostname' => $request->get('hostname'),
|
||||
];
|
||||
|
||||
$this->hostnameRepository
|
||||
->storeHostname($insertData)
|
||||
->then(function ($hostname) use ($httpConnection) {
|
||||
if (is_null($hostname)) {
|
||||
$httpConnection->send(respond_json(['error' => 'The hostname is already taken.'], 422));
|
||||
$httpConnection->close();
|
||||
|
||||
return;
|
||||
}
|
||||
$httpConnection->send(respond_json(['hostname' => $hostname], 200));
|
||||
$httpConnection->close();
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,77 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Server\Http\Controllers\Admin;
|
||||
|
||||
use App\Contracts\SubdomainRepository;
|
||||
use App\Contracts\UserRepository;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Ratchet\ConnectionInterface;
|
||||
|
||||
class StoreSubdomainController extends AdminController
|
||||
{
|
||||
protected $keepConnectionOpen = true;
|
||||
|
||||
/** @var SubdomainRepository */
|
||||
protected $subdomainRepository;
|
||||
|
||||
/** @var UserRepository */
|
||||
protected $userRepository;
|
||||
|
||||
public function __construct(UserRepository $userRepository, SubdomainRepository $subdomainRepository)
|
||||
{
|
||||
$this->userRepository = $userRepository;
|
||||
$this->subdomainRepository = $subdomainRepository;
|
||||
}
|
||||
|
||||
public function handle(Request $request, ConnectionInterface $httpConnection)
|
||||
{
|
||||
$validator = Validator::make($request->all(), [
|
||||
'subdomain' => 'required',
|
||||
], [
|
||||
'required' => 'The :attribute field is required.',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
$httpConnection->send(respond_json(['errors' => $validator->getMessageBag()], 401));
|
||||
$httpConnection->close();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->userRepository->getUserByToken($request->get('auth_token', ''))
|
||||
->then(function ($user) use ($httpConnection, $request) {
|
||||
if (is_null($user)) {
|
||||
$httpConnection->send(respond_json(['error' => 'The user does not exist'], 404));
|
||||
$httpConnection->close();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ($user['can_specify_subdomains'] === 0) {
|
||||
$httpConnection->send(respond_json(['error' => 'The user is not allowed to reserve subdomains.'], 401));
|
||||
$httpConnection->close();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$insertData = [
|
||||
'user_id' => $user['id'],
|
||||
'subdomain' => $request->get('subdomain'),
|
||||
];
|
||||
|
||||
$this->subdomainRepository
|
||||
->storeSubdomain($insertData)
|
||||
->then(function ($subdomain) use ($httpConnection) {
|
||||
if (is_null($subdomain)) {
|
||||
$httpConnection->send(respond_json(['error' => 'The subdomain is already taken.'], 422));
|
||||
$httpConnection->close();
|
||||
|
||||
return;
|
||||
}
|
||||
$httpConnection->send(respond_json(['subdomain' => $subdomain], 200));
|
||||
$httpConnection->close();
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -39,7 +39,6 @@ class StoreUsersController extends AdminController
|
||||
$insertData = [
|
||||
'name' => $request->get('name'),
|
||||
'auth_token' => (string) Str::uuid(),
|
||||
'can_specify_hostnames' => (int) $request->get('can_specify_hostnames'),
|
||||
'can_specify_subdomains' => (int) $request->get('can_specify_subdomains'),
|
||||
'can_share_tcp_ports' => (int) $request->get('can_share_tcp_ports'),
|
||||
];
|
||||
|
||||
@@ -3,19 +3,13 @@
|
||||
namespace App\Server\Http\Controllers;
|
||||
|
||||
use App\Contracts\ConnectionManager;
|
||||
use App\Contracts\HostnameRepository;
|
||||
use App\Contracts\SubdomainRepository;
|
||||
use App\Contracts\UserRepository;
|
||||
use App\Http\QueryParameters;
|
||||
use App\Server\Connections\ConnectionConfiguration;
|
||||
use App\Server\Exceptions\NoFreePortAvailable;
|
||||
use Illuminate\Support\Str;
|
||||
use Ratchet\ConnectionInterface;
|
||||
use Ratchet\WebSocket\MessageComponentInterface;
|
||||
use React\Promise\Deferred;
|
||||
use React\Promise\PromiseInterface;
|
||||
use function React\Promise\reject;
|
||||
use function React\Promise\resolve as resolvePromise;
|
||||
use stdClass;
|
||||
|
||||
class ControlMessageController implements MessageComponentInterface
|
||||
@@ -26,18 +20,10 @@ class ControlMessageController implements MessageComponentInterface
|
||||
/** @var UserRepository */
|
||||
protected $userRepository;
|
||||
|
||||
/** @var SubdomainRepository */
|
||||
protected $subdomainRepository;
|
||||
|
||||
/** @var HostnameRepository */
|
||||
protected $hostnameRepository;
|
||||
|
||||
public function __construct(ConnectionManager $connectionManager, UserRepository $userRepository, SubdomainRepository $subdomainRepository, HostnameRepository $hostnameRepository)
|
||||
public function __construct(ConnectionManager $connectionManager, UserRepository $userRepository)
|
||||
{
|
||||
$this->connectionManager = $connectionManager;
|
||||
$this->userRepository = $userRepository;
|
||||
$this->subdomainRepository = $subdomainRepository;
|
||||
$this->hostnameRepository = $hostnameRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -114,25 +100,22 @@ class ControlMessageController implements MessageComponentInterface
|
||||
|
||||
protected function handleHttpConnection(ConnectionInterface $connection, $data, $user = null)
|
||||
{
|
||||
$this->hasValidConfiguration($connection, $data, $user)
|
||||
->then(function (ConnectionConfiguration $configuration) use ($data, $connection) {
|
||||
$data->subdomain = $configuration->getSubdomain();
|
||||
$data->hostname = $configuration->getHostname();
|
||||
if (! $this->hasValidSubdomain($connection, $data->subdomain, $user)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$connectionInfo = $this->connectionManager->storeConnection($data->host, $data->subdomain, $data->hostname, $connection);
|
||||
$connectionInfo = $this->connectionManager->storeConnection($data->host, $data->subdomain, $connection);
|
||||
|
||||
$this->connectionManager->limitConnectionLength($connectionInfo, config('expose.admin.maximum_connection_length'));
|
||||
$this->connectionManager->limitConnectionLength($connectionInfo, config('expose.admin.maximum_connection_length'));
|
||||
|
||||
$connection->send(json_encode([
|
||||
'event' => 'authenticated',
|
||||
'data' => [
|
||||
'message' => config('expose.admin.messages.message_of_the_day'),
|
||||
'subdomain' => $connectionInfo->subdomain,
|
||||
'hostname' => $connectionInfo->hostname,
|
||||
'client_id' => $connectionInfo->client_id,
|
||||
],
|
||||
]));
|
||||
});
|
||||
$connection->send(json_encode([
|
||||
'event' => 'authenticated',
|
||||
'data' => [
|
||||
'message' => config('expose.admin.messages.message_of_the_day'),
|
||||
'subdomain' => $connectionInfo->subdomain,
|
||||
'client_id' => $connectionInfo->client_id,
|
||||
],
|
||||
]));
|
||||
}
|
||||
|
||||
protected function handleTcpConnection(ConnectionInterface $connection, $data, $user = null)
|
||||
@@ -200,7 +183,7 @@ class ControlMessageController implements MessageComponentInterface
|
||||
protected function verifyAuthToken(ConnectionInterface $connection): PromiseInterface
|
||||
{
|
||||
if (config('expose.admin.validate_auth_tokens') !== true) {
|
||||
return resolvePromise(null);
|
||||
return \React\Promise\resolve(null);
|
||||
}
|
||||
|
||||
$deferred = new Deferred();
|
||||
@@ -220,126 +203,39 @@ class ControlMessageController implements MessageComponentInterface
|
||||
return $deferred->promise();
|
||||
}
|
||||
|
||||
protected function hasValidSubdomain(ConnectionInterface $connection, ?string $subdomain, ?array $user): PromiseInterface
|
||||
protected function hasValidSubdomain(ConnectionInterface $connection, ?string $subdomain, ?array $user): bool
|
||||
{
|
||||
/**
|
||||
* Check if the user can specify a custom subdomain in the first place.
|
||||
*/
|
||||
if (! is_null($user) && $user['can_specify_subdomains'] === 0 && ! is_null($subdomain)) {
|
||||
$connection->send(json_encode([
|
||||
'event' => 'info',
|
||||
'event' => 'subdomainTaken',
|
||||
'data' => [
|
||||
'message' => config('expose.admin.messages.custom_subdomain_unauthorized').PHP_EOL,
|
||||
'message' => config('expose.admin.messages.custom_subdomain_unauthorized'),
|
||||
],
|
||||
]));
|
||||
$connection->close();
|
||||
|
||||
return resolvePromise(ConnectionConfiguration::withSubdomain(null));
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the given subdomain is reserved for a different user.
|
||||
*/
|
||||
if (! is_null($subdomain)) {
|
||||
return $this->subdomainRepository->getSubdomainByName($subdomain)
|
||||
->then(function ($foundSubdomain) use ($connection, $subdomain, $user) {
|
||||
if (! is_null($foundSubdomain) && ! is_null($user) && $foundSubdomain['user_id'] !== $user['id']) {
|
||||
$message = config('expose.admin.messages.subdomain_reserved');
|
||||
$message = str_replace(':subdomain', $subdomain, $message);
|
||||
$controlConnection = $this->connectionManager->findControlConnectionForSubdomain($subdomain);
|
||||
if (! is_null($controlConnection) || $subdomain === config('expose.admin.subdomain')) {
|
||||
$message = config('expose.admin.messages.subdomain_taken');
|
||||
$message = str_replace(':subdomain', $subdomain, $message);
|
||||
|
||||
$connection->send(json_encode([
|
||||
'event' => 'subdomainTaken',
|
||||
'data' => [
|
||||
'message' => $message,
|
||||
],
|
||||
]));
|
||||
$connection->close();
|
||||
$connection->send(json_encode([
|
||||
'event' => 'subdomainTaken',
|
||||
'data' => [
|
||||
'message' => $message,
|
||||
],
|
||||
]));
|
||||
$connection->close();
|
||||
|
||||
return reject(false);
|
||||
}
|
||||
|
||||
$controlConnection = $this->connectionManager->findControlConnectionForSubdomain($subdomain);
|
||||
|
||||
if (! is_null($controlConnection) || $subdomain === config('expose.admin.subdomain')) {
|
||||
$message = config('expose.admin.messages.subdomain_taken');
|
||||
$message = str_replace(':subdomain', $subdomain, $message);
|
||||
|
||||
$connection->send(json_encode([
|
||||
'event' => 'subdomainTaken',
|
||||
'data' => [
|
||||
'message' => $message,
|
||||
],
|
||||
]));
|
||||
$connection->close();
|
||||
|
||||
return reject(false);
|
||||
}
|
||||
|
||||
return resolvePromise(ConnectionConfiguration::withSubdomain($subdomain));
|
||||
});
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return resolvePromise(ConnectionConfiguration::withSubdomain($subdomain));
|
||||
}
|
||||
|
||||
protected function hasValidHostname(ConnectionInterface $connection, string $hostname, ?array $user): PromiseInterface
|
||||
{
|
||||
/**
|
||||
* Check if the user can specify a custom hostname in the first place.
|
||||
*/
|
||||
if (! is_null($user) && $user['can_specify_hostnames'] === 0) {
|
||||
$connection->send(json_encode([
|
||||
'event' => 'info',
|
||||
'data' => [
|
||||
'message' => config('expose.admin.messages.custom_hostname_unauthorized').PHP_EOL,
|
||||
],
|
||||
]));
|
||||
|
||||
return reject();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the given hostname is reserved for a different user.
|
||||
*/
|
||||
return $this->hostnameRepository->getHostnamesByUserId($user['id'])
|
||||
->then(function ($foundHostnames) use ($connection, $hostname) {
|
||||
$foundHostname = collect($foundHostnames)->first(function ($foundHostname) use ($hostname) {
|
||||
return Str::is($foundHostname['hostname'], $hostname);
|
||||
});
|
||||
|
||||
if (is_null($foundHostname)) {
|
||||
$message = config('expose.admin.messages.hostname_invalid');
|
||||
$message = str_replace(':hostname', $hostname, $message);
|
||||
|
||||
$connection->send(json_encode([
|
||||
'event' => 'hostnameTaken',
|
||||
'data' => [
|
||||
'message' => $message,
|
||||
],
|
||||
]));
|
||||
$connection->close();
|
||||
|
||||
return reject(false);
|
||||
}
|
||||
|
||||
$controlConnection = $this->connectionManager->findControlConnectionForHostname($hostname);
|
||||
|
||||
if (! is_null($controlConnection)) {
|
||||
$message = config('expose.admin.messages.hostname_taken');
|
||||
$message = str_replace(':hostname', $hostname, $message);
|
||||
|
||||
$connection->send(json_encode([
|
||||
'event' => 'hostnameTaken',
|
||||
'data' => [
|
||||
'message' => $message,
|
||||
],
|
||||
]));
|
||||
$connection->close();
|
||||
|
||||
return reject(false);
|
||||
}
|
||||
|
||||
return resolvePromise(ConnectionConfiguration::withHostname($hostname));
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function canShareTcpPorts(ConnectionInterface $connection, $data, $user)
|
||||
@@ -358,13 +254,4 @@ class ControlMessageController implements MessageComponentInterface
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function hasValidConfiguration(ConnectionInterface $connection, $data, $user)
|
||||
{
|
||||
if (isset($data->hostname) && ! is_null($data->hostname)) {
|
||||
return $this->hasValidHostname($connection, $data->hostname, $user);
|
||||
}
|
||||
|
||||
return $this->hasValidSubdomain($connection, $data->subdomain, $user);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,9 +36,8 @@ class TunnelMessageController extends Controller
|
||||
public function handle(Request $request, ConnectionInterface $httpConnection)
|
||||
{
|
||||
$subdomain = $this->detectSubdomain($request);
|
||||
$hostname = $request->getHost();
|
||||
|
||||
if (is_null($subdomain) && $hostname === $this->configuration->hostname()) {
|
||||
if (is_null($subdomain)) {
|
||||
$httpConnection->send(
|
||||
respond_html($this->getView($httpConnection, 'server.homepage'), 200)
|
||||
);
|
||||
@@ -47,11 +46,7 @@ class TunnelMessageController extends Controller
|
||||
return;
|
||||
}
|
||||
|
||||
if (! is_null($subdomain)) {
|
||||
$controlConnection = $this->connectionManager->findControlConnectionForSubdomain($subdomain);
|
||||
} else {
|
||||
$controlConnection = $this->connectionManager->findControlConnectionForHostname($hostname);
|
||||
}
|
||||
$controlConnection = $this->connectionManager->findControlConnectionForSubdomain($subdomain);
|
||||
|
||||
if (is_null($controlConnection)) {
|
||||
$httpConnection->send(
|
||||
@@ -80,7 +75,7 @@ class TunnelMessageController extends Controller
|
||||
|
||||
$httpConnection = $this->connectionManager->storeHttpConnection($httpConnection, $requestId);
|
||||
|
||||
transform($this->passRequestThroughModifiers($request, $httpConnection), function (Request $request) use ($controlConnection, $requestId) {
|
||||
transform($this->passRequestThroughModifiers($request, $httpConnection), function (Request $request) use ($controlConnection , $requestId) {
|
||||
$controlConnection->once('proxy_ready_'.$requestId, function (ConnectionInterface $proxy) use ($request) {
|
||||
// Convert the Laravel request into a PSR7 request
|
||||
$psr17Factory = new Psr17Factory();
|
||||
@@ -118,19 +113,13 @@ class TunnelMessageController extends Controller
|
||||
$host .= ":{$this->configuration->port()}";
|
||||
}
|
||||
|
||||
if (empty($controlConnection->subdomain)) {
|
||||
$originalHost = $controlConnection->hostname;
|
||||
} else {
|
||||
$originalHost = "{$controlConnection->subdomain}.{$host}";
|
||||
}
|
||||
|
||||
$request->headers->set('Host', $controlConnection->host);
|
||||
$request->headers->set('X-Forwarded-Proto', $request->isSecure() ? 'https' : 'http');
|
||||
$request->headers->set('X-Expose-Request-ID', uniqid());
|
||||
$request->headers->set('Upgrade-Insecure-Requests', 1);
|
||||
$request->headers->set('X-Exposed-By', config('app.name').' '.config('app.version'));
|
||||
$request->headers->set('X-Original-Host', $originalHost);
|
||||
$request->headers->set('X-Forwarded-Host', $originalHost);
|
||||
$request->headers->set('X-Original-Host', "{$controlConnection->subdomain}.{$host}");
|
||||
$request->headers->set('X-Forwarded-Host', "{$controlConnection->subdomain}.{$host}");
|
||||
|
||||
return $request;
|
||||
}
|
||||
|
||||
@@ -1,132 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Server\SubdomainRepository;
|
||||
|
||||
use App\Contracts\SubdomainRepository;
|
||||
use Clue\React\SQLite\DatabaseInterface;
|
||||
use Clue\React\SQLite\Result;
|
||||
use React\Promise\Deferred;
|
||||
use React\Promise\PromiseInterface;
|
||||
|
||||
class DatabaseSubdomainRepository implements SubdomainRepository
|
||||
{
|
||||
/** @var DatabaseInterface */
|
||||
protected $database;
|
||||
|
||||
public function __construct(DatabaseInterface $database)
|
||||
{
|
||||
$this->database = $database;
|
||||
}
|
||||
|
||||
public function getSubdomains(): PromiseInterface
|
||||
{
|
||||
$deferred = new Deferred();
|
||||
|
||||
$this->database
|
||||
->query('SELECT * FROM subdomains ORDER by created_at DESC')
|
||||
->then(function (Result $result) use ($deferred) {
|
||||
$deferred->resolve($result->rows);
|
||||
});
|
||||
|
||||
return $deferred->promise();
|
||||
}
|
||||
|
||||
public function getSubdomainById($id): PromiseInterface
|
||||
{
|
||||
$deferred = new Deferred();
|
||||
|
||||
$this->database
|
||||
->query('SELECT * FROM subdomains WHERE id = :id', ['id' => $id])
|
||||
->then(function (Result $result) use ($deferred) {
|
||||
$deferred->resolve($result->rows[0] ?? null);
|
||||
});
|
||||
|
||||
return $deferred->promise();
|
||||
}
|
||||
|
||||
public function getSubdomainByName(string $name): PromiseInterface
|
||||
{
|
||||
$deferred = new Deferred();
|
||||
|
||||
$this->database
|
||||
->query('SELECT * FROM subdomains WHERE subdomain = :name', ['name' => $name])
|
||||
->then(function (Result $result) use ($deferred) {
|
||||
$deferred->resolve($result->rows[0] ?? null);
|
||||
});
|
||||
|
||||
return $deferred->promise();
|
||||
}
|
||||
|
||||
public function getSubdomainsByUserId($id): PromiseInterface
|
||||
{
|
||||
$deferred = new Deferred();
|
||||
|
||||
$this->database
|
||||
->query('SELECT * FROM subdomains WHERE user_id = :user_id ORDER by created_at DESC', [
|
||||
'user_id' => $id,
|
||||
])
|
||||
->then(function (Result $result) use ($deferred) {
|
||||
$deferred->resolve($result->rows);
|
||||
});
|
||||
|
||||
return $deferred->promise();
|
||||
}
|
||||
|
||||
public function storeSubdomain(array $data): PromiseInterface
|
||||
{
|
||||
$deferred = new Deferred();
|
||||
|
||||
$this->getSubdomainByName($data['subdomain'])
|
||||
->then(function ($registeredSubdomain) use ($data, $deferred) {
|
||||
if (! is_null($registeredSubdomain)) {
|
||||
$deferred->resolve(null);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->database->query("
|
||||
INSERT INTO subdomains (user_id, subdomain, created_at)
|
||||
VALUES (:user_id, :subdomain, DATETIME('now'))
|
||||
", $data)
|
||||
->then(function (Result $result) use ($deferred) {
|
||||
$this->database->query('SELECT * FROM subdomains WHERE id = :id', ['id' => $result->insertId])
|
||||
->then(function (Result $result) use ($deferred) {
|
||||
$deferred->resolve($result->rows[0]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
return $deferred->promise();
|
||||
}
|
||||
|
||||
public function getSubdomainsByUserIdAndName($id, $name): PromiseInterface
|
||||
{
|
||||
$deferred = new Deferred();
|
||||
|
||||
$this->database
|
||||
->query('SELECT * FROM subdomains WHERE user_id = :user_id AND subdomain = :name ORDER by created_at DESC', [
|
||||
'user_id' => $id,
|
||||
'name' => $name,
|
||||
])
|
||||
->then(function (Result $result) use ($deferred) {
|
||||
$deferred->resolve($result->rows);
|
||||
});
|
||||
|
||||
return $deferred->promise();
|
||||
}
|
||||
|
||||
public function deleteSubdomainForUserId($userId, $subdomainId): PromiseInterface
|
||||
{
|
||||
$deferred = new Deferred();
|
||||
|
||||
$this->database->query('DELETE FROM subdomains WHERE id = :id AND user_id = :user_id', [
|
||||
'id' => $subdomainId,
|
||||
'user_id' => $userId,
|
||||
])
|
||||
->then(function (Result $result) use ($deferred) {
|
||||
$deferred->resolve($result);
|
||||
});
|
||||
|
||||
return $deferred->promise();
|
||||
}
|
||||
}
|
||||
@@ -114,8 +114,8 @@ class DatabaseUserRepository implements UserRepository
|
||||
$deferred = new Deferred();
|
||||
|
||||
$this->database->query("
|
||||
INSERT INTO users (name, auth_token, can_specify_subdomains, can_specify_hostnames, can_share_tcp_ports, created_at)
|
||||
VALUES (:name, :auth_token, :can_specify_subdomains, :can_specify_hostnames, :can_share_tcp_ports, DATETIME('now'))
|
||||
INSERT INTO users (name, auth_token, can_specify_subdomains, can_share_tcp_ports, created_at)
|
||||
VALUES (:name, :auth_token, :can_specify_subdomains, :can_share_tcp_ports, DATETIME('now'))
|
||||
", $data)
|
||||
->then(function (Result $result) use ($deferred) {
|
||||
$this->database->query('SELECT * FROM users WHERE id = :id', ['id' => $result->insertId])
|
||||
|
||||
@@ -232,10 +232,6 @@ return [
|
||||
*/
|
||||
'user_repository' => \App\Server\UserRepository\DatabaseUserRepository::class,
|
||||
|
||||
'subdomain_repository' => \App\Server\SubdomainRepository\DatabaseSubdomainRepository::class,
|
||||
|
||||
'hostname_repository' => \App\Server\HostnameRepository\DatabaseHostnameRepository::class,
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Messages
|
||||
@@ -253,7 +249,7 @@ return [
|
||||
|
||||
'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. Assigning a random subdomain instead.',
|
||||
'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.',
|
||||
],
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
CREATE TABLE IF NOT EXISTS subdomains (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
user_id INTEGER NOT NULL,
|
||||
subdomain STRING NOT NULL,
|
||||
created_at DATETIME,
|
||||
updated_at DATETIME
|
||||
)
|
||||
@@ -1 +0,0 @@
|
||||
ALTER TABLE users ADD can_specify_hostnames BOOLEAN DEFAULT 1;
|
||||
@@ -1,7 +0,0 @@
|
||||
CREATE TABLE IF NOT EXISTS hostnames (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
user_id INTEGER NOT NULL,
|
||||
hostname STRING NOT NULL,
|
||||
created_at DATETIME,
|
||||
updated_at DATETIME
|
||||
)
|
||||
@@ -9,10 +9,10 @@
|
||||
<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 Host
|
||||
Host
|
||||
</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 Host
|
||||
Subdomain
|
||||
</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
|
||||
@@ -26,13 +26,13 @@
|
||||
@{ site.host }
|
||||
</td>
|
||||
<td class="px-6 py-4 whitespace-no-wrap border-b border-gray-200 text-sm leading-5 text-gray-500">
|
||||
@{ getUrl(site) }
|
||||
@{ site.subdomain }.{{ configuration.hostname()}}:{{ configuration.port() }}
|
||||
</td>
|
||||
<td class="px-6 py-4 whitespace-no-wrap border-b border-gray-200 text-sm leading-5 text-gray-500">
|
||||
@{ site.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="'{{ scheme|raw }}://'+getUrl(site)" target="_blank"
|
||||
<a :href="'{{ scheme|raw }}://'+site.subdomain+'.{{ configuration.hostname()}}:{{ configuration.port() }}'" target="_blank"
|
||||
class="text-indigo-600 hover:text-indigo-900">Visit</a>
|
||||
<a href="#"
|
||||
@click.prevent="disconnectSite(site.client_id)"
|
||||
@@ -60,12 +60,6 @@
|
||||
},
|
||||
|
||||
methods: {
|
||||
getUrl(site) {
|
||||
if (site.hostname !== '' && site.hostname !== null) {
|
||||
return site.hostname;
|
||||
}
|
||||
return `${site.subdomain}.{{ configuration.hostname()}}:{{ configuration.port() }}`;
|
||||
},
|
||||
disconnectSite(id) {
|
||||
fetch('/api/sites/' + id, {
|
||||
method: 'DELETE',
|
||||
|
||||
@@ -43,25 +43,6 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="sm:grid sm:grid-cols-3 sm:gap-4 sm:items-start sm:pt-5">
|
||||
<label for="can_specify_hostnames"
|
||||
class="block text-sm font-medium leading-5 text-gray-700 sm:mt-px sm:pt-2">
|
||||
Can specify custom hostnames
|
||||
</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_specify_hostnames"
|
||||
v-model="userForm.can_specify_hostnames"
|
||||
name="can_specify_hostnames"
|
||||
value="1" type="checkbox" class="form-checkbox h-4 w-4 text-indigo-600 transition duration-150 ease-in-out" />
|
||||
<label for="can_specify_hostnames" class="ml-2 block text-sm leading-5 text-gray-900">
|
||||
Yes
|
||||
</label>
|
||||
</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">
|
||||
@@ -111,9 +92,6 @@
|
||||
<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
|
||||
</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">
|
||||
Custom Hostnames
|
||||
</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>
|
||||
@@ -139,14 +117,6 @@
|
||||
Yes
|
||||
</span>
|
||||
</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_specify_hostnames === 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">
|
||||
<span v-if="user.can_share_tcp_ports === 0">
|
||||
No
|
||||
@@ -204,7 +174,6 @@
|
||||
userForm: {
|
||||
name: '',
|
||||
can_specify_subdomains: true,
|
||||
can_specify_hostnames: true,
|
||||
can_share_tcp_ports: true,
|
||||
errors: {},
|
||||
},
|
||||
@@ -249,7 +218,6 @@
|
||||
if (data.user) {
|
||||
this.userForm.name = '';
|
||||
this.userForm.can_specify_subdomains = true;
|
||||
this.userForm.can_specify_hostnames = true;
|
||||
this.userForm.can_share_tcp_ports = true;
|
||||
this.userForm.errors = {};
|
||||
this.users.unshift(data.user);
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace Tests\Feature\Client;
|
||||
|
||||
use App\Client\Configuration;
|
||||
use App\Client\Factory;
|
||||
use App\Client\Http\HttpClient;
|
||||
use App\Logger\LoggedRequest;
|
||||
@@ -130,10 +129,6 @@ class DashboardTest extends TestCase
|
||||
|
||||
protected function startDashboard()
|
||||
{
|
||||
app()->singleton(Configuration::class, function ($app) {
|
||||
return new Configuration('localhost', '8080', false);
|
||||
});
|
||||
|
||||
$this->dashboardFactory = (new Factory())
|
||||
->setLoop($this->loop)
|
||||
->createHttpServer();
|
||||
|
||||
@@ -152,7 +152,7 @@ class AdminTest extends TestCase
|
||||
$connection = \Mockery::mock(IoConnection::class);
|
||||
$connection->httpRequest = new Request('GET', '/?authToken=some-token');
|
||||
|
||||
$connectionManager->storeConnection('some-host.text', 'fixed-subdomain', '', $connection);
|
||||
$connectionManager->storeConnection('some-host.text', 'fixed-subdomain', $connection);
|
||||
|
||||
/** @var Response $response */
|
||||
$response = $this->await($this->browser->get('http://127.0.0.1:8080/sites', [
|
||||
|
||||
@@ -5,7 +5,6 @@ namespace Tests\Feature\Server;
|
||||
use App\Contracts\ConnectionManager;
|
||||
use App\Server\Factory;
|
||||
use Clue\React\Buzz\Browser;
|
||||
use Clue\React\Buzz\Message\ResponseException;
|
||||
use GuzzleHttp\Psr7\Response;
|
||||
use Nyholm\Psr7\Request;
|
||||
use Ratchet\Server\IoConnection;
|
||||
@@ -65,164 +64,16 @@ class ApiTest extends TestCase
|
||||
$this->assertSame([], $users[0]->sites);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_does_not_allow_subdomain_reservation_for_users_without_the_right_flag()
|
||||
{
|
||||
/** @var Response $response */
|
||||
$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',
|
||||
])));
|
||||
|
||||
$user = json_decode($response->getBody()->getContents())->user;
|
||||
|
||||
$this->expectException(ResponseException::class);
|
||||
$this->expectExceptionMessage('HTTP status code 401');
|
||||
|
||||
$this->await($this->browser->post('http://127.0.0.1:8080/api/subdomains', [
|
||||
'Host' => 'expose.localhost',
|
||||
'Authorization' => base64_encode('username:secret'),
|
||||
'Content-Type' => 'application/json',
|
||||
], json_encode([
|
||||
'auth_token' => $user->auth_token,
|
||||
'subdomain' => 'reserved',
|
||||
])));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_allows_subdomain_reservation_for_users_with_the_right_flag()
|
||||
{
|
||||
/** @var Response $response */
|
||||
$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_specify_subdomains' => 1,
|
||||
])));
|
||||
|
||||
$user = json_decode($response->getBody()->getContents())->user;
|
||||
|
||||
$response = $this->await($this->browser->post('http://127.0.0.1:8080/api/subdomains', [
|
||||
'Host' => 'expose.localhost',
|
||||
'Authorization' => base64_encode('username:secret'),
|
||||
'Content-Type' => 'application/json',
|
||||
], json_encode([
|
||||
'auth_token' => $user->auth_token,
|
||||
'subdomain' => 'reserved',
|
||||
])));
|
||||
|
||||
$this->assertSame(200, $response->getStatusCode());
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_allows__hostname_reservation_for_users_with_the_right_flag()
|
||||
{
|
||||
/** @var Response $response */
|
||||
$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_specify_hostnames' => 1,
|
||||
])));
|
||||
|
||||
$user = json_decode($response->getBody()->getContents())->user;
|
||||
|
||||
$response = $this->await($this->browser->post('http://127.0.0.1:8080/api/hostnames', [
|
||||
'Host' => 'expose.localhost',
|
||||
'Authorization' => base64_encode('username:secret'),
|
||||
'Content-Type' => 'application/json',
|
||||
], json_encode([
|
||||
'auth_token' => $user->auth_token,
|
||||
'hostname' => 'reserved.beyondco.de',
|
||||
])));
|
||||
|
||||
$this->assertSame(200, $response->getStatusCode());
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_can_delete_hostnames()
|
||||
{
|
||||
/** @var Response $response */
|
||||
$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_specify_hostnames' => 1,
|
||||
])));
|
||||
|
||||
$user = json_decode($response->getBody()->getContents())->user;
|
||||
|
||||
$response = $this->await($this->browser->post('http://127.0.0.1:8080/api/hostnames', [
|
||||
'Host' => 'expose.localhost',
|
||||
'Authorization' => base64_encode('username:secret'),
|
||||
'Content-Type' => 'application/json',
|
||||
], json_encode([
|
||||
'hostname' => 'reserved.beyondco.de',
|
||||
'auth_token' => $user->auth_token,
|
||||
])));
|
||||
|
||||
$this->await($this->browser->delete('http://127.0.0.1:8080/api/hostnames/1', [
|
||||
'Host' => 'expose.localhost',
|
||||
'Authorization' => base64_encode('username:secret'),
|
||||
'Content-Type' => 'application/json',
|
||||
], json_encode([
|
||||
'auth_token' => $user->auth_token,
|
||||
])));
|
||||
|
||||
/** @var Response $response */
|
||||
$response = $this->await($this->browser->get('http://127.0.0.1:8080/api/users/1', [
|
||||
'Host' => 'expose.localhost',
|
||||
'Authorization' => base64_encode('username:secret'),
|
||||
'Content-Type' => 'application/json',
|
||||
]));
|
||||
|
||||
$body = json_decode($response->getBody()->getContents());
|
||||
$hostnames = $body->hostnames;
|
||||
|
||||
$this->assertCount(0, $hostnames);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_can_get_user_details()
|
||||
{
|
||||
/** @var Response $response */
|
||||
$response = $this->await($this->browser->post('http://127.0.0.1:8080/api/users', [
|
||||
$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_specify_hostnames' => 1,
|
||||
'can_specify_subdomains' => 1,
|
||||
])));
|
||||
|
||||
$user = json_decode($response->getBody()->getContents())->user;
|
||||
|
||||
$this->await($this->browser->post('http://127.0.0.1:8080/api/subdomains', [
|
||||
'Host' => 'expose.localhost',
|
||||
'Authorization' => base64_encode('username:secret'),
|
||||
'Content-Type' => 'application/json',
|
||||
], json_encode([
|
||||
'auth_token' => $user->auth_token,
|
||||
'subdomain' => 'reserved',
|
||||
])));
|
||||
|
||||
$this->await($this->browser->post('http://127.0.0.1:8080/api/hostnames', [
|
||||
'Host' => 'expose.localhost',
|
||||
'Authorization' => base64_encode('username:secret'),
|
||||
'Content-Type' => 'application/json',
|
||||
], json_encode([
|
||||
'auth_token' => $user->auth_token,
|
||||
'hostname' => 'reserved.beyondco.de',
|
||||
])));
|
||||
|
||||
/** @var Response $response */
|
||||
@@ -234,119 +85,10 @@ class ApiTest extends TestCase
|
||||
|
||||
$body = json_decode($response->getBody()->getContents());
|
||||
$user = $body->user;
|
||||
$subdomains = $body->subdomains;
|
||||
$hostnames = $body->hostnames;
|
||||
|
||||
$this->assertSame('Marcel', $user->name);
|
||||
$this->assertSame([], $user->sites);
|
||||
$this->assertSame([], $user->tcp_connections);
|
||||
|
||||
$this->assertCount(1, $subdomains);
|
||||
$this->assertCount(1, $hostnames);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_can_delete_subdomains()
|
||||
{
|
||||
/** @var Response $response */
|
||||
$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_specify_subdomains' => 1,
|
||||
])));
|
||||
|
||||
$user = json_decode($response->getBody()->getContents())->user;
|
||||
|
||||
$response = $this->await($this->browser->post('http://127.0.0.1:8080/api/subdomains', [
|
||||
'Host' => 'expose.localhost',
|
||||
'Authorization' => base64_encode('username:secret'),
|
||||
'Content-Type' => 'application/json',
|
||||
], json_encode([
|
||||
'subdomain' => 'reserved',
|
||||
'auth_token' => $user->auth_token,
|
||||
])));
|
||||
|
||||
$this->await($this->browser->delete('http://127.0.0.1:8080/api/subdomains/1', [
|
||||
'Host' => 'expose.localhost',
|
||||
'Authorization' => base64_encode('username:secret'),
|
||||
'Content-Type' => 'application/json',
|
||||
], json_encode([
|
||||
'auth_token' => $user->auth_token,
|
||||
])));
|
||||
|
||||
/** @var Response $response */
|
||||
$response = $this->await($this->browser->get('http://127.0.0.1:8080/api/users/1', [
|
||||
'Host' => 'expose.localhost',
|
||||
'Authorization' => base64_encode('username:secret'),
|
||||
'Content-Type' => 'application/json',
|
||||
]));
|
||||
|
||||
$body = json_decode($response->getBody()->getContents());
|
||||
$subdomains = $body->subdomains;
|
||||
|
||||
$this->assertCount(0, $subdomains);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_can_not_reserve_an_already_reserved_subdomain()
|
||||
{
|
||||
/** @var Response $response */
|
||||
$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_specify_subdomains' => 1,
|
||||
])));
|
||||
|
||||
$user = json_decode($response->getBody()->getContents())->user;
|
||||
|
||||
$this->await($this->browser->post('http://127.0.0.1:8080/api/subdomains', [
|
||||
'Host' => 'expose.localhost',
|
||||
'Authorization' => base64_encode('username:secret'),
|
||||
'Content-Type' => 'application/json',
|
||||
], json_encode([
|
||||
'subdomain' => 'reserved',
|
||||
'auth_token' => $user->auth_token,
|
||||
])));
|
||||
|
||||
$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' => 'Sebastian',
|
||||
'can_specify_subdomains' => 1,
|
||||
])));
|
||||
|
||||
$user = json_decode($response->getBody()->getContents())->user;
|
||||
|
||||
$this->expectException(ResponseException::class);
|
||||
$this->expectExceptionMessage('HTTP status code 422');
|
||||
|
||||
$this->await($this->browser->post('http://127.0.0.1:8080/api/subdomains', [
|
||||
'Host' => 'expose.localhost',
|
||||
'Authorization' => base64_encode('username:secret'),
|
||||
'Content-Type' => 'application/json',
|
||||
], json_encode([
|
||||
'subdomain' => 'reserved',
|
||||
'auth_token' => $user->auth_token,
|
||||
])));
|
||||
|
||||
$response = $this->await($this->browser->get('http://127.0.0.1:8080/api/users/2', [
|
||||
'Host' => 'expose.localhost',
|
||||
'Authorization' => base64_encode('username:secret'),
|
||||
'Content-Type' => 'application/json',
|
||||
]));
|
||||
|
||||
$body = json_decode($response->getBody()->getContents());
|
||||
$subdomains = $body->subdomains;
|
||||
|
||||
$this->assertCount(0, $subdomains);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
@@ -368,11 +110,11 @@ class ApiTest extends TestCase
|
||||
|
||||
$connection = \Mockery::mock(IoConnection::class);
|
||||
$connection->httpRequest = new Request('GET', '/?authToken='.$createdUser->auth_token);
|
||||
$connectionManager->storeConnection('some-host.test', 'fixed-subdomain', '', $connection);
|
||||
$connectionManager->storeConnection('some-host.test', 'fixed-subdomain', $connection);
|
||||
|
||||
$connection = \Mockery::mock(IoConnection::class);
|
||||
$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);
|
||||
@@ -403,7 +145,7 @@ class ApiTest extends TestCase
|
||||
$connection = \Mockery::mock(IoConnection::class);
|
||||
$connection->httpRequest = new Request('GET', '/?authToken=some-token');
|
||||
|
||||
$connectionManager->storeConnection('some-host.test', 'fixed-subdomain', '', $connection);
|
||||
$connectionManager->storeConnection('some-host.test', 'fixed-subdomain', $connection);
|
||||
|
||||
/** @var Response $response */
|
||||
$response = $this->await($this->browser->get('http://127.0.0.1:8080/api/sites', [
|
||||
@@ -430,7 +172,7 @@ class ApiTest extends TestCase
|
||||
$connection = \Mockery::mock(IoConnection::class);
|
||||
$connection->httpRequest = new Request('GET', '/');
|
||||
|
||||
$connectionManager->storeConnection('some-host.test', 'fixed-subdomain', '', $connection);
|
||||
$connectionManager->storeConnection('some-host.test', 'fixed-subdomain', $connection);
|
||||
|
||||
/** @var Response $response */
|
||||
$response = $this->await($this->browser->get('http://127.0.0.1:8080/api/sites', [
|
||||
|
||||
@@ -9,7 +9,6 @@ use Clue\React\Buzz\Message\ResponseException;
|
||||
use GuzzleHttp\Psr7\Response;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use React\Http\Server;
|
||||
use React\Promise\Timer\TimeoutException;
|
||||
use React\Socket\Connection;
|
||||
use Tests\Feature\TestCase;
|
||||
|
||||
@@ -90,76 +89,6 @@ class TunnelTest extends TestCase
|
||||
$this->assertSame('Hello World!', $response->getBody()->getContents());
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_sends_incoming_requests_to_the_connected_client_with_random_subdomain()
|
||||
{
|
||||
$this->createTestHttpServer();
|
||||
|
||||
$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();
|
||||
$data = $this->await($client->connectToServer('127.0.0.1:8085', null));
|
||||
|
||||
/**
|
||||
* Once the client is connected, we perform a GET request on the
|
||||
* created tunnel.
|
||||
*/
|
||||
$response = $this->await($this->browser->get('http://127.0.0.1:8080/', [
|
||||
'Host' => $data->subdomain.'.localhost',
|
||||
]));
|
||||
|
||||
$this->assertSame('Hello World!', $response->getBody()->getContents());
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_sends_incoming_requests_to_the_connected_client_with_specific_hostname()
|
||||
{
|
||||
$this->createTestHttpServer();
|
||||
|
||||
$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_specify_hostnames' => 1,
|
||||
])));
|
||||
|
||||
$user = json_decode($response->getBody()->getContents())->user;
|
||||
|
||||
$this->await($this->browser->post('http://127.0.0.1:8080/api/hostnames', [
|
||||
'Host' => 'expose.localhost',
|
||||
'Authorization' => base64_encode('username:secret'),
|
||||
'Content-Type' => 'application/json',
|
||||
], json_encode([
|
||||
'hostname' => 'reserved.beyondco.de',
|
||||
'auth_token' => $user->auth_token,
|
||||
])));
|
||||
|
||||
/**
|
||||
* We create an expose client that connects to our server and shares
|
||||
* the created test HTTP server.
|
||||
*/
|
||||
$client = $this->createClient();
|
||||
$data = $this->await($client->connectToServer('127.0.0.1:8085', null, 'reserved.beyondco.de', $user->auth_token));
|
||||
|
||||
/**
|
||||
* Once the client is connected, we perform a GET request on the
|
||||
* created tunnel.
|
||||
*/
|
||||
$response = $this->await($this->browser->get('http://127.0.0.1:8080/', [
|
||||
'Host' => 'reserved.beyondco.de',
|
||||
]));
|
||||
|
||||
$this->assertSame('Hello World!', $response->getBody()->getContents());
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_sends_incoming_requests_to_the_connected_client_via_tcp()
|
||||
{
|
||||
@@ -287,7 +216,7 @@ class TunnelTest extends TestCase
|
||||
* the created test HTTP server.
|
||||
*/
|
||||
$client = $this->createClient();
|
||||
$response = $this->await($client->connectToServer('127.0.0.1:8085', 'tunnel', null, $user->auth_token));
|
||||
$response = $this->await($client->connectToServer('127.0.0.1:8085', 'tunnel', $user->auth_token));
|
||||
|
||||
$this->assertSame('tunnel', $response->subdomain);
|
||||
}
|
||||
@@ -306,288 +235,20 @@ class TunnelTest extends TestCase
|
||||
'can_specify_subdomains' => 0,
|
||||
])));
|
||||
|
||||
$user = json_decode($response->getBody()->getContents())->user;
|
||||
|
||||
$this->createTestHttpServer();
|
||||
|
||||
/**
|
||||
* We create an expose client that connects to our server and shares
|
||||
* the created test HTTP server.
|
||||
*/
|
||||
$client = $this->createClient();
|
||||
$response = $this->await($client->connectToServer('127.0.0.1:8085', 'tunnel', null, $user->auth_token));
|
||||
|
||||
$this->assertNotSame('tunnel', $response->subdomain);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_rejects_users_that_want_to_use_a_reserved_subdomain()
|
||||
{
|
||||
$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_specify_subdomains' => 1,
|
||||
])));
|
||||
|
||||
$user = json_decode($response->getBody()->getContents())->user;
|
||||
|
||||
$response = $this->await($this->browser->post('http://127.0.0.1:8080/api/subdomains', [
|
||||
'Host' => 'expose.localhost',
|
||||
'Authorization' => base64_encode('username:secret'),
|
||||
'Content-Type' => 'application/json',
|
||||
], json_encode([
|
||||
'subdomain' => 'reserved',
|
||||
'auth_token' => $user->auth_token,
|
||||
])));
|
||||
|
||||
$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' => 'Test-User',
|
||||
'can_specify_subdomains' => 1,
|
||||
])));
|
||||
|
||||
$user = json_decode($response->getBody()->getContents())->user;
|
||||
|
||||
$this->createTestHttpServer();
|
||||
|
||||
$this->expectException(\UnexpectedValueException::class);
|
||||
/**
|
||||
* We create an expose client that connects to our server and shares
|
||||
* the created test HTTP server.
|
||||
*/
|
||||
$client = $this->createClient();
|
||||
$response = $this->await($client->connectToServer('127.0.0.1:8085', 'reserved', $user->auth_token));
|
||||
|
||||
$this->assertSame('reserved', $response->subdomain);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_allows_users_to_use_their_own_reserved_subdomains()
|
||||
{
|
||||
$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_specify_subdomains' => 1,
|
||||
])));
|
||||
|
||||
$user = json_decode($response->getBody()->getContents())->user;
|
||||
|
||||
$response = $this->await($this->browser->post('http://127.0.0.1:8080/api/subdomains', [
|
||||
'Host' => 'expose.localhost',
|
||||
'Authorization' => base64_encode('username:secret'),
|
||||
'Content-Type' => 'application/json',
|
||||
], json_encode([
|
||||
'subdomain' => 'reserved',
|
||||
'auth_token' => $user->auth_token,
|
||||
])));
|
||||
|
||||
$this->createTestHttpServer();
|
||||
/**
|
||||
* We create an expose client that connects to our server and shares
|
||||
* the created test HTTP server.
|
||||
*/
|
||||
$client = $this->createClient();
|
||||
$response = $this->await($client->connectToServer('127.0.0.1:8085', 'reserved', null, $user->auth_token));
|
||||
|
||||
$this->assertSame('reserved', $response->subdomain);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_allows_users_to_use_their_own_reserved_hostnames()
|
||||
{
|
||||
$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_specify_hostnames' => 1,
|
||||
])));
|
||||
|
||||
$user = json_decode($response->getBody()->getContents())->user;
|
||||
|
||||
$response = $this->await($this->browser->post('http://127.0.0.1:8080/api/hostnames', [
|
||||
'Host' => 'expose.localhost',
|
||||
'Authorization' => base64_encode('username:secret'),
|
||||
'Content-Type' => 'application/json',
|
||||
], json_encode([
|
||||
'hostname' => 'reserved.beyondco.de',
|
||||
'auth_token' => $user->auth_token,
|
||||
])));
|
||||
|
||||
$this->createTestHttpServer();
|
||||
/**
|
||||
* We create an expose client that connects to our server and shares
|
||||
* the created test HTTP server.
|
||||
*/
|
||||
$client = $this->createClient();
|
||||
$response = $this->await($client->connectToServer('127.0.0.1:8085', null, 'reserved.beyondco.de', $user->auth_token));
|
||||
|
||||
$this->assertSame('reserved.beyondco.de', $response->hostname);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_allows_users_to_use_their_own_reserved_hostnames_with_wildcards()
|
||||
{
|
||||
$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_specify_hostnames' => 1,
|
||||
])));
|
||||
|
||||
$user = json_decode($response->getBody()->getContents())->user;
|
||||
|
||||
$response = $this->await($this->browser->post('http://127.0.0.1:8080/api/hostnames', [
|
||||
'Host' => 'expose.localhost',
|
||||
'Authorization' => base64_encode('username:secret'),
|
||||
'Content-Type' => 'application/json',
|
||||
], json_encode([
|
||||
'hostname' => '*.share.beyondco.de',
|
||||
'auth_token' => $user->auth_token,
|
||||
])));
|
||||
|
||||
$this->createTestHttpServer();
|
||||
/**
|
||||
* We create an expose client that connects to our server and shares
|
||||
* the created test HTTP server.
|
||||
*/
|
||||
$client = $this->createClient();
|
||||
$response = $this->await($client->connectToServer('127.0.0.1:8085', null, 'foo.share.beyondco.de', $user->auth_token));
|
||||
|
||||
$this->assertSame('foo.share.beyondco.de', $response->hostname);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_rejects_users_trying_to_use_non_registered_hostnames()
|
||||
{
|
||||
$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_specify_hostnames' => 1,
|
||||
])));
|
||||
|
||||
$user = json_decode($response->getBody()->getContents())->user;
|
||||
|
||||
$response = $this->await($this->browser->post('http://127.0.0.1:8080/api/hostnames', [
|
||||
'Host' => 'expose.localhost',
|
||||
'Authorization' => base64_encode('username:secret'),
|
||||
'Content-Type' => 'application/json',
|
||||
], json_encode([
|
||||
'hostname' => 'share.beyondco.de',
|
||||
'auth_token' => $user->auth_token,
|
||||
])));
|
||||
|
||||
$this->createTestHttpServer();
|
||||
|
||||
$this->expectException(TimeoutException::class);
|
||||
|
||||
/**
|
||||
* We create an expose client that connects to our server and shares
|
||||
* the created test HTTP server.
|
||||
*/
|
||||
$client = $this->createClient();
|
||||
$this->await($client->connectToServer('127.0.0.1:8085', null, 'foo.beyondco.de', $user->auth_token));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_rejects_users_trying_to_use_other_peoples_registered_hostnames()
|
||||
{
|
||||
$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_specify_hostnames' => 1,
|
||||
])));
|
||||
|
||||
$user = json_decode($response->getBody()->getContents())->user;
|
||||
|
||||
$response = $this->await($this->browser->post('http://127.0.0.1:8080/api/hostnames', [
|
||||
'Host' => 'expose.localhost',
|
||||
'Authorization' => base64_encode('username:secret'),
|
||||
'Content-Type' => 'application/json',
|
||||
], json_encode([
|
||||
'hostname' => '*.share.beyondco.de',
|
||||
'auth_token' => $user->auth_token,
|
||||
])));
|
||||
|
||||
$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_specify_hostnames' => 1,
|
||||
])));
|
||||
|
||||
$user = json_decode($response->getBody()->getContents())->user;
|
||||
|
||||
$this->createTestHttpServer();
|
||||
|
||||
$this->expectException(TimeoutException::class);
|
||||
|
||||
/**
|
||||
* We create an expose client that connects to our server and shares
|
||||
* the created test HTTP server.
|
||||
*/
|
||||
$client = $this->createClient();
|
||||
$this->await($client->connectToServer('127.0.0.1:8085', null, 'foo.share.beyondco.de', $user->auth_token));
|
||||
}
|
||||
$response = $this->await($client->connectToServer('127.0.0.1:8085', 'tunnel', $user->auth_token));
|
||||
|
||||
/** @test */
|
||||
public function it_rejects_clients_to_specify_custom_hostnames()
|
||||
{
|
||||
$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_specify_hostnames' => 0,
|
||||
])));
|
||||
|
||||
$user = json_decode($response->getBody()->getContents())->user;
|
||||
|
||||
$this->createTestHttpServer();
|
||||
|
||||
$this->expectException(TimeoutException::class);
|
||||
|
||||
/**
|
||||
* We create an expose client that connects to our server and shares
|
||||
* the created test HTTP server.
|
||||
*/
|
||||
$client = $this->createClient();
|
||||
$this->await($client->connectToServer('127.0.0.1:8085', null, 'reserved.beyondco.de', $user->auth_token));
|
||||
$this->assertSame('tunnel', $response->subdomain);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
@@ -613,7 +274,7 @@ class TunnelTest extends TestCase
|
||||
* the created test HTTP server.
|
||||
*/
|
||||
$client = $this->createClient();
|
||||
$response = $this->await($client->connectToServer('127.0.0.1:8085', '', null, $user->auth_token));
|
||||
$response = $this->await($client->connectToServer('127.0.0.1:8085', '', $user->auth_token));
|
||||
|
||||
$this->assertInstanceOf(\stdClass::class, $response);
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ use Symfony\Component\Console\Output\ConsoleOutputInterface;
|
||||
|
||||
abstract class TestCase extends \Tests\TestCase
|
||||
{
|
||||
const AWAIT_TIMEOUT = 0.2;
|
||||
const AWAIT_TIMEOUT = 5.0;
|
||||
|
||||
/** @var LoopInterface */
|
||||
protected $loop;
|
||||
|
||||
Reference in New Issue
Block a user