mirror of
https://github.com/pterodactyl/panel.git
synced 2024-11-22 09:02:28 +01:00
Update server policy definitions
This commit is contained in:
parent
4f3629fc4c
commit
57cf636816
@ -60,6 +60,70 @@ class ServerPolicy
|
||||
return $user->permissions()->server($server)->permission('power')->exists();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if user has permission to start a server.
|
||||
*
|
||||
* @param Pterodactyl\Models\User $user
|
||||
* @param Pterodactyl\Models\Server $server
|
||||
* @return boolean
|
||||
*/
|
||||
public function powerStart(User $user, Server $server)
|
||||
{
|
||||
if ($this->isOwner($user, $server)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $user->permissions()->server($server)->permission('power-start')->exists();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if user has permission to stop a server.
|
||||
*
|
||||
* @param Pterodactyl\Models\User $user
|
||||
* @param Pterodactyl\Models\Server $server
|
||||
* @return boolean
|
||||
*/
|
||||
public function powerStop(User $user, Server $server)
|
||||
{
|
||||
if ($this->isOwner($user, $server)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $user->permissions()->server($server)->permission('power-stop')->exists();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if user has permission to restart a server.
|
||||
*
|
||||
* @param Pterodactyl\Models\User $user
|
||||
* @param Pterodactyl\Models\Server $server
|
||||
* @return boolean
|
||||
*/
|
||||
public function powerRestart(User $user, Server $server)
|
||||
{
|
||||
if ($this->isOwner($user, $server)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $user->permissions()->server($server)->permission('power-restart')->exists();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if user has permission to kill a server.
|
||||
*
|
||||
* @param Pterodactyl\Models\User $user
|
||||
* @param Pterodactyl\Models\Server $server
|
||||
* @return boolean
|
||||
*/
|
||||
public function powerKill(User $user, Server $server)
|
||||
{
|
||||
if ($this->isOwner($user, $server)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $user->permissions()->server($server)->permission('power-kill')->exists();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if user has permission to run a command on a server.
|
||||
*
|
||||
@ -67,13 +131,13 @@ class ServerPolicy
|
||||
* @param Pterodactyl\Models\Server $server
|
||||
* @return boolean
|
||||
*/
|
||||
public function command(User $user, Server $server)
|
||||
public function sendCommand(User $user, Server $server)
|
||||
{
|
||||
if ($this->isOwner($user, $server)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $user->permissions()->server($server)->permission('command')->exists();
|
||||
return $user->permissions()->server($server)->permission('send-command')->exists();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -212,13 +276,77 @@ class ServerPolicy
|
||||
* @param Pterodactyl\Models\Server $server
|
||||
* @return boolean
|
||||
*/
|
||||
public function viewSubusers(User $user, Server $server)
|
||||
public function listSubusers(User $user, Server $server)
|
||||
{
|
||||
if ($this->isOwner($user, $server)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $user->permissions()->server($server)->permission('view-subusers')->exists();
|
||||
return $user->permissions()->server($server)->permission('list-subusers')->exists();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if user has permission to view specific subuser permissions.
|
||||
*
|
||||
* @param Pterodactyl\Models\User $user
|
||||
* @param Pterodactyl\Models\Server $server
|
||||
* @return boolean
|
||||
*/
|
||||
public function viewSubuser(User $user, Server $server)
|
||||
{
|
||||
if ($this->isOwner($user, $server)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $user->permissions()->server($server)->permission('view-subuser')->exists();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if user has permission to edit a subuser.
|
||||
*
|
||||
* @param Pterodactyl\Models\User $user
|
||||
* @param Pterodactyl\Models\Server $server
|
||||
* @return boolean
|
||||
*/
|
||||
public function editSubuser(User $user, Server $server)
|
||||
{
|
||||
if ($this->isOwner($user, $server)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $user->permissions()->server($server)->permission('edit-subuser')->exists();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if user has permission to delete a subuser.
|
||||
*
|
||||
* @param Pterodactyl\Models\User $user
|
||||
* @param Pterodactyl\Models\Server $server
|
||||
* @return boolean
|
||||
*/
|
||||
public function deleteSubuser(User $user, Server $server)
|
||||
{
|
||||
if ($this->isOwner($user, $server)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $user->permissions()->server($server)->permission('delete-subuser')->exists();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if user has permission to edit a subuser.
|
||||
*
|
||||
* @param Pterodactyl\Models\User $user
|
||||
* @param Pterodactyl\Models\Server $server
|
||||
* @return boolean
|
||||
*/
|
||||
public function createSubuser(User $user, Server $server)
|
||||
{
|
||||
if ($this->isOwner($user, $server)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $user->permissions()->server($server)->permission('create-subuser')->exists();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -194,7 +194,7 @@
|
||||
<a href="#" class="list-group-item list-group-item-heading"><strong>{{ trans('pagination.sidebar.server_controls') }}</strong></a>
|
||||
<a href="/server/{{ $server->uuidShort }}/" class="list-group-item server-index">{{ trans('pagination.sidebar.overview') }}</a>
|
||||
@can('list-files', $server)<a href="/server/{{ $server->uuidShort }}/files" class="list-group-item server-files">{{ trans('pagination.sidebar.files') }}</a>@endcan
|
||||
@can('view-subusers', $server)<a href="/server/{{ $server->uuidShort }}/users" class="list-group-item server-users">{{ trans('pagination.sidebar.subusers') }}</a>@endcan
|
||||
@can('list-subusers', $server)<a href="/server/{{ $server->uuidShort }}/users" class="list-group-item server-users">{{ trans('pagination.sidebar.subusers') }}</a>@endcan
|
||||
@can('view-manage', $server)<a href="/server/{{ $server->uuidShort }}/settings" class="list-group-item server-settings">{{ trans('pagination.sidebar.manage') }}</a>@endcan
|
||||
</div>
|
||||
@endif
|
||||
|
@ -43,14 +43,12 @@
|
||||
</div>
|
||||
<div class="col-md-6" style="text-align:center;">
|
||||
<hr />
|
||||
@can('power', $server)
|
||||
<button class="btn btn-success btn-sm disabled" data-attr="power" data-action="start">Start</button>
|
||||
<button class="btn btn-primary btn-sm disabled" data-attr="power" data-action="restart">Restart</button>
|
||||
<button class="btn btn-danger btn-sm disabled" data-attr="power" data-action="stop">Stop</button>
|
||||
<button class="btn btn-danger btn-sm disabled" data-attr="power" data-action="kill"><i class="fa fa-ban" data-toggle="tooltip" data-placement="top" title="Kill Running Process"></i></button>
|
||||
<button class="btn btn-primary btn-sm" data-toggle="modal" data-target="#pauseConsole" id="pause_console"><small><i class="fa fa-pause fa-fw"></i></small></button>
|
||||
<div id="pw_resp" style="display:none;margin-top: 15px;"></div>
|
||||
@endcan
|
||||
@can('power-start', $server)<button class="btn btn-success btn-sm disabled" data-attr="power" data-action="start">Start</button>@endcan
|
||||
@can('power-restart', $server)<button class="btn btn-primary btn-sm disabled" data-attr="power" data-action="restart">Restart</button>@endcan
|
||||
@can('power-stop', $server)<button class="btn btn-danger btn-sm disabled" data-attr="power" data-action="stop">Stop</button>@endcan
|
||||
@can('power-kill', $server)<button class="btn btn-danger btn-sm disabled" data-attr="power" data-action="kill"><i class="fa fa-ban" data-toggle="tooltip" data-placement="top" title="Kill Running Process"></i></button>@endcan
|
||||
<button class="btn btn-primary btn-sm" data-toggle="modal" data-target="#pauseConsole" id="pause_console"><small><i class="fa fa-pause fa-fw"></i></small></button>
|
||||
<div id="pw_resp" style="display:none;margin-top: 15px;"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
@ -462,87 +460,84 @@ $(window).load(function () {
|
||||
});
|
||||
});
|
||||
@endcan
|
||||
@can('power', $server)
|
||||
var can_run = true;
|
||||
function updateServerPowerControls (data) {
|
||||
|
||||
// Reset Console Data
|
||||
if (data === 2) {
|
||||
$('#live_console').val($('#live_console').val() + '\n --+ Server Detected as Booting + --\n');
|
||||
$('#live_console').scrollTop($('#live_console')[0].scrollHeight);
|
||||
}
|
||||
|
||||
// Server is On or Starting
|
||||
if(data == 1 || data == 2) {
|
||||
$("#console_command").slideDown();
|
||||
$('[data-attr="power"][data-action="start"]').addClass('disabled');
|
||||
$('[data-attr="power"][data-action="stop"], [data-attr="power"][data-action="restart"]').removeClass('disabled');
|
||||
} else {
|
||||
$("#console_command").slideUp();
|
||||
$('[data-attr="power"][data-action="start"]').removeClass('disabled');
|
||||
$('[data-attr="power"][data-action="stop"], [data-attr="power"][data-action="restart"]').addClass('disabled');
|
||||
}
|
||||
|
||||
if(data !== 0) {
|
||||
$('[data-attr="power"][data-action="kill"]').removeClass('disabled');
|
||||
} else {
|
||||
$('[data-attr="power"][data-action="kill"]').addClass('disabled');
|
||||
}
|
||||
var can_run = true;
|
||||
function updateServerPowerControls (data) {
|
||||
|
||||
// Reset Console Data
|
||||
if (data === 2) {
|
||||
$('#live_console').val($('#live_console').val() + '\n --+ Server Detected as Booting + --\n');
|
||||
$('#live_console').scrollTop($('#live_console')[0].scrollHeight);
|
||||
}
|
||||
|
||||
$('[data-attr="power"]').click(function (event) {
|
||||
event.preventDefault();
|
||||
var action = $(this).data('action');
|
||||
var killConfirm = false;
|
||||
if (action === 'kill') {
|
||||
swal({
|
||||
type: 'warning',
|
||||
title: '',
|
||||
text: 'This operation will not save your server data gracefully. You should only use this if your server is failing to respond to normal stop commands.',
|
||||
showCancelButton: true,
|
||||
allowOutsideClick: true,
|
||||
closeOnConfirm: true,
|
||||
confirmButtonText: 'Kill Server',
|
||||
confirmButtonColor: '#d9534f'
|
||||
}, function () {
|
||||
setTimeout(function() {
|
||||
powerToggleServer('kill');
|
||||
}, 100);
|
||||
});
|
||||
} else {
|
||||
powerToggleServer(action);
|
||||
}
|
||||
// Server is On or Starting
|
||||
if(data == 1 || data == 2) {
|
||||
$("#console_command").slideDown();
|
||||
$('[data-attr="power"][data-action="start"]').addClass('disabled');
|
||||
$('[data-attr="power"][data-action="stop"], [data-attr="power"][data-action="restart"]').removeClass('disabled');
|
||||
} else {
|
||||
$("#console_command").slideUp();
|
||||
$('[data-attr="power"][data-action="start"]').removeClass('disabled');
|
||||
$('[data-attr="power"][data-action="stop"], [data-attr="power"][data-action="restart"]').addClass('disabled');
|
||||
}
|
||||
|
||||
});
|
||||
if(data !== 0) {
|
||||
$('[data-attr="power"][data-action="kill"]').removeClass('disabled');
|
||||
} else {
|
||||
$('[data-attr="power"][data-action="kill"]').addClass('disabled');
|
||||
}
|
||||
|
||||
function powerToggleServer(action) {
|
||||
$.ajax({
|
||||
type: 'PUT',
|
||||
headers: {
|
||||
'X-Access-Token': '{{ $server->daemonSecret }}',
|
||||
'X-Access-Server': '{{ $server->uuid }}'
|
||||
},
|
||||
contentType: 'application/json; charset=utf-8',
|
||||
data: JSON.stringify({
|
||||
action: action
|
||||
}),
|
||||
url: '{{ $node->scheme }}://{{ $node->fqdn }}:{{ $node->daemonListen }}/server/power',
|
||||
timeout: 10000
|
||||
}).fail(function(jqXHR) {
|
||||
var error = 'An error occured while trying to process this request.';
|
||||
if (typeof jqXHR.responseJSON !== 'undefined' && typeof jqXHR.responseJSON.error !== 'undefined') {
|
||||
error = jqXHR.responseJSON.error;
|
||||
}
|
||||
swal({
|
||||
type: 'error',
|
||||
title: 'Whoops!',
|
||||
text: error
|
||||
});
|
||||
}
|
||||
|
||||
$('[data-attr="power"]').click(function (event) {
|
||||
event.preventDefault();
|
||||
var action = $(this).data('action');
|
||||
var killConfirm = false;
|
||||
if (action === 'kill') {
|
||||
swal({
|
||||
type: 'warning',
|
||||
title: '',
|
||||
text: 'This operation will not save your server data gracefully. You should only use this if your server is failing to respond to normal stop commands.',
|
||||
showCancelButton: true,
|
||||
allowOutsideClick: true,
|
||||
closeOnConfirm: true,
|
||||
confirmButtonText: 'Kill Server',
|
||||
confirmButtonColor: '#d9534f'
|
||||
}, function () {
|
||||
setTimeout(function() {
|
||||
powerToggleServer('kill');
|
||||
}, 100);
|
||||
});
|
||||
} else {
|
||||
powerToggleServer(action);
|
||||
}
|
||||
|
||||
@endcan
|
||||
});
|
||||
|
||||
function powerToggleServer(action) {
|
||||
$.ajax({
|
||||
type: 'PUT',
|
||||
headers: {
|
||||
'X-Access-Token': '{{ $server->daemonSecret }}',
|
||||
'X-Access-Server': '{{ $server->uuid }}'
|
||||
},
|
||||
contentType: 'application/json; charset=utf-8',
|
||||
data: JSON.stringify({
|
||||
action: action
|
||||
}),
|
||||
url: '{{ $node->scheme }}://{{ $node->fqdn }}:{{ $node->daemonListen }}/server/power',
|
||||
timeout: 10000
|
||||
}).fail(function(jqXHR) {
|
||||
var error = 'An error occured while trying to process this request.';
|
||||
if (typeof jqXHR.responseJSON !== 'undefined' && typeof jqXHR.responseJSON.error !== 'undefined') {
|
||||
error = jqXHR.responseJSON.error;
|
||||
}
|
||||
swal({
|
||||
type: 'error',
|
||||
title: 'Whoops!',
|
||||
text: error
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
$(document).ready(function () {
|
||||
|
Loading…
Reference in New Issue
Block a user