diff --git a/htroot/SettingsAck_p.html b/htroot/SettingsAck_p.html index 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 enabled
:: You are now permanently online. After a short while you should see the effect on the status page.
:: -Port is: #[port]#
-PeerName is: #[peerName]#
+Port is: #[port]#
+PeerName is: #[peerName]#
+Transparent Proxy Support is: #[isTransparentProxy]#

if you changed the Port, you need to restart the Proxy. :: SeedFTP Server Settings changed. You are now a principal peer.
diff --git a/htroot/SettingsAck_p.java b/htroot/SettingsAck_p.java index 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 exists yacySeed oldSeed = yacyCore.seedDB.lookupByName(peerName); - if (oldSeed == null) { + if ((oldSeed == null) || (env.getConfig("peerName","").equals(peerName))) { // the name is new boolean nameOK = (peerName.length() <= 80); for (int i = 0; i < peerName.length(); i++) { @@ -212,10 +213,12 @@ public class SettingsAck_p { // set values env.setConfig("port", port); env.setConfig("peerName", peerName); + env.setConfig("isTransparentProxy", httpdProxyHandler.isTransparentProxy ? "true" : "false"); prop.put("info", 12);//port or peername changed prop.put("info_port", port); prop.put("info_peerName", peerName); + prop.put("info_isTransparentProxy", httpdProxyHandler.isTransparentProxy ? "on" : "off"); } } else { // deny change diff --git a/htroot/Settings_p.html b/htroot/Settings_p.html index 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 fold Using your 'Home Page' and 'File Share' - zones you also have a platform to provide content to your new domain.
(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..) + + Use as Transparent Proxy: + + With this you can specify if YaCy can be used as transparent proxy. + diff --git a/htroot/Settings_p.java b/htroot/Settings_p.java index 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 values String s; int pos; diff --git a/source/de/anomic/http/httpd.java b/source/de/anomic/http/httpd.java index 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 header httpHeader 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 are diff --git a/source/de/anomic/http/httpdProxyHandler.java b/source/de/anomic/http/httpdProxyHandler.java index 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 htt public 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 htt public 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.java index 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; }