@ -139,6 +139,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
// class initializer
public serverCore ( int port , int maxSessions , int timeout ,
public serverCore ( int port , int maxSessions , int timeout ,
@ -299,19 +308,20 @@ public final class serverCore extends serverAbstractThread implements serverThre
announceThreadBlockApply ( ) ;
announceThreadBlockApply ( ) ;
Socket controlSocket = this . socket . accept ( ) ;
Socket controlSocket = this . socket . accept ( ) ;
announceThreadBlockRelease ( ) ;
announceThreadBlockRelease ( ) ;
String clientIP = "" + controlSocket . getInetAddress ( ) . getHostAddress ( ) ;
String cIP = clientAddress ( controlSocket ) ;
if ( bfHost . get ( clientIP ) ! = null ) {
//System.out.println("server bfHosts=" + bfHost.toString());
log . logInfo ( "SLOWING DOWN ACCESS FOR BRUTE-FORCE PREVENTION FROM " + clientIP ) ;
if ( bfHost . get ( cIP ) ! = null ) {
log . logInfo ( "SLOWING DOWN ACCESS FOR BRUTE-FORCE PREVENTION FROM " + cIP ) ;
// add a delay to make brute-force harder
// 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 ) ;
controlSocket . setSoTimeout ( this . timeout ) ;
Session connection = ( Session ) this . theSessionPool . borrowObject ( ) ;
Session connection = ( Session ) this . theSessionPool . borrowObject ( ) ;
connection . execute ( controlSocket ) ;
connection . execute ( controlSocket ) ;
//log.logDebug("* NEW SESSION: " + connection.request + " from " + clientIP);
//log.logDebug("* NEW SESSION: " + connection.request + " from " + clientIP);
} else {
} 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
// idle until number of maximal threads is (again) reached
//synchronized(this) {
//synchronized(this) {