From 15c611b32eb2fdfba54bf44a45e937c8f813bf5b Mon Sep 17 00:00:00 2001 From: Andre Lorbach Date: Fri, 25 Jul 2008 14:48:58 +0200 Subject: [PATCH] Fixed Bug 82 from bugtracker. Internal IP Addresses are not linked anymore --- src/include/functions_common.php | 37 ++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/src/include/functions_common.php b/src/include/functions_common.php index 836dcd9..364ee07 100644 --- a/src/include/functions_common.php +++ b/src/include/functions_common.php @@ -866,16 +866,16 @@ function AddContextLinks(&$sourceTxt) // Create Search Array $search = array ( - '/\.([\w\d\_\-]+)\.(' . $szTLDDomains . ')([^a-zA-Z0-9\.])/x', + '/\.([\w\d\_\-]+)\.(' . $szTLDDomains . ')([^a-zA-Z0-9\.])/e', // '|([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})|', -/* (?:127)| */ '/(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)/x', +/* (?:127)| */ '/(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)/e', ); // Create Replace Array $replace = array ( - '.$1.$2$3', - '$1.$2.$3.$4', + "'.' . InsertLookupLink(\"\", \"\\1.\\2\", \"\", \"\\3\")", + "'.' . InsertLookupLink(\"\\1.\\2.\\3.\\4\", \"\", \"\", \"\")", ); // Replace and return! @@ -885,6 +885,35 @@ function AddContextLinks(&$sourceTxt) //return $outTxt; } +/* +* Helper to create a Lookup Link! +*/ +function InsertLookupLink( $szIP, $szDomain, $prepend, $append ) +{ + // Create string + $szReturn = $prepend; + if ( strlen($szIP) > 0 ) + { + if ( + (($pos = strpos($szIP, "10.")) !== FALSE && $pos == 0) || + (($pos = strpos($szIP, "127.")) !== FALSE && $pos == 0) || + (($pos = strpos($szIP, "172.")) !== FALSE && $pos == 0) || + (($pos = strpos($szIP, "192.")) !== FALSE && $pos == 0) + ) + // Do not create a LINK in this case! + $szReturn .= '' . $szIP . ''; + else + // Normal LINK! + $szReturn .= '' . $szIP . ''; + } + else if ( strlen($szDomain) > 0 ) + $szReturn .= '' . $szDomain . ''; + $szReturn .= $append; + + // return result + return $szReturn; +} + /* * Reserve Resolve IP Address! */