|
|
@ -3,7 +3,10 @@
|
|
|
|
// part of YACY
|
|
|
|
// part of YACY
|
|
|
|
// (C) by Michael Peter Christen; mc@anomic.de
|
|
|
|
// (C) by Michael Peter Christen; mc@anomic.de
|
|
|
|
// first published on http://www.anomic.de
|
|
|
|
// first published on http://www.anomic.de
|
|
|
|
// Frankfurt, Germany, 2004
|
|
|
|
//
|
|
|
|
|
|
|
|
// $LastChangedDate$
|
|
|
|
|
|
|
|
// $LastChangedRevision$
|
|
|
|
|
|
|
|
// $LastChangedBy$
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// This file ist contributed by Alexander Schier
|
|
|
|
// This file ist contributed by Alexander Schier
|
|
|
|
// last major change: 09.08.2004
|
|
|
|
// last major change: 09.08.2004
|
|
|
@ -53,190 +56,191 @@ import java.io.InputStreamReader;
|
|
|
|
import java.io.PrintWriter;
|
|
|
|
import java.io.PrintWriter;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Iterator;
|
|
|
|
import java.util.Iterator;
|
|
|
|
|
|
|
|
|
|
|
|
import de.anomic.plasma.plasmaSwitchboard;
|
|
|
|
import de.anomic.plasma.plasmaSwitchboard;
|
|
|
|
import de.anomic.server.serverCore;
|
|
|
|
import de.anomic.server.serverCore;
|
|
|
|
|
|
|
|
|
|
|
|
//The Naming of the functions is a bit strange...
|
|
|
|
// The Naming of the functions is a bit strange...
|
|
|
|
|
|
|
|
|
|
|
|
public class listManager {
|
|
|
|
public class listManager {
|
|
|
|
public static plasmaSwitchboard switchboard;
|
|
|
|
public static plasmaSwitchboard switchboard;
|
|
|
|
public static File listsPath;
|
|
|
|
public static File listsPath;
|
|
|
|
|
|
|
|
|
|
|
|
//===============Listslists=====================
|
|
|
|
//===============Listslists=====================
|
|
|
|
//get an array of all Lists from a Config Property
|
|
|
|
// get an array of all Lists from a Config Property
|
|
|
|
public static String[] getListslistArray(String Listname){
|
|
|
|
public static String[] getListslistArray(String Listname) {
|
|
|
|
return switchboard.getConfig(Listname, "").split(",");
|
|
|
|
return switchboard.getConfig(Listname, "").split(",");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//removes a List from a Lists-List
|
|
|
|
// removes a List from a Lists-List
|
|
|
|
public static void removeListFromListslist(String ListName, String BlackList){
|
|
|
|
public static void removeListFromListslist(String ListName, String BlackList) {
|
|
|
|
String[] Lists = getListslistArray(ListName);
|
|
|
|
String[] Lists = getListslistArray(ListName);
|
|
|
|
String temp = "";
|
|
|
|
String temp = "";
|
|
|
|
|
|
|
|
|
|
|
|
for(int i=0;i <= Lists.length -1;i++){
|
|
|
|
for (int i=0; i <= Lists.length -1; i++) {
|
|
|
|
if( !Lists[i].equals(BlackList) && !Lists[i].equals("") ){
|
|
|
|
if (!Lists[i].equals(BlackList) && !Lists[i].equals("")) {
|
|
|
|
temp += Lists[i] + ",";
|
|
|
|
temp += Lists[i] + ",";
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if( temp.endsWith(",") ){ //remove "," at end...
|
|
|
|
|
|
|
|
temp = temp.substring(0, temp.length() -1);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if( temp.startsWith(",") ){ //remove "," at end...
|
|
|
|
|
|
|
|
temp = temp.substring(1, temp.length() );
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
switchboard.setConfig(ListName, temp);
|
|
|
|
if (temp.endsWith(",")) { //remove "," at end...
|
|
|
|
|
|
|
|
temp = temp.substring(0, temp.length() -1);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (temp.startsWith(",") ) { //remove "," at end...
|
|
|
|
|
|
|
|
temp = temp.substring(1, temp.length());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
switchboard.setConfig(ListName, temp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//add a new List to a List-List
|
|
|
|
// add a new List to a List-List
|
|
|
|
public static void addListToListslist(String ListName, String newList){
|
|
|
|
public static void addListToListslist(String ListName, String newList) {
|
|
|
|
String[] Lists = getListslistArray(ListName);
|
|
|
|
String[] Lists = getListslistArray(ListName);
|
|
|
|
String temp = "";
|
|
|
|
String temp = "";
|
|
|
|
|
|
|
|
|
|
|
|
for(int i = 0;i <= (Lists.length -1); i++){
|
|
|
|
for (int i = 0; i <= (Lists.length -1); i++) {
|
|
|
|
temp += Lists[i] + ",";
|
|
|
|
temp += Lists[i] + ",";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
temp += newList;
|
|
|
|
temp += newList;
|
|
|
|
switchboard.setConfig(ListName, temp);
|
|
|
|
switchboard.setConfig(ListName, temp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//returns true, if the Lists-List contains the Listname
|
|
|
|
// returns true, if the Lists-List contains the Listname
|
|
|
|
public static boolean ListInListslist(String Listname, String BlackList){
|
|
|
|
public static boolean ListInListslist(String Listname, String BlackList) {
|
|
|
|
String[] Lists = getListslistArray(Listname);
|
|
|
|
String[] Lists = getListslistArray(Listname);
|
|
|
|
|
|
|
|
|
|
|
|
for(int u=0;u <= Lists.length -1;u++){
|
|
|
|
for (int u=0; u <= Lists.length -1; u++) {
|
|
|
|
if( BlackList.equals(Lists[u]) ){
|
|
|
|
if (BlackList.equals(Lists[u])) {
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//================generel Lists==================
|
|
|
|
//================generel Lists==================
|
|
|
|
|
|
|
|
|
|
|
|
//Gets a Array of all lines(Items) of a (list)file
|
|
|
|
// Gets a Array of all lines(Items) of a (list)file
|
|
|
|
public static ArrayList getListArray(File listFile){
|
|
|
|
public static ArrayList getListArray(File listFile){
|
|
|
|
String line;
|
|
|
|
String line;
|
|
|
|
ArrayList list = new ArrayList();
|
|
|
|
ArrayList list = new ArrayList();
|
|
|
|
int count = 0;
|
|
|
|
int count = 0;
|
|
|
|
BufferedReader br = null;
|
|
|
|
BufferedReader br = null;
|
|
|
|
try{
|
|
|
|
try {
|
|
|
|
br = new BufferedReader(new InputStreamReader(new FileInputStream(listFile)));
|
|
|
|
br = new BufferedReader(new InputStreamReader(new FileInputStream(listFile)));
|
|
|
|
|
|
|
|
|
|
|
|
while( (line = br.readLine()) != null){
|
|
|
|
while((line = br.readLine()) != null){
|
|
|
|
list.add(line);
|
|
|
|
list.add(line);
|
|
|
|
count++;
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
br.close();
|
|
|
|
br.close();
|
|
|
|
}catch(IOException e){
|
|
|
|
} catch(IOException e) {
|
|
|
|
//list is empty
|
|
|
|
// list is empty
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
if (br!=null)try{br.close();}catch(Exception e) {}
|
|
|
|
if (br!=null) try { br.close(); } catch (Exception e) {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return list;
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//Writes the Liststring to a file
|
|
|
|
// Writes the Liststring to a file
|
|
|
|
public static boolean writeList(File listFile, String out){
|
|
|
|
public static boolean writeList(File listFile, String out) {
|
|
|
|
BufferedWriter bw = null;
|
|
|
|
BufferedWriter bw = null;
|
|
|
|
try{
|
|
|
|
try {
|
|
|
|
bw = new BufferedWriter(new PrintWriter(new FileWriter(listFile)));
|
|
|
|
bw = new BufferedWriter(new PrintWriter(new FileWriter(listFile)));
|
|
|
|
bw.write(out);
|
|
|
|
bw.write(out);
|
|
|
|
bw.close();
|
|
|
|
bw.close();
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}catch(IOException e){
|
|
|
|
} catch(IOException e) {
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
if (bw!=null)try{bw.close();}catch(Exception e){}
|
|
|
|
if (bw!=null) try { bw.close(); } catch (Exception e) {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//overloaded function to write an array
|
|
|
|
// overloaded function to write an array
|
|
|
|
public static boolean writeList(File listFile, String[] list){
|
|
|
|
public static boolean writeList(File listFile, String[] list){
|
|
|
|
String out = "";
|
|
|
|
String out = "";
|
|
|
|
for(int i=0;i <= list.length; i++){
|
|
|
|
for(int i=0;i <= list.length; i++){
|
|
|
|
out += list[i] + serverCore.crlfString;
|
|
|
|
out += list[i] + serverCore.crlfString;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return writeList(listFile, out); //(File, String)
|
|
|
|
return writeList(listFile, out); //(File, String)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static String getListString(String filename, boolean withcomments){
|
|
|
|
public static String getListString(String filename, boolean withcomments){
|
|
|
|
String temp = "";
|
|
|
|
String temp = "";
|
|
|
|
String line = "";
|
|
|
|
String line = "";
|
|
|
|
BufferedReader br = null;
|
|
|
|
BufferedReader br = null;
|
|
|
|
try{
|
|
|
|
try{
|
|
|
|
br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(listsPath ,filename))));
|
|
|
|
br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(listsPath ,filename))));
|
|
|
|
//Read the List
|
|
|
|
// Read the List
|
|
|
|
while((line = br.readLine()) != null){
|
|
|
|
while ((line = br.readLine()) != null) {
|
|
|
|
if( (!line.startsWith("#") || withcomments) || (!line.equals("")) ){
|
|
|
|
if ((!line.startsWith("#") || withcomments) || !line.equals("")) {
|
|
|
|
temp += line + serverCore.crlfString;
|
|
|
|
temp += line + serverCore.crlfString;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
br.close();
|
|
|
|
br.close();
|
|
|
|
} catch(IOException e){
|
|
|
|
} catch (IOException e) {
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
if (br!=null)try{br.close();}catch(Exception e){}
|
|
|
|
if (br!=null) try { br.close(); } catch (Exception e) {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return temp;
|
|
|
|
return temp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//get a Directory Listing as a String Array
|
|
|
|
// get a Directory Listing as a String Array
|
|
|
|
public static String[] getDirListing(String dirname){
|
|
|
|
public static String[] getDirListing(String dirname){
|
|
|
|
String[] fileListString;
|
|
|
|
String[] fileListString;
|
|
|
|
File[] fileList;
|
|
|
|
File[] fileList;
|
|
|
|
File dir = new File(dirname);
|
|
|
|
final File dir = new File(dirname);
|
|
|
|
|
|
|
|
|
|
|
|
if(dir != null){
|
|
|
|
if (dir != null ) {
|
|
|
|
if(!dir.exists()){
|
|
|
|
if (!dir.exists()) {
|
|
|
|
dir.mkdir();
|
|
|
|
dir.mkdir();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fileList = dir.listFiles();
|
|
|
|
fileList = dir.listFiles();
|
|
|
|
fileListString = new String[fileList.length];
|
|
|
|
fileListString = new String[fileList.length];
|
|
|
|
for(int i=0;i<= fileList.length-1;i++){
|
|
|
|
for (int i=0; i<= fileList.length-1; i++) {
|
|
|
|
fileListString[i]=fileList[i].getName();
|
|
|
|
fileListString[i]=fileList[i].getName();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return fileListString;
|
|
|
|
return fileListString;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static ArrayList getDirsRecursive(File dir){
|
|
|
|
public static ArrayList getDirsRecursive(File dir){
|
|
|
|
return getDirsRecursive(dir, true);
|
|
|
|
return getDirsRecursive(dir, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Returns a List of all dirs and subdirs as File Objects
|
|
|
|
* Returns a List of all dirs and subdirs as File Objects
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Warning: untested
|
|
|
|
* Warning: untested
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public static ArrayList getDirsRecursive(File dir, boolean excludeDotfiles){
|
|
|
|
public static ArrayList getDirsRecursive(File dir, boolean excludeDotfiles){
|
|
|
|
File[] dirList = dir.listFiles();
|
|
|
|
final File[] dirList = dir.listFiles();
|
|
|
|
ArrayList resultList = new ArrayList();
|
|
|
|
final ArrayList resultList = new ArrayList();
|
|
|
|
ArrayList recursive;
|
|
|
|
ArrayList recursive;
|
|
|
|
Iterator it;
|
|
|
|
Iterator iter;
|
|
|
|
for(int i=0;i<dirList.length;i++){
|
|
|
|
for (int i=0;i<dirList.length;i++) {
|
|
|
|
if(dirList[i].isDirectory() && (!excludeDotfiles || !dirList[i].getName().startsWith(".")) ){
|
|
|
|
if (dirList[i].isDirectory() && (!excludeDotfiles || !dirList[i].getName().startsWith("."))) {
|
|
|
|
resultList.add(dirList[i]);
|
|
|
|
resultList.add(dirList[i]);
|
|
|
|
recursive = getDirsRecursive(dirList[i]);
|
|
|
|
recursive = getDirsRecursive(dirList[i]);
|
|
|
|
it=recursive.iterator();
|
|
|
|
iter=recursive.iterator();
|
|
|
|
while(it.hasNext()){
|
|
|
|
while (iter.hasNext()) {
|
|
|
|
resultList.add(it.next());
|
|
|
|
resultList.add(iter.next());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return resultList;
|
|
|
|
return resultList;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//=============Blacklist specific================
|
|
|
|
//=============Blacklist specific================
|
|
|
|
|
|
|
|
|
|
|
|
//load all active Blacklists in the Proxy
|
|
|
|
// load all active Blacklists in the Proxy
|
|
|
|
public static void reloadBlacklists(){
|
|
|
|
public static void reloadBlacklists(){
|
|
|
|
String f = switchboard.getConfig("proxyBlackListsActive", "");
|
|
|
|
final String f = switchboard.getConfig("proxyBlackListsActive", "");
|
|
|
|
switchboard.urlBlacklist.clear();
|
|
|
|
de.anomic.plasma.plasmaSwitchboard.urlBlacklist.clear();
|
|
|
|
if (f != "") switchboard.urlBlacklist.loadLists("black", f, "/");
|
|
|
|
if (f != "") {
|
|
|
|
}
|
|
|
|
de.anomic.plasma.plasmaSwitchboard.urlBlacklist.loadLists("black", f, "/");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// switchboard.urlBlacklist.clear();
|
|
|
|
|
|
|
|
// if (f != "") switchboard.urlBlacklist.loadLists("black", f, "/");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|