Search in sources :

Example 1 with App

use of net.i2p.router.web.App in project i2p.i2p by i2p.

the class HomeHelper method buildSearchApps.

static Collection<App> buildSearchApps(String config) {
    String[] args = DataHelper.split(config, SS);
    Set<App> apps = new TreeSet<App>(new AppComparator());
    for (int i = 0; i < args.length - 1; i += 2) {
        String name = args[i];
        String url = args[i + 1];
        apps.add(new App(name, null, url, null));
    }
    return apps;
}
Also used : App(net.i2p.router.web.App) TreeSet(java.util.TreeSet)

Example 2 with App

use of net.i2p.router.web.App in project i2p.i2p by i2p.

the class HomeHelper method buildApps.

static Collection<App> buildApps(RouterContext ctx, String config) {
    String[] args = DataHelper.split(config, SS);
    Set<App> apps = new TreeSet<App>(new AppComparator());
    for (int i = 0; i < args.length - 3; i += 4) {
        String name = Messages.getString(args[i], ctx);
        String desc = Messages.getString(args[i + 1], ctx);
        String url = args[i + 2];
        String icon = args[i + 3];
        apps.add(new App(name, desc, url, icon));
    }
    return apps;
}
Also used : App(net.i2p.router.web.App) TreeSet(java.util.TreeSet)

Example 3 with App

use of net.i2p.router.web.App in project i2p.i2p by i2p.

the class NavHelper method getClientApps.

/**
 *  For HomeHelper
 *  @param ctx unused
 *  @return non-null, possibly empty
 *  @since 0.9, public since 0.9.33, was package private
 */
public static List<App> getClientApps(I2PAppContext ctx) {
    if (_apps.isEmpty())
        return Collections.emptyList();
    List<App> rv = new ArrayList<App>(_apps.size());
    for (Map.Entry<String, String> e : _apps.entrySet()) {
        String name = e.getKey();
        String path = e.getValue();
        if (path == null)
            continue;
        String tip = _tooltips.get(name);
        if (tip == null)
            tip = "";
        String icon;
        if (_icons.containsKey(name))
            icon = _icons.get(name);
        else // hardcoded hack
        if (path.equals("/i2pbote/index.jsp"))
            icon = "/themes/console/images/email.png";
        else
            icon = "/themes/console/images/plugin.png";
        App app = new App(name, tip, path, icon);
        rv.add(app);
    }
    return rv;
}
Also used : App(net.i2p.router.web.App) ArrayList(java.util.ArrayList) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 4 with App

use of net.i2p.router.web.App in project i2p.i2p by i2p.

the class ConfigHomeHandler method processForm.

@Override
protected void processForm() {
    if (_action == null)
        return;
    String group = getJettyString("group");
    boolean deleting = _action.equals(_t("Delete selected"));
    boolean adding = _action.equals(_t("Add item"));
    boolean restoring = _action.equals(_t("Restore defaults"));
    if (_action.equals(_t("Save")) && "0".equals(group)) {
        boolean old = _context.getBooleanProperty(HomeHelper.PROP_OLDHOME);
        boolean nnew = getJettyString("oldHome") != null;
        if (old != nnew) {
            _context.router().saveConfig(HomeHelper.PROP_OLDHOME, "" + nnew);
            addFormNotice(_t("Home page changed"));
        }
    } else if (adding || deleting || restoring) {
        String prop;
        String dflt;
        if ("1".equals(group)) {
            prop = HomeHelper.PROP_FAVORITES;
            dflt = HomeHelper.DEFAULT_FAVORITES;
        } else if ("2".equals(group)) {
            prop = HomeHelper.PROP_SERVICES;
            dflt = HomeHelper.DEFAULT_SERVICES;
        } else if ("3".equals(group)) {
            prop = SearchHelper.PROP_ENGINES;
            dflt = SearchHelper.ENGINES_DEFAULT;
        } else {
            addFormError("Bad group");
            return;
        }
        if (restoring) {
            // _context.router().saveConfig(prop, dflt);
            // remove config so user will see updates
            _context.router().saveConfig(prop, null);
            addFormNotice(_t("Restored default settings"));
            return;
        }
        String config = _context.getProperty(prop, dflt);
        Collection<App> apps;
        if ("3".equals(group))
            apps = HomeHelper.buildSearchApps(config);
        else
            apps = HomeHelper.buildApps(_context, config);
        if (adding) {
            String name = getJettyString("nofilter_name");
            if (name == null || name.length() <= 0) {
                addFormError(_t("No name entered"));
                return;
            }
            String url = getJettyString("nofilter_url");
            if (url == null || url.length() <= 0) {
                addFormError(_t("No URL entered"));
                return;
            }
            // these would get double-escaped so we can't do it this way...
            // name = DataHelper.escapeHTML(name).replace(",", "&#44;");
            // url = DataHelper.escapeHTML(url).replace(",", "&#44;");
            name = name.replace(",", ".");
            // fail
            url = url.replace(",", ".");
            App app = null;
            if ("1".equals(group))
                app = new App(name, "", url, "/themes/console/images/eepsite.png");
            else if ("2".equals(group))
                app = new App(name, "", url, "/themes/console/images/title_window.png");
            else
                app = new App(name, "", url, "/themes/console/images/question.png");
            apps.add(app);
            addFormNotice(_t("Added") + ": " + app.name);
        } else {
            // deleting
            Set<String> toDelete = new HashSet<String>();
            for (Object o : _settings.keySet()) {
                if (!(o instanceof String))
                    continue;
                String k = (String) o;
                if (!k.startsWith("delete_"))
                    continue;
                k = k.substring(7);
                toDelete.add(k);
            }
            for (Iterator<App> iter = apps.iterator(); iter.hasNext(); ) {
                App app = iter.next();
                if (toDelete.contains(app.name)) {
                    iter.remove();
                    addFormNotice(_t("Removed") + ": " + app.name);
                }
            }
        }
        HomeHelper.saveApps(_context, prop, apps, !("3".equals(group)));
    } else {
    // addFormError(_t("Unsupported"));
    }
}
Also used : App(net.i2p.router.web.App) HashSet(java.util.HashSet) Set(java.util.Set) Iterator(java.util.Iterator) Collection(java.util.Collection)

Example 5 with App

use of net.i2p.router.web.App in project i2p.i2p by i2p.

the class HomeHelper method renderApps.

private String renderApps(Collection<App> apps) {
    String website = _t("Web Server");
    StringBuilder buf = new StringBuilder(1024);
    buf.append("<div class=\"appgroup\">");
    PortMapper pm = _context.portMapper();
    for (App app : apps) {
        String url;
        if (app.name.equals(website) && app.url.equals("http://127.0.0.1:7658/")) {
            int port = pm.getPort(PortMapper.SVC_EEPSITE);
            int sslPort = pm.getPort(PortMapper.SVC_HTTPS_EEPSITE);
            if (port <= 0 && sslPort <= 0)
                continue;
            // fixup eepsite link
            if (sslPort > 0) {
                url = "https://" + pm.getActualHost(PortMapper.SVC_HTTPS_EEPSITE, "127.0.0.1") + ':' + sslPort + '/';
            } else {
                url = "http://" + pm.getActualHost(PortMapper.SVC_EEPSITE, "127.0.0.1") + ':' + port + '/';
            }
        } else {
            url = app.url;
            // check for disabled webapps and other things
            if (url.equals("/dns")) {
                if (pm.getPort("susidns") <= 0)
                    continue;
            } else if (url.equals("/webmail")) {
                if (pm.getPort("susimail") <= 0)
                    continue;
            } else if (url.equals("/torrents")) {
                if (pm.getPort("i2psnark") <= 0)
                    continue;
            } else if (url.equals("/configplugins")) {
                if (!PluginStarter.pluginsEnabled(_context))
                    continue;
            }
        }
        buf.append("\n<div class=\"app\">\n" + "<div class=\"appimg\">" + // usability: add tabindex -1 so we avoid 2 tabs per app
        "<a href=\"").append(url).append("\" tabindex=\"-1\">" + "<img alt=\"\" title=\"").append(app.desc).append("\" src=\"").append(app.icon).append("\"></a>" + "</div>\n" + "<table><tr><td>" + "<div class=\"applabel\">" + "<a href=\"").append(url).append("\" title=\"").append(app.desc).append("\">").append(app.name).append("</a>" + "</div>" + "</td></tr></table>\n" + "</div>");
    }
    buf.append("</div>\n");
    return buf.toString();
}
Also used : App(net.i2p.router.web.App) PortMapper(net.i2p.util.PortMapper)

Aggregations

App (net.i2p.router.web.App)7 TreeSet (java.util.TreeSet)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 Set (java.util.Set)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 PortMapper (net.i2p.util.PortMapper)1