mirror of
https://github.com/bitinflow/expose.git
synced 2026-03-17 07:25:54 +00:00
wip
This commit is contained in:
83
app/Commands/ClearDefaultDomainCommand.php
Normal file
83
app/Commands/ClearDefaultDomainCommand.php
Normal file
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
namespace App\Commands;
|
||||
|
||||
use App\Client\Support\ClearDomainNodeVisitor;
|
||||
use App\Client\Support\DefaultDomainNodeVisitor;
|
||||
use App\Client\Support\DefaultServerNodeVisitor;
|
||||
use App\Client\Support\InsertDefaultDomainNodeVisitor;
|
||||
use Illuminate\Console\Command;
|
||||
use PhpParser\Lexer\Emulative;
|
||||
use PhpParser\Node;
|
||||
use PhpParser\NodeFinder;
|
||||
use PhpParser\NodeTraverser;
|
||||
use PhpParser\NodeVisitor\CloningVisitor;
|
||||
use PhpParser\Parser\Php7;
|
||||
use PhpParser\PrettyPrinter\Standard;
|
||||
|
||||
class ClearDefaultDomainCommand extends Command
|
||||
{
|
||||
protected $signature = 'default-domain:clear';
|
||||
|
||||
protected $description = 'Clear the default domain to use with Expose.';
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$this->info('Clearing the default Expose domain.');
|
||||
|
||||
$configFile = implode(DIRECTORY_SEPARATOR, [
|
||||
$_SERVER['HOME'] ?? $_SERVER['USERPROFILE'],
|
||||
'.expose',
|
||||
'config.php',
|
||||
]);
|
||||
|
||||
if (! file_exists($configFile)) {
|
||||
@mkdir(dirname($configFile), 0777, true);
|
||||
$updatedConfigFile = $this->modifyConfigurationFile(base_path('config/expose.php'));
|
||||
} else {
|
||||
$updatedConfigFile = $this->modifyConfigurationFile($configFile);
|
||||
}
|
||||
|
||||
file_put_contents($configFile, $updatedConfigFile);
|
||||
}
|
||||
|
||||
protected function modifyConfigurationFile(string $configFile)
|
||||
{
|
||||
$lexer = new Emulative([
|
||||
'usedAttributes' => [
|
||||
'comments',
|
||||
'startLine', 'endLine',
|
||||
'startTokenPos', 'endTokenPos',
|
||||
],
|
||||
]);
|
||||
$parser = new Php7($lexer);
|
||||
|
||||
$oldStmts = $parser->parse(file_get_contents($configFile));
|
||||
$oldTokens = $lexer->getTokens();
|
||||
|
||||
$nodeTraverser = new NodeTraverser;
|
||||
$nodeTraverser->addVisitor(new CloningVisitor());
|
||||
$newStmts = $nodeTraverser->traverse($oldStmts);
|
||||
|
||||
$nodeFinder = new NodeFinder;
|
||||
|
||||
$defaultDomainNode = $nodeFinder->findFirst($newStmts, function(Node $node) {
|
||||
return ($node instanceof Node\Expr\ArrayItem && $node->key && $node->key->value === 'default_domain');
|
||||
});
|
||||
|
||||
if (is_null($defaultDomainNode)) {
|
||||
$nodeTraverser = new NodeTraverser;
|
||||
$nodeTraverser->addVisitor(new InsertDefaultDomainNodeVisitor());
|
||||
$newStmts = $nodeTraverser->traverse($newStmts);
|
||||
}
|
||||
|
||||
$nodeTraverser = new NodeTraverser;
|
||||
$nodeTraverser->addVisitor(new ClearDomainNodeVisitor());
|
||||
|
||||
$newStmts = $nodeTraverser->traverse($newStmts);
|
||||
|
||||
$prettyPrinter = new Standard();
|
||||
|
||||
return $prettyPrinter->printFormatPreserving($newStmts, $oldStmts, $oldTokens);
|
||||
}
|
||||
}
|
||||
@@ -14,13 +14,13 @@ abstract class ServerAwareCommand extends Command
|
||||
{
|
||||
const DEFAULT_HOSTNAME = 'sharedwithexpose.com';
|
||||
const DEFAULT_PORT = 443;
|
||||
const DEFAULT_SERVER_ENDPOINT = 'https://beyondco.de/api/expose/servers';
|
||||
const DEFAULT_SERVER_ENDPOINT = 'https://expose.beyondco.de/api/servers';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$inheritedSignature = '{--server=default} {--server-host=} {--server-port=}';
|
||||
$inheritedSignature = '{--server=} {--server-host=} {--server-port=}';
|
||||
|
||||
$this->getDefinition()->addOptions(Parser::parse($inheritedSignature)[2]);
|
||||
|
||||
@@ -51,7 +51,7 @@ abstract class ServerAwareCommand extends Command
|
||||
return static::DEFAULT_HOSTNAME;
|
||||
}
|
||||
|
||||
$server = $this->option('server');
|
||||
$server = $this->option('server') ?? config('expose.default_server');
|
||||
$host = config('expose.servers.'.$server.'.host');
|
||||
|
||||
if (! is_null($host)) {
|
||||
@@ -76,7 +76,7 @@ abstract class ServerAwareCommand extends Command
|
||||
return static::DEFAULT_PORT;
|
||||
}
|
||||
|
||||
$server = $this->option('server');
|
||||
$server = $this->option('server') ?? config('expose.default_server');
|
||||
$host = config('expose.servers.'.$server.'.port');
|
||||
|
||||
if (! is_null($host)) {
|
||||
|
||||
98
app/Commands/SetDefaultDomainCommand.php
Normal file
98
app/Commands/SetDefaultDomainCommand.php
Normal file
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
|
||||
namespace App\Commands;
|
||||
|
||||
use App\Client\Support\DefaultDomainNodeVisitor;
|
||||
use App\Client\Support\DefaultServerNodeVisitor;
|
||||
use App\Client\Support\InsertDefaultDomainNodeVisitor;
|
||||
use Illuminate\Console\Command;
|
||||
use PhpParser\Lexer\Emulative;
|
||||
use PhpParser\Node;
|
||||
use PhpParser\NodeFinder;
|
||||
use PhpParser\NodeTraverser;
|
||||
use PhpParser\NodeVisitor\CloningVisitor;
|
||||
use PhpParser\Parser\Php7;
|
||||
use PhpParser\PrettyPrinter\Standard;
|
||||
|
||||
class SetDefaultDomainCommand extends Command
|
||||
{
|
||||
protected $signature = 'default-domain {domain?} {--server=}';
|
||||
|
||||
protected $description = 'Set or retrieve the default domain to use with Expose.';
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$domain = $this->argument('domain');
|
||||
$server = $this->option('server');
|
||||
if (! is_null($domain)) {
|
||||
$this->info('Setting the Expose default domain to "'.$domain.'"');
|
||||
|
||||
$configFile = implode(DIRECTORY_SEPARATOR, [
|
||||
$_SERVER['HOME'] ?? $_SERVER['USERPROFILE'],
|
||||
'.expose',
|
||||
'config.php',
|
||||
]);
|
||||
|
||||
if (! file_exists($configFile)) {
|
||||
@mkdir(dirname($configFile), 0777, true);
|
||||
$updatedConfigFile = $this->modifyConfigurationFile(base_path('config/expose.php'), $domain, $server);
|
||||
} else {
|
||||
$updatedConfigFile = $this->modifyConfigurationFile($configFile, $domain, $server);
|
||||
}
|
||||
|
||||
file_put_contents($configFile, $updatedConfigFile);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (is_null($domain = config('expose.default_domain'))) {
|
||||
$this->info('There is no default domain specified.');
|
||||
} else {
|
||||
$this->info('Current default domain: '.$domain);
|
||||
}
|
||||
}
|
||||
|
||||
protected function modifyConfigurationFile(string $configFile, string $domain, ?string $server)
|
||||
{
|
||||
$lexer = new Emulative([
|
||||
'usedAttributes' => [
|
||||
'comments',
|
||||
'startLine', 'endLine',
|
||||
'startTokenPos', 'endTokenPos',
|
||||
],
|
||||
]);
|
||||
$parser = new Php7($lexer);
|
||||
|
||||
$oldStmts = $parser->parse(file_get_contents($configFile));
|
||||
$oldTokens = $lexer->getTokens();
|
||||
|
||||
$nodeTraverser = new NodeTraverser;
|
||||
$nodeTraverser->addVisitor(new CloningVisitor());
|
||||
$newStmts = $nodeTraverser->traverse($oldStmts);
|
||||
|
||||
$nodeFinder = new NodeFinder;
|
||||
|
||||
$defaultDomainNode = $nodeFinder->findFirst($newStmts, function(Node $node) {
|
||||
return ($node instanceof Node\Expr\ArrayItem && $node->key && $node->key->value === 'default_domain');
|
||||
});
|
||||
|
||||
if (is_null($defaultDomainNode)) {
|
||||
$nodeTraverser = new NodeTraverser;
|
||||
$nodeTraverser->addVisitor(new InsertDefaultDomainNodeVisitor());
|
||||
$newStmts = $nodeTraverser->traverse($newStmts);
|
||||
}
|
||||
|
||||
$nodeTraverser = new NodeTraverser;
|
||||
$nodeTraverser->addVisitor(new DefaultDomainNodeVisitor($domain));
|
||||
|
||||
if (! is_null($server)) {
|
||||
$nodeTraverser->addVisitor(new DefaultServerNodeVisitor($server));
|
||||
}
|
||||
|
||||
$newStmts = $nodeTraverser->traverse($newStmts);
|
||||
|
||||
$prettyPrinter = new Standard();
|
||||
|
||||
return $prettyPrinter->printFormatPreserving($newStmts, $oldStmts, $oldTokens);
|
||||
}
|
||||
}
|
||||
94
app/Commands/SetDefaultServerCommand.php
Normal file
94
app/Commands/SetDefaultServerCommand.php
Normal file
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
|
||||
namespace App\Commands;
|
||||
|
||||
use App\Client\Support\DefaultDomainNodeVisitor;
|
||||
use App\Client\Support\DefaultServerNodeVisitor;
|
||||
use App\Client\Support\InsertDefaultDomainNodeVisitor;
|
||||
use App\Client\Support\InsertDefaultServerNodeVisitor;
|
||||
use Illuminate\Console\Command;
|
||||
use PhpParser\Lexer\Emulative;
|
||||
use PhpParser\Node;
|
||||
use PhpParser\NodeFinder;
|
||||
use PhpParser\NodeTraverser;
|
||||
use PhpParser\NodeVisitor\CloningVisitor;
|
||||
use PhpParser\Parser\Php7;
|
||||
use PhpParser\PrettyPrinter\Standard;
|
||||
|
||||
class SetDefaultServerCommand extends Command
|
||||
{
|
||||
protected $signature = 'default-server {server?}';
|
||||
|
||||
protected $description = 'Set or retrieve the default server to use with Expose.';
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$server = $this->argument('server');
|
||||
if (! is_null($server)) {
|
||||
$this->info('Setting the Expose default server to "'.$server.'"');
|
||||
|
||||
$configFile = implode(DIRECTORY_SEPARATOR, [
|
||||
$_SERVER['HOME'] ?? $_SERVER['USERPROFILE'],
|
||||
'.expose',
|
||||
'config.php',
|
||||
]);
|
||||
|
||||
if (! file_exists($configFile)) {
|
||||
@mkdir(dirname($configFile), 0777, true);
|
||||
$updatedConfigFile = $this->modifyConfigurationFile(base_path('config/expose.php'), $server);
|
||||
} else {
|
||||
$updatedConfigFile = $this->modifyConfigurationFile($configFile, $server);
|
||||
}
|
||||
|
||||
file_put_contents($configFile, $updatedConfigFile);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (is_null($server = config('expose.default_server'))) {
|
||||
$this->info('There is no default server specified.');
|
||||
} else {
|
||||
$this->info('Current default server: '.$server);
|
||||
}
|
||||
}
|
||||
|
||||
protected function modifyConfigurationFile(string $configFile, string $server)
|
||||
{
|
||||
$lexer = new Emulative([
|
||||
'usedAttributes' => [
|
||||
'comments',
|
||||
'startLine', 'endLine',
|
||||
'startTokenPos', 'endTokenPos',
|
||||
],
|
||||
]);
|
||||
$parser = new Php7($lexer);
|
||||
|
||||
$oldStmts = $parser->parse(file_get_contents($configFile));
|
||||
$oldTokens = $lexer->getTokens();
|
||||
|
||||
$nodeTraverser = new NodeTraverser;
|
||||
$nodeTraverser->addVisitor(new CloningVisitor());
|
||||
$newStmts = $nodeTraverser->traverse($oldStmts);
|
||||
|
||||
$nodeFinder = new NodeFinder;
|
||||
|
||||
$defaultServerNode = $nodeFinder->findFirst($newStmts, function(Node $node) {
|
||||
return ($node instanceof Node\Expr\ArrayItem && $node->key && $node->key->value === 'default_server');
|
||||
});
|
||||
|
||||
if (is_null($defaultServerNode)) {
|
||||
$nodeTraverser = new NodeTraverser;
|
||||
$nodeTraverser->addVisitor(new InsertDefaultServerNodeVisitor());
|
||||
$newStmts = $nodeTraverser->traverse($newStmts);
|
||||
}
|
||||
|
||||
$nodeTraverser = new NodeTraverser;
|
||||
$nodeTraverser->addVisitor(new DefaultServerNodeVisitor($server));
|
||||
|
||||
$newStmts = $nodeTraverser->traverse($newStmts);
|
||||
|
||||
$prettyPrinter = new Standard();
|
||||
|
||||
return $prettyPrinter->printFormatPreserving($newStmts, $oldStmts, $oldTokens);
|
||||
}
|
||||
}
|
||||
@@ -23,6 +23,16 @@ class ShareCommand extends ServerAwareCommand
|
||||
config(['expose.dns' => empty($this->option('dns')) ? true : $this->option('dns')]);
|
||||
}
|
||||
|
||||
$domain = config('expose.default_domain');
|
||||
|
||||
if (! is_null($this->option('server'))) {
|
||||
$domain = null;
|
||||
}
|
||||
|
||||
if (! is_null($this->option('domain'))) {
|
||||
$domain = $this->option('domain');
|
||||
}
|
||||
|
||||
(new Factory())
|
||||
->setLoop(app(LoopInterface::class))
|
||||
->setHost($this->getServerHost())
|
||||
@@ -32,7 +42,7 @@ class ShareCommand extends ServerAwareCommand
|
||||
->share(
|
||||
$this->argument('host'),
|
||||
explode(',', $this->option('subdomain')),
|
||||
$this->option('domain')
|
||||
$domain
|
||||
)
|
||||
->createHttpServer()
|
||||
->run();
|
||||
|
||||
@@ -14,7 +14,7 @@ class StoreAuthenticationTokenCommand extends Command
|
||||
{
|
||||
protected $signature = 'token {token?}';
|
||||
|
||||
protected $description = 'Set or retrieve the authentication token to use with expose.';
|
||||
protected $description = 'Set or retrieve the authentication token to use with Expose.';
|
||||
|
||||
public function handle()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user