From 617dfbbd0637c8db7d249b2cb73b2141057c8fd1 Mon Sep 17 00:00:00 2001 From: orbiter Date: Fri, 5 Mar 2010 16:03:55 +0000 Subject: [PATCH] allo 'authorization by encoded password' also if requesting client is not from localhost but from the same host as yacy is running on. git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@6714 6c8d7289-2bf4-0310-a012-ef5d649a1542 --- source/de/anomic/search/Switchboard.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/source/de/anomic/search/Switchboard.java b/source/de/anomic/search/Switchboard.java index 34f63c569..61434ece6 100644 --- a/source/de/anomic/search/Switchboard.java +++ b/source/de/anomic/search/Switchboard.java @@ -41,7 +41,9 @@ import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.UnsupportedEncodingException; +import java.net.InetAddress; import java.net.MalformedURLException; +import java.net.UnknownHostException; import java.security.NoSuchAlgorithmException; import java.security.PublicKey; import java.security.spec.InvalidKeySpecException; @@ -1823,7 +1825,12 @@ public final class Switchboard extends serverSwitch { // authorization for localhost, only if flag is set to grant localhost access as admin final String clientIP = requestHeader.get(HeaderFramework.CONNECTION_PROP_CLIENTIP, ""); final String refererHost = requestHeader.refererHost(); - final boolean accessFromLocalhost = serverCore.isLocalhost(clientIP) && (refererHost.length() == 0 || serverCore.isLocalhost(refererHost)); + boolean accessFromLocalhost = serverCore.isLocalhost(clientIP) && (refererHost.length() == 0 || serverCore.isLocalhost(refererHost)); + if (!accessFromLocalhost) try { + // the access may also be from a different IP than localhost if it is the same as the YaCy instance is running on + InetAddress myaddress = InetAddress.getLocalHost(); + accessFromLocalhost = myaddress.equals(InetAddress.getByName(clientIP)) && (refererHost.length() == 0 || myaddress.equals(InetAddress.getByName(refererHost))); + } catch (UnknownHostException e) {} if (getConfigBool("adminAccountForLocalhost", false) && accessFromLocalhost) return 3; // soft-authenticated for localhost // get the authorization string from the header