2009-06-11 18:05:05 +00:00
|
|
|
package net.i2p.router.web;
|
|
|
|
|
2011-09-02 17:24:14 +00:00
|
|
|
import java.util.Map;
|
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
|
|
2009-06-11 18:05:05 +00:00
|
|
|
/**
|
|
|
|
* Copied and modded from I2PTunnel IndexBean (GPL)
|
|
|
|
* @author zzz
|
|
|
|
*/
|
|
|
|
public class CSSHelper extends HelperBase {
|
2011-09-02 17:24:14 +00:00
|
|
|
|
|
|
|
private static final Map<String, Boolean> _UACache = new ConcurrentHashMap();
|
|
|
|
|
2009-06-11 18:05:05 +00:00
|
|
|
public CSSHelper() {}
|
|
|
|
|
|
|
|
public static final String PROP_THEME_NAME = "routerconsole.theme";
|
2009-07-15 22:56:53 +00:00
|
|
|
public static final String DEFAULT_THEME = "light";
|
2010-06-27 17:04:51 +00:00
|
|
|
public static final String BASE_THEME_PATH = "/themes/console/";
|
2009-07-10 13:38:09 +00:00
|
|
|
private static final String FORCE = "classic";
|
2010-01-02 02:43:18 +00:00
|
|
|
public static final String PROP_REFRESH = "routerconsole.summaryRefresh";
|
|
|
|
public static final String DEFAULT_REFRESH = "60";
|
2009-06-11 18:05:05 +00:00
|
|
|
|
2009-07-10 13:38:09 +00:00
|
|
|
public String getTheme(String userAgent) {
|
2010-06-27 17:04:51 +00:00
|
|
|
String url = BASE_THEME_PATH;
|
2009-07-10 13:38:09 +00:00
|
|
|
if (userAgent != null && userAgent.contains("MSIE")) {
|
|
|
|
url += FORCE + "/";
|
|
|
|
} else {
|
2010-05-05 18:44:12 +00:00
|
|
|
// This is the first thing to use _context on most pages
|
|
|
|
if (_context == null)
|
|
|
|
throw new IllegalStateException("No contexts. This is usually because the router is either starting up or shutting down.");
|
2009-07-15 22:56:53 +00:00
|
|
|
String theme = _context.getProperty(PROP_THEME_NAME, DEFAULT_THEME);
|
|
|
|
url += theme + "/";
|
2009-07-10 13:38:09 +00:00
|
|
|
}
|
2009-06-11 18:05:05 +00:00
|
|
|
return url;
|
|
|
|
}
|
2009-10-18 14:06:07 +00:00
|
|
|
|
2011-03-08 03:07:02 +00:00
|
|
|
/** change default language for the router AND save it */
|
2009-10-18 14:06:07 +00:00
|
|
|
public void setLang(String lang) {
|
2011-03-08 03:07:02 +00:00
|
|
|
// Protected with nonce in css.jsi
|
|
|
|
if (lang != null && lang.length() == 2 && !lang.equals(_context.getProperty(Messages.PROP_LANG))) {
|
2012-01-18 01:54:34 +00:00
|
|
|
_context.router().saveConfig(Messages.PROP_LANG, lang);
|
2011-03-08 03:07:02 +00:00
|
|
|
}
|
2009-10-18 14:06:07 +00:00
|
|
|
}
|
2009-10-20 12:12:26 +00:00
|
|
|
|
2009-10-22 22:25:53 +00:00
|
|
|
/** needed for conditional css loads for zh */
|
|
|
|
public String getLang() {
|
|
|
|
return Messages.getLanguage(_context);
|
|
|
|
}
|
|
|
|
|
2011-11-09 18:38:39 +00:00
|
|
|
/**
|
|
|
|
* 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"));
|
|
|
|
}
|
|
|
|
|
2010-01-02 02:43:18 +00:00
|
|
|
/** change refresh and save it */
|
|
|
|
public void setRefresh(String r) {
|
2012-01-18 01:54:34 +00:00
|
|
|
_context.router().saveConfig(PROP_REFRESH, r);
|
2010-01-02 02:43:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/** @return refresh time in seconds, as a string */
|
|
|
|
public String getRefresh() {
|
|
|
|
return _context.getProperty(PROP_REFRESH, DEFAULT_REFRESH);
|
|
|
|
}
|
|
|
|
|
2009-10-20 12:12:26 +00:00
|
|
|
/** translate the title and display consistently */
|
|
|
|
public String title(String s) {
|
|
|
|
StringBuilder buf = new StringBuilder(128);
|
|
|
|
buf.append("<title>")
|
|
|
|
.append(_("I2P Router Console"))
|
|
|
|
.append(" - ")
|
|
|
|
.append(_(s))
|
|
|
|
.append("</title>");
|
|
|
|
return buf.toString();
|
|
|
|
}
|
2011-03-08 03:07:02 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Should we allow a refreshing IFrame?
|
|
|
|
* @since 0.8.5
|
|
|
|
*/
|
|
|
|
public boolean allowIFrame(String ua) {
|
2011-09-02 17:24:14 +00:00
|
|
|
if (ua == null)
|
|
|
|
return true;
|
|
|
|
Boolean brv = _UACache.get(ua);
|
|
|
|
if (brv != null)
|
|
|
|
return brv.booleanValue();
|
|
|
|
boolean rv = shouldAllowIFrame(ua);
|
|
|
|
_UACache.put(ua, Boolean.valueOf(rv));
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
private static boolean shouldAllowIFrame(String ua) {
|
|
|
|
return
|
2011-04-10 18:22:43 +00:00
|
|
|
// text
|
|
|
|
!(ua.startsWith("Lynx") || ua.startsWith("w3m") ||
|
2011-03-19 16:40:10 +00:00
|
|
|
ua.startsWith("ELinks") || ua.startsWith("Links") ||
|
2011-04-10 18:22:43 +00:00
|
|
|
ua.startsWith("Dillo") ||
|
|
|
|
// mobile
|
|
|
|
// http://www.zytrax.com/tech/web/mobile_ids.html
|
|
|
|
ua.contains("Android") || ua.contains("iPhone") ||
|
|
|
|
ua.contains("iPod") || ua.contains("iPad") ||
|
|
|
|
ua.contains("Kindle") || ua.contains("Mobile") ||
|
|
|
|
ua.contains("Nintendo Wii") || ua.contains("Opera Mini") ||
|
|
|
|
ua.contains("Palm") ||
|
|
|
|
ua.contains("PLAYSTATION") || ua.contains("Playstation") ||
|
|
|
|
ua.contains("Profile/MIDP-") || ua.contains("SymbianOS") ||
|
|
|
|
ua.contains("Windows CE") || ua.contains("Windows Phone") ||
|
|
|
|
ua.startsWith("BlackBerry") || ua.startsWith("DoCoMo") ||
|
|
|
|
ua.startsWith("Nokia") || ua.startsWith("OPWV-SDK") ||
|
|
|
|
ua.startsWith("MOT-") || ua.startsWith("SAMSUNG-") ||
|
|
|
|
ua.startsWith("nook") || ua.startsWith("SCH-") ||
|
|
|
|
ua.startsWith("SEC-") || ua.startsWith("SonyEricsson") ||
|
|
|
|
ua.startsWith("Vodafone"));
|
2011-03-08 03:07:02 +00:00
|
|
|
}
|
2009-06-11 18:05:05 +00:00
|
|
|
}
|