mirror of
https://github.com/yacy/yacy_search_server.git
synced 2024-09-19 00:01:41 +02:00
*) offer router configuration on ConfigBasic.html
- checkbox to allow router configuration is shown if - a) the UPnP forwarder is installed - b) a UPnP enabled router was found - c) no other forwarder was configured See: http://www.yacy-forum.de/viewtopic.php?p=24264 git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@2358 6c8d7289-2bf4-0310-a012-ef5d649a1542
This commit is contained in:
parent
dcbb4d0a6b
commit
c09f734d06
|
@ -52,7 +52,9 @@ Your YaCy Peer needs some basic information to operate properly
|
|||
<li>#(statusName)#<img src="/env/grafics/warning.png"> Your peer name has not been customized; please set your own peer name::<img src="/env/grafics/ok.png" height="32px" width="32px"> You have a nice peer name#(/statusName)#<br>
|
||||
Peer Name: <input type="text" name="peername" value="#[defaultName]#" size="20" maxlength="32"><br><br></li>
|
||||
<li>#(statusPort)#<img src="/env/grafics/warning.png"> Your peer cannot be reached from outside (what is not fatal, but would be good for the YaCy network); please open your firewall for this port and/or set a virtual server option in your router to allow connections on this port.::<img src="/env/grafics/ok.png" height="32px" width="32px"> Your peer can be reached by other peers#(/statusPort)#<br>
|
||||
Peer Port: <input type="text" name="port" value="#[defaultPort]#" size="5" maxlength="5"><br><br></li>
|
||||
Peer Port: <input type="text" name="port" value="#[defaultPort]#" size="5" maxlength="5"><br>
|
||||
#(upnp)#::Configure your router for yacy: <input type="checkbox" name="enableUpnp" align="top" #(enabled)#::checked#(/enabled)#>#(/upnp)#<br>
|
||||
</li>
|
||||
</ol>
|
||||
<br> <input type="submit" name="set" value="Set Configuration">
|
||||
</form>
|
||||
|
|
|
@ -48,6 +48,7 @@
|
|||
// if the shell's current path is HTROOT
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import de.anomic.data.translator;
|
||||
import de.anomic.http.httpHeader;
|
||||
|
@ -58,6 +59,7 @@ import de.anomic.server.serverCore;
|
|||
import de.anomic.server.serverInstantThread;
|
||||
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.yacySeed;
|
||||
|
||||
|
@ -70,7 +72,9 @@ public class ConfigBasic {
|
|||
|
||||
|
||||
public static serverObjects respond(httpHeader header, serverObjects post, serverSwitch env) {
|
||||
|
||||
// return variable that accumulates replacements
|
||||
ConfigBasic config = new ConfigBasic();
|
||||
plasmaSwitchboard sb = (plasmaSwitchboard) env;
|
||||
serverObjects prop = new serverObjects();
|
||||
String langPath = new File(env.getRootPath(), env.getConfig("langPath", "DATA/LOCALE")).toString();
|
||||
|
@ -83,11 +87,40 @@ public class ConfigBasic {
|
|||
return prop;
|
||||
}
|
||||
|
||||
// reconfigure port forwarding
|
||||
if ((post != null)) config.reinitPortForwarding(post, env);
|
||||
|
||||
// starting a peer ping
|
||||
boolean doPeerPing = false;
|
||||
if ((yacyCore.seedDB.mySeed.isVirgin()) || (yacyCore.seedDB.mySeed.isJunior())) {
|
||||
serverInstantThread.oneTimeJob(sb.yc, "peerPing", null, 0);
|
||||
try {Thread.sleep(3000);} catch (InterruptedException e) {} // wait a little bit for success of ping
|
||||
doPeerPing = true;
|
||||
}
|
||||
|
||||
// scan for Upnp routers
|
||||
long begin = System.currentTimeMillis();
|
||||
boolean upnpRouterFound = config.findUPnPRouter(3000);
|
||||
long end = System.currentTimeMillis();
|
||||
|
||||
// if the upnp router scan has taken less than 3 sec, we need to wait
|
||||
// a little bit for success of peer ping
|
||||
if ((doPeerPing) && ((end - begin) < 3000 )) {
|
||||
try {Thread.sleep(3000-(end - begin));} catch (InterruptedException e) {/* */}
|
||||
}
|
||||
|
||||
// if a UPnP router is available
|
||||
String currentForwarder = env.getConfig("portForwarding.Type", "none");
|
||||
boolean forwardingEnabled = env.getConfigBool("portForwarding.Enabled",false);
|
||||
boolean otherForwarderEnabled = serverCore.portForwardingEnabled && serverCore.portForwarding != null && !currentForwarder.equalsIgnoreCase("upnp");
|
||||
if (otherForwarderEnabled) {
|
||||
prop.put("upnp",0);
|
||||
} else {
|
||||
prop.put("upnp", upnpRouterFound ? 1 : 0);
|
||||
}
|
||||
|
||||
// if UPnp is already enabled
|
||||
prop.put("upnp_enabled", currentForwarder.equalsIgnoreCase("upnp") && forwardingEnabled ? 1 : 0);
|
||||
|
||||
// language settings
|
||||
if ((post != null) && (!(post.get("language", "default").equals(lang)))) {
|
||||
translator.changeLang(env, langPath, post.get("language", "default") + ".lng");
|
||||
|
@ -201,4 +234,80 @@ public class ConfigBasic {
|
|||
return prop;
|
||||
}
|
||||
|
||||
private boolean findUPnPRouter(int timeout) {
|
||||
|
||||
// determine if the upnp port forwarding class is available and load it dynamically
|
||||
Object[] UpnpForwarder = this.getUpnpForwarderClasses();
|
||||
serverPortForwarding upnp = (serverPortForwarding) UpnpForwarder[0];
|
||||
Method scanForRouter = (Method) UpnpForwarder[1];
|
||||
if ((upnp == null) || (scanForRouter == null)) return false;
|
||||
|
||||
// trying to find a upnp router
|
||||
try {
|
||||
Object result = scanForRouter.invoke(upnp, new Object[]{new Integer(timeout)});
|
||||
if ((result != null)&&(result instanceof Boolean)) {
|
||||
return ((Boolean)result).booleanValue();
|
||||
}
|
||||
} catch (Exception e) {/* ignore this error */
|
||||
} catch (Error e) {/* ignore this error */}
|
||||
return false;
|
||||
}
|
||||
|
||||
private Object[] getUpnpForwarderClasses() {
|
||||
serverPortForwarding upnp = null;
|
||||
Method scanForRouter = null;
|
||||
|
||||
try {
|
||||
|
||||
// trying to load the upnp forwarder class
|
||||
Class forwarderClass = Class.forName("de.anomic.server.portForwarding.upnp.serverPortForwardingUpnp");
|
||||
// create a new instance
|
||||
upnp = (serverPortForwarding) forwarderClass.newInstance();
|
||||
// trying to get the proper method for router scanning
|
||||
scanForRouter = upnp.getClass().getMethod("routerAvailable", new Class[] {int.class});
|
||||
|
||||
} catch (Exception e) {/* ignore this error */
|
||||
} catch (Error e) {/* ignore this error */}
|
||||
|
||||
return new Object[]{upnp,scanForRouter};
|
||||
}
|
||||
|
||||
private void reinitPortForwarding(serverObjects post, serverSwitch env) {
|
||||
if ((post != null)) {
|
||||
try {
|
||||
boolean reinitPortForwarding = false;
|
||||
|
||||
if (post.containsKey("enableUpnp")) {
|
||||
// upnp should be enabled
|
||||
env.setConfig("portForwarding.Enabled","true");
|
||||
env.setConfig("portForwarding.Type", "upnp");
|
||||
reinitPortForwarding = true;
|
||||
} else {
|
||||
String currentForwarder = env.getConfig("portForwarding.Type", "none");
|
||||
boolean otherForwarderEnabled = serverCore.portForwardingEnabled && serverCore.portForwarding != null && !currentForwarder.equalsIgnoreCase("upnp");
|
||||
|
||||
// if no other forwarder is running we deactivate forwarding
|
||||
// and try to stop an eventually running upnp forwarder
|
||||
if (!otherForwarderEnabled) {
|
||||
env.setConfig("portForwarding.Enabled","false");
|
||||
env.setConfig("portForwarding.Type", "none");
|
||||
reinitPortForwarding = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (reinitPortForwarding) {
|
||||
if ((serverCore.portForwardingEnabled) && (serverCore.portForwarding != null)) {
|
||||
// trying to shutdown the current port forwarding channel
|
||||
serverCore.portForwarding.disconnect();
|
||||
}
|
||||
|
||||
// trying to reinitialize the port forwarding
|
||||
serverCore httpd = (serverCore) env.getThread("10_httpd");
|
||||
httpd.initPortForwarding();
|
||||
}
|
||||
|
||||
} catch (Exception e) { /* */ }
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -497,6 +497,8 @@ public final class plasmaCrawlWorker extends Thread {
|
|||
// if the response has not the right response type then reject file
|
||||
log.logInfo("REJECTED WRONG STATUS TYPE '" + res.status + "' for URL " + url.toString());
|
||||
// not processed any further
|
||||
|
||||
// TODO: add the url into the error url DB
|
||||
}
|
||||
|
||||
if (remote != null) remote.close();
|
||||
|
|
|
@ -57,13 +57,11 @@ import de.anomic.server.logging.serverLog;
|
|||
import de.anomic.server.portForwarding.serverPortForwarding;
|
||||
|
||||
public class serverPortForwardingUpnp implements serverPortForwarding {
|
||||
private InternetGatewayDevice gateway;
|
||||
|
||||
private String localHost;
|
||||
private int localHostPort;
|
||||
|
||||
private InternetGatewayDevice gateway;
|
||||
private String localHost;
|
||||
private int localHostPort;
|
||||
private String externalAddress = null;
|
||||
|
||||
private serverLog log;
|
||||
|
||||
public serverPortForwardingUpnp() {
|
||||
|
@ -126,6 +124,16 @@ public class serverPortForwardingUpnp implements serverPortForwarding {
|
|||
throw new IOException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public boolean routerAvailable(int timeout) {
|
||||
try {
|
||||
InternetGatewayDevice[] IGDs = InternetGatewayDevice.getDevices(timeout);
|
||||
return (IGDs != null) && (IGDs.length > 0);
|
||||
} catch (Exception e) {
|
||||
this.log.logSevere("Unable to determine available routers: " + e.getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void disconnect() throws IOException {
|
||||
if (this.gateway == null) throw new IOException("No connection established.");
|
||||
|
|
Loading…
Reference in New Issue
Block a user