1
1
mirror of https://github.com/pterodactyl/panel.git synced 2024-11-25 10:32:31 +01:00

Add allocations tab

Strips some core allocation features for now, will be added back with
more features once the theme is done.
This commit is contained in:
Dane Everitt 2017-01-18 20:45:10 -05:00
parent 758927db8e
commit 88378ce983
No known key found for this signature in database
GPG Key ID: EEA66103B3D71F53
8 changed files with 185 additions and 46 deletions

View File

@ -71,7 +71,6 @@ class ServerController extends Controller
return view('server.index', [
'server' => $server,
'allocations' => Models\Allocation::where('assigned_to', $server->id)->orderBy('ip', 'asc')->orderBy('port', 'asc')->get(),
'node' => $node,
]);
}
@ -196,54 +195,21 @@ class ServerController extends Controller
return redirect($node->scheme . '://' . $node->fqdn . ':' . $node->daemonListen . '/server/file/download/' . $download->token);
}
/**
* Renders server settings page.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Contracts\View\View
*/
public function getSettings(Request $request, $uuid)
public function getAllocation(Request $request, $uuid)
{
$server = Models\Server::getByUUID($uuid);
$allocation = Models\Allocation::findOrFail($server->allocation);
$this->authorize('view-allocation', $server);
$node = Models\Node::find($server->node);
$variables = Models\ServiceVariables::select(
'service_variables.*',
DB::raw('COALESCE(server_variables.variable_value, service_variables.default_value) as a_serverValue')
)->leftJoin('server_variables', 'server_variables.variable_id', '=', 'service_variables.id')
->where('service_variables.option_id', $server->option)
->where('server_variables.server_id', $server->id)
->get();
Javascript::put([
'server' => collect($server->makeVisible('daemonSecret'))->only(['uuid', 'uuidShort', 'daemonSecret', 'username']),
'node' => collect($node)->only('fqdn', 'scheme', 'daemonListen'),
]);
$service = Models\Service::select(
DB::raw('IFNULL(service_options.executable, services.executable) as executable')
)->leftJoin('service_options', 'service_options.parent_service', '=', 'services.id')
->where('service_options.id', $server->option)
->where('services.id', $server->service)
->first();
$serverVariables = [
'{{SERVER_MEMORY}}' => $server->memory,
'{{SERVER_IP}}' => $allocation->ip,
'{{SERVER_PORT}}' => $allocation->port,
];
$processed = str_replace(array_keys($serverVariables), array_values($serverVariables), $server->startup);
foreach ($variables as &$variable) {
$replace = ($variable->user_viewable === 1) ? $variable->a_serverValue : '**';
$processed = str_replace('{{' . $variable->env_variable . '}}', $replace, $processed);
}
return view('server.settings', [
return view('server.settings.allocation', [
'server' => $server,
'databases' => Models\Database::select('databases.*', 'database_servers.host as a_host', 'database_servers.port as a_port')
->where('server_id', $server->id)
->join('database_servers', 'database_servers.id', '=', 'databases.db_server')
->get(),
'node' => Models\Node::find($server->node),
'variables' => $variables->where('user_viewable', 1),
'service' => $service,
'processedStartup' => $processed,
'allocations' => Models\Allocation::where('assigned_to', $server->id)->orderBy('ip', 'asc')->orderBy('port', 'asc')->get(),
'node' => $node,
]);
}

View File

@ -74,6 +74,11 @@ class ServerRoutes
'uses' => 'Server\ServerController@postSettingsStartup',
]);
$router->get('/settings/allocation', [
'as' => 'server.settings.allocation',
'uses' => 'Server\ServerController@getAllocation',
]);
// File Manager Routes
$router->get('/files', [
'as' => 'server.files.index',

View File

@ -498,6 +498,30 @@ class ServerPolicy
return $this->checkPermission($user, $server, 'create-task');
}
/**
* Check if user has permission to view server allocations.
*
* @param \Pterodactyl\Models\User $user
* @param \Pterodactyl\Models\Server $server
* @return bool
*/
public function viewAllocation(User $user, Server $server)
{
return $this->checkPermission($user, $server, 'view-allocation');
}
/**
* Check if user has permission to set the default allocation.
*
* @param \Pterodactyl\Models\User $user
* @param \Pterodactyl\Models\Server $server
* @return bool
*/
public function setAllocation(User $user, Server $server)
{
return $this->checkPermission($user, $server, 'set-allocation');
}
/**
* Checks if the user has the given permission on/for the server.
*

View File

@ -57,3 +57,7 @@ code {
.table {
font-size: 14px !important;
}
.middle {
vertical-align: middle !important;
}

View File

@ -31,5 +31,12 @@ return [
'no_dbs' => 'There are no databases listed for this server.',
'add_db' => 'Add a new database.',
],
'allocation' => [
'header' => 'Server Allocations',
'header_sub' => 'Control the IPs and ports available on this server.',
'available' => 'Available Allocations',
'help' => 'Allocation Help',
'help_text' => 'The list to the left includes all available IPs and ports that are open for your server to use for incoming connections.'
],
],
];

View File

@ -45,4 +45,8 @@ return [
'create' => 'Create',
'select_all' => 'Select All',
'select_none' => 'Select None',
'alias' => 'Alias',
'primary' => 'Primary',
'make_primary' => 'Make Primary',
'none' => 'None',
];

View File

@ -167,7 +167,7 @@
</a>
</li>
<li class="treeview
@if(in_array(Route::currentRouteName(), ['server.settings.sftp', 'server.settings.databases', 'server.settings.startup', 'server.settings.allocations']))
@if(in_array(Route::currentRouteName(), ['server.settings.sftp', 'server.settings.databases', 'server.settings.startup', 'server.settings.allocation']))
active
@endif
">
@ -179,7 +179,7 @@
</span>
</a>
<ul class="treeview-menu">
<li><a href=""><i class="fa fa-angle-right"></i> @lang('navigation.server.port_allocations')</a></li>
<li class="{{ Route::currentRouteName() !== 'server.settings.allocation' ?: 'active' }}"><a href="{{ route('server.settings.allocation', $server->uuidShort) }}"><i class="fa fa-angle-right"></i> @lang('navigation.server.port_allocations')</a></li>
<li class="{{ Route::currentRouteName() !== 'server.settings.sftp' ?: 'active' }}"><a href="{{ route('server.settings.sftp', $server->uuidShort) }}"><i class="fa fa-angle-right"></i> @lang('navigation.server.sftp_settings')</a></li>
<li class="{{ Route::currentRouteName() !== 'server.settings.startup' ?: 'active' }}"><a href="{{ route('server.settings.startup', $server->uuidShort) }}"><i class="fa fa-angle-right"></i> @lang('navigation.server.startup_parameters')</a></li>
<li class="{{ Route::currentRouteName() !== 'server.settings.databases' ?: 'active' }}"><a href="{{ route('server.settings.databases', $server->uuidShort) }}"><i class="fa fa-angle-right"></i> @lang('navigation.server.databases')</a></li>

View File

@ -0,0 +1,129 @@
{{-- Copyright (c) 2015 - 2016 Dane Everitt <dane@daneeveritt.com> --}}
{{-- Permission is hereby granted, free of charge, to any person obtaining a copy --}}
{{-- of this software and associated documentation files (the "Software"), to deal --}}
{{-- in the Software without restriction, including without limitation the rights --}}
{{-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell --}}
{{-- copies of the Software, and to permit persons to whom the Software is --}}
{{-- furnished to do so, subject to the following conditions: --}}
{{-- The above copyright notice and this permission notice shall be included in all --}}
{{-- copies or substantial portions of the Software. --}}
{{-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR --}}
{{-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, --}}
{{-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE --}}
{{-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER --}}
{{-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, --}}
{{-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE --}}
{{-- SOFTWARE. --}}
@extends('layouts.master')
@section('title')
@lang('server.config.allocation.header')
@endsection
@section('content-header')
<h1>@lang('server.config.allocation.header')<small>@lang('server.config.allocation.header_sub')</small></h1>
<ol class="breadcrumb">
<li><a href="{{ route('index') }}">@lang('strings.home')</a></li>
<li><a href="{{ route('server.index', $server->uuidShort) }}">{{ $server->name }}</a></li>
<li>@lang('navigation.server.configuration')</li>
<li class="active">@lang('navigation.server.port_allocations')</li>
</ol>
@endsection
@section('content')
<div class="row">
<div class="col-sm-8">
<div class="box">
<div class="box-header with-border">
<h3 class="box-title">@lang('server.config.allocation.available')</h3>
</div>
<div class="box-body table-responsive no-padding">
<table class="table table-hover">
<tbody>
<tr>
<th>@lang('strings.ip')</th>
<th>@lang('strings.alias')</th>
<th>@lang('strings.port')</th>
<th></th>
</tr>
@foreach ($allocations as $allocation)
<tr>
<td>
<code>{{ $allocation->ip }}</code>
</td>
<td class="middle">
@if(is_null($allocation->ip_alias))
<span class="label label-default">@lang('strings.none')</span>
@else
<code>{{ $allocation->ip_alias }}</code>
@endif
</td>
<td><code>{{ $allocation->port }}</code></td>
<td class="col-xs-2 middle">
@if($allocation->id === $server->allocation)
<span class="label label-success" data-allocation="{{ $allocation->id }}">@lang('strings.primary')</span>
@else
<span class="label label-default" data-action="set-connection" data-allocation="{{ $allocation->id }}">@lang('strings.make_primary')</span>
@endif
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
</div>
</div>
<div class="col-sm-4">
<div class="box">
<div class="box-header with-border">
<h3 class="box-title">@lang('server.config.allocation.help')</h3>
</div>
<div class="box-body">
<p>@lang('server.config.allocation.help_text')</p>
</div>
</div>
<div>
</div>
@endsection
@section('footer-scripts')
@parent
{!! Theme::js('js/frontend/server.socket.js') !!}
<script>
@can('reset-db-password', $server)
$('[data-action="reset-database-password"]').click(function (e) {
e.preventDefault();
var block = $(this);
$(this).find('i').addClass('fa-spin');
$.ajax({
type: 'POST',
url: Router.route('server.ajax.reset-database-password', { server: Pterodactyl.server.uuidShort }),
headers: {
'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content'),
},
data: {
'database': $(this).data('id')
}
}).done(function (data) {
block.parent().find('code').html(data);
}).fail(function(jqXHR, textStatus, errorThrown) {
console.error(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
});
}).always(function () {
block.find('i').removeClass('fa-spin');
});
});
@endcan
</script>
@endsection