diff --git a/app/Classes/Pterodactyl.php b/app/Classes/Pterodactyl.php
index c1726bf8..dd86f914 100644
--- a/app/Classes/Pterodactyl.php
+++ b/app/Classes/Pterodactyl.php
@@ -11,10 +11,22 @@ use Exception;
use Illuminate\Http\Client\PendingRequest;
use Illuminate\Http\Client\Response;
use Illuminate\Support\Facades\Http;
-use Illuminate\Validation\Validator;
class Pterodactyl
{
+ /**
+ * @return null
+ * @throws Exception
+ */
+ public static function getNests()
+ {
+ $response = self::client()->get('/application/nests');
+ if ($response->failed()) throw self::getException();
+ return $response->json()['data'];
+ }
+
+ //TODO: Extend error handling (maybe logger for more errors when debugging)
+
/**
* @return PendingRequest
*/
@@ -27,18 +39,57 @@ class Pterodactyl
])->baseUrl(env('PTERODACTYL_URL') . '/api');
}
- //TODO: Extend error handling (maybe logger for more errors when debugging)
/**
- * Get user by pterodactyl id
- * @param int $pterodactylId
+ * @return Exception
+ */
+ private static function getException(): Exception
+ {
+ return new Exception('Request Failed, is pterodactyl set-up correctly?');
+ }
+
+ /**
+ * @param Nest $nest
+ * @return mixed
+ * @throws Exception
+ */
+ public static function getEggs(Nest $nest)
+ {
+ $response = self::client()->get("/application/nests/{$nest->id}/eggs?include=nest,variables");
+ if ($response->failed()) throw self::getException();
+ return $response->json()['data'];
+ }
+
+ /**
+ * @return mixed
+ * @throws Exception
+ */
+ public static function getNodes()
+ {
+ $response = self::client()->get('/application/nodes');
+ if ($response->failed()) throw self::getException();
+ dd($response->json());
+ return $response->json()['data'];
+ }
+
+ /**
+ * @return mixed
+ * @throws Exception
+ */
+ public static function getLocations()
+ {
+ $response = self::client()->get('/application/locations');
+ if ($response->failed()) throw self::getException();
+ return $response->json()['data'];
+ }
+
+ /**
+ * @param Node $node
* @return mixed
*/
- public function getUser(int $pterodactylId)
+ public static function getFreeAllocationId(Node $node)
{
- $response = self::client()->get("/application/users/{$pterodactylId}");
- if ($response->failed()) return $response->json();
- return $response->json()['attributes'];
+ return self::getFreeAllocations($node)[0]['attributes']['id'] ?? null;
}
/**
@@ -62,64 +113,6 @@ class Pterodactyl
return $freeAllocations;
}
- /**
- * @return null
- * @throws Exception
- */
- public static function getNests()
- {
- $response = self::client()->get('/application/nests');
- if ($response->failed()) throw self::getException();
- return $response->json()['data'];
- }
-
- /**
- * @param Nest $nest
- * @return mixed
- * @throws Exception
- */
- public static function getEggs(Nest $nest)
- {
- $response = self::client()->get("/application/nests/{$nest->id}/eggs?include=nest,variables");
- if ($response->failed()) throw self::getException();
- return $response->json()['data'];
- }
-
-
- /**
- * @return mixed
- * @throws Exception
- */
- public static function getNodes()
- {
- $response = self::client()->get('/application/nodes');
- if ($response->failed()) throw self::getException();
- return $response->json()['data'];
- }
-
-
- /**
- * @return mixed
- * @throws Exception
- */
- public static function getLocations()
- {
- $response = self::client()->get('/application/locations');
- if ($response->failed()) throw self::getException();
- return $response->json()['data'];
- }
-
- /**
- * @param Node $node
- * @return mixed
- */
- public static function getFreeAllocationId(Node $node)
- {
-
- return self::getFreeAllocations($node)[0]['attributes']['id'] ?? null;
- }
-
-
/**
* @param Node $node
* @throws Exception
@@ -132,7 +125,6 @@ class Pterodactyl
return $response->json();
}
-
/**
* @param String $route
* @return string
@@ -151,21 +143,21 @@ class Pterodactyl
public static function createServer(Server $server, Egg $egg, int $allocationId)
{
return self::client()->post("/application/servers", [
- "name" => $server->name,
- "external_id" => $server->id,
- "user" => $server->user->pterodactyl_id,
- "egg" => $egg->id,
- "docker_image" => $egg->docker_image,
- "startup" => $egg->startup,
- "environment" => $egg->getEnvironmentVariables(),
- "limits" => [
+ "name" => $server->name,
+ "external_id" => $server->id,
+ "user" => $server->user->pterodactyl_id,
+ "egg" => $egg->id,
+ "docker_image" => $egg->docker_image,
+ "startup" => $egg->startup,
+ "environment" => $egg->getEnvironmentVariables(),
+ "limits" => [
"memory" => $server->product->memory,
"swap" => $server->product->swap,
"disk" => $server->product->disk,
"io" => $server->product->io,
"cpu" => $server->product->cpu
],
- "feature_limits" => [
+ "feature_limits" => [
"databases" => $server->product->databases,
"backups" => $server->product->backups,
"allocations" => $server->product->allocations,
@@ -174,6 +166,7 @@ class Pterodactyl
"default" => $allocationId
]
]);
+
}
public static function suspendServer(Server $server)
@@ -191,10 +184,15 @@ class Pterodactyl
}
/**
- * @return Exception
+ * Get user by pterodactyl id
+ * @param int $pterodactylId
+ * @return mixed
*/
- private static function getException(): Exception
+ public function getUser(int $pterodactylId)
{
- return new Exception('Request Failed, is pterodactyl set-up correctly?');
+ $response = self::client()->get("/application/users/{$pterodactylId}");
+
+ if ($response->failed()) return $response->json();
+ return $response->json()['attributes'];
}
}
diff --git a/app/Http/Controllers/Admin/NestsController.php b/app/Http/Controllers/Admin/NestsController.php
index afaf508b..4ed765ea 100644
--- a/app/Http/Controllers/Admin/NestsController.php
+++ b/app/Http/Controllers/Admin/NestsController.php
@@ -14,6 +14,11 @@ use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
+/**
+ * @deprecated
+ * Class NestsController
+ * @package App\Http\Controllers\Admin
+ */
class NestsController extends Controller
{
/**
diff --git a/app/Http/Controllers/Admin/NodeController.php b/app/Http/Controllers/Admin/NodeController.php
index 1fbba109..932338f8 100644
--- a/app/Http/Controllers/Admin/NodeController.php
+++ b/app/Http/Controllers/Admin/NodeController.php
@@ -14,6 +14,11 @@ use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
+/**
+ * @deprecated
+ * Class NodeController
+ * @package App\Http\Controllers\Admin
+ */
class NodeController extends Controller
{
/**
diff --git a/app/Http/Controllers/Admin/OverViewController.php b/app/Http/Controllers/Admin/OverViewController.php
new file mode 100644
index 00000000..34a774bc
--- /dev/null
+++ b/app/Http/Controllers/Admin/OverViewController.php
@@ -0,0 +1,40 @@
+count();
+ });
+
+ $creditCount = Cache::remember('credit:count', self::TTL, function () {
+ return User::query()->sum('credits');
+ });
+
+ $paymentCount = Cache::remember('payment:count', self::TTL, function () {
+ return Payment::query()->count();
+ });
+
+ $serverCount = Cache::remember('server:count', self::TTL, function () {
+ return Server::query()->count();
+ });
+
+ return view('admin.overview.index', [
+ 'serverCount' => $serverCount,
+ 'userCount' => $userCount,
+ 'paymentCount' => $paymentCount,
+ 'creditCount' => number_format($creditCount, 2, '.', ''),
+ ]);
+ }
+}
diff --git a/app/Http/Controllers/ServerController.php b/app/Http/Controllers/ServerController.php
index 075502bf..209f982c 100644
--- a/app/Http/Controllers/ServerController.php
+++ b/app/Http/Controllers/ServerController.php
@@ -52,8 +52,8 @@ class ServerController extends Controller
}
// minimum credits
- if (FacadesRequest::has("product_id")) {
- $product = Product::findOrFail(FacadesRequest::input("product_id"));
+ if (FacadesRequest::has("product")) {
+ $product = Product::findOrFail(FacadesRequest::input("product"));
if (
Auth::user()->credits <
($product->minimum_credits == -1
@@ -83,17 +83,20 @@ class ServerController extends Controller
if (!is_null($this->validateConfigurationRules())) return $this->validateConfigurationRules();
$request->validate([
- "name" => "required|max:191",
- "description" => "nullable|max:191",
- "node_id" => "required|exists:nodes,id",
- "egg_id" => "required|exists:eggs,id",
- "product_id" => "required|exists:products,id"
+ "name" => "required|max:191",
+ "node" => "required|exists:nodes,id",
+ "egg" => "required|exists:eggs,id",
+ "product" => "required|exists:products,id"
]);
//get required resources
- $egg = Egg::findOrFail($request->input('egg_id'));
- $node = Node::findOrFail($request->input('node_id'));
- $server = Auth::user()->servers()->create($request->all());
+ $egg = Egg::findOrFail($request->input('egg'));
+ $node = Node::findOrFail($request->input('node'));
+
+ $server = $request->user()->servers()->create([
+ 'name' => $request->input('name'),
+ 'product_id' => $request->input('product'),
+ ]);
//get free allocation ID
$allocationId = Pterodactyl::getFreeAllocationId($node);
@@ -110,8 +113,8 @@ class ServerController extends Controller
]);
if (Configuration::getValueByKey('SERVER_CREATE_CHARGE_FIRST_HOUR', 'true') == 'true') {
- if (Auth::user()->credits >= $server->product->getHourlyPrice()) {
- Auth::user()->decrement('credits', $server->product->getHourlyPrice());
+ if ($request->user()->credits >= $server->product->getHourlyPrice()) {
+ $request->user()->decrement('credits', $server->product->getHourlyPrice());
}
}
diff --git a/app/Models/Node.php b/app/Models/Node.php
index 3e626802..680ba44a 100644
--- a/app/Models/Node.php
+++ b/app/Models/Node.php
@@ -33,7 +33,6 @@ class Node extends Model
Location::syncLocations();
$nodes = Pterodactyl::getNodes();
-
$nodes = array_map(function($node) {
return array(
'id' => $node['attributes']['id'],
diff --git a/composer.json b/composer.json
index 50dc100a..8873c2be 100644
--- a/composer.json
+++ b/composer.json
@@ -28,6 +28,7 @@
"yajra/laravel-datatables-oracle": "~9.0"
},
"require-dev": {
+ "barryvdh/laravel-debugbar": "^3.6",
"facade/ignition": "^2.5",
"fakerphp/faker": "^1.9.1",
"laravel/sail": "^1.0.1",
diff --git a/composer.lock b/composer.lock
index 0ff1f168..a8ba8147 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
- "content-hash": "f7ba581ff6641d3ab79d558070e99f3c",
+ "content-hash": "500346cc4a4a83b162e07bb0071d1602",
"packages": [
{
"name": "asm89/stack-cors",
@@ -6202,6 +6202,91 @@
}
],
"packages-dev": [
+ {
+ "name": "barryvdh/laravel-debugbar",
+ "version": "v3.6.4",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/barryvdh/laravel-debugbar.git",
+ "reference": "3c2d678269ba60e178bcd93e36f6a91c36b727f1"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/barryvdh/laravel-debugbar/zipball/3c2d678269ba60e178bcd93e36f6a91c36b727f1",
+ "reference": "3c2d678269ba60e178bcd93e36f6a91c36b727f1",
+ "shasum": ""
+ },
+ "require": {
+ "illuminate/routing": "^6|^7|^8",
+ "illuminate/session": "^6|^7|^8",
+ "illuminate/support": "^6|^7|^8",
+ "maximebf/debugbar": "^1.17.2",
+ "php": ">=7.2",
+ "symfony/debug": "^4.3|^5",
+ "symfony/finder": "^4.3|^5"
+ },
+ "require-dev": {
+ "mockery/mockery": "^1.3.3",
+ "orchestra/testbench-dusk": "^4|^5|^6",
+ "phpunit/phpunit": "^8.5|^9.0",
+ "squizlabs/php_codesniffer": "^3.5"
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "3.6-dev"
+ },
+ "laravel": {
+ "providers": [
+ "Barryvdh\\Debugbar\\ServiceProvider"
+ ],
+ "aliases": {
+ "Debugbar": "Barryvdh\\Debugbar\\Facade"
+ }
+ }
+ },
+ "autoload": {
+ "psr-4": {
+ "Barryvdh\\Debugbar\\": "src/"
+ },
+ "files": [
+ "src/helpers.php"
+ ]
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Barry vd. Heuvel",
+ "email": "barryvdh@gmail.com"
+ }
+ ],
+ "description": "PHP Debugbar integration for Laravel",
+ "keywords": [
+ "debug",
+ "debugbar",
+ "laravel",
+ "profiler",
+ "webprofiler"
+ ],
+ "support": {
+ "issues": "https://github.com/barryvdh/laravel-debugbar/issues",
+ "source": "https://github.com/barryvdh/laravel-debugbar/tree/v3.6.4"
+ },
+ "funding": [
+ {
+ "url": "https://fruitcake.nl",
+ "type": "custom"
+ },
+ {
+ "url": "https://github.com/barryvdh",
+ "type": "github"
+ }
+ ],
+ "time": "2021-10-21T10:57:31+00:00"
+ },
{
"name": "doctrine/instantiator",
"version": "1.4.0",
@@ -6713,6 +6798,71 @@
},
"time": "2021-05-25T16:41:13+00:00"
},
+ {
+ "name": "maximebf/debugbar",
+ "version": "v1.17.3",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/maximebf/php-debugbar.git",
+ "reference": "e8ac3499af0ea5b440908e06cc0abe5898008b3c"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/maximebf/php-debugbar/zipball/e8ac3499af0ea5b440908e06cc0abe5898008b3c",
+ "reference": "e8ac3499af0ea5b440908e06cc0abe5898008b3c",
+ "shasum": ""
+ },
+ "require": {
+ "php": "^7.1|^8",
+ "psr/log": "^1|^2|^3",
+ "symfony/var-dumper": "^2.6|^3|^4|^5"
+ },
+ "require-dev": {
+ "phpunit/phpunit": "^7.5.20 || ^9.4.2"
+ },
+ "suggest": {
+ "kriswallsmith/assetic": "The best way to manage assets",
+ "monolog/monolog": "Log using Monolog",
+ "predis/predis": "Redis storage"
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "1.17-dev"
+ }
+ },
+ "autoload": {
+ "psr-4": {
+ "DebugBar\\": "src/DebugBar/"
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Maxime Bouroumeau-Fuseau",
+ "email": "maxime.bouroumeau@gmail.com",
+ "homepage": "http://maximebf.com"
+ },
+ {
+ "name": "Barry vd. Heuvel",
+ "email": "barryvdh@gmail.com"
+ }
+ ],
+ "description": "Debug bar in the browser for php application",
+ "homepage": "https://github.com/maximebf/php-debugbar",
+ "keywords": [
+ "debug",
+ "debugbar"
+ ],
+ "support": {
+ "issues": "https://github.com/maximebf/php-debugbar/issues",
+ "source": "https://github.com/maximebf/php-debugbar/tree/v1.17.3"
+ },
+ "time": "2021-10-19T12:33:27+00:00"
+ },
{
"name": "mockery/mockery",
"version": "1.4.3",
@@ -8652,6 +8802,74 @@
],
"time": "2020-09-28T06:39:44+00:00"
},
+ {
+ "name": "symfony/debug",
+ "version": "v4.4.31",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/symfony/debug.git",
+ "reference": "43ede438d4cb52cd589ae5dc070e9323866ba8e0"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/symfony/debug/zipball/43ede438d4cb52cd589ae5dc070e9323866ba8e0",
+ "reference": "43ede438d4cb52cd589ae5dc070e9323866ba8e0",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=7.1.3",
+ "psr/log": "^1|^2|^3"
+ },
+ "conflict": {
+ "symfony/http-kernel": "<3.4"
+ },
+ "require-dev": {
+ "symfony/http-kernel": "^3.4|^4.0|^5.0"
+ },
+ "type": "library",
+ "autoload": {
+ "psr-4": {
+ "Symfony\\Component\\Debug\\": ""
+ },
+ "exclude-from-classmap": [
+ "/Tests/"
+ ]
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Fabien Potencier",
+ "email": "fabien@symfony.com"
+ },
+ {
+ "name": "Symfony Community",
+ "homepage": "https://symfony.com/contributors"
+ }
+ ],
+ "description": "Provides tools to ease debugging PHP code",
+ "homepage": "https://symfony.com",
+ "support": {
+ "source": "https://github.com/symfony/debug/tree/v4.4.31"
+ },
+ "funding": [
+ {
+ "url": "https://symfony.com/sponsor",
+ "type": "custom"
+ },
+ {
+ "url": "https://github.com/fabpot",
+ "type": "github"
+ },
+ {
+ "url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
+ "type": "tidelift"
+ }
+ ],
+ "time": "2021-09-24T13:30:14+00:00"
+ },
{
"name": "theseer/tokenizer",
"version": "1.2.0",
@@ -8713,5 +8931,5 @@
"ext-intl": "*"
},
"platform-dev": [],
- "plugin-api-version": "2.1.0"
+ "plugin-api-version": "2.0.0"
}
diff --git a/resources/views/admin/overview/index.blade.php b/resources/views/admin/overview/index.blade.php
new file mode 100644
index 00000000..ef4a355b
--- /dev/null
+++ b/resources/views/admin/overview/index.blade.php
@@ -0,0 +1,147 @@
+@extends('layouts.main')
+
+@section('content')
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {{__('Servers')}}
+ {{$serverCount}}
+
+
+
+
+
+
+
+
+
+
+
+ {{__('Users')}}
+ {{$userCount}}
+
+
+
+
+
+
+
+
+
+
+
+ {{__('Total')}} {{CREDITS_DISPLAY_NAME}}
+ {{$creditCount}}
+
+
+
+
+
+
+
+
+
+
+
+ {{__('Payments')}}
+ {{$paymentCount}}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {{__('Resources')}} |
+ {{__('Count')}} |
+
+
+
+
+ {{__('Locations')}} |
+ 1 |
+
+
+ {{__('Nodes')}} |
+ 1 |
+
+
+ {{__('Nests')}} |
+ 1 |
+
+
+ {{__('Eggs')}} |
+ 1 |
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+@endsection
diff --git a/resources/views/admin/products/create.blade.php b/resources/views/admin/products/create.blade.php
index 5ad9b60b..b757033c 100644
--- a/resources/views/admin/products/create.blade.php
+++ b/resources/views/admin/products/create.blade.php
@@ -50,7 +50,8 @@