mirror of
https://github.com/bitinflow/expose.git
synced 2026-03-14 14:05:54 +00:00
Compare commits
14 Commits
share-file
...
fix-http-p
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
763b45a77e | ||
|
|
f137ea298b | ||
|
|
2f457352c5 | ||
|
|
c5cdd8c352 | ||
|
|
6f72d719bf | ||
|
|
f6d04777e1 | ||
|
|
bded9f754e | ||
|
|
c92d4b258c | ||
|
|
eb8d1f4f91 | ||
|
|
da39fb8ad8 | ||
|
|
5b7a80bb0c | ||
|
|
f5c009eadd | ||
|
|
7459c0189b | ||
|
|
8b8426cd3b |
@@ -21,3 +21,4 @@ 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"]
|
||||
|
||||
@@ -45,13 +45,13 @@ class Client
|
||||
$sharedUrl = $this->prepareSharedUrl($sharedUrl);
|
||||
|
||||
foreach ($subdomains as $subdomain) {
|
||||
$this->connectToServer($sharedUrl, $subdomain, config('expose.auth_token'));
|
||||
$this->connectToServer($sharedUrl, $subdomain, $this->configuration->auth());
|
||||
}
|
||||
}
|
||||
|
||||
public function sharePort(int $port)
|
||||
{
|
||||
$this->connectToServerAndShareTcp($port, config('expose.auth_token'));
|
||||
$this->connectToServerAndShareTcp($port, $this->configuration->auth());
|
||||
}
|
||||
|
||||
protected function prepareSharedUrl(string $sharedUrl): string
|
||||
@@ -60,16 +60,11 @@ class Client
|
||||
return $sharedUrl;
|
||||
}
|
||||
|
||||
$url = Arr::get($parsedUrl, 'host', Arr::get($parsedUrl, 'path'));
|
||||
$host = Arr::get($parsedUrl, 'host', Arr::get($parsedUrl, 'path', 'localhost'));
|
||||
$scheme = Arr::get($parsedUrl, 'scheme', 'http');
|
||||
$port = Arr::get($parsedUrl, 'port', $scheme === 'https' ? 443 : 80);
|
||||
|
||||
if (Arr::get($parsedUrl, 'scheme') === 'https') {
|
||||
$url .= ':443';
|
||||
}
|
||||
if (! is_null($port = Arr::get($parsedUrl, 'port'))) {
|
||||
$url .= ":{$port}";
|
||||
}
|
||||
|
||||
return $url;
|
||||
return sprintf('%s://%s:%s', $scheme, $host, $port);
|
||||
}
|
||||
|
||||
public function connectToServer(string $sharedUrl, $subdomain, $authToken = ''): PromiseInterface
|
||||
|
||||
@@ -11,10 +11,12 @@ use function GuzzleHttp\Psr7\str;
|
||||
use Laminas\Http\Request;
|
||||
use Psr\Http\Message\RequestInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\UriInterface;
|
||||
use Ratchet\Client\WebSocket;
|
||||
use Ratchet\RFC6455\Messaging\Frame;
|
||||
use React\EventLoop\LoopInterface;
|
||||
use React\Socket\Connector;
|
||||
use React\Stream\ReadableStreamInterface;
|
||||
|
||||
class HttpClient
|
||||
{
|
||||
@@ -74,7 +76,6 @@ class HttpClient
|
||||
protected function createConnector(): Connector
|
||||
{
|
||||
return new Connector($this->loop, [
|
||||
'dns' => '127.0.0.1',
|
||||
'tls' => [
|
||||
'verify_peer' => false,
|
||||
'verify_peer_name' => false,
|
||||
@@ -85,22 +86,17 @@ class HttpClient
|
||||
protected function sendRequestToApplication(RequestInterface $request, $proxyConnection = null)
|
||||
{
|
||||
(new Browser($this->loop, $this->createConnector()))
|
||||
->withOptions([
|
||||
'followRedirects' => false,
|
||||
'obeySuccessCode' => false,
|
||||
'streaming' => true,
|
||||
])
|
||||
->send($request)
|
||||
->withFollowRedirects(false)
|
||||
->withRejectErrorResponse(false)
|
||||
->requestStreaming($request->getMethod(), $this->getExposeUri($request), $request->getHeaders(), $request->getBody())
|
||||
->then(function (ResponseInterface $response) use ($proxyConnection) {
|
||||
if (!isset($response->buffer)) {
|
||||
$response = $this->rewriteResponseHeaders($response);
|
||||
|
||||
if (! isset($response->buffer)) {
|
||||
$response->buffer = str($response);
|
||||
}
|
||||
|
||||
$this->sendChunkToServer($response->buffer, $proxyConnection);
|
||||
|
||||
/* @var $body \React\Stream\ReadableStreamInterface */
|
||||
/* @var $body ReadableStreamInterface */
|
||||
$body = $response->getBody();
|
||||
|
||||
$this->logResponse(str($response));
|
||||
@@ -137,24 +133,14 @@ class HttpClient
|
||||
return Request::fromString($data);
|
||||
}
|
||||
|
||||
protected function rewriteResponseHeaders(ResponseInterface $response)
|
||||
private function getExposeUri(RequestInterface $request): UriInterface
|
||||
{
|
||||
if (!$response->hasHeader('Location')) {
|
||||
return $response;
|
||||
}
|
||||
$exposeProto = $request->getHeader('x-expose-proto')[0];
|
||||
$exposeHost = explode(':', $request->getHeader('x-expose-host')[0]);
|
||||
|
||||
$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);
|
||||
return $request->getUri()
|
||||
->withScheme($exposeProto)
|
||||
->withHost($exposeHost[0])
|
||||
->withPort($exposeHost[1]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ use Symfony\Component\Console\Output\ConsoleOutput;
|
||||
|
||||
class ShareCommand extends Command
|
||||
{
|
||||
protected $signature = 'share {host} {--subdomain=} {--auth=}';
|
||||
protected $signature = 'share {host} {--subdomain=} {--auth=} {--server-host=} {--server-port=}';
|
||||
|
||||
protected $description = 'Share a local url with a remote expose server';
|
||||
|
||||
@@ -27,11 +27,15 @@ class ShareCommand extends Command
|
||||
{
|
||||
$this->configureConnectionLogger();
|
||||
|
||||
$serverHost = $this->option('server-host') ?? config('expose.host', 'localhost');
|
||||
$serverPort = $this->option('server-port') ?? config('expose.port', 8080);
|
||||
$auth = $this->option('auth') ?? config('expose.auth_token', '');
|
||||
|
||||
(new Factory())
|
||||
->setLoop(app(LoopInterface::class))
|
||||
->setHost(config('expose.host', 'localhost'))
|
||||
->setPort(config('expose.port', 8080))
|
||||
->setAuth($this->option('auth'))
|
||||
->setHost($serverHost)
|
||||
->setPort($serverPort)
|
||||
->setAuth($auth)
|
||||
->createClient()
|
||||
->share($this->argument('host'), explode(',', $this->option('subdomain')))
|
||||
->createHttpServer()
|
||||
|
||||
@@ -4,7 +4,7 @@ namespace App\Commands;
|
||||
|
||||
class ShareCurrentWorkingDirectoryCommand extends ShareCommand
|
||||
{
|
||||
protected $signature = 'share-cwd {host?} {--subdomain=} {--auth=}';
|
||||
protected $signature = 'share-cwd {host?} {--subdomain=} {--auth=} {--server-host=} {--server-port=}';
|
||||
|
||||
public function handle()
|
||||
{
|
||||
|
||||
@@ -37,6 +37,14 @@ class AppServiceProvider extends ServiceProvider
|
||||
{
|
||||
$builtInConfig = config('expose');
|
||||
|
||||
$keyServerVariable = 'EXPOSE_CONFIG_FILE';
|
||||
if (array_key_exists($keyServerVariable, $_SERVER) && is_string($_SERVER[$keyServerVariable]) && file_exists($_SERVER[$keyServerVariable])) {
|
||||
$localConfig = require $_SERVER[$keyServerVariable];
|
||||
config()->set('expose', array_merge($builtInConfig, $localConfig));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$localConfigFile = getcwd().DIRECTORY_SEPARATOR.'.expose.php';
|
||||
|
||||
if (file_exists($localConfigFile)) {
|
||||
|
||||
@@ -45,15 +45,13 @@ class ConnectionManager implements ConnectionManagerContract
|
||||
|
||||
public function storeConnection(string $host, ?string $subdomain, ConnectionInterface $connection): ControlConnection
|
||||
{
|
||||
$clientId = (string) uniqid();
|
||||
|
||||
$connection->client_id = $clientId;
|
||||
$connection->client_id = sha1(uniqid('', true));
|
||||
|
||||
$storedConnection = new ControlConnection(
|
||||
$connection,
|
||||
$host,
|
||||
$subdomain ?? $this->subdomainGenerator->generateSubdomain(),
|
||||
$clientId,
|
||||
$connection->client_id,
|
||||
$this->getAuthTokenFromConnection($connection)
|
||||
);
|
||||
|
||||
|
||||
@@ -75,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();
|
||||
@@ -113,9 +113,13 @@ class TunnelMessageController extends Controller
|
||||
$host .= ":{$this->configuration->port()}";
|
||||
}
|
||||
|
||||
$request->headers->set('Host', $controlConnection->host);
|
||||
$exposeUrl = parse_url($controlConnection->host);
|
||||
|
||||
$request->headers->set('Host', "{$controlConnection->subdomain}.{$host}");
|
||||
$request->headers->set('X-Forwarded-Proto', $request->isSecure() ? 'https' : 'http');
|
||||
$request->headers->set('X-Expose-Request-ID', uniqid());
|
||||
$request->headers->set('X-Expose-Request-ID', sha1(uniqid('', true)));
|
||||
$request->headers->set('X-Expose-Host', sprintf('%s:%s', $exposeUrl['host'], $exposeUrl['port']));
|
||||
$request->headers->set('X-Expose-Proto', $exposeUrl['scheme']);
|
||||
$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', "{$controlConnection->subdomain}.{$host}");
|
||||
|
||||
@@ -17,6 +17,12 @@ The configuration file will be written to your home directory inside a `.expose`
|
||||
|
||||
`~/.expose/config.php`
|
||||
|
||||
You can also provide a custom location of the config file by providing the full path as a server variable.
|
||||
|
||||
```bash
|
||||
EXPOSE_CONFIG_FILE="~/my-custom-config.php" expose share
|
||||
```
|
||||
|
||||
And the default content of the configuration file is this:
|
||||
|
||||
```php
|
||||
|
||||
Reference in New Issue
Block a user