@ -140,6 +140,15 @@ public final class serverCore extends serverAbstractThread implements serverThre
}
}
public static String clientAddress ( Socket s ) {
InetAddress uAddr = s . getInetAddress ( ) ;
if ( uAddr . isAnyLocalAddress ( ) ) return "localhost" ;
String cIP = uAddr . getHostAddress ( ) ;
if ( cIP . equals ( "0:0:0:0:0:0:0:1" ) ) cIP = "localhost" ;
if ( cIP . equals ( "127.0.0.1" ) ) cIP = "localhost" ;
return cIP ;
}
// class initializer
public serverCore ( int port , int maxSessions , int timeout ,
boolean termSleepingThreads , boolean blockAttack ,
@ -299,19 +308,20 @@ public final class serverCore extends serverAbstractThread implements serverThre
announceThreadBlockApply ( ) ;
Socket controlSocket = this . socket . accept ( ) ;
announceThreadBlockRelease ( ) ;
String clientIP = "" + controlSocket . getInetAddress ( ) . getHostAddress ( ) ;
if ( bfHost . get ( clientIP ) ! = null ) {
log . logInfo ( "SLOWING DOWN ACCESS FOR BRUTE-FORCE PREVENTION FROM " + clientIP ) ;
String cIP = clientAddress ( controlSocket ) ;
//System.out.println("server bfHosts=" + bfHost.toString());
if ( bfHost . get ( cIP ) ! = null ) {
log . logInfo ( "SLOWING DOWN ACCESS FOR BRUTE-FORCE PREVENTION FROM " + cIP ) ;
// add a delay to make brute-force harder
try { Thread . currentThread ( ) . sleep ( 1 000) ; } catch ( InterruptedException e ) { }
try { Thread . currentThread ( ) . sleep ( 3 000) ; } catch ( InterruptedException e ) { }
}
if ( ( this . denyHost = = null ) | | ( this . denyHost . get ( c lient IP) = = null ) ) {
if ( ( this . denyHost = = null ) | | ( this . denyHost . get ( c IP) = = null ) ) {
controlSocket . setSoTimeout ( this . timeout ) ;
Session connection = ( Session ) this . theSessionPool . borrowObject ( ) ;
connection . execute ( controlSocket ) ;
//log.logDebug("* NEW SESSION: " + connection.request + " from " + clientIP);
} else {
System . out . println ( "ACCESS FROM " + c lient IP + " DENIED" ) ;
System . out . println ( "ACCESS FROM " + c IP + " DENIED" ) ;
}
// idle until number of maximal threads is (again) reached
//synchronized(this) {