From dfc3d0bd427f7dae1181413b56c7a5aae730dded Mon Sep 17 00:00:00 2001 From: ok236449 Date: Tue, 23 Aug 2022 20:08:49 +0200 Subject: [PATCH 1/4] fix division by zero --- app/Http/Controllers/Admin/OverViewController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/Admin/OverViewController.php b/app/Http/Controllers/Admin/OverViewController.php index 178e4822..c0cb0c4c 100644 --- a/app/Http/Controllers/Admin/OverViewController.php +++ b/app/Http/Controllers/Admin/OverViewController.php @@ -97,7 +97,7 @@ class OverViewController extends Controller $output[$nodeId]->totalEarnings = 0; $output[$nodeId]->activeEarnings = 0; } - $counters['totalUsagePercent'] = round($counters['totalUsagePercent']/$nodes->count(), 2); + $counters['totalUsagePercent'] = ($nodes->count())?round($counters['totalUsagePercent']/$nodes->count(), 2):0; foreach(Pterodactyl::getServers() as $server){ //gets all servers from Pterodactyl and calculates total of credit usage for each node separately + total $nodeId = $server['attributes']['node']; From 30d29cdd62fd6727e22131e2cdcf4147e454b43d Mon Sep 17 00:00:00 2001 From: ok236449 Date: Wed, 24 Aug 2022 17:52:05 +0200 Subject: [PATCH 2/4] Check for overallocation for every package --- app/Http/Controllers/ProductController.php | 14 +++++++++++++- resources/views/servers/create.blade.php | 4 ++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/ProductController.php b/app/Http/Controllers/ProductController.php index a5e7bcbd..61e480f0 100644 --- a/app/Http/Controllers/ProductController.php +++ b/app/Http/Controllers/ProductController.php @@ -2,6 +2,7 @@ namespace App\Http\Controllers; +use App\Classes\Pterodactyl; use App\Models\Egg; use App\Models\Location; use App\Models\Node; @@ -55,6 +56,10 @@ class ProductController extends Controller public function getLocationsBasedOnEgg(Request $request, Egg $egg) { $nodes = $this->getNodesBasedOnEgg($request, $egg); + foreach($nodes as $key => $node){ + $pteroNode = Pterodactyl::getNode($node->id); + if($pteroNode['allocated_resources']['memory']>=($pteroNode['memory']*($pteroNode['memory_overallocate']+100)/100)||$pteroNode['allocated_resources']['disk']>=($pteroNode['disk']*($pteroNode['disk_overallocate']+100)/100)) $nodes->forget($key); + } $locations = collect(); //locations @@ -87,7 +92,7 @@ class ProductController extends Controller { if (is_null($egg->id) || is_null($node->id)) return response()->json('node and egg id is required', '400'); - return Product::query() + $products = Product::query() ->where('disabled', '=', false) ->whereHas('nodes', function (Builder $builder) use ($node) { $builder->where('id', '=', $node->id); @@ -96,5 +101,12 @@ class ProductController extends Controller $builder->where('id', '=', $egg->id); }) ->get(); + + $pteroNode = Pterodactyl::getNode($node->id); + foreach($products as $key => $product){ + if($product->memory>($pteroNode['memory']*($pteroNode['memory_overallocate']+100)/100)-$pteroNode['allocated_resources']['memory']||$product->disk>($pteroNode['disk']*($pteroNode['disk_overallocate']+100)/100)-$pteroNode['allocated_resources']['disk']) $product->doesNotFit = true; + } + + return $products; } } diff --git a/resources/views/servers/create.blade.php b/resources/views/servers/create.blade.php index 5454a6b6..4ac74f79 100644 --- a/resources/views/servers/create.blade.php +++ b/resources/views/servers/create.blade.php @@ -218,10 +218,10 @@ From df0d37bb81668ae86096e08af7920fef587f98e1 Mon Sep 17 00:00:00 2001 From: ok236449 Date: Wed, 24 Aug 2022 17:52:51 +0200 Subject: [PATCH 3/4] Check for resources when upgrading server --- app/Http/Controllers/ServerController.php | 13 ++++++++++++- resources/views/servers/settings.blade.php | 4 ++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/ServerController.php b/app/Http/Controllers/ServerController.php index 20deffca..5324cbd1 100644 --- a/app/Http/Controllers/ServerController.php +++ b/app/Http/Controllers/ServerController.php @@ -241,6 +241,9 @@ class ServerController extends Controller $serverRelationships = $serverAttributes['relationships']; $serverLocationAttributes = $serverRelationships['location']['attributes']; + //Get current product + $currentProduct = Product::where('id', $server->product_id)->first(); + //Set server infos $server->location = $serverLocationAttributes['long'] ? $serverLocationAttributes['long'] : @@ -249,11 +252,19 @@ class ServerController extends Controller $server->node = $serverRelationships['node']['attributes']['name']; $server->name = $serverAttributes['name']; $server->egg = $serverRelationships['egg']['attributes']['name']; - $products = Product::orderBy("created_at")->get(); + + $pteroNode = Pterodactyl::getNode($serverRelationships['node']['attributes']['id']); + + $products = Product::orderBy("created_at") + ->whereHas('nodes', function (Builder $builder) use ($serverRelationships) { //Only show products for that node + $builder->where('id', '=', $serverRelationships['node']['attributes']['id']); + }) + ->get(); // Set the each product eggs array to just contain the eggs name foreach ($products as $product) { $product->eggs = $product->eggs->pluck('name')->toArray(); + if($product->memory-$currentProduct->memory>($pteroNode['memory']*($pteroNode['memory_overallocate']+100)/100)-$pteroNode['allocated_resources']['memory']||$product->disk-$currentProduct->disk>($pteroNode['disk']*($pteroNode['disk_overallocate']+100)/100)-$pteroNode['allocated_resources']['disk']) $product->doesNotFit = true; } return view('servers.settings')->with([ diff --git a/resources/views/servers/settings.blade.php b/resources/views/servers/settings.blade.php index e320533c..5c8513aa 100644 --- a/resources/views/servers/settings.blade.php +++ b/resources/views/servers/settings.blade.php @@ -255,8 +255,8 @@ @foreach($products as $product) @if(in_array($server->egg, $product->eggs) && $product->id != $server->product->id && $product->disabled == false) - + @endif @endforeach From 2b3b8ddec9f6bef4bc1d61638f2200999162b3ec Mon Sep 17 00:00:00 2001 From: ok236449 Date: Wed, 24 Aug 2022 18:22:24 +0200 Subject: [PATCH 4/4] fix single underscore in translation --- resources/views/servers/settings.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/views/servers/settings.blade.php b/resources/views/servers/settings.blade.php index 5c8513aa..1a1b269b 100644 --- a/resources/views/servers/settings.blade.php +++ b/resources/views/servers/settings.blade.php @@ -261,7 +261,7 @@ @endforeach
{{__("Once the Upgrade button is pressed, we will automatically deduct the amount for the first hour according to the new product from your credits")}}.
-
{{_("Server will be automatically restarted once upgraded")}} +
{{__("Server will be automatically restarted once upgraded")}}