Search in sources :

Example 6 with ConsoleUpdateManager

use of net.i2p.router.update.ConsoleUpdateManager in project i2p.i2p by i2p.

the class ConfigClientsHandler method installPlugin.

/**
 *  @param app null for a new install
 *  @param url http: or file:
 */
private void installPlugin(String app, String url) {
    ConsoleUpdateManager mgr = UpdateHandler.updateManager(_context);
    if (mgr == null) {
        addFormError("Update manager not registered, cannot install");
        return;
    }
    if (mgr.isUpdateInProgress()) {
        addFormError(_t("Plugin or update download already in progress."));
        return;
    }
    URI uri;
    try {
        uri = new URI(url);
    } catch (URISyntaxException use) {
        addFormError(_t("Bad URL {0}", url));
        return;
    }
    if (!url.startsWith("file:")) {
        if (uri.getScheme() == null || uri.getHost() == null || uri.getPath() == null || uri.getPath().length() <= 1) {
            addFormError(_t("Bad URL {0}", url));
            return;
        }
        if (!verifyProxy())
            return;
    }
    if (mgr.installPlugin(app, uri)) {
        if (url.startsWith("file:"))
            addFormNotice(_t("Installing plugin from {0}", uri.getPath()));
        else
            addFormNotice(_t("Downloading plugin from {0}", url));
    } else {
        addFormError("Cannot install, check logs");
    }
    // So that update() will post a status to the summary bar before we reload
    try {
        Thread.sleep(5000);
    } catch (InterruptedException ie) {
    }
}
Also used : ConsoleUpdateManager(net.i2p.router.update.ConsoleUpdateManager) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 7 with ConsoleUpdateManager

use of net.i2p.router.update.ConsoleUpdateManager in project i2p.i2p by i2p.

the class ConfigUpdateHandler method processForm.

@Override
protected void processForm() {
    if (_action == null)
        return;
    if (_action.equals(_t("Check for updates"))) {
        ConsoleUpdateManager mgr = UpdateHandler.updateManager(_context);
        if (mgr == null) {
            addFormError("Update manager not registered, cannot check");
            return;
        }
        if (mgr.isUpdateInProgress() || mgr.isCheckInProgress()) {
            addFormError(_t("Update or check already in progress"));
            return;
        }
        boolean shouldProxy = _context.getProperty(PROP_SHOULD_PROXY_NEWS, DEFAULT_SHOULD_PROXY_NEWS);
        String proxyHost = _context.getProperty(PROP_PROXY_HOST, DEFAULT_PROXY_HOST);
        int proxyPort = proxyPort(_context);
        if (shouldProxy && proxyPort == ConfigUpdateHandler.DEFAULT_PROXY_PORT_INT && proxyHost.equals(ConfigUpdateHandler.DEFAULT_PROXY_HOST) && _context.portMapper().getPort(PortMapper.SVC_HTTP_PROXY) < 0) {
            addFormError(_t("HTTP client proxy tunnel must be running"));
            return;
        }
        boolean a1 = mgr.checkAvailable(NEWS, 40 * 1000) != null;
        boolean a2 = false;
        boolean a3 = false;
        if ((!a1) && _updateDevSU3 && _devSU3URL != null && _devSU3URL.length() > 0)
            a2 = mgr.checkAvailable(ROUTER_DEV_SU3, 40 * 1000) != null;
        if ((!a2) && _updateUnsigned && _zipURL != null && _zipURL.length() > 0)
            a3 = mgr.checkAvailable(ROUTER_UNSIGNED, 40 * 1000) != null;
        if (a1 || a2 || a3) {
            if ((_updatePolicy == null) || (!_updatePolicy.equals("notify")))
                addFormNotice(_t("Update available, attempting to download now"));
            else
                addFormNotice(_t("Update available, click button on left to download"));
            // So that update() will post a status to the summary bar before we reload
            try {
                Thread.sleep(1000);
            } catch (InterruptedException ie) {
            }
        } else
            addFormNotice(_t("No update available"));
        return;
    }
    if (!_action.equals(_t("Save")))
        return;
    Map<String, String> changes = new HashMap<String, String>();
    if ((_newsURL != null) && (_newsURL.length() > 0)) {
        if (_newsURL.startsWith("https"))
            _newsThroughProxy = false;
        String oldURL = ConfigUpdateHelper.getNewsURL(_context);
        if ((oldURL == null) || (!_newsURL.equals(oldURL))) {
            if (isAdvanced()) {
                changes.put(PROP_NEWS_URL, _newsURL);
                // this invalidates the news
                changes.put(NewsHelper.PROP_LAST_CHECKED, "0");
                addFormNotice(_t("Updating news URL to {0}", _newsURL));
            } else {
                addFormError("Changing news URL disabled");
            }
        }
    }
    if (_proxyHost != null && _proxyHost.length() > 0 && !_proxyHost.equals(_t("internal"))) {
        String oldHost = _context.router().getConfigSetting(PROP_PROXY_HOST);
        if ((oldHost == null) || (!_proxyHost.equals(oldHost))) {
            changes.put(PROP_PROXY_HOST, _proxyHost);
            addFormNotice(_t("Updating proxy host to {0}", _proxyHost));
        }
    }
    if (_proxyPort != null && _proxyPort.length() > 0 && !_proxyPort.equals(_t("internal"))) {
        String oldPort = _context.router().getConfigSetting(PROP_PROXY_PORT);
        if ((oldPort == null) || (!_proxyPort.equals(oldPort))) {
            changes.put(PROP_PROXY_PORT, _proxyPort);
            addFormNotice(_t("Updating proxy port to {0}", _proxyPort));
        }
    }
    if (isAdvanced()) {
        changes.put(PROP_SHOULD_PROXY_NEWS, Boolean.toString(_newsThroughProxy));
        if (!_context.getBooleanProperty(PROP_UPDATE_DISABLED)) {
            changes.put(PROP_SHOULD_PROXY, Boolean.toString(_updateThroughProxy));
            changes.put(PROP_UPDATE_UNSIGNED, Boolean.toString(_updateUnsigned));
            changes.put(PROP_UPDATE_DEV_SU3, Boolean.toString(_updateDevSU3));
        }
    }
    String oldFreqStr = _context.getProperty(PROP_REFRESH_FREQUENCY, DEFAULT_REFRESH_FREQUENCY);
    long oldFreq = DEFAULT_REFRESH_FREQ;
    try {
        oldFreq = Long.parseLong(oldFreqStr);
    } catch (NumberFormatException nfe) {
    }
    if (_refreshFrequency != oldFreq) {
        changes.put(PROP_REFRESH_FREQUENCY, "" + _refreshFrequency);
        addFormNoticeNoEscape(_t("Updating refresh frequency to {0}", _refreshFrequency <= 0 ? _t("Never") : DataHelper.formatDuration2(_refreshFrequency)));
    }
    if ((_updatePolicy != null) && (_updatePolicy.length() > 0)) {
        String oldPolicy = _context.router().getConfigSetting(PROP_UPDATE_POLICY);
        if ((oldPolicy == null) || (!_updatePolicy.equals(oldPolicy))) {
            changes.put(PROP_UPDATE_POLICY, _updatePolicy);
            addFormNotice(_t("Updating update policy to {0}", _updatePolicy));
        }
    }
    if ((_updateURL != null) && (_updateURL.length() > 0)) {
        _updateURL = _updateURL.replace("\r\n", ",").replace("\n", ",");
        String oldURL = _context.router().getConfigSetting(PROP_UPDATE_URL);
        if ((oldURL == null) || (!_updateURL.equals(oldURL))) {
            changes.put(PROP_UPDATE_URL, _updateURL);
            addFormNotice(_t("Updating update URLs."));
        }
    }
    if ((_trustedKeys != null) && (_trustedKeys.length() > 0)) {
        _trustedKeys = _trustedKeys.replace("\r\n", ",").replace("\n", ",");
        String oldKeys = new TrustedUpdate(_context).getTrustedKeysString();
        oldKeys = oldKeys.replace("\r\n", ",");
        if (!_trustedKeys.equals(oldKeys)) {
            // note that keys are not validated here and no console error message will be generated
            if (isAdvanced()) {
                changes.put(PROP_TRUSTED_KEYS, _trustedKeys);
                addFormNotice(_t("Updating trusted keys."));
            } else {
                addFormError("Changing trusted keys disabled");
            }
        }
    }
    if ((_zipURL != null) && (_zipURL.length() > 0)) {
        String oldURL = _context.router().getConfigSetting(PROP_ZIP_URL);
        if ((oldURL == null) || (!_zipURL.equals(oldURL))) {
            if (isAdvanced()) {
                changes.put(PROP_ZIP_URL, _zipURL);
                addFormNotice(_t("Updating unsigned update URL to {0}", _zipURL));
            } else {
                addFormError("Changing unsigned update URL disabled");
            }
        }
    }
    if ((_devSU3URL != null) && (_devSU3URL.length() > 0)) {
        String oldURL = _context.router().getConfigSetting(PROP_DEV_SU3_URL);
        if ((oldURL == null) || (!_devSU3URL.equals(oldURL))) {
            if (isAdvanced()) {
                changes.put(PROP_DEV_SU3_URL, _devSU3URL);
                addFormNotice(_t("Updating signed development build URL to {0}", _devSU3URL));
            } else {
                addFormError("Changing signed update URL disabled");
            }
        }
    }
    _context.router().saveConfig(changes, null);
}
Also used : HashMap(java.util.HashMap) ConsoleUpdateManager(net.i2p.router.update.ConsoleUpdateManager) TrustedUpdate(net.i2p.crypto.TrustedUpdate)

Example 8 with ConsoleUpdateManager

use of net.i2p.router.update.ConsoleUpdateManager in project i2p.i2p by i2p.

the class NewsHelper method updateVersionDownloaded.

/**
 *  Release update only.
 *  Already downloaded but not installed version.
 *  @return null if none
 *  @since 0.9.4
 */
public static String updateVersionDownloaded() {
    ConsoleUpdateManager mgr = ConsoleUpdateManager.getInstance();
    if (mgr == null)
        return null;
    String rv = mgr.getUpdateDownloaded(ROUTER_SIGNED_SU3);
    if (rv != null)
        return rv;
    return mgr.getUpdateDownloaded(ROUTER_SIGNED);
}
Also used : ConsoleUpdateManager(net.i2p.router.update.ConsoleUpdateManager)

Example 9 with ConsoleUpdateManager

use of net.i2p.router.update.ConsoleUpdateManager in project i2p.i2p by i2p.

the class PluginStarter method updateAll.

/**
 *  inline
 *  @since 0.8.13
 */
private static void updateAll(RouterContext ctx, boolean delay) {
    List<String> plugins = getPlugins();
    Map<String, String> toUpdate = new HashMap<String, String>();
    for (String appName : plugins) {
        Properties props = pluginProperties(ctx, appName);
        String url = props.getProperty("updateURL");
        if (url != null)
            toUpdate.put(appName, url);
    }
    if (toUpdate.isEmpty())
        return;
    ConsoleUpdateManager mgr = UpdateHandler.updateManager(ctx);
    if (mgr == null)
        return;
    if (mgr.isUpdateInProgress())
        return;
    if (delay) {
        // wait for proxy
        mgr.update(TYPE_DUMMY, 3 * 60 * 1000);
        mgr.notifyProgress(null, Messages.getString("Checking for plugin updates", ctx));
        int loop = 0;
        do {
            try {
                Thread.sleep(5 * 1000);
            } catch (InterruptedException ie) {
            }
            if (loop++ > 40)
                break;
        } while (mgr.isUpdateInProgress(TYPE_DUMMY));
    }
    String proxyHost = ctx.getProperty(ConfigUpdateHandler.PROP_PROXY_HOST, ConfigUpdateHandler.DEFAULT_PROXY_HOST);
    int proxyPort = ConfigUpdateHandler.proxyPort(ctx);
    if (proxyPort == ConfigUpdateHandler.DEFAULT_PROXY_PORT_INT && proxyHost.equals(ConfigUpdateHandler.DEFAULT_PROXY_HOST) && ctx.portMapper().getPort(PortMapper.SVC_HTTP_PROXY) < 0) {
        mgr.notifyComplete(null, Messages.getString("Plugin update check failed", ctx) + " - " + Messages.getString("HTTP client proxy tunnel must be running", ctx));
        return;
    }
    if (ctx.commSystem().isDummy()) {
        mgr.notifyComplete(null, Messages.getString("Plugin update check failed", ctx) + " - " + "VM Comm System");
        return;
    }
    Log log = ctx.logManager().getLog(PluginStarter.class);
    int updated = 0;
    for (Map.Entry<String, String> entry : toUpdate.entrySet()) {
        String appName = entry.getKey();
        if (log.shouldLog(Log.WARN))
            log.warn("Checking for update plugin: " + appName);
        // blocking
        if (mgr.checkAvailable(PLUGIN, appName, 60 * 1000) == null) {
            if (log.shouldLog(Log.WARN))
                log.warn("No update available for plugin: " + appName);
            continue;
        }
        if (log.shouldLog(Log.WARN))
            log.warn("Updating plugin: " + appName);
        // non-blocking
        mgr.update(PLUGIN, appName, 30 * 60 * 1000);
        int loop = 0;
        do {
            // keep going
            try {
                Thread.sleep(5 * 1000);
            } catch (InterruptedException ie) {
            }
            if (loop++ > 48)
                break;
        } while (mgr.isUpdateInProgress(PLUGIN, appName));
        if (mgr.getUpdateAvailable(PLUGIN, appName) != null)
            updated++;
    }
    if (updated > 0)
        mgr.notifyComplete(null, ngettext("1 plugin updated", "{0} plugins updated", updated, ctx));
    else
        mgr.notifyComplete(null, Messages.getString("Plugin update check complete", ctx));
}
Also used : HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Log(net.i2p.util.Log) ConsoleUpdateManager(net.i2p.router.update.ConsoleUpdateManager) Properties(java.util.Properties) HashMap(java.util.HashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Aggregations

ConsoleUpdateManager (net.i2p.router.update.ConsoleUpdateManager)9 File (java.io.File)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 Properties (java.util.Properties)2 BufferedOutputStream (java.io.BufferedOutputStream)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 InetSocketAddress (java.net.InetSocketAddress)1 ServerSocket (java.net.ServerSocket)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 StringTokenizer (java.util.StringTokenizer)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)1 SU3File (net.i2p.crypto.SU3File)1