2005-03-23 21:13:03 +00:00
|
|
|
package net.i2p.router.web;
|
|
|
|
|
2009-06-19 00:04:19 +00:00
|
|
|
import net.i2p.I2PAppContext;
|
2005-03-23 21:13:03 +00:00
|
|
|
import net.i2p.crypto.TrustedUpdate;
|
2008-07-16 13:42:54 +00:00
|
|
|
import net.i2p.data.DataHelper;
|
2005-03-23 21:13:03 +00:00
|
|
|
|
2009-01-29 02:16:18 +00:00
|
|
|
public class ConfigUpdateHelper extends HelperBase {
|
2010-02-02 15:25:26 +00:00
|
|
|
private boolean _dontInstall;
|
|
|
|
|
2005-03-23 21:13:03 +00:00
|
|
|
public ConfigUpdateHelper() {}
|
|
|
|
|
2010-02-02 15:25:26 +00:00
|
|
|
/** hook this so we can call dontInstall() once after getting a context */
|
|
|
|
@Override
|
|
|
|
public void setContextId(String contextId) {
|
|
|
|
super.setContextId(contextId);
|
|
|
|
_dontInstall = NewsFetcher.getInstance(_context).dontInstall();
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean canInstall() {
|
|
|
|
return !_dontInstall;
|
|
|
|
}
|
|
|
|
|
2005-03-23 21:13:03 +00:00
|
|
|
public boolean updateAvailable() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getNewsURL() {
|
2009-06-19 00:04:19 +00:00
|
|
|
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))
|
2005-03-23 21:13:03 +00:00
|
|
|
return url;
|
|
|
|
else
|
|
|
|
return ConfigUpdateHandler.DEFAULT_NEWS_URL;
|
|
|
|
}
|
|
|
|
public String getUpdateURL() {
|
|
|
|
String url = _context.getProperty(ConfigUpdateHandler.PROP_UPDATE_URL);
|
|
|
|
if (url != null)
|
2010-10-19 14:39:29 +00:00
|
|
|
return url.replace(",", "\n");
|
2005-03-23 21:13:03 +00:00
|
|
|
else
|
|
|
|
return ConfigUpdateHandler.DEFAULT_UPDATE_URL;
|
|
|
|
}
|
2005-03-24 01:19:52 +00:00
|
|
|
public String getProxyHost() {
|
2009-06-19 00:04:19 +00:00
|
|
|
return _context.getProperty(ConfigUpdateHandler.PROP_PROXY_HOST, ConfigUpdateHandler.DEFAULT_PROXY_HOST);
|
2005-03-24 01:19:52 +00:00
|
|
|
}
|
|
|
|
public String getProxyPort() {
|
2009-06-19 00:04:19 +00:00
|
|
|
return _context.getProperty(ConfigUpdateHandler.PROP_PROXY_PORT, ConfigUpdateHandler.DEFAULT_PROXY_PORT);
|
2005-03-24 01:19:52 +00:00
|
|
|
}
|
2005-03-23 21:13:03 +00:00
|
|
|
|
|
|
|
public String getUpdateThroughProxy() {
|
|
|
|
String proxy = _context.getProperty(ConfigUpdateHandler.PROP_SHOULD_PROXY, ConfigUpdateHandler.DEFAULT_SHOULD_PROXY);
|
|
|
|
if (Boolean.valueOf(proxy).booleanValue())
|
2009-07-30 23:10:48 +00:00
|
|
|
return "<input type=\"checkbox\" class=\"optbox\" value=\"true\" name=\"updateThroughProxy\" checked=\"true\" >";
|
2005-03-23 21:13:03 +00:00
|
|
|
else
|
2009-07-30 23:10:48 +00:00
|
|
|
return "<input type=\"checkbox\" class=\"optbox\" value=\"true\" name=\"updateThroughProxy\" >";
|
2005-03-23 21:13:03 +00:00
|
|
|
}
|
|
|
|
|
2009-08-09 14:28:20 +00:00
|
|
|
public String getUpdateUnsigned() {
|
|
|
|
String foo = _context.getProperty(ConfigUpdateHandler.PROP_UPDATE_UNSIGNED);
|
|
|
|
if (Boolean.valueOf(foo).booleanValue())
|
|
|
|
return "<input type=\"checkbox\" class=\"optbox\" value=\"true\" name=\"updateUnsigned\" checked=\"true\" >";
|
|
|
|
else
|
|
|
|
return "<input type=\"checkbox\" class=\"optbox\" value=\"true\" name=\"updateUnsigned\" >";
|
|
|
|
}
|
|
|
|
|
2005-03-24 01:19:52 +00:00
|
|
|
private static final long PERIODS[] = new long[] { 12*60*60*1000l, 24*60*60*1000l, 48*60*60*1000l, -1l };
|
|
|
|
|
2005-03-23 21:13:03 +00:00
|
|
|
public String getRefreshFrequencySelectBox() {
|
2005-03-24 01:19:52 +00:00
|
|
|
String freq = _context.getProperty(ConfigUpdateHandler.PROP_REFRESH_FREQUENCY);
|
|
|
|
if (freq == null) freq = ConfigUpdateHandler.DEFAULT_REFRESH_FREQUENCY;
|
|
|
|
long ms = -1;
|
|
|
|
try {
|
|
|
|
ms = Long.parseLong(freq);
|
|
|
|
} catch (NumberFormatException nfe) {}
|
|
|
|
|
2009-07-01 16:00:43 +00:00
|
|
|
StringBuilder buf = new StringBuilder(256);
|
2005-03-24 01:19:52 +00:00
|
|
|
buf.append("<select name=\"refreshFrequency\">");
|
|
|
|
for (int i = 0; i < PERIODS.length; i++) {
|
|
|
|
buf.append("<option value=\"").append(PERIODS[i]);
|
|
|
|
if (PERIODS[i] == ms)
|
|
|
|
buf.append("\" selected=\"true\"");
|
|
|
|
|
|
|
|
if (PERIODS[i] == -1)
|
2009-10-26 02:21:15 +00:00
|
|
|
buf.append("\">" + _("Never") + "</option>\n");
|
2005-03-24 01:19:52 +00:00
|
|
|
else
|
2010-11-06 12:28:38 +00:00
|
|
|
buf.append("\">" + _("Every") + " ").append(DataHelper.formatDuration2(PERIODS[i])).append("</option>\n");
|
2005-03-24 01:19:52 +00:00
|
|
|
}
|
|
|
|
buf.append("</select>\n");
|
|
|
|
return buf.toString();
|
2005-03-23 21:13:03 +00:00
|
|
|
}
|
2005-03-24 01:19:52 +00:00
|
|
|
|
2010-02-02 15:25:26 +00:00
|
|
|
/**
|
|
|
|
* Right now the jsp hides the whole select box if _dontInstall is true but this could change
|
|
|
|
*/
|
2005-03-23 21:13:03 +00:00
|
|
|
public String getUpdatePolicySelectBox() {
|
2009-06-19 00:04:19 +00:00
|
|
|
String policy = _context.getProperty(ConfigUpdateHandler.PROP_UPDATE_POLICY, ConfigUpdateHandler.DEFAULT_UPDATE_POLICY);
|
2005-03-24 01:19:52 +00:00
|
|
|
|
2009-07-01 16:00:43 +00:00
|
|
|
StringBuilder buf = new StringBuilder(256);
|
2005-03-24 01:19:52 +00:00
|
|
|
buf.append("<select name=\"updatePolicy\">");
|
|
|
|
|
2010-02-02 15:25:26 +00:00
|
|
|
buf.append("<option value=\"notify\"");
|
|
|
|
if ("notify".equals(policy) || _dontInstall)
|
|
|
|
buf.append(" selected=\"true\"");
|
|
|
|
buf.append('>').append(_("Notify only")).append("</option>");
|
2005-03-24 01:19:52 +00:00
|
|
|
|
2010-02-02 15:25:26 +00:00
|
|
|
buf.append("<option value=\"download\"");
|
|
|
|
if (_dontInstall)
|
|
|
|
buf.append(" disabled=\"true\"");
|
|
|
|
else if ("download".equals(policy))
|
|
|
|
buf.append(" selected=\"true\"");
|
|
|
|
buf.append('>').append(_("Download and verify only")).append("</option>");
|
2008-05-10 14:31:18 +00:00
|
|
|
|
2008-12-03 14:46:37 +00:00
|
|
|
if (System.getProperty("wrapper.version") != null) {
|
2010-02-02 15:25:26 +00:00
|
|
|
buf.append("<option value=\"install\"");
|
|
|
|
if (_dontInstall)
|
|
|
|
buf.append(" disabled=\"true\"");
|
|
|
|
else if ("install".equals(policy))
|
|
|
|
buf.append(" selected=\"true\"");
|
|
|
|
buf.append('>').append(_("Download, verify, and restart")).append("</option>");
|
2008-12-02 19:07:58 +00:00
|
|
|
}
|
2005-03-24 01:19:52 +00:00
|
|
|
|
|
|
|
buf.append("</select>\n");
|
|
|
|
return buf.toString();
|
2005-03-23 21:13:03 +00:00
|
|
|
}
|
2005-03-24 01:19:52 +00:00
|
|
|
|
2005-03-23 21:13:03 +00:00
|
|
|
public String getTrustedKeys() {
|
2007-12-26 08:14:54 +00:00
|
|
|
return new TrustedUpdate(_context).getTrustedKeysString();
|
2005-03-23 21:13:03 +00:00
|
|
|
}
|
2008-06-09 13:14:52 +00:00
|
|
|
|
2009-08-09 14:28:20 +00:00
|
|
|
public String getZipURL() {
|
|
|
|
return _context.getProperty(ConfigUpdateHandler.PROP_ZIP_URL, "");
|
2008-06-09 13:14:52 +00:00
|
|
|
}
|
|
|
|
|
2009-08-09 14:28:20 +00:00
|
|
|
public String getNewsStatus() {
|
|
|
|
return NewsFetcher.getInstance(_context).status();
|
2008-06-09 13:14:52 +00:00
|
|
|
}
|
2005-03-23 21:13:03 +00:00
|
|
|
}
|