Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance
Java decentralizedintranet-searchintranet-search-enginep2pp2p-networkprivacyprivacy-protectionsearch-enginesearchenginewebweb-search-enginewebsearchwebseearch-engine
*) adding support for upnp A new port forwarding method for upnp was added. If this method is enabled, yacy automatically determines an UPnP capable internet gateway and configures the gateway port forwarding settings properly.
theli6e676224d00a
diff --git a/addon/jsmooth/yacy.jsmooth b/addon/jsmooth/yacy.jsmoothindex da3748e03..a3e29c2f3 100644--- a/addon/jsmooth/yacy.jsmooth+++ b/addon/jsmooth/yacy.jsmooth@@ -22,7 +22,6 @@<classPath>..\..\libx\commons-logging.jar</classPath><classPath>..\..\libx\informa-0.6.0.jar</classPath><classPath>..\..\libx\jakarta-oro-2.0.7.jar</classPath>-<classPath>..\..\libx\javasvn.jar</classPath><classPath>..\..\libx\jaxrpc.jar</classPath><classPath>..\..\libx\jdom.jar</classPath><classPath>..\..\libx\jmimemagic-0.0.4a.jar</classPath>diff --git a/build.xml b/build.xmlindex e612cdb37..5574eeedd 100644--- a/build.xml+++ b/build.xml@@ -208,7 +208,7 @@<!-- compiling the main sources --><javac srcdir="${src}/" destdir="${build}"- excludes="de/anomic/plasma/parser/*/*,de/anomic/yacy/seedUpload/**,de/anomic/soap/**,yacy.java,de/anomic/server/serverPortForwardingSch.java"+ excludes="de/anomic/plasma/parser/*/*,de/anomic/yacy/seedUpload/**,de/anomic/soap/**,yacy.java,de/anomic/server/portForwarding/*/*"debug="true" debuglevel="lines,vars,source"source="${javacSource}" target="${javacTarget}"><classpath refid="project.class.path"/>@@ -301,27 +301,34 @@</target><target name="compilePortForwarding" depends="compileMain" description="Compiling and zipping additional port forwarder">- <javac srcdir="${src}/de/anomic/server/" destdir="${build}" source="${javacSource}" target="${javacTarget}" debug="true" debuglevel="lines,vars,source">- <include name="serverPortForwardingSch.java"/>+ <javac srcdir="${src}/de/anomic/server/portForwarding" destdir="${build}" source="${javacSource}" target="${javacTarget}" debug="true" debuglevel="lines,vars,source">+ <exclude name="serverPortForwarding.java"/><classpath><pathelement location="${build}" />- <!-- main lib needed to parse rss/atom feed files -->+ <!-- libs needed by the sch port forwarder --><pathelement location="${libx}/jsch-0.1.21.jar" />++ <!-- libs needed by the upnp port forwarder -->+ <pathelement location="${libx}/commons-logging.jar" />+ <pathelement location="${libx}/commons-jxpath-1.1.jar" />+ <pathelement location="${libx}/sbbi-upnplib-1.0.3.jar" /></classpath></javac><copy todir="${release_ext}/libx/">- <fileset dir="${libx}" includes="jsch-0.1.21.*"/>+ <fileset dir="${libx}" includes="jsch-0.1.21.*"/>+ <fileset dir="${libx}" includes="commons-logging.*"/>+ <fileset dir="${libx}" includes="commons-jxpath-1.1.*"/>+ <fileset dir="${libx}" includes="sbbi-upnplib-1.0.3.*"/></copy>- <copy todir="${release_ext}/source/de/anomic/server/">- <fileset dir="${src}/de/anomic/server/">- <include name="serverPortForwardingSch.java"/>+ <copy todir="${release_ext}/source/de/anomic/server/portForwarding">+ <fileset dir="${src}/de/anomic/server/portForwarding">+ <include name="**/*.java"/></fileset></copy>- <copy todir="${release_ext}/classes/de/anomic/server/">- <fileset dir="${build}/de/anomic/server/">- <include name="serverPortForwardingSch.class"/>- <include name="serverPortForwardingSch$MyUserInfo.class"/>+ <copy todir="${release_ext}/classes/de/anomic/server/portForwarding">+ <fileset dir="${build}/de/anomic/server/portForwarding">+ <include name="**/*.class"/></fileset></copy></target>@@ -368,8 +375,7 @@<!-- excluding the soap handler --><exclude name="de/anomic/soap/**"/><!-- excluding the port forwarder -->- <exclude name="de/anomic/server/serverPortForwardingSch.class"/>- <exclude name="de/anomic/server/serverPortForwardingSch$MyUserInfo.class"/>+ <exclude name="de/anomic/server/portForwarding/*/*"/></fileset><!-- copy standard seed uploaders -->@@ -465,7 +471,7 @@<!-- excluding soap --><exclude name="de/anomic/soap/**"/><!-- excluding the port forwarder -->- <exclude name="de/anomic/server/serverPortForwardingSch.java"/>+ <exclude name="de/anomic/server/portForwarding/*/*"/></fileset><fileset dir="${src}"><include name="de/anomic/yacy/seedUpload/yacySeedUploadFile.java"/>diff --git a/htroot/SettingsAck_p.html b/htroot/SettingsAck_p.htmlindex 0ae5e1eff..30c68dc65 100644--- a/htroot/SettingsAck_p.html+++ b/htroot/SettingsAck_p.html@@ -144,19 +144,25 @@ Seed Upload method was changed successfully.<table><tr><td>Port Forwarding Support is:</td>- <td class="settingsValue">#[portForwardingEnabled]#</td>+ <td class="settingsValue">#[portForwarding.Enabled]#</td></tr>+<tr>+ <td>Port Forwarding Method:</td>+ <td class="settingsValue">#[portForwarding.Type]#</t+</tr>+<tr><td colspan="2"><hr></td></tr>+<tr><td colspan="2"><b>Secure channel specific settings:</b></td></tr><tr><td>Port Forwarding Port:</td>- <td class="settingsValue">#[portForwardingPort]#</td>+ <td class="settingsValue">#[portForwarding.sch.Port]#</td></tr><tr><td>Port Forwarding Host:</td>- <td class="settingsValue">#[portForwardingHostUser]#@#[portForwardingHost]#:#[portForwardingHostPort]#</td>+ <td class="settingsValue">#[portForwarding.sch.HostUser]#@#[portForwarding.sch.Host]#:#[portForwarding.sch.HostPort]#</td></tr><tr><td>Port Forwarding uses proxy:</td>- <td class="settingsValue">#[portForwardingUseProxy]#</td>+ <td class="settingsValue">#[portForwarding.sch.UseProxy]#</td></tr></table>::<!-- 23 : Port forwarding - error -->diff --git a/htroot/SettingsAck_p.java b/htroot/SettingsAck_p.javaindex f6c085336..4365912a7 100644--- a/htroot/SettingsAck_p.java+++ b/htroot/SettingsAck_p.java@@ -244,14 +244,15 @@ public class SettingsAck_p {// port forwarding configurationif (post.containsKey("portForwarding")) {- env.setConfig("portForwardingEnabled", post.containsKey("portForwardingEnabled")?"true":"false");- env.setConfig("portForwardingUseProxy",post.containsKey("portForwardingUseProxy")?"true":"false");- env.setConfig("portForwardingPort", (String)post.get("portForwardingPort"));-- env.setConfig("portForwardingHost", (String)post.get("portForwardingHost"));- env.setConfig("portForwardingHostPort",(String)post.get("portForwardingHostPort"));- env.setConfig("portForwardingHostUser",(String)post.get("portForwardingHostUser"));- env.setConfig("portForwardingHostPwd", (String)post.get("portForwardingHostPwd"));+ env.setConfig("portForwarding.Enabled", post.containsKey("portForwarding.Enabled")?"true":"false");+ env.setConfig("portForwarding.Type", (String)post.get("portForwarding.Type"));++ env.setConfig("portForwarding.sch.UseProxy",post.containsKey("portForwarding.sch.UseProxy")?"true":"false");+ env.setConfig("portForwarding.sch.Port", (String)post.get("portForwarding.sch.Port"));+ env.setConfig("portForwarding.sch.Host", (String)post.get("portForwarding.sch.Host"));+ env.setConfig("portForwarding.sch.HostPort",(String)post.get("portForwarding.sch.HostPort"));+ env.setConfig("portForwarding.sch.HostUser",(String)post.get("portForwarding.sch.HostUser"));+ env.setConfig("portForwarding.sch.HostPwd", (String)post.get("portForwarding.sch.HostPwd"));// trying to reconnect the port forwarding channeltry {@@ -273,13 +274,15 @@ public class SettingsAck_p {}prop.put("info", 22);- prop.put("info_portForwardingEnabled", post.containsKey("portForwardingEnabled")?"on":"off");- prop.put("info_portForwardingUseProxy",post.containsKey("portForwardingUseProxy")?"on":"off");- prop.put("info_portForwardingPort", (String)post.get("portForwardingPort"));- prop.put("info_portForwardingHost", (String)post.get("portForwardingHost"));- prop.put("info_portForwardingHostPort",(String)post.get("portForwardingHostPort"));- prop.put("info_portForwardingHostUser",(String)post.get("portForwardingHostUser"));- prop.put("info_portForwardingHostPwd", (String)post.get("portForwardingHostPwd"));+ prop.put("info_portForwarding.Enabled", post.containsKey("portForwarding.Enabled")?"on":"off");+ prop.put("info_portForwarding.Type", (String)post.get("portForwarding.Type"));++ prop.put("info_portForwarding.sch.UseProxy",post.containsKey("portForwarding.sch.UseProxy")?"on":"off");+ prop.put("info_portForwarding.sch.Port", (String)post.get("portForwarding.sch.Port"));+ prop.put("info_portForwarding.sch.Host", (String)post.get("portForwarding.sch.Host"));+ prop.put("info_portForwarding.sch.HostPort",(String)post.get("portForwarding.sch.HostPort"));+ prop.put("info_portForwarding.sch.HostUser",(String)post.get("portForwarding.sch.HostUser"));+ prop.put("info_portForwarding.sch.HostPwd", (String)post.get("portForwarding.sch.HostPwd"));return prop;}diff --git a/htroot/Settings_PortForwarding.inc b/htroot/Settings_PortForwarding.incindex e41906db1..2dc3aa009 100644--- a/htroot/Settings_PortForwarding.inc+++ b/htroot/Settings_PortForwarding.inc@@ -3,46 +3,60 @@<p>You can use a remote server running a ssh demon to forward your server/proxy port.This is useful if you want to tunnel throug a NAT/router.Alternatively, you can simply set a virtual server port on your NAT/Server to enable connections from outside.</p>-#(portForwardingAvailable)#<p><font color="red">You need to install libx to use this feature</font></p>::#(/portForwardingAvailable)#+#(portForwarding.Available)#<p><b><font color="red">You need to install libx to use this feature</font></b></p>::#(/portForwarding.Available)#<table border="0" cellspacing="5"><tr valign="top"><td>Enable port forwarding:</td>- <td><input type="checkbox" name="portForwardingEnabled" align="top" #(portForwardingEnabled)#::checked#(/portForwardingEnabled)##(portForwardingAvailable)# disabled="disabled"::#(/portForwardingAvailable)#></td>- <td>Enabling disabling port forwarding via secure channel.</td>+ <td><input type="checkbox" name="portForwarding.Enabled" align="top" #(portForwarding.Enabled)#::checked#(/portForwarding.Enabled)##(portForwarding.Available)# disabled="disabled"::#(/portForwarding.Available)#></td>+ <td>Enabling disabling port forwarding</td></tr>+ <tr valign="top">+ <td>Forwarding method:</td>+ <td><select name="portForwarding.Type" size="1">+ #{forwardingMethods}#+ <option value="#[name]#" #(selected)#::selected#(/selected)#>#[name]#</option>+ #{/forwardingMethods}#+ </select>+ </td>+ <td>Select the port forwarding method to use.</td>+ </tr>++ <tr><td colspan="3"><hr></td></tr>+ <tr><td colspan="3"><b>Special settings for port forwarding using secure channel</b></td></tr><tr valign="top"><td>Forwarding via proxy:</td>- <td><input type="checkbox" name="portForwardingUseProxy" align="top" #(portForwardingUseProxy)#::checked#(/portForwardingUseProxy)# DISABLED></td>+ <td><input type="checkbox" name="portForwarding.sch.UseProxy" align="top" #(portForwarding.sch.UseProxy)#::checked#(/portForwarding.sch.UseProxy)# DISABLED></td><td><!-- Specifies if the connection should be established through the <a href="#proxy">remote proxy</a>.--><i>Function not available at the moment.</i></td></tr><tr valign="top"><td>Forwarding port:</td>- <td><input name="portForwardingPort" type="text" size="5" maxlength="5" value="#[portForwardingPort]#"></td>- <td>The port on the remote server that should be forwarded via the secure channel to the local host.</td>+ <td><input name="portForwarding.sch.Port" type="text" size="5" maxlength="5" value="#[portForwarding.sch.Port]#"></td>+ <td>The tcp/ip port on the remote server that should be forwarded via the secure channel to the local host.</td></tr><tr valign="top"><td>Forwarding host:</td>- <td><input name="portForwardingHost" type="text" size="32" maxlength="128" value="#[portForwardingHost]#"></td>- <td> </td>+ <td><input name="portForwarding.sch.Host" type="text" size="32" maxlength="128" value="#[portForwarding.sch.Host]#"></td>+ <td>ip address or name of the remote server</td></tr><tr valign="top"><td>Forwarding host port:</td>- <td><input name="portForwardingHostPort" type="text" size="5" maxlength="5" value="#[portForwardingHostPort]#"></td>- <td> </td>+ <td><input name="portForwarding.sch.HostPort" type="text" size="5" maxlength="5" value="#[portForwarding.sch.HostPort]#"></td>+ <td>ssh port of the remote server</td></tr><tr valign="top"><td>Forwarding host user:</td>- <td><input name="portForwardingHostUser" type="text" size="32" maxlength="128" value="#[portForwardingHostUser]#"></td>- <td> </td>+ <td><input name="portForwarding.sch.HostUser" type="text" size="32" maxlength="128" value="#[portForwarding.sch.HostUser]#"></td>+ <td>username to login on the remote server</td></tr><tr valign="top"><td>Forwarding host password:</td>- <td><input name="portForwardingHostPwd" type="password" size="32" maxlength="128" value="#[portForwardingHostPwd]#"></td>- <td> </td>+ <td><input name="portForwarding.sch.HostPwd" type="password" size="32" maxlength="128" value="#[portForwarding.sch.HostPwd]#"></td>+ <td>password to login on the remote server</td></tr>+ <tr><td colspan="3"><hr></td></tr><tr valign="top">- <td colspan="3"><input type="submit" name="portForwarding" value="Submit"#(portForwardingAvailable)# disabled="disabled"::#(/portForwardingAvailable)#> <i>Changes will take effect immediately.</i></td>+ <td colspan="3"><input type="submit" name="portForwarding" value="Submit"#(portForwarding.Available)# disabled="disabled"::#(/portForwarding.Available)#> <i>Changes will take effect immediately.</i></td></tr></table></fieldset>diff --git a/htroot/Settings_p.java b/htroot/Settings_p.javaindex 3be190403..7209e12c2 100644--- a/htroot/Settings_p.java+++ b/htroot/Settings_p.java@@ -53,8 +53,10 @@ import de.anomic.plasma.plasmaParser;import de.anomic.plasma.plasmaParserConfig;import de.anomic.plasma.plasmaSwitchboard;import de.anomic.plasma.parser.ParserInfo;+import de.anomic.server.serverCore;import de.anomic.server.serverObjects;import de.anomic.server.serverSwitch;+import de.anomic.server.portForwarding.serverPortForwarding;import de.anomic.yacy.yacyCore;import de.anomic.yacy.yacySeedUploader;@@ -120,22 +122,34 @@ public final class Settings_p {prop.put("proxy.sendXForwardedForHeader", env.getConfig("proxy.sendXForwardedForHeader", "true").equals("true") ? 1 : 0);// remote port forwarding settings+ String[] forwardingMethods = new String[]{"sch","upnp"};+ String currentForwarder = env.getConfig("portForwarding.Type", "none");boolean portForwardingAvailable = false;- try {- Class.forName("de.anomic.server.serverPortForwardingSch");- portForwardingAvailable = true;- } catch (Exception e) {- } catch (Error e) {}-- prop.put("portForwardingAvailable",portForwardingAvailable? 1:0);- prop.put("portForwardingEnabled",env.getConfig("portForwardingEnabled","false").equals("true")? 1 : 0);- prop.put("portForwardingUseProxy",env.getConfig("portForwardingUseProxy", "false").equals("true")? 1 : 0);- prop.put("portForwardingPort",env.getConfig("portForwardingPort", ""));-- prop.put("portForwardingHost",env.getConfig("portForwardingHost", ""));- prop.put("portForwardingHostPort",env.getConfig("portForwardingHostPort", ""));- prop.put("portForwardingHostUser",env.getConfig("portForwardingHostUser", ""));- prop.put("portForwardingHostPwd",env.getConfig("portForwardingHostPwd", ""));+ int methodCount = 0;++ for (int i=0; i < forwardingMethods.length; i++) {+ try {+ Class forwarder = Class.forName(env.getConfig("portForwarding." + forwardingMethods[i],""));+ prop.put("forwardingMethods_" + methodCount + "_name",forwardingMethods[i]);+ prop.put("forwardingMethods_" + methodCount + "_selected", forwardingMethods[i].equals(currentForwarder)?1:0);+ methodCount++;+ } catch (Exception e) {+ } catch (Error e) {}+ }+ prop.put("forwardingMethods",methodCount);++ if (methodCount > 0) portForwardingAvailable = true;++ prop.put("portForwarding.Type",currentForwarder);+ prop.put("portForwarding.Available",portForwardingAvailable? 1:0);+ prop.put("portForwarding.Enabled",env.getConfig("portForwarding.Enabled","false").equals("true")? 1 : 0);++ prop.put("portForwarding.sch.UseProxy",env.getConfig("portForwarding.sch.UseProxy", "false").equals("true")? 1 : 0);+ prop.put("portForwarding.sch.Port",env.getConfig("portForwarding.sch.Port", ""));+ prop.put("portForwarding.sch.Host",env.getConfig("portForwarding.sch.Host", ""));+ prop.put("portForwarding.sch.HostPort",env.getConfig("portForwarding.sch.HostPort", ""));+ prop.put("portForwarding.sch.HostUser",env.getConfig("portForwarding.sch.HostUser", ""));+ prop.put("portForwarding.sch.HostPwd",env.getConfig("portForwarding.sch.HostPwd", ""));// set valuesString s;diff --git a/libx/commons-jxpath-1.1.jar b/libx/commons-jxpath-1.1.jarnew file mode 100644index 000000000..9516e2ad6Binary files /dev/null and b/libx/commons-jxpath-1.1.jar differdiff --git a/libx/sbbi-upnplib-1.0.3.jar b/libx/sbbi-upnplib-1.0.3.jarnew file mode 100644index 000000000..32f07d59eBinary files /dev/null and b/libx/sbbi-upnplib-1.0.3.jar differdiff --git a/source/de/anomic/http/httpHeader.java b/source/de/anomic/http/httpHeader.javaindex dda7344c2..25082cfad 100644--- a/source/de/anomic/http/httpHeader.java+++ b/source/de/anomic/http/httpHeader.java@@ -769,6 +769,7 @@ public final class httpHeader extends TreeMap implements Map {// and therefor was set to virtualHost by function parseQuery()if (!prop.getProperty(CONNECTION_PROP_HOST).equals(virtualHost)) return;+ // TODO: we could have problems with connections from extern here ...String dstHostSocket = (String) header.get(httpHeader.HOST);prop.setProperty(CONNECTION_PROP_HOST,(httpd.isThisHostName(dstHostSocket)?virtualHost:dstHostSocket));}diff --git a/source/de/anomic/server/portForwarding/sch/serverPortForwardingSch.java b/source/de/anomic/server/portForwarding/sch/serverPortForwardingSch.javanew file mode 100644index 000000000..ee9d817ae--- /dev/null+++ b/source/de/anomic/server/portForwarding/sch/serverPortForwardingSch.java@@ -0,0 +1,321 @@+// serverPortForwardingSch.java+// -------------------------------------+// part of YACY+// (C) by Michael Peter Christen; [email protected]+// first published on http://www.anomic.de+// Frankfurt, Germany, 2004+//+// This file ist contributed by Martin Thelian+//+// $LastChangedDate: 2006-02-20 23:57:42 +0100 (Mo, 20 Feb 2006) $+// $LastChangedRevision: 1715 $+// $LastChangedBy: borg-0300 $+//+// This program is free software; you can redistribute it and/or modify+// it under the terms of the GNU General Public License as published by+// the Free Software Foundation; either version 2 of the License, or+// (at your option) any later version.+//+// This program is distributed in the hope that it will be useful,+// but WITHOUT ANY WARRANTY; without even the implied warranty of+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+// GNU General Public License for more details.+//+// You should have received a copy of the GNU General Public License+// along with this program; if not, write to the Free Software+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA+//+// Using this software in any meaning (reading, learning, copying, compiling,+// running) means that you agree that the Author(s) is (are) not responsible+// for cost, loss of data or any harm that may be caused directly or indirectly+// by usage of this softare or this documentation. The usage of this software+// is on your own risk. The installation and usage (starting/running) of this+// software may allow other people or application to access your computer and+// any attached devices and is highly dependent on the configuration of the+// software which must be done by the user of the software; the author(s) is+// (are) also not responsible for proper configuration and usage of the+// software, even if provoked by documentation provided together with+// the software.+//+// Any changes to this file according to the GPL as documented in the file+// gpl.txt aside this file in the shipment you received can be done to the+// lines that follows this copyright notice here, but changes must not be+// done inside the copyright notive above. A re-distribution must contain+// the intact and unchanged copyright notice.+// Contributions and changes to the program code must be marked as such.++package de.anomic.server.portForwarding.sch;++import java.io.IOException;+import com.jcraft.jsch.JSch;+import com.jcraft.jsch.ProxyHTTP;+import com.jcraft.jsch.Session;+import com.jcraft.jsch.UIKeyboardInteractive;+import com.jcraft.jsch.UserInfo;++import de.anomic.server.serverInstantThread;+import de.anomic.server.serverSwitch;+import de.anomic.server.logging.serverLog;+import de.anomic.server.portForwarding.serverPortForwarding;+import de.anomic.yacy.yacyClient;+import de.anomic.yacy.yacyCore;++public class serverPortForwardingSch implements serverPortForwarding{++ /* ========================================================================+ * Constants needed to read properties from the configuration file+ * ======================================================================== */+ public static final String FORWARDING_HOST = "portForwarding.sch.Host";+ public static final String FORWARDING_HOST_PORT = "portForwarding.sch.HostPort";+ public static final String FORWARDING_HOST_USER = "portForwarding.sch.HostUser";+ public static final String FORWARDING_HOST_PWD = "portForwarding.sch.HostPwd";++ public static final String FORWARDING_PORT = "portForwarding.sch.Port";+ public static final String FORWARDING_USE_PROXY = "portForwarding.sch.UseProxy";+++ /* ========================================================================+ * Other object fields+ * ======================================================================== */+ private serverSwitch switchboard;++ private String forwardingHost;+ private int forwardingHostPort;+ private String forwardingHostUser;+ private String forwardingHostPwd;++ private int forwardingPort;+ private boolean useProxy;++ private String remoteProxyHost;+ private int remoteProxyPort;++ private String localHost;+ private int localHostPort;++ private static Session session;+ private static serverInstantThread sessionWatcher;++ private serverLog log;++ public serverPortForwardingSch() {+ super();+ this.log = new serverLog("PORT_FORWARDING_SCH");+ }++ public void init(+ serverSwitch switchboard,+ String localHost,+ int localPort+ ) throws Exception {+ try {+ this.log.logFine("Initializing port forwarding via sch ...");++ this.switchboard = switchboard;++ this.forwardingHost = switchboard.getConfig(FORWARDING_HOST,"localhost");+ this.forwardingHostPort = Integer.valueOf(switchboard.getConfig(FORWARDING_HOST_PORT,"8080")).intValue();+ this.forwardingHostUser = switchboard.getConfig(FORWARDING_HOST_USER,"xxx");+ this.forwardingHostPwd = switchboard.getConfig(FORWARDING_HOST_PWD,"xxx");++ this.forwardingPort = Integer.valueOf(switchboard.getConfig(FORWARDING_PORT,"8080")).intValue();+ this.useProxy = Boolean.valueOf(switchboard.getConfig(FORWARDING_USE_PROXY,"false")).booleanValue();++ this.localHost = localHost;+ this.localHostPort = localPort;++ // load remote proxy data+ this.remoteProxyHost = switchboard.getConfig("remoteProxyHost","");+ try {+ this.remoteProxyPort = Integer.parseInt(switchboard.getConfig("remoteProxyPort","3128"));+ } catch (NumberFormatException e) {+ remoteProxyPort = 3128;+ }++ // checking if all needed libs are availalbe+ String javaClassPath = System.getProperty("java.class.path");+ if (javaClassPath.indexOf("jsch") == -1) {+ throw new IllegalStateException("Missing library.");+ }+ } catch (Exception e) {+ this.log.logSevere("Unable to initialize port forwarding.",e);+ throw e;+ }+ }++ public String getHost() {+ return this.forwardingHost;+ }++ public int getPort() {+ return this.forwardingPort;+ }++ public synchronized void connect() throws IOException {+ try{+ if ((session != null) && (session.isConnected()))+ throw new IOException("Session already connected");++ this.log.logInfo("Trying to connect to remote port forwarding host " + this.forwardingHostUser + "@" + this.forwardingHost + ":" + this.forwardingHostPort);++ JSch jsch=new JSch();+ session=jsch.getSession(this.forwardingHostUser, this.forwardingHost, this.forwardingHostPort);+ session.setPassword(this.forwardingHostPwd);++ /*+ * Setting the StrictHostKeyChecking to ignore unknown+ * hosts because of a missing known_hosts file ...+ */+ java.util.Properties config = new java.util.Properties();+ config.put("StrictHostKeyChecking","no");+ session.setConfig(config);++ // setting the proxy that should be used+ if (this.useProxy) {+ session.setProxy(new ProxyHTTP(this.remoteProxyHost, this.remoteProxyPort));+ }++ // username and password will be given via UserInfo interface.+ UserInfo ui= new MyUserInfo(this.forwardingHostPwd);+ session.setUserInfo(ui);++ // trying to connect ...+ session.connect();++ // activating remote port forwarding+ session.setPortForwardingR(this.forwardingPort, this.localHost, this.localHostPort);++ // using a timer task to control if the session remains open+ if (sessionWatcher == null) {+ this.log.logFine("Deploying port forwarding session watcher thread.");+ this.switchboard.deployThread("portForwardingWatcher", "Remote Port Forwarding Watcher", "this thread is used to detect broken connections and to re-establish it if necessary.", null,+ sessionWatcher = new serverInstantThread(this, "reconnect", null), 30000,30000,30000,1000);+ sessionWatcher.setSyncObject(new Object());+ }++ this.log.logInfo("Remote port forwarding connection established: " ++ this.forwardingHost+ ":" + this.forwardingPort + " -> " ++ this.localHost + ":" + this.localHostPort);+ }+ catch(Exception e){+ this.log.logSevere("Unable to connect to remote port forwarding host.",e);+ throw new IOException(e.getMessage());+ }+ }++ public synchronized boolean reconnect() throws IOException {+ if ((!this.isConnected()) && (!Thread.currentThread().isInterrupted())) {+ this.log.logFine("Trying to reconnect to port forwarding host.");+ this.disconnect();+ this.connect();+ return this.isConnected();+ }+ return false;+ }++ public synchronized void disconnect() throws IOException {+ if (session == null) throw new IOException("No connection established.");++ // terminating port watcher thread+ this.log.logFine("Terminating port forwarding session watcher thread.");+ this.switchboard.terminateThread("portForwardingWatcher",true);+ sessionWatcher = null;++ // disconnection the session+ try {+ session.disconnect();+ this.log.logFine("Successfully disconnected from port forwarding host.");+ } catch (Exception e) {+ this.log.logSevere("Error while trying to disconnect from port forwarding host.",e);+ throw new IOException(e.getMessage());+ }+ }++ public synchronized boolean isConnected() {+ if (session == null) return false;+ if (!session.isConnected()) return false;+ int urls = yacyClient.queryUrlCount(yacyCore.seedDB.mySeed);+ return !(urls < 0);+ }++ class MyUserInfo+ implements UserInfo, UIKeyboardInteractive {+ String passwd;++ public MyUserInfo(String password) {+ this.passwd = password;+ }++ public String getPassword() {+ return this.passwd;+ }++ public boolean promptYesNo(String str){+ System.err.println("User was prompted from: " + str);+ return true;+ }++ public String getPassphrase() {+ return null;+ }++ public boolean promptPassphrase(String message) {+ System.out.println("promptPassphrase : " + message);+ return false;+ }++ public boolean promptPassword(String message) {+ System.out.println("promptPassword : " + message);+ return true;+ }++ /**+ * @see com.jcraft.jsch.UserInfo#showMessage(java.lang.String)+ */+ public void showMessage(String message) {+ System.out.println("Sch has tried to show the following message to the user: " + message);+ }++ public String[] promptKeyboardInteractive(String destination,+ String name,+ String instruction,+ String[] prompt,+ boolean[] echo) {+ System.out.println("User was prompted using interactive-keyboard: " ++ "\n\tDestination: " + destination ++ "\n\tName: " + name ++ "\n\tInstruction: " + instruction ++ "\n\tPrompt: " + arrayToString2(prompt,"|") ++ "\n\techo: " + arrayToString2(echo,"|"));++ if ((prompt.length >= 1) && (prompt[0].startsWith("Password")))+ return new String[]{this.passwd};+ return new String[]{};+ }++ String arrayToString2(String[] a, String separator) {+ StringBuffer result = new StringBuffer(); // start with first element+ if (a.length > 0) {+ result.append(a[0]);+ for (int i=1; i<a.length; i++) {+ result.append(separator);+ result.append(a[i]);+ }+ }+ return result.toString();+ }++ String arrayToString2(boolean[] a, String separator) {+ StringBuffer result = new StringBuffer(); // start with first element+ if (a.length > 0) {+ result.append(a[0]);+ for (int i=1; i<a.length; i++) {+ result.append(separator);+ result.append(a[i]);+ }+ }+ return result.toString();+ }+ }++}diff --git a/source/de/anomic/server/portForwarding/serverPortForwarding.java b/source/de/anomic/server/portForwarding/serverPortForwarding.javanew file mode 100644index 000000000..8facd2b90--- /dev/null+++ b/source/de/anomic/server/portForwarding/serverPortForwarding.java@@ -0,0 +1,63 @@+// serverPortForwarding.java+// -------------------------------------+// part of YACY+// (C) by Michael Peter Christen; [email protected]+// first published on http://www.anomic.de+// Frankfurt, Germany, 2004+//+// This file ist contributed by Martin Thelian+//+// $LastChangedDate: 2006-02-20 23:57:42 +0100 (Mo, 20 Feb 2006) $+// $LastChangedRevision: 1715 $+// $LastChangedBy: borg-0300 $+//+// This program is free software; you can redistribute it and/or modify+// it under the terms of the GNU General Public License as published by+// the Free Software Foundation; either version 2 of the License, or+// (at your option) any later version.+//+// This program is distributed in the hope that it will be useful,+// but WITHOUT ANY WARRANTY; without even the implied warranty of+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+// GNU General Public License for more details.+//+// You should have received a copy of the GNU General Public License+// along with this program; if not, write to the Free Software+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA+//+// Using this software in any meaning (reading, learning, copying, compiling,+// running) means that you agree that the Author(s) is (are) not responsible+// for cost, loss of data or any harm that may be caused directly or indirectly+// by usage of this softare or this documentation. The usage of this software+// is on your own risk. The installation and usage (starting/running) of this+// software may allow other people or application to access your computer and+// any attached devices and is highly dependent on the configuration of the+// software which must be done by the user of the software; the author(s) is+// (are) also not responsible for proper configuration and usage of the+// software, even if provoked by documentation provided together with+// the software.+//+// Any changes to this file according to the GPL as documented in the file+// gpl.txt aside this file in the shipment you received can be done to the+// lines that follows this copyright notice here, but changes must not be+// done inside the copyright notive above. A re-distribution must contain+// the intact and unchanged copyright notice.+// Contributions and changes to the program code must be marked as such.++package de.anomic.server.portForwarding;++import java.io.IOException;++import de.anomic.server.serverSwitch;++public interface serverPortForwarding {+ public void init(serverSwitch switchboard, String localHost, int localPort) throws Exception;++ public String getHost();+ public int getPort();++ public void connect() throws IOException;+ public void disconnect() throws IOException;+ public boolean reconnect() throws IOException;+ public boolean isConnected();+}diff --git a/source/de/anomic/server/portForwarding/upnp/serverPortForwardingUpnp.java b/source/de/anomic/server/portForwarding/upnp/serverPortForwardingUpnp.javanew file mode 100644index 000000000..3154b2c0d--- /dev/null+++ b/source/de/anomic/server/portForwarding/upnp/serverPortForwardingUpnp.java@@ -0,0 +1,174 @@+package de.anomic.server.portForwarding.upnp;++import java.io.IOException;+import java.net.InetAddress;+import java.net.URL;++import com.jcraft.jsch.Session;++import net.sbbi.upnp.devices.UPNPRootDevice;+import net.sbbi.upnp.impls.InternetGatewayDevice;+import net.sbbi.upnp.messages.ActionResponse;+import net.sbbi.upnp.messages.UPNPResponseException;++import de.anomic.server.serverInstantThread;+import de.anomic.server.serverSwitch;+import de.anomic.server.logging.serverLog;+import de.anomic.server.portForwarding.serverPortForwarding;++public class serverPortForwardingUpnp implements serverPortForwarding {+ private InternetGatewayDevice gateway;++ private serverSwitch switchboard;++ private String localHost;+ private int localHostPort;++ private String externalAddress = null;++ private serverLog log;++ public serverPortForwardingUpnp() {+ super();+ this.log = new serverLog("PORT_FORWARDING_UPNP");+ }++ public void connect() throws IOException {+ try {+ if (this.gateway != null)+ throw new IOException("Session already connected");++ int timeout = 8000;+ try {+ // trying to get all internet gateways on the local network+ this.log.logInfo("Trying to find all available internet gateways.");+ InternetGatewayDevice[] IGDs = InternetGatewayDevice.getDevices(timeout);+ boolean mapped = false;+ if ( IGDs != null ) {+ for ( int i = 0; i < IGDs.length; i++ ) {++ this.gateway = IGDs[i];+ this.log.logInfo("Found device " + this.gateway.getIGDRootDevice().getModelName() );+ this.log.logInfo("NAT table size is " + this.gateway.getNatTableSize() );++ // now let's open the port+ this.log.logInfo("Adding port mapping ...");+ mapped = this.gateway.addPortMapping(+ "YaCy port forwarding",+ null,+ this.localHostPort,+ this.localHostPort,+ this.localHost,+ 0,+ "TCP"+ );++ if ( mapped ) {+ this.log.logInfo("Gateway port " + this.localHostPort + " mapped to " + this.localHost );+ this.log.logInfo("Current mappings count is " + this.gateway.getNatMappingsCount() );+ mapped = isConnected();+ }+ if (mapped) break;+ }+ if (!mapped) {+ throw new IOException("Unable to configure the port mapping.");+ }+ } else {+ throw new IOException("No internet gateway device found.");+ }++ } catch ( IOException ex ) {+ throw new Exception("IOException occured during discovery or ports mapping " + ex.getMessage());+ } catch( UPNPResponseException respEx ) {+ throw new Exception("UPNP device unhappy " + respEx.getDetailErrorCode() + " " + respEx.getDetailErrorDescription() );+ }+ } catch (Exception e) {+ this.gateway = null;+ this.log.logSevere("Unable to connect to remote port forwarding host. ",e);+ throw new IOException(e.getMessage());+ }+ }++ public void disconnect() throws IOException {+ if (this.gateway == null) throw new IOException("No connection established.");++ boolean unmapped;+ try {+ this.log.logInfo("Trying to disable port mapping ...");+ unmapped = this.gateway.deletePortMapping( null, this.localHostPort, "TCP" );+ if ( unmapped ) {+ this.log.logInfo("Port mapping disabled");+ }+ } catch (UPNPResponseException e) {+ new IOException("Unable to disable port forwarding. " + e.getMessage());+ }+ }++ public String getHost() {+ if (this.gateway == null) return "";+ if (this.externalAddress == null) {+ try {+ this.externalAddress = this.gateway.getExternalIPAddress();+ } catch (Exception e) {+ this.log.logWarning("Unable to get the external address of the gateway");+ }+ }+ return this.externalAddress;+ }++ public int getPort() {+ return this.localHostPort;+ }++ public void init(serverSwitch switchboard, String localHost, int localPort)+ throws Exception {+ try {+ this.log.logFine("Initializing port forwarding via sch ...");+ this.switchboard = switchboard;++ if (localHost.equals("0.0.0.0")) {+ this.localHost = InetAddress.getLocalHost().getHostAddress();+ } else {+ this.localHost = localHost;+ }+ this.localHostPort = localPort;++ // checking if all needed libs are availalbe+ String javaClassPath = System.getProperty("java.class.path");+ if (javaClassPath.indexOf("sbbi-upnplib") == -1) {+ throw new IllegalStateException("Missing library.");+ }++ // setting the proper xml parser+// if (System.getProperty("javax.xml.parsers.DocumentBuilderFactory", "").equals("")) {+// System.setProperty("javax.xml.parsers.DocumentBuilderFactory", "");+// }++ } catch (Exception e) {+ this.log.logSevere("Unable to initialize port forwarding.",e);+ throw e;+ }+ }++ public boolean isConnected() {+ if (this.gateway == null) return false;+ try {+ ActionResponse resp = this.gateway.getSpecificPortMappingEntry( null, this.localHostPort, "TCP" );+ return ( resp != null );+ } catch (Exception e) {+ this.log.logSevere("Unable to determine the connection status");+ return false;+ }+ }++ public boolean reconnect() throws IOException {+ if (!this.isConnected()) {+ this.log.logFine("Trying to reconnect to port forwarding host.");+ this.disconnect();+ this.connect();+ return this.isConnected();+ }+ return false;+ }++}diff --git a/source/de/anomic/server/serverCore.java b/source/de/anomic/server/serverCore.javaindex 63e571f94..08b41f037 100644--- a/source/de/anomic/server/serverCore.java+++ b/source/de/anomic/server/serverCore.java@@ -82,6 +82,7 @@ import de.anomic.http.httpc;import de.anomic.icap.icapd;import de.anomic.plasma.plasmaSwitchboard;import de.anomic.server.logging.serverLog;+import de.anomic.server.portForwarding.serverPortForwarding;import de.anomic.tools.PKCS12Tool;import de.anomic.urlRedirector.urlRedirectord;import de.anomic.yacy.yacyCore;@@ -340,19 +341,23 @@ public final class serverCore extends serverAbstractThread implements serverThrepublic void initPortForwarding() throws Exception {// doing the port forwarding stuff- if (this.switchboard.getConfig("portForwardingEnabled","false").equalsIgnoreCase("true")) {+ if (this.switchboard.getConfigBool("portForwarding.Enabled",false)) {this.log.logInfo("Initializing port forwarding ...");try {- String localHost = this.socket.getInetAddress().getHostName();- Integer localPort = new Integer(this.socket.getLocalPort());-- this.log.logInfo("Trying to load port forwarding class");+ // getting the port forwarding type to use+ String forwardingType = this.switchboard.getConfig("portForwarding.Type","none");// loading port forwarding class- Class forwarderClass = Class.forName("de.anomic.server.serverPortForwardingSch");+ this.log.logInfo("Trying to load port forwarding class for forwarding type '" + forwardingType + "'.");+ String forwardingClass = this.switchboard.getConfig("portForwarding." + forwardingType ,"");++ Class forwarderClass = Class.forName(forwardingClass);serverCore.portForwarding = (serverPortForwarding) forwarderClass.newInstance();// initializing port forwarding+ String localHost = this.socket.getInetAddress().getHostName();+ Integer localPort = new Integer(this.socket.getLocalPort());+serverCore.portForwarding.init(this.switchboard,localHost,@@ -366,11 +371,11 @@ public final class serverCore extends serverAbstractThread implements serverThreyacyCore.seedDB.mySeed.put(yacySeed.PORT,Integer.toString(serverCore.portForwarding.getPort()));} catch (Exception e) {serverCore.portForwardingEnabled = false;- this.switchboard.setConfig("portForwardingEnabled", "false");+ this.switchboard.setConfig("portForwarding.Enabled", "false");throw e;} catch (Error e) {serverCore.portForwardingEnabled = false;- this.switchboard.setConfig("portForwardingEnabled", "false");+ this.switchboard.setConfig("portForwarding.Enabled", "false");throw e;}diff --git a/source/de/anomic/server/serverSwitch.java b/source/de/anomic/server/serverSwitch.javaindex 9c269b7fd..af0d02c10 100644--- a/source/de/anomic/server/serverSwitch.java+++ b/source/de/anomic/server/serverSwitch.java@@ -94,6 +94,7 @@ public interface serverSwitch {public void setConfig(String key, String value);public String getConfig(String key, String dflt);public long getConfigLong(String key, long dflt);+ public boolean getConfigBool(String key, boolean dflt);public Iterator configKeys();public Map getRemoved();diff --git a/source/migration.java b/source/migration.javaindex b0d60426a..a36690dc3 100644--- a/source/migration.java+++ b/source/migration.java@@ -217,6 +217,8 @@ public class migration {}public static void migrateSwitchConfigSettings(plasmaSwitchboard sb) {++ // migration for additional parser settingsString value = "";if ((value = sb.getConfig("parseableMimeTypes","")).length() > 0) {sb.setConfig("parseableMimeTypes.CRAWLER", value);@@ -228,6 +230,21 @@ public class migration {if(sb.getConfig("htLocalePath", "htroot/locale").equals("htroot/locale")){sb.setConfig("htLocalePath", "DATA/HTDOCS/locale");}++ // migration for port forwarding settings+ if ((value = sb.getConfig("portForwardingHost","")).length() > 0) {+ sb.setConfig("portForwarding.Enabled", sb.getConfig("portForwardingEnabled",""));+ if (sb.getConfigBool("portForwardingEnabled", false)) {+ sb.setConfig("portForwarding.Type", "sch");+ }++ sb.setConfig("portForwarding.sch.UseProxy", sb.getConfig("portForwardingUseProxy",""));+ sb.setConfig("portForwarding.sch.Port", sb.getConfig("portForwardingPort",""));+ sb.setConfig("portForwarding.sch.Host", sb.getConfig("portForwardingHost",""));+ sb.setConfig("portForwarding.sch.HostPort", sb.getConfig("portForwardingHostPort",""));+ sb.setConfig("portForwarding.sch.HostUser", sb.getConfig("portForwardingHostUser",""));+ sb.setConfig("portForwarding.sch.HostPwd", sb.getConfig("portForwardingHostPwd",""));+ }}}diff --git a/source/yacy.java b/source/yacy.javaindex 8251331b1..0b25fb8e0 100644--- a/source/yacy.java+++ b/source/yacy.java@@ -1260,12 +1260,12 @@ public final class yacy {// go into headless awt modeSystem.setProperty("java.awt.headless", "true");//which XML Parser?- if(System.getProperty("javax.xml.parsers.DocumentBuilderFactory")==null){- System.setProperty("javax.xml.parsers.DocumentBuilderFactory", "org.apache.crimson.jaxp.DocumentBuilderFactoryImpl");- }- if(System.getProperty("javax.xml.parsers.SAXParserFactory")==null){- System.setProperty("javax.xml.parsers.SAXParserFactory", "org.apache.crimson.jaxp.SAXParserFactoryImpl");- }+// if(System.getProperty("javax.xml.parsers.DocumentBuilderFactory")==null){+// System.setProperty("javax.xml.parsers.DocumentBuilderFactory", "org.apache.crimson.jaxp.DocumentBuilderFactoryImpl");+// }+// if(System.getProperty("javax.xml.parsers.SAXParserFactory")==null){+// System.setProperty("javax.xml.parsers.SAXParserFactory", "org.apache.crimson.jaxp.SAXParserFactoryImpl");+// }String applicationRoot = System.getProperty("user.dir").replace('\\', '/');//System.out.println("args.length=" + args.length);diff --git a/yacy.init b/yacy.initindex 0255ddfb7..b8c386bc9 100644--- a/yacy.init+++ b/yacy.init@@ -594,14 +594,20 @@ proxy.sendViaHeader=trueproxy.sendXForwardedForHeader=true# Configuration options needed to configure server port forwarding-portForwardingEnabled=false-portForwardingUseProxy=false-portForwardingPort=--portForwardingHost=-portForwardingHostPort=22-portForwardingHostUser=-portForwardingHostPwd=+portForwarding.Enabled=false+portForwarding.Type=none++# port forwarding via sch+portForwarding.sch=de.anomic.server.portForwarding.sch.serverPortForwardingSch+portForwarding.sch.UseProxy=false+portForwarding.sch.Port=+portForwarding.sch.Host=+portForwarding.sch.HostPort=22+portForwarding.sch.HostUser=+portForwarding.sch.HostPwd=++# port forwarding via upnp+portForwarding.upnp=de.anomic.server.portForwarding.upnp.serverPortForwardingUpnp# msgForwarding: Specifies if yacy should forward received messages via# email to the configured email address