Updates: Fail fast if HTTP proxy is not running (ticket #1530)

Covers router, unsigned router, plugin, and news updates
This commit is contained in:
zzz
2015-04-24 16:08:08 +00:00
parent 37c6ac3a88
commit aecc95825b
9 changed files with 127 additions and 9 deletions

View File

@ -26,6 +26,7 @@ import net.i2p.router.startup.LoadClientAppsJob;
import net.i2p.router.update.ConsoleUpdateManager;
import static net.i2p.update.UpdateType.*;
import net.i2p.util.SecureFileOutputStream;
import net.i2p.util.PortMapper;
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
@ -490,6 +491,8 @@ public class ConfigClientsHandler extends FormHandler {
addFormError(_("Plugin or update download already in progress."));
return;
}
if (!verifyProxy())
return;
addFormNotice(_("Updating all plugins"));
PluginStarter.updateAll(_context);
// So that update() will post a status to the summary bar before we reload
@ -500,6 +503,7 @@ public class ConfigClientsHandler extends FormHandler {
/**
* @param app null for a new install
* @param url http: or file:
*/
private void installPlugin(String app, String url) {
ConsoleUpdateManager mgr = UpdateHandler.updateManager(_context);
@ -518,6 +522,10 @@ public class ConfigClientsHandler extends FormHandler {
addFormError(_("Bad URL {0}", url));
return;
}
if (!url.startsWith("file:")) {
if (!verifyProxy())
return;
}
if (mgr.installPlugin(app, uri)) {
if (url.startsWith("file:"))
addFormNotice(_("Installing plugin from {0}", uri.getPath()));
@ -538,6 +546,8 @@ public class ConfigClientsHandler extends FormHandler {
addFormError("Update manager not registered, cannot check");
return;
}
if (!verifyProxy())
return;
mgr.check(PLUGIN, app);
addFormNotice(_("Checking plugin {0} for updates", app));
// So that update() will post a status to the summary bar before we reload
@ -546,6 +556,27 @@ public class ConfigClientsHandler extends FormHandler {
} catch (InterruptedException ie) {}
}
/**
* Plugin checks, updates, and installs are always proxied.
* See if the proxy tunnel is available, unless we're configured
* to use something else (probably not).
* Outputs form error if returning false.
*
* @return true if available
* @since 0.9.20
*/
private boolean verifyProxy() {
String proxyHost = _context.getProperty(ConfigUpdateHandler.PROP_PROXY_HOST, ConfigUpdateHandler.DEFAULT_PROXY_HOST);
int proxyPort = ConfigUpdateHandler.proxyPort(_context);
boolean rv = !
(proxyPort == ConfigUpdateHandler.DEFAULT_PROXY_PORT_INT &&
proxyHost.equals(ConfigUpdateHandler.DEFAULT_PROXY_HOST) &&
_context.portMapper().getPort(PortMapper.SVC_HTTP_PROXY) < 0);
if (!rv)
addFormError(_("HTTP client proxy tunnel must be running"));
return rv;
}
private void startPlugin(String app) {
try {
PluginStarter.startPlugin(_context, app);