forked from I2P_Developers/i2p.i2p
* Console: Add ability to hide news
This commit is contained in:
@ -48,6 +48,17 @@ public class CSSHelper extends HelperBase {
|
|||||||
return Messages.getLanguage(_context);
|
return Messages.getLanguage(_context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Show / hide news on home page
|
||||||
|
* @param val if non-null, "1" to show, else hide
|
||||||
|
* @since 0.8.12
|
||||||
|
*/
|
||||||
|
public void setNews(String val) {
|
||||||
|
// Protected with nonce in css.jsi
|
||||||
|
if (val != null)
|
||||||
|
NewsFetcher.getInstance(_context).showNews(val.equals("1"));
|
||||||
|
}
|
||||||
|
|
||||||
/** change refresh and save it */
|
/** change refresh and save it */
|
||||||
public void setRefresh(String r) {
|
public void setRefresh(String r) {
|
||||||
_context.router().setConfigSetting(PROP_REFRESH, r);
|
_context.router().setConfigSetting(PROP_REFRESH, r);
|
||||||
|
@ -24,8 +24,8 @@ import net.i2p.util.Log;
|
|||||||
* track of whether that has an announcement for a new version.
|
* track of whether that has an announcement for a new version.
|
||||||
*/
|
*/
|
||||||
public class NewsFetcher implements Runnable, EepGet.StatusListener {
|
public class NewsFetcher implements Runnable, EepGet.StatusListener {
|
||||||
private I2PAppContext _context;
|
private final RouterContext _context;
|
||||||
private Log _log;
|
private final Log _log;
|
||||||
private boolean _updateAvailable;
|
private boolean _updateAvailable;
|
||||||
private boolean _unsignedUpdateAvailable;
|
private boolean _unsignedUpdateAvailable;
|
||||||
private long _lastFetch;
|
private long _lastFetch;
|
||||||
@ -34,13 +34,13 @@ public class NewsFetcher implements Runnable, EepGet.StatusListener {
|
|||||||
private String _unsignedUpdateVersion;
|
private String _unsignedUpdateVersion;
|
||||||
private String _lastModified;
|
private String _lastModified;
|
||||||
private boolean _invalidated;
|
private boolean _invalidated;
|
||||||
private File _newsFile;
|
private final File _newsFile;
|
||||||
private File _tempFile;
|
private final File _tempFile;
|
||||||
private static NewsFetcher _instance;
|
private static NewsFetcher _instance;
|
||||||
private volatile boolean _isRunning;
|
private volatile boolean _isRunning;
|
||||||
|
|
||||||
//public static final synchronized NewsFetcher getInstance() { return _instance; }
|
//public static final synchronized NewsFetcher getInstance() { return _instance; }
|
||||||
public static final synchronized NewsFetcher getInstance(I2PAppContext ctx) {
|
public static final synchronized NewsFetcher getInstance(RouterContext ctx) {
|
||||||
if (_instance != null)
|
if (_instance != null)
|
||||||
return _instance;
|
return _instance;
|
||||||
_instance = new NewsFetcher(ctx);
|
_instance = new NewsFetcher(ctx);
|
||||||
@ -52,8 +52,10 @@ public class NewsFetcher implements Runnable, EepGet.StatusListener {
|
|||||||
/** @since 0.7.14 not configurable */
|
/** @since 0.7.14 not configurable */
|
||||||
private static final String BACKUP_NEWS_URL = "http://www.i2p2.i2p/_static/news/news.xml";
|
private static final String BACKUP_NEWS_URL = "http://www.i2p2.i2p/_static/news/news.xml";
|
||||||
private static final String PROP_LAST_CHECKED = "router.newsLastChecked";
|
private static final String PROP_LAST_CHECKED = "router.newsLastChecked";
|
||||||
|
/** @since 0.8.12 */
|
||||||
|
private static final String PROP_LAST_HIDDEN = "routerconsole.newsLastHidden";
|
||||||
|
|
||||||
private NewsFetcher(I2PAppContext ctx) {
|
private NewsFetcher(RouterContext ctx) {
|
||||||
_context = ctx;
|
_context = ctx;
|
||||||
_log = ctx.logManager().getLog(NewsFetcher.class);
|
_log = ctx.logManager().getLog(NewsFetcher.class);
|
||||||
_instance = this;
|
_instance = this;
|
||||||
@ -94,9 +96,40 @@ public class NewsFetcher implements Runnable, EepGet.StatusListener {
|
|||||||
public boolean unsignedUpdateAvailable() { return _unsignedUpdateAvailable; }
|
public boolean unsignedUpdateAvailable() { return _unsignedUpdateAvailable; }
|
||||||
public String unsignedUpdateVersion() { return _unsignedUpdateVersion; }
|
public String unsignedUpdateVersion() { return _unsignedUpdateVersion; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is the news newer than the last time it was hidden?
|
||||||
|
* @since 0.8.12
|
||||||
|
*/
|
||||||
|
public boolean shouldShowNews() {
|
||||||
|
if (_lastUpdated <= 0)
|
||||||
|
return true;
|
||||||
|
String h = _context.getProperty(PROP_LAST_HIDDEN);
|
||||||
|
if (h == null)
|
||||||
|
return true;
|
||||||
|
long last = 0;
|
||||||
|
try {
|
||||||
|
last = Long.parseLong(h);
|
||||||
|
} catch (NumberFormatException nfe) {}
|
||||||
|
return _lastUpdated > last;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save config with the timestamp of the current news to hide, or 0 to show
|
||||||
|
* @since 0.8.12
|
||||||
|
*/
|
||||||
|
public void showNews(boolean yes) {
|
||||||
|
long stamp = yes ? 0 : _lastUpdated;
|
||||||
|
_context.router().setConfigSetting(PROP_LAST_HIDDEN, Long.toString(stamp));
|
||||||
|
_context.router().saveConfig();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return HTML
|
||||||
|
*/
|
||||||
public String status() {
|
public String status() {
|
||||||
StringBuilder buf = new StringBuilder(128);
|
StringBuilder buf = new StringBuilder(128);
|
||||||
long now = _context.clock().now();
|
long now = _context.clock().now();
|
||||||
|
buf.append("<i>");
|
||||||
if (_lastUpdated > 0) {
|
if (_lastUpdated > 0) {
|
||||||
buf.append(Messages.getString("News last updated {0} ago.",
|
buf.append(Messages.getString("News last updated {0} ago.",
|
||||||
DataHelper.formatDuration2(now - _lastUpdated),
|
DataHelper.formatDuration2(now - _lastUpdated),
|
||||||
@ -108,6 +141,18 @@ public class NewsFetcher implements Runnable, EepGet.StatusListener {
|
|||||||
DataHelper.formatDuration2(now - _lastFetch),
|
DataHelper.formatDuration2(now - _lastFetch),
|
||||||
_context));
|
_context));
|
||||||
}
|
}
|
||||||
|
buf.append("</i>");
|
||||||
|
String consoleNonce = System.getProperty("router.consoleNonce");
|
||||||
|
if (_lastUpdated > 0 && consoleNonce != null) {
|
||||||
|
if (shouldShowNews()) {
|
||||||
|
buf.append(" <a href=\"/?news=0&consoleNonce=").append(consoleNonce).append("\">")
|
||||||
|
.append(Messages.getString("Hide news", _context));
|
||||||
|
} else {
|
||||||
|
buf.append(" <a href=\"/?news=1&consoleNonce=").append(consoleNonce).append("\">")
|
||||||
|
.append(Messages.getString("Show news", _context));
|
||||||
|
}
|
||||||
|
buf.append("</a>");
|
||||||
|
}
|
||||||
return buf.toString();
|
return buf.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -232,16 +277,15 @@ public class NewsFetcher implements Runnable, EepGet.StatusListener {
|
|||||||
if (get.fetch()) {
|
if (get.fetch()) {
|
||||||
String lastmod = get.getLastModified();
|
String lastmod = get.getLastModified();
|
||||||
if (lastmod != null) {
|
if (lastmod != null) {
|
||||||
if (!(_context.isRouterContext())) return;
|
|
||||||
long modtime = RFC822Date.parse822Date(lastmod);
|
long modtime = RFC822Date.parse822Date(lastmod);
|
||||||
if (modtime <= 0) return;
|
if (modtime <= 0) return;
|
||||||
String lastUpdate = _context.getProperty(UpdateHandler.PROP_LAST_UPDATE_TIME);
|
String lastUpdate = _context.getProperty(UpdateHandler.PROP_LAST_UPDATE_TIME);
|
||||||
if (lastUpdate == null) {
|
if (lastUpdate == null) {
|
||||||
// we don't know what version you have, so stamp it with the current time,
|
// we don't know what version you have, so stamp it with the current time,
|
||||||
// and we'll look for something newer next time around.
|
// and we'll look for something newer next time around.
|
||||||
((RouterContext)_context).router().setConfigSetting(UpdateHandler.PROP_LAST_UPDATE_TIME,
|
_context.router().setConfigSetting(UpdateHandler.PROP_LAST_UPDATE_TIME,
|
||||||
"" + _context.clock().now());
|
Long.toString(_context.clock().now()));
|
||||||
((RouterContext)_context).router().saveConfig();
|
_context.router().saveConfig();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
long ms = 0;
|
long ms = 0;
|
||||||
@ -267,7 +311,7 @@ public class NewsFetcher implements Runnable, EepGet.StatusListener {
|
|||||||
String url = _context.getProperty(ConfigUpdateHandler.PROP_ZIP_URL);
|
String url = _context.getProperty(ConfigUpdateHandler.PROP_ZIP_URL);
|
||||||
if (url == null || url.length() <= 0)
|
if (url == null || url.length() <= 0)
|
||||||
return;
|
return;
|
||||||
UpdateHandler handler = new UnsignedUpdateHandler((RouterContext)_context, url,
|
UpdateHandler handler = new UnsignedUpdateHandler(_context, url,
|
||||||
_unsignedUpdateVersion);
|
_unsignedUpdateVersion);
|
||||||
handler.update();
|
handler.update();
|
||||||
}
|
}
|
||||||
@ -329,18 +373,8 @@ public class NewsFetcher implements Runnable, EepGet.StatusListener {
|
|||||||
if (shouldInstall()) {
|
if (shouldInstall()) {
|
||||||
if (_log.shouldLog(Log.DEBUG))
|
if (_log.shouldLog(Log.DEBUG))
|
||||||
_log.debug("Policy requests update, so we update");
|
_log.debug("Policy requests update, so we update");
|
||||||
UpdateHandler handler = null;
|
UpdateHandler handler = new UpdateHandler(_context);
|
||||||
if (_context.isRouterContext()) {
|
handler.update();
|
||||||
handler = new UpdateHandler((RouterContext)_context);
|
|
||||||
} else {
|
|
||||||
List contexts = RouterContext.listContexts();
|
|
||||||
if (!contexts.isEmpty())
|
|
||||||
handler = new UpdateHandler((RouterContext)contexts.get(0));
|
|
||||||
else
|
|
||||||
_log.log(Log.CRIT, "No router context to update with?");
|
|
||||||
}
|
|
||||||
if (handler != null)
|
|
||||||
handler.update();
|
|
||||||
} else {
|
} else {
|
||||||
if (_log.shouldLog(Log.DEBUG))
|
if (_log.shouldLog(Log.DEBUG))
|
||||||
_log.debug("Policy requests manual update, so we do nothing");
|
_log.debug("Policy requests manual update, so we do nothing");
|
||||||
@ -373,10 +407,8 @@ public class NewsFetcher implements Runnable, EepGet.StatusListener {
|
|||||||
_log.warn("Transfer complete, but no file? - probably 304 Not Modified");
|
_log.warn("Transfer complete, but no file? - probably 304 Not Modified");
|
||||||
}
|
}
|
||||||
_lastFetch = now;
|
_lastFetch = now;
|
||||||
if (_context.isRouterContext()) {
|
_context.router().setConfigSetting(PROP_LAST_CHECKED, Long.toString(now));
|
||||||
((RouterContext)_context).router().setConfigSetting(PROP_LAST_CHECKED, "" + now);
|
_context.router().saveConfig();
|
||||||
((RouterContext)_context).router().saveConfig();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void transferFailed(String url, long bytesTransferred, long bytesRemaining, int currentAttempt) {
|
public void transferFailed(String url, long bytesTransferred, long bytesRemaining, int currentAttempt) {
|
||||||
|
@ -17,4 +17,9 @@ public class NewsHelper extends ContentHelper {
|
|||||||
_page = (new File(_context.getBaseDir(), "docs/initialNews/initialNews.xml")).getAbsolutePath();
|
_page = (new File(_context.getBaseDir(), "docs/initialNews/initialNews.xml")).getAbsolutePath();
|
||||||
return super.getContent();
|
return super.getContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @since 0.8.12 */
|
||||||
|
public boolean shouldShowNews() {
|
||||||
|
return NewsFetcher.getInstance(_context).shouldShowNews();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -341,16 +341,17 @@ public class RouterConsoleRunner {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
NewsFetcher fetcher = NewsFetcher.getInstance(I2PAppContext.getGlobalContext());
|
|
||||||
Thread newsThread = new I2PAppThread(fetcher, "NewsFetcher", true);
|
|
||||||
newsThread.start();
|
|
||||||
|
|
||||||
Thread t = new I2PAppThread(new StatSummarizer(), "StatSummarizer", true);
|
Thread t = new I2PAppThread(new StatSummarizer(), "StatSummarizer", true);
|
||||||
t.start();
|
t.start();
|
||||||
|
|
||||||
List<RouterContext> contexts = RouterContext.listContexts();
|
List<RouterContext> contexts = RouterContext.listContexts();
|
||||||
if (contexts != null) {
|
if (contexts != null) {
|
||||||
RouterContext ctx = contexts.get(0);
|
RouterContext ctx = contexts.get(0);
|
||||||
|
|
||||||
|
NewsFetcher fetcher = NewsFetcher.getInstance(ctx);
|
||||||
|
Thread newsThread = new I2PAppThread(fetcher, "NewsFetcher", true);
|
||||||
|
newsThread.start();
|
||||||
|
|
||||||
if (PluginStarter.pluginsEnabled(ctx)) {
|
if (PluginStarter.pluginsEnabled(ctx)) {
|
||||||
t = new I2PAppThread(new PluginStarter(ctx), "PluginStarter", true);
|
t = new I2PAppThread(new PluginStarter(ctx), "PluginStarter", true);
|
||||||
t.start();
|
t.start();
|
||||||
@ -359,7 +360,7 @@ public class RouterConsoleRunner {
|
|||||||
ctx.addShutdownTask(new NewsShutdown(fetcher, newsThread));
|
ctx.addShutdownTask(new NewsShutdown(fetcher, newsThread));
|
||||||
// stat summarizer registers its own hook
|
// stat summarizer registers its own hook
|
||||||
ctx.addShutdownTask(new ServerShutdown());
|
ctx.addShutdownTask(new ServerShutdown());
|
||||||
}
|
} // else log CRIT ?
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
<jsp:useBean class="net.i2p.router.web.ConfigUpdateHelper" id="updatehelper" scope="request" />
|
<jsp:useBean class="net.i2p.router.web.ConfigUpdateHelper" id="updatehelper" scope="request" />
|
||||||
<jsp:setProperty name="updatehelper" property="contextId" value="<%=(String)session.getAttribute("i2p.contextId")%>" />
|
<jsp:setProperty name="updatehelper" property="contextId" value="<%=(String)session.getAttribute("i2p.contextId")%>" />
|
||||||
<div class="messages">
|
<div class="messages">
|
||||||
<i><jsp:getProperty name="updatehelper" property="newsStatus" /></i></div>
|
<jsp:getProperty name="updatehelper" property="newsStatus" /></div>
|
||||||
<div class="configure">
|
<div class="configure">
|
||||||
<form action="" method="POST">
|
<form action="" method="POST">
|
||||||
<input type="hidden" name="nonce" value="<jsp:getProperty name="formhandler" property="newNonce" />" >
|
<input type="hidden" name="nonce" value="<jsp:getProperty name="formhandler" property="newNonce" />" >
|
||||||
|
@ -32,6 +32,7 @@
|
|||||||
String conNonceParam = request.getParameter("consoleNonce");
|
String conNonceParam = request.getParameter("consoleNonce");
|
||||||
if (conNonceParam != null && conNonceParam.equals(System.getProperty("router.consoleNonce"))) {
|
if (conNonceParam != null && conNonceParam.equals(System.getProperty("router.consoleNonce"))) {
|
||||||
intl.setLang(request.getParameter("lang"));
|
intl.setLang(request.getParameter("lang"));
|
||||||
|
intl.setNews(request.getParameter("news"));
|
||||||
}
|
}
|
||||||
%>
|
%>
|
||||||
<link href="<%=intl.getTheme(request.getHeader("User-Agent"))%>console.css" rel="stylesheet" type="text/css">
|
<link href="<%=intl.getTheme(request.getHeader("User-Agent"))%>console.css" rel="stylesheet" type="text/css">
|
||||||
|
@ -18,14 +18,20 @@
|
|||||||
<div class="news" id="news">
|
<div class="news" id="news">
|
||||||
<jsp:useBean class="net.i2p.router.web.NewsHelper" id="newshelper" scope="request" />
|
<jsp:useBean class="net.i2p.router.web.NewsHelper" id="newshelper" scope="request" />
|
||||||
<jsp:setProperty name="newshelper" property="contextId" value="<%=(String)session.getAttribute("i2p.contextId")%>" />
|
<jsp:setProperty name="newshelper" property="contextId" value="<%=(String)session.getAttribute("i2p.contextId")%>" />
|
||||||
<% java.io.File fpath = new java.io.File(net.i2p.I2PAppContext.getGlobalContext().getRouterDir(), "docs/news.xml"); %>
|
<%
|
||||||
|
if (newshelper.shouldShowNews()) {
|
||||||
|
java.io.File fpath = new java.io.File(net.i2p.I2PAppContext.getGlobalContext().getRouterDir(), "docs/news.xml");
|
||||||
|
%>
|
||||||
<jsp:setProperty name="newshelper" property="page" value="<%=fpath.getAbsolutePath()%>" />
|
<jsp:setProperty name="newshelper" property="page" value="<%=fpath.getAbsolutePath()%>" />
|
||||||
<jsp:setProperty name="newshelper" property="maxLines" value="300" />
|
<jsp:setProperty name="newshelper" property="maxLines" value="300" />
|
||||||
<jsp:getProperty name="newshelper" property="content" />
|
<jsp:getProperty name="newshelper" property="content" />
|
||||||
|
<hr>
|
||||||
|
<%
|
||||||
|
} // shouldShowNews()
|
||||||
|
%>
|
||||||
<jsp:useBean class="net.i2p.router.web.ConfigUpdateHelper" id="updatehelper" scope="request" />
|
<jsp:useBean class="net.i2p.router.web.ConfigUpdateHelper" id="updatehelper" scope="request" />
|
||||||
<jsp:setProperty name="updatehelper" property="contextId" value="<%=(String)session.getAttribute("i2p.contextId")%>" />
|
<jsp:setProperty name="updatehelper" property="contextId" value="<%=(String)session.getAttribute("i2p.contextId")%>" />
|
||||||
<hr><i><jsp:getProperty name="updatehelper" property="newsStatus" /></i><br>
|
<jsp:getProperty name="updatehelper" property="newsStatus" /><br>
|
||||||
</div><div class="main" id="main">
|
</div><div class="main" id="main">
|
||||||
<jsp:useBean class="net.i2p.router.web.ContentHelper" id="contenthelper" scope="request" />
|
<jsp:useBean class="net.i2p.router.web.ContentHelper" id="contenthelper" scope="request" />
|
||||||
<div class="welcome">
|
<div class="welcome">
|
||||||
@ -50,7 +56,7 @@
|
|||||||
<a name="top"></a>
|
<a name="top"></a>
|
||||||
<h2><%=intl._("Welcome to I2P")%></h2>
|
<h2><%=intl._("Welcome to I2P")%></h2>
|
||||||
</div>
|
</div>
|
||||||
<% fpath = new java.io.File(net.i2p.I2PAppContext.getGlobalContext().getBaseDir(), "docs/readme.html"); %>
|
<% java.io.File fpath = new java.io.File(net.i2p.I2PAppContext.getGlobalContext().getBaseDir(), "docs/readme.html"); %>
|
||||||
<jsp:setProperty name="contenthelper" property="page" value="<%=fpath.getAbsolutePath()%>" />
|
<jsp:setProperty name="contenthelper" property="page" value="<%=fpath.getAbsolutePath()%>" />
|
||||||
<jsp:setProperty name="contenthelper" property="maxLines" value="300" />
|
<jsp:setProperty name="contenthelper" property="maxLines" value="300" />
|
||||||
<jsp:setProperty name="contenthelper" property="contextId" value="<%=(String)session.getAttribute("i2p.contextId")%>" />
|
<jsp:setProperty name="contenthelper" property="contextId" value="<%=(String)session.getAttribute("i2p.contextId")%>" />
|
||||||
|
@ -419,10 +419,6 @@ div.news h3 {
|
|||||||
text-shadow: 0px 0px 0px #77f;
|
text-shadow: 0px 0px 0px #77f;
|
||||||
}
|
}
|
||||||
|
|
||||||
div.news i {
|
|
||||||
font-style: normal;
|
|
||||||
}
|
|
||||||
|
|
||||||
div.news h4 {
|
div.news h4 {
|
||||||
border-bottom: 0px;
|
border-bottom: 0px;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
|
Reference in New Issue
Block a user