Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance
Java decentralizedintranet-searchintranet-search-enginep2pp2p-networkprivacyprivacy-protectionsearch-enginesearchenginewebweb-search-enginewebsearchwebseearch-engine
fixed mess with test on localhost (which means local hosts for some cases)
Michael Peter Christen1c56befb9390
diff --git a/source/net/yacy/cora/protocol/Domains.java b/source/net/yacy/cora/protocol/Domains.javaindex 2f9556e12..74267d668 100644--- a/source/net/yacy/cora/protocol/Domains.java+++ b/source/net/yacy/cora/protocol/Domains.java@@ -73,7 +73,8 @@ public class Domains {private static Method InetAddressLocatorGetLocaleInetAddressMethod;private static final Set<String> ccSLD_TLD = new HashSet<String>();private static final String PRESENT = "";- private static final Pattern LOCAL_PATTERNS = Pattern.compile("(10\\..*)|(127\\..*)|(172\\.(1[6-9]|2[0-9]|3[0-1])\\..*)|(169\\.254\\..*)|(192\\.168\\..*)|(localhost)|(\\[?\\:\\:1/.*)|(\\[?fc.*)|(\\[?fd.*)|(\\[?(fe80|0)\\:0\\:0\\:0\\:0\\:0\\:0\\:1.*)");+ private static final Pattern LOCALHOST_PATTERNS = Pattern.compile("(127\\..*)|(localhost)|(\\[?(fe80|0)\\:0\\:0\\:0\\:0\\:0\\:0\\:1.*)");+ private static final Pattern INTRANET_PATTERNS = Pattern.compile("(10\\..*)|(127\\..*)|(172\\.(1[6-9]|2[0-9]|3[0-1])\\..*)|(169\\.254\\..*)|(192\\.168\\..*)|(localhost)|(\\[?\\:\\:1/.*)|(\\[?fc.*)|(\\[?fd.*)|(\\[?(fe80|0)\\:0\\:0\\:0\\:0\\:0\\:0\\:1.*)");private static final int MAX_NAME_CACHE_HIT_SIZE = 10000;private static final int MAX_NAME_CACHE_MISS_SIZE = 1000;@@ -1029,6 +1030,15 @@ public class Domains {return (isLocal(host, hostaddress)) ? TLD_Local_ID : TLD_Generic_ID;}+ /**+ * check the host ip string against localhost names+ * @param host+ * @return true if the host from the string is the localhost+ */+ public static boolean isLocalhost(final String host) {+ return (host != null && LOCALHOST_PATTERNS.matcher(host).matches());+ }+/*** check if a given host is the name for a local host address* this method will return true if noLocalCheck is switched on. This means that@@ -1038,11 +1048,11 @@ public class Domains {* @param host* @return*/- public static boolean isLocalhost(final String host) {+ public static boolean isIntranet(final String host) {return (noLocalCheck || // DO NOT REMOVE THIS! it is correct to return true if the check is off- (host != null && LOCAL_PATTERNS.matcher(host).matches()));+ (host != null && INTRANET_PATTERNS.matcher(host).matches()));}-+/*** check if the given host is a local address.* the hostaddress is optional and shall be given if the address is already known@@ -1061,9 +1071,9 @@ public class Domains {host.isEmpty()) return true;// check local ip addresses- if (isLocalhost(host)) return true;+ if (isIntranet(host)) return true;if (hostaddress != null && (- isLocalhost(hostaddress.getHostAddress()) ||+ isIntranet(hostaddress.getHostAddress()) ||isLocal(hostaddress))) return true;diff --git a/source/net/yacy/http/Jetty8YaCySecurityHandler.java b/source/net/yacy/http/Jetty8YaCySecurityHandler.javaindex 0c8a81e16..eceaeffb6 100644--- a/source/net/yacy/http/Jetty8YaCySecurityHandler.java+++ b/source/net/yacy/http/Jetty8YaCySecurityHandler.java@@ -183,7 +183,7 @@ public class Jetty8YaCySecurityHandler extends SecurityHandler {refererHost = null;}final boolean accessFromLocalhost = Domains.isLocalhost(request.getRemoteHost()) && (refererHost == null || refererHost.length() == 0 || Domains.isLocalhost(refererHost));- // ! note : accessFromLocalhost compares localhost ip pattern ( ! currently also any intranet host is a local host)+ // ! note : accessFromLocalhost compares localhost ip patternfinal boolean grantedForLocalhost = adminAccountForLocalhost && accessFromLocalhost;boolean protectedPage = (pathInContext.indexOf("_p.") > 0);// check "/gsa" and "/solr" if not publicSearchpagediff --git a/source/net/yacy/peers/Network.java b/source/net/yacy/peers/Network.javaindex 502851e51..2879f840a 100644--- a/source/net/yacy/peers/Network.java+++ b/source/net/yacy/peers/Network.java@@ -765,8 +765,8 @@ public class Network}seedURL = new DigestURL(seedURLStr);final String host = seedURL.getHost();- if (Domains.isLocalhost(host)) { // check seedlist reacheable- final String errorMsg = "seedURL in localhost rejected (localhost can't be reached from outside)";+ if (Domains.isIntranet(host)) { // check seedlist reacheable+ final String errorMsg = "seedURL in local network rejected (local hosts can't be reached from outside)";log.warn("SaveSeedList: " + errorMsg);return errorMsg;}diff --git a/source/net/yacy/peers/Seed.java b/source/net/yacy/peers/Seed.javaindex 9a75d2197..352cd55d5 100644--- a/source/net/yacy/peers/Seed.java+++ b/source/net/yacy/peers/Seed.java@@ -1087,8 +1087,8 @@ public class Seed implements Cloneable, Comparable<Seed>, Comparator<Seed>try {final URL url = new URL(seedURL);final String host = url.getHost();- if (Domains.isLocalhost(host)) {- return "seedURL in localhost rejected";+ if (Domains.isIntranet(host)) {+ return "seedURL in local network rejected";}} catch (final MalformedURLException e ) {return "seedURL malformed";