From fb96d9468ed2152253db2e667f39dec3790270a9 Mon Sep 17 00:00:00 2001 From: Matthew Penner Date: Sat, 11 Apr 2020 12:35:27 -0600 Subject: [PATCH 1/6] Prevent primary allocation from being an additional allocation at the same time when creating a server --- .../themes/pterodactyl/js/admin/new-server.js | 39 +++++++++++++++++-- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/public/themes/pterodactyl/js/admin/new-server.js b/public/themes/pterodactyl/js/admin/new-server.js index 5a7393b4f..3da41da0f 100644 --- a/public/themes/pterodactyl/js/admin/new-server.js +++ b/public/themes/pterodactyl/js/admin/new-server.js @@ -21,18 +21,23 @@ $(document).ready(function() { $('#pNestId').select2({ placeholder: 'Select a Nest', }).change(); + $('#pEggId').select2({ placeholder: 'Select a Nest Egg', }); + $('#pPackId').select2({ placeholder: 'Select a Service Pack', }); + $('#pNodeId').select2({ placeholder: 'Select a Node', }).change(); + $('#pAllocation').select2({ placeholder: 'Select a Default Allocation', }); + $('#pAllocationAdditional').select2({ placeholder: 'Select Additional Allocations', }); @@ -97,10 +102,8 @@ $('#pNodeId').on('change', function () { data: v.allocations, placeholder: 'Select a Default Allocation', }); - $('#pAllocationAdditional').html('').select2({ - data: v.allocations, - placeholder: 'Select Additional Allocations', - }) + + updateAdditionalAllocations(); } }); }); @@ -154,3 +157,31 @@ $('#pEggId').on('change', function (event) { $('#appendVariablesTo').append(dataAppend); }); }); + +$('#pAllocation').on('change', function () { + updateAdditionalAllocations(); +}); + +function updateAdditionalAllocations() { + let currentAllocation = $('#pAllocation').val(); + let currentNode = $('#pNodeId').val(); + + $.each(Pterodactyl.nodeData, function (i, v) { + if (v.id == currentNode) { + let allocations = []; + + for (let i = 0; i < v.allocations.length; i++) { + const allocation = v.allocations[i]; + + if (allocation.id != currentAllocation) { + allocations.push(allocation); + } + } + + $('#pAllocationAdditional').html('').select2({ + data: allocations, + placeholder: 'Select Additional Allocations', + }); + } + }); +} From b5e50719acd05b3abb7daa5687a397eb6095e350 Mon Sep 17 00:00:00 2001 From: Matthew Penner Date: Sat, 11 Apr 2020 13:56:03 -0600 Subject: [PATCH 2/6] Remove old Theme::js calls in blade layouts. Persist checkboxes, Server Owner, Node, Default Allocation, and Additional Allocations on servers/new.blade.php --- .../Repository/UserRepositoryInterface.php | 8 ++ app/Helpers/Utilities.php | 12 ++ app/Http/Controllers/Admin/UserController.php | 7 +- app/Repositories/Eloquent/UserRepository.php | 18 +++ .../themes/pterodactyl/js/admin/new-server.js | 91 ++++++------ resources/views/admin/servers/new.blade.php | 132 ++++++++++++++---- resources/views/layouts/admin.blade.php | 6 +- resources/views/layouts/auth.blade.php | 2 +- resources/views/layouts/master.blade.php | 6 +- 9 files changed, 209 insertions(+), 73 deletions(-) diff --git a/app/Contracts/Repository/UserRepositoryInterface.php b/app/Contracts/Repository/UserRepositoryInterface.php index 41649f48b..f5ba47b4b 100644 --- a/app/Contracts/Repository/UserRepositoryInterface.php +++ b/app/Contracts/Repository/UserRepositoryInterface.php @@ -22,4 +22,12 @@ interface UserRepositoryInterface extends RepositoryInterface, SearchableInterfa * @return \Illuminate\Support\Collection */ public function filterUsersByQuery(?string $query): Collection; + + /** + * Returns a user with the given id in a format that can be used for dropdowns. + * + * @param int $id + * @return \Pterodactyl\Models\Model + */ + public function filterById(int $id): \Pterodactyl\Models\Model; } diff --git a/app/Helpers/Utilities.php b/app/Helpers/Utilities.php index 2a0689124..d900425d9 100644 --- a/app/Helpers/Utilities.php +++ b/app/Helpers/Utilities.php @@ -6,6 +6,7 @@ use Exception; use Carbon\Carbon; use Cron\CronExpression; use Illuminate\Support\Facades\Log; +use Illuminate\Support\ViewErrorBag; class Utilities { @@ -50,4 +51,15 @@ class Utilities sprintf('%s %s %s * %s', $minute, $hour, $dayOfMonth, $dayOfWeek) )->getNextRunDate()); } + + public static function checked($name, $default) + { + $errors = session('errors'); + + if (isset($errors) && $errors instanceof ViewErrorBag && $errors->any()) { + return old($name) ? 'checked' : ''; + } + + return ($default) ? 'checked' : ''; + } } diff --git a/app/Http/Controllers/Admin/UserController.php b/app/Http/Controllers/Admin/UserController.php index 14b3b594f..18e7e3b43 100644 --- a/app/Http/Controllers/Admin/UserController.php +++ b/app/Http/Controllers/Admin/UserController.php @@ -177,10 +177,15 @@ class UserController extends Controller * Get a JSON response of users on the system. * * @param \Illuminate\Http\Request $request - * @return \Illuminate\Support\Collection + * @return \Illuminate\Support\Collection|\Pterodactyl\Models\Model */ public function json(Request $request) { + // Handle single user requests. + if ($request->query('user_id')) { + return $this->repository->filterById($request->input('user_id')); + } + return $this->repository->filterUsersByQuery($request->input('q')); } } diff --git a/app/Repositories/Eloquent/UserRepository.php b/app/Repositories/Eloquent/UserRepository.php index 1ed6c5b74..b6468b5bb 100644 --- a/app/Repositories/Eloquent/UserRepository.php +++ b/app/Repositories/Eloquent/UserRepository.php @@ -54,4 +54,22 @@ class UserRepository extends EloquentRepository implements UserRepositoryInterfa return $item; }); } + + /** + * Returns a user with the given id in a format that can be used for dropdowns. + * + * @param int $id + * @return \Pterodactyl\Models\Model + */ + public function filterById(int $id): \Pterodactyl\Models\Model + { + $this->setColumns([ + 'id', 'email', 'username', 'name_first', 'name_last', + ]); + + $model = $this->getBuilder()->findOrFail($id, $this->getColumns())->getModel(); + $model->md5 = md5(strtolower($model->email)); + + return $model; + } } diff --git a/public/themes/pterodactyl/js/admin/new-server.js b/public/themes/pterodactyl/js/admin/new-server.js index 3da41da0f..cf8766356 100644 --- a/public/themes/pterodactyl/js/admin/new-server.js +++ b/public/themes/pterodactyl/js/admin/new-server.js @@ -41,47 +41,6 @@ $(document).ready(function() { $('#pAllocationAdditional').select2({ placeholder: 'Select Additional Allocations', }); - - $('#pUserId').select2({ - ajax: { - url: '/admin/users/accounts.json', - dataType: 'json', - delay: 250, - data: function (params) { - return { - q: params.term, // search term - page: params.page, - }; - }, - processResults: function (data, params) { - return { results: data }; - }, - cache: true, - }, - escapeMarkup: function (markup) { return markup; }, - minimumInputLength: 2, - templateResult: function (data) { - if (data.loading) return data.text; - - return '
\ - User Image \ - \ - ' + data.name_first + ' ' + data.name_last +' \ - \ - ' + data.email + ' - ' + data.username + ' \ -
'; - }, - templateSelection: function (data) { - return '
\ - \ - User Image \ - \ - \ - ' + data.name_first + ' ' + data.name_last + ' (' + data.email + ') \ - \ -
'; - } - }); }); var lastActiveBox = null; @@ -185,3 +144,53 @@ function updateAdditionalAllocations() { } }); } + +function initUserIdSelect(data) { + $('#pUserId').select2({ + ajax: { + url: '/admin/users/accounts.json', + dataType: 'json', + delay: 250, + + data: function (params) { + return { + q: params.term, // search term + page: params.page, + }; + }, + + processResults: function (data, params) { + return { results: data }; + }, + + cache: true, + }, + + data: data, + escapeMarkup: function (markup) { return markup; }, + minimumInputLength: 2, + + templateResult: function (data) { + if (data.loading) return data.text; + + return '
\ + User Image \ + \ + ' + data.name_first + ' ' + data.name_last +' \ + \ + ' + data.email + ' - ' + data.username + ' \ +
'; + }, + + templateSelection: function (data) { + return '
\ + \ + User Image \ + \ + \ + ' + data.name_first + ' ' + data.name_last + ' (' + data.email + ') \ + \ +
'; + } + }); +} diff --git a/resources/views/admin/servers/new.blade.php b/resources/views/admin/servers/new.blade.php index 7aa4477e9..59011aa46 100644 --- a/resources/views/admin/servers/new.blade.php +++ b/resources/views/admin/servers/new.blade.php @@ -26,6 +26,7 @@

Core Details

+
@@ -33,20 +34,23 @@

Character limits: a-z A-Z 0-9 _ - . and [Space] (max 200 characters).

+
- +
+
- - + +

A brief description of this server.

+
- +
@@ -55,6 +59,7 @@
+
@@ -62,6 +67,7 @@

Allocation Management

+
@@ -78,22 +84,26 @@ @endforeach +

The node which this server will be deployed to.

+
- +

The main allocation that will be assigned to this server.

+
- +

Additional allocations to assign to this server on creation.

+
@@ -101,18 +111,20 @@

Application Feature Limits

+
- +
- +

The total number of databases a user is allowed to create for this server. Leave blank to allow unlimited.

+
- +
- +

The total number of allocations a user is allowed to create for this server. Leave blank to allow unlimited.

@@ -126,71 +138,90 @@

Resource Management

+
+
- + %
-

If you do not want to limit CPU usage, set the value to 0. To determine a value, take the number of physical cores and multiply it by 100. For example, on a quad core system (4 * 100 = 400) there is 400% available. To limit a server to using half of a single core, you would set the value to 50. To allow a server to use up to two physical cores, set the value to 200. BlockIO should be a value between 10 and 1000. Please see this documentation for more information about it.

+ +

If you do not want to limit CPU usage, set the value to 0. To determine a value, take the number of physical cores and multiply it by 100. For example, on a quad core system (4 * 100 = 400) there is 400% available. To limit a server to using half of a single core, you would set the value to 50. To allow a server to use up to two physical cores, set the value to 200. BlockIO should be a value between 10 and 1000. Please see this documentation for more information about it.

+
+
- +
+

Advanced: Enter the specific CPU cores that this process can run on, or leave blank to allow all cores. This can be a single number, or a comma seperated list. Example: 0, 0-1,3, or 0,1,3,4.

+
+
- + MB
+
+
- + MB
+ +
+
- - MB + + MB
+
+
- +
-

Advanced: The IO performance of this server relative to other running containers on the system. Value should be between 10 and 1000.

+ +

Advanced: The IO performance of this server relative to other running containers on the system. Value should be between 10 and 1000.

+

Nest Configuration

+
- @foreach($nests as $nest) @endforeach +

Select the Nest that this server will be grouped under.

+
- +

Select the Egg that will define how this server should operate.

+
- +

Select a data pack to be automatically installed on this server when first created.

+
- +
+

If the selected Egg has an install script attached to it, the script will run during install after the pack is installed. If you would like to skip this step, check this box.

+

Docker Configuration

+
@@ -236,23 +274,28 @@
+

Startup Configuration

+
- +

The following data substitutes are available for the startup command: @{{SERVER_MEMORY}}, @{{SERVER_IP}}, and @{{SERVER_PORT}}. They will be replaced with the allocated memory, server IP, and server port respectively.

+

Service Variables

+
+ @section('footer-scripts') - {!! Theme::js('js/keyboard.polyfill.js') !!} - + {{--{!! Theme::js('js/keyboard.polyfill.js') !!} + --}} {!! Theme::js('vendor/jquery/jquery.min.js?t={cache-version}') !!} {!! Theme::js('vendor/sweetalert/sweetalert.min.js?t={cache-version}') !!} @@ -185,7 +185,7 @@ {!! Theme::js('vendor/bootstrap-notify/bootstrap-notify.min.js?t={cache-version}') !!} {!! Theme::js('vendor/select2/select2.full.min.js?t={cache-version}') !!} {!! Theme::js('js/admin/functions.js?t={cache-version}') !!} - {!! Theme::js('js/autocomplete.js?t={cache-version}') !!} + {{-- {!! Theme::js('js/autocomplete.js?t={cache-version}') !!} --}} @if(Auth::user()->root_admin) + {{--{!! Theme::js('js/keyboard.polyfill.js?t={cache-version}') !!} + --}} {!! Theme::js('vendor/jquery/jquery.min.js?t={cache-version}') !!} {!! Theme::js('vendor/sweetalert/sweetalert.min.js?t={cache-version}') !!} @@ -284,7 +284,7 @@ {!! Theme::js('vendor/adminlte/app.min.js?t={cache-version}') !!} {!! Theme::js('vendor/socketio/socket.io.v203.min.js?t={cache-version}') !!} {!! Theme::js('vendor/bootstrap-notify/bootstrap-notify.min.js?t={cache-version}') !!} - {!! Theme::js('js/autocomplete.js?t={cache-version}') !!} + {{-- {!! Theme::js('js/autocomplete.js?t={cache-version}') !!} --}} @if(Auth::user()->root_admin) @endsection From a7dab697115713ee45728a36296b31edf5d31fc8 Mon Sep 17 00:00:00 2001 From: Matthew Penner Date: Sat, 11 Apr 2020 14:46:30 -0600 Subject: [PATCH 5/6] Persist service variables --- .../themes/pterodactyl/js/admin/new-server.js | 7 +++ resources/views/admin/servers/new.blade.php | 48 +++++++++++++------ 2 files changed, 41 insertions(+), 14 deletions(-) diff --git a/public/themes/pterodactyl/js/admin/new-server.js b/public/themes/pterodactyl/js/admin/new-server.js index d52502f33..3e0718a46 100644 --- a/public/themes/pterodactyl/js/admin/new-server.js +++ b/public/themes/pterodactyl/js/admin/new-server.js @@ -101,8 +101,11 @@ $('#pEggId').on('change', function (event) { ), }); + const variableIds = {}; $('#appendVariablesTo').html(''); $.each(_.get(objectChain, 'variables', []), function (i, item) { + variableIds[item.env_variable] = 'var_ref_' + item.id; + let isRequired = (item.required === 1) ? 'Required ' : ''; let dataAppend = ' \
\ @@ -115,6 +118,10 @@ $('#pEggId').on('change', function (event) { '; $('#appendVariablesTo').append(dataAppend); }); + + // If you receive a warning on this line, it should be fine to ignore. this function is + // defined in "resources/views/admin/servers/new.blade.php" near the bottom of the file. + serviceVariablesUpdated($('#pEggId').val(), variableIds); }); $('#pAllocation').on('change', function () { diff --git a/resources/views/admin/servers/new.blade.php b/resources/views/admin/servers/new.blade.php index b3418347e..1d61f1a50 100644 --- a/resources/views/admin/servers/new.blade.php +++ b/resources/views/admin/servers/new.blade.php @@ -309,11 +309,31 @@ @section('footer-scripts') @parent {!! Theme::js('vendor/lodash/lodash.js') !!} + + + {!! Theme::js('js/admin/new-server.js') !!} @endsection From 4d833af5f4190d565b4a84d68824e30ef464df18 Mon Sep 17 00:00:00 2001 From: Matthew Penner Date: Sat, 11 Apr 2020 14:49:40 -0600 Subject: [PATCH 6/6] Fix script paths in layouts --- resources/views/layouts/admin.blade.php | 6 +++--- resources/views/layouts/auth.blade.php | 2 +- resources/views/layouts/master.blade.php | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/resources/views/layouts/admin.blade.php b/resources/views/layouts/admin.blade.php index 6559c89d2..551d83860 100644 --- a/resources/views/layouts/admin.blade.php +++ b/resources/views/layouts/admin.blade.php @@ -173,8 +173,8 @@
@section('footer-scripts') - {{--{!! Theme::js('js/keyboard.polyfill.js') !!} - --}} + + {!! Theme::js('vendor/jquery/jquery.min.js?t={cache-version}') !!} {!! Theme::js('vendor/sweetalert/sweetalert.min.js?t={cache-version}') !!} @@ -185,7 +185,7 @@ {!! Theme::js('vendor/bootstrap-notify/bootstrap-notify.min.js?t={cache-version}') !!} {!! Theme::js('vendor/select2/select2.full.min.js?t={cache-version}') !!} {!! Theme::js('js/admin/functions.js?t={cache-version}') !!} - {{-- {!! Theme::js('js/autocomplete.js?t={cache-version}') !!} --}} + @if(Auth::user()->root_admin) {!! Theme::js('vendor/particlesjs/particles.min.js?t={cache-version}') !!} --}} + + {!! Theme::js('vendor/jquery/jquery.min.js?t={cache-version}') !!} {!! Theme::js('vendor/sweetalert/sweetalert.min.js?t={cache-version}') !!} @@ -284,7 +284,7 @@ {!! Theme::js('vendor/adminlte/app.min.js?t={cache-version}') !!} {!! Theme::js('vendor/socketio/socket.io.v203.min.js?t={cache-version}') !!} {!! Theme::js('vendor/bootstrap-notify/bootstrap-notify.min.js?t={cache-version}') !!} - {{-- {!! Theme::js('js/autocomplete.js?t={cache-version}') !!} --}} + @if(Auth::user()->root_admin)