From 4e68f2a157b7a8360bba0c90d86b5891cc2b817e Mon Sep 17 00:00:00 2001 From: complication Date: Wed, 26 Dec 2007 08:14:54 +0000 Subject: [PATCH] 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 --- .../i2p/router/web/ConfigUpdateHandler.java | 40 +++++++++++++------ .../i2p/router/web/ConfigUpdateHelper.java | 8 +--- .../src/net/i2p/router/web/UpdateHandler.java | 6 ++- apps/routerconsole/jsp/configupdate.jsp | 15 ++++--- .../src/net/i2p/crypto/TrustedUpdate.java | 23 ++++++++++- core/java/src/net/i2p/data/DataHelper.java | 4 ++ history.txt | 17 +++++++- router/java/src/net/i2p/router/Router.java | 4 ++ .../src/net/i2p/router/RouterVersion.java | 4 +- 9 files changed, 88 insertions(+), 33 deletions(-) diff --git a/apps/routerconsole/java/src/net/i2p/router/web/ConfigUpdateHandler.java b/apps/routerconsole/java/src/net/i2p/router/web/ConfigUpdateHandler.java index d83ce09e2..ac479e7c8 100644 --- a/apps/routerconsole/java/src/net/i2p/router/web/ConfigUpdateHandler.java +++ b/apps/routerconsole/java/src/net/i2p/router/web/ConfigUpdateHandler.java @@ -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(); } diff --git a/apps/routerconsole/java/src/net/i2p/router/web/ConfigUpdateHelper.java b/apps/routerconsole/java/src/net/i2p/router/web/ConfigUpdateHelper.java index 11954508d..ca42999f5 100644 --- a/apps/routerconsole/java/src/net/i2p/router/web/ConfigUpdateHelper.java +++ b/apps/routerconsole/java/src/net/i2p/router/web/ConfigUpdateHelper.java @@ -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(); } } diff --git a/apps/routerconsole/java/src/net/i2p/router/web/UpdateHandler.java b/apps/routerconsole/java/src/net/i2p/router/web/UpdateHandler.java index 02e5bc99f..0b71364e4 100644 --- a/apps/routerconsole/java/src/net/i2p/router/web/UpdateHandler.java +++ b/apps/routerconsole/java/src/net/i2p/router/web/UpdateHandler.java @@ -106,6 +106,8 @@ public class UpdateHandler { _startedOn = -1; _status = "Updating
"; 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); } } diff --git a/apps/routerconsole/jsp/configupdate.jsp b/apps/routerconsole/jsp/configupdate.jsp index 096f44d00..38dfe207b 100644 --- a/apps/routerconsole/jsp/configupdate.jsp +++ b/apps/routerconsole/jsp/configupdate.jsp @@ -32,18 +32,17 @@ ">
Refresh frequency:
- Update URLs: - ">
Update policy:
-Update through the eepProxy? +

Update through the eepProxy?
eepProxy host: " />
- eepProxy port: " />
- - Trusted keys: - -

+ eepProxy port: " />

+

Update URLs:
+

+

Trusted keys:
+

+
diff --git a/core/java/src/net/i2p/crypto/TrustedUpdate.java b/core/java/src/net/i2p/crypto/TrustedUpdate.java index 7c743fc7b..9c8f1ac7f 100644 --- a/core/java/src/net/i2p/crypto/TrustedUpdate.java +++ b/core/java/src/net/i2p/crypto/TrustedUpdate.java @@ -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 String 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. * diff --git a/core/java/src/net/i2p/data/DataHelper.java b/core/java/src/net/i2p/data/DataHelper.java index 6a6777475..d5c6d636d 100644 --- a/core/java/src/net/i2p/data/DataHelper.java +++ b/core/java/src/net/i2p/data/DataHelper.java @@ -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); diff --git a/history.txt b/history.txt index 5dfa3af8e..64cf2f075 100644 --- a/history.txt +++ b/history.txt @@ -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 diff --git a/router/java/src/net/i2p/router/Router.java b/router/java/src/net/i2p/router/Router.java index 08469130e..1dacd705f 100644 --- a/router/java/src/net/i2p/router/Router.java +++ b/router/java/src/net/i2p/router/Router.java @@ -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'); } } diff --git a/router/java/src/net/i2p/router/RouterVersion.java b/router/java/src/net/i2p/router/RouterVersion.java index de2b8d16c..fd783cc36 100644 --- a/router/java/src/net/i2p/router/RouterVersion.java +++ b/router/java/src/net/i2p/router/RouterVersion.java @@ -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);