2007-12-26 Complication

* Escape both CR, LF and CR LF line breaks in Router.saveConfig()
      and unescape them in DataHelper.loadProps() to support
      saving and loading config properties with line breaks
    * Change the update URLs textbox into a textarea like keys have,
      so different URLs go on different lines
    * Modify TrustedUpdate to provide a method which supplies a key list
      delimited with CR LF line breaks
    * Modify DEFAULT_UPDATE_URL to supply a default URL list
      delimited with CR LF line breaks
    * Modify selectUpdateURL() to handle URL lists
      delimited by any kind of line breaks
    * Start saving trusted update keys
    * Improve formatting on configupdate.jsp
This commit is contained in:
complication
2007-12-26 08:14:54 +00:00
committed by zzz
parent e9bd6907d1
commit 4e68f2a157
9 changed files with 88 additions and 33 deletions

View File

@ -2,6 +2,7 @@ package net.i2p.router.web;
import net.i2p.I2PAppContext;
import net.i2p.data.DataHelper;
import net.i2p.crypto.TrustedUpdate;
import net.i2p.router.Router;
import net.i2p.router.web.ConfigServiceHandler.UpdateWrapperManagerTask;
import net.i2p.util.Log;
@ -23,9 +24,6 @@ public class ConfigUpdateHandler extends FormHandler {
public static final String DEFAULT_NEWS_URL = "http://dev.i2p.net/cgi-bin/cvsweb.cgi/i2p/news.xml?rev=HEAD";
public static final String PROP_REFRESH_FREQUENCY = "router.newsRefreshFrequency";
public static final String DEFAULT_REFRESH_FREQUENCY = 12*60*60*1000 + "";
public static final String PROP_UPDATE_URL = "router.updateURL";
// public static final String DEFAULT_UPDATE_URL = "http://dev.i2p.net/i2p/i2pupdate.sud";
public static final String DEFAULT_UPDATE_URL = "http://amiga.i2p/i2p/i2pupdate.sud,http://stats.i2p/i2p/i2pupdate.sud,http://complication.i2p/i2p/i2pupdate.sud";
public static final String PROP_UPDATE_POLICY = "router.updatePolicy";
public static final String DEFAULT_UPDATE_POLICY = "notify";
public static final String PROP_SHOULD_PROXY = "router.updateThroughProxy";
@ -35,6 +33,16 @@ public class ConfigUpdateHandler extends FormHandler {
public static final String PROP_PROXY_PORT = "router.updateProxyPort";
public static final String DEFAULT_PROXY_PORT = "4444";
public static final String PROP_UPDATE_URL = "router.updateURL";
// public static final String DEFAULT_UPDATE_URL = "http://dev.i2p.net/i2p/i2pupdate.sud";
public static final String DEFAULT_UPDATE_URL =
"http://amiga.i2p/i2p/i2pupdate.sud\r\n" +
"http://stats.i2p/i2p/i2pupdate.sud\r\n" +
"http://complication.i2p/i2p/i2pupdate.sud";
public static final String PROP_TRUSTED_KEYS = "router.trustedUpdateKeys";
protected void processForm() {
if ("Check for update now".equals(_action)) {
NewsFetcher fetcher = NewsFetcher.getInstance(I2PAppContext.getGlobalContext());
@ -53,14 +61,6 @@ public class ConfigUpdateHandler extends FormHandler {
}
}
if ( (_updateURL != null) && (_updateURL.length() > 0) ) {
String oldURL = _context.router().getConfigSetting(PROP_UPDATE_URL);
if ( (oldURL == null) || (!_updateURL.equals(oldURL)) ) {
_context.router().setConfigSetting(PROP_UPDATE_URL, _updateURL);
addFormNotice("Updating update URL to " + _updateURL);
}
}
if ( (_proxyHost != null) && (_proxyHost.length() > 0) ) {
String oldHost = _context.router().getConfigSetting(PROP_PROXY_HOST);
if ( (oldHost == null) || (!_proxyHost.equals(oldHost)) ) {
@ -99,8 +99,22 @@ public class ConfigUpdateHandler extends FormHandler {
addFormNotice("Updating update policy to " + _updatePolicy);
}
}
// should save the keys...
if ( (_updateURL != null) && (_updateURL.length() > 0) ) {
String oldURL = _context.router().getConfigSetting(PROP_UPDATE_URL);
if ( (oldURL == null) || (!_updateURL.equals(oldURL)) ) {
_context.router().setConfigSetting(PROP_UPDATE_URL, _updateURL);
addFormNotice("Updating update URLs.");
}
}
if ( (_trustedKeys != null) && (_trustedKeys.length() > 0) ) {
String oldKeys = new TrustedUpdate(_context).getTrustedKeysString();
if ( (oldKeys == null) || (!_trustedKeys.equals(oldKeys)) ) {
_context.router().setConfigSetting(PROP_TRUSTED_KEYS, _trustedKeys);
addFormNotice("Updating trusted keys.");
}
}
_context.router().saveConfig();
}

View File

@ -1,6 +1,5 @@
package net.i2p.router.web;
import java.util.List;
import net.i2p.data.DataHelper;
import net.i2p.crypto.TrustedUpdate;
import net.i2p.router.RouterContext;
@ -113,11 +112,6 @@ public class ConfigUpdateHelper {
}
public String getTrustedKeys() {
StringBuffer buf = new StringBuffer(1024);
TrustedUpdate up = new TrustedUpdate(_context);
List keys = up.getTrustedKeys();
for (int i = 0; i < keys.size(); i++)
buf.append((String)keys.get(i)).append('\n');
return buf.toString();
return new TrustedUpdate(_context).getTrustedKeysString();
}
}

View File

@ -106,6 +106,8 @@ public class UpdateHandler {
_startedOn = -1;
_status = "<b>Updating</b><br />";
String updateURL = selectUpdateURL();
if (_log.shouldLog(Log.DEBUG))
_log.debug("Selected update URL: " + updateURL);
boolean shouldProxy = Boolean.valueOf(_context.getProperty(ConfigUpdateHandler.PROP_SHOULD_PROXY, ConfigUpdateHandler.DEFAULT_SHOULD_PROXY)).booleanValue();
String proxyHost = _context.getProperty(ConfigUpdateHandler.PROP_PROXY_HOST, ConfigUpdateHandler.DEFAULT_PROXY_HOST);
String port = _context.getProperty(ConfigUpdateHandler.PROP_PROXY_PORT, ConfigUpdateHandler.DEFAULT_PROXY_PORT);
@ -182,16 +184,18 @@ public class UpdateHandler {
private String selectUpdateURL() {
String URLs = _context.getProperty(ConfigUpdateHandler.PROP_UPDATE_URL, ConfigUpdateHandler.DEFAULT_UPDATE_URL);
StringTokenizer tok = new StringTokenizer(URLs, ",");
StringTokenizer tok = new StringTokenizer(URLs, "\r\n");
List URLList = new ArrayList();
while (tok.hasMoreTokens())
URLList.add(tok.nextToken().trim());
int size = URLList.size();
_log.log(Log.DEBUG, "Picking update source from " + size + " candidates.");
if (size <= 0) {
_log.log(Log.WARN, "Update list is empty - no update available");
return null;
}
int index = I2PAppContext.getGlobalContext().random().nextInt(size);
_log.log(Log.DEBUG, "Picked update source " + index + ".");
return (String) URLList.get(index);
}
}

View File

@ -32,18 +32,17 @@
<input type="text" size="60" name="newsURL" value="<jsp:getProperty name="updatehelper" property="newsURL" />"><br />
Refresh frequency:
<jsp:getProperty name="updatehelper" property="refreshFrequencySelectBox" /><br />
Update URLs:
<input type="text" size="90" name="updateURL" value="<jsp:getProperty name="updatehelper" property="updateURL" />"><br />
Update policy:
<jsp:getProperty name="updatehelper" property="updatePolicySelectBox" /><br />
Update through the eepProxy?
<p>Update through the eepProxy?
<jsp:getProperty name="updatehelper" property="updateThroughProxy" /><br />
eepProxy host: <input type="text" size="10" name="proxyHost" value="<jsp:getProperty name="updatehelper" property="proxyHost" />" /><br />
eepProxy port: <input type="text" size="4" name="proxyPort" value="<jsp:getProperty name="updatehelper" property="proxyPort" />" /><br />
<!-- prompt for the eepproxy -->
Trusted keys:
<textarea name="trustedKeys" cols="60" rows="2"><jsp:getProperty name="updatehelper" property="trustedKeys" /></textarea>
<br /><br />
eepProxy port: <input type="text" size="4" name="proxyPort" value="<jsp:getProperty name="updatehelper" property="proxyPort" />" /></p>
<p>Update URLs:<br />
<textarea name="updateURL" cols="90" rows="4"><jsp:getProperty name="updatehelper" property="updateURL" /></textarea></p>
<p>Trusted keys:</br />
<textarea name="trustedKeys" cols="90" rows="4"><jsp:getProperty name="updatehelper" property="trustedKeys" /></textarea></p>
<br />
<input type="submit" name="action" value="Save" />
</form>
</div>

View File

@ -92,7 +92,7 @@ jP69nPbh4KLGhF+SD0+0bW4=
String propertyTrustedKeys = context.getProperty(PROP_TRUSTED_KEYS);
if ( (propertyTrustedKeys != null) && (propertyTrustedKeys.length() > 0) ) {
StringTokenizer propertyTrustedKeysTokens = new StringTokenizer(propertyTrustedKeys, ",");
StringTokenizer propertyTrustedKeysTokens = new StringTokenizer(propertyTrustedKeys, "\r\n");
while (propertyTrustedKeysTokens.hasMoreTokens())
_trustedKeys.add(propertyTrustedKeysTokens.nextToken().trim());
@ -100,6 +100,8 @@ jP69nPbh4KLGhF+SD0+0bW4=
} else {
_trustedKeys.add(DEFAULT_TRUSTED_KEY);
}
if (_log.shouldLog(Log.DEBUG))
_log.debug("TrustedUpdate created, trusting " + _trustedKeys.size() + " keys.");
}
/**
@ -274,7 +276,26 @@ jP69nPbh4KLGhF+SD0+0bW4=
public ArrayList getTrustedKeys() {
return _trustedKeys;
}
/**
* Fetches the trusted keys for the current instance.
*
* @return A <code>String</code> containing the trusted keys,
* delimited by CR LF line breaks.
*/
public String getTrustedKeysString() {
StringBuffer buf = new StringBuffer(1024);
for (int i = 0; i < _trustedKeys.size(); i++) {
// If something already buffered, first add line break.
if (buf.length() > 0) buf.append("\r\n");
buf.append((String) _trustedKeys.get(i));
}
return buf.toString();
}
/**
* Reads the version string from a signed update file.
*

View File

@ -236,6 +236,10 @@ public class DataHelper {
if (split <= 0) continue;
String key = line.substring(0, split);
String val = line.substring(split+1);
// Unescape line breaks after loading.
// Remember: "\" needs escaping both for regex and string.
val = val.replaceAll("\\\\r","\r");
val = val.replaceAll("\\\\n","\n");
if ( (key.length() > 0) && (val.length() > 0) )
if (forceLowerCase)
props.setProperty(key.toLowerCase(), val);

View File

@ -1,4 +1,19 @@
$Id: history.txt,v 1.601 2007-12-10 17:23:00 zzz Exp $
$Id: history.txt,v 1.602 2007-12-22 18:58:48 zzz Exp $
2007-12-26 Complication
* Escape both CR, LF and CR LF line breaks in Router.saveConfig()
and unescape them in DataHelper.loadProps() to support
saving and loading config properties with line breaks
* Change the update URLs textbox into a textarea like keys have,
so different URLs go on different lines
* Modify TrustedUpdate to provide a method which supplies a key list
delimited with CR LF line breaks
* Modify DEFAULT_UPDATE_URL to supply a default URL list
delimited with CR LF line breaks
* Modify selectUpdateURL() to handle URL lists
delimited by any kind of line breaks
* Start saving trusted update keys
* Improve formatting on configupdate.jsp
2007-12-22 zzz
* Add support for multiple update URLs

View File

@ -939,6 +939,10 @@ public class Router {
for (Iterator iter = ordered.iterator() ; iter.hasNext(); ) {
String key = (String)iter.next();
String val = _config.getProperty(key);
// Escape line breaks before saving.
// Remember: "\" needs escaping both for regex and string.
val = val.replaceAll("\\r","\\\\r");
val = val.replaceAll("\\n","\\\\n");
buf.append(key).append('=').append(val).append('\n');
}
}

View File

@ -15,9 +15,9 @@ import net.i2p.CoreVersion;
*
*/
public class RouterVersion {
public final static String ID = "$Revision: 1.536 $ $Date: 2007-12-10 17:22:59 $";
public final static String ID = "$Revision: 1.537 $ $Date: 2007-12-22 18:58:46 $";
public final static String VERSION = "0.6.1.30";
public final static long BUILD = 8;
public final static long BUILD = 9;
public static void main(String args[]) {
System.out.println("I2P Router version: " + VERSION + "-" + BUILD);
System.out.println("Router ID: " + RouterVersion.ID);