*) adding transparent proxy support

Now a firewall can transparently redirect all 
   http traffic through yacy.
   

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@96 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
theli 20 years ago
parent 92a65874d6
commit 74f12bb0f3

@ -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>

@ -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

@ -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.</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>

@ -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;

@ -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

@ -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;

@ -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;
}

Loading…
Cancel
Save