Dashboard UI updates, allow multiple expose servers, exclude subdomains

This commit is contained in:
Marcel Pociot
2021-05-19 20:21:19 +02:00
parent c1f7125f72
commit db57f83bdf
8 changed files with 150 additions and 99 deletions

View File

@@ -0,0 +1,42 @@
<?php
namespace App\Commands;
use App\Logger\CliRequestLogger;
use Illuminate\Console\Parser;
use LaravelZero\Framework\Commands\Command;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\ConsoleOutput;
abstract class ServerAwareCommand extends Command
{
public function __construct()
{
parent::__construct();
$inheritedSignature = '{--server=default} {--server-host=} {--server-port=}';
$this->getDefinition()->addOptions(Parser::parse($inheritedSignature)[2]);
$this->configureConnectionLogger();
}
protected function configureConnectionLogger()
{
app()->bind(CliRequestLogger::class, function () {
return new CliRequestLogger(new ConsoleOutput());
});
return $this;
}
protected function getServerHost()
{
return $this->option('server-host') ?? config('expose.servers.'.$this->option('server').'.host', 'localhost');
}
protected function getServerPort()
{
return $this->option('server-port') ?? config('expose.servers.'.$this->option('server').'.port', 8080);
}
}

View File

@@ -4,31 +4,17 @@ namespace App\Commands;
use App\Client\Factory;
use App\Logger\CliRequestLogger;
use LaravelZero\Framework\Commands\Command;
use React\EventLoop\LoopInterface;
use Symfony\Component\Console\Output\ConsoleOutput;
class ShareCommand extends Command
class ShareCommand extends ServerAwareCommand
{
protected $signature = 'share {host} {--subdomain=} {--auth=} {--server-host=} {--server-port=} {--dns=}';
protected $signature = 'share {host} {--subdomain=} {--auth=} {--dns=}';
protected $description = 'Share a local url with a remote expose server';
protected function configureConnectionLogger()
{
app()->bind(CliRequestLogger::class, function () {
return new CliRequestLogger(new ConsoleOutput());
});
return $this;
}
public function handle()
{
$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', '');
if (strstr($this->argument('host'), 'host.docker.internal')) {
@@ -41,8 +27,8 @@ class ShareCommand extends Command
(new Factory())
->setLoop(app(LoopInterface::class))
->setHost($serverHost)
->setPort($serverPort)
->setHost($this->getServerHost())
->setPort($this->getServerPort())
->setAuth($auth)
->createClient()
->share($this->argument('host'), explode(',', $this->option('subdomain')))

View File

@@ -4,7 +4,7 @@ namespace App\Commands;
class ShareCurrentWorkingDirectoryCommand extends ShareCommand
{
protected $signature = 'share-cwd {host?} {--subdomain=} {--auth=} {--server-host=} {--server-port=}';
protected $signature = 'share-cwd {host?} {--subdomain=} {--auth=}';
public function handle()
{

View File

@@ -8,37 +8,24 @@ use LaravelZero\Framework\Commands\Command;
use React\EventLoop\LoopInterface;
use Symfony\Component\Console\Output\ConsoleOutput;
class ShareFilesCommand extends Command
class ShareFilesCommand extends ServerAwareCommand
{
protected $signature = 'share-files {folder=.} {--name=} {--subdomain=} {--auth=} {--server-host=} {--server-port=}';
protected $signature = 'share-files {folder=.} {--name=} {--subdomain=} {--auth=}';
protected $description = 'Share a local folder with a remote expose server';
protected function configureConnectionLogger()
{
app()->bind(CliRequestLogger::class, function () {
return new CliRequestLogger(new ConsoleOutput());
});
return $this;
}
public function handle()
{
if (! is_dir($this->argument('folder'))) {
throw new \InvalidArgumentException('The folder '.$this->argument('folder').' does not exist.');
}
$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($serverHost)
->setPort($serverPort)
->setHost($this->getServerHost())
->setPort($this->getServerPort())
->setAuth($auth)
->createClient()
->shareFolder(

View File

@@ -3,36 +3,22 @@
namespace App\Commands;
use App\Client\Factory;
use App\Logger\CliRequestLogger;
use LaravelZero\Framework\Commands\Command;
use React\EventLoop\LoopInterface;
use Symfony\Component\Console\Output\ConsoleOutput;
class SharePortCommand extends Command
class SharePortCommand extends ServerAwareCommand
{
protected $signature = 'share-port {port} {--auth=}';
protected $description = 'Share a local port with a remote expose server';
protected function configureConnectionLogger()
{
app()->bind(CliRequestLogger::class, function () {
return new CliRequestLogger(new ConsoleOutput());
});
return $this;
}
public function handle()
{
$this->configureConnectionLogger();
$auth = $this->option('auth') ?? config('expose.auth_token', '');
(new Factory())
->setLoop(app(LoopInterface::class))
->setHost(config('expose.host', 'localhost'))
->setPort(config('expose.port', 8080))
->setHost($this->getServerHost())
->setPort($this->getServerPort())
->setAuth($auth)
->createClient()
->sharePort($this->argument('port'))