mirror of
https://github.com/bitinflow/expose.git
synced 2026-03-17 23:45:55 +00:00
Allow users to specify custom hostnames
This commit is contained in:
35
app/Server/Connections/ConnectionConfiguration.php
Normal file
35
app/Server/Connections/ConnectionConfiguration.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?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,16 +43,23 @@ class ConnectionManager implements ConnectionManagerContract
|
||||
});
|
||||
}
|
||||
|
||||
public function storeConnection(string $host, ?string $subdomain, ConnectionInterface $connection): ControlConnection
|
||||
public function storeConnection(string $host, ?string $subdomain, ?string $hostname, 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 ?? $this->subdomainGenerator->generateSubdomain(),
|
||||
$subdomain,
|
||||
$hostname,
|
||||
$clientId,
|
||||
$this->getAuthTokenFromConnection($connection)
|
||||
);
|
||||
@@ -150,6 +157,13 @@ 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,15 +14,17 @@ 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 $clientId, string $authToken = '')
|
||||
public function __construct(ConnectionInterface $socket, string $host, string $subdomain, ?string $hostname, 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();
|
||||
@@ -64,6 +66,7 @@ class ControlConnection
|
||||
'client_id' => $this->client_id,
|
||||
'auth_token' => $this->authToken,
|
||||
'subdomain' => $this->subdomain,
|
||||
'hostname' => $this->hostname,
|
||||
'shared_at' => $this->shared_at,
|
||||
];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user