2022-05-14 01:30:16 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Pterodactyl\Console\Commands\Node;
|
|
|
|
|
|
|
|
use Pterodactyl\Models\Node;
|
|
|
|
use Illuminate\Console\Command;
|
|
|
|
|
|
|
|
class NodeConfigurationCommand extends Command
|
|
|
|
{
|
|
|
|
protected $signature = 'p:node:configuration
|
|
|
|
{node : The ID or UUID of the node to return the configuration for.}
|
|
|
|
{--format=yaml : The output format. Options are "yaml" and "json".}';
|
|
|
|
|
|
|
|
protected $description = 'Displays the configuration for the specified node.';
|
|
|
|
|
2022-10-14 16:59:20 +00:00
|
|
|
public function handle(): int
|
2022-05-14 01:30:16 +00:00
|
|
|
{
|
2022-05-14 01:49:06 +00:00
|
|
|
$column = ctype_digit((string) $this->argument('node')) ? 'id' : 'uuid';
|
|
|
|
|
2022-05-14 01:30:16 +00:00
|
|
|
/** @var \Pterodactyl\Models\Node $node */
|
2022-05-14 01:49:06 +00:00
|
|
|
$node = Node::query()->where($column, $this->argument('node'))->firstOr(function () {
|
|
|
|
$this->error('The selected node does not exist.');
|
|
|
|
|
|
|
|
exit(1);
|
|
|
|
});
|
2022-05-14 01:30:16 +00:00
|
|
|
|
|
|
|
$format = $this->option('format');
|
|
|
|
if (!in_array($format, ['yaml', 'yml', 'json'])) {
|
|
|
|
$this->error('Invalid format specified. Valid options are "yaml" and "json".');
|
|
|
|
|
2022-10-14 16:59:20 +00:00
|
|
|
return 1;
|
2022-05-14 01:30:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($format === 'json') {
|
|
|
|
$this->output->write($node->getJsonConfiguration(true));
|
|
|
|
} else {
|
|
|
|
$this->output->write($node->getYamlConfiguration());
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->output->newLine();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|