update host validation

This commit is contained in:
ghost 2023-12-16 16:25:07 +02:00
parent 0e89d599c9
commit 728d1c4907

View File

@ -20,6 +20,30 @@ if (empty($_GET['port']) || !\Yggverse\Net\Socket::isPort($_GET['port']))
);
}
// Set client address if optional host not provided
if (empty($_GET['host']))
{
// Valid REMOTE_ADDR required to continue
if (empty($_SERVER['REMOTE_ADDR']) || !\Yggverse\Net\Socket::isHost($_SERVER['REMOTE_ADDR']))
{
exit(
json_encode(
[
'success' => false,
'message' => _('could not detect valid REMOTE_ADDR')
]
)
);
}
else
{
$host = $_SERVER['REMOTE_ADDR'];
}
}
else
{
// Valid host required to continue
if (isset($_GET['host']) && !\Yggverse\Net\Socket::isHost($_GET['host']))
{
@ -33,22 +57,17 @@ if (isset($_GET['host']) && !\Yggverse\Net\Socket::isHost($_GET['host']))
);
}
// Set client address if optional host not provided
if (empty($_GET['host']) && isset($_SERVER['REMOTE_ADDR']) && !\Yggverse\Net\Socket::isHost($_SERVER['REMOTE_ADDR']))
{
$host = $_SERVER['REMOTE_ADDR'];
}
else
{
$host = $_GET['host'];
}
}
// Connection test
exit(
json_encode(
[
'success' => \Yggverse\Net\Socket::isOpen($_GET['host'], $_GET['port'], 3)
'success' => \Yggverse\Net\Socket::isOpen($host, $_GET['port'], 3)
]
)
);