|
@@ -30,7 +30,7 @@ class ServerController extends Controller
|
|
foreach ($servers as $server) {
|
|
foreach ($servers as $server) {
|
|
|
|
|
|
//Get server infos from ptero
|
|
//Get server infos from ptero
|
|
- $serverAttributes = $this->client->getServerAttributes($server->pterodactyl_id, true);
|
|
|
|
|
|
+ $serverAttributes = $this->pterodactyl->getServerAttributes($server->pterodactyl_id, true);
|
|
if (! $serverAttributes) {
|
|
if (! $serverAttributes) {
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
@@ -123,18 +123,15 @@ class ServerController extends Controller
|
|
$nodeName = $node->name;
|
|
$nodeName = $node->name;
|
|
|
|
|
|
// Check if node has enough memory and disk space
|
|
// Check if node has enough memory and disk space
|
|
- $checkResponse = $this->client->checkNodeResources($node, $product->memory, $product->disk);
|
|
|
|
|
|
+ $checkResponse = $this->pterodactyl->checkNodeResources($node, $product->memory, $product->disk);
|
|
if ($checkResponse == false) {
|
|
if ($checkResponse == false) {
|
|
return redirect()->route('servers.index')->with('error', __("The node '".$nodeName."' doesn't have the required memory or disk left to allocate this product."));
|
|
return redirect()->route('servers.index')->with('error', __("The node '".$nodeName."' doesn't have the required memory or disk left to allocate this product."));
|
|
}
|
|
}
|
|
|
|
|
|
// Min. Credits
|
|
// Min. Credits
|
|
- if (
|
|
|
|
- Auth::user()->credits <
|
|
|
|
- ($product->minimum_credits == -1
|
|
|
|
- ? config('SETTINGS::USER:MINIMUM_REQUIRED_CREDITS_TO_MAKE_SERVER', 50)
|
|
|
|
- : $product->minimum_credits)
|
|
|
|
- ) {
|
|
|
|
|
|
+ if (Auth::user()->credits < ($product->minimum_credits == -1
|
|
|
|
+ ? $user_settings->min_credits_to_make_server
|
|
|
|
+ : $product->minimum_credits)) {
|
|
return redirect()->route('servers.index')->with('error', 'You do not have the required amount of '.CREDITS_DISPLAY_NAME.' to use this product!');
|
|
return redirect()->route('servers.index')->with('error', 'You do not have the required amount of '.CREDITS_DISPLAY_NAME.' to use this product!');
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -158,13 +155,15 @@ class ServerController extends Controller
|
|
}
|
|
}
|
|
|
|
|
|
/** Store a newly created resource in storage. */
|
|
/** Store a newly created resource in storage. */
|
|
- public function store(Request $request)
|
|
|
|
|
|
+ public function store(Request $request, UserSettings $user_settings, ServerSettings $server_settings)
|
|
{
|
|
{
|
|
/** @var Node $node */
|
|
/** @var Node $node */
|
|
/** @var Egg $egg */
|
|
/** @var Egg $egg */
|
|
/** @var Product $product */
|
|
/** @var Product $product */
|
|
- if (! is_null($this->validateConfigurationRules())) {
|
|
|
|
- return $this->validateConfigurationRules();
|
|
|
|
|
|
+ $validate_configuration = $this->validateConfigurationRules($user_settings, $server_settings);
|
|
|
|
+
|
|
|
|
+ if (!is_null($validate_configuration)) {
|
|
|
|
+ return $validate_configuration;
|
|
}
|
|
}
|
|
|
|
|
|
$request->validate([
|
|
$request->validate([
|
|
@@ -185,13 +184,13 @@ class ServerController extends Controller
|
|
]);
|
|
]);
|
|
|
|
|
|
//get free allocation ID
|
|
//get free allocation ID
|
|
- $allocationId = $this->client->getFreeAllocationId($node);
|
|
|
|
|
|
+ $allocationId = $this->pterodactyl->getFreeAllocationId($node);
|
|
if (! $allocationId) {
|
|
if (! $allocationId) {
|
|
return $this->noAllocationsError($server);
|
|
return $this->noAllocationsError($server);
|
|
}
|
|
}
|
|
|
|
|
|
//create server on pterodactyl
|
|
//create server on pterodactyl
|
|
- $response = $this->client->createServer($server, $egg, $allocationId);
|
|
|
|
|
|
+ $response = $this->pterodactyl->createServer($server, $egg, $allocationId);
|
|
if ($response->failed()) {
|
|
if ($response->failed()) {
|
|
return $this->serverCreationFailed($response, $server);
|
|
return $this->serverCreationFailed($response, $server);
|
|
}
|
|
}
|
|
@@ -203,7 +202,7 @@ class ServerController extends Controller
|
|
'identifier' => $serverAttributes['identifier'],
|
|
'identifier' => $serverAttributes['identifier'],
|
|
]);
|
|
]);
|
|
|
|
|
|
- if (config('SETTINGS::SYSTEM:SERVER_CREATE_CHARGE_FIRST_HOUR', 'true') == 'true') {
|
|
|
|
|
|
+ if ($server_settings->charge_first_hour) {
|
|
if ($request->user()->credits >= $server->product->getHourlyPrice()) {
|
|
if ($request->user()->credits >= $server->product->getHourlyPrice()) {
|
|
$request->user()->decrement('credits', $server->product->getHourlyPrice());
|
|
$request->user()->decrement('credits', $server->product->getHourlyPrice());
|
|
}
|
|
}
|
|
@@ -257,9 +256,9 @@ class ServerController extends Controller
|
|
public function show(Server $server)
|
|
public function show(Server $server)
|
|
{
|
|
{
|
|
if ($server->user_id != Auth::user()->id) {
|
|
if ($server->user_id != Auth::user()->id) {
|
|
- return back()->with('error', __('´This is not your Server!'));
|
|
|
|
|
|
+ return back()->with('error', __('This is not your Server!'));
|
|
}
|
|
}
|
|
- $serverAttributes = $this->client->getServerAttributes($server->pterodactyl_id);
|
|
|
|
|
|
+ $serverAttributes = $this->pterodactyl->getServerAttributes($server->pterodactyl_id);
|
|
$serverRelationships = $serverAttributes['relationships'];
|
|
$serverRelationships = $serverAttributes['relationships'];
|
|
$serverLocationAttributes = $serverRelationships['location']['attributes'];
|
|
$serverLocationAttributes = $serverRelationships['location']['attributes'];
|
|
|
|
|
|
@@ -275,7 +274,7 @@ class ServerController extends Controller
|
|
$server->name = $serverAttributes['name'];
|
|
$server->name = $serverAttributes['name'];
|
|
$server->egg = $serverRelationships['egg']['attributes']['name'];
|
|
$server->egg = $serverRelationships['egg']['attributes']['name'];
|
|
|
|
|
|
- $pteroNode = $this->client->getNode($serverRelationships['node']['attributes']['id']);
|
|
|
|
|
|
+ $pteroNode = $this->pterodactyl->getNode($serverRelationships['node']['attributes']['id']);
|
|
|
|
|
|
$products = Product::orderBy('created_at')
|
|
$products = Product::orderBy('created_at')
|
|
->whereHas('nodes', function (Builder $builder) use ($serverRelationships) { //Only show products for that node
|
|
->whereHas('nodes', function (Builder $builder) use ($serverRelationships) { //Only show products for that node
|
|
@@ -308,7 +307,7 @@ class ServerController extends Controller
|
|
$user = Auth::user();
|
|
$user = Auth::user();
|
|
$oldProduct = Product::where('id', $server->product->id)->first();
|
|
$oldProduct = Product::where('id', $server->product->id)->first();
|
|
$newProduct = Product::where('id', $request->product_upgrade)->first();
|
|
$newProduct = Product::where('id', $request->product_upgrade)->first();
|
|
- $serverAttributes = $this->client->getServerAttributes($server->pterodactyl_id);
|
|
|
|
|
|
+ $serverAttributes = $this->pterodactyl->getServerAttributes($server->pterodactyl_id);
|
|
$serverRelationships = $serverAttributes['relationships'];
|
|
$serverRelationships = $serverAttributes['relationships'];
|
|
|
|
|
|
// Get node resource allocation info
|
|
// Get node resource allocation info
|
|
@@ -319,7 +318,7 @@ class ServerController extends Controller
|
|
// Check if node has enough memory and disk space
|
|
// Check if node has enough memory and disk space
|
|
$requireMemory = $newProduct->memory - $oldProduct->memory;
|
|
$requireMemory = $newProduct->memory - $oldProduct->memory;
|
|
$requiredisk = $newProduct->disk - $oldProduct->disk;
|
|
$requiredisk = $newProduct->disk - $oldProduct->disk;
|
|
- $checkResponse = $this->client->checkNodeResources($node, $requireMemory, $requiredisk);
|
|
|
|
|
|
+ $checkResponse = $this->pterodactyl->checkNodeResources($node, $requireMemory, $requiredisk);
|
|
if ($checkResponse == false) {
|
|
if ($checkResponse == false) {
|
|
return redirect()->route('servers.index')->with('error', __("The node '".$nodeName."' doesn't have the required memory or disk left to upgrade the server."));
|
|
return redirect()->route('servers.index')->with('error', __("The node '".$nodeName."' doesn't have the required memory or disk left to upgrade the server."));
|
|
}
|
|
}
|
|
@@ -333,14 +332,14 @@ class ServerController extends Controller
|
|
$server->product_id = $request->product_upgrade;
|
|
$server->product_id = $request->product_upgrade;
|
|
$server->update();
|
|
$server->update();
|
|
$server->allocation = $serverAttributes['allocation'];
|
|
$server->allocation = $serverAttributes['allocation'];
|
|
- $response = $this->client->updateServer($server, $newProduct);
|
|
|
|
|
|
+ $response = $this->pterodactyl->updateServer($server, $newProduct);
|
|
if ($response->failed()) {
|
|
if ($response->failed()) {
|
|
return $this->serverCreationFailed($response, $server);
|
|
return $this->serverCreationFailed($response, $server);
|
|
}
|
|
}
|
|
//update user balance
|
|
//update user balance
|
|
$user->decrement('credits', $priceupgrade);
|
|
$user->decrement('credits', $priceupgrade);
|
|
//restart the server
|
|
//restart the server
|
|
- $response = $this->client->powerAction($server, 'restart');
|
|
|
|
|
|
+ $response = $this->pterodactyl->powerAction($server, 'restart');
|
|
if ($response->failed()) {
|
|
if ($response->failed()) {
|
|
return redirect()->route('servers.index')->with('error', $response->json()['errors'][0]['detail']);
|
|
return redirect()->route('servers.index')->with('error', $response->json()['errors'][0]['detail']);
|
|
}
|
|
}
|