Skip to content

Commit 88378ce

Browse files
committed
Add allocations tab
Strips some core allocation features for now, will be added back with more features once the theme is done.
1 parent 758927d commit 88378ce

File tree

8 files changed

+185
-46
lines changed

8 files changed

+185
-46
lines changed

app/Http/Controllers/Server/ServerController.php

Lines changed: 10 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ public function getIndex(Request $request)
7171

7272
return view('server.index', [
7373
'server' => $server,
74-
'allocations' => Models\Allocation::where('assigned_to', $server->id)->orderBy('ip', 'asc')->orderBy('port', 'asc')->get(),
7574
'node' => $node,
7675
]);
7776
}
@@ -196,54 +195,21 @@ public function getDownloadFile(Request $request, $uuid, $file)
196195
return redirect($node->scheme . '://' . $node->fqdn . ':' . $node->daemonListen . '/server/file/download/' . $download->token);
197196
}
198197

199-
/**
200-
* Renders server settings page.
201-
*
202-
* @param \Illuminate\Http\Request $request
203-
* @return \Illuminate\Contracts\View\View
204-
*/
205-
public function getSettings(Request $request, $uuid)
198+
public function getAllocation(Request $request, $uuid)
206199
{
207200
$server = Models\Server::getByUUID($uuid);
208-
$allocation = Models\Allocation::findOrFail($server->allocation);
209-
210-
$variables = Models\ServiceVariables::select(
211-
'service_variables.*',
212-
DB::raw('COALESCE(server_variables.variable_value, service_variables.default_value) as a_serverValue')
213-
)->leftJoin('server_variables', 'server_variables.variable_id', '=', 'service_variables.id')
214-
->where('service_variables.option_id', $server->option)
215-
->where('server_variables.server_id', $server->id)
216-
->get();
217-
218-
$service = Models\Service::select(
219-
DB::raw('IFNULL(service_options.executable, services.executable) as executable')
220-
)->leftJoin('service_options', 'service_options.parent_service', '=', 'services.id')
221-
->where('service_options.id', $server->option)
222-
->where('services.id', $server->service)
223-
->first();
224-
225-
$serverVariables = [
226-
'{{SERVER_MEMORY}}' => $server->memory,
227-
'{{SERVER_IP}}' => $allocation->ip,
228-
'{{SERVER_PORT}}' => $allocation->port,
229-
];
201+
$this->authorize('view-allocation', $server);
202+
$node = Models\Node::find($server->node);
230203

231-
$processed = str_replace(array_keys($serverVariables), array_values($serverVariables), $server->startup);
232-
foreach ($variables as &$variable) {
233-
$replace = ($variable->user_viewable === 1) ? $variable->a_serverValue : '**';
234-
$processed = str_replace('{{' . $variable->env_variable . '}}', $replace, $processed);
235-
}
204+
Javascript::put([
205+
'server' => collect($server->makeVisible('daemonSecret'))->only(['uuid', 'uuidShort', 'daemonSecret', 'username']),
206+
'node' => collect($node)->only('fqdn', 'scheme', 'daemonListen'),
207+
]);
236208

237-
return view('server.settings', [
209+
return view('server.settings.allocation', [
238210
'server' => $server,
239-
'databases' => Models\Database::select('databases.*', 'database_servers.host as a_host', 'database_servers.port as a_port')
240-
->where('server_id', $server->id)
241-
->join('database_servers', 'database_servers.id', '=', 'databases.db_server')
242-
->get(),
243-
'node' => Models\Node::find($server->node),
244-
'variables' => $variables->where('user_viewable', 1),
245-
'service' => $service,
246-
'processedStartup' => $processed,
211+
'allocations' => Models\Allocation::where('assigned_to', $server->id)->orderBy('ip', 'asc')->orderBy('port', 'asc')->get(),
212+
'node' => $node,
247213
]);
248214
}
249215

app/Http/Routes/ServerRoutes.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ public function map(Router $router)
7474
'uses' => 'Server\ServerController@postSettingsStartup',
7575
]);
7676

77+
$router->get('/settings/allocation', [
78+
'as' => 'server.settings.allocation',
79+
'uses' => 'Server\ServerController@getAllocation',
80+
]);
81+
7782
// File Manager Routes
7883
$router->get('/files', [
7984
'as' => 'server.files.index',

app/Policies/ServerPolicy.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,30 @@ public function createTask(User $user, Server $server)
498498
return $this->checkPermission($user, $server, 'create-task');
499499
}
500500

501+
/**
502+
* Check if user has permission to view server allocations.
503+
*
504+
* @param \Pterodactyl\Models\User $user
505+
* @param \Pterodactyl\Models\Server $server
506+
* @return bool
507+
*/
508+
public function viewAllocation(User $user, Server $server)
509+
{
510+
return $this->checkPermission($user, $server, 'view-allocation');
511+
}
512+
513+
/**
514+
* Check if user has permission to set the default allocation.
515+
*
516+
* @param \Pterodactyl\Models\User $user
517+
* @param \Pterodactyl\Models\Server $server
518+
* @return bool
519+
*/
520+
public function setAllocation(User $user, Server $server)
521+
{
522+
return $this->checkPermission($user, $server, 'set-allocation');
523+
}
524+
501525
/**
502526
* Checks if the user has the given permission on/for the server.
503527
*

public/themes/pterodactyl/css/pterodactyl.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,7 @@ code {
5757
.table {
5858
font-size: 14px !important;
5959
}
60+
61+
.middle {
62+
vertical-align: middle !important;
63+
}

resources/lang/en/server.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,12 @@
3131
'no_dbs' => 'There are no databases listed for this server.',
3232
'add_db' => 'Add a new database.',
3333
],
34+
'allocation' => [
35+
'header' => 'Server Allocations',
36+
'header_sub' => 'Control the IPs and ports available on this server.',
37+
'available' => 'Available Allocations',
38+
'help' => 'Allocation Help',
39+
'help_text' => 'The list to the left includes all available IPs and ports that are open for your server to use for incoming connections.'
40+
],
3441
],
3542
];

resources/lang/en/strings.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,8 @@
4545
'create' => 'Create',
4646
'select_all' => 'Select All',
4747
'select_none' => 'Select None',
48+
'alias' => 'Alias',
49+
'primary' => 'Primary',
50+
'make_primary' => 'Make Primary',
51+
'none' => 'None',
4852
];

resources/themes/pterodactyl/layouts/master.blade.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@
167167
</a>
168168
</li>
169169
<li class="treeview
170-
@if(in_array(Route::currentRouteName(), ['server.settings.sftp', 'server.settings.databases', 'server.settings.startup', 'server.settings.allocations']))
170+
@if(in_array(Route::currentRouteName(), ['server.settings.sftp', 'server.settings.databases', 'server.settings.startup', 'server.settings.allocation']))
171171
active
172172
@endif
173173
">
@@ -179,7 +179,7 @@
179179
</span>
180180
</a>
181181
<ul class="treeview-menu">
182-
<li><a href=""><i class="fa fa-angle-right"></i> @lang('navigation.server.port_allocations')</a></li>
182+
<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>
183183
<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>
184184
<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>
185185
<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>
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
{{-- Copyright (c) 2015 - 2016 Dane Everitt <dane@daneeveritt.com> --}}
2+
3+
{{-- Permission is hereby granted, free of charge, to any person obtaining a copy --}}
4+
{{-- of this software and associated documentation files (the "Software"), to deal --}}
5+
{{-- in the Software without restriction, including without limitation the rights --}}
6+
{{-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell --}}
7+
{{-- copies of the Software, and to permit persons to whom the Software is --}}
8+
{{-- furnished to do so, subject to the following conditions: --}}
9+
10+
{{-- The above copyright notice and this permission notice shall be included in all --}}
11+
{{-- copies or substantial portions of the Software. --}}
12+
13+
{{-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR --}}
14+
{{-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, --}}
15+
{{-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE --}}
16+
{{-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER --}}
17+
{{-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, --}}
18+
{{-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE --}}
19+
{{-- SOFTWARE. --}}
20+
@extends('layouts.master')
21+
22+
@section('title')
23+
@lang('server.config.allocation.header')
24+
@endsection
25+
26+
@section('content-header')
27+
<h1>@lang('server.config.allocation.header')<small>@lang('server.config.allocation.header_sub')</small></h1>
28+
<ol class="breadcrumb">
29+
<li><a href="{{ route('index') }}">@lang('strings.home')</a></li>
30+
<li><a href="{{ route('server.index', $server->uuidShort) }}">{{ $server->name }}</a></li>
31+
<li>@lang('navigation.server.configuration')</li>
32+
<li class="active">@lang('navigation.server.port_allocations')</li>
33+
</ol>
34+
@endsection
35+
36+
@section('content')
37+
<div class="row">
38+
<div class="col-sm-8">
39+
<div class="box">
40+
<div class="box-header with-border">
41+
<h3 class="box-title">@lang('server.config.allocation.available')</h3>
42+
</div>
43+
<div class="box-body table-responsive no-padding">
44+
<table class="table table-hover">
45+
<tbody>
46+
<tr>
47+
<th>@lang('strings.ip')</th>
48+
<th>@lang('strings.alias')</th>
49+
<th>@lang('strings.port')</th>
50+
<th></th>
51+
</tr>
52+
@foreach ($allocations as $allocation)
53+
<tr>
54+
<td>
55+
<code>{{ $allocation->ip }}</code>
56+
</td>
57+
<td class="middle">
58+
@if(is_null($allocation->ip_alias))
59+
<span class="label label-default">@lang('strings.none')</span>
60+
@else
61+
<code>{{ $allocation->ip_alias }}</code>
62+
@endif
63+
</td>
64+
<td><code>{{ $allocation->port }}</code></td>
65+
<td class="col-xs-2 middle">
66+
@if($allocation->id === $server->allocation)
67+
<span class="label label-success" data-allocation="{{ $allocation->id }}">@lang('strings.primary')</span>
68+
@else
69+
<span class="label label-default" data-action="set-connection" data-allocation="{{ $allocation->id }}">@lang('strings.make_primary')</span>
70+
@endif
71+
</td>
72+
</tr>
73+
@endforeach
74+
</tbody>
75+
</table>
76+
</div>
77+
</div>
78+
</div>
79+
<div class="col-sm-4">
80+
<div class="box">
81+
<div class="box-header with-border">
82+
<h3 class="box-title">@lang('server.config.allocation.help')</h3>
83+
</div>
84+
<div class="box-body">
85+
<p>@lang('server.config.allocation.help_text')</p>
86+
</div>
87+
</div>
88+
<div>
89+
</div>
90+
@endsection
91+
92+
@section('footer-scripts')
93+
@parent
94+
{!! Theme::js('js/frontend/server.socket.js') !!}
95+
<script>
96+
@can('reset-db-password', $server)
97+
$('[data-action="reset-database-password"]').click(function (e) {
98+
e.preventDefault();
99+
var block = $(this);
100+
$(this).find('i').addClass('fa-spin');
101+
$.ajax({
102+
type: 'POST',
103+
url: Router.route('server.ajax.reset-database-password', { server: Pterodactyl.server.uuidShort }),
104+
headers: {
105+
'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content'),
106+
},
107+
data: {
108+
'database': $(this).data('id')
109+
}
110+
}).done(function (data) {
111+
block.parent().find('code').html(data);
112+
}).fail(function(jqXHR, textStatus, errorThrown) {
113+
console.error(jqXHR);
114+
var error = 'An error occured while trying to process this request.';
115+
if (typeof jqXHR.responseJSON !== 'undefined' && typeof jqXHR.responseJSON.error !== 'undefined') {
116+
error = jqXHR.responseJSON.error;
117+
}
118+
swal({
119+
type: 'error',
120+
title: 'Whoops!',
121+
text: error
122+
});
123+
}).always(function () {
124+
block.find('i').removeClass('fa-spin');
125+
});
126+
});
127+
@endcan
128+
</script>
129+
@endsection

0 commit comments

Comments
 (0)