diff --git a/app/Http/Controllers/Admin/ServersController.php b/app/Http/Controllers/Admin/ServersController.php index c7a647924..69509d334 100644 --- a/app/Http/Controllers/Admin/ServersController.php +++ b/app/Http/Controllers/Admin/ServersController.php @@ -65,6 +65,10 @@ class ServersController extends Controller ->where('servers.id', $id) ->first(); + if (!$server) { + return abort(404); + } + return view('admin.servers.view', [ 'server' => $server, 'assigned' => Models\Allocation::select('id', 'ip', 'port')->where('assigned_to', $id)->orderBy('ip', 'asc')->orderBy('port', 'asc')->get(), @@ -289,4 +293,23 @@ class ServersController extends Controller ]); } + public function deleteServer(Request $request, $id, $force = null) + { + try { + $server = new ServerRepository; + $server->deleteServer($id, $force); + Alert::success('Server was successfully deleted from the panel and the daemon.')->flash(); + return redirect()->route('admin.servers'); + } catch (\Pterodactyl\Exceptions\DisplayException $e) { + Alert::danger($e->getMessage())->flash(); + } catch(\Exception $e) { + Log::error($e); + Alert::danger('An unhandled exception occured while attemping to add this server. Please try again.')->flash(); + } + return redirect()->route('admin.servers.view', [ + 'id' => $id, + 'tab' => 'tab_delete' + ]); + } + } diff --git a/app/Http/Routes/AdminRoutes.php b/app/Http/Routes/AdminRoutes.php index 9ec7858f0..f073f9e56 100644 --- a/app/Http/Routes/AdminRoutes.php +++ b/app/Http/Routes/AdminRoutes.php @@ -33,6 +33,7 @@ class AdminRoutes { $router->post('/view/{id}/details', [ 'uses' => 'Admin\ServersController@postUpdateServerDetails' ]); $router->post('/view/{id}/rebuild', [ 'uses' => 'Admin\ServersController@postUpdateServerToggleBuild' ]); $router->post('/view/{id}/build', [ 'uses' => 'Admin\ServersController@postUpdateServerUpdateBuild' ]); + $router->delete('/view/{id}/{force?}', [ 'uses' => 'Admin\ServersController@deleteServer' ]); $router->post('/new', [ 'uses' => 'Admin\ServersController@postNewServer']); $router->post('/new/get-nodes', [ 'uses' => 'Admin\ServersController@postNewServerGetNodes' ]); diff --git a/app/Repositories/ServerRepository.php b/app/Repositories/ServerRepository.php index 4c8fdbd9a..648ff077f 100644 --- a/app/Repositories/ServerRepository.php +++ b/app/Repositories/ServerRepository.php @@ -524,4 +524,55 @@ class ServerRepository } + public function deleteServer($id, $force) + { + $server = Models\Server::findOrFail($id); + $node = Models\Node::findOrFail($server->node); + DB::beginTransaction(); + + // Delete Allocations + Models\Allocation::where('assigned_to', $server->id)->update([ + 'assigned_to' => null + ]); + + // Remove Variables + Models\ServerVariables::where('server_id', $server->id)->delete(); + + // Remove SubUsers + Models\Subuser::where('server_id', $server->id)->delete(); + + // Remove Permissions + Models\Permission::where('server_id', $server->id)->delete(); + + // Remove Downloads + Models\Download::where('server', $server->uuid)->delete(); + + try { + $client = Models\Node::guzzleRequest($server->node); + $client->request('DELETE', '/servers', [ + 'headers' => [ + 'X-Access-Token' => $node->daemonSecret, + 'X-Access-Server' => $server->uuid + ] + ]); + + $server->delete(); + DB::commit(); + return true; + } catch (\GuzzleHttp\Exception\TransferException $ex) { + if ($force === 'force') { + $server->delete(); + DB::commit(); + return true; + } else { + DB::rollBack(); + Log::error($ex); + throw new DisplayException('An error occured while attempting to delete the server on the daemon: ' . $ex->getMessage()); + } + } catch (\Exception $ex) { + DB::rollBack(); + throw $ex; + } + } + } diff --git a/resources/views/admin/servers/index.blade.php b/resources/views/admin/servers/index.blade.php index d37335e29..6b5ebdcd0 100644 --- a/resources/views/admin/servers/index.blade.php +++ b/resources/views/admin/servers/index.blade.php @@ -10,6 +10,14 @@
  • Admin Control
  • Servers
  • + @foreach (Alert::getMessages() as $type => $messages) + @foreach ($messages as $message) + + @endforeach + @endforeach

    All Servers


    diff --git a/resources/views/admin/servers/new.blade.php b/resources/views/admin/servers/new.blade.php index b5c076751..cfdad9ee4 100644 --- a/resources/views/admin/servers/new.blade.php +++ b/resources/views/admin/servers/new.blade.php @@ -397,7 +397,7 @@ $(document).ready(function () { $.each(data, function (i, item) { var isRequired = (item.required === 1) ? 'Required' : ''; var dataAppend = ' \ -
    \ +
    \ ' + isRequired + '\
    \ \ diff --git a/resources/views/admin/servers/view.blade.php b/resources/views/admin/servers/view.blade.php index 0a974b85a..a38bd4a0d 100644 --- a/resources/views/admin/servers/view.blade.php +++ b/resources/views/admin/servers/view.blade.php @@ -33,8 +33,9 @@
  • About
  • Details
  • Build Configuration
  • -
  • Startup Settings
  • +
  • Startup
  • Manage
  • +
  • Delete
  • @@ -251,55 +252,80 @@
    -
    - - - - - - - - - - - - - - - - - - -
    - - - - -

    This will take you to the server management page that users normally see and allow you to manage server files as well as check the console and data usage.

    -
    -
    - {!! csrf_field() !!} - -
    -
    -

    This will toggle the install status for the server.

    -
    If you have just created this server it is ill advised to perform this action as the daemon will contact the panel when finished which could cause the install status to be wrongly set.
    -
    -
    - {!! csrf_field() !!} - -
    -
    -

    This will trigger a rebuild of the server container when it next starts up. This is useful if you modified the server configuration file manually, or something just didn't work out correctly. Please be aware: if you manually updated the server's configuration file, you will need to restart the daemon before doing this, or it will be overwritten.

    -
    A rebuild will automatically occur whenever you edit build configuration settings for the server.
    -
    -
    - {!! csrf_field() !!} - -
    -
    -
    Deleting a server is an irreversible action. All data will be immediately removed relating to this server.
    -
    +
    +
    + + + +
    +
    +

    This will take you to the server management page that users normally see and allow you to manage server files as well as check the console and data usage.

    +
    +
    + +
    +
    +
    +
    +
    + {!! csrf_field() !!} + +
    +
    +
    +

    This will toggle the install status for the server.

    +
    If you have just created this server it is ill advised to perform this action as the daemon will contact the panel when finished which could cause the install status to be wrongly set.
    +
    +
    +
    +
    +
    +
    +
    +
    + {!! csrf_field() !!} + +
    +
    +
    +

    This will trigger a rebuild of the server container when it next starts up. This is useful if you modified the server configuration file manually, or something just didn't work out correctly. Please be aware: if you manually updated the server's configuration file, you will need to restart the daemon before doing this, or it will be overwritten.

    +
    A rebuild will automatically occur whenever you edit build configuration settings for the server.
    +
    +
    +
    + + +
    +
    +
    +
    +
    +
    +
    + {!! csrf_field() !!} + {!! method_field('DELETE') !!} + +
    +
    +
    +
    Deleting a server is an irreversible action. All data will be immediately removed relating to this server.
    +
    +
    +
    +
    +
    +
    +
    +
    + {!! csrf_field() !!} + {!! method_field('DELETE') !!} + +
    +
    +
    +
    This is the same as deleting a server, however, if an error is returned by the daemon it is ignored and the server is still removed from the panel.
    +
    +
    @@ -312,6 +338,11 @@ $(document).ready(function () { $('select[name="remove_additional[]"]').find('option:disabled').prop('disabled', false); $('select[name="remove_additional[]"]').find('option[value="' + $(this).val() + '"]').prop('disabled', true).prop('selected', false); }); + $('form[data-attr="deleteServer"]').submit(function (event) { + if (confirm('Are you sure that you want to delete this server? There is no going back, all data will immediately be removed.')) { + event.submit(); + } + }); }); @endsection diff --git a/resources/views/server/index.blade.php b/resources/views/server/index.blade.php index b84ba2298..732cc8693 100644 --- a/resources/views/server/index.blade.php +++ b/resources/views/server/index.blade.php @@ -317,7 +317,6 @@ $(window).load(function () { // New Console Data Recieved socket.on('console', function (data) { - console.log(JSON.stringify(data)); $('#live_console').val($('#live_console').val() + data.line); $('#live_console').scrollTop($('#live_console')[0].scrollHeight); }); @@ -445,7 +444,8 @@ $(window).load(function () { // Reset Console Data if (data === 2) { - $("#live_console").val(''); + $('#live_console').val($('#live_console').val() + '\n --+ Server Detected as Booting + --\n'); + $('#live_console').scrollTop($('#live_console')[0].scrollHeight); } // Server is On or Starting