Skip to content

Commit 7b91c38

Browse files
authored
Lookup both A and AAAA records for node FQDNs (pterodactyl#4398)
Allows IPv6 addresses to be used, instead of IPv4 being required. Closes <pterodactyl#4011>
1 parent 815e1e4 commit 7b91c38

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

app/Console/Commands/Node/MakeNodeCommand.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,13 @@ public function handle(NodeCreationService $creationService)
5959
$data['description'] = $this->option('description') ?? $this->ask('Enter a description to identify the node');
6060
$data['location_id'] = $this->option('locationId') ?? $this->ask('Enter a valid location id');
6161
$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');
62-
if (!filter_var(gethostbyname($data['fqdn']), FILTER_VALIDATE_IP)) {
62+
63+
// Note, this function will also resolve CNAMEs for us automatically,
64+
// there is no need to manually resolve them here.
65+
//
66+
// Using @ as workaround to fix https://bugs.php.net/bug.php?id=73149
67+
$records = @dns_get_record($data['fqdn'], DNS_A + DNS_AAAA);
68+
if (empty($records)) {
6369
$this->error('The FQDN or IP address provided does not resolve to a valid IP address.');
6470

6571
return;

app/Http/Requests/Admin/Node/NodeFormRequest.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,12 @@ public function rules()
3434
public function withValidator($validator)
3535
{
3636
$validator->after(function ($validator) {
37-
// Check that the FQDN is a valid IP address.
38-
if (!filter_var(gethostbyname($this->input('fqdn')), FILTER_VALIDATE_IP)) {
37+
// Note, this function will also resolve CNAMEs for us automatically,
38+
// there is no need to manually resolve them here.
39+
//
40+
// Using @ as workaround to fix https://bugs.php.net/bug.php?id=73149
41+
$records = @dns_get_record($this->input('fqdn'), DNS_A + DNS_AAAA);
42+
if (empty($records)) {
3943
$validator->errors()->add('fqdn', trans('admin/node.validation.fqdn_not_resolvable'));
4044
}
4145

app/Services/Allocations/AssignmentService.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ public function handle(Node $node, array $data)
6060
}
6161

6262
try {
63+
// TODO: how should we approach supporting IPv6 with this?
64+
// gethostbyname only supports IPv4, but the alternative (dns_get_record) returns
65+
// an array of records, which is not ideal for this use case, we need a SINGLE
66+
// IP to use, not multiple.
6367
$underlying = gethostbyname($data['allocation_ip']);
6468
$parsed = Network::parse($underlying);
6569
} catch (Exception $exception) {

0 commit comments

Comments
 (0)