From a9d0b4a4fedc02f65d350f8e06524b9646329d9d Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Thu, 29 Sep 2016 21:34:20 -0400 Subject: [PATCH] Add support for setting IP aliases though panel --- CHANGELOG.md | 1 + .../Controllers/Admin/NodesController.php | 74 +++++--- app/Http/Routes/AdminRoutes.php | 13 +- public/themes/default/css/pterodactyl.css | 18 ++ resources/views/admin/nodes/view.blade.php | 170 +++++++++++------- .../views/vendor/pagination/default.blade.php | 6 +- 6 files changed, 188 insertions(+), 94 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 438425131..e1426d64a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ This project follows [Semantic Versioning](http://semver.org) guidelines. ### Added * Support for creating server without having to assign a node and allocation manually. Simply select the checkbox or pass `auto_deploy=true` to the API to auto-select a node and allocation given a location. +* Support for setting IP Aliases through the panel on the node overview page. Also cleaned up allocation removal. ### Changed * Prevent clicking server start button until server is completely off, not just stopping. diff --git a/app/Http/Controllers/Admin/NodesController.php b/app/Http/Controllers/Admin/NodesController.php index 75ed5043a..26051081e 100644 --- a/app/Http/Controllers/Admin/NodesController.php +++ b/app/Http/Controllers/Admin/NodesController.php @@ -96,32 +96,21 @@ class NodesController extends Controller public function getView(Request $request, $id) { $node = Models\Node::findOrFail($id); - $allocations = []; - $alloc = Models\Allocation::select('ip', 'port', 'assigned_to')->where('node', $node->id)->orderBy('ip', 'asc')->orderBy('port', 'asc')->get(); - if ($alloc) { - foreach($alloc as &$alloc) { - if (!array_key_exists($alloc->ip, $allocations)) { - $allocations[$alloc->ip] = [[ - 'port' => $alloc->port, - 'assigned_to' => $alloc->assigned_to - ]]; - } else { - array_push($allocations[$alloc->ip], [ - 'port' => $alloc->port, - 'assigned_to' => $alloc->assigned_to - ]); - } - } - } + return view('admin.nodes.view', [ 'node' => $node, 'servers' => Models\Server::select('servers.*', 'users.email as a_ownerEmail', 'services.name as a_serviceName') ->join('users', 'users.id', '=', 'servers.owner') ->join('services', 'services.id', '=', 'servers.service') - ->where('node', $id)->paginate(10), + ->where('node', $id)->paginate(10, ['*'], 'servers'), 'stats' => Models\Server::select(DB::raw('SUM(memory) as memory, SUM(disk) as disk'))->where('node', $node->id)->first(), 'locations' => Models\Location::all(), - 'allocations' => json_decode(json_encode($allocations), false), + 'allocations' => Models\Allocation::select('allocations.*', 'servers.name as assigned_to_name') + ->where('allocations.node', $node->id) + ->leftJoin('servers', 'servers.id', '=', 'allocations.assigned_to') + ->orderBy('allocations.ip', 'asc') + ->orderBy('allocations.port', 'asc') + ->paginate(20, ['*'], 'allocations'), ]); } @@ -151,24 +140,51 @@ class NodesController extends Controller ])->withInput(); } - public function deleteAllocation(Request $request, $id, $ip, $port = null) + public function deallocateSingle(Request $request, $node, $allocation) { - $query = Models\Allocation::where('node', $id)->whereNull('assigned_to')->where('ip', $ip); - if (is_null($port) || $port === 'undefined') { - $allocation = $query; - } else { - $allocation = $query->where('port', $port)->first(); - } - - if (!$allocation) { + $query = Models\Allocation::where('node', $node)->whereNull('assigned_to')->where('id', $allocation)->delete(); + if ((int) $query === 0) { return response()->json([ 'error' => 'Unable to find an allocation matching those details to delete.' ], 400); } - $allocation->delete(); return response('', 204); } + public function deallocateBlock(Request $request, $node) + { + $query = Models\Allocation::where('node', $node)->whereNull('assigned_to')->where('ip', $request->input('ip'))->delete(); + if ((int) $query === 0) { + Alert::danger('There was an error while attempting to delete allocations on that IP.')->flash(); + return redirect()->route('admin.nodes.view', [ + 'id' => $node, + 'tab' => 'tab_allocations' + ]); + } + Alert::success('Deleted all unallocated ports for ' . $request->input('ip') . '.')->flash(); + return redirect()->route('admin.nodes.view', [ + 'id' => $node, + 'tab' => 'tab_allocations' + ]); + } + + public function setAlias(Request $request, $node) + { + if (!$request->input('allocation')) { + return response('Missing required parameters.', 422); + } + + try { + $update = Models\Allocation::findOrFail($request->input('allocation')); + $update->ip_alias = $request->input('alias'); + $update->save(); + + return response('', 204); + } catch (\Exception $ex) { + throw $ex; + } + } + public function getAllocationsJson(Request $request, $id) { $allocations = Models\Allocation::select('ip')->where('node', $id)->groupBy('ip')->get(); diff --git a/app/Http/Routes/AdminRoutes.php b/app/Http/Routes/AdminRoutes.php index 2a209e35b..a1d1956e0 100644 --- a/app/Http/Routes/AdminRoutes.php +++ b/app/Http/Routes/AdminRoutes.php @@ -243,8 +243,17 @@ class AdminRoutes { 'uses' => 'Admin\NodesController@postView' ]); - $router->delete('/view/{id}/allocation/{ip}/{port?}', [ - 'uses' => 'Admin\NodesController@deleteAllocation' + $router->delete('/view/{id}/deallocate/single/{allocation}', [ + 'uses' => 'Admin\NodesController@deallocateSingle' + ]); + + $router->post('/view/{id}/deallocate/block', [ + 'uses' => 'Admin\NodesController@deallocateBlock' + ]); + + $router->post('/view/{id}/alias', [ + 'as' => 'admin.nodes.alias', + 'uses' => 'Admin\NodesController@setAlias' ]); $router->get('/view/{id}/allocations.json', [ diff --git a/public/themes/default/css/pterodactyl.css b/public/themes/default/css/pterodactyl.css index 04798f049..6284089f9 100755 --- a/public/themes/default/css/pterodactyl.css +++ b/public/themes/default/css/pterodactyl.css @@ -90,6 +90,21 @@ body{font-size:13px} .btn-xxs{padding:2px 6px;font-size:10px;-webkit-border-radius:1px;-moz-border-radius:1px;border-radius:2px} .form-control{height:36px} .input-group-addon{font-size:12px;} +.input-sm { + height: 30px; + padding: 4px 8px !important; + font-size: 12px !important; + border-radius: 2px; +} +.input-loader { + display: none; + position:relative; + top: -23px; + float: right; + right: 5px; + color: #cccccc; + height: 0; +} pre{display:block;padding:12px 12px;margin:0;font-size:12px;color:#c7254e;background-color:#f9f2f4;border:1px solid #c7254e;border-radius:0;white-space:pre} .badge.label-danger {background: #d9534f !important;} .close {color:#000;opacity:0.2;font-size:1.6em;} @@ -102,6 +117,9 @@ form .text-muted {margin: 0 0 -5.5px} .label{border-radius: .25em;padding: .2em .6em .3em;} kbd{border-radius: .25em} .modal-open .modal {padding-left: 0px !important;padding-right: 0px !important;overflow-y: scroll;} +.align-middle { + vertical-align: middle !important; +} /** * Pillboxes diff --git a/resources/views/admin/nodes/view.blade.php b/resources/views/admin/nodes/view.blade.php index 811ebda29..5f70604fd 100644 --- a/resources/views/admin/nodes/view.blade.php +++ b/resources/views/admin/nodes/view.blade.php @@ -307,45 +307,6 @@
-
- - - - - - - - @foreach($allocations as $ip => $ports) - - - - - - @endforeach - -
IP AddressPorts
{{ $ip }} - @foreach($ports as $id => $allocation) - @if (($id % 2) === 0) - @if($allocation->assigned_to === null) - {{ $allocation->port }}
- @else - {{ $allocation->port }}
- @endif - @endif - @endforeach -
- @foreach($ports as $id => $allocation) - @if (($id % 2) === 1) - @if($allocation->assigned_to === null) - {{ $allocation->port }}
- @else - {{ $allocation->port }}
- @endif - @endif - @endforeach -
-
-

Allocate Additional Ports

@@ -391,6 +352,43 @@
+
+
+
+ + + + + + + + + + @foreach($allocations as $allocation) + + + + + + + + @endforeach + +
IP Address IP AliasPortAssigned To
{{ $allocation->ip }} + + + {{ $allocation->port }}@if(!is_null($allocation->assigned_to)){{ $allocation->assigned_to_name }}@endif + @if(is_null($allocation->assigned_to)) + + @else + + @endif +
+
+ {{ $allocations->appends(['tab' => 'tab_allocation'])->links() }} +
+
+
@@ -458,6 +456,38 @@
+ @endsection diff --git a/resources/views/vendor/pagination/default.blade.php b/resources/views/vendor/pagination/default.blade.php index 668fc1330..26e56994f 100644 --- a/resources/views/vendor/pagination/default.blade.php +++ b/resources/views/vendor/pagination/default.blade.php @@ -1,8 +1,8 @@ -@if ($paginator->count() > 1) +@if ($paginator->lastPage() > 1) @endif