Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance
Java decentralizedintranet-searchintranet-search-enginep2pp2p-networkprivacyprivacy-protectionsearch-enginesearchenginewebweb-search-enginewebsearchwebseearch-engine
*) adding transparent proxy support Now a firewall can transparently redirect all http traffic through yacy.
theli74f12bb0f307
diff --git a/htroot/SettingsAck_p.html b/htroot/SettingsAck_p.htmlindex 1d7ed9c14..342d92767 100644--- a/htroot/SettingsAck_p.html+++ b/htroot/SettingsAck_p.html@@ -47,8 +47,9 @@ Auto pop-up of the Status page is now <b>enabled</b><br>::You are now permanently <b>online</b>. After a short while you should see the effect on the <a href="Status.html">status</a> page.<br>::-<b>Port is: #[port]#</b><br>-<b>PeerName is: #[peerName]#</b><br>+<b>Port is: <font color="#556699">#[port]#</font></b><br>+<b>PeerName is: <font color="#556699">#[peerName]#</font></b><br>+<b>Transparent Proxy Support is: <font color="#556699">#[isTransparentProxy]#</font></b><p><u>if you changed the Port, you need to restart the Proxy.</u>::<b>SeedFTP Server Settings changed. You are now a principal peer.</b><br>diff --git a/htroot/SettingsAck_p.java b/htroot/SettingsAck_p.javaindex 143c7defc..a2f3ddb3a 100644--- a/htroot/SettingsAck_p.java+++ b/htroot/SettingsAck_p.java@@ -194,11 +194,12 @@ public class SettingsAck_p {if (post.containsKey("generalsettings")) {String port = (String) post.get("port");String peerName = (String) post.get("peername");+ httpdProxyHandler.isTransparentProxy = post.get("isTransparentProxy", "").equals("on");// check if peer name already existsyacySeed oldSeed = yacyCore.seedDB.lookupByName(peerName);- if (oldSeed == null) {+ if ((oldSeed == null) || (env.getConfig("peerName","").equals(peerName))) {// the name is newboolean nameOK = (peerName.length() <= 80);for (int i = 0; i < peerName.length(); i++) {@@ -212,10 +213,12 @@ public class SettingsAck_p {// set valuesenv.setConfig("port", port);env.setConfig("peerName", peerName);+ env.setConfig("isTransparentProxy", httpdProxyHandler.isTransparentProxy ? "true" : "false");prop.put("info", 12);//port or peername changedprop.put("info_port", port);prop.put("info_peerName", peerName);+ prop.put("info_isTransparentProxy", httpdProxyHandler.isTransparentProxy ? "on" : "off");}} else {// deny changediff --git a/htroot/Settings_p.html b/htroot/Settings_p.htmlindex cfde67205..d6d42ae3c 100644--- a/htroot/Settings_p.html+++ b/htroot/Settings_p.html@@ -44,6 +44,11 @@ delete the file 'DATA/SETTINGS/httpProxy.conf' in the YaCy application root foldUsing your 'Home Page' and 'File Share' - zones you also have a platform to provide content to your new domain.</b><br><i>(hint: choose a name that appears on a web page that tells something about you, vistit the page, get the 'senior' status, and you can be found..)</i></td></tr>+ <tr valign="top">+ <td>Use as Transparent Proxy:</td>+ <td><input type="checkbox" name="isTransparentProxy" align="top" #(isTransparentProxy)#::checked#(/isTransparentProxy)#></td>+ <td>With this you can specify if YaCy can be used as transparent proxy.</td>+ </tr><tr><td><input type="submit" name="generalsettings" value="submit"></td><td></td>diff --git a/htroot/Settings_p.java b/htroot/Settings_p.javaindex 37fd96911..1ac92904b 100644--- a/htroot/Settings_p.java+++ b/htroot/Settings_p.java@@ -64,6 +64,8 @@ public class Settings_p {prop.put("port", env.getConfig("port", "8080"));prop.put("peerName", env.getConfig("peerName", "nameless"));+ prop.put("isTransparentProxy", env.getConfig("isTransparentProxy", "false").equals("true") ? 1 : 0);+// set valuesString s;int pos;diff --git a/source/de/anomic/http/httpd.java b/source/de/anomic/http/httpd.javaindex faaa9e2b4..6b3443ad8 100644--- a/source/de/anomic/http/httpd.java+++ b/source/de/anomic/http/httpd.java@@ -53,7 +53,10 @@ import java.io.IOException;import java.io.InputStream;import java.io.PushbackInputStream;import java.net.InetAddress;+import java.net.NetworkInterface;+import java.util.Arrays;import java.util.HashMap;+import java.util.HashSet;import java.util.Properties;import java.util.Set;import java.util.StringTokenizer;@@ -206,10 +209,30 @@ public final class httpd implements serverHandler {// we now know the HTTP version. depending on that, we read the headerhttpHeader header;String httpVersion = prop.getProperty("HTTP", "HTTP/0.9");- if (httpVersion.equals("HTTP/0.9"))+ if (httpVersion.equals("HTTP/0.9")) {header = new httpHeader(reverseMappingCache);- else+ } else {header = readHeader();+ if ((httpdProxyHandler.isTransparentProxy) && header.containsKey("HOST")){+ Integer dstPort;+ String dstHost = (String) header.get("HOST");++ int idx = dstHost.indexOf(":");+ if (idx != -1) {+ dstPort = Integer.valueOf(dstHost.substring(idx+1));+ dstHost = dstHost.substring(0,idx);+ } else {+ dstPort = new Integer(80);+ }++ if (dstPort.intValue() == 80) {+ InetAddress dstHostAddress = InetAddress.getByName(dstHost);+ if (!(dstHostAddress.isAnyLocalAddress() || dstHostAddress.isLoopbackAddress())) {+ this.prop.setProperty("HOST",dstHost);+ }+ }+ }+ }// managing keep-alive: in HTTP/0.9 and HTTP/1.0 every connection is closed// afterwards. In HTTP/1.1 (and above, in the future?) connections arediff --git a/source/de/anomic/http/httpdProxyHandler.java b/source/de/anomic/http/httpdProxyHandler.javaindex b4286df38..699018049 100644--- a/source/de/anomic/http/httpdProxyHandler.java+++ b/source/de/anomic/http/httpdProxyHandler.java@@ -105,6 +105,9 @@ public final class httpdProxyHandler extends httpdAbstractHandler implements httpublic static TreeMap blackListURLs = null;private static int timeout = 30000;private static boolean yacyTrigger = true;++ public static boolean isTransparentProxy = false;+public static boolean remoteProxyUse = false;public static String remoteProxyHost = "";public static int remoteProxyPort = -1;@@ -112,6 +115,8 @@ public final class httpdProxyHandler extends httpdAbstractHandler implements httpublic static String[] remoteProxyNoProxyPatterns = null;private static final HashSet remoteProxyAllowProxySet = new HashSet();private static final HashSet remoteProxyDisallowProxySet = new HashSet();++private static htmlFilterTransformer transformer = null;public static final String userAgent = "yacy (" + httpc.systemOST +") yacy.net";private File htRootPath = null;diff --git a/source/de/anomic/server/serverFileUtils.java b/source/de/anomic/server/serverFileUtils.javaindex f5c12d3da..b4da479d0 100644--- a/source/de/anomic/server/serverFileUtils.java+++ b/source/de/anomic/server/serverFileUtils.java@@ -101,13 +101,13 @@ public final class serverFileUtils {public static byte[] read(File source) throws IOException {byte[] buffer = new byte[(int) source.length()];InputStream fis = null;- try {- fis = new FileInputStream(source);+ try {+ fis = new FileInputStream(source);int p = 0, c;while ((c = fis.read(buffer, p, buffer.length - p)) > 0) p += c;- } finally {+ } finally {if (fis != null) try { fis.close(); } catch (Exception e) {}- }+ }return buffer;}