Skip to content
This repository has been archived by the owner on Dec 11, 2022. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'origin/develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
TheFallenSpirit committed Jan 18, 2022
2 parents 9061099 + 2484797 commit e818780
Show file tree
Hide file tree
Showing 74 changed files with 2,011 additions and 2,997 deletions.
4 changes: 0 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ jobs:
git commit -m "bump version for release"
git push
- name: Copy settings.json
run: |
mv settings.json.example settings.json
- name: Build assets
run: |
yarn install
Expand Down
88 changes: 88 additions & 0 deletions app/Console/Commands/Node/MakeNodeCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?php

/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <[email protected]>.
*
* This software is licensed under the terms of the MIT license.
* https://opensource.org/licenses/MIT
*/

namespace Pterodactyl\Console\Commands\Node;

use Illuminate\Console\Command;
use Pterodactyl\Services\Nodes\NodeCreationService;

class MakeNodeCommand extends Command
{
/**
* @var \Pterodactyl\Services\Nodes\NodeCreationService
*/
protected $creationService;

/**
* @var string
*/
protected $signature = 'p:node:make
{--name= : A name to identify the node.}
{--description= : A description to identify the node.}
{--locationId= : A valid locationId.}
{--fqdn= : The domain name (e.g node.example.com) to be used for connecting to the daemon. An IP address may only be used if you are not using SSL for this node.}
{--public= : Should the node be public or private? (public=1 / private=0).}
{--scheme= : Which scheme should be used? (Enable SSL=https / Disable SSL=http).}
{--proxy= : Is the daemon behind a proxy? (Yes=1 / No=0).}
{--maintenance= : Should maintenance mode be enabled? (Enable Maintenance mode=1 / Disable Maintenance mode=0).}
{--maxMemory= : Set the max memory amount.}
{--overallocateMemory= : Enter the amount of ram to overallocate (% or -1 to overallocate the maximum).}
{--maxDisk= : Set the max disk amount.}
{--overallocateDisk= : Enter the amount of disk to overallocate (% or -1 to overallocate the maximum).}
{--uploadSize= : Enter the maximum upload filesize.}
{--daemonListeningPort= : Enter the wings listening port.}
{--daemonSFTPPort= : Enter the wings SFTP listening port.}
{--daemonBase= : Enter the base folder.}';

/**
* @var string
*/
protected $description = 'Creates a new node on the system via the CLI.';


/**
* Handle the command execution process.
*
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
*/
public function handle(NodeCreationService $creationService)
{
$this->creationService = $creationService;

$data['name'] = $this->option('name') ?? $this->ask('Enter a short identifier used to distinguish this node from others');
$data['description'] = $this->option('description') ?? $this->ask('Enter a description to identify the node');
$data['location_id'] = $this->option('locationId') ?? $this->ask('Enter a valid location id');
$data['fqdn'] = $this->option('fqdn') ?? $this->ask('Enter a domain name (e.g node.example.com) to be used for connecting to the daemon. An IP address may only be used if you are not using SSL for this node');
if (!filter_var(gethostbyname($data['fqdn']), FILTER_VALIDATE_IP)) {
$this->error('The FQDN or IP address provided does not resolve to a valid IP address.');
return;
}
$data['public'] = $this->option('public') ?? $this->confirm('Should this node be public? As a note, setting a node to private you will be denying the ability to auto-deploy to this node.', true);
$data['scheme'] = $this->option('scheme') ?? $this->anticipate('Please either enter https for SSL or http for a non-ssl connection',
["https","http",],"https");
if (filter_var($data['fqdn'], FILTER_VALIDATE_IP) && $data['scheme'] === 'https') {
$this->error('A fully qualified domain name that resolves to a public IP address is required in order to use SSL for this node.');
return;
}
$data['behind_proxy'] = $this->option('proxy') ?? $this->confirm('Is your FQDN behind a proxy?');
$data['maintenance_mode'] = $this->option('maintenance') ?? $this->confirm('Should maintenance mode be enabled?');
$data['memory'] = $this->option('maxMemory') ?? $this->ask('Enter the maximum amount of memory');
$data['memory_overallocate'] = $this->option('overallocateMemory') ?? $this->ask('Enter the amount of memory to over allocate by, -1 will disable checking and 0 will prevent creating new servers');
$data['disk'] = $this->option('maxDisk') ?? $this->ask('Enter the maximum amount of disk space');
$data['disk_overallocate'] = $this->option('overallocateDisk') ?? $this->ask('Enter the amount of memory to over allocate by, -1 will disable checking and 0 will prevent creating new server');
$data['upload_size'] = $this->option('uploadSize') ?? $this->ask('Enter the maximum filesize upload', '100');
$data['daemonListen'] = $this->option('daemonListeningPort') ?? $this->ask('Enter the wings listening port', '8080');
$data['daemonSFTP'] = $this->option('daemonSFTPPort') ?? $this->ask('Enter the wings SFTP listening port', '2022');
$data['daemonBase'] = $this->option('daemonBase') ?? $this->ask('Enter the base folder', '/var/lib/pterodactyl/volumes');

$node = $this->creationService->handle($data);
$this->line('Successfully created a new node on the location ' . $data['location_id'] . ' with the name ' . $data['name'] . ' and has an id of ' . $node->id . '.');
}
}
30 changes: 30 additions & 0 deletions app/Contracts/Repository/BillingRepositoryInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace Pterodactyl\Contracts\Repository;

use Pterodactyl\Exceptions\Model\DataValidationException;
use Pterodactyl\Exceptions\Repository\RecordNotFoundException;

interface BillingRepositoryInterface extends RepositoryInterface
{
/**
* Store a new persistent setting in the database.
*
* @throws DataValidationException
* @throws RecordNotFoundException
*/
public function set(string $key, string $value = null);

/**
* Retrieve a persistent setting from the database.
*
* @param mixed $default
* @return mixed
*/
public function get(string $key, $default);

/**
* Remove a key from the database cache.
*/
public function forget(string $key);
}
50 changes: 50 additions & 0 deletions app/Http/Controllers/Admin/BillingController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

namespace Pterodactyl\Http\Controllers\Admin;

use Illuminate\Http\RedirectResponse;
use Illuminate\View\View;
use Prologue\Alerts\AlertsMessageBag;
use Pterodactyl\Exceptions\Model\DataValidationException;
use Pterodactyl\Exceptions\Repository\RecordNotFoundException;
use Pterodactyl\Http\Controllers\Controller;
use Pterodactyl\Contracts\Repository\BillingRepositoryInterface;
use Pterodactyl\Http\Requests\Admin\BillingFormRequest;

class BillingController extends Controller
{
private BillingRepositoryInterface $billing;
private AlertsMessageBag $alert;

public function __construct(BillingRepositoryInterface $billing, AlertsMessageBag $alert)
{
$this->billing = $billing;
$this->alert = $alert;
}

/**
* @return View
*/
public function index(): View
{
return view('admin.billing', [
'enabled' => $this->billing->get('config:enabled', false)
]);
}

/**
* @throws DataValidationException
* @throws RecordNotFoundException
*/
public function update(BillingFormRequest $request): RedirectResponse
{
foreach ($request->normalize() as $key => $value) {
$this->billing->set('config:'.$key, $value);
}

$this->alert->success('Billing System has been updated.')->flash();

return redirect()->route('admin.billing');
}
}

81 changes: 0 additions & 81 deletions app/Http/Controllers/Admin/Settings/SecretController.php

This file was deleted.

59 changes: 20 additions & 39 deletions app/Http/Controllers/Api/Client/Credits/StoreController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,23 @@

namespace Pterodactyl\Http\Controllers\Api\Client\Credits;

use Throwable;
use Pterodactyl\Models\Node;
use Illuminate\Support\Facades\DB;
use Illuminate\Validation\ValidationException;
use Pterodactyl\Exceptions\DisplayException;
use Pterodactyl\Exceptions\Repository\RecordNotFoundException;
use Pterodactyl\Exceptions\Service\Deployment\NoViableAllocationException;
use Pterodactyl\Exceptions\Service\Deployment\NoViableNodeException;
use Pterodactyl\Http\Controllers\Api\Client\ClientApiController;
use Illuminate\Validation\ValidationException;
use Pterodactyl\Http\Requests\Api\Client\StoreRequest;
use Pterodactyl\Models\Node;
use Pterodactyl\Services\Servers\ServerCreationService;
use Throwable;
use Pterodactyl\Exceptions\Repository\RecordNotFoundException;
use Pterodactyl\Http\Controllers\Api\Client\ClientApiController;
use Pterodactyl\Exceptions\Service\Deployment\NoViableNodeException;
use Pterodactyl\Exceptions\Service\Deployment\NoViableAllocationException;

class StoreController extends ClientApiController
{
private Node $node;
private ServerCreationService $creationService;

/**
* StoreController constructor.
*/
Expand All @@ -40,7 +41,6 @@ public function getConfig(StoreRequest $request): array
'user' => $user,
],
];

}

/**
Expand All @@ -60,9 +60,6 @@ public function newServer(StoreRequest $request): array
'storage' => 'required',
]);

$allocation = $this->getAllocationId(1);
if ($allocation == -1) throw new DisplayException('No allocations could be found on the requested node.');

$egg = DB::table('eggs')->where('id', '=', 1)->first();
$nest = DB::table('nests')->where('id', '=', 1)->first();

Expand All @@ -71,7 +68,7 @@ public function newServer(StoreRequest $request): array
'owner_id' => $request->user()->id,
'egg_id' => $egg->id,
'nest_id' => $nest->id,
'allocation_id' => $allocation,
'allocation_id' => $this->getAllocationId(1),
'environment' => [],
'memory' => $request->input('ram') * 1024,
'disk' => $request->input('storage') * 1024,
Expand All @@ -83,40 +80,24 @@ public function newServer(StoreRequest $request): array
'start_on_completion' => true,
];

if ($request->user()->cr_slots < 1) {
throw new DisplayException('You don\'t have a server slot available to make this server.');
return [
'success' => false,
'data' => []
];
}
if ($request->user()->cr_cpu < $request->input('cpu')) {
throw new DisplayException('You don\'t have enough CPU available in your account.');
return [
'success' => false,
'data' => []
];
}
if ($request->user()->cr_ram < $request->input('ram')) {
throw new DisplayException('You don\'t have enough RAM available in your account.');
return [
'success' => false,
'data' => []
];
foreach (DB::table('egg_variables')->where('egg_id', '=', $egg->id)->get() as $var) {
$key = "v{$nest->id}-{$egg->id}-{$var->env_variable}";
$data['environment'][$var->env_variable] = $request->get($key, $var->default_value);
}
if ($request->user()->cr_storage < $request->input('storage')) {
throw new DisplayException('You don\'t have that much storage available om your account.');

if (
$request->user()->cr_slots < 1 |
$request->user()->cr_cpu < $request->input('cpu') |
$request->user()->cr_ram < $request->input('ram') |
$request->user()->cr_storage < $request->input('storage')
) {
throw new DisplayException('You don\'t have the resources available to make this server.');
return [
'success' => false,
'data' => []
];
}

foreach (DB::table('egg_variables')->where('egg_id', '=', $egg->id)->get() as $var) {
$key = "v{$nest->id}-{$egg->id}-{$var->env_variable}";
$data['environment'][$var->env_variable] = $request->get($key, $var->default_value);
}

$server = $this->creationService->handle($data);
$server->save();

Expand Down
Loading

0 comments on commit e818780

Please sign in to comment.