@ -43,6 +43,7 @@ import net.yacy.kelondro.data.meta.DigestURI;
import net.yacy.kelondro.logging.Log ;
import net.yacy.kelondro.logging.Log ;
import net.yacy.kelondro.util.FileUtils ;
import net.yacy.kelondro.util.FileUtils ;
import net.yacy.repository.Blacklist ;
import net.yacy.repository.Blacklist ;
import net.yacy.repository.Blacklist.BlacklistType ;
import net.yacy.search.Switchboard ;
import net.yacy.search.Switchboard ;
import net.yacy.search.query.SearchEventCache ;
import net.yacy.search.query.SearchEventCache ;
import de.anomic.data.ListManager ;
import de.anomic.data.ListManager ;
@ -64,10 +65,6 @@ public class Blacklist_p {
ListManager . switchboard = ( Switchboard ) env ;
ListManager . switchboard = ( Switchboard ) env ;
ListManager . listsPath = new File ( ListManager . switchboard . getDataPath ( ) , ListManager . switchboard . getConfig ( "listManager.listsPath" , "DATA/LISTS" ) ) ;
ListManager . listsPath = new File ( ListManager . switchboard . getDataPath ( ) , ListManager . switchboard . getConfig ( "listManager.listsPath" , "DATA/LISTS" ) ) ;
// get the list of supported blacklist types
final String supportedBlacklistTypesStr = Blacklist . BLACKLIST_TYPES_STRING ;
final String [ ] supportedBlacklistTypes = supportedBlacklistTypesStr . split ( "," ) ;
// load all blacklist files located in the directory
// load all blacklist files located in the directory
List < String > dirlist = FileUtils . getDirListing ( ListManager . listsPath , Blacklist . BLACKLIST_FILENAME_FILTER ) ;
List < String > dirlist = FileUtils . getDirListing ( ListManager . listsPath , Blacklist . BLACKLIST_FILENAME_FILTER ) ;
@ -98,22 +95,22 @@ public class Blacklist_p {
}
}
if ( testurl ! = null ) {
if ( testurl ! = null ) {
prop . putHTML ( "testlist_url" , testurl . toString ( ) ) ;
prop . putHTML ( "testlist_url" , testurl . toString ( ) ) ;
if ( Switchboard . urlBlacklist . isListed ( Blacklist . BLACKLIST_ CRAWLER, testurl ) ) {
if ( Switchboard . urlBlacklist . isListed ( Blacklist Type . CRAWLER, testurl ) ) {
prop . put ( "testlist_listedincrawler" , "1" ) ;
prop . put ( "testlist_listedincrawler" , "1" ) ;
}
}
if ( Switchboard . urlBlacklist . isListed ( Blacklist . BLACKLIST_ DHT, testurl ) ) {
if ( Switchboard . urlBlacklist . isListed ( Blacklist Type . DHT, testurl ) ) {
prop . put ( "testlist_listedindht" , "1" ) ;
prop . put ( "testlist_listedindht" , "1" ) ;
}
}
if ( Switchboard . urlBlacklist . isListed ( Blacklist . BLACKLIST_ NEWS, testurl ) ) {
if ( Switchboard . urlBlacklist . isListed ( Blacklist Type . NEWS, testurl ) ) {
prop . put ( "testlist_listedinnews" , "1" ) ;
prop . put ( "testlist_listedinnews" , "1" ) ;
}
}
if ( Switchboard . urlBlacklist . isListed ( Blacklist . BLACKLIST_ PROXY, testurl ) ) {
if ( Switchboard . urlBlacklist . isListed ( Blacklist Type . PROXY, testurl ) ) {
prop . put ( "testlist_listedinproxy" , "1" ) ;
prop . put ( "testlist_listedinproxy" , "1" ) ;
}
}
if ( Switchboard . urlBlacklist . isListed ( Blacklist . BLACKLIST_ SEARCH, testurl ) ) {
if ( Switchboard . urlBlacklist . isListed ( Blacklist Type . SEARCH, testurl ) ) {
prop . put ( "testlist_listedinsearch" , "1" ) ;
prop . put ( "testlist_listedinsearch" , "1" ) ;
}
}
if ( Switchboard . urlBlacklist . isListed ( Blacklist . BLACKLIST_ SURFTIPS, testurl ) ) {
if ( Switchboard . urlBlacklist . isListed ( Blacklist Type . SURFTIPS, testurl ) ) {
prop . put ( "testlist_listedinsurftips" , "1" ) ;
prop . put ( "testlist_listedinsurftips" , "1" ) ;
}
}
} else {
} else {
@ -159,7 +156,7 @@ public class Blacklist_p {
ListManager . updateListSet ( BLACKLIST_SHARED , blacklistToUse ) ;
ListManager . updateListSet ( BLACKLIST_SHARED , blacklistToUse ) ;
// activate it for all known blacklist types
// activate it for all known blacklist types
for ( final String supportedBlacklistType : supported BlacklistTypes) {
for ( final BlacklistType supportedBlacklistType : BlacklistType. value s( ) ) {
ListManager . updateListSet ( supportedBlacklistType + ".BlackLists" , blacklistToUse ) ;
ListManager . updateListSet ( supportedBlacklistType + ".BlackLists" , blacklistToUse ) ;
}
}
} catch ( final IOException e ) { /* */ }
} catch ( final IOException e ) { /* */ }
@ -189,7 +186,7 @@ public class Blacklist_p {
Log . logWarning ( "Blacklist" , "file " + blackListFile + " could not be deleted!" ) ;
Log . logWarning ( "Blacklist" , "file " + blackListFile + " could not be deleted!" ) ;
}
}
for ( final String supportedBlacklistType : supported BlacklistTypes) {
for ( final BlacklistType supportedBlacklistType : BlacklistType. value s( ) ) {
ListManager . removeFromListSet ( supportedBlacklistType + ".BlackLists" , blacklistToUse ) ;
ListManager . removeFromListSet ( supportedBlacklistType + ".BlackLists" , blacklistToUse ) ;
}
}
@ -212,7 +209,7 @@ public class Blacklist_p {
return prop ;
return prop ;
}
}
for ( final String supportedBlacklistType : supported BlacklistTypes) {
for ( final BlacklistType supportedBlacklistType : BlacklistType. value s( ) ) {
if ( post . containsKey ( "activateList4" + supportedBlacklistType ) ) {
if ( post . containsKey ( "activateList4" + supportedBlacklistType ) ) {
ListManager . updateListSet ( supportedBlacklistType + ".BlackLists" , blacklistToUse ) ;
ListManager . updateListSet ( supportedBlacklistType + ".BlackLists" , blacklistToUse ) ;
} else {
} else {
@ -253,7 +250,7 @@ public class Blacklist_p {
if ( selectedBlacklistEntries . length > 0 ) {
if ( selectedBlacklistEntries . length > 0 ) {
String temp = null ;
String temp = null ;
for ( final String selectedBlacklistEntry : selectedBlacklistEntries ) {
for ( final String selectedBlacklistEntry : selectedBlacklistEntries ) {
if ( ( temp = deleteBlacklistEntry ( blacklistToUse , selectedBlacklistEntry , header , supported BlacklistTypes) ) ! = null ) {
if ( ( temp = deleteBlacklistEntry ( blacklistToUse , selectedBlacklistEntry , header , BlacklistType. value s( ) ) ) ! = null ) {
prop . put ( "LOCATION" , temp ) ;
prop . put ( "LOCATION" , temp ) ;
return prop ;
return prop ;
}
}
@ -273,7 +270,7 @@ public class Blacklist_p {
// store this call as api call
// store this call as api call
ListManager . switchboard . tables . recordAPICall ( post , "Blacklist_p.html" , WorkTables . TABLE_API_TYPE_CONFIGURATION , "add to blacklist: " + blentry ) ;
ListManager . switchboard . tables . recordAPICall ( post , "Blacklist_p.html" , WorkTables . TABLE_API_TYPE_CONFIGURATION , "add to blacklist: " + blentry ) ;
final String temp = addBlacklistEntry ( blacklistToUse , blentry , header , supported BlacklistTypes) ;
final String temp = addBlacklistEntry ( blacklistToUse , blentry , header , BlacklistType. value s( ) ) ;
if ( temp ! = null ) {
if ( temp ! = null ) {
prop . put ( "LOCATION" , temp ) ;
prop . put ( "LOCATION" , temp ) ;
return prop ;
return prop ;
@ -298,12 +295,12 @@ public class Blacklist_p {
! targetBlacklist . equals ( blacklistToUse ) ) {
! targetBlacklist . equals ( blacklistToUse ) ) {
String temp ;
String temp ;
for ( final String selectedBlacklistEntry : selectedBlacklistEntries ) {
for ( final String selectedBlacklistEntry : selectedBlacklistEntries ) {
if ( ( temp = addBlacklistEntry ( targetBlacklist , selectedBlacklistEntry , header , supported BlacklistTypes) ) ! = null ) {
if ( ( temp = addBlacklistEntry ( targetBlacklist , selectedBlacklistEntry , header , BlacklistType. value s( ) ) ) ! = null ) {
prop . put ( "LOCATION" , temp ) ;
prop . put ( "LOCATION" , temp ) ;
return prop ;
return prop ;
}
}
if ( ( temp = deleteBlacklistEntry ( blacklistToUse , selectedBlacklistEntry , header , supported BlacklistTypes) ) ! = null ) {
if ( ( temp = deleteBlacklistEntry ( blacklistToUse , selectedBlacklistEntry , header , BlacklistType. value s( ) ) ) ! = null ) {
prop . put ( "LOCATION" , temp ) ;
prop . put ( "LOCATION" , temp ) ;
return prop ;
return prop ;
@ -338,12 +335,12 @@ public class Blacklist_p {
if ( ! selectedBlacklistEntries [ i ] . equals ( editedBlacklistEntries [ i ] ) ) {
if ( ! selectedBlacklistEntries [ i ] . equals ( editedBlacklistEntries [ i ] ) ) {
if ( ( temp = deleteBlacklistEntry ( blacklistToUse , selectedBlacklistEntries [ i ] , header , supported BlacklistTypes) ) ! = null ) {
if ( ( temp = deleteBlacklistEntry ( blacklistToUse , selectedBlacklistEntries [ i ] , header , BlacklistType. value s( ) ) ) ! = null ) {
prop . put ( "LOCATION" , temp ) ;
prop . put ( "LOCATION" , temp ) ;
return prop ;
return prop ;
}
}
if ( ( temp = addBlacklistEntry ( blacklistToUse , editedBlacklistEntries [ i ] , header , supported BlacklistTypes) ) ! = null ) {
if ( ( temp = addBlacklistEntry ( blacklistToUse , editedBlacklistEntries [ i ] , header , BlacklistType. value s( ) ) ) ! = null ) {
prop . put ( "LOCATION" , temp ) ;
prop . put ( "LOCATION" , temp ) ;
return prop ;
return prop ;
}
}
@ -475,12 +472,12 @@ public class Blacklist_p {
if ( element . equals ( blacklistToUse ) ) { //current List
if ( element . equals ( blacklistToUse ) ) { //current List
prop . put ( DISABLED + BLACKLIST + blacklistCount + "_selected" , "1" ) ;
prop . put ( DISABLED + BLACKLIST + blacklistCount + "_selected" , "1" ) ;
for ( int blTypes = 0 ; blTypes < supported BlacklistTypes. length ; blTypes + + ) {
for ( int blTypes = 0 ; blTypes < BlacklistType. value s( ) . length ; blTypes + + ) {
prop . putXML ( DISABLED + "currentActiveFor_" + blTypes + "_blTypeName" , supported BlacklistTypes [blTypes ] ) ;
prop . putXML ( DISABLED + "currentActiveFor_" + blTypes + "_blTypeName" , BlacklistType. value s() [blTypes ] . toString ( ) ) ;
prop . put ( DISABLED + "currentActiveFor_" + blTypes + "_checked" ,
prop . put ( DISABLED + "currentActiveFor_" + blTypes + "_checked" ,
ListManager . listSetContains ( supported BlacklistTypes[ blTypes ] + ".BlackLists" , element ) ? "0" : "1" ) ;
ListManager . listSetContains ( BlacklistType. value s( ) [ blTypes ] + ".BlackLists" , element ) ? "0" : "1" ) ;
}
}
prop . put ( DISABLED + "currentActiveFor" , supported BlacklistTypes. length ) ;
prop . put ( DISABLED + "currentActiveFor" , BlacklistType. value s( ) . length ) ;
} else {
} else {
prop . putXML ( DISABLED + EDIT + BLACKLIST_MOVE + blacklistMoveCount + "_name" , element ) ;
prop . putXML ( DISABLED + EDIT + BLACKLIST_MOVE + blacklistMoveCount + "_name" , element ) ;
@ -494,9 +491,9 @@ public class Blacklist_p {
}
}
int activeCount = 0 ;
int activeCount = 0 ;
for ( final String supportedBlacklistType : supported BlacklistTypes) {
for ( final BlacklistType supportedBlacklistType : BlacklistType. value s( ) ) {
if ( ListManager . listSetContains ( supportedBlacklistType + ".BlackLists" , element ) ) {
if ( ListManager . listSetContains ( supportedBlacklistType + ".BlackLists" , element ) ) {
prop . putHTML ( DISABLED + BLACKLIST + blacklistCount + "_active_" + activeCount + "_blTypeName" , supportedBlacklistType );
prop . putHTML ( DISABLED + BLACKLIST + blacklistCount + "_active_" + activeCount + "_blTypeName" , supportedBlacklistType .toString ( ) );
activeCount + + ;
activeCount + + ;
}
}
}
}
@ -521,13 +518,13 @@ public class Blacklist_p {
* @param newEntry the entry that is to be added
* @param newEntry the entry that is to be added
* @param header
* @param header
* @param supportedBlacklistTypes
* @param supportedBlacklistTypes
* @return null if no error occur ed, else a String to put into LOCATION
* @return null if no error occur r ed, else a String to put into LOCATION
* /
* /
private static String addBlacklistEntry (
private static String addBlacklistEntry (
final String blacklistToUse ,
final String blacklistToUse ,
final String newEntry ,
final String newEntry ,
final RequestHeader header ,
final RequestHeader header ,
final String [ ] supportedBlacklistTypes ) {
final BlacklistType [ ] supportedBlacklistTypes ) {
if ( blacklistToUse = = null | | blacklistToUse . length ( ) = = 0 ) {
if ( blacklistToUse = = null | | blacklistToUse . length ( ) = = 0 ) {
return "" ;
return "" ;
@ -555,7 +552,7 @@ public class Blacklist_p {
final String blacklistToUse ,
final String blacklistToUse ,
final String oldEntry ,
final String oldEntry ,
final RequestHeader header ,
final RequestHeader header ,
final String [ ] supportedBlacklistTypes ) {
final BlacklistType [ ] supportedBlacklistTypes ) {
if ( blacklistToUse = = null | | blacklistToUse . length ( ) = = 0 ) {
if ( blacklistToUse = = null | | blacklistToUse . length ( ) = = 0 ) {
return "" ;
return "" ;
@ -580,7 +577,7 @@ public class Blacklist_p {
final File listsPath ,
final File listsPath ,
final String blacklistToUse ,
final String blacklistToUse ,
String oldEntry ,
String oldEntry ,
final String [ ] supportedBlacklistTypes ) {
final BlacklistType [ ] supportedBlacklistTypes ) {
// load blacklist data from file
// load blacklist data from file
final List < String > list = FileUtils . getListArray ( new File ( listsPath , blacklistToUse ) ) ;
final List < String > list = FileUtils . getListArray ( new File ( listsPath , blacklistToUse ) ) ;
@ -603,7 +600,7 @@ public class Blacklist_p {
pos = oldEntry . length ( ) ;
pos = oldEntry . length ( ) ;
oldEntry = oldEntry + "/.*" ;
oldEntry = oldEntry + "/.*" ;
}
}
for ( final String supportedBlacklistType : supportedBlacklistTypes ) {
for ( final BlacklistType supportedBlacklistType : supportedBlacklistTypes ) {
if ( ListManager . listSetContains ( supportedBlacklistType + ".BlackLists" , blacklistToUse ) ) {
if ( ListManager . listSetContains ( supportedBlacklistType + ".BlackLists" , blacklistToUse ) ) {
Switchboard . urlBlacklist . remove ( supportedBlacklistType , oldEntry . substring ( 0 , pos ) , oldEntry . substring ( pos + 1 ) ) ;
Switchboard . urlBlacklist . remove ( supportedBlacklistType , oldEntry . substring ( 0 , pos ) , oldEntry . substring ( pos + 1 ) ) ;
}
}
@ -622,7 +619,7 @@ public class Blacklist_p {
final File listsPath ,
final File listsPath ,
final String blacklistToUse ,
final String blacklistToUse ,
String newEntry ,
String newEntry ,
final String [ ] supportedBlacklistTypes ) {
final BlacklistType [ ] supportedBlacklistTypes ) {
// ignore empty entries
// ignore empty entries
if ( newEntry = = null | | newEntry . isEmpty ( ) ) {
if ( newEntry = = null | | newEntry . isEmpty ( ) ) {
@ -659,7 +656,7 @@ public class Blacklist_p {
final File listsPath ,
final File listsPath ,
final String blacklistToUse ,
final String blacklistToUse ,
String newEntry ,
String newEntry ,
final String [ ] supportedBlacklistTypes ) {
final BlacklistType [ ] supportedBlacklistTypes ) {
if ( ! Blacklist . blacklistFileContains ( listsPath , blacklistToUse , newEntry ) ) {
if ( ! Blacklist . blacklistFileContains ( listsPath , blacklistToUse , newEntry ) ) {
// append the line to the file
// append the line to the file
@ -683,7 +680,7 @@ public class Blacklist_p {
// add to blacklist
// add to blacklist
int pos = newEntry . indexOf ( '/' , 0 ) ;
int pos = newEntry . indexOf ( '/' , 0 ) ;
for ( final String supportedBlacklistType : supportedBlacklistTypes ) {
for ( final BlacklistType supportedBlacklistType : supportedBlacklistTypes ) {
if ( ListManager . listSetContains ( supportedBlacklistType + ".BlackLists" , blacklistToUse ) ) {
if ( ListManager . listSetContains ( supportedBlacklistType + ".BlackLists" , blacklistToUse ) ) {
Switchboard . urlBlacklist . add ( supportedBlacklistType , newEntry . substring ( 0 , pos ) , newEntry . substring ( pos + 1 ) ) ;
Switchboard . urlBlacklist . add ( supportedBlacklistType , newEntry . substring ( 0 , pos ) , newEntry . substring ( pos + 1 ) ) ;
}
}