@ -33,7 +33,6 @@ import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest ;
import javax.servlet.http.HttpServletRequest ;
import javax.servlet.http.HttpServletResponse ;
import javax.servlet.http.HttpServletResponse ;
import net.yacy.cora.protocol.Domains ;
import net.yacy.cora.protocol.Domains ;
import net.yacy.cora.util.ConcurrentLog ;
import net.yacy.search.Switchboard ;
import net.yacy.search.Switchboard ;
@ -81,10 +80,10 @@ abstract public class AbstractRemoteHandler extends AbstractHandler implements H
@Override
@Override
public void handle ( String target , Request baseRequest , HttpServletRequest request ,
public void handle ( String target , Request baseRequest , HttpServletRequest request ,
HttpServletResponse response ) throws IOException , ServletException {
HttpServletResponse response ) throws IOException , ServletException {
String host = request . getHeader ( "Host" ) ;
String host = request . getHeader ( "Host" ) ;
if ( host = = null ) return ; // no proxy request, continue processing by handlers
if ( host = = null ) return ; // no proxy request, continue processing by handlers
int hostSplitPos = host . indexOf ( ':' ) ;
int hostSplitPos = host . indexOf ( ':' ) ;
String hostOnly = hostSplitPos < 0 ? host : host . substring ( 0 , hostSplitPos ) ;
String hostOnly = hostSplitPos < 0 ? host : host . substring ( 0 , hostSplitPos ) ;
@ -98,7 +97,7 @@ abstract public class AbstractRemoteHandler extends AbstractHandler implements H
InetAddress resolvedIP = Domains . dnsResolve ( hostOnly ) ; // during testing isLocal() failed to resolve domain against publicIP
InetAddress resolvedIP = Domains . dnsResolve ( hostOnly ) ; // during testing isLocal() failed to resolve domain against publicIP
if ( sb . myPublicIP ( ) . equals ( resolvedIP . getHostAddress ( ) ) ) {
if ( sb . myPublicIP ( ) . equals ( resolvedIP . getHostAddress ( ) ) ) {
localVirtualHostNames . add ( resolvedIP . getHostName ( ) ) ; // remember resolved hostname
localVirtualHostNames . add ( resolvedIP . getHostName ( ) ) ; // remember resolved hostname
//localVirtualHostNames.add(resolved.getHostAddress());
//localVirtualHostNames.add(resolved.getHostAddress()); // might change ?
return ;
return ;
}
}
@ -113,12 +112,10 @@ abstract public class AbstractRemoteHandler extends AbstractHandler implements H
}
}
String remoteHost = request . getRemoteHost ( ) ;
String remoteHost = request . getRemoteHost ( ) ;
InetAddress remoteIP = Domains . dnsResolve ( remoteHost ) ;
if ( ! Domains . isThisHostIP ( remoteHost ) ) { // isThisHostIP checks resolves & isAnyLocal & isLoopback IP
if ( ! remoteIP . isAnyLocalAddress ( ) & & ! remoteIP . isLoopbackAddress ( ) ) {
// TODO: handle proxy account ~ ? use proxyClient config instead fix of localIP?
// access not from local IP
// TODO: should .isLinkLocalAddress() be check ? & handle proxy account ~ ? use proxyClient config instead fix of localIP?
response . sendError ( HttpServletResponse . SC_FORBIDDEN ,
response . sendError ( HttpServletResponse . SC_FORBIDDEN ,
"proxy use not granted for IP " + re moteIP. getHostAddress ( ) + " (see Server Proxy Access settings)." ) ;
"proxy use not granted for IP " + request . getRemoteAddr ( ) + " (see Server Proxy Access settings)." ) ;
baseRequest . setHandled ( true ) ;
baseRequest . setHandled ( true ) ;
return ;
return ;
}
}