mirror of
https://github.com/YGGverse/web-api.git
synced 2026-03-31 17:45:30 +00:00
update host validation
This commit is contained in:
parent
0e89d599c9
commit
728d1c4907
1 changed files with 36 additions and 17 deletions
|
|
@ -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']))
|
||||
{
|
||||
exit(
|
||||
json_encode(
|
||||
[
|
||||
'success' => false,
|
||||
'message' => _('valid host required')
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// Set client address if optional host not provided
|
||||
if (empty($_GET['host']) && isset($_SERVER['REMOTE_ADDR']) && !\Yggverse\Net\Socket::isHost($_SERVER['REMOTE_ADDR']))
|
||||
if (empty($_GET['host']))
|
||||
{
|
||||
$host = $_SERVER['REMOTE_ADDR'];
|
||||
// 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
|
||||
{
|
||||
$host = $_GET['host'];
|
||||
// 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…
Add table
Add a link
Reference in a new issue