Add support for client-side server reinstallation
This commit is contained in:
parent
86de7372a8
commit
85e3945cd7
|
@ -4,9 +4,12 @@ namespace Pterodactyl\Http\Controllers\Api\Client\Servers;
|
||||||
|
|
||||||
use Illuminate\Http\Response;
|
use Illuminate\Http\Response;
|
||||||
use Pterodactyl\Models\Server;
|
use Pterodactyl\Models\Server;
|
||||||
|
use Illuminate\Http\JsonResponse;
|
||||||
use Pterodactyl\Repositories\Eloquent\ServerRepository;
|
use Pterodactyl\Repositories\Eloquent\ServerRepository;
|
||||||
|
use Pterodactyl\Services\Servers\ReinstallServerService;
|
||||||
use Pterodactyl\Http\Controllers\Api\Client\ClientApiController;
|
use Pterodactyl\Http\Controllers\Api\Client\ClientApiController;
|
||||||
use Pterodactyl\Http\Requests\Api\Client\Servers\Settings\RenameServerRequest;
|
use Pterodactyl\Http\Requests\Api\Client\Servers\Settings\RenameServerRequest;
|
||||||
|
use Pterodactyl\Http\Requests\Api\Client\Servers\Settings\ReinstallServerRequest;
|
||||||
|
|
||||||
class SettingsController extends ClientApiController
|
class SettingsController extends ClientApiController
|
||||||
{
|
{
|
||||||
|
@ -15,16 +18,25 @@ class SettingsController extends ClientApiController
|
||||||
*/
|
*/
|
||||||
private $repository;
|
private $repository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var \Pterodactyl\Services\Servers\ReinstallServerService
|
||||||
|
*/
|
||||||
|
private $reinstallServerService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SettingsController constructor.
|
* SettingsController constructor.
|
||||||
*
|
*
|
||||||
* @param \Pterodactyl\Repositories\Eloquent\ServerRepository $repository
|
* @param \Pterodactyl\Repositories\Eloquent\ServerRepository $repository
|
||||||
|
* @param \Pterodactyl\Services\Servers\ReinstallServerService $reinstallServerService
|
||||||
*/
|
*/
|
||||||
public function __construct(ServerRepository $repository)
|
public function __construct(
|
||||||
{
|
ServerRepository $repository,
|
||||||
|
ReinstallServerService $reinstallServerService
|
||||||
|
) {
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
|
|
||||||
$this->repository = $repository;
|
$this->repository = $repository;
|
||||||
|
$this->reinstallServerService = $reinstallServerService;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -32,7 +44,7 @@ class SettingsController extends ClientApiController
|
||||||
*
|
*
|
||||||
* @param \Pterodactyl\Http\Requests\Api\Client\Servers\Settings\RenameServerRequest $request
|
* @param \Pterodactyl\Http\Requests\Api\Client\Servers\Settings\RenameServerRequest $request
|
||||||
* @param \Pterodactyl\Models\Server $server
|
* @param \Pterodactyl\Models\Server $server
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\JsonResponse
|
||||||
*
|
*
|
||||||
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
||||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||||
|
@ -43,6 +55,22 @@ class SettingsController extends ClientApiController
|
||||||
'name' => $request->input('name'),
|
'name' => $request->input('name'),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return Response::create('', Response::HTTP_NO_CONTENT);
|
return JsonResponse::create([], Response::HTTP_NO_CONTENT);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reinstalls the server on the daemon.
|
||||||
|
*
|
||||||
|
* @param \Pterodactyl\Http\Requests\Api\Client\Servers\Settings\ReinstallServerRequest $request
|
||||||
|
* @param \Pterodactyl\Models\Server $server
|
||||||
|
* @return \Illuminate\Http\JsonResponse
|
||||||
|
*
|
||||||
|
* @throws \Throwable
|
||||||
|
*/
|
||||||
|
public function reinstall(ReinstallServerRequest $request, Server $server)
|
||||||
|
{
|
||||||
|
$this->reinstallServerService->reinstall($server);
|
||||||
|
|
||||||
|
return JsonResponse::create([], Response::HTTP_ACCEPTED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Pterodactyl\Http\Requests\Api\Client\Servers\Settings;
|
||||||
|
|
||||||
|
use Pterodactyl\Models\Permission;
|
||||||
|
use Pterodactyl\Http\Requests\Api\Client\ClientApiRequest;
|
||||||
|
|
||||||
|
class ReinstallServerRequest extends ClientApiRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function permission()
|
||||||
|
{
|
||||||
|
return Permission::ACTION_SETTINGS_REINSTALL;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
import http from '@/api/http';
|
||||||
|
|
||||||
|
export default (uuid: string): Promise<void> => {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
http.post(`/api/client/servers/${uuid}/settings/reinstall`)
|
||||||
|
.then(() => resolve())
|
||||||
|
.catch(reject);
|
||||||
|
});
|
||||||
|
}
|
|
@ -11,10 +11,6 @@ interface Props {
|
||||||
const Can = ({ action, matchAny = false, renderOnError, children }: Props) => {
|
const Can = ({ action, matchAny = false, renderOnError, children }: Props) => {
|
||||||
const can = usePermissions(action);
|
const can = usePermissions(action);
|
||||||
|
|
||||||
if (matchAny) {
|
|
||||||
console.log('Can.tsx', can);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{
|
{
|
||||||
|
|
|
@ -0,0 +1,63 @@
|
||||||
|
import React, { useState } from 'react';
|
||||||
|
import { ServerContext } from '@/state/server';
|
||||||
|
import SpinnerOverlay from '@/components/elements/SpinnerOverlay';
|
||||||
|
import TitledGreyBox from '@/components/elements/TitledGreyBox';
|
||||||
|
import ConfirmationModal from '@/components/elements/ConfirmationModal';
|
||||||
|
import reinstallServer from '@/api/server/reinstallServer';
|
||||||
|
import { Actions, useStoreActions } from 'easy-peasy';
|
||||||
|
import { ApplicationStore } from '@/state';
|
||||||
|
import { httpErrorToHuman } from '@/api/http';
|
||||||
|
|
||||||
|
export default () => {
|
||||||
|
const uuid = ServerContext.useStoreState(state => state.server.data!.uuid);
|
||||||
|
const [ isSubmitting, setIsSubmitting ] = useState(false);
|
||||||
|
const [ modalVisible, setModalVisible ] = useState(false);
|
||||||
|
const { addFlash, clearFlashes } = useStoreActions((actions: Actions<ApplicationStore>) => actions.flashes);
|
||||||
|
|
||||||
|
const reinstall = () => {
|
||||||
|
clearFlashes('settings');
|
||||||
|
setIsSubmitting(true);
|
||||||
|
reinstallServer(uuid)
|
||||||
|
.then(() => {
|
||||||
|
addFlash({ key: 'settings', type: 'success', message: 'Your server has begun the reinstallation process.' });
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
console.error(error);
|
||||||
|
|
||||||
|
addFlash({ key: 'settings', type: 'error', message: httpErrorToHuman(error) });
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
setIsSubmitting(false);
|
||||||
|
setModalVisible(false);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<TitledGreyBox title={'Reinstall Server'} className={'relative'}>
|
||||||
|
<ConfirmationModal
|
||||||
|
title={'Confirm server reinstallation'}
|
||||||
|
buttonText={'Yes, reinstall server'}
|
||||||
|
onConfirmed={() => reinstall()}
|
||||||
|
showSpinnerOverlay={isSubmitting}
|
||||||
|
visible={modalVisible}
|
||||||
|
onDismissed={() => setModalVisible(false)}
|
||||||
|
>
|
||||||
|
Your server will be stopped and some files may be deleted or modified during this process, are you sure you wish to continue?
|
||||||
|
</ConfirmationModal>
|
||||||
|
<p className={'text-sm'}>
|
||||||
|
Reinstalling your server will stop it, and then re-run the installation script that initially
|
||||||
|
set it up.<strong className={'font-bold'}>Some files may be deleted or modified during this process,
|
||||||
|
please back up your data before continuing.</strong>
|
||||||
|
</p>
|
||||||
|
<div className={'mt-6 text-right'}>
|
||||||
|
<button
|
||||||
|
type={'button'}
|
||||||
|
className={'btn btn-sm btn-secondary btn-red'}
|
||||||
|
onClick={() => setModalVisible(true)}
|
||||||
|
>
|
||||||
|
Reinstall Server
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</TitledGreyBox>
|
||||||
|
);
|
||||||
|
};
|
|
@ -7,6 +7,7 @@ import { UserData } from '@/state/user';
|
||||||
import RenameServerBox from '@/components/server/settings/RenameServerBox';
|
import RenameServerBox from '@/components/server/settings/RenameServerBox';
|
||||||
import FlashMessageRender from '@/components/FlashMessageRender';
|
import FlashMessageRender from '@/components/FlashMessageRender';
|
||||||
import Can from '@/components/elements/Can';
|
import Can from '@/components/elements/Can';
|
||||||
|
import ReinstallServerBox from '@/components/server/settings/ReinstallServerBox';
|
||||||
|
|
||||||
export default () => {
|
export default () => {
|
||||||
const user = useStoreState<ApplicationStore, UserData>(state => state.user.data!);
|
const user = useStoreState<ApplicationStore, UserData>(state => state.user.data!);
|
||||||
|
@ -17,49 +18,56 @@ export default () => {
|
||||||
<FlashMessageRender byKey={'settings'} className={'mb-4'}/>
|
<FlashMessageRender byKey={'settings'} className={'mb-4'}/>
|
||||||
<div className={'md:flex'}>
|
<div className={'md:flex'}>
|
||||||
<Can action={'file.sftp'}>
|
<Can action={'file.sftp'}>
|
||||||
<TitledGreyBox title={'SFTP Details'} className={'w-full md:flex-1 md:max-w-1/2 md:mr-6'}>
|
<div className={'w-full md:flex-1 md:max-w-1/2 md:mr-10'}>
|
||||||
<div>
|
<TitledGreyBox title={'SFTP Details'}>
|
||||||
<label className={'input-dark-label'}>Server Address</label>
|
<div>
|
||||||
<input
|
<label className={'input-dark-label'}>Server Address</label>
|
||||||
type={'text'}
|
<input
|
||||||
className={'input-dark'}
|
type={'text'}
|
||||||
value={`sftp://${server.sftpDetails.ip}:${server.sftpDetails.port}`}
|
className={'input-dark'}
|
||||||
readOnly={true}
|
value={`sftp://${server.sftpDetails.ip}:${server.sftpDetails.port}`}
|
||||||
/>
|
readOnly={true}
|
||||||
</div>
|
/>
|
||||||
<div className={'mt-6'}>
|
</div>
|
||||||
<label className={'input-dark-label'}>Username</label>
|
<div className={'mt-6'}>
|
||||||
<input
|
<label className={'input-dark-label'}>Username</label>
|
||||||
type={'text'}
|
<input
|
||||||
className={'input-dark'}
|
type={'text'}
|
||||||
value={`${user.username}.${server.id}`}
|
className={'input-dark'}
|
||||||
readOnly={true}
|
value={`${user.username}.${server.id}`}
|
||||||
/>
|
readOnly={true}
|
||||||
</div>
|
/>
|
||||||
<div className={'mt-6 flex items-center'}>
|
</div>
|
||||||
<div className={'flex-1'}>
|
<div className={'mt-6 flex items-center'}>
|
||||||
<div className={'border-l-4 border-cyan-500 p-3'}>
|
<div className={'flex-1'}>
|
||||||
<p className={'text-xs text-neutral-200'}>
|
<div className={'border-l-4 border-cyan-500 p-3'}>
|
||||||
Your SFTP password is the same as the password you use to access this panel.
|
<p className={'text-xs text-neutral-200'}>
|
||||||
</p>
|
Your SFTP password is the same as the password you use to access this panel.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className={'ml-4'}>
|
||||||
|
<a
|
||||||
|
href={`sftp://${user.username}.${server.id}@${server.sftpDetails.ip}:${server.sftpDetails.port}`}
|
||||||
|
className={'btn btn-sm btn-secondary'}
|
||||||
|
>
|
||||||
|
Launch SFTP
|
||||||
|
</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className={'ml-4'}>
|
</TitledGreyBox>
|
||||||
<a
|
|
||||||
href={`sftp://${user.username}.${server.id}@${server.sftpDetails.ip}:${server.sftpDetails.port}`}
|
|
||||||
className={'btn btn-sm btn-secondary'}
|
|
||||||
>
|
|
||||||
Launch SFTP
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</TitledGreyBox>
|
|
||||||
</Can>
|
|
||||||
<Can action={'settings.rename'}>
|
|
||||||
<div className={'w-full mt-6 md:flex-1 md:max-w-1/2 md:mt-0'}>
|
|
||||||
<RenameServerBox/>
|
|
||||||
</div>
|
</div>
|
||||||
</Can>
|
</Can>
|
||||||
|
<div className={'w-full mt-6 md:flex-1 md:max-w-1/2 md:mt-0'}>
|
||||||
|
<Can action={'settings.rename'}>
|
||||||
|
<div className={'mb-6 md:mb-10'}>
|
||||||
|
<RenameServerBox/>
|
||||||
|
</div>
|
||||||
|
</Can>
|
||||||
|
<Can action={'settings.reinstall'}>
|
||||||
|
<ReinstallServerBox/>
|
||||||
|
</Can>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
|
@ -89,5 +89,6 @@ Route::group(['prefix' => '/servers/{server}', 'middleware' => [AuthenticateServ
|
||||||
|
|
||||||
Route::group(['prefix' => '/settings'], function () {
|
Route::group(['prefix' => '/settings'], function () {
|
||||||
Route::post('/rename', 'Servers\SettingsController@rename');
|
Route::post('/rename', 'Servers\SettingsController@rename');
|
||||||
|
Route::post('/reinstall', 'Servers\SettingsController@reinstall');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue