1
1
mirror of https://github.com/pterodactyl/panel.git synced 2024-10-27 04:12:28 +01:00

support for changing allocation on frontend

This commit is contained in:
Dane Everitt 2016-01-03 15:15:14 -05:00
parent fb77e23eb4
commit a7fdb9618c
4 changed files with 86 additions and 3 deletions

View File

@ -178,4 +178,38 @@ class AjaxController extends Controller
}
/**
* [postSetConnection description]
* @param Request $request
* @param string $uuid
* @return \Illuminate\Http\Response
*/
public function postSetConnection(Request $request, $uuid)
{
$server = Server::getByUUID($uuid);
$this->authorize('set-connection', $server);
try {
$repo = new Repositories\ServerRepository;
$repo->changeBuild($server->id, [
'default' => $request->input('connection'),
]);
return response('The default connection for this server has been updated. Please be aware that you will need to restart your server for this change to go into effect.');
} catch (\Exception $e) {
if ($e instanceof \Pterodactyl\Exceptions\DisplayException || $e instanceof \Pterodactyl\Exceptions\DisplayValidationException) {
return response()->json([
'error' => $e->getMessage(),
], 503);
} else {
Log::error($e);
return response()->json([
'error' => 'An unhandled exception occured while attemping to modify the default connection for this server.'
], 503);
}
}
}
}

View File

@ -18,6 +18,7 @@ class ServerRoutes {
// Ajax Routes
$router->group(['prefix' => 'ajax'], function ($server) use ($router) {
$router->get('status', [ 'uses' => 'Server\AjaxController@getStatus' ]);
$router->post('set-connection', [ 'uses' => 'Server\AjaxController@postSetConnection' ]);
$router->post('files/directory-list', [ 'uses' => 'Server\AjaxController@postDirectoryList' ]);
$router->post('files/save', [ 'uses' => 'Server\AjaxController@postSaveFile' ]);
});

View File

@ -175,4 +175,20 @@ class ServerPolicy
return $user->permissions()->server($server)->permission('download-files')->exists();
}
/**
* Check if user has permission to change the default connection information.
*
* @param Pterodactyl\Models\User $user
* @param Pterodactyl\Models\Server $server
* @return boolean
*/
public function setConnection(User $user, Server $server)
{
if ($this->isOwner($user, $server)) {
return true;
}
return $user->permissions()->server($server)->permission('set-connection')->exists();
}
}

View File

@ -88,7 +88,7 @@
<div class="panel-heading"></div>
<div class="panel-body">
<div class="alert alert-info">Below is a listing of all avaliable IPs and Ports for your service. To change the default connection address for your server, simply click on the one you would like to make default below.</div>
<ul class="nav nav-pills nav-stacked">
<ul class="nav nav-pills nav-stacked" id="conn_options">
@foreach ($allocations as $allocation)
<li role="presentation" @if($allocation->ip === $server->ip && $allocation->port === $server->port) class="active" @endif><a href="#/set-connnection/{{ $allocation->ip }}:{{ $allocation->port }}" data-action="set-connection" data-connection="{{ $allocation->ip }}:{{ $allocation->port }}">{{ $allocation->ip }} <span class="badge">{{ $allocation->port }}</span></a></li>
@endforeach
@ -292,8 +292,7 @@ $(window).load(function () {
});
}
if({{ $server->cpu }} > 0) {
CPUChart.series[ i + 1 ].addPoint(parseFloat(((proc.data.cpu.cores[i] / {{ $server->cpu }}) * 100).toFixed(3).toString())
, true, true);
CPUChart.series[ i + 1 ].addPoint(parseFloat(((proc.data.cpu.cores[i] / {{ $server->cpu }}) * 100).toFixed(3).toString()), true, true);
} else {
CPUChart.series[ i + 1 ].addPoint(proc.data.cpu.cores[i], true, true);
}
@ -378,6 +377,39 @@ $(window).load(function () {
}
}
@can('set-connection', $server)
// Send Request
$('[data-action="set-connection"]').click(function (event) {
event.preventDefault();
var element = $(this);
if (element.hasClass('active')) {
return;
}
$.ajax({
method: 'POST',
url: '/server/{{ $server->uuidShort }}/ajax/set-connection',
data: {
connection: element.data('connection')
},
headers: {
'X-CSRF-TOKEN': '{{ csrf_token() }}'
}
}).done(function (data) {
$('#conn_options').find('li.active').removeClass('active');
element.parent().addClass('active');
alert(data);
}).fail(function (jqXHR) {
console.error(jqXHR);
if (typeof jqXHR.responseJSON.error === 'undefined' || jqXHR.responseJSON.error === '') {
return alert('An error occured while attempting to perform this action.');
} else {
return alert(jqXHR.responseJSON.error);
}
});
});
@endcan
@can('command', $server)
// Send Command to Server
$('#console_command').submit(function (event) {