From 728d1c4907f523d30b89a166a49608f73aedd133 Mon Sep 17 00:00:00 2001 From: ghost Date: Sat, 16 Dec 2023 16:25:07 +0200 Subject: [PATCH] update host validation --- src/public/socket.php | 53 +++++++++++++++++++++++++++++-------------- 1 file changed, 36 insertions(+), 17 deletions(-) diff --git a/src/public/socket.php b/src/public/socket.php index 6d49ccb..d7eb349 100644 --- a/src/public/socket.php +++ b/src/public/socket.php @@ -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) ] ) );