From: Roland Häder Date: Thu, 31 Mar 2011 01:49:19 +0000 (+0000) Subject: Rewritten session id solver to lesser negation X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=0a29725abae8105ec97ca1e4d861b6de70d7a008;p=hub.git Rewritten session id solver to lesser negation --- diff --git a/application/hub/main/tools/class_HubTools.php b/application/hub/main/tools/class_HubTools.php index 5426c0b7c..60fd33ca7 100644 --- a/application/hub/main/tools/class_HubTools.php +++ b/application/hub/main/tools/class_HubTools.php @@ -112,38 +112,38 @@ class HubTools extends BaseFrameworkSystem { $recipient = $sessionId; // Does it match a direct ip:port? (hint: see www.regexlib.com for the regular expression) - if (!preg_match('/((25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])):([0-9]{3,5})/', $sessionId)) { - // Is it in cache? - if (isset($selfInstance->sessionIdCache[$sessionId])) { - // Debug message - $selfInstance->debugOutput('HUB-TOOLS: Using entry from sessionIdCache[] array.'); - - // Then use it - $recipient = $selfInstance->sessionIdCache[$sessionId]; - } elseif (preg_match('/([a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,6}/', $sessionId)) { - // Hostname:port found - $hostnameArray = explode(':', $sessionId); - - // Try to resolve it and add port again - // @TODO We may want to encapsulate this PHP call into an own class - $recipient = gethostbyname($hostnameArray[0]) . ':' . $hostnameArray[1]; - - // Is it valid? - if ($recipient == $sessionId) { - // Resolving hostname->IP failed! - throw new NoValidHostnameException($hostnameArray, self::EXCEPTION_HOSTNAME_NOT_FOUND); - } // END - if - } elseif (!preg_match('/([a-f0-9]{' . $selfInstance->getSessionIdLength() . '})/', $sessionId)) { - // Invalid session id - throw new InvalidSessionIdException($sessionId, self::EXCEPTION_SESSION_ID_IS_INVALID); - } else { - // Debug message - $selfInstance->debugOutput('HUB-TOOLS: Using internal resolver.'); - - // Resolve it here - $recipient = $selfInstance->resolveIpPortBySessionId($sessionId); - } - } // END - if + if (preg_match('/((25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])):([0-9]{3,5})/', $sessionId)) { + // Direct ip:port found + $selfInstance->debugOutput('HUB-TOOLS: Direct ip:port ' . $sessionId . ' detected.'); + } elseif (isset($selfInstance->sessionIdCache[$sessionId])) { + // Debug message + $selfInstance->debugOutput('HUB-TOOLS: Using entry from sessionIdCache[] array.'); + + // Found in cache! + $recipient = $selfInstance->sessionIdCache[$sessionId]; + } elseif (preg_match('/([a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,6}/', $sessionId)) { + // Hostname:port found + $hostnameArray = explode(':', $sessionId); + + // Try to resolve it and add port again + // @TODO We may want to encapsulate this PHP call into an own class + $recipient = gethostbyname($hostnameArray[0]) . ':' . $hostnameArray[1]; + + // Is it valid? + if ($recipient == $sessionId) { + // Resolving hostname->IP failed! + throw new NoValidHostnameException($hostnameArray, self::EXCEPTION_HOSTNAME_NOT_FOUND); + } // END - if + } elseif (preg_match('/([a-f0-9]{' . $selfInstance->getSessionIdLength() . '})/', $sessionId)) { + // Debug message + $selfInstance->debugOutput('HUB-TOOLS: Using internal resolver.'); + + // Resolve session id into a ip:port combination + $recipient = $selfInstance->resolveIpPortBySessionId($sessionId); + } else { + // Invalid session id + throw new InvalidSessionIdException($sessionId, self::EXCEPTION_SESSION_ID_IS_INVALID); + } // Output message $selfInstance->debugOutput('HUB-TOOLS: Session id ' . $sessionId . ' resolved to ' . $recipient);