mirror of
https://github.com/bitinflow/expose.git
synced 2026-03-13 13:35:54 +00:00
wip
This commit is contained in:
@@ -41,7 +41,9 @@ class Client
|
||||
{
|
||||
$token = config('expose.auth_token');
|
||||
|
||||
connect("ws://{$this->configuration->host()}:{$this->configuration->port()}/__expose_control__?authToken={$token}", [], [
|
||||
$protocol = $this->configuration->port() === 443 ? "wss" : "ws";
|
||||
|
||||
connect($protocol."://{$this->configuration->host()}:{$this->configuration->port()}/__expose_control__?authToken={$token}", [], [
|
||||
'X-Expose-Control' => 'enabled',
|
||||
], $this->loop)
|
||||
->then(function (WebSocket $clientConnection) use ($sharedUrl, $subdomain) {
|
||||
@@ -65,8 +67,10 @@ class Client
|
||||
static::$subdomains[] = "$data->subdomain.{$this->configuration->host()}:{$this->configuration->port()}";
|
||||
});
|
||||
|
||||
}, function ($e) {
|
||||
echo "Could not connect: {$e->getMessage()}\n";
|
||||
}, function (\Exception $e) {
|
||||
$this->logger->error("Could not connect to the server.");
|
||||
$this->logger->error($e->getMessage());
|
||||
exit(1);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,6 +34,6 @@ class Configuration
|
||||
|
||||
public function port(): int
|
||||
{
|
||||
return $this->port;
|
||||
return intval($this->port);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,9 @@ class ProxyManager
|
||||
|
||||
public function createProxy(string $clientId, $connectionData)
|
||||
{
|
||||
connect("ws://{$this->configuration->host()}:{$this->configuration->port()}/__expose_control__", [], [
|
||||
$protocol = $this->configuration->port() === 443 ? "wss" : "ws";
|
||||
|
||||
connect($protocol."://{$this->configuration->host()}:{$this->configuration->port()}/__expose_control__", [], [
|
||||
'X-Expose-Control' => 'enabled',
|
||||
], $this->loop)
|
||||
->then(function (WebSocket $proxyConnection) use ($clientId, $connectionData) {
|
||||
|
||||
@@ -30,8 +30,8 @@ class ShareCommand extends Command
|
||||
|
||||
(new Factory())
|
||||
->setLoop(app(LoopInterface::class))
|
||||
// ->setHost('beyond.sh') // TODO: Read from (local/global) config file
|
||||
// ->setPort(8080) // TODO: Read from (local/global) config file
|
||||
->setHost(config('expose.host', 'localhost'))
|
||||
->setPort(config('expose.port', 8080))
|
||||
->setAuth($this->option('auth'))
|
||||
->createClient($this->argument('host'), explode(',', $this->option('subdomain')))
|
||||
->createHttpServer()
|
||||
|
||||
@@ -12,6 +12,8 @@ class ShareCurrentWorkingDirectoryCommand extends ShareCommand
|
||||
{
|
||||
$this->input->setArgument('host', basename(getcwd()).'.test');
|
||||
|
||||
$this->input->setOption('subdomain', basename(getcwd()));
|
||||
|
||||
parent::handle();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,9 @@ namespace App\HttpServer\Controllers;
|
||||
use Exception;
|
||||
use Ratchet\ConnectionInterface;
|
||||
use Ratchet\Http\HttpServerInterface;
|
||||
use Twig\Environment;
|
||||
use Twig\Loader\ArrayLoader;
|
||||
use function GuzzleHttp\Psr7\stream_for;
|
||||
|
||||
abstract class Controller implements HttpServerInterface
|
||||
{
|
||||
@@ -22,4 +25,17 @@ abstract class Controller implements HttpServerInterface
|
||||
public function onMessage(ConnectionInterface $from, $msg)
|
||||
{
|
||||
}
|
||||
|
||||
protected function getView(string $view, array $data)
|
||||
{
|
||||
$templatePath = implode(DIRECTORY_SEPARATOR, explode('.', $view));
|
||||
|
||||
$twig = new Environment(
|
||||
new ArrayLoader([
|
||||
'template' => file_get_contents(base_path('resources/views/'.$templatePath.'.twig')),
|
||||
])
|
||||
);
|
||||
|
||||
return stream_for($twig->render('template', $data));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,19 +16,12 @@ class DashboardController extends Controller
|
||||
str(new Response(
|
||||
200,
|
||||
['Content-Type' => 'text/html'],
|
||||
$this->getView()
|
||||
$this->getView('client.dashboard', [
|
||||
'subdomains' => Client::$subdomains,
|
||||
])
|
||||
))
|
||||
);
|
||||
|
||||
$connection->close();
|
||||
}
|
||||
|
||||
protected function getView(): string
|
||||
{
|
||||
$view = file_get_contents(base_path('resources/views/index.html'));
|
||||
|
||||
$view = str_replace('%subdomains%', implode(' ', Client::$subdomains), $view);
|
||||
|
||||
return $view;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,6 +31,14 @@ class AppServiceProvider extends ServiceProvider
|
||||
|
||||
protected function loadConfigurationFile()
|
||||
{
|
||||
$localConfigFile = getcwd() . DIRECTORY_SEPARATOR . '.expose.php';
|
||||
|
||||
if (file_exists($localConfigFile)) {
|
||||
config()->set('expose', require_once $localConfigFile);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
$configFile = implode(DIRECTORY_SEPARATOR, [
|
||||
$_SERVER['HOME'],
|
||||
'.expose',
|
||||
@@ -39,12 +47,6 @@ class AppServiceProvider extends ServiceProvider
|
||||
|
||||
if (file_exists($configFile)) {
|
||||
config()->set('expose', require_once $configFile);
|
||||
return;
|
||||
}
|
||||
|
||||
$localConfigFile = getcwd() . DIRECTORY_SEPARATOR . '.expose.php';
|
||||
if (file_exists($localConfigFile)) {
|
||||
config()->set('expose', require_once $localConfigFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,9 +80,12 @@ class Factory
|
||||
|
||||
protected function addExposeRoutes()
|
||||
{
|
||||
$wsServer = new WsServer(app(ControlMessageController::class));
|
||||
$wsServer->enableKeepAlive($this->loop);
|
||||
|
||||
$this->routes->add('control',
|
||||
new Route('/__expose_control__', [
|
||||
'_controller' => new WsServer(app(ControlMessageController::class))
|
||||
'_controller' => $wsServer
|
||||
], [], [], null, [], []
|
||||
)
|
||||
);
|
||||
|
||||
@@ -27,18 +27,7 @@ class ListSitesController extends PostController
|
||||
public function handle(Request $request, ConnectionInterface $httpConnection)
|
||||
{
|
||||
$httpConnection->send(
|
||||
respond_html($this->getView(['sites' => $this->connectionManager->getConnections()]))
|
||||
respond_html($this->getView('server.sites.index', ['sites' => $this->connectionManager->getConnections()]))
|
||||
);
|
||||
}
|
||||
|
||||
protected function getView(array $data)
|
||||
{
|
||||
$twig = new Environment(
|
||||
new ArrayLoader([
|
||||
'template' => file_get_contents(base_path('resources/views/admin/sites/index.twig')),
|
||||
])
|
||||
);
|
||||
|
||||
return stream_for($twig->render('template', $data));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ class ListUsersController extends PostController
|
||||
{
|
||||
$this->database->query('SELECT * FROM users ORDER by created_at DESC')->then(function (Result $result) use ($httpConnection) {
|
||||
$httpConnection->send(
|
||||
respond_html($this->getView(['users' => $result->rows]))
|
||||
respond_html($this->getView('server.users.index', ['users' => $result->rows]))
|
||||
);
|
||||
|
||||
$httpConnection->close();
|
||||
@@ -39,15 +39,4 @@ class ListUsersController extends PostController
|
||||
$httpConnection->close();
|
||||
});
|
||||
}
|
||||
|
||||
protected function getView(array $data)
|
||||
{
|
||||
$twig = new Environment(
|
||||
new ArrayLoader([
|
||||
'template' => file_get_contents(base_path('resources/views/admin/users/index.twig')),
|
||||
])
|
||||
);
|
||||
|
||||
return stream_for($twig->render('template', $data));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,11 +3,6 @@
|
||||
use GuzzleHttp\Psr7\Response;
|
||||
use function GuzzleHttp\Psr7\str;
|
||||
|
||||
function expose_view_path(string $path = '')
|
||||
{
|
||||
return base_path('resources/views/' . $path);
|
||||
}
|
||||
|
||||
function respond_json($responseData, int $statusCode = 200)
|
||||
{
|
||||
return str(new Response(
|
||||
|
||||
Reference in New Issue
Block a user