2004-07-24 02:06:07 +00:00
|
|
|
package net.i2p.router.web;
|
|
|
|
|
2014-01-31 18:34:27 +00:00
|
|
|
import java.io.BufferedReader;
|
Big directory rework.
Eliminate all uses of the current working directory, and
set up multiple directories specified by absolute paths for various uses.
Add a WorkingDir class to create a user config directory and
migrate files to it for new installs.
The directory will be $HOME/.i2p on linux and %APPDIR%\I2P on Windows,
or as specified in the system property -Di2p.dir.config=/path/to/i2pdir
All files except for the base install and temp files will be
in the config directory by default.
Temp files will be in a i2p-xxxxx subdirectory of the system temp directory
specified by the system property java.io.tmpdir.
Convert all file opens in the code to be relative to a specific directory,
as specified in the context. Code and applications should never open
files relative to the current working directory (e.g. new File("foo")).
All files should be accessed in the appropriate context directory,
e.g. new File(_context.getAppDir(), "foo").
The router.config file location may be specified as a system property on the
java command line with -Drouter.configLocation=/path/to/router.config
All directories may be specified as properties in the router.config file.
The migration will copy all files from an existing installation,
except i2psnark/, with the system property -Di2p.dir.migrate=true.
Otherwise it will just set up a new directory with a minimal configuration.
The migration will also create a modified wrapper.config and (on linux only)
a modified i2prouter script, and place them in the config directory.
There are no changes to the installer or the default i2prouter, i2prouter.bat,
i2prouter, wrapper.config, runplain.sh, windows service installer/uninstaller,
etc. in this checkin.
* Directories. These are all set at instantiation and will not be changed by
* subsequent property changes.
* All properties, if set, should be absolute paths.
*
* Name Property Method Files
* ----- -------- ----- -----
* Base i2p.dir.base getBaseDir() lib/, webapps/, docs/, geoip/, licenses/, ...
* Temp i2p.dir.temp getTempDir() Temporary files
* Config i2p.dir.config getConfigDir() *.config, hosts.txt, addressbook/, ...
*
* (the following all default to the same as Config)
*
* Router i2p.dir.router getRouterDir() netDb/, peerProfiles/, router.*, keyBackup/, ...
* Log i2p.dir.log getLogDir() wrapper.log*, logs/
* PID i2p.dir.pid getPIDDir() wrapper *.pid files, router.ping
* App i2p.dir.app getAppDir() eepsite/, ...
*
* Note that we can't control where the wrapper actually puts its files.
All these will be set appropriately in a Router Context.
In an I2P App Context, all except Temp will be the current working directory.
Lightly tested so far, needs much more testing.
2009-06-04 19:14:40 +00:00
|
|
|
import java.io.File;
|
2014-01-31 18:34:27 +00:00
|
|
|
import java.io.FileInputStream;
|
|
|
|
import java.io.InputStreamReader;
|
|
|
|
import java.io.IOException;
|
2016-04-16 16:05:19 +00:00
|
|
|
import java.lang.reflect.Method;
|
2014-01-31 18:34:27 +00:00
|
|
|
import java.util.ArrayList;
|
2004-07-24 02:06:07 +00:00
|
|
|
import java.util.List;
|
|
|
|
|
2012-05-20 18:12:41 +00:00
|
|
|
import net.i2p.I2PAppContext;
|
2014-08-30 19:00:57 +00:00
|
|
|
import net.i2p.crypto.SigType;
|
2004-09-29 19:34:02 +00:00
|
|
|
import net.i2p.util.FileUtil;
|
2012-01-14 17:46:34 +00:00
|
|
|
import net.i2p.util.VersionComparator;
|
2004-07-24 02:06:07 +00:00
|
|
|
|
2012-11-21 20:49:18 +00:00
|
|
|
import org.eclipse.jetty.server.Server;
|
2012-01-14 17:46:34 +00:00
|
|
|
import org.tanukisoftware.wrapper.WrapperManager;
|
2011-11-16 00:48:17 +00:00
|
|
|
|
2009-01-29 02:16:18 +00:00
|
|
|
public class LogsHelper extends HelperBase {
|
2012-01-14 17:46:34 +00:00
|
|
|
|
|
|
|
private static final String LOCATION_AVAILABLE = "3.3.7";
|
2016-04-16 16:05:19 +00:00
|
|
|
private static final String _jstlVersion = jstlVersion();
|
|
|
|
|
2012-01-06 00:38:33 +00:00
|
|
|
/** @since 0.8.12 */
|
2011-11-16 00:48:17 +00:00
|
|
|
public String getJettyVersion() {
|
2011-12-23 00:56:48 +00:00
|
|
|
return Server.getVersion();
|
2011-12-24 00:48:30 +00:00
|
|
|
}
|
2011-11-16 00:48:17 +00:00
|
|
|
|
2011-12-24 00:48:30 +00:00
|
|
|
/** @since 0.8.13 */
|
Big refactor of the router console update subsystem, in preparation for
implementing out-of-console updaters like i2psnark.
- Add new update interfaces in net.i2p.update
- All update implementations moved to routerconsole update/
- Implement an UpdateManager that registers with the RouterContext
- UpdateManager handles multiple types of things to update
(router, plugins, news, ...) and methods of updating (HTTP, ...)
- UpdateManager maintains list of installed, downloaded, and available versions of everything
- Define Updaters that can check for a new version and/or download an item
- Individual Updaters register with the UpdateManager obtained from
I2PAppContext, identifying the type of update item and
update method they can handle.
- Updaters need only core libs, no router.jar or routerconsole access required.
- All checks and updates are initiated via the UpdateManager.
- All status on checks and updates in-progress or completed are
obtained from the UpdateManager. No more use of System properties
to broadcast update state.
- All update and checker tasks are intantiated on demand and threaded;
no more static references left over.
- Split out the Runners and Checkers from the Handlers and make the inheritance more sane.
- No more permanent NewsFetcher thread; run on the SimpleScheduler queue
and thread a checker task only to fetch the news.
- No more static NewsFetcher instance in routerconsole.
All helper methods that are still required are moved to NewsHelper.
The UpdateManager implements the policy for when to check and download.
All requests go through the UpdateManager.
For each update type, there's several parts:
- The xxxUpdateHandler implements the Updater
- The xxxUpdateChecker implements the UpdateTask for checking
- The xxxUpdateRunner implements the UpdateTask for downloading
New and moved classes:
web/ update/
---- -------
new ConsoleUpdateManager.java
new PluginUpdateChecker.java from PluginUpdateChecker
PluginUpdateChecker -> PluginUpdateHandler.java
PluginUpdateHandler.java -> PluginUpdateRunner
new UnsignedUpdateHandler.java
UnsignedUpdateHandler -> UnsignedUpdateRunner.java
new UnsignedUpdateChecker from NewsFetcher
UpdateHandler.java remains
new UpdateHandler.java
new UpdateRunner.java from UpdateHandler
move NewsHandler from NewsFetcher
new NewsFetcher
new NewsTimerTask
new DummyHandler
Initial checkin. Unfinished, untested, unpolished.
2012-06-18 22:09:45 +00:00
|
|
|
public static String jettyVersion() {
|
2012-01-08 15:01:35 +00:00
|
|
|
return Server.getVersion();
|
2011-11-16 00:48:17 +00:00
|
|
|
}
|
|
|
|
|
2014-08-30 19:00:57 +00:00
|
|
|
/** @since 0.9.15 */
|
|
|
|
public String getUnavailableCrypto() {
|
|
|
|
StringBuilder buf = new StringBuilder(128);
|
|
|
|
for (SigType t : SigType.values()) {
|
|
|
|
if (!t.isAvailable()) {
|
|
|
|
buf.append("<b>Crypto:</b> ").append(t.toString()).append(" unavailable<br>");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return buf.toString();
|
|
|
|
}
|
|
|
|
|
2016-04-16 16:05:19 +00:00
|
|
|
/**
|
|
|
|
* @return non-null, "n/a" on failure
|
|
|
|
* @since 0.9.26
|
|
|
|
*/
|
|
|
|
public String getJstlVersion() {
|
|
|
|
return _jstlVersion;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return non-null, "n/a" on failure
|
|
|
|
* @since 0.9.26
|
|
|
|
*/
|
|
|
|
private static String jstlVersion() {
|
|
|
|
String rv = "n/a";
|
|
|
|
try {
|
|
|
|
Class<?> cls = Class.forName("org.apache.taglibs.standard.Version", true, ClassLoader.getSystemClassLoader());
|
|
|
|
Method getVersion = cls.getMethod("getVersion");
|
|
|
|
// returns "standard-taglib 1.2.0"
|
|
|
|
Object version = getVersion.invoke(null, (Object[]) null);
|
|
|
|
rv = (String) version;
|
|
|
|
//int sp = rv.indexOf(' ');
|
|
|
|
//if (sp >= 0 && rv.length() > sp + 1)
|
|
|
|
// rv = rv.substring(sp + 1);
|
|
|
|
} catch (Exception e) {}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2012-10-07 20:50:26 +00:00
|
|
|
/**
|
|
|
|
* Does not call logManager.flush(); call getCriticalLogs() first to flush
|
|
|
|
*/
|
2004-07-24 02:06:07 +00:00
|
|
|
public String getLogs() {
|
2009-06-28 17:40:17 +00:00
|
|
|
String str = formatMessages(_context.logManager().getBuffer().getMostRecentMessages());
|
2016-08-21 20:21:50 +00:00
|
|
|
return "<p>" + _t("File location") + ": <a href=\"/router.log\">" + _context.logManager().currentFile() + "</a></p>" + str;
|
2005-02-22 07:07:29 +00:00
|
|
|
}
|
|
|
|
|
2012-10-07 20:50:26 +00:00
|
|
|
/**
|
|
|
|
* Side effect - calls logManager.flush()
|
|
|
|
*/
|
2005-02-22 07:07:29 +00:00
|
|
|
public String getCriticalLogs() {
|
2012-10-07 20:50:26 +00:00
|
|
|
_context.logManager().flush();
|
Big directory rework.
Eliminate all uses of the current working directory, and
set up multiple directories specified by absolute paths for various uses.
Add a WorkingDir class to create a user config directory and
migrate files to it for new installs.
The directory will be $HOME/.i2p on linux and %APPDIR%\I2P on Windows,
or as specified in the system property -Di2p.dir.config=/path/to/i2pdir
All files except for the base install and temp files will be
in the config directory by default.
Temp files will be in a i2p-xxxxx subdirectory of the system temp directory
specified by the system property java.io.tmpdir.
Convert all file opens in the code to be relative to a specific directory,
as specified in the context. Code and applications should never open
files relative to the current working directory (e.g. new File("foo")).
All files should be accessed in the appropriate context directory,
e.g. new File(_context.getAppDir(), "foo").
The router.config file location may be specified as a system property on the
java command line with -Drouter.configLocation=/path/to/router.config
All directories may be specified as properties in the router.config file.
The migration will copy all files from an existing installation,
except i2psnark/, with the system property -Di2p.dir.migrate=true.
Otherwise it will just set up a new directory with a minimal configuration.
The migration will also create a modified wrapper.config and (on linux only)
a modified i2prouter script, and place them in the config directory.
There are no changes to the installer or the default i2prouter, i2prouter.bat,
i2prouter, wrapper.config, runplain.sh, windows service installer/uninstaller,
etc. in this checkin.
* Directories. These are all set at instantiation and will not be changed by
* subsequent property changes.
* All properties, if set, should be absolute paths.
*
* Name Property Method Files
* ----- -------- ----- -----
* Base i2p.dir.base getBaseDir() lib/, webapps/, docs/, geoip/, licenses/, ...
* Temp i2p.dir.temp getTempDir() Temporary files
* Config i2p.dir.config getConfigDir() *.config, hosts.txt, addressbook/, ...
*
* (the following all default to the same as Config)
*
* Router i2p.dir.router getRouterDir() netDb/, peerProfiles/, router.*, keyBackup/, ...
* Log i2p.dir.log getLogDir() wrapper.log*, logs/
* PID i2p.dir.pid getPIDDir() wrapper *.pid files, router.ping
* App i2p.dir.app getAppDir() eepsite/, ...
*
* Note that we can't control where the wrapper actually puts its files.
All these will be set appropriately in a Router Context.
In an I2P App Context, all except Temp will be the current working directory.
Lightly tested so far, needs much more testing.
2009-06-04 19:14:40 +00:00
|
|
|
return formatMessages(_context.logManager().getBuffer().getMostRecentCriticalMessages());
|
2004-07-24 02:06:07 +00:00
|
|
|
}
|
2004-08-24 18:02:48 +00:00
|
|
|
|
2012-05-20 18:12:41 +00:00
|
|
|
/**
|
|
|
|
* Does not necessarily exist.
|
2016-08-21 20:21:50 +00:00
|
|
|
*
|
|
|
|
* @return non-null, doesn't necessarily exist
|
|
|
|
* @since 0.9.1, public since 0.9.27
|
2012-05-20 18:12:41 +00:00
|
|
|
*/
|
2016-08-21 20:21:50 +00:00
|
|
|
public static File wrapperLogFile(I2PAppContext ctx) {
|
2012-01-14 17:46:34 +00:00
|
|
|
File f = null;
|
2012-05-20 18:12:41 +00:00
|
|
|
if (ctx.hasWrapper()) {
|
2012-01-14 17:46:34 +00:00
|
|
|
String wv = System.getProperty("wrapper.version");
|
2013-05-26 17:25:02 +00:00
|
|
|
if (wv != null && VersionComparator.comp(wv, LOCATION_AVAILABLE) >= 0) {
|
2012-01-14 17:46:34 +00:00
|
|
|
try {
|
|
|
|
f = WrapperManager.getWrapperLogFile();
|
|
|
|
} catch (Throwable t) {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (f == null || !f.exists()) {
|
|
|
|
// RouterLaunch puts the location here if no wrapper
|
|
|
|
String path = System.getProperty("wrapper.logfile");
|
|
|
|
if (path != null) {
|
|
|
|
f = new File(path);
|
|
|
|
} else {
|
|
|
|
// look in new and old places
|
|
|
|
f = new File(System.getProperty("java.io.tmpdir"), "wrapper.log");
|
|
|
|
if (!f.exists())
|
2012-05-20 18:12:41 +00:00
|
|
|
f = new File(ctx.getBaseDir(), "wrapper.log");
|
2012-01-14 17:46:34 +00:00
|
|
|
}
|
2009-06-13 21:04:27 +00:00
|
|
|
}
|
2012-05-20 18:12:41 +00:00
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getServiceLogs() {
|
|
|
|
File f = wrapperLogFile(_context);
|
2014-01-31 18:34:27 +00:00
|
|
|
String str;
|
|
|
|
if (_context.hasWrapper()) {
|
|
|
|
// platform encoding
|
|
|
|
str = readTextFile(f, 250);
|
|
|
|
} else {
|
|
|
|
// UTF-8
|
|
|
|
str = FileUtil.readTextFile(f.getAbsolutePath(), 250, false);
|
|
|
|
}
|
|
|
|
if (str == null) {
|
2015-09-25 19:55:36 +00:00
|
|
|
return "<p>" + _t("File not found") + ": <b><code>" + f.getAbsolutePath() + "</code></b></p>";
|
2014-01-31 18:34:27 +00:00
|
|
|
} else {
|
2010-10-19 14:39:29 +00:00
|
|
|
str = str.replace("&", "&").replace("<", "<").replace(">", ">");
|
2017-01-08 01:37:15 +00:00
|
|
|
return "<p>" + _t("File location") + ": <a href=\"/wrapper.log\">" + f.getAbsolutePath() + "</a></p></td></tr>\n<tr><td><pre>" + str + "</pre>";
|
2005-10-30 05:47:55 +00:00
|
|
|
}
|
2004-08-24 18:02:48 +00:00
|
|
|
}
|
2004-09-27 07:57:43 +00:00
|
|
|
|
Big directory rework.
Eliminate all uses of the current working directory, and
set up multiple directories specified by absolute paths for various uses.
Add a WorkingDir class to create a user config directory and
migrate files to it for new installs.
The directory will be $HOME/.i2p on linux and %APPDIR%\I2P on Windows,
or as specified in the system property -Di2p.dir.config=/path/to/i2pdir
All files except for the base install and temp files will be
in the config directory by default.
Temp files will be in a i2p-xxxxx subdirectory of the system temp directory
specified by the system property java.io.tmpdir.
Convert all file opens in the code to be relative to a specific directory,
as specified in the context. Code and applications should never open
files relative to the current working directory (e.g. new File("foo")).
All files should be accessed in the appropriate context directory,
e.g. new File(_context.getAppDir(), "foo").
The router.config file location may be specified as a system property on the
java command line with -Drouter.configLocation=/path/to/router.config
All directories may be specified as properties in the router.config file.
The migration will copy all files from an existing installation,
except i2psnark/, with the system property -Di2p.dir.migrate=true.
Otherwise it will just set up a new directory with a minimal configuration.
The migration will also create a modified wrapper.config and (on linux only)
a modified i2prouter script, and place them in the config directory.
There are no changes to the installer or the default i2prouter, i2prouter.bat,
i2prouter, wrapper.config, runplain.sh, windows service installer/uninstaller,
etc. in this checkin.
* Directories. These are all set at instantiation and will not be changed by
* subsequent property changes.
* All properties, if set, should be absolute paths.
*
* Name Property Method Files
* ----- -------- ----- -----
* Base i2p.dir.base getBaseDir() lib/, webapps/, docs/, geoip/, licenses/, ...
* Temp i2p.dir.temp getTempDir() Temporary files
* Config i2p.dir.config getConfigDir() *.config, hosts.txt, addressbook/, ...
*
* (the following all default to the same as Config)
*
* Router i2p.dir.router getRouterDir() netDb/, peerProfiles/, router.*, keyBackup/, ...
* Log i2p.dir.log getLogDir() wrapper.log*, logs/
* PID i2p.dir.pid getPIDDir() wrapper *.pid files, router.ping
* App i2p.dir.app getAppDir() eepsite/, ...
*
* Note that we can't control where the wrapper actually puts its files.
All these will be set appropriately in a Router Context.
In an I2P App Context, all except Temp will be the current working directory.
Lightly tested so far, needs much more testing.
2009-06-04 19:14:40 +00:00
|
|
|
/***** unused
|
2004-09-27 07:57:43 +00:00
|
|
|
public String getConnectionLogs() {
|
Big directory rework.
Eliminate all uses of the current working directory, and
set up multiple directories specified by absolute paths for various uses.
Add a WorkingDir class to create a user config directory and
migrate files to it for new installs.
The directory will be $HOME/.i2p on linux and %APPDIR%\I2P on Windows,
or as specified in the system property -Di2p.dir.config=/path/to/i2pdir
All files except for the base install and temp files will be
in the config directory by default.
Temp files will be in a i2p-xxxxx subdirectory of the system temp directory
specified by the system property java.io.tmpdir.
Convert all file opens in the code to be relative to a specific directory,
as specified in the context. Code and applications should never open
files relative to the current working directory (e.g. new File("foo")).
All files should be accessed in the appropriate context directory,
e.g. new File(_context.getAppDir(), "foo").
The router.config file location may be specified as a system property on the
java command line with -Drouter.configLocation=/path/to/router.config
All directories may be specified as properties in the router.config file.
The migration will copy all files from an existing installation,
except i2psnark/, with the system property -Di2p.dir.migrate=true.
Otherwise it will just set up a new directory with a minimal configuration.
The migration will also create a modified wrapper.config and (on linux only)
a modified i2prouter script, and place them in the config directory.
There are no changes to the installer or the default i2prouter, i2prouter.bat,
i2prouter, wrapper.config, runplain.sh, windows service installer/uninstaller,
etc. in this checkin.
* Directories. These are all set at instantiation and will not be changed by
* subsequent property changes.
* All properties, if set, should be absolute paths.
*
* Name Property Method Files
* ----- -------- ----- -----
* Base i2p.dir.base getBaseDir() lib/, webapps/, docs/, geoip/, licenses/, ...
* Temp i2p.dir.temp getTempDir() Temporary files
* Config i2p.dir.config getConfigDir() *.config, hosts.txt, addressbook/, ...
*
* (the following all default to the same as Config)
*
* Router i2p.dir.router getRouterDir() netDb/, peerProfiles/, router.*, keyBackup/, ...
* Log i2p.dir.log getLogDir() wrapper.log*, logs/
* PID i2p.dir.pid getPIDDir() wrapper *.pid files, router.ping
* App i2p.dir.app getAppDir() eepsite/, ...
*
* Note that we can't control where the wrapper actually puts its files.
All these will be set appropriately in a Router Context.
In an I2P App Context, all except Temp will be the current working directory.
Lightly tested so far, needs much more testing.
2009-06-04 19:14:40 +00:00
|
|
|
return formatMessages(_context.commSystem().getMostRecentErrorMessages());
|
|
|
|
}
|
|
|
|
******/
|
|
|
|
|
2010-11-06 12:34:53 +00:00
|
|
|
private final static String NL = System.getProperty("line.separator");
|
|
|
|
|
2010-10-02 15:03:20 +00:00
|
|
|
/** formats in reverse order */
|
|
|
|
private String formatMessages(List<String> msgs) {
|
|
|
|
if (msgs.isEmpty())
|
2016-04-18 05:46:58 +00:00
|
|
|
return "</td></tr><tr><td><p><i>" + _t("No log messages") + "</i></p>";
|
2011-09-01 13:25:18 +00:00
|
|
|
boolean colorize = _context.getBooleanPropertyDefaultTrue("routerconsole.logs.color");
|
2009-07-01 16:00:43 +00:00
|
|
|
StringBuilder buf = new StringBuilder(16*1024);
|
2016-04-18 05:46:58 +00:00
|
|
|
buf.append("</td></tr><tr><td><ul>");
|
2011-09-01 13:25:18 +00:00
|
|
|
for (int i = msgs.size() - 1; i >= 0; i--) {
|
|
|
|
String msg = msgs.get(i);
|
2012-10-29 22:10:42 +00:00
|
|
|
// don't display the dup message if it is last
|
|
|
|
if (i == 0 && msg.contains("↓"))
|
|
|
|
break;
|
2010-10-19 14:39:29 +00:00
|
|
|
msg = msg.replace("&", "&").replace("<", "<").replace(">", ">");
|
2012-10-07 20:50:26 +00:00
|
|
|
msg = msg.replace("&darr;", "↓"); // hack - undo the damage (LogWriter)
|
2010-11-06 12:34:53 +00:00
|
|
|
// remove last \n that LogRecordFormatter added
|
|
|
|
if (msg.endsWith(NL))
|
|
|
|
msg = msg.substring(0, msg.length() - NL.length());
|
|
|
|
// replace \n so that exception stack traces will format correctly and will paste nicely into pastebin
|
|
|
|
msg = msg.replace("\n", "<br> \n");
|
2004-09-27 07:57:43 +00:00
|
|
|
buf.append("<li>");
|
Big directory rework.
Eliminate all uses of the current working directory, and
set up multiple directories specified by absolute paths for various uses.
Add a WorkingDir class to create a user config directory and
migrate files to it for new installs.
The directory will be $HOME/.i2p on linux and %APPDIR%\I2P on Windows,
or as specified in the system property -Di2p.dir.config=/path/to/i2pdir
All files except for the base install and temp files will be
in the config directory by default.
Temp files will be in a i2p-xxxxx subdirectory of the system temp directory
specified by the system property java.io.tmpdir.
Convert all file opens in the code to be relative to a specific directory,
as specified in the context. Code and applications should never open
files relative to the current working directory (e.g. new File("foo")).
All files should be accessed in the appropriate context directory,
e.g. new File(_context.getAppDir(), "foo").
The router.config file location may be specified as a system property on the
java command line with -Drouter.configLocation=/path/to/router.config
All directories may be specified as properties in the router.config file.
The migration will copy all files from an existing installation,
except i2psnark/, with the system property -Di2p.dir.migrate=true.
Otherwise it will just set up a new directory with a minimal configuration.
The migration will also create a modified wrapper.config and (on linux only)
a modified i2prouter script, and place them in the config directory.
There are no changes to the installer or the default i2prouter, i2prouter.bat,
i2prouter, wrapper.config, runplain.sh, windows service installer/uninstaller,
etc. in this checkin.
* Directories. These are all set at instantiation and will not be changed by
* subsequent property changes.
* All properties, if set, should be absolute paths.
*
* Name Property Method Files
* ----- -------- ----- -----
* Base i2p.dir.base getBaseDir() lib/, webapps/, docs/, geoip/, licenses/, ...
* Temp i2p.dir.temp getTempDir() Temporary files
* Config i2p.dir.config getConfigDir() *.config, hosts.txt, addressbook/, ...
*
* (the following all default to the same as Config)
*
* Router i2p.dir.router getRouterDir() netDb/, peerProfiles/, router.*, keyBackup/, ...
* Log i2p.dir.log getLogDir() wrapper.log*, logs/
* PID i2p.dir.pid getPIDDir() wrapper *.pid files, router.ping
* App i2p.dir.app getAppDir() eepsite/, ...
*
* Note that we can't control where the wrapper actually puts its files.
All these will be set appropriately in a Router Context.
In an I2P App Context, all except Temp will be the current working directory.
Lightly tested so far, needs much more testing.
2009-06-04 19:14:40 +00:00
|
|
|
if (colorize) {
|
2011-09-01 13:25:18 +00:00
|
|
|
// TODO this would be a lot easier if LogConsoleBuffer stored LogRecords instead of formatted strings
|
Big directory rework.
Eliminate all uses of the current working directory, and
set up multiple directories specified by absolute paths for various uses.
Add a WorkingDir class to create a user config directory and
migrate files to it for new installs.
The directory will be $HOME/.i2p on linux and %APPDIR%\I2P on Windows,
or as specified in the system property -Di2p.dir.config=/path/to/i2pdir
All files except for the base install and temp files will be
in the config directory by default.
Temp files will be in a i2p-xxxxx subdirectory of the system temp directory
specified by the system property java.io.tmpdir.
Convert all file opens in the code to be relative to a specific directory,
as specified in the context. Code and applications should never open
files relative to the current working directory (e.g. new File("foo")).
All files should be accessed in the appropriate context directory,
e.g. new File(_context.getAppDir(), "foo").
The router.config file location may be specified as a system property on the
java command line with -Drouter.configLocation=/path/to/router.config
All directories may be specified as properties in the router.config file.
The migration will copy all files from an existing installation,
except i2psnark/, with the system property -Di2p.dir.migrate=true.
Otherwise it will just set up a new directory with a minimal configuration.
The migration will also create a modified wrapper.config and (on linux only)
a modified i2prouter script, and place them in the config directory.
There are no changes to the installer or the default i2prouter, i2prouter.bat,
i2prouter, wrapper.config, runplain.sh, windows service installer/uninstaller,
etc. in this checkin.
* Directories. These are all set at instantiation and will not be changed by
* subsequent property changes.
* All properties, if set, should be absolute paths.
*
* Name Property Method Files
* ----- -------- ----- -----
* Base i2p.dir.base getBaseDir() lib/, webapps/, docs/, geoip/, licenses/, ...
* Temp i2p.dir.temp getTempDir() Temporary files
* Config i2p.dir.config getConfigDir() *.config, hosts.txt, addressbook/, ...
*
* (the following all default to the same as Config)
*
* Router i2p.dir.router getRouterDir() netDb/, peerProfiles/, router.*, keyBackup/, ...
* Log i2p.dir.log getLogDir() wrapper.log*, logs/
* PID i2p.dir.pid getPIDDir() wrapper *.pid files, router.ping
* App i2p.dir.app getAppDir() eepsite/, ...
*
* Note that we can't control where the wrapper actually puts its files.
All these will be set appropriately in a Router Context.
In an I2P App Context, all except Temp will be the current working directory.
Lightly tested so far, needs much more testing.
2009-06-04 19:14:40 +00:00
|
|
|
String color;
|
|
|
|
// Homeland Security Advisory System
|
|
|
|
// http://www.dhs.gov/xinfoshare/programs/Copy_of_press_release_0046.shtm
|
|
|
|
// but pink instead of yellow for WARN
|
2015-09-25 19:55:36 +00:00
|
|
|
if (msg.contains(_t("CRIT")))
|
Big directory rework.
Eliminate all uses of the current working directory, and
set up multiple directories specified by absolute paths for various uses.
Add a WorkingDir class to create a user config directory and
migrate files to it for new installs.
The directory will be $HOME/.i2p on linux and %APPDIR%\I2P on Windows,
or as specified in the system property -Di2p.dir.config=/path/to/i2pdir
All files except for the base install and temp files will be
in the config directory by default.
Temp files will be in a i2p-xxxxx subdirectory of the system temp directory
specified by the system property java.io.tmpdir.
Convert all file opens in the code to be relative to a specific directory,
as specified in the context. Code and applications should never open
files relative to the current working directory (e.g. new File("foo")).
All files should be accessed in the appropriate context directory,
e.g. new File(_context.getAppDir(), "foo").
The router.config file location may be specified as a system property on the
java command line with -Drouter.configLocation=/path/to/router.config
All directories may be specified as properties in the router.config file.
The migration will copy all files from an existing installation,
except i2psnark/, with the system property -Di2p.dir.migrate=true.
Otherwise it will just set up a new directory with a minimal configuration.
The migration will also create a modified wrapper.config and (on linux only)
a modified i2prouter script, and place them in the config directory.
There are no changes to the installer or the default i2prouter, i2prouter.bat,
i2prouter, wrapper.config, runplain.sh, windows service installer/uninstaller,
etc. in this checkin.
* Directories. These are all set at instantiation and will not be changed by
* subsequent property changes.
* All properties, if set, should be absolute paths.
*
* Name Property Method Files
* ----- -------- ----- -----
* Base i2p.dir.base getBaseDir() lib/, webapps/, docs/, geoip/, licenses/, ...
* Temp i2p.dir.temp getTempDir() Temporary files
* Config i2p.dir.config getConfigDir() *.config, hosts.txt, addressbook/, ...
*
* (the following all default to the same as Config)
*
* Router i2p.dir.router getRouterDir() netDb/, peerProfiles/, router.*, keyBackup/, ...
* Log i2p.dir.log getLogDir() wrapper.log*, logs/
* PID i2p.dir.pid getPIDDir() wrapper *.pid files, router.ping
* App i2p.dir.app getAppDir() eepsite/, ...
*
* Note that we can't control where the wrapper actually puts its files.
All these will be set appropriately in a Router Context.
In an I2P App Context, all except Temp will be the current working directory.
Lightly tested so far, needs much more testing.
2009-06-04 19:14:40 +00:00
|
|
|
color = "#cc0000";
|
2015-09-25 19:55:36 +00:00
|
|
|
else if (msg.contains(_t("ERROR")))
|
Big directory rework.
Eliminate all uses of the current working directory, and
set up multiple directories specified by absolute paths for various uses.
Add a WorkingDir class to create a user config directory and
migrate files to it for new installs.
The directory will be $HOME/.i2p on linux and %APPDIR%\I2P on Windows,
or as specified in the system property -Di2p.dir.config=/path/to/i2pdir
All files except for the base install and temp files will be
in the config directory by default.
Temp files will be in a i2p-xxxxx subdirectory of the system temp directory
specified by the system property java.io.tmpdir.
Convert all file opens in the code to be relative to a specific directory,
as specified in the context. Code and applications should never open
files relative to the current working directory (e.g. new File("foo")).
All files should be accessed in the appropriate context directory,
e.g. new File(_context.getAppDir(), "foo").
The router.config file location may be specified as a system property on the
java command line with -Drouter.configLocation=/path/to/router.config
All directories may be specified as properties in the router.config file.
The migration will copy all files from an existing installation,
except i2psnark/, with the system property -Di2p.dir.migrate=true.
Otherwise it will just set up a new directory with a minimal configuration.
The migration will also create a modified wrapper.config and (on linux only)
a modified i2prouter script, and place them in the config directory.
There are no changes to the installer or the default i2prouter, i2prouter.bat,
i2prouter, wrapper.config, runplain.sh, windows service installer/uninstaller,
etc. in this checkin.
* Directories. These are all set at instantiation and will not be changed by
* subsequent property changes.
* All properties, if set, should be absolute paths.
*
* Name Property Method Files
* ----- -------- ----- -----
* Base i2p.dir.base getBaseDir() lib/, webapps/, docs/, geoip/, licenses/, ...
* Temp i2p.dir.temp getTempDir() Temporary files
* Config i2p.dir.config getConfigDir() *.config, hosts.txt, addressbook/, ...
*
* (the following all default to the same as Config)
*
* Router i2p.dir.router getRouterDir() netDb/, peerProfiles/, router.*, keyBackup/, ...
* Log i2p.dir.log getLogDir() wrapper.log*, logs/
* PID i2p.dir.pid getPIDDir() wrapper *.pid files, router.ping
* App i2p.dir.app getAppDir() eepsite/, ...
*
* Note that we can't control where the wrapper actually puts its files.
All these will be set appropriately in a Router Context.
In an I2P App Context, all except Temp will be the current working directory.
Lightly tested so far, needs much more testing.
2009-06-04 19:14:40 +00:00
|
|
|
color = "#ff3300";
|
2015-09-25 19:55:36 +00:00
|
|
|
else if (msg.contains(_t("WARN")))
|
Big directory rework.
Eliminate all uses of the current working directory, and
set up multiple directories specified by absolute paths for various uses.
Add a WorkingDir class to create a user config directory and
migrate files to it for new installs.
The directory will be $HOME/.i2p on linux and %APPDIR%\I2P on Windows,
or as specified in the system property -Di2p.dir.config=/path/to/i2pdir
All files except for the base install and temp files will be
in the config directory by default.
Temp files will be in a i2p-xxxxx subdirectory of the system temp directory
specified by the system property java.io.tmpdir.
Convert all file opens in the code to be relative to a specific directory,
as specified in the context. Code and applications should never open
files relative to the current working directory (e.g. new File("foo")).
All files should be accessed in the appropriate context directory,
e.g. new File(_context.getAppDir(), "foo").
The router.config file location may be specified as a system property on the
java command line with -Drouter.configLocation=/path/to/router.config
All directories may be specified as properties in the router.config file.
The migration will copy all files from an existing installation,
except i2psnark/, with the system property -Di2p.dir.migrate=true.
Otherwise it will just set up a new directory with a minimal configuration.
The migration will also create a modified wrapper.config and (on linux only)
a modified i2prouter script, and place them in the config directory.
There are no changes to the installer or the default i2prouter, i2prouter.bat,
i2prouter, wrapper.config, runplain.sh, windows service installer/uninstaller,
etc. in this checkin.
* Directories. These are all set at instantiation and will not be changed by
* subsequent property changes.
* All properties, if set, should be absolute paths.
*
* Name Property Method Files
* ----- -------- ----- -----
* Base i2p.dir.base getBaseDir() lib/, webapps/, docs/, geoip/, licenses/, ...
* Temp i2p.dir.temp getTempDir() Temporary files
* Config i2p.dir.config getConfigDir() *.config, hosts.txt, addressbook/, ...
*
* (the following all default to the same as Config)
*
* Router i2p.dir.router getRouterDir() netDb/, peerProfiles/, router.*, keyBackup/, ...
* Log i2p.dir.log getLogDir() wrapper.log*, logs/
* PID i2p.dir.pid getPIDDir() wrapper *.pid files, router.ping
* App i2p.dir.app getAppDir() eepsite/, ...
*
* Note that we can't control where the wrapper actually puts its files.
All these will be set appropriately in a Router Context.
In an I2P App Context, all except Temp will be the current working directory.
Lightly tested so far, needs much more testing.
2009-06-04 19:14:40 +00:00
|
|
|
color = "#ff00cc";
|
2015-09-25 19:55:36 +00:00
|
|
|
else if (msg.contains(_t("INFO")))
|
Big directory rework.
Eliminate all uses of the current working directory, and
set up multiple directories specified by absolute paths for various uses.
Add a WorkingDir class to create a user config directory and
migrate files to it for new installs.
The directory will be $HOME/.i2p on linux and %APPDIR%\I2P on Windows,
or as specified in the system property -Di2p.dir.config=/path/to/i2pdir
All files except for the base install and temp files will be
in the config directory by default.
Temp files will be in a i2p-xxxxx subdirectory of the system temp directory
specified by the system property java.io.tmpdir.
Convert all file opens in the code to be relative to a specific directory,
as specified in the context. Code and applications should never open
files relative to the current working directory (e.g. new File("foo")).
All files should be accessed in the appropriate context directory,
e.g. new File(_context.getAppDir(), "foo").
The router.config file location may be specified as a system property on the
java command line with -Drouter.configLocation=/path/to/router.config
All directories may be specified as properties in the router.config file.
The migration will copy all files from an existing installation,
except i2psnark/, with the system property -Di2p.dir.migrate=true.
Otherwise it will just set up a new directory with a minimal configuration.
The migration will also create a modified wrapper.config and (on linux only)
a modified i2prouter script, and place them in the config directory.
There are no changes to the installer or the default i2prouter, i2prouter.bat,
i2prouter, wrapper.config, runplain.sh, windows service installer/uninstaller,
etc. in this checkin.
* Directories. These are all set at instantiation and will not be changed by
* subsequent property changes.
* All properties, if set, should be absolute paths.
*
* Name Property Method Files
* ----- -------- ----- -----
* Base i2p.dir.base getBaseDir() lib/, webapps/, docs/, geoip/, licenses/, ...
* Temp i2p.dir.temp getTempDir() Temporary files
* Config i2p.dir.config getConfigDir() *.config, hosts.txt, addressbook/, ...
*
* (the following all default to the same as Config)
*
* Router i2p.dir.router getRouterDir() netDb/, peerProfiles/, router.*, keyBackup/, ...
* Log i2p.dir.log getLogDir() wrapper.log*, logs/
* PID i2p.dir.pid getPIDDir() wrapper *.pid files, router.ping
* App i2p.dir.app getAppDir() eepsite/, ...
*
* Note that we can't control where the wrapper actually puts its files.
All these will be set appropriately in a Router Context.
In an I2P App Context, all except Temp will be the current working directory.
Lightly tested so far, needs much more testing.
2009-06-04 19:14:40 +00:00
|
|
|
color = "#000099";
|
|
|
|
else
|
|
|
|
color = "#006600";
|
|
|
|
buf.append("<font color=\"").append(color).append("\">");
|
2010-10-19 14:39:29 +00:00
|
|
|
buf.append(msg);
|
Big directory rework.
Eliminate all uses of the current working directory, and
set up multiple directories specified by absolute paths for various uses.
Add a WorkingDir class to create a user config directory and
migrate files to it for new installs.
The directory will be $HOME/.i2p on linux and %APPDIR%\I2P on Windows,
or as specified in the system property -Di2p.dir.config=/path/to/i2pdir
All files except for the base install and temp files will be
in the config directory by default.
Temp files will be in a i2p-xxxxx subdirectory of the system temp directory
specified by the system property java.io.tmpdir.
Convert all file opens in the code to be relative to a specific directory,
as specified in the context. Code and applications should never open
files relative to the current working directory (e.g. new File("foo")).
All files should be accessed in the appropriate context directory,
e.g. new File(_context.getAppDir(), "foo").
The router.config file location may be specified as a system property on the
java command line with -Drouter.configLocation=/path/to/router.config
All directories may be specified as properties in the router.config file.
The migration will copy all files from an existing installation,
except i2psnark/, with the system property -Di2p.dir.migrate=true.
Otherwise it will just set up a new directory with a minimal configuration.
The migration will also create a modified wrapper.config and (on linux only)
a modified i2prouter script, and place them in the config directory.
There are no changes to the installer or the default i2prouter, i2prouter.bat,
i2prouter, wrapper.config, runplain.sh, windows service installer/uninstaller,
etc. in this checkin.
* Directories. These are all set at instantiation and will not be changed by
* subsequent property changes.
* All properties, if set, should be absolute paths.
*
* Name Property Method Files
* ----- -------- ----- -----
* Base i2p.dir.base getBaseDir() lib/, webapps/, docs/, geoip/, licenses/, ...
* Temp i2p.dir.temp getTempDir() Temporary files
* Config i2p.dir.config getConfigDir() *.config, hosts.txt, addressbook/, ...
*
* (the following all default to the same as Config)
*
* Router i2p.dir.router getRouterDir() netDb/, peerProfiles/, router.*, keyBackup/, ...
* Log i2p.dir.log getLogDir() wrapper.log*, logs/
* PID i2p.dir.pid getPIDDir() wrapper *.pid files, router.ping
* App i2p.dir.app getAppDir() eepsite/, ...
*
* Note that we can't control where the wrapper actually puts its files.
All these will be set appropriately in a Router Context.
In an I2P App Context, all except Temp will be the current working directory.
Lightly tested so far, needs much more testing.
2009-06-04 19:14:40 +00:00
|
|
|
buf.append("</font>");
|
|
|
|
} else {
|
|
|
|
buf.append(msg);
|
|
|
|
}
|
2004-09-27 07:57:43 +00:00
|
|
|
buf.append("</li>\n");
|
|
|
|
}
|
2011-03-12 16:11:10 +00:00
|
|
|
buf.append("</ul>\n");
|
2004-09-27 07:57:43 +00:00
|
|
|
|
|
|
|
return buf.toString();
|
|
|
|
}
|
2014-01-31 18:34:27 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Read in the last few lines of a (newline delimited) textfile, or null if
|
|
|
|
* the file doesn't exist.
|
|
|
|
*
|
|
|
|
* Same as FileUtil.readTextFile but uses platform encoding,
|
|
|
|
* not UTF-8, since the wrapper log cannot be configured:
|
|
|
|
* http://stackoverflow.com/questions/14887690/how-do-i-get-the-tanuki-wrapper-log-files-to-be-utf-8-encoded
|
|
|
|
*
|
|
|
|
* Warning - this inefficiently allocates a StringBuilder of size maxNumLines*80,
|
|
|
|
* so don't make it too big.
|
|
|
|
* Warning - converts \r\n to \n
|
|
|
|
*
|
|
|
|
* @param maxNumLines max number of lines (greater than zero)
|
|
|
|
* @return string or null; does not throw IOException.
|
|
|
|
* @since 0.9.11 modded from FileUtil.readTextFile()
|
|
|
|
*/
|
|
|
|
private static String readTextFile(File f, int maxNumLines) {
|
|
|
|
if (!f.exists()) return null;
|
|
|
|
FileInputStream fis = null;
|
2014-04-21 10:54:52 +00:00
|
|
|
BufferedReader in = null;
|
2014-01-31 18:34:27 +00:00
|
|
|
try {
|
|
|
|
fis = new FileInputStream(f);
|
2014-04-21 10:54:52 +00:00
|
|
|
in = new BufferedReader(new InputStreamReader(fis));
|
2014-01-31 18:34:27 +00:00
|
|
|
List<String> lines = new ArrayList<String>(maxNumLines);
|
|
|
|
String line = null;
|
|
|
|
while ( (line = in.readLine()) != null) {
|
|
|
|
lines.add(line);
|
|
|
|
if (lines.size() >= maxNumLines)
|
|
|
|
lines.remove(0);
|
|
|
|
}
|
|
|
|
StringBuilder buf = new StringBuilder(lines.size() * 80);
|
|
|
|
for (int i = 0; i < lines.size(); i++) {
|
|
|
|
buf.append(lines.get(i)).append('\n');
|
|
|
|
}
|
|
|
|
return buf.toString();
|
|
|
|
} catch (IOException ioe) {
|
|
|
|
return null;
|
|
|
|
} finally {
|
2014-04-21 10:54:52 +00:00
|
|
|
if (in != null) try { in.close(); } catch (IOException ioe) {}
|
2014-01-31 18:34:27 +00:00
|
|
|
}
|
|
|
|
}
|
2004-07-24 02:06:07 +00:00
|
|
|
}
|