Skip to content

Commit

Permalink
Merge pull request #285 from ControlPanel-gg/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
AVMG20 authored Nov 12, 2021
2 parents 93fdab5 + 47c251e commit 0c51471
Show file tree
Hide file tree
Showing 53 changed files with 15,978 additions and 616 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
/storage/*.key
/vendor
/storage/credit_deduction_log
storage/debugbar
.env
.env.testing
.env.backup
Expand Down
92 changes: 45 additions & 47 deletions app/Classes/Pterodactyl.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@
use Illuminate\Http\Client\PendingRequest;
use Illuminate\Http\Client\Response;
use Illuminate\Support\Facades\Http;
use Illuminate\Validation\Validator;

class Pterodactyl
{
//TODO: Extend error handling (maybe logger for more errors when debugging)

/**
* @return PendingRequest
*/
Expand All @@ -27,77 +28,48 @@ public static function client()
])->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 mixed
*/
public function getUser(int $pterodactylId)
{
$response = self::client()->get("/application/users/{$pterodactylId}");

if ($response->failed()) return $response->json();
return $response->json()['attributes'];
}

/**
* @param Node $node
* @return array|mixed|null
* @throws Exception
* @return Exception
*/
public static function getFreeAllocations(Node $node)
private static function getException(): Exception
{
$response = self::getAllocations($node);
$freeAllocations = [];

if (isset($response['data'])) {
if (!empty($response['data'])) {
foreach ($response['data'] as $allocation) {
if (!$allocation['attributes']['assigned']) array_push($freeAllocations, $allocation);
}
}
}

return $freeAllocations;
return new Exception('Request Failed, is pterodactyl set-up correctly?');
}

/**
* @return null
* @param Nest $nest
* @return mixed
* @throws Exception
*/
public static function getNests()
public static function getEggs(Nest $nest)
{
$response = self::client()->get('/application/nests');
$response = self::client()->get("/application/nests/{$nest->id}/eggs?include=nest,variables");
if ($response->failed()) throw self::getException();
return $response->json()['data'];
}

/**
* @param Nest $nest
* @return mixed
* @throws Exception
*/
public static function getEggs(Nest $nest)
public static function getNodes()
{
$response = self::client()->get("/application/nests/{$nest->id}/eggs?include=nest,variables");
$response = self::client()->get('/application/nodes');
if ($response->failed()) throw self::getException();
return $response->json()['data'];
}


/**
* @return mixed
* @return null
* @throws Exception
*/
public static function getNodes()
public static function getNests()
{
$response = self::client()->get('/application/nodes');
$response = self::client()->get('/application/nests');
if ($response->failed()) throw self::getException();
return $response->json()['data'];
}


/**
* @return mixed
* @throws Exception
Expand All @@ -112,16 +84,37 @@ public static function getLocations()
/**
* @param Node $node
* @return mixed
* @throws Exception
*/
public static function getFreeAllocationId(Node $node)
{

return self::getFreeAllocations($node)[0]['attributes']['id'] ?? null;
}

/**
* @param Node $node
* @return array|mixed|null
* @throws Exception
*/
public static function getFreeAllocations(Node $node)
{
$response = self::getAllocations($node);
$freeAllocations = [];

if (isset($response['data'])) {
if (!empty($response['data'])) {
foreach ($response['data'] as $allocation) {
if (!$allocation['attributes']['assigned']) array_push($freeAllocations, $allocation);
}
}
}

return $freeAllocations;
}

/**
* @param Node $node
* @return array|mixed
* @throws Exception
*/
public static function getAllocations(Node $node)
Expand All @@ -132,7 +125,6 @@ public static function getAllocations(Node $node)
return $response->json();
}


/**
* @param String $route
* @return string
Expand Down Expand Up @@ -174,6 +166,7 @@ public static function createServer(Server $server, Egg $egg, int $allocationId)
"default" => $allocationId
]
]);

}

public static function suspendServer(Server $server)
Expand All @@ -191,10 +184,15 @@ public static function unSuspendServer(Server $server)
}

/**
* @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'];
}
}
5 changes: 5 additions & 0 deletions app/Http/Controllers/Admin/NestsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
use Illuminate\Http\Request;
use Illuminate\Http\Response;

/**
* @deprecated
* Class NestsController
* @package App\Http\Controllers\Admin
*/
class NestsController extends Controller
{
/**
Expand Down
5 changes: 5 additions & 0 deletions app/Http/Controllers/Admin/NodeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
use Illuminate\Http\Request;
use Illuminate\Http\Response;

/**
* @deprecated
* Class NodeController
* @package App\Http\Controllers\Admin
*/
class NodeController extends Controller
{
/**
Expand Down
64 changes: 64 additions & 0 deletions app/Http/Controllers/Admin/OverViewController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Models\Egg;
use App\Models\Location;
use App\Models\Nest;
use App\Models\Node;
use App\Models\Payment;
use App\Models\Server;
use App\Models\User;
use Illuminate\Support\Facades\Cache;

class OverViewController extends Controller
{
public const TTL = 86400;

public function index()
{
$userCount = Cache::remember('user:count', self::TTL, function () {
return User::query()->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();
});

$lastEgg = Egg::query()->latest('updated_at')->first();
$syncLastUpdate = $lastEgg ? $lastEgg->updated_at->isoFormat('LLL') : __('unknown');

return view('admin.overview.index', [
'serverCount' => $serverCount,
'userCount' => $userCount,
'paymentCount' => $paymentCount,
'creditCount' => number_format($creditCount, 2, '.', ''),

'locationCount' => Location::query()->count(),
'nodeCount' => Node::query()->count(),
'nestCount' => Nest::query()->count(),
'eggCount' => Egg::query()->count(),
'syncLastUpdate' => $syncLastUpdate
]);
}

/**
* @description Sync locations,nodes,nests,eggs with the linked pterodactyl panel
*/
public function syncPterodactyl()
{
Node::syncNodes();
Egg::syncEggs();

return redirect()->back()->with('success', __('Pterodactyl synced'));
}
}
37 changes: 32 additions & 5 deletions app/Http/Controllers/Admin/PaymentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

class PaymentController extends Controller
{

/**
* @return Application|Factory|View
*/
Expand All @@ -45,7 +46,10 @@ public function index()
public function checkOut(Request $request, PaypalProduct $paypalProduct)
{
return view('store.checkout')->with([
'product' => $paypalProduct
'product' => $paypalProduct,
'taxvalue' => $paypalProduct->getTaxValue(),
'taxpercent' => $paypalProduct->getTaxPercent(),
'total' => $paypalProduct->getTotalPrice()
]);
}

Expand All @@ -65,8 +69,20 @@ public function pay(Request $request, PaypalProduct $paypalProduct)
"reference_id" => uniqid(),
"description" => $paypalProduct->description,
"amount" => [
"value" => $paypalProduct->price,
"currency_code" => strtoupper($paypalProduct->currency_code)
"value" => $paypalProduct->getTotalPrice(),
'currency_code' => strtoupper($paypalProduct->currency_code),
'breakdown' =>[
'item_total' =>
[
'currency_code' => strtoupper($paypalProduct->currency_code),
'value' => $paypalProduct->price,
],
'tax_total' =>
[
'currency_code' => strtoupper($paypalProduct->currency_code),
'value' => $paypalProduct->getTaxValue(),
]
]
]
]
],
Expand All @@ -76,6 +92,8 @@ public function pay(Request $request, PaypalProduct $paypalProduct)
'brand_name' => config('app.name', 'Laravel'),
'shipping_preference' => 'NO_SHIPPING'
]


];


Expand Down Expand Up @@ -161,6 +179,9 @@ public function success(Request $laravelRequest)
'status' => $response->result->status,
'amount' => $paypalProduct->quantity,
'price' => $paypalProduct->price,
'tax_value' => $paypalProduct->getTaxValue(),
'tax_percent' => $paypalProduct->getTaxPercent(),
'total_price' => $paypalProduct->getTotalPrice(),
'currency_code' => $paypalProduct->currency_code,
'payer' => json_encode($response->result->payer),
]);
Expand Down Expand Up @@ -199,7 +220,7 @@ public function success(Request $laravelRequest)
*/
public function cancel(Request $request)
{
return redirect()->route('store.index')->with('success', 'Payment was Cannceled');
return redirect()->route('store.index')->with('success', 'Payment was Canceled');
}


Expand All @@ -216,7 +237,13 @@ public function dataTable()
return $payment->user->name;
})
->editColumn('price', function (Payment $payment) {
return $payment->formatCurrency();
return $payment->formatToCurrency($payment->price);
})
->editColumn('tax_value', function (Payment $payment) {
return $payment->formatToCurrency($payment->tax_value);
})
->editColumn('total_price', function (Payment $payment) {
return $payment->formatToCurrency($payment->total_price);
})
->editColumn('created_at', function (Payment $payment) {
return $payment->created_at ? $payment->created_at->diffForHumans() : '';
Expand Down
Loading

0 comments on commit 0c51471

Please sign in to comment.