Update server policy definitions
This commit is contained in:
parent
4f3629fc4c
commit
57cf636816
3 changed files with 209 additions and 86 deletions
|
@ -60,6 +60,70 @@ class ServerPolicy
|
||||||
return $user->permissions()->server($server)->permission('power')->exists();
|
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.
|
* Check if user has permission to run a command on a server.
|
||||||
*
|
*
|
||||||
|
@ -67,13 +131,13 @@ class ServerPolicy
|
||||||
* @param Pterodactyl\Models\Server $server
|
* @param Pterodactyl\Models\Server $server
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public function command(User $user, Server $server)
|
public function sendCommand(User $user, Server $server)
|
||||||
{
|
{
|
||||||
if ($this->isOwner($user, $server)) {
|
if ($this->isOwner($user, $server)) {
|
||||||
return true;
|
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
|
* @param Pterodactyl\Models\Server $server
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public function viewSubusers(User $user, Server $server)
|
public function listSubusers(User $user, Server $server)
|
||||||
{
|
{
|
||||||
if ($this->isOwner($user, $server)) {
|
if ($this->isOwner($user, $server)) {
|
||||||
return true;
|
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="#" 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>
|
<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('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
|
@can('view-manage', $server)<a href="/server/{{ $server->uuidShort }}/settings" class="list-group-item server-settings">{{ trans('pagination.sidebar.manage') }}</a>@endcan
|
||||||
</div>
|
</div>
|
||||||
@endif
|
@endif
|
||||||
|
|
|
@ -43,14 +43,12 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-6" style="text-align:center;">
|
<div class="col-md-6" style="text-align:center;">
|
||||||
<hr />
|
<hr />
|
||||||
@can('power', $server)
|
@can('power-start', $server)<button class="btn btn-success btn-sm disabled" data-attr="power" data-action="start">Start</button>@endcan
|
||||||
<button class="btn btn-success btn-sm disabled" data-attr="power" data-action="start">Start</button>
|
@can('power-restart', $server)<button class="btn btn-primary btn-sm disabled" data-attr="power" data-action="restart">Restart</button>@endcan
|
||||||
<button class="btn btn-primary btn-sm disabled" data-attr="power" data-action="restart">Restart</button>
|
@can('power-stop', $server)<button class="btn btn-danger btn-sm disabled" data-attr="power" data-action="stop">Stop</button>@endcan
|
||||||
<button class="btn btn-danger btn-sm disabled" data-attr="power" data-action="stop">Stop</button>
|
@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-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>
|
||||||
<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 id="pw_resp" style="display:none;margin-top: 15px;"></div>
|
|
||||||
@endcan
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
@ -462,87 +460,84 @@ $(window).load(function () {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@endcan
|
@endcan
|
||||||
@can('power', $server)
|
var can_run = true;
|
||||||
var can_run = true;
|
function updateServerPowerControls (data) {
|
||||||
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');
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// 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) {
|
// Server is On or Starting
|
||||||
event.preventDefault();
|
if(data == 1 || data == 2) {
|
||||||
var action = $(this).data('action');
|
$("#console_command").slideDown();
|
||||||
var killConfirm = false;
|
$('[data-attr="power"][data-action="start"]').addClass('disabled');
|
||||||
if (action === 'kill') {
|
$('[data-attr="power"][data-action="stop"], [data-attr="power"][data-action="restart"]').removeClass('disabled');
|
||||||
swal({
|
} else {
|
||||||
type: 'warning',
|
$("#console_command").slideUp();
|
||||||
title: '',
|
$('[data-attr="power"][data-action="start"]').removeClass('disabled');
|
||||||
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.',
|
$('[data-attr="power"][data-action="stop"], [data-attr="power"][data-action="restart"]').addClass('disabled');
|
||||||
showCancelButton: true,
|
}
|
||||||
allowOutsideClick: true,
|
|
||||||
closeOnConfirm: true,
|
|
||||||
confirmButtonText: 'Kill Server',
|
|
||||||
confirmButtonColor: '#d9534f'
|
|
||||||
}, function () {
|
|
||||||
setTimeout(function() {
|
|
||||||
powerToggleServer('kill');
|
|
||||||
}, 100);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
powerToggleServer(action);
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
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',
|
$('[data-attr="power"]').click(function (event) {
|
||||||
headers: {
|
event.preventDefault();
|
||||||
'X-Access-Token': '{{ $server->daemonSecret }}',
|
var action = $(this).data('action');
|
||||||
'X-Access-Server': '{{ $server->uuid }}'
|
var killConfirm = false;
|
||||||
},
|
if (action === 'kill') {
|
||||||
contentType: 'application/json; charset=utf-8',
|
swal({
|
||||||
data: JSON.stringify({
|
type: 'warning',
|
||||||
action: action
|
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.',
|
||||||
url: '{{ $node->scheme }}://{{ $node->fqdn }}:{{ $node->daemonListen }}/server/power',
|
showCancelButton: true,
|
||||||
timeout: 10000
|
allowOutsideClick: true,
|
||||||
}).fail(function(jqXHR) {
|
closeOnConfirm: true,
|
||||||
var error = 'An error occured while trying to process this request.';
|
confirmButtonText: 'Kill Server',
|
||||||
if (typeof jqXHR.responseJSON !== 'undefined' && typeof jqXHR.responseJSON.error !== 'undefined') {
|
confirmButtonColor: '#d9534f'
|
||||||
error = jqXHR.responseJSON.error;
|
}, function () {
|
||||||
}
|
setTimeout(function() {
|
||||||
swal({
|
powerToggleServer('kill');
|
||||||
type: 'error',
|
}, 100);
|
||||||
title: 'Whoops!',
|
|
||||||
text: error
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
} 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 () {
|
$(document).ready(function () {
|
||||||
|
|
Loading…
Reference in a new issue