diff --git a/src/mibew/libs/chat.php b/src/mibew/libs/chat.php index 39b1f6e4..d893c536 100644 --- a/src/mibew/libs/chat.php +++ b/src/mibew/libs/chat.php @@ -572,8 +572,7 @@ function visitor_from_request() } /** - * @return array Return remote host from active request. contains - * (user_id string, user_name string) + * @return string Return remote host from active request */ function get_remote_host() { @@ -581,7 +580,10 @@ function get_remote_host() $has_proxy = isset($_SERVER['HTTP_X_FORWARDED_FOR']) && $_SERVER['HTTP_X_FORWARDED_FOR'] != $_SERVER['REMOTE_ADDR']; if ($has_proxy) { - $ext_addr = $_SERVER['REMOTE_ADDR'] . ' (' . $_SERVER['HTTP_X_FORWARDED_FOR'] . ')'; + $ips = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR'], 2); + $ext_addr = (count($ips) > 1) + ? $ips[0] . ' (' . $_SERVER['HTTP_X_FORWARDED_FOR'] . ')' + : $ips[0]; } return isset($_SERVER['REMOTE_HOST']) ? $_SERVER['REMOTE_HOST'] : $ext_addr; diff --git a/src/mibew/libs/classes/Mibew/RequestProcessor/UsersProcessor.php b/src/mibew/libs/classes/Mibew/RequestProcessor/UsersProcessor.php index 4cc007d1..b5f34ad2 100644 --- a/src/mibew/libs/classes/Mibew/RequestProcessor/UsersProcessor.php +++ b/src/mibew/libs/classes/Mibew/RequestProcessor/UsersProcessor.php @@ -266,11 +266,8 @@ class UsersProcessor extends ClientSideProcessor implements AuthenticationManage ); // Get user ip - if (preg_match("/(\\d+\\.\\d+\\.\\d+\\.\\d+)/", $thread->remote, $matches) != 0) { - $user_ip = $matches[1]; - } else { - $user_ip = false; - } + $user_ip = preg_replace('/^(\S+)(\s.+)?/', '\\1', $thread->remote); + $user_ip = filter_var($user_ip, FILTER_VALIDATE_IP); // Get thread operartor name $next_agent = $thread->nextAgent != 0 @@ -438,11 +435,8 @@ class UsersProcessor extends ClientSideProcessor implements AuthenticationManage $user_agent = get_user_agent_version($details['user_agent']); // Get user ip - if (preg_match("/(\\d+\\.\\d+\\.\\d+\\.\\d+)/", $details['remote_host'], $matches) != 0) { - $user_ip = $matches[1]; - } else { - $user_ip = false; - } + $user_ip = preg_replace('/^(\S+)(\s.+)?/', '\\1', $details['remote_host']); + $user_ip = filter_var($user_ip, FILTER_VALIDATE_IP); // Get invitation info $row['invited'] = ($row['invitationstate'] == Thread::INVITATION_WAIT);