From c8a35a013077267da0cec88748b416355879d685 Mon Sep 17 00:00:00 2001
From: theli
Date: Wed, 12 Oct 2005 08:17:43 +0000
Subject: [PATCH] *) Adding new connection tracking page (currently only for
incoming connections) *) Displaying statistic for incoming connections on
status page *) Bugfix for Loop-Access Bug when trying to access the yacy page
while yacy is configured as proxy See:
http://www.yacy-forum.de/viewtopic.php?p=6826 *) Bugfix for Referer Bug
See: http://www.yacy-forum.de/viewtopic.php?p=11098#11098 *) Adding reverse
Name lookup for yacy-domain names (used by the connection tracking page)
git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@916 6c8d7289-2bf4-0310-a012-ef5d649a1542
---
htroot/Connections_p.html | 37 ++++
htroot/Connections_p.java | 167 ++++++++++++++++++
htroot/Status.java | 10 ++
htroot/Status_p.inc | 118 +++++++++----
source/de/anomic/http/httpHeader.java | 33 +---
source/de/anomic/http/httpd.java | 85 ++++++++-
.../de/anomic/plasma/plasmaCrawlStacker.java | 8 +-
.../de/anomic/plasma/plasmaSwitchboard.java | 10 +-
source/de/anomic/server/serverCore.java | 59 ++++++-
source/de/anomic/yacy/yacyPeerActions.java | 5 +
source/de/anomic/yacy/yacySeedDB.java | 107 +++++++++++
11 files changed, 568 insertions(+), 71 deletions(-)
create mode 100644 htroot/Connections_p.html
create mode 100644 htroot/Connections_p.java
diff --git a/htroot/Connections_p.html b/htroot/Connections_p.html
new file mode 100644
index 000000000..c3941206f
--- /dev/null
+++ b/htroot/Connections_p.html
@@ -0,0 +1,37 @@
+
+
+
+YaCy '#[clientname]#': Connection Tracking
+#[metas]#
+
+
+#[header]#
+Connection Tracking
+Showing #[numActiveRunning]# active connections, #[numActivePending]# pending connections from a max. of #[numMax]# allowed incoming connections.
+
-
-Protection |
-#(protection)#
-Your settings are _not_ protected! Please go to the settings page immediately and set an administration password.
-::
-Your settings are protected by a password.
-#(/protection)#
- |
-Proxy host | #[host]#:#[port]# |
-Port forwarding host | #(portForwarding)#not used::#[host]#:#[port]# (#(status)#broken::connected#(/status)#)#(/portForwarding)# |
-Remote proxy | #(remoteProxy)#not used::#[host]#:#[port]##(/remoteProxy)# |
-Auto-popup on start-up |
-#(popup)#
-Disabled. To enable this again please use the Settings page
-::
-Enabled. To disable this please use the Settings page
-#(/popup)#
- |
-Memory Usage |
-
-free: #[freeMemory]# | total: #[totalMemory]# | max: #[maxMemory]#
- |
-Traffic |
-Out: #[trafficIn]# | In: #[trafficOut]#
- |
-System Resources |
-Processors: #[processors]#
- |
-Indexing Queue | #[indexingQueueSize]# | #[indexingQueueMax]# |
-Loader Queue | #[loaderQueueSize]# | #[loaderQueueMax]# #(loaderPaused)#::(paused)#(/loaderPaused)# |
-Local Crawler Queue | Enqueued: #[localCrawlQueueSize]# | Pending: #[stackCrawlQueueSize]# |
-Remote Crawler Queue | #[remoteCrawlQueueSize]# |
+
+
+ System Resources |
+ Processors: #[processors]# |
+ |
+
+
+ Protection |
+
+ #(protection)#
+ Your settings are _not_ protected! Please go to the settings page immediately and set an administration password.
+ ::
+ Your settings are protected by a password.
+ #(/protection)#
+ |
+ |
+
+
+ Proxy host |
+ #[host]#:#[port]# |
+ |
+
+
+ Port forwarding host |
+ #(portForwarding)#not used::#[host]#:#[port]# (#(status)#broken::connected#(/status)#)#(/portForwarding)# |
+ |
+
+
+ Remote proxy |
+ #(remoteProxy)#not used::#[host]#:#[port]##(/remoteProxy)# |
+ |
+
+
+ Auto-popup on start-up |
+
+ #(popup)#
+ Disabled. To enable this again please use the Settings page
+ ::
+ Enabled. To disable this please use the Settings page
+ #(/popup)#
+ |
+ |
+
+
+ Memory Usage |
+
+ free: #[freeMemory]# | total: #[totalMemory]# | max: #[maxMemory]#
+ |
+ |
+
+
+ Traffic |
+ Out: #[trafficIn]# | In: #[trafficOut]# |
+ |
+
+
+ Connections Incoming |
+ Active: #[connectionsActive]# | Idle: #[connectionsIdle]# | Max: #[connectionsMax]# |
+ [Details] |
+
+
+ Indexing Queue |
+ #[indexingQueueSize]# | #[indexingQueueMax]# |
+ [Details] |
+
+
+ Loader Queue |
+ #[loaderQueueSize]# | #[loaderQueueMax]# #(loaderPaused)#::(paused)#(/loaderPaused)# |
+ [Details] |
+
+
+ Local Crawler Queue |
+ Enqueued: #[localCrawlQueueSize]# | Pending: #[stackCrawlQueueSize]# |
+ [Details] |
+
+
+ Remote Crawler Queue |
+ #[remoteCrawlQueueSize]# |
+ [Details] |
+
\ No newline at end of file
diff --git a/source/de/anomic/http/httpHeader.java b/source/de/anomic/http/httpHeader.java
index d086c6915..e45d0c533 100644
--- a/source/de/anomic/http/httpHeader.java
+++ b/source/de/anomic/http/httpHeader.java
@@ -541,7 +541,8 @@ public final class httpHeader extends TreeMap implements Map {
} else {
// THIS IS THE "GOOD" CASE
// a perfect formulated url
- prop.setProperty(httpHeader.CONNECTION_PROP_HOST, args.substring(0, sep));
+ String dstHostSocket = args.substring(0, sep);
+ prop.setProperty(httpHeader.CONNECTION_PROP_HOST, (httpd.isThisHostName(dstHostSocket)?virtualHost:dstHostSocket));
prop.setProperty(httpHeader.CONNECTION_PROP_PATH, args.substring(sep)); // yes, including beginning "/"
}
} else {
@@ -699,29 +700,11 @@ public final class httpHeader extends TreeMap implements Map {
// if the transparent proxy support was disabled, we have nothing todo here ...
if (!(isTransparentProxy && header.containsKey(HOST))) return;
- try {
- String dstHost, dstHostSocket = (String) header.get(HOST);
-
- int idx = dstHostSocket.indexOf(":");
- dstHost = (idx != -1) ? dstHostSocket.substring(0,idx).trim() : dstHostSocket.trim();
- Integer dstPort = (idx != -1) ? Integer.valueOf(dstHostSocket.substring(idx+1)) : new Integer(80);
-
- if (dstPort.intValue() == 80) {
- if (dstHost.endsWith(".yacy")) {
- // if this peer is accessed via its yacy domain name we need to set the
- // host property to virtualHost to redirect the request to the yacy server
- if (dstHost.endsWith(yacyCore.seedDB.mySeed.getName()+".yacy")) {
- prop.setProperty(CONNECTION_PROP_HOST,virtualHost);
- } else {
- prop.setProperty(CONNECTION_PROP_HOST,dstHostSocket);
- }
- } else {
- InetAddress dstHostAddress = InetAddress.getByName(dstHost);
- if (!(dstHostAddress.isAnyLocalAddress() || dstHostAddress.isLoopbackAddress())) {
- prop.setProperty(CONNECTION_PROP_HOST,dstHostSocket);
- }
- }
- }
- } catch (Exception e) {}
+ // we only need to do the transparent proxy support if the request URL didn't contain the hostname
+ // and therefor was set to virtualHost by function parseQuery()
+ if (!prop.getProperty(CONNECTION_PROP_HOST).equals(virtualHost)) return;
+
+ String dstHostSocket = (String) header.get(httpHeader.HOST);
+ prop.setProperty(CONNECTION_PROP_HOST,(httpd.isThisHostName(dstHostSocket)?virtualHost:dstHostSocket));
}
}
\ No newline at end of file
diff --git a/source/de/anomic/http/httpd.java b/source/de/anomic/http/httpd.java
index 0aab9bc74..c629f7a63 100644
--- a/source/de/anomic/http/httpd.java
+++ b/source/de/anomic/http/httpd.java
@@ -148,6 +148,10 @@ public final class httpd implements serverHandler {
keepAliveSupport = Boolean.valueOf(switchboard.getConfig("connectionKeepAliveSupport","false")).booleanValue();
}
+ public Properties getConProp() {
+ return this.prop;
+ }
+
/**
* Can be used to reset this {@link serverHandler} oject so that
* it can be reused for further connections
@@ -782,7 +786,7 @@ public final class httpd implements serverHandler {
}
// parsing post request bodies which are gzip content-encoded
} else {
- ByteArrayOutputStream bout = new ByteArrayOutputStream();
+ serverByteBuffer bout = new serverByteBuffer();
serverFileUtils.copy(in,bout);
buffer = bout.toByteArray();
bout.close(); bout = null;
@@ -1310,6 +1314,85 @@ public final class httpd implements serverHandler {
// httpHeader.CONNECTION_PROP_PROXY_RESPOND_STATUS
}
+ public static boolean isThisHostPortForwardingIP(String hostName) {
+ if ((hostName == null) || (hostName.length() == 0)) return false;
+ if ((!serverCore.portForwardingEnabled) || (serverCore.portForwarding == null)) return false;
+
+ boolean isThisHostIP = false;
+ try {
+ InetAddress hostAddress = InetAddress.getByName(hostName);
+ InetAddress forwardingAddress = InetAddress.getByName(serverCore.portForwarding.getHost());
+
+ if (hostAddress.equals(forwardingAddress)) return true;
+ } catch (Exception e) {}
+ return isThisHostIP;
+ }
+
+ public static boolean isThisHostIP(String hostName) {
+ if ((hostName == null) || (hostName.length() == 0)) return false;
+
+ boolean isThisHostIP = false;
+ try {
+ final InetAddress clientAddress = InetAddress.getByName(hostName);
+ if (clientAddress.isAnyLocalAddress() || clientAddress.isLoopbackAddress()) return true;
+
+ final InetAddress[] localAddress = InetAddress.getAllByName(InetAddress.getLocalHost().getHostName());
+ for (int i=0; i