diff --git a/htroot/ConfigBasic.html b/htroot/ConfigBasic.html index cc9fb5c81..36a1e802d 100644 --- a/htroot/ConfigBasic.html +++ b/htroot/ConfigBasic.html @@ -11,6 +11,8 @@ document.getElementById("value").value=element.value; } --> + + #(reconnect)#::#(/reconnect)# #%env/templates/header.template%# @@ -39,7 +41,7 @@ Your YaCy Peer needs some basic information to operate properly

What you should do next:
-#(nextStep)# +#(nextStep)# Your basic configuration is complete! You can now (for example):

:: + You did not set a user name and/or a password. Some pages are protected by passwords. You should set a password here to secure your YaCy peer.:: + Your Peer name is a default name; please set another peer name. If this does not work, the name is probably taken by someone else. Please try to choose another one.:: -You did not open a port in your firewall or your router does not forward the server port to your peer. This is needed if you want to fully participate in the YaCy network. You can also use your peer without opening it, but this is not recomended. + +You did not open a port in your firewall or your router does not forward the server port to your peer. This is needed if you want to fully participate in the YaCy network. You can also use your peer without opening it, but this is not recomended.:: + +The peer port was changed successfully. Your browser will be redirected to the new location in 10 seconds. #(/nextStep)# #%env/templates/footer.template%# diff --git a/htroot/ConfigBasic.java b/htroot/ConfigBasic.java index 09b961b76..9aa64fa6b 100644 --- a/htroot/ConfigBasic.java +++ b/htroot/ConfigBasic.java @@ -62,6 +62,12 @@ import de.anomic.yacy.yacyCore; import de.anomic.yacy.yacySeed; public class ConfigBasic { + private static final int NEXTSTEP_FINISHED = 0; + private static final int NEXTSTEP_PWD = 1; + private static final int NEXTSTEP_PEERNAME = 2; + private static final int NEXTSTEP_PEERPORT = 3; + private static final int NEXTSTEP_RECONNECT = 4; + public static serverObjects respond(httpHeader header, serverObjects post, serverSwitch env) { // return variable that accumulates replacements @@ -121,11 +127,26 @@ public class ConfigBasic { } // check port + boolean reconnect = false; if (!env.getConfig("port", port).equals(port)) { // validate port serverCore theServerCore = (serverCore) env.getThread("10_httpd"); env.setConfig("port", port); - theServerCore.reconnect(); + + // redirect the browser to the new port + reconnect = true; + prop.put("reconnect", 1); + prop.put("reconnect_host", serverCore.publicLocalIP().getHostAddress()); + prop.put("nextStep_host", serverCore.publicLocalIP().getHostAddress()); + prop.put("reconnect_port", port); + prop.put("nextStep_port", port); + prop.put("reconnect_sslSupport", theServerCore.withSSL() ? 1:0); + prop.put("nextStep_sslSupport", theServerCore.withSSL() ? 1:0); + + // force reconnection in 7 seconds + theServerCore.reconnect(7000); + } else { + prop.put("reconnect", 0); } // check if values are proper @@ -140,21 +161,19 @@ public class ConfigBasic { prop.put("statusName", (properName) ? 1 : 0); prop.put("statusPassword", (properPW) ? 1 : 0); prop.put("statusPort", (properPort) ? 1 : 0); - if (properPW) { - if (properName) { - if (properPort) { - prop.put("nextStep", 0); - } else { - prop.put("nextStep", 3); - } - } else { - prop.put("nextStep", 2); - } + if (reconnect) { + prop.put("nextStep", NEXTSTEP_RECONNECT); + } else if (!properPW) { + prop.put("nextStep", NEXTSTEP_PWD); + } else if (!properName) { + prop.put("nextStep", NEXTSTEP_PEERNAME); + } else if (!properPort) { + prop.put("nextStep", NEXTSTEP_PEERPORT); } else { - prop.put("nextStep", 1); + prop.put("nextStep", NEXTSTEP_FINISHED); } - // set default values + // set default values prop.put("defaultName", env.getConfig("peerName", "")); prop.put("defaultUser", "admin"); prop.put("defaultPort", env.getConfig("port", "8080")); diff --git a/source/de/anomic/server/serverCore.java b/source/de/anomic/server/serverCore.java index 70c5694b5..94c17e3ec 100644 --- a/source/de/anomic/server/serverCore.java +++ b/source/de/anomic/server/serverCore.java @@ -64,6 +64,8 @@ import java.net.URL; import java.net.UnknownHostException; import java.nio.channels.ClosedByInterruptException; import java.security.KeyStore; +import java.security.PublicKey; +import java.security.cert.Certificate; import java.util.Enumeration; import java.util.Hashtable; @@ -71,6 +73,7 @@ import javax.net.ssl.HandshakeCompletedEvent; import javax.net.ssl.HandshakeCompletedListener; import javax.net.ssl.KeyManagerFactory; import javax.net.ssl.SSLContext; +import javax.net.ssl.SSLSession; import javax.net.ssl.SSLSocket; import javax.net.ssl.SSLSocketFactory; @@ -203,6 +206,10 @@ public final class serverCore extends serverAbstractThread implements serverThre init(); } + public boolean withSSL() { + return this.sslSocketFactory != null; + } + public synchronized void init() { this.log.logInfo("Initializing serverCore ..."); @@ -1291,8 +1298,10 @@ public final class serverCore extends serverAbstractThread implements serverThre if (currentThread.isInterrupted()) throw new InterruptedException(); if ((currentThread instanceof serverCore.Session) && ((serverCore.Session)currentThread).isStopped()) throw new InterruptedException(); } - public void reconnect() { + this.reconnect(5000); + } + public void reconnect(int delay) { Thread restart = new Restarter(); restart.start(); } @@ -1300,10 +1309,11 @@ public final class serverCore extends serverAbstractThread implements serverThre // restarting the serverCore public class Restarter extends Thread { public serverCore theServerCore = null; + public int delay = 5000; public void run() { // waiting for a while try { - Thread.sleep(5000); + Thread.sleep(delay); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -1372,7 +1382,7 @@ public final class serverCore extends serverAbstractThread implements serverThre sock.getInetAddress().getHostName(), sock.getPort(), true); - + sslsock.addHandshakeCompletedListener( new HandshakeCompletedListener() { public void handshakeCompleted( diff --git a/source/yacy.java b/source/yacy.java index ecc50a8cf..a74667a6b 100644 --- a/source/yacy.java +++ b/source/yacy.java @@ -384,7 +384,7 @@ public final class yacy { boolean properPW = (sb.getConfig("adminAccount", "").length() == 0) && (sb.getConfig("adminAccountBase64MD5", "").length() > 0); if (!properPW) browserPopUpPage = "ConfigBasic.html"; final String browserPopUpApplication = sb.getConfig("browserPopUpApplication", "netscape"); - serverSystem.openBrowser("http://localhost:" + serverCore.getPortNr(port) + "/" + browserPopUpPage, browserPopUpApplication); + serverSystem.openBrowser((server.withSSL()?"https":"http") + "://localhost:" + serverCore.getPortNr(port) + "/" + browserPopUpPage, browserPopUpApplication); } //Copy the shipped locales into DATA @@ -460,7 +460,7 @@ public final class yacy { server.terminate(false); server.interrupt(); if (server.isAlive()) try { - URL u = new URL("http://localhost:" + serverCore.getPortNr(port)); + URL u = new URL((server.withSSL()?"https":"http")+"://localhost:" + serverCore.getPortNr(port)); httpc.wget(u, u.getHost(), 1000, null, null, null); // kick server serverLog.logConfig("SHUTDOWN", "sent termination signal to server socket"); } catch (IOException ee) {