Basic support for installation process
This commit is contained in:
parent
f609271c35
commit
3b11ba9fca
6 changed files with 76 additions and 11 deletions
|
@ -67,7 +67,7 @@ class WebsocketController extends ClientApiController
|
||||||
'connect',
|
'connect',
|
||||||
'send-command',
|
'send-command',
|
||||||
'send-power',
|
'send-power',
|
||||||
], $request->user()->root_admin ? ['receive-errors'] : []))
|
], $request->user()->root_admin ? ['receive-errors', 'receive-install'] : []))
|
||||||
->getToken($signer, new Key($server->node->daemonSecret));
|
->getToken($signer, new Key($server->node->daemonSecret));
|
||||||
|
|
||||||
$socket = str_replace(['https://', 'http://'], ['wss://', 'ws://'], $server->node->getConnectionAddress());
|
$socket = str_replace(['https://', 'http://'], ['wss://', 'ws://'], $server->node->getConnectionAddress());
|
||||||
|
|
|
@ -0,0 +1,47 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Pterodactyl\Http\Controllers\Api\Remote\Servers;
|
||||||
|
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Http\JsonResponse;
|
||||||
|
use Pterodactyl\Http\Controllers\Controller;
|
||||||
|
use Pterodactyl\Repositories\Eloquent\ServerRepository;
|
||||||
|
|
||||||
|
class ServerInstallController extends Controller
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var \Pterodactyl\Repositories\Eloquent\ServerRepository
|
||||||
|
*/
|
||||||
|
private $repository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ServerInstallController constructor.
|
||||||
|
*
|
||||||
|
* @param \Pterodactyl\Repositories\Eloquent\ServerRepository $repository
|
||||||
|
*/
|
||||||
|
public function __construct(ServerRepository $repository)
|
||||||
|
{
|
||||||
|
$this->repository = $repository;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns installation information for a server.
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Http\Request $request
|
||||||
|
* @param string $uuid
|
||||||
|
* @return \Illuminate\Http\JsonResponse
|
||||||
|
*
|
||||||
|
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||||
|
*/
|
||||||
|
public function __invoke(Request $request, string $uuid)
|
||||||
|
{
|
||||||
|
$server = $this->repository->getByUuid($uuid);
|
||||||
|
$egg = $server->egg;
|
||||||
|
|
||||||
|
return JsonResponse::create([
|
||||||
|
'container_image' => $egg->copy_script_container,
|
||||||
|
'entrypoint' => $egg->copy_script_entry,
|
||||||
|
'script' => $egg->copy_script_install,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,6 +4,22 @@ namespace Pterodactyl\Models;
|
||||||
|
|
||||||
use Pterodactyl\Models\Traits\Searchable;
|
use Pterodactyl\Models\Traits\Searchable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @property int $id
|
||||||
|
* @property int $egg_id
|
||||||
|
* @property string $uuid
|
||||||
|
* @property string $name
|
||||||
|
* @property string $version
|
||||||
|
* @property string $description
|
||||||
|
* @property bool $selectable
|
||||||
|
* @property bool $visible
|
||||||
|
* @property bool $locked
|
||||||
|
* @property \Carbon\Carbon $created_at
|
||||||
|
* @property \Carbon\Carbon $updated_at
|
||||||
|
*
|
||||||
|
* @property \Pterodactyl\Models\Egg|null $egg
|
||||||
|
* @property \Illuminate\Database\Eloquent\Collection|\Pterodactyl\Models\Server[] $servers
|
||||||
|
*/
|
||||||
class Pack extends Validable
|
class Pack extends Validable
|
||||||
{
|
{
|
||||||
use Searchable;
|
use Searchable;
|
||||||
|
|
|
@ -253,11 +253,11 @@ class Server extends Validable
|
||||||
/**
|
/**
|
||||||
* Gets information for the egg associated with this server.
|
* Gets information for the egg associated with this server.
|
||||||
*
|
*
|
||||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
* @return \Illuminate\Database\Eloquent\Relations\HasOne
|
||||||
*/
|
*/
|
||||||
public function egg()
|
public function egg()
|
||||||
{
|
{
|
||||||
return $this->belongsTo(Egg::class);
|
return $this->hasOne(Egg::class, 'id', 'egg_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -47,21 +47,22 @@ const TerminalDiv = styled.div`
|
||||||
`;
|
`;
|
||||||
|
|
||||||
export default () => {
|
export default () => {
|
||||||
|
const TERMINAL_PRELUDE = '\u001b[1m\u001b[33mcontainer@pterodactyl~ \u001b[0m';
|
||||||
const [ terminalElement, setTerminalElement ] = useState<HTMLDivElement | null>(null);
|
const [ terminalElement, setTerminalElement ] = useState<HTMLDivElement | null>(null);
|
||||||
const useRef = useCallback(node => setTerminalElement(node), []);
|
const useRef = useCallback(node => setTerminalElement(node), []);
|
||||||
const terminal = useMemo(() => new Terminal({ ...terminalProps }), []);
|
const terminal = useMemo(() => new Terminal({ ...terminalProps }), []);
|
||||||
const { connected, instance } = ServerContext.useStoreState(state => state.socket);
|
const { connected, instance } = ServerContext.useStoreState(state => state.socket);
|
||||||
|
|
||||||
const handleConsoleOutput = (line: string) => terminal.writeln(
|
const handleConsoleOutput = (line: string, prelude = false) => terminal.writeln(
|
||||||
line.replace(/(?:\r\n|\r|\n)$/im, '') + '\u001b[0m',
|
(prelude ? TERMINAL_PRELUDE : '') + line.replace(/(?:\r\n|\r|\n)$/im, '') + '\u001b[0m',
|
||||||
);
|
);
|
||||||
|
|
||||||
const handleDaemonErrorOutput = (line: string) => terminal.writeln(
|
const handleDaemonErrorOutput = (line: string) => terminal.writeln(
|
||||||
'\u001b[1m\u001b[41m[Internal] ' + line.replace(/(?:\r\n|\r|\n)$/im, '') + '\u001b[0m',
|
TERMINAL_PRELUDE + '\u001b[1m\u001b[41m' + line.replace(/(?:\r\n|\r|\n)$/im, '') + '\u001b[0m',
|
||||||
);
|
);
|
||||||
|
|
||||||
const handlePowerChangeEvent = (state: string) => terminal.writeln(
|
const handlePowerChangeEvent = (state: string) => terminal.writeln(
|
||||||
'\u001b[1m\u001b[33m[Status Change] Server marked as ' + state + '...\u001b[0m',
|
TERMINAL_PRELUDE + 'Server marked as ' + state + '...\u001b[0m',
|
||||||
);
|
);
|
||||||
|
|
||||||
const handleCommandKeydown = (e: React.KeyboardEvent<HTMLInputElement>) => {
|
const handleCommandKeydown = (e: React.KeyboardEvent<HTMLInputElement>) => {
|
||||||
|
@ -89,12 +90,16 @@ export default () => {
|
||||||
|
|
||||||
instance.addListener('status', handlePowerChangeEvent);
|
instance.addListener('status', handlePowerChangeEvent);
|
||||||
instance.addListener('console output', handleConsoleOutput);
|
instance.addListener('console output', handleConsoleOutput);
|
||||||
|
instance.addListener('install output', handleConsoleOutput);
|
||||||
|
instance.addListener('daemon message', line => handleConsoleOutput(line, true));
|
||||||
instance.addListener('daemon error', handleDaemonErrorOutput);
|
instance.addListener('daemon error', handleDaemonErrorOutput);
|
||||||
instance.send('send logs');
|
instance.send('send logs');
|
||||||
}
|
}
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
instance && instance.removeListener('console output', handleConsoleOutput)
|
instance && instance.removeListener('console output', handleConsoleOutput)
|
||||||
|
.removeListener('install output', handleConsoleOutput)
|
||||||
|
.removeListener('daemon message', line => handleConsoleOutput(line, true))
|
||||||
.removeListener('daemon error', handleDaemonErrorOutput)
|
.removeListener('daemon error', handleDaemonErrorOutput)
|
||||||
.removeListener('status', handlePowerChangeEvent);
|
.removeListener('status', handlePowerChangeEvent);
|
||||||
};
|
};
|
||||||
|
|
|
@ -5,12 +5,9 @@ use Illuminate\Support\Facades\Route;
|
||||||
Route::get('/authenticate/{token}', 'ValidateKeyController@index');
|
Route::get('/authenticate/{token}', 'ValidateKeyController@index');
|
||||||
Route::post('/download-file', 'FileDownloadController@index');
|
Route::post('/download-file', 'FileDownloadController@index');
|
||||||
|
|
||||||
Route::group(['prefix' => '/scripts'], function () {
|
|
||||||
Route::get('/{uuid}', 'EggInstallController@index')->name('api.remote.scripts');
|
|
||||||
});
|
|
||||||
|
|
||||||
// Routes for the Wings daemon.
|
// Routes for the Wings daemon.
|
||||||
Route::post('/sftp/auth', 'SftpAuthenticationController');
|
Route::post('/sftp/auth', 'SftpAuthenticationController');
|
||||||
Route::group(['prefix' => '/servers/{uuid}'], function () {
|
Route::group(['prefix' => '/servers/{uuid}'], function () {
|
||||||
Route::get('/', 'Servers\ServerDetailsController');
|
Route::get('/', 'Servers\ServerDetailsController');
|
||||||
|
Route::get('/install', 'Servers\ServerInstallController');
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue