Add delete server support as well as fix a few other bugs
Also a few JS fixes to make things work better and not clear the console every time the server is booted
This commit is contained in:
parent
9d2d726992
commit
4fe4881f77
7 changed files with 167 additions and 53 deletions
|
@ -65,6 +65,10 @@ class ServersController extends Controller
|
||||||
->where('servers.id', $id)
|
->where('servers.id', $id)
|
||||||
->first();
|
->first();
|
||||||
|
|
||||||
|
if (!$server) {
|
||||||
|
return abort(404);
|
||||||
|
}
|
||||||
|
|
||||||
return view('admin.servers.view', [
|
return view('admin.servers.view', [
|
||||||
'server' => $server,
|
'server' => $server,
|
||||||
'assigned' => Models\Allocation::select('id', 'ip', 'port')->where('assigned_to', $id)->orderBy('ip', 'asc')->orderBy('port', 'asc')->get(),
|
'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'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,6 +33,7 @@ class AdminRoutes {
|
||||||
$router->post('/view/{id}/details', [ 'uses' => 'Admin\ServersController@postUpdateServerDetails' ]);
|
$router->post('/view/{id}/details', [ 'uses' => 'Admin\ServersController@postUpdateServerDetails' ]);
|
||||||
$router->post('/view/{id}/rebuild', [ 'uses' => 'Admin\ServersController@postUpdateServerToggleBuild' ]);
|
$router->post('/view/{id}/rebuild', [ 'uses' => 'Admin\ServersController@postUpdateServerToggleBuild' ]);
|
||||||
$router->post('/view/{id}/build', [ 'uses' => 'Admin\ServersController@postUpdateServerUpdateBuild' ]);
|
$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', [ 'uses' => 'Admin\ServersController@postNewServer']);
|
||||||
$router->post('/new/get-nodes', [ 'uses' => 'Admin\ServersController@postNewServerGetNodes' ]);
|
$router->post('/new/get-nodes', [ 'uses' => 'Admin\ServersController@postNewServerGetNodes' ]);
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,14 @@
|
||||||
<li><a href="/admin">Admin Control</a></li>
|
<li><a href="/admin">Admin Control</a></li>
|
||||||
<li class="active">Servers</li>
|
<li class="active">Servers</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
@foreach (Alert::getMessages() as $type => $messages)
|
||||||
|
@foreach ($messages as $message)
|
||||||
|
<div class="alert alert-{{ $type }} alert-dismissable" role="alert">
|
||||||
|
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
|
||||||
|
{!! $message !!}
|
||||||
|
</div>
|
||||||
|
@endforeach
|
||||||
|
@endforeach
|
||||||
<h3>All Servers</h3><hr />
|
<h3>All Servers</h3><hr />
|
||||||
<table class="table table-bordered table-hover">
|
<table class="table table-bordered table-hover">
|
||||||
<thead>
|
<thead>
|
||||||
|
|
|
@ -397,7 +397,7 @@ $(document).ready(function () {
|
||||||
$.each(data, function (i, item) {
|
$.each(data, function (i, item) {
|
||||||
var isRequired = (item.required === 1) ? '<code>Required</code>' : '';
|
var isRequired = (item.required === 1) ? '<code>Required</code>' : '';
|
||||||
var dataAppend = ' \
|
var dataAppend = ' \
|
||||||
<div class="form-group col-md-6">\
|
<div class="form-group col-md-12">\
|
||||||
<label for="var_ref_' + item.id + '" class="control-label">' + item.name + '</label> ' + isRequired + '\
|
<label for="var_ref_' + item.id + '" class="control-label">' + item.name + '</label> ' + isRequired + '\
|
||||||
<div>\
|
<div>\
|
||||||
<input type="text" autocomplete="off" name="env_' + item.env_variable + '" class="form-control" value="' + item.default_value + '" />\
|
<input type="text" autocomplete="off" name="env_' + item.env_variable + '" class="form-control" value="' + item.default_value + '" />\
|
||||||
|
|
|
@ -33,8 +33,9 @@
|
||||||
<li class="active"><a href="#tab_about" data-toggle="tab">About</a></li>
|
<li class="active"><a href="#tab_about" data-toggle="tab">About</a></li>
|
||||||
<li><a href="#tab_details" data-toggle="tab">Details</a></li>
|
<li><a href="#tab_details" data-toggle="tab">Details</a></li>
|
||||||
<li><a href="#tab_build" data-toggle="tab">Build Configuration</a></li>
|
<li><a href="#tab_build" data-toggle="tab">Build Configuration</a></li>
|
||||||
<li><a href="#tab_startup" data-toggle="tab">Startup Settings</a></li>
|
<li><a href="#tab_startup" data-toggle="tab">Startup</a></li>
|
||||||
<li><a href="#tab_manage" data-toggle="tab">Manage</a></li>
|
<li><a href="#tab_manage" data-toggle="tab">Manage</a></li>
|
||||||
|
<li><a href="#tab_delete" data-toggle="tab">Delete</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
<div class="tab-content">
|
<div class="tab-content">
|
||||||
<div class="tab-pane active" id="tab_about">
|
<div class="tab-pane active" id="tab_about">
|
||||||
|
@ -251,55 +252,80 @@
|
||||||
<div class="panel panel-default">
|
<div class="panel panel-default">
|
||||||
<div class="panel-heading"></div>
|
<div class="panel-heading"></div>
|
||||||
<div class="panel-body">
|
<div class="panel-body">
|
||||||
<table class="table table-striped" style="margin-bottom: 0;">
|
<div class="row">
|
||||||
<tbody>
|
<div class="col-md-4 text-center">
|
||||||
<tr>
|
<a href="/server/{{ $server->uuidShort }}/" target="_blank">
|
||||||
<td class="text-center" style="vertical-align:middle;">
|
<button type="submit" class="btn btn-sm btn-primary">Manage Server</button>
|
||||||
<a href="/server/{{ $server->uuidShort }}/">
|
</a>
|
||||||
<button type="submit" class="btn btn-sm btn-primary">Manage Server</button>
|
</div>
|
||||||
</a>
|
<div class="col-md-8">
|
||||||
</td>
|
<p>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.</p>
|
||||||
<td>
|
</div>
|
||||||
<p>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.</p>
|
</div>
|
||||||
</td>
|
</div>
|
||||||
</tr>
|
<div class="panel-heading" style="border-top: 1px solid #ddd;"></div>
|
||||||
<tr>
|
<div class="panel-body">
|
||||||
<td class="text-center" style="vertical-align:middle;">
|
<div class="row">
|
||||||
<form action="/admin/servers/view/{{ $server->id }}/installed" method="POST">
|
<div class="col-md-4 text-center">
|
||||||
{!! csrf_field() !!}
|
<form action="/admin/servers/view/{{ $server->id }}/installed" method="POST">
|
||||||
<button type="submit" class="btn btn-sm btn-primary">Toggle Install Status</button>
|
{!! csrf_field() !!}
|
||||||
</form>
|
<button type="submit" class="btn btn-sm btn-primary">Toggle Install Status</button>
|
||||||
</td>
|
</form>
|
||||||
<td>
|
</div>
|
||||||
<p>This will toggle the install status for the server.</p>
|
<div class="col-md-8">
|
||||||
<div class="alert alert-warning">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.</div>
|
<p>This will toggle the install status for the server.</p>
|
||||||
</td>
|
<div class="alert alert-warning">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.</div>
|
||||||
</tr>
|
</div>
|
||||||
<tr>
|
</div>
|
||||||
<td class="text-center" style="vertical-align:middle;">
|
</div>
|
||||||
<form action="/admin/servers/view/{{ $server->id }}/rebuild" method="POST">
|
<div class="panel-heading" style="border-top: 1px solid #ddd;"></div>
|
||||||
{!! csrf_field() !!}
|
<div class="panel-body">
|
||||||
<button type="submit" class="btn btn-sm btn-primary">Rebuild Server Container</button>
|
<div class="row">
|
||||||
</form>
|
<div class="col-md-4 text-center">
|
||||||
</td>
|
<form action="/admin/servers/view/{{ $server->id }}/rebuild" method="POST">
|
||||||
<td>
|
{!! csrf_field() !!}
|
||||||
<p>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.</p>
|
<button type="submit" class="btn btn-sm btn-primary">Rebuild Server Container</button>
|
||||||
<div class="alert alert-info">A rebuild will automatically occur whenever you edit build configuration settings for the server.</div>
|
</form>
|
||||||
</td>
|
</div>
|
||||||
</tr>
|
<div class="col-md-8">
|
||||||
<tr>
|
<p>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.</p>
|
||||||
<td class="text-center" style="vertical-align:middle;">
|
<div class="alert alert-info">A rebuild will automatically occur whenever you edit build configuration settings for the server.</div>
|
||||||
<form action="/admin/servers/view/{{ $server->id }}/delete" method="POST">
|
</div>
|
||||||
{!! csrf_field() !!}
|
</div>
|
||||||
<button type="submit" class="btn btn-sm btn-danger">Delete Server</button>
|
</div>
|
||||||
</form>
|
</div>
|
||||||
</td>
|
</div>
|
||||||
<td>
|
<div class="tab-pane" id="tab_delete">
|
||||||
<div class="alert alert-danger" style="margin-top:21px;">Deleting a server is an irreversible action. <strong>All data will be immediately removed relating to this server.</strong></div>
|
<div class="panel panel-default">
|
||||||
</td>
|
<div class="panel-heading"></div>
|
||||||
</tr>
|
<div class="panel-body">
|
||||||
</tbody>
|
<div class="row">
|
||||||
</table>
|
<div class="col-md-4 text-center">
|
||||||
|
<form action="/admin/servers/view/{{ $server->id }}" method="POST" data-attr="deleteServer">
|
||||||
|
{!! csrf_field() !!}
|
||||||
|
{!! method_field('DELETE') !!}
|
||||||
|
<button type="submit" class="btn btn-sm btn-danger">Delete Server</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-8">
|
||||||
|
<div class="alert alert-danger">Deleting a server is an irreversible action. <strong>All data will be immediately removed relating to this server.</strong></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="panel-heading" style="border-top: 1px solid #ddd;"></div>
|
||||||
|
<div class="panel-body">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-4 text-center">
|
||||||
|
<form action="/admin/servers/view/{{ $server->id }}/force" method="POST" data-attr="deleteServer">
|
||||||
|
{!! csrf_field() !!}
|
||||||
|
{!! method_field('DELETE') !!}
|
||||||
|
<button type="submit" class="btn btn-sm btn-danger">Force Delete Server</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-8">
|
||||||
|
<div class="alert alert-danger">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.</strong></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -312,6 +338,11 @@ $(document).ready(function () {
|
||||||
$('select[name="remove_additional[]"]').find('option:disabled').prop('disabled', false);
|
$('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);
|
$('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();
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
@endsection
|
@endsection
|
||||||
|
|
|
@ -317,7 +317,6 @@ $(window).load(function () {
|
||||||
|
|
||||||
// New Console Data Recieved
|
// New Console Data Recieved
|
||||||
socket.on('console', function (data) {
|
socket.on('console', function (data) {
|
||||||
console.log(JSON.stringify(data));
|
|
||||||
$('#live_console').val($('#live_console').val() + data.line);
|
$('#live_console').val($('#live_console').val() + data.line);
|
||||||
$('#live_console').scrollTop($('#live_console')[0].scrollHeight);
|
$('#live_console').scrollTop($('#live_console')[0].scrollHeight);
|
||||||
});
|
});
|
||||||
|
@ -445,7 +444,8 @@ $(window).load(function () {
|
||||||
|
|
||||||
// Reset Console Data
|
// Reset Console Data
|
||||||
if (data === 2) {
|
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
|
// Server is On or Starting
|
||||||
|
|
Loading…
Reference in a new issue