Merge branch 'develop' into feature/react-admin

This commit is contained in:
Matthew Penner 2021-03-05 08:45:39 -07:00
commit d57060dad9
9 changed files with 76 additions and 34 deletions

View file

@ -2,9 +2,11 @@
namespace Pterodactyl\Services\Allocations;
use Exception;
use IPTools\Network;
use Pterodactyl\Models\Node;
use Illuminate\Database\ConnectionInterface;
use Pterodactyl\Exceptions\DisplayException;
use Pterodactyl\Contracts\Repository\AllocationRepositoryInterface;
use Pterodactyl\Exceptions\Service\Allocation\CidrOutOfRangeException;
use Pterodactyl\Exceptions\Service\Allocation\PortOutOfRangeException;
@ -42,9 +44,10 @@ class AssignmentService
/**
* Insert allocations into the database and link them to a specific node.
*
* @throws \Pterodactyl\Exceptions\DisplayException
* @throws \Pterodactyl\Exceptions\Service\Allocation\CidrOutOfRangeException
* @throws \Pterodactyl\Exceptions\Service\Allocation\PortOutOfRangeException
* @throws \Pterodactyl\Exceptions\Service\Allocation\InvalidPortMappingException
* @throws \Pterodactyl\Exceptions\Service\Allocation\PortOutOfRangeException
* @throws \Pterodactyl\Exceptions\Service\Allocation\TooManyPortsInRangeException
*/
public function handle(Node $node, array $data)
@ -56,8 +59,16 @@ class AssignmentService
}
}
try {
$underlying = gethostbyname($data['allocation_ip']);
$parsed = Network::parse($underlying);
} catch (Exception $exception) {
/* @noinspection PhpUndefinedVariableInspection */
throw new DisplayException("Could not parse provided allocation IP address ({$underlying}): {$exception->getMessage()}", $exception);
}
$this->connection->beginTransaction();
foreach (Network::parse(gethostbyname($data['allocation_ip'])) as $ip) {
foreach ($parsed as $ip) {
foreach ($data['allocation_ports'] as $port) {
if (!is_digit($port) && !preg_match(self::PORT_RANGE_REGEX, $port)) {
throw new InvalidPortMappingException($port);

View file

@ -98,6 +98,16 @@ class EggConfigurationService
// Normalize the output of the configuration for the new Wings Daemon to more
// easily ingest, as well as make things more flexible down the road.
foreach ($configs as $file => $data) {
// Try to head off any errors relating to parsing a set of configuration files
// or other JSON data for the egg. This should probably be blocked at the time
// of egg creation/update, but it isn't so this check will at least prevent a
// 500 error which would crash the entire Wings boot process.
//
// @see https://github.com/pterodactyl/panel/issues/3055
if (!is_object($data) || !isset($data->find)) {
continue;
}
$append = array_merge((array) $data, ['file' => $file, 'replace' => []]);
foreach ($this->iterate($data->find, $structure) as $find => $replace) {