2004-07-24 02:06:07 +00:00
|
|
|
package net.i2p.router.web;
|
|
|
|
|
2004-09-29 19:34:02 +00:00
|
|
|
import java.io.File;
|
2008-06-16 12:26:36 +00:00
|
|
|
import java.io.FilenameFilter;
|
2004-07-24 02:06:07 +00:00
|
|
|
import java.io.IOException;
|
2004-08-10 19:51:11 +00:00
|
|
|
import java.util.List;
|
2008-06-16 12:26:36 +00:00
|
|
|
import java.util.Properties;
|
2009-04-08 01:34:12 +00:00
|
|
|
import java.util.StringTokenizer;
|
2004-08-10 19:51:11 +00:00
|
|
|
|
2005-03-24 01:19:52 +00:00
|
|
|
import net.i2p.I2PAppContext;
|
2004-08-29 21:06:15 +00:00
|
|
|
import net.i2p.apps.systray.SysTray;
|
2008-06-16 12:26:36 +00:00
|
|
|
import net.i2p.data.DataHelper;
|
2008-07-16 13:42:54 +00:00
|
|
|
import net.i2p.router.RouterContext;
|
2004-09-29 19:34:02 +00:00
|
|
|
import net.i2p.util.FileUtil;
|
2005-03-24 01:19:52 +00:00
|
|
|
import net.i2p.util.I2PThread;
|
2004-08-10 19:51:11 +00:00
|
|
|
|
2004-08-29 22:35:55 +00:00
|
|
|
import org.mortbay.http.DigestAuthenticator;
|
2004-08-10 19:51:11 +00:00
|
|
|
import org.mortbay.http.HashUserRealm;
|
|
|
|
import org.mortbay.http.SecurityConstraint;
|
2008-07-16 13:42:54 +00:00
|
|
|
import org.mortbay.http.handler.SecurityHandler;
|
|
|
|
import org.mortbay.jetty.Server;
|
|
|
|
import org.mortbay.jetty.servlet.WebApplicationContext;
|
2004-07-24 02:06:07 +00:00
|
|
|
|
|
|
|
public class RouterConsoleRunner {
|
|
|
|
private Server _server;
|
|
|
|
private String _listenPort = "7657";
|
2004-08-10 19:51:11 +00:00
|
|
|
private String _listenHost = "127.0.0.1";
|
2004-07-24 02:06:07 +00:00
|
|
|
private String _webAppsDir = "./webapps/";
|
2008-06-16 12:26:36 +00:00
|
|
|
private static final String PROP_WEBAPP_CONFIG_FILENAME = "router.webappsConfigFile";
|
|
|
|
private static final String DEFAULT_WEBAPP_CONFIG_FILENAME = "webapps.config";
|
|
|
|
public static final String ROUTERCONSOLE = "routerconsole";
|
|
|
|
public static final String PREFIX = "webapps.";
|
|
|
|
public static final String ENABLED = ".startOnLoad";
|
2004-07-24 02:06:07 +00:00
|
|
|
|
2004-09-30 06:57:22 +00:00
|
|
|
static {
|
|
|
|
System.setProperty("org.mortbay.http.Version.paranoid", "true");
|
2006-03-16 21:45:17 +00:00
|
|
|
System.setProperty("java.awt.headless", "true");
|
2004-09-30 06:57:22 +00:00
|
|
|
}
|
|
|
|
|
2009-04-08 01:34:12 +00:00
|
|
|
/**
|
|
|
|
* @param args second arg may be a comma-separated list of bind addresses,
|
|
|
|
* for example ::1,127.0.0.1
|
|
|
|
* On XP, the other order (127.0.0.1,::1) fails the IPV6 bind,
|
|
|
|
* because 127.0.0.1 will bind ::1 also. But even though it's bound
|
|
|
|
* to both, we can't connect to [::1]:7657 for some reason.
|
|
|
|
* So the wise choice is ::1,127.0.0.1
|
|
|
|
*/
|
2004-07-24 02:06:07 +00:00
|
|
|
public RouterConsoleRunner(String args[]) {
|
|
|
|
if (args.length == 3) {
|
|
|
|
_listenPort = args[0].trim();
|
|
|
|
_listenHost = args[1].trim();
|
|
|
|
_webAppsDir = args[2].trim();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void main(String args[]) {
|
|
|
|
RouterConsoleRunner runner = new RouterConsoleRunner(args);
|
|
|
|
runner.startConsole();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void startConsole() {
|
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
|
|
|
File workDir = new File(I2PAppContext.getGlobalContext().getTempDir(), "jetty-work");
|
2004-09-29 19:34:02 +00:00
|
|
|
boolean workDirRemoved = FileUtil.rmdir(workDir, false);
|
|
|
|
if (!workDirRemoved)
|
|
|
|
System.err.println("ERROR: Unable to remove Jetty temporary work directory");
|
|
|
|
boolean workDirCreated = workDir.mkdirs();
|
|
|
|
if (!workDirCreated)
|
|
|
|
System.err.println("ERROR: Unable to create Jetty temporary work directory");
|
|
|
|
|
2004-07-24 02:06:07 +00:00
|
|
|
_server = new Server();
|
2008-06-16 12:26:36 +00:00
|
|
|
boolean rewrite = false;
|
|
|
|
Properties props = webAppProperties();
|
|
|
|
if (props.size() <= 0) {
|
|
|
|
props.setProperty(PREFIX + ROUTERCONSOLE + ENABLED, "true");
|
|
|
|
rewrite = true;
|
|
|
|
}
|
2004-07-24 02:06:07 +00:00
|
|
|
try {
|
2009-04-08 01:34:12 +00:00
|
|
|
StringTokenizer tok = new StringTokenizer(_listenHost, " ,");
|
|
|
|
int boundAddresses = 0;
|
|
|
|
while (tok.hasMoreTokens()) {
|
|
|
|
String host = tok.nextToken().trim();
|
|
|
|
try {
|
|
|
|
if (host.indexOf(":") >= 0) // IPV6 - requires patched Jetty 5
|
|
|
|
_server.addListener('[' + host + "]:" + _listenPort);
|
|
|
|
else
|
|
|
|
_server.addListener(host + ':' + _listenPort);
|
|
|
|
boundAddresses++;
|
|
|
|
} catch (IOException ioe) { // this doesn't seem to work, exceptions don't happen until start() below
|
|
|
|
System.err.println("Unable to bind routerconsole to " + host + " port " + _listenPort + ' ' + ioe);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (boundAddresses <= 0) {
|
|
|
|
System.err.println("Unable to bind routerconsole to any address on port " + _listenPort);
|
|
|
|
return;
|
|
|
|
}
|
2008-06-16 12:26:36 +00:00
|
|
|
_server.setRootWebApp(ROUTERCONSOLE);
|
|
|
|
WebApplicationContext wac = _server.addWebApplication("/", _webAppsDir + ROUTERCONSOLE + ".war");
|
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
|
|
|
File tmpdir = new File(workDir, ROUTERCONSOLE + "-" + _listenPort);
|
|
|
|
tmpdir.mkdir();
|
|
|
|
wac.setTempDirectory(tmpdir);
|
2008-06-16 12:26:36 +00:00
|
|
|
initialize(wac);
|
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
|
|
|
File dir = new File(I2PAppContext.getGlobalContext().getBaseDir(), _webAppsDir);
|
2008-06-16 12:26:36 +00:00
|
|
|
String fileNames[] = dir.list(WarFilenameFilter.instance());
|
|
|
|
if (fileNames != null) {
|
|
|
|
for (int i = 0; i < fileNames.length; i++) {
|
|
|
|
try {
|
|
|
|
String appName = fileNames[i].substring(0, fileNames[i].lastIndexOf(".war"));
|
|
|
|
String enabled = props.getProperty(PREFIX + appName + ENABLED);
|
|
|
|
if (! "false".equals(enabled)) {
|
|
|
|
String path = new File(dir, fileNames[i]).getCanonicalPath();
|
|
|
|
wac = _server.addWebApplication("/"+ appName, path);
|
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
|
|
|
tmpdir = new File(workDir, appName + "-" + _listenPort);
|
|
|
|
tmpdir.mkdir();
|
|
|
|
wac.setTempDirectory(tmpdir);
|
2008-06-16 12:26:36 +00:00
|
|
|
initialize(wac);
|
|
|
|
if (enabled == null) {
|
|
|
|
// do this so configclients.jsp knows about all apps from reading the config
|
|
|
|
props.setProperty(PREFIX + appName + ENABLED, "true");
|
|
|
|
rewrite = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (IOException ioe) {
|
|
|
|
System.err.println("Error resolving '" + fileNames[i] + "' in '" + dir);
|
|
|
|
}
|
|
|
|
}
|
2004-08-10 19:51:11 +00:00
|
|
|
}
|
2004-07-24 02:06:07 +00:00
|
|
|
} catch (IOException ioe) {
|
|
|
|
ioe.printStackTrace();
|
|
|
|
}
|
2008-06-16 12:26:36 +00:00
|
|
|
if (rewrite)
|
|
|
|
storeWebAppProperties(props);
|
2004-07-24 02:06:07 +00:00
|
|
|
try {
|
|
|
|
_server.start();
|
2005-02-16 jrandom
* (Merged the 0.5-pre branch back into CVS HEAD)
* Replaced the old tunnel routing crypto with the one specified in
router/doc/tunnel-alt.html, including updates to the web console to view
and tweak it.
* Provide the means for routers to reject tunnel requests with a wider
range of responses:
probabalistic rejection, due to approaching overload
transient rejection, due to temporary overload
bandwidth rejection, due to persistent bandwidth overload
critical rejection, due to general router fault (or imminent shutdown)
The different responses are factored into the profiles accordingly.
* Replaced the old I2CP tunnel related options (tunnels.depthInbound, etc)
with a series of new properties, relevent to the new tunnel routing code:
inbound.nickname (used on the console)
inbound.quantity (# of tunnels to use in any leaseSets)
inbound.backupQuantity (# of tunnels to keep in the ready)
inbound.length (# of remote peers in the tunnel)
inbound.lengthVariance (if > 0, permute the length by adding a random #
up to the variance. if < 0, permute the length
by adding or subtracting a random # up to the
variance)
outbound.* (same as the inbound, except for the, uh, outbound tunnels
in that client's pool)
There are other options, and more will be added later, but the above are
the most relevent ones.
* Replaced Jetty 4.2.21 with Jetty 5.1.2
* Compress all profile data on disk.
* Adjust the reseeding functionality to work even when the JVM's http proxy
is set.
* Enable a poor-man's interactive-flow in the streaming lib by choking the
max window size.
* Reduced the default streaming lib max message size to 16KB (though still
configurable by the user), also doubling the default maximum window
size.
* Replaced the RouterIdentity in a Lease with its SHA256 hash.
* Reduced the overall I2NP message checksum from a full 32 byte SHA256 to
the first byte of the SHA256.
* Added a new "netId" flag to let routers drop references to other routers
who we won't be able to talk to.
* Extended the timestamper to get a second (or third) opinion whenever it
wants to actually adjust the clock offset.
* Replaced that kludge of a timestamp I2NP message with a full blown
DateMessage.
* Substantial memory optimizations within the router and the SDK to reduce
GC churn. Client apps and the streaming libs have not been tuned,
however.
* More bugfixes thank you can shake a stick at.
2005-02-13 jrandom
* Updated jbigi source to handle 64bit CPUs. The bundled jbigi.jar still
only contains 32bit versions, so build your own, placing libjbigi.so in
your install dir if necessary. (thanks mule!)
* Added support for libjbigi-$os-athlon64 to NativeBigInteger and CPUID
(thanks spaetz!)
2005-02-16 22:23:47 +00:00
|
|
|
} catch (Exception me) {
|
2009-04-08 01:34:12 +00:00
|
|
|
System.err.println("WARNING: Error starting one or more listeners of the Router Console server.\n" +
|
|
|
|
"If your console is still accessible at http://127.0.0.1:7657/,\n" +
|
|
|
|
"this may be a problem only with binding to the IPV6 address ::1.\n" +
|
|
|
|
"If so, you may ignore this error, or remove the\n" +
|
|
|
|
"\"::1,\" in the \"clientApp.0.args\" line of the clients.config file.\n" +
|
|
|
|
"Exception: " + me);
|
2004-07-24 02:06:07 +00:00
|
|
|
}
|
2004-08-29 21:06:15 +00:00
|
|
|
try {
|
|
|
|
SysTray tray = SysTray.getInstance();
|
|
|
|
} catch (Throwable t) {
|
|
|
|
t.printStackTrace();
|
|
|
|
}
|
2005-09-29 19:19:22 +00:00
|
|
|
|
2005-09-30 07:17:56 +00:00
|
|
|
// we check the i2p installation directory (.) for a flag telling us not to reseed,
|
|
|
|
// but also check the home directory for that flag too, since new users installing i2p
|
|
|
|
// don't have an installation directory that they can put the flag in yet.
|
2005-09-29 19:19:22 +00:00
|
|
|
File noReseedFile = new File(new File(System.getProperty("user.home")), ".i2pnoreseed");
|
2005-09-30 07:17:56 +00:00
|
|
|
File noReseedFileAlt1 = new File(new File(System.getProperty("user.home")), "noreseed.i2p");
|
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
|
|
|
File noReseedFileAlt2 = new File(I2PAppContext.getGlobalContext().getConfigDir(), ".i2pnoreseed");
|
|
|
|
File noReseedFileAlt3 = new File(I2PAppContext.getGlobalContext().getConfigDir(), "noreseed.i2p");
|
2005-09-30 07:17:56 +00:00
|
|
|
if (!noReseedFile.exists() && !noReseedFileAlt1.exists() && !noReseedFileAlt2.exists() && !noReseedFileAlt3.exists()) {
|
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
|
|
|
File netDb = new File(I2PAppContext.getGlobalContext().getRouterDir(), "netDb");
|
2005-09-30 07:17:56 +00:00
|
|
|
// sure, some of them could be "my.info" or various leaseSet- files, but chances are,
|
|
|
|
// if someone has those files, they've already been seeded (at least enough to let them
|
|
|
|
// get i2p started - they can reseed later in the web console)
|
|
|
|
String names[] = (netDb.exists() ? netDb.list() : null);
|
|
|
|
if ( (names == null) || (names.length < 15) ) {
|
2007-07-15 00:56:18 +00:00
|
|
|
ReseedHandler reseedHandler = new ReseedHandler();
|
|
|
|
reseedHandler.requestReseed();
|
2005-09-29 19:19:22 +00:00
|
|
|
}
|
|
|
|
}
|
2005-03-24 01:19:52 +00:00
|
|
|
|
2005-04-05 16:06:14 +00:00
|
|
|
NewsFetcher fetcher = NewsFetcher.getInstance(I2PAppContext.getGlobalContext());
|
|
|
|
I2PThread t = new I2PThread(fetcher, "NewsFetcher");
|
2005-03-24 01:19:52 +00:00
|
|
|
t.setDaemon(true);
|
|
|
|
t.start();
|
2006-03-16 21:45:17 +00:00
|
|
|
|
|
|
|
I2PThread st = new I2PThread(new StatSummarizer(), "StatSummarizer");
|
|
|
|
st.setDaemon(true);
|
|
|
|
st.start();
|
2004-07-24 02:06:07 +00:00
|
|
|
}
|
|
|
|
|
2004-08-10 19:51:11 +00:00
|
|
|
private void initialize(WebApplicationContext context) {
|
|
|
|
String password = getPassword();
|
|
|
|
if (password != null) {
|
2005-03-01 17:50:52 +00:00
|
|
|
HashUserRealm realm = new HashUserRealm("i2prouter");
|
2004-08-10 19:51:11 +00:00
|
|
|
realm.put("admin", password);
|
|
|
|
realm.addUserToRole("admin", "routerAdmin");
|
|
|
|
context.setRealm(realm);
|
2004-08-29 22:35:55 +00:00
|
|
|
context.setAuthenticator(new DigestAuthenticator());
|
2004-08-10 19:51:11 +00:00
|
|
|
context.addHandler(0, new SecurityHandler());
|
|
|
|
SecurityConstraint constraint = new SecurityConstraint("admin", "routerAdmin");
|
|
|
|
constraint.setAuthenticate(true);
|
|
|
|
context.addSecurityConstraint("/", constraint);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private String getPassword() {
|
|
|
|
List contexts = RouterContext.listContexts();
|
|
|
|
if (contexts != null) {
|
|
|
|
for (int i = 0; i < contexts.size(); i++) {
|
|
|
|
RouterContext ctx = (RouterContext)contexts.get(i);
|
|
|
|
String password = ctx.getProperty("consolePassword");
|
|
|
|
if (password != null) {
|
|
|
|
password = password.trim();
|
|
|
|
if (password.length() > 0) {
|
|
|
|
return password;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// no password in any context
|
|
|
|
return null;
|
|
|
|
} else {
|
|
|
|
// no contexts?!
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-07-24 02:06:07 +00:00
|
|
|
public void stopConsole() {
|
|
|
|
try {
|
|
|
|
_server.stop();
|
|
|
|
} catch (InterruptedException ie) {
|
|
|
|
ie.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-16 12:26:36 +00:00
|
|
|
public static Properties webAppProperties() {
|
|
|
|
Properties rv = new Properties();
|
|
|
|
// String webappConfigFile = ctx.getProperty(PROP_WEBAPP_CONFIG_FILENAME, DEFAULT_WEBAPP_CONFIG_FILENAME);
|
|
|
|
String webappConfigFile = DEFAULT_WEBAPP_CONFIG_FILENAME;
|
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
|
|
|
File cfgFile = new File(I2PAppContext.getGlobalContext().getConfigDir(), webappConfigFile);
|
2008-06-16 12:26:36 +00:00
|
|
|
|
|
|
|
try {
|
|
|
|
DataHelper.loadProps(rv, cfgFile);
|
|
|
|
} catch (IOException ioe) {
|
|
|
|
// _log.warn("Error loading the client app properties from " + cfgFile.getName(), ioe);
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void storeWebAppProperties(Properties props) {
|
|
|
|
// String webappConfigFile = ctx.getProperty(PROP_WEBAPP_CONFIG_FILENAME, DEFAULT_WEBAPP_CONFIG_FILENAME);
|
|
|
|
String webappConfigFile = DEFAULT_WEBAPP_CONFIG_FILENAME;
|
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
|
|
|
File cfgFile = new File(I2PAppContext.getGlobalContext().getConfigDir(), webappConfigFile);
|
2008-06-16 12:26:36 +00:00
|
|
|
|
|
|
|
try {
|
|
|
|
DataHelper.storeProps(props, cfgFile);
|
|
|
|
} catch (IOException ioe) {
|
|
|
|
// _log.warn("Error loading the client app properties from " + cfgFile.getName(), ioe);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private static class WarFilenameFilter implements FilenameFilter {
|
|
|
|
private static final WarFilenameFilter _filter = new WarFilenameFilter();
|
|
|
|
public static WarFilenameFilter instance() { return _filter; }
|
|
|
|
public boolean accept(File dir, String name) {
|
|
|
|
return (name != null) && (name.endsWith(".war") && !name.equals(ROUTERCONSOLE + ".war"));
|
|
|
|
}
|
|
|
|
}
|
2004-07-24 02:06:07 +00:00
|
|
|
}
|