mirror of
https://github.com/bitinflow/expose.git
synced 2026-03-13 21:45:55 +00:00
wip
This commit is contained in:
@@ -32,14 +32,17 @@ class Connection
|
||||
return array_pop($this->proxies);
|
||||
}
|
||||
|
||||
public function rewriteHostInformation($serverHost, $port, string $data)
|
||||
public function rewriteHostInformation($serverHost, $port, $requestId, string $data)
|
||||
{
|
||||
$appName = config('app.name');
|
||||
$appVersion = config('app.version');
|
||||
|
||||
$originalHost = "{$this->subdomain}.{$serverHost}:{$port}";
|
||||
|
||||
$data = preg_replace('/Host: '.$this->subdomain.'.'.$serverHost.'(.*)\r\n/', "Host: {$this->host}\r\n" .
|
||||
"X-Tunnel-By: {$appName} {$appVersion}\r\n" .
|
||||
"X-Original-Host: {$this->subdomain}.{$serverHost}:{$port}\r\n", $data);
|
||||
"X-Exposed-By: {$appName} {$appVersion}\r\n" .
|
||||
"X-Expose-Request-ID: {$requestId}\r\n" .
|
||||
"X-Original-Host: {$originalHost}\r\n", $data);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ use Ratchet\ConnectionInterface;
|
||||
use Ratchet\MessageComponentInterface;
|
||||
use function GuzzleHttp\Psr7\parse_request;
|
||||
|
||||
class Shaft implements MessageComponentInterface
|
||||
class Expose implements MessageComponentInterface
|
||||
{
|
||||
protected $connectionManager;
|
||||
|
||||
@@ -60,7 +60,7 @@ class Factory
|
||||
|
||||
$connectionManager = new ConnectionManager($this->hostname, $this->port);
|
||||
|
||||
$app = new Shaft($connectionManager);
|
||||
$app = new Expose($connectionManager);
|
||||
|
||||
return new IoServer($app, $socket, $this->loop);
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ namespace App\Server\Messages;
|
||||
use App\Server\Connections\ConnectionManager;
|
||||
use Illuminate\Support\Str;
|
||||
use Ratchet\ConnectionInterface;
|
||||
use React\EventLoop\LoopInterface;
|
||||
use stdClass;
|
||||
|
||||
class ControlMessage implements Message
|
||||
@@ -45,6 +46,13 @@ class ControlMessage implements Message
|
||||
'subdomain' => $connectionInfo->subdomain,
|
||||
'client_id' => $connectionInfo->client_id
|
||||
]));
|
||||
|
||||
$loop = app(LoopInterface::class);
|
||||
$timer = $loop->addPeriodicTimer(5, function () use ($connection) {
|
||||
$connection->send(json_encode([
|
||||
'event' => 'ping'
|
||||
]));
|
||||
});
|
||||
}
|
||||
|
||||
protected function registerProxy(ConnectionInterface $connection, $data)
|
||||
|
||||
@@ -69,10 +69,10 @@ class TunnelMessage implements Message
|
||||
|
||||
private function copyDataToClient(Connection $clientConnection)
|
||||
{
|
||||
$data = $clientConnection->rewriteHostInformation($this->connectionManager->host(), $this->connectionManager->port(), $this->connection->buffer);
|
||||
|
||||
$requestId = uniqid();
|
||||
|
||||
$data = $clientConnection->rewriteHostInformation($this->connectionManager->host(), $this->connectionManager->port(), $requestId, $this->connection->buffer);
|
||||
|
||||
// Ask client to create a new proxy
|
||||
$clientConnection->socket->send(json_encode([
|
||||
'event' => 'createProxy',
|
||||
|
||||
Reference in New Issue
Block a user