mirror of
https://github.com/pelican-dev/panel.git
synced 2025-07-12 02:51: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;
|
||||
}
|
||||
|
||||
$validRecords = gethostbynamel($state);
|
||||
if ($validRecords) {
|
||||
$ip = get_ip_from_hostname($state);
|
||||
if ($ip) {
|
||||
$set('dns', true);
|
||||
|
||||
$set('ip', collect($validRecords)->first());
|
||||
|
||||
return;
|
||||
$set('ip', $ip);
|
||||
} else {
|
||||
$set('dns', false);
|
||||
}
|
||||
|
||||
$set('dns', false);
|
||||
})
|
||||
->maxLength(255),
|
||||
|
||||
|
@ -154,16 +154,14 @@ class EditNode extends EditRecord
|
||||
return;
|
||||
}
|
||||
|
||||
$validRecords = gethostbynamel($state);
|
||||
if ($validRecords) {
|
||||
$ip = get_ip_from_hostname($state);
|
||||
if ($ip) {
|
||||
$set('dns', true);
|
||||
|
||||
$set('ip', collect($validRecords)->first());
|
||||
|
||||
return;
|
||||
$set('ip', $ip);
|
||||
} else {
|
||||
$set('dns', false);
|
||||
}
|
||||
|
||||
$set('dns', false);
|
||||
})
|
||||
->maxLength(255),
|
||||
TextInput::make('ip')
|
||||
@ -618,10 +616,10 @@ class EditNode extends EditRecord
|
||||
$data['config'] = $node->getYamlConfiguration();
|
||||
|
||||
if (!is_ip($node->fqdn)) {
|
||||
$validRecords = gethostbynamel($node->fqdn);
|
||||
if ($validRecords) {
|
||||
$ip = get_ip_from_hostname($node->fqdn);
|
||||
if ($ip) {
|
||||
$data['dns'] = true;
|
||||
$data['ip'] = collect($validRecords)->first();
|
||||
$data['ip'] = $ip;
|
||||
} else {
|
||||
$data['dns'] = false;
|
||||
}
|
||||
|
@ -81,3 +81,20 @@ if (!function_exists('resolve_path')) {
|
||||
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