22
33namespace Pterodactyl \Services \Allocations ;
44
5+ use Exception ;
56use IPTools \Network ;
67use Pterodactyl \Models \Node ;
78use Illuminate \Database \ConnectionInterface ;
9+ use Pterodactyl \Exceptions \DisplayException ;
810use Pterodactyl \Contracts \Repository \AllocationRepositoryInterface ;
911use Pterodactyl \Exceptions \Service \Allocation \CidrOutOfRangeException ;
1012use Pterodactyl \Exceptions \Service \Allocation \PortOutOfRangeException ;
@@ -42,9 +44,10 @@ public function __construct(AllocationRepositoryInterface $repository, Connectio
4244 /**
4345 * Insert allocations into the database and link them to a specific node.
4446 *
47+ * @throws \Pterodactyl\Exceptions\DisplayException
4548 * @throws \Pterodactyl\Exceptions\Service\Allocation\CidrOutOfRangeException
46- * @throws \Pterodactyl\Exceptions\Service\Allocation\PortOutOfRangeException
4749 * @throws \Pterodactyl\Exceptions\Service\Allocation\InvalidPortMappingException
50+ * @throws \Pterodactyl\Exceptions\Service\Allocation\PortOutOfRangeException
4851 * @throws \Pterodactyl\Exceptions\Service\Allocation\TooManyPortsInRangeException
4952 */
5053 public function handle (Node $ node , array $ data )
@@ -56,8 +59,16 @@ public function handle(Node $node, array $data)
5659 }
5760 }
5861
62+ try {
63+ $ underlying = gethostbyname ($ data ['allocation_ip ' ]);
64+ $ parsed = Network::parse ($ underlying );
65+ } catch (Exception $ exception ) {
66+ /* @noinspection PhpUndefinedVariableInspection */
67+ throw new DisplayException ("Could not parse provided allocation IP address ( {$ underlying }): {$ exception ->getMessage ()}" , $ exception );
68+ }
69+
5970 $ this ->connection ->beginTransaction ();
60- foreach (Network:: parse ( gethostbyname ( $ data [ ' allocation_ip ' ])) as $ ip ) {
71+ foreach ($ parsed as $ ip ) {
6172 foreach ($ data ['allocation_ports ' ] as $ port ) {
6273 if (!is_digit ($ port ) && !preg_match (self ::PORT_RANGE_REGEX , $ port )) {
6374 throw new InvalidPortMappingException ($ port );
0 commit comments