Apply fixes from StyleCI

This commit is contained in:
Dane Everitt 2016-12-07 22:46:38 +00:00 committed by StyleCI Bot
parent a1d3bbf73d
commit c1fb0a665f
150 changed files with 1558 additions and 1760 deletions

View file

@ -1,7 +1,7 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2016 Dane Everitt <dane@daneeveritt.com>
* Copyright (c) 2015 - 2016 Dane Everitt <dane@daneeveritt.com>.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@ -21,20 +21,19 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
namespace Pterodactyl\Repositories;
use DB;
use Validator;
use IPTools\Network;
use Pterodactyl\Models;
use Pterodactyl\Services\UuidService;
use IPTools\Network;
use Pterodactyl\Exceptions\DisplayException;
use Pterodactyl\Exceptions\DisplayValidationException;
class NodeRepository {
class NodeRepository
{
public function __construct()
{
//
@ -70,7 +69,7 @@ class NodeRepository {
}
// Verify FQDN is resolvable, or if not using SSL that the IP is valid.
if (!filter_var(gethostbyname($data['fqdn']), FILTER_VALIDATE_IP)) {
if (! filter_var(gethostbyname($data['fqdn']), FILTER_VALIDATE_IP)) {
throw new DisplayException('The FQDN (or IP Address) provided does not resolve to a valid IP address.');
}
@ -88,7 +87,6 @@ class NodeRepository {
$node->save();
return $node->id;
}
public function update($id, array $data)
@ -123,17 +121,16 @@ class NodeRepository {
if (isset($data['fqdn'])) {
// Verify the FQDN if using SSL
if ((isset($data['scheme']) && $data['scheme'] === 'https') || (!isset($data['scheme']) && $node->scheme === 'https')) {
if ((isset($data['scheme']) && $data['scheme'] === 'https') || (! isset($data['scheme']) && $node->scheme === 'https')) {
if (filter_var($data['fqdn'], FILTER_VALIDATE_IP)) {
throw new DisplayException('A fully qualified domain name is required to use secure comunication on this node.');
}
}
// Verify FQDN is resolvable, or if not using SSL that the IP is valid.
if (!filter_var(gethostbyname($data['fqdn']), FILTER_VALIDATE_IP)) {
if (! filter_var(gethostbyname($data['fqdn']), FILTER_VALIDATE_IP)) {
throw new DisplayException('The FQDN (or IP Address) provided does not resolve to a valid IP address.');
}
}
// Should we be nulling the overallocations?
@ -165,7 +162,7 @@ class NodeRepository {
'listen' => $node->daemonListen,
'ssl' => [
'enabled' => ($node->scheme === 'https'),
'certificate' => '/etc/letsencrypt/live/' . $node->fqdn .'/fullchain.pem',
'certificate' => '/etc/letsencrypt/live/' . $node->fqdn . '/fullchain.pem',
'key' => '/etc/letsencrypt/live/' . $node->fqdn . '/privkey.pem',
],
],
@ -183,13 +180,12 @@ class NodeRepository {
],
'keys' => [
$node->daemonSecret,
]
],
],
]);
} catch (\Exception $ex) {
throw new DisplayException('Failed to update the node configuration, however your changes have been saved to the database. You will need to manually update the configuration file for the node to apply these changes.');
}
}
public function addAllocations($id, array $allocations)
@ -199,7 +195,7 @@ class NodeRepository {
DB::beginTransaction();
try {
foreach($allocations as $rawIP => $ports) {
foreach ($allocations as $rawIP => $ports) {
try {
$setAlias = null;
$parsedIP = Network::parse($rawIP);
@ -211,25 +207,25 @@ class NodeRepository {
throw $ex;
}
}
foreach($parsedIP as $ip) {
foreach($ports as $port) {
if (!is_int($port) && !preg_match('/^(\d{1,5})-(\d{1,5})$/', $port)) {
foreach ($parsedIP as $ip) {
foreach ($ports as $port) {
if (! is_int($port) && ! preg_match('/^(\d{1,5})-(\d{1,5})$/', $port)) {
throw new DisplayException('The mapping for ' . $port . ' is invalid and cannot be processed.');
}
if (preg_match('/^(\d{1,5})-(\d{1,5})$/', $port, $matches)) {
foreach(range($matches[1], $matches[2]) as $assignPort) {
foreach (range($matches[1], $matches[2]) as $assignPort) {
$alloc = Models\Allocation::firstOrNew([
'node' => $node->id,
'ip' => $ip,
'port' => $assignPort
'port' => $assignPort,
]);
if (!$alloc->exists) {
if (! $alloc->exists) {
$alloc->fill([
'node' => $node->id,
'ip' => $ip,
'port' => $assignPort,
'ip_alias' => $setAlias,
'assigned_to' => null
'assigned_to' => null,
]);
$alloc->save();
}
@ -238,15 +234,15 @@ class NodeRepository {
$alloc = Models\Allocation::firstOrNew([
'node' => $node->id,
'ip' => $ip,
'port' => $port
'port' => $port,
]);
if (!$alloc->exists) {
if (! $alloc->exists) {
$alloc->fill([
'node' => $node->id,
'ip' => $ip,
'port' => $port,
'ip_alias' => $setAlias,
'assigned_to' => null
'assigned_to' => null,
]);
$alloc->save();
}
@ -290,5 +286,4 @@ class NodeRepository {
throw $ex;
}
}
}