mirror of
https://github.com/pelican-dev/panel.git
synced 2025-07-12 10:41:07 +02:00
Replace gethostbynamel
with dns_get_record
(#1479)
This commit is contained in:
parent
c5aa8a3980
commit
23ddded61e
@ -89,16 +89,14 @@ class CreateNode extends CreateRecord
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$validRecords = gethostbynamel($state);
|
$ip = get_ip_from_hostname($state);
|
||||||
if ($validRecords) {
|
if ($ip) {
|
||||||
$set('dns', true);
|
$set('dns', true);
|
||||||
|
|
||||||
$set('ip', collect($validRecords)->first());
|
$set('ip', $ip);
|
||||||
|
} else {
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$set('dns', false);
|
$set('dns', false);
|
||||||
|
}
|
||||||
})
|
})
|
||||||
->maxLength(255),
|
->maxLength(255),
|
||||||
|
|
||||||
|
@ -154,16 +154,14 @@ class EditNode extends EditRecord
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$validRecords = gethostbynamel($state);
|
$ip = get_ip_from_hostname($state);
|
||||||
if ($validRecords) {
|
if ($ip) {
|
||||||
$set('dns', true);
|
$set('dns', true);
|
||||||
|
|
||||||
$set('ip', collect($validRecords)->first());
|
$set('ip', $ip);
|
||||||
|
} else {
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$set('dns', false);
|
$set('dns', false);
|
||||||
|
}
|
||||||
})
|
})
|
||||||
->maxLength(255),
|
->maxLength(255),
|
||||||
TextInput::make('ip')
|
TextInput::make('ip')
|
||||||
@ -618,10 +616,10 @@ class EditNode extends EditRecord
|
|||||||
$data['config'] = $node->getYamlConfiguration();
|
$data['config'] = $node->getYamlConfiguration();
|
||||||
|
|
||||||
if (!is_ip($node->fqdn)) {
|
if (!is_ip($node->fqdn)) {
|
||||||
$validRecords = gethostbynamel($node->fqdn);
|
$ip = get_ip_from_hostname($node->fqdn);
|
||||||
if ($validRecords) {
|
if ($ip) {
|
||||||
$data['dns'] = true;
|
$data['dns'] = true;
|
||||||
$data['ip'] = collect($validRecords)->first();
|
$data['ip'] = $ip;
|
||||||
} else {
|
} else {
|
||||||
$data['dns'] = false;
|
$data['dns'] = false;
|
||||||
}
|
}
|
||||||
|
@ -81,3 +81,20 @@ if (!function_exists('resolve_path')) {
|
|||||||
return implode('/', $absolutes);
|
return implode('/', $absolutes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!function_exists('get_ip_from_hostname')) {
|
||||||
|
function get_ip_from_hostname(string $hostname): string|bool
|
||||||
|
{
|
||||||
|
$validARecords = @dns_get_record($hostname, DNS_A);
|
||||||
|
if ($validARecords) {
|
||||||
|
return collect($validARecords)->first()['ip'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$validAAAARecords = @dns_get_record($hostname, DNS_AAAA);
|
||||||
|
if ($validAAAARecords) {
|
||||||
|
return collect($validAAAARecords)->first()['ipv6'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user