Files
i2p.i2p/apps/routerconsole/java/src/net/i2p/router/web/ConfigUpdateHelper.java

189 lines
7.5 KiB
Java
Raw Normal View History

package net.i2p.router.web;
import net.i2p.I2PAppContext;
import net.i2p.crypto.TrustedUpdate;
import net.i2p.data.DataHelper;
import net.i2p.util.PortMapper;
public class ConfigUpdateHelper extends HelperBase {
private boolean _dontInstall;
public ConfigUpdateHelper() {}
/** hook this so we can call dontInstall() once after getting a context */
@Override
public void setContextId(String contextId) {
super.setContextId(contextId);
Big refactor of the router console update subsystem, in preparation for implementing out-of-console updaters like i2psnark. - Add new update interfaces in net.i2p.update - All update implementations moved to routerconsole update/ - Implement an UpdateManager that registers with the RouterContext - UpdateManager handles multiple types of things to update (router, plugins, news, ...) and methods of updating (HTTP, ...) - UpdateManager maintains list of installed, downloaded, and available versions of everything - Define Updaters that can check for a new version and/or download an item - Individual Updaters register with the UpdateManager obtained from I2PAppContext, identifying the type of update item and update method they can handle. - Updaters need only core libs, no router.jar or routerconsole access required. - All checks and updates are initiated via the UpdateManager. - All status on checks and updates in-progress or completed are obtained from the UpdateManager. No more use of System properties to broadcast update state. - All update and checker tasks are intantiated on demand and threaded; no more static references left over. - Split out the Runners and Checkers from the Handlers and make the inheritance more sane. - No more permanent NewsFetcher thread; run on the SimpleScheduler queue and thread a checker task only to fetch the news. - No more static NewsFetcher instance in routerconsole. All helper methods that are still required are moved to NewsHelper. The UpdateManager implements the policy for when to check and download. All requests go through the UpdateManager. For each update type, there's several parts: - The xxxUpdateHandler implements the Updater - The xxxUpdateChecker implements the UpdateTask for checking - The xxxUpdateRunner implements the UpdateTask for downloading New and moved classes: web/ update/ ---- ------- new ConsoleUpdateManager.java new PluginUpdateChecker.java from PluginUpdateChecker PluginUpdateChecker -> PluginUpdateHandler.java PluginUpdateHandler.java -> PluginUpdateRunner new UnsignedUpdateHandler.java UnsignedUpdateHandler -> UnsignedUpdateRunner.java new UnsignedUpdateChecker from NewsFetcher UpdateHandler.java remains new UpdateHandler.java new UpdateRunner.java from UpdateHandler move NewsHandler from NewsFetcher new NewsFetcher new NewsTimerTask new DummyHandler Initial checkin. Unfinished, untested, unpolished.
2012-06-18 22:09:45 +00:00
_dontInstall = NewsHelper.dontInstall(_context);
}
public boolean canInstall() {
return !_dontInstall;
}
public boolean updateAvailable() {
return true;
}
public String getNewsURL() {
return getNewsURL(_context);
}
/** hack to replace the old news location with the new one, even if they have saved
the update page at some point */
public static String getNewsURL(I2PAppContext ctx) {
String url = ctx.getProperty(ConfigUpdateHandler.PROP_NEWS_URL);
if (url != null && !url.equals(ConfigUpdateHandler.OLD_DEFAULT_NEWS_URL) &&
2015-07-07 13:38:44 +00:00
!url.equals(ConfigUpdateHandler.DEFAULT_NEWS_URL) &&
!url.equals(ConfigUpdateHandler.OLD_DEFAULT_NEWS_URL_SU3))
return url;
else
return ConfigUpdateHandler.DEFAULT_NEWS_URL_SU3;
}
public String getUpdateURL() {
String url = _context.getProperty(ConfigUpdateHandler.PROP_UPDATE_URL);
if (url != null)
return url.replace(",", "\n");
else
return ConfigUpdateHandler.DEFAULT_UPDATE_URL;
}
public String getProxyHost() {
if (isInternal())
return _t("internal") + "\" readonly=\"readonly";
return _context.getProperty(ConfigUpdateHandler.PROP_PROXY_HOST, ConfigUpdateHandler.DEFAULT_PROXY_HOST);
}
public String getProxyPort() {
if (isInternal())
return _t("internal") + "\" readonly=\"readonly";
return Integer.toString(ConfigUpdateHandler.proxyPort(_context));
}
/**
* This should almost always be true.
* @return true if settings are at defaults and proxy is registered
* @since 0.8.13
*/
private boolean isInternal() {
String host = _context.getProperty(ConfigUpdateHandler.PROP_PROXY_HOST);
String port = _context.getProperty(ConfigUpdateHandler.PROP_PROXY_PORT);
return (host == null || host.equals(ConfigUpdateHandler.DEFAULT_PROXY_HOST)) &&
(port == null || port.equals(ConfigUpdateHandler.DEFAULT_PROXY_PORT)) &&
_context.portMapper().getPort(PortMapper.SVC_HTTP_PROXY) == ConfigUpdateHandler.DEFAULT_PROXY_PORT_INT;
}
public String getUpdateThroughProxy() {
if (_context.getProperty(ConfigUpdateHandler.PROP_SHOULD_PROXY, ConfigUpdateHandler.DEFAULT_SHOULD_PROXY))
2012-03-02 22:32:45 +00:00
return "<input type=\"checkbox\" class=\"optbox\" value=\"true\" name=\"updateThroughProxy\" checked=\"checked\" >";
else
return "<input type=\"checkbox\" class=\"optbox\" value=\"true\" name=\"updateThroughProxy\" >";
}
/** @since 0.9.9 */
public String getNewsThroughProxy() {
if (_context.getProperty(ConfigUpdateHandler.PROP_SHOULD_PROXY_NEWS, ConfigUpdateHandler.DEFAULT_SHOULD_PROXY_NEWS))
return "<input type=\"checkbox\" class=\"optbox\" value=\"true\" name=\"newsThroughProxy\" checked=\"checked\" >";
else
return "<input type=\"checkbox\" class=\"optbox\" value=\"true\" name=\"newsThroughProxy\" >";
}
public String getUpdateUnsigned() {
if (_context.getBooleanProperty(ConfigUpdateHandler.PROP_UPDATE_UNSIGNED))
2012-03-02 22:32:45 +00:00
return "<input type=\"checkbox\" class=\"optbox\" value=\"true\" name=\"updateUnsigned\" checked=\"checked\" >";
else
return "<input type=\"checkbox\" class=\"optbox\" value=\"true\" name=\"updateUnsigned\" >";
}
/** @since 0.9.20 */
public String getUpdateDevSU3() {
if (_context.getBooleanProperty(ConfigUpdateHandler.PROP_UPDATE_DEV_SU3))
return "<input type=\"checkbox\" class=\"optbox\" value=\"true\" name=\"updateDevSU3\" checked=\"checked\" >";
else
return "<input type=\"checkbox\" class=\"optbox\" value=\"true\" name=\"updateDevSU3\" >";
}
2011-06-30 12:42:45 +00:00
private static final long PERIODS[] = new long[] { 12*60*60*1000l, 24*60*60*1000l,
36*60*60*1000l, 48*60*60*1000l,
3*24*60*60*1000l, 7*24*60*60*1000l,
-1l };
public String getRefreshFrequencySelectBox() {
2011-06-30 12:42:45 +00:00
String freq = _context.getProperty(ConfigUpdateHandler.PROP_REFRESH_FREQUENCY,
ConfigUpdateHandler.DEFAULT_REFRESH_FREQUENCY);
long ms = ConfigUpdateHandler.DEFAULT_REFRESH_FREQ;
try {
ms = Long.parseLong(freq);
if (ms <= 0)
ms = -1;
} catch (NumberFormatException nfe) {}
StringBuilder buf = new StringBuilder(256);
buf.append("<select name=\"refreshFrequency\">");
for (int i = 0; i < PERIODS.length; i++) {
buf.append("<option value=\"").append(PERIODS[i]);
if (PERIODS[i] == ms)
2012-03-02 22:32:45 +00:00
buf.append("\" selected=\"selected");
if (PERIODS[i] == -1)
buf.append("\">").append(_t("Never")).append("</option>\n");
else
buf.append("\">").append(_t("Every")).append(' ').append(DataHelper.formatDuration2(PERIODS[i])).append("</option>\n");
}
buf.append("</select>\n");
return buf.toString();
}
/**
* Right now the jsp hides the whole select box if _dontInstall is true but this could change
*/
public String getUpdatePolicySelectBox() {
String policy = _context.getProperty(ConfigUpdateHandler.PROP_UPDATE_POLICY, ConfigUpdateHandler.DEFAULT_UPDATE_POLICY);
StringBuilder buf = new StringBuilder(256);
buf.append("<select name=\"updatePolicy\">");
buf.append("<option value=\"notify\"");
if ("notify".equals(policy) || _dontInstall)
2012-03-02 22:32:45 +00:00
buf.append(" selected=\"selected\"");
buf.append('>').append(_t("Notify only")).append("</option>");
buf.append("<option value=\"download\"");
if (_dontInstall)
2012-03-02 22:32:45 +00:00
buf.append(" disabled=\"disabled\"");
else if ("download".equals(policy))
2012-03-02 22:32:45 +00:00
buf.append(" selected=\"selected\"");
buf.append('>').append(_t("Download and verify only")).append("</option>");
if (_context.hasWrapper()) {
buf.append("<option value=\"install\"");
if (_dontInstall)
2012-03-02 22:32:45 +00:00
buf.append(" disabled=\"disabled\"");
else if ("install".equals(policy))
2012-03-02 22:32:45 +00:00
buf.append(" selected=\"selected\"");
buf.append('>').append(_t("Download, verify, and restart")).append("</option>");
2008-12-02 19:07:58 +00:00
}
buf.append("</select>\n");
return buf.toString();
}
public String getTrustedKeys() {
return new TrustedUpdate(_context).getTrustedKeysString();
}
public String getZipURL() {
return _context.getProperty(ConfigUpdateHandler.PROP_ZIP_URL, "");
}
/** @since 0.9.20 */
public String getDevSU3URL() {
return _context.getProperty(ConfigUpdateHandler.PROP_DEV_SU3_URL, "");
}
public String getNewsStatus() {
Big refactor of the router console update subsystem, in preparation for implementing out-of-console updaters like i2psnark. - Add new update interfaces in net.i2p.update - All update implementations moved to routerconsole update/ - Implement an UpdateManager that registers with the RouterContext - UpdateManager handles multiple types of things to update (router, plugins, news, ...) and methods of updating (HTTP, ...) - UpdateManager maintains list of installed, downloaded, and available versions of everything - Define Updaters that can check for a new version and/or download an item - Individual Updaters register with the UpdateManager obtained from I2PAppContext, identifying the type of update item and update method they can handle. - Updaters need only core libs, no router.jar or routerconsole access required. - All checks and updates are initiated via the UpdateManager. - All status on checks and updates in-progress or completed are obtained from the UpdateManager. No more use of System properties to broadcast update state. - All update and checker tasks are intantiated on demand and threaded; no more static references left over. - Split out the Runners and Checkers from the Handlers and make the inheritance more sane. - No more permanent NewsFetcher thread; run on the SimpleScheduler queue and thread a checker task only to fetch the news. - No more static NewsFetcher instance in routerconsole. All helper methods that are still required are moved to NewsHelper. The UpdateManager implements the policy for when to check and download. All requests go through the UpdateManager. For each update type, there's several parts: - The xxxUpdateHandler implements the Updater - The xxxUpdateChecker implements the UpdateTask for checking - The xxxUpdateRunner implements the UpdateTask for downloading New and moved classes: web/ update/ ---- ------- new ConsoleUpdateManager.java new PluginUpdateChecker.java from PluginUpdateChecker PluginUpdateChecker -> PluginUpdateHandler.java PluginUpdateHandler.java -> PluginUpdateRunner new UnsignedUpdateHandler.java UnsignedUpdateHandler -> UnsignedUpdateRunner.java new UnsignedUpdateChecker from NewsFetcher UpdateHandler.java remains new UpdateHandler.java new UpdateRunner.java from UpdateHandler move NewsHandler from NewsFetcher new NewsFetcher new NewsTimerTask new DummyHandler Initial checkin. Unfinished, untested, unpolished.
2012-06-18 22:09:45 +00:00
return NewsHelper.status(_context);
}
}