Skip to content

Commit 3b11ba9

Browse files
committed
Basic support for installation process
1 parent f609271 commit 3b11ba9

File tree

6 files changed

+76
-11
lines changed

6 files changed

+76
-11
lines changed

app/Http/Controllers/Api/Client/Servers/WebsocketController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function __invoke(Request $request, Server $server)
6767
'connect',
6868
'send-command',
6969
'send-power',
70-
], $request->user()->root_admin ? ['receive-errors'] : []))
70+
], $request->user()->root_admin ? ['receive-errors', 'receive-install'] : []))
7171
->getToken($signer, new Key($server->node->daemonSecret));
7272

7373
$socket = str_replace(['https://', 'http://'], ['wss://', 'ws://'], $server->node->getConnectionAddress());
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
namespace Pterodactyl\Http\Controllers\Api\Remote\Servers;
4+
5+
use Illuminate\Http\Request;
6+
use Illuminate\Http\JsonResponse;
7+
use Pterodactyl\Http\Controllers\Controller;
8+
use Pterodactyl\Repositories\Eloquent\ServerRepository;
9+
10+
class ServerInstallController extends Controller
11+
{
12+
/**
13+
* @var \Pterodactyl\Repositories\Eloquent\ServerRepository
14+
*/
15+
private $repository;
16+
17+
/**
18+
* ServerInstallController constructor.
19+
*
20+
* @param \Pterodactyl\Repositories\Eloquent\ServerRepository $repository
21+
*/
22+
public function __construct(ServerRepository $repository)
23+
{
24+
$this->repository = $repository;
25+
}
26+
27+
/**
28+
* Returns installation information for a server.
29+
*
30+
* @param \Illuminate\Http\Request $request
31+
* @param string $uuid
32+
* @return \Illuminate\Http\JsonResponse
33+
*
34+
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
35+
*/
36+
public function __invoke(Request $request, string $uuid)
37+
{
38+
$server = $this->repository->getByUuid($uuid);
39+
$egg = $server->egg;
40+
41+
return JsonResponse::create([
42+
'container_image' => $egg->copy_script_container,
43+
'entrypoint' => $egg->copy_script_entry,
44+
'script' => $egg->copy_script_install,
45+
]);
46+
}
47+
}

app/Models/Pack.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,22 @@
44

55
use Pterodactyl\Models\Traits\Searchable;
66

7+
/**
8+
* @property int $id
9+
* @property int $egg_id
10+
* @property string $uuid
11+
* @property string $name
12+
* @property string $version
13+
* @property string $description
14+
* @property bool $selectable
15+
* @property bool $visible
16+
* @property bool $locked
17+
* @property \Carbon\Carbon $created_at
18+
* @property \Carbon\Carbon $updated_at
19+
*
20+
* @property \Pterodactyl\Models\Egg|null $egg
21+
* @property \Illuminate\Database\Eloquent\Collection|\Pterodactyl\Models\Server[] $servers
22+
*/
723
class Pack extends Validable
824
{
925
use Searchable;

app/Models/Server.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,11 +253,11 @@ public function nest()
253253
/**
254254
* Gets information for the egg associated with this server.
255255
*
256-
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
256+
* @return \Illuminate\Database\Eloquent\Relations\HasOne
257257
*/
258258
public function egg()
259259
{
260-
return $this->belongsTo(Egg::class);
260+
return $this->hasOne(Egg::class, 'id', 'egg_id');
261261
}
262262

263263
/**

resources/scripts/components/server/Console.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,21 +47,22 @@ const TerminalDiv = styled.div`
4747
`;
4848

4949
export default () => {
50+
const TERMINAL_PRELUDE = '\u001b[1m\u001b[33mcontainer@pterodactyl~ \u001b[0m';
5051
const [ terminalElement, setTerminalElement ] = useState<HTMLDivElement | null>(null);
5152
const useRef = useCallback(node => setTerminalElement(node), []);
5253
const terminal = useMemo(() => new Terminal({ ...terminalProps }), []);
5354
const { connected, instance } = ServerContext.useStoreState(state => state.socket);
5455

55-
const handleConsoleOutput = (line: string) => terminal.writeln(
56-
line.replace(/(?:\r\n|\r|\n)$/im, '') + '\u001b[0m',
56+
const handleConsoleOutput = (line: string, prelude = false) => terminal.writeln(
57+
(prelude ? TERMINAL_PRELUDE : '') + line.replace(/(?:\r\n|\r|\n)$/im, '') + '\u001b[0m',
5758
);
5859

5960
const handleDaemonErrorOutput = (line: string) => terminal.writeln(
60-
'\u001b[1m\u001b[41m[Internal] ' + line.replace(/(?:\r\n|\r|\n)$/im, '') + '\u001b[0m',
61+
TERMINAL_PRELUDE + '\u001b[1m\u001b[41m' + line.replace(/(?:\r\n|\r|\n)$/im, '') + '\u001b[0m',
6162
);
6263

6364
const handlePowerChangeEvent = (state: string) => terminal.writeln(
64-
'\u001b[1m\u001b[33m[Status Change] Server marked as ' + state + '...\u001b[0m',
65+
TERMINAL_PRELUDE + 'Server marked as ' + state + '...\u001b[0m',
6566
);
6667

6768
const handleCommandKeydown = (e: React.KeyboardEvent<HTMLInputElement>) => {
@@ -89,12 +90,16 @@ export default () => {
8990

9091
instance.addListener('status', handlePowerChangeEvent);
9192
instance.addListener('console output', handleConsoleOutput);
93+
instance.addListener('install output', handleConsoleOutput);
94+
instance.addListener('daemon message', line => handleConsoleOutput(line, true));
9295
instance.addListener('daemon error', handleDaemonErrorOutput);
9396
instance.send('send logs');
9497
}
9598

9699
return () => {
97100
instance && instance.removeListener('console output', handleConsoleOutput)
101+
.removeListener('install output', handleConsoleOutput)
102+
.removeListener('daemon message', line => handleConsoleOutput(line, true))
98103
.removeListener('daemon error', handleDaemonErrorOutput)
99104
.removeListener('status', handlePowerChangeEvent);
100105
};

routes/api-remote.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,9 @@
55
Route::get('/authenticate/{token}', 'ValidateKeyController@index');
66
Route::post('/download-file', 'FileDownloadController@index');
77

8-
Route::group(['prefix' => '/scripts'], function () {
9-
Route::get('/{uuid}', 'EggInstallController@index')->name('api.remote.scripts');
10-
});
11-
128
// Routes for the Wings daemon.
139
Route::post('/sftp/auth', 'SftpAuthenticationController');
1410
Route::group(['prefix' => '/servers/{uuid}'], function () {
1511
Route::get('/', 'Servers\ServerDetailsController');
12+
Route::get('/install', 'Servers\ServerInstallController');
1613
});

0 commit comments

Comments
 (0)