Search in sources :

Example 6 with ClientAppManager

use of net.i2p.app.ClientAppManager in project i2p.i2p by i2p.

the class ConfigServiceHandler method changeSystray.

/**
 *  Enable/disable and start/stop systray
 *
 *  @since 0.9.26
 */
private void changeSystray(boolean enable) {
    ClientAppManager mgr = _context.clientAppManager();
    if (mgr != null) {
        try {
            ClientApp dtg = mgr.getRegisteredApp("desktopgui");
            if (dtg != null) {
                if (enable) {
                    if (dtg.getState() == ClientAppState.STOPPED) {
                        dtg.startup();
                        addFormNotice(_t("Enabled system tray"));
                    }
                } else {
                    if (dtg.getState() == ClientAppState.RUNNING) {
                        dtg.shutdown(null);
                        addFormNotice(_t("Disabled system tray"));
                    }
                }
            } else if (enable) {
                // already set to true, GraphicsEnvironment initialized, can't change it now
                if (Boolean.valueOf(System.getProperty("java.awt.headless"))) {
                    addFormError(_t("Restart required to take effect"));
                } else {
                    dtg = new net.i2p.desktopgui.Main(_context, mgr, null);
                    dtg.startup();
                    addFormNotice(_t("Enabled system tray"));
                }
            }
        } catch (Throwable t) {
            if (enable)
                addFormError(_t("Failed to start systray") + ": " + t);
            else
                addFormError(_t("Failed to stop systray") + ": " + t);
        }
    }
    boolean saved = _context.router().saveConfig(RouterConsoleRunner.PROP_DTG_ENABLED, Boolean.toString(enable));
    if (saved)
        addFormNotice(_t("Configuration saved successfully"));
    else
        addFormError(_t("Error saving the configuration (applied but not saved) - please see the error logs"));
}
Also used : ClientApp(net.i2p.app.ClientApp) ClientAppManager(net.i2p.app.ClientAppManager)

Example 7 with ClientAppManager

use of net.i2p.app.ClientAppManager in project i2p.i2p by i2p.

the class NewsFetcher method processSU3.

/**
 *  Process the fetched su3 news file _tempFile.
 *  Handles 3 types of contained files: xml.gz (preferred), xml, and html (old format fake xml)
 *
 *  @return the temp file contining the HTML-format news.xml
 *  @since 0.9.17
 */
private File processSU3() throws IOException {
    SU3File su3 = new SU3File(_context, _tempFile);
    // real xml, maybe gz, maybe not
    File to1 = new File(_context.getTempDir(), "tmp-" + _context.random().nextInt() + ".xml");
    // real xml
    File to2 = new File(_context.getTempDir(), "tmp2-" + _context.random().nextInt() + ".xml");
    try {
        su3.verifyAndMigrate(to1);
        int type = su3.getFileType();
        if (su3.getContentType() != SU3File.CONTENT_NEWS)
            throw new IOException("bad content type: " + su3.getContentType());
        if (type == SU3File.TYPE_HTML)
            return to1;
        if (type != SU3File.TYPE_XML && type != SU3File.TYPE_XML_GZ)
            throw new IOException("bad file type: " + type);
        File xml;
        if (type == SU3File.TYPE_XML_GZ) {
            gunzip(to1, to2);
            xml = to2;
            to1.delete();
        } else {
            xml = to1;
        }
        NewsXMLParser parser = new NewsXMLParser(_context);
        Node root = parser.parse(xml);
        xml.delete();
        NewsMetadata data = parser.getMetadata();
        List<NewsEntry> entries = parser.getEntries();
        // add entries to the news manager
        ClientAppManager cmgr = _context.clientAppManager();
        if (cmgr != null) {
            NewsManager nmgr = (NewsManager) cmgr.getRegisteredApp(NewsManager.APP_NAME);
            if (nmgr != null) {
                nmgr.addEntries(entries);
                List<Node> nodes = NewsXMLParser.getNodes(root, "entry");
                nmgr.storeEntries(nodes);
            }
        }
        // Persist any new CRL entries
        List<CRLEntry> crlEntries = parser.getCRLEntries();
        if (crlEntries != null)
            persistCRLEntries(crlEntries);
        else
            _log.info("No CRL entries found in news feed");
        // Block any new blocklist entries
        BlocklistEntries ble = parser.getBlocklistEntries();
        if (ble != null && ble.isVerified())
            processBlocklistEntries(ble);
        else
            _log.info("No blocklist entries found in news feed");
        // store entries and metadata in old news.xml format
        String sudVersion = su3.getVersionString();
        String signingKeyName = su3.getSignerString();
        File to3 = new File(_context.getTempDir(), "tmp3-" + _context.random().nextInt() + ".xml");
        outputOldNewsXML(data, entries, sudVersion, signingKeyName, to3);
        return to3;
    } finally {
        to2.delete();
    }
}
Also used : NewsMetadata(net.i2p.router.news.NewsMetadata) Node(org.cybergarage.xml.Node) IOException(java.io.IOException) CRLEntry(net.i2p.router.news.CRLEntry) SU3File(net.i2p.crypto.SU3File) NewsEntry(net.i2p.router.news.NewsEntry) ClientAppManager(net.i2p.app.ClientAppManager) NewsXMLParser(net.i2p.router.news.NewsXMLParser) NewsManager(net.i2p.router.news.NewsManager) BlocklistEntries(net.i2p.router.news.BlocklistEntries) SU3File(net.i2p.crypto.SU3File) SecureFile(net.i2p.util.SecureFile) File(java.io.File)

Example 8 with ClientAppManager

use of net.i2p.app.ClientAppManager in project i2p.i2p by i2p.

the class SummaryBarRenderer method renderNewsHeadingsHTML.

/**
 * @since 0.9.1
 */
public String renderNewsHeadingsHTML() {
    if (_helper == null)
        return "";
    NewsHelper newshelper = _helper.getNewsHelper();
    if (newshelper == null || newshelper.shouldShowNews())
        return "";
    StringBuilder buf = new StringBuilder(512);
    String consoleNonce = CSSHelper.getNonce();
    if (consoleNonce != null) {
        // Set up title and pre-headings stuff.
        // buf.append("<h3><a href=\"/configupdate\">")
        buf.append("<h3><a href=\"/news\">").append(_t("News &amp; Updates")).append("</a></h3><hr class=\"b\"><div class=\"sb_newsheadings\">\n");
        // Get news content.
        List<NewsEntry> entries = Collections.emptyList();
        ClientAppManager cmgr = _context.clientAppManager();
        if (cmgr != null) {
            NewsManager nmgr = (NewsManager) cmgr.getRegisteredApp(NewsManager.APP_NAME);
            if (nmgr != null)
                entries = nmgr.getEntries();
        }
        if (!entries.isEmpty()) {
            buf.append("<table>\n");
            DateFormat fmt = DateFormat.getDateInstance(DateFormat.SHORT);
            // the router sets the JVM time zone to UTC but saves the original here so we can get it
            fmt.setTimeZone(SystemVersion.getSystemTimeZone(_context));
            int i = 0;
            // show a min of 1, max of 3, none older than 60 days over min
            final int min = 1;
            final int max = 3;
            for (NewsEntry entry : entries) {
                if (i >= min && entry.updated > 0 && entry.updated < _context.clock().now() - 60 * 24 * 60 * 60 * 1000L)
                    break;
                buf.append("<tr><td><a href=\"/?news=1&amp;consoleNonce=").append(consoleNonce).append("\"");
                if (entry.updated > 0) {
                    Date date = new Date(entry.updated);
                    buf.append(" title=\"").append(_t("Published")).append(": ").append(fmt.format(date)).append("\"");
                }
                buf.append(">");
                buf.append(entry.title).append("</a></td></tr>\n");
                if (++i >= max)
                    break;
            }
            buf.append("</table>\n");
        } else {
            buf.append("<center><i>").append(_t("none")).append("</i></center>");
        }
        // Add post-headings stuff.
        // buf.append("<a href=\"/news\">")
        // .append(_t("Show all news"))
        // .append("</a>\n");
        buf.append("</div>\n");
    }
    return buf.toString();
}
Also used : NewsHelper(net.i2p.router.web.NewsHelper) DateFormat(java.text.DateFormat) NewsManager(net.i2p.router.news.NewsManager) NewsEntry(net.i2p.router.news.NewsEntry) Date(java.util.Date) ClientAppManager(net.i2p.app.ClientAppManager)

Aggregations

ClientAppManager (net.i2p.app.ClientAppManager)8 IOException (java.io.IOException)4 ClientApp (net.i2p.app.ClientApp)3 NewsEntry (net.i2p.router.news.NewsEntry)3 NewsManager (net.i2p.router.news.NewsManager)3 OutputStream (java.io.OutputStream)2 Socket (java.net.Socket)2 DateFormat (java.text.DateFormat)2 Date (java.util.Date)2 I2PException (net.i2p.I2PException)2 Outproxy (net.i2p.app.Outproxy)2 I2PSocket (net.i2p.client.streaming.I2PSocket)2 I2PSocketOptions (net.i2p.client.streaming.I2PSocketOptions)2 Destination (net.i2p.data.Destination)2 File (java.io.File)1 InputStream (java.io.InputStream)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 Properties (java.util.Properties)1 I2PSession (net.i2p.client.I2PSession)1