Browse Source

update host validation

main
ghost 12 months ago
parent
commit
728d1c4907
  1. 35
      src/public/socket.php

35
src/public/socket.php

@ -20,35 +20,54 @@ if (empty($_GET['port']) || !\Yggverse\Net\Socket::isPort($_GET['port'])) @@ -20,35 +20,54 @@ if (empty($_GET['port']) || !\Yggverse\Net\Socket::isPort($_GET['port']))
);
}
// Valid host required to continue
if (isset($_GET['host']) && !\Yggverse\Net\Socket::isHost($_GET['host']))
// 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' => _('valid host required')
'message' => _('could not detect valid REMOTE_ADDR')
]
)
);
}
}
// Set client address if optional host not provided
if (empty($_GET['host']) && isset($_SERVER['REMOTE_ADDR']) && !\Yggverse\Net\Socket::isHost($_SERVER['REMOTE_ADDR']))
{
else
{
$host = $_SERVER['REMOTE_ADDR'];
}
}
else
{
// Valid host required to continue
if (isset($_GET['host']) && !\Yggverse\Net\Socket::isHost($_GET['host']))
{
exit(
json_encode(
[
'success' => false,
'message' => _('valid host required')
]
)
);
}
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)
]
)
);

Loading…
Cancel
Save