add configreseed page

This commit is contained in:
zzz
2010-12-29 12:56:48 +00:00
parent cd58dfdf99
commit a61183303f
7 changed files with 207 additions and 12 deletions

View File

@ -12,12 +12,12 @@ public class ConfigNavHelper extends HelperBase {
private static final String pages[] =
{"", "ui", "service", "update", "tunnels",
"clients", "peer", "keyring", "logging", "stats",
"advanced" };
"reseed", "advanced" };
private static final String titles[] =
{_x("Network"), _x("UI"), _x("Service"), _x("Update"), _x("Tunnels"),
_x("Clients"), _x("Peers"), _x("Keyring"), _x("Logging"), _x("Stats"),
_x("Advanced") };
_x("Reseeding"), _x("Advanced") };
public void renderNavBar(String requestURI) throws IOException {
StringBuilder buf = new StringBuilder(1024);

View File

@ -0,0 +1,68 @@
package net.i2p.router.web;
import java.util.HashMap;
import java.util.Map;
import net.i2p.router.networkdb.reseed.Reseeder;
/**
* @since 0.8.3
*/
public class ConfigReseedHandler extends FormHandler {
private Map _settings;
@Override
protected void processForm() {
if (_action.equals(_("Save Configuration and Reseed Now"))) {
saveChanges();
boolean reseedInProgress = Boolean.valueOf(System.getProperty("net.i2p.router.web.ReseedHandler.reseedInProgress")).booleanValue();
if (reseedInProgress) {
addFormError(_("Reseeding is already in progress"));
} else {
// skip the nonce checking in ReseedHandler
addFormNotice(_("Starting reseed process"));
(new ReseedHandler(_context)).requestReseed();
}
return;
}
if (_action.equals(_("Save Configuration"))) {
saveChanges();
return;
}
addFormError(_("Unsupported") + ' ' + _action + '.');
}
public void setSettings(Map settings) { _settings = new HashMap(settings); }
/** curses Jetty for returning arrays */
private String getJettyString(String key) {
String[] arr = (String[]) _settings.get(key);
if (arr == null)
return null;
return arr[0].trim();
}
private void saveChanges() {
String port = getJettyString("port");
if (port != null)
_context.router().setConfigSetting(Reseeder.PROP_PROXY_PORT, port);
String host = getJettyString("host");
if (host != null)
_context.router().setConfigSetting(Reseeder.PROP_PROXY_HOST, host);
String url = getJettyString("reseedURL");
if (url != null)
_context.router().setConfigSetting(Reseeder.PROP_RESEED_URL, url.trim().replace("\r\n", ",").replace("\n", ","));
String mode = getJettyString("mode");
boolean req = "1".equals(mode);
boolean disabled = "2".equals(mode);
_context.router().setConfigSetting(Reseeder.PROP_SSL_REQUIRED,
Boolean.toString(req));
_context.router().setConfigSetting(Reseeder.PROP_SSL_DISABLE,
Boolean.toString(disabled));
boolean proxy = getJettyString("enable") != null;
_context.router().setConfigSetting(Reseeder.PROP_PROXY_ENABLE, Boolean.toString(proxy));
_context.router().saveConfig();
addFormNotice(_("Configuration saved successfully."));
}
}

View File

@ -0,0 +1,58 @@
package net.i2p.router.web;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.StringTokenizer;
import net.i2p.router.networkdb.reseed.Reseeder;
/**
* @since 0.8.3
*/
public class ConfigReseedHelper extends HelperBase {
public String getPort() {
return _context.getProperty(Reseeder.PROP_PROXY_PORT, "");
}
public String getHost() {
return _context.getProperty(Reseeder.PROP_PROXY_HOST, "");
}
public String modeChecked(int mode) {
boolean required = _context.getBooleanProperty(Reseeder.PROP_SSL_REQUIRED);
boolean disabled = _context.getBooleanProperty(Reseeder.PROP_SSL_DISABLE);
if ((mode == 0 && (!disabled) && (!required)) ||
(mode == 1 && (!disabled) && required) ||
(mode == 2 && disabled))
return "checked=\"true\"";
return "";
}
public String getEnable() {
boolean enabled = _context.getBooleanProperty(Reseeder.PROP_PROXY_ENABLE);
if (enabled)
return "checked=\"true\"";
return "";
}
public String getReseedURL() {
String urls = _context.getProperty(Reseeder.PROP_RESEED_URL, Reseeder.DEFAULT_SEED_URL + ',' + Reseeder.DEFAULT_SSL_SEED_URL);
StringTokenizer tok = new StringTokenizer(urls, " ,\r\n");
List<String> URLList = new ArrayList(16);
while (tok.hasMoreTokens()) {
String s = tok.nextToken().trim();
if (s.length() > 0)
URLList.add(s);
}
Collections.sort(URLList);
StringBuilder buf = new StringBuilder();
for (String s : URLList) {
if (buf.length() > 0)
buf.append('\n');
buf.append(s);
}
return buf.toString();
}
}

View File

@ -0,0 +1,59 @@
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head>
<%@include file="css.jsi" %>
<%=intl.title("config reseeding")%>
</head><body>
<%@include file="summary.jsi" %>
<jsp:useBean class="net.i2p.router.web.ConfigReseedHelper" id="reseedHelper" scope="request" />
<jsp:setProperty name="reseedHelper" property="contextId" value="<%=(String)session.getAttribute("i2p.contextId")%>" />
<h1><%=intl._("I2P Reseeding Configuration")%></h1>
<div class="main" id="main">
<%@include file="confignav.jsi" %>
<jsp:useBean class="net.i2p.router.web.ConfigReseedHandler" id="formhandler" scope="request" />
<% formhandler.storeMethod(request.getMethod()); %>
<jsp:setProperty name="formhandler" property="contextId" value="<%=(String)session.getAttribute("i2p.contextId")%>" />
<jsp:setProperty name="formhandler" property="action" value="<%=request.getParameter("action")%>" />
<jsp:setProperty name="formhandler" property="nonce" value="<%=request.getParameter("nonce")%>" />
<jsp:setProperty name="formhandler" property="settings" value="<%=request.getParameterMap()%>" />
<jsp:getProperty name="formhandler" property="allMessages" />
<div class="configure"><form action="" method="POST">
<% String prev = System.getProperty("net.i2p.router.web.ConfigReseedHandler.nonce");
if (prev != null) System.setProperty("net.i2p.router.web.ConfigReseedHandler.noncePrev", prev);
System.setProperty("net.i2p.router.web.ConfigReseedHandler.nonce", new java.util.Random().nextLong()+""); %>
<input type="hidden" name="nonce" value="<%=System.getProperty("net.i2p.router.web.ConfigReseedHandler.nonce")%>" >
<h3><%=intl._("Reseeding Configuration")%></h3>
<p><%=intl._("Reeseeding is the bootstrapping process used to find other routers when you first install I2P, or when your router has too few router references remaining.")%></b>
<%=intl._("If reseeding has failed, you should first check your network connection.")%></b>
<p><b><%=intl._("The default settings will work for most people.")%></b>
<%=intl._("Change these only if HTTP is blocked by a restrictive firewall, reseed has failed, and you have access to an HTTP proxy.")%>
<%=intl._("See {0} for instructions on reseeding manually.", "<a href=\"http://www.i2p2.de/faq.html#manual_reseed\">" + intl._("the FAQ") + "</a>")%>
</p>
<div class="wideload">
<table border="0" cellspacing="5">
<tr><td class="mediumtags" align="right"><b><%=intl._("Reseed URL Selection")%></b></td>
<td><input type="radio" class="optbox" name="mode" value="0" <%=reseedHelper.modeChecked(0) %> >
<%=intl._("Try SSL first then non-SSL")%>
<input type="radio" class="optbox" name="mode" value="1" <%=reseedHelper.modeChecked(1) %> >
<%=intl._("Use SSL only")%>
<input type="radio" class="optbox" name="mode" value="2" <%=reseedHelper.modeChecked(2) %> >
<%=intl._("Use non-SSL only")%></td></tr>
<tr><td class="mediumtags" align="right"><b><%=intl._("Reseed URLs")%></td>
<td><textarea name="reseedURL" wrap="off"><jsp:getProperty name="reseedHelper" property="reseedURL" /></textarea></td></tr>
<tr><td class="mediumtags" align="right"><b><%=intl._("Enable HTTP proxy (not used for SSL)")%></b></td>
<td><input type="checkbox" class="optbox" name="enable" value="true" <jsp:getProperty name="reseedHelper" property="enable" /> ></td></tr>
<tr><td class="mediumtags" align="right"><b><%=intl._("HTTP Proxy Host")%>:</b></td>
<td><input name="host" type="text" value="<jsp:getProperty name="reseedHelper" property="host" />" ></td></tr>
<tr><td class="mediumtags" align="right"><b><%=intl._("HTTP Proxy Port")%>:</b></td>
<td><input name="port" type="text" value="<jsp:getProperty name="reseedHelper" property="port" />" ></td></tr>
</table></div>
<hr><div class="formaction">
<input type="submit" name="foo" value="<%=intl._("Cancel")%>" />
<input type="submit" name="action" value="<%=intl._("Save Configuration and Reseed Now")%>" />
<input type="submit" name="action" value="<%=intl._("Save Configuration")%>" />
</form></div></div></body></html>

View File

@ -1,3 +1,9 @@
2010-12-29 zzz
* Console: Add 500 error page
* Reseed:
- Add new configreseed page
- Add StartCom CA cert required for www.i2pbote.net
2010-12-27 zzz
* Crypto: Cleanups and fixups
* Console:

View File

@ -18,7 +18,7 @@ public class RouterVersion {
/** deprecated */
public final static String ID = "Monotone";
public final static String VERSION = CoreVersion.VERSION;
public final static long BUILD = 2;
public final static long BUILD = 3;
/** for example "-test" */
public final static String EXTRA = "";

View File

@ -40,12 +40,12 @@ public class Reseeder {
// Reject unreasonably big files, because we download into a ByteArrayOutputStream.
private static final long MAX_RESEED_RESPONSE_SIZE = 1024 * 1024;
private static final String DEFAULT_SEED_URL =
public static final String DEFAULT_SEED_URL =
"http://a.netdb.i2p2.de/,http://b.netdb.i2p2.de/,http://c.netdb.i2p2.de/," +
"http://reseed.i2p-projekt.de/,http://www.i2pbote.net/netDb/,http://r31453.ovh.net/static_media/files/netDb/";
/** @since 0.8.2 */
private static final String DEFAULT_SSL_SEED_URL =
public static final String DEFAULT_SSL_SEED_URL =
"https://a.netdb.i2p2.de/,https://c.netdb.i2p2.de/," +
"https://www.i2pbote.net/netDb/," +
"https://r31453.ovh.net/static_media/files/netDb/";
@ -63,11 +63,8 @@ public class Reseeder {
public static final String PROP_SSL_DISABLE = "router.reseedSSLDisable";
/** @since 0.8.2 */
public static final String PROP_SSL_REQUIRED = "router.reseedSSLRequired";
private static final String RESEED_TIPS =
_x("Ensure that nothing blocks outbound HTTP, check <a target=\"_top\" href=\"logs.jsp\">logs</a> " +
"and if nothing helps, read the <a target=\"_top\" href=\"http://www.i2p2.de/faq.html\">FAQ</a> about reseeding manually.");
/** @since 0.8.3 */
public static final String PROP_RESEED_URL = "i2p.reseedURL";
public Reseeder(RouterContext ctx) {
_context = ctx;
@ -128,7 +125,9 @@ public class Reseeder {
System.out.println(
"Ensure that nothing blocks outbound HTTP, check the logs, " +
"and if nothing helps, read the FAQ about reseeding manually.");
System.setProperty(PROP_ERROR, _("Reseed failed.") + ' ' + _(RESEED_TIPS));
System.setProperty(PROP_ERROR, _("Reseed failed.") + ' ' +
_("See {0} for help.",
"<a target=\"_top\" href=\"/configreseed\">" + _("reseed configuration page") + "</a>"));
}
System.setProperty(PROP_INPROGRESS, "false");
System.clearProperty(PROP_STATUS);
@ -165,7 +164,7 @@ public class Reseeder {
*/
private int reseed(boolean echoStatus) {
List<String> URLList = new ArrayList();
String URLs = _context.getProperty("i2p.reseedURL");
String URLs = _context.getProperty(PROP_RESEED_URL);
boolean defaulted = URLs == null;
boolean SSLDisable = _context.getBooleanProperty(PROP_SSL_DISABLE);
if (defaulted) {
@ -369,6 +368,11 @@ public class Reseeder {
return Translate.getString(key, _context, BUNDLE_NAME);
}
/** translate */
private String _(String s, Object o) {
return Translate.getString(s, o, _context, BUNDLE_NAME);
}
/** translate */
private String _(String s, Object o, Object o2) {
return Translate.getString(s, o, o2, _context, BUNDLE_NAME);