Skip to content

Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance

- added new property setting 'repositoryPath' which can be used to map any path to http://localhost:8080/repository/ This can be used to do an intranet-indexing without the setting of symbolic links - which does not work in Windows environment. Now also Windows users can index their file system easily using the intranet use case. - fixed some problems with the identification of the alternative path in DATA/HTDOCS in the httpd file server

orbiterfe77fc3d62e1
diff --git a/defaults/yacy.init b/defaults/yacy.init
index 591790fc5..bec584163 100644
--- a/defaults/yacy.init
+++ b/defaults/yacy.init
@@ -162,15 +162,23 @@ htTemplatePath = htroot/env/templates
htDefaultPath=htroot
# individual htroot folder
-# every user may publicise her/his own web pages
+# every user may publicize her/his own web pages
# these pages shall be placed in the path defined here
# the htdocs path shares its content with the htroot path
htDocsPath = DATA/HTDOCS
+# alternative path for the repository path of the web server: the URL
+# http://localhost:8080/repository
+# points to DATA/HTDOCS/repository, but can be altered with this repository path
+# hint: the repository path is the default path for intranet indexing. The easiest ways
+# to do a indexing of the local storage system is to set a path here for the repository
+# that points to the root path of the files that shall be indexed
+repositoryPath=DATA/HTDOCS/repository
+
# the default files (typically index.html), if no file name is given
# The complete path to this file is created by combination with the rootPath
# you can set a list of defaults, separated by comma
-# the first one is priorized
+# the first one is preferred
defaultFiles = ConfigBasic.html,index.html,index.htm,default.html,search.html,console.html,control.html,welcome.html,wiki.html,forum.html,blog.html,email.html,content.html,monitor.html,share.html,dir.html,readme.txt
# locale-options: YaCy supports localization.
diff --git a/source/de/anomic/http/httpdFileHandler.java b/source/de/anomic/http/httpdFileHandler.java
index 1b60fe289..49ea7e677 100644
--- a/source/de/anomic/http/httpdFileHandler.java
+++ b/source/de/anomic/http/httpdFileHandler.java
@@ -202,35 +202,22 @@ public final class httpdFileHandler {
* @param path relative from htroot
* @param localeSelection language of localized file; locale.language from switchboard is used if localeSelection.equals("") */
public static File getLocalizedFile(final String path, final String localeSelection){
- if (htDefaultPath == null) htDefaultPath = switchboard.getConfigPath("htDefaultPath","htroot");
- if (htLocalePath == null) htLocalePath = switchboard.getConfigPath("locale.translated_html","DATA/LOCALE/htroot");
+ //if (htDefaultPath == null) htDefaultPath = switchboard.getConfigPath("htDefaultPath", "htroot");
+ //if (htLocalePath == null) htLocalePath = switchboard.getConfigPath("locale.translated_html", "DATA/LOCALE/htroot");
+ //if (htDocsPath == null) htDocsPath = switchboard.getConfigPath(plasmaSwitchboardConstants.HTDOCS_PATH, plasmaSwitchboardConstants.HTDOCS_PATH_DEFAULT);
+ if (path.startsWith("/repository/"))
+ return new File(switchboard.getConfig("repositoryPath", "DATA/HTDOCS/repository"), path.substring(11));
if (!(localeSelection.equals("default"))) {
final File localePath = new File(htLocalePath, localeSelection + '/' + path);
- if (localePath.exists()) // avoid "NoSuchFile" troubles if the "localeSelection" is misspelled
- return localePath;
+ if (localePath.exists()) return localePath; // avoid "NoSuchFile" troubles if the "localeSelection" is misspelled
}
+
+ File docsPath = new File(htDocsPath, path);
+ if (docsPath.exists()) return docsPath;
return new File(htDefaultPath, path);
}
-// private void textMessage(OutputStream out, int retcode, String body) throws IOException {
-// httpd.sendRespondHeader(
-// this.connectionProperties, // the connection properties
-// out, // the output stream
-// "HTTP/1.1", // the http version that should be used
-// retcode, // the http status code
-// null, // the http status message
-// "text/plain", // the mimetype
-// body.length(), // the content length
-// httpc.nowDate(), // the modification date
-// null, // the expires date
-// null, // cookies
-// null, // content encoding
-// null); // transfer encoding
-// out.write(body.getBytes());
-// out.flush();
-// }
-
private static final httpResponseHeader getDefaultHeaders(final String path) {
final httpResponseHeader headers = new httpResponseHeader();
String ext;
@@ -412,7 +399,7 @@ public final class httpdFileHandler {
File targetClass=null;
// locate the file
- if (!(path.startsWith("/"))) path = "/" + path; // attach leading slash
+ if (!path.startsWith("/") && !path.startsWith("\\")) path = "/" + path; // attach leading slash
// a different language can be desired (by i.e. ConfigBasic.html) than the one stored in the locale.language
String localeSelection = switchboard.getConfig("locale.language","default");
@@ -426,9 +413,9 @@ public final class httpdFileHandler {
}
File targetFile = getLocalizedFile(path, localeSelection);
- final String targetExt = conProp.getProperty("EXT","");
+ final String targetExt = conProp.getProperty("EXT","");
targetClass = rewriteClassFile(new File(htDefaultPath, path));
- if (path.endsWith("/")) {
+ if (path.endsWith("/") || path.endsWith("\\")) {
String testpath;
// attach default file name
for (int i = 0; i < defaultFiles.length; i++) {
@@ -440,13 +427,13 @@ public final class httpdFileHandler {
break;
}
}
+ targetFile = getLocalizedFile(path, localeSelection);
//no defaultfile, send a dirlisting
- if (targetFile == null || !targetFile.exists()) {
+ if (targetFile == null || !targetFile.exists() || (targetFile.exists() && targetFile.isDirectory())) {
final StringBuilder aBuffer = new StringBuilder();
aBuffer.append("<html>\n<head>\n</head>\n<body>\n<h1>Index of " + path + "</h1>\n <ul>\n");
- final File dir = new File(htDocsPath, path);
- String[] list = dir.list();
+ String[] list = targetFile.list();
if (list == null) list = new String[0]; // should not occur!
File f;
String size;
@@ -455,7 +442,7 @@ public final class httpdFileHandler {
int images, links;
htmlFilterContentScraper scraper;
for (int i = 0; i < list.length; i++) {
- f = new File(dir, list[i]);
+ f = new File(targetFile, list[i]);
if (f.isDirectory()) {
aBuffer.append(" <li><a href=\"" + path + list[i] + "/\">" + list[i] + "/</a><br></li>\n");
} else {
@@ -492,7 +479,7 @@ public final class httpdFileHandler {
aBuffer.append(" </ul>\n</body>\n</html>\n");
// write the list to the client
- httpd.sendRespondHeader(conProp, out, httpVersion, 200, null, "text/html; charset=UTF-8", aBuffer.length(), new Date(dir.lastModified()), null, new httpResponseHeader(), null, null, true);
+ httpd.sendRespondHeader(conProp, out, httpVersion, 200, null, "text/html; charset=UTF-8", aBuffer.length(), new Date(targetFile.lastModified()), null, new httpResponseHeader(), null, null, true);
if (!method.equals(httpHeader.METHOD_HEAD)) {
out.write(aBuffer.toString().getBytes("UTF-8"));
}
@@ -724,7 +711,7 @@ public final class httpdFileHandler {
/* servletProperties tp = (servlerObjects) */ invokeServlet(targetClass, requestHeader, args);
forceConnectionClose(conProp);
return;
- } else if ((targetFile.exists()) && (targetFile.canRead())) {
+ } else if (targetFile.exists() && targetFile.isFile() && targetFile.canRead()) {
// we have found a file that can be written to the client
// if this file uses templates, then we use the template
// re-write - method to create an result