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.
This commit is contained in:
zzz
2009-06-04 19:14:40 +00:00
parent 8ff2724213
commit 524a25eb2c
46 changed files with 1039 additions and 244 deletions

View File

@@ -23,6 +23,7 @@
*/
package net.i2p.BOB;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
@@ -34,6 +35,8 @@ import java.net.Socket;
import java.net.SocketTimeoutException;
import java.util.Properties;
import java.util.concurrent.atomic.AtomicBoolean;
import net.i2p.I2PAppContext;
import net.i2p.client.I2PClient;
import net.i2p.client.streaming.RetransmissionTimer;
import net.i2p.util.Log;
@@ -186,16 +189,19 @@ public class BOB {
i = Y2.hashCode();
try {
{
File cfg = new File(configLocation);
if (!cfg.isAbsolute())
cfg = new File(I2PAppContext.getGlobalContext().getConfigDir(), configLocation);
try {
FileInputStream fi = new FileInputStream(configLocation);
FileInputStream fi = new FileInputStream(cfg);
props.load(fi);
fi.close();
} catch (FileNotFoundException fnfe) {
warn("Unable to load up the BOB config file " + configLocation + ", Using defaults.");
warn("Unable to load up the BOB config file " + cfg.getAbsolutePath() + ", Using defaults.");
warn(fnfe.toString());
save = true;
} catch (IOException ioe) {
warn("IOException on BOB config file " + configLocation + ", using defaults.");
warn("IOException on BOB config file " + cfg.getAbsolutePath() + ", using defaults.");
warn(ioe.toString());
}
}
@@ -228,13 +234,16 @@ public class BOB {
props.setProperty(PROP_BOB_HOST, "localhost");
}
if (save) {
File cfg = new File(configLocation);
if (!cfg.isAbsolute())
cfg = new File(I2PAppContext.getGlobalContext().getConfigDir(), configLocation);
try {
warn("Writing new defaults file " + configLocation);
FileOutputStream fo = new FileOutputStream(configLocation);
props.store(fo, configLocation);
warn("Writing new defaults file " + cfg.getAbsolutePath());
FileOutputStream fo = new FileOutputStream(cfg);
props.store(fo, cfg.getAbsolutePath());
fo.close();
} catch (IOException ioe) {
error("IOException on BOB config file " + configLocation + ", " + ioe);
error("IOException on BOB config file " + cfg.getAbsolutePath() + ", " + ioe);
}
}

View File

@@ -94,20 +94,21 @@ public class AddressBook {
* @param proxyPort port number of proxy
*/
public AddressBook(Subscription subscription, String proxyHost, int proxyPort) {
File tmp = new File(I2PAppContext.getGlobalContext().getTempDir(), "addressbook.tmp");
this.location = subscription.getLocation();
EepGet get = new EepGet(I2PAppContext.getGlobalContext(), true,
proxyHost, proxyPort, 0, -1l, MAX_SUB_SIZE, "addressbook.tmp", null,
proxyHost, proxyPort, 0, -1l, MAX_SUB_SIZE, tmp.getAbsolutePath(), null,
subscription.getLocation(), true, subscription.getEtag(), subscription.getLastModified(), null);
if (get.fetch()) {
subscription.setEtag(get.getETag());
subscription.setLastModified(get.getLastModified());
}
try {
this.addresses = ConfigParser.parse(new File("addressbook.tmp"));
this.addresses = ConfigParser.parse(tmp);
} catch (IOException exp) {
this.addresses = new HashMap();
}
new File("addressbook.tmp").delete();
tmp.delete();
}
/**

View File

@@ -28,6 +28,8 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import net.i2p.I2PAppContext;
/**
* Main class of addressbook. Performs updates, and runs the main loop.
*
@@ -125,11 +127,13 @@ public class Daemon {
public void run(String[] args) {
String settingsLocation = "config.txt";
String home;
File homeFile;
if (args.length > 0) {
home = args[0];
homeFile = new File(args[0]);
if (!homeFile.isAbsolute())
homeFile = new File(I2PAppContext.getGlobalContext().getRouterDir(), args[0]);
} else {
home = ".";
homeFile = new File(System.getProperty("user.dir"));
}
Map defaultSettings = new HashMap();
@@ -145,7 +149,6 @@ public class Daemon {
defaultSettings.put("last_modified", "last_modified");
defaultSettings.put("update_delay", "12");
File homeFile = new File(home);
if (!homeFile.exists()) {
boolean created = homeFile.mkdirs();
if (created)
@@ -169,7 +172,7 @@ public class Daemon {
delay = 1;
}
update(settings, home);
update(settings, homeFile.getAbsolutePath());
try {
synchronized (this) {
wait(delay * 60 * 60 * 1000);

View File

@@ -73,7 +73,7 @@ public class I2PSnarkUtil {
// This is used for both announce replies and .torrent file downloads,
// so it must be available even if not connected to I2CP.
// so much for multiple instances
_tmpDir = new File("tmp", "i2psnark");
_tmpDir = new File(ctx.getTempDir(), "i2psnark");
FileUtil.rmdir(_tmpDir, false);
_tmpDir.mkdirs();
}

View File

@@ -31,7 +31,7 @@ public class SnarkManager implements Snark.CompleteListener {
/** map of (canonical) filename to Snark instance (unsynchronized) */
private Map _snarks;
private Object _addSnarkLock;
private String _configFile = "i2psnark.config";
private File _configFile;
private Properties _config;
private I2PAppContext _context;
private Log _log;
@@ -51,6 +51,7 @@ public class SnarkManager implements Snark.CompleteListener {
public static final String PROP_META_PREFIX = "i2psnark.zmeta.";
public static final String PROP_META_BITFIELD_SUFFIX = ".bitfield";
private static final String CONFIG_FILE = "i2psnark.config";
public static final String PROP_AUTO_START = "i2snark.autoStart"; // oops
public static final String DEFAULT_AUTO_START = "false";
public static final String PROP_LINK_PREFIX = "i2psnark.linkPrefix";
@@ -66,6 +67,9 @@ public class SnarkManager implements Snark.CompleteListener {
_log = _context.logManager().getLog(SnarkManager.class);
_messages = new ArrayList(16);
_util = new I2PSnarkUtil(_context);
_configFile = new File(CONFIG_FILE);
if (!_configFile.isAbsolute())
_configFile = new File(_context.getConfigDir(), CONFIG_FILE);
loadConfig(null);
}
@@ -112,10 +116,11 @@ public class SnarkManager implements Snark.CompleteListener {
}
private int getStartupDelayMinutes() { return 3; }
public File getDataDir() {
String dir = _config.getProperty(PROP_DIR);
if ( (dir == null) || (dir.trim().length() <= 0) )
dir = "i2psnark";
return new File(dir);
String dir = _config.getProperty(PROP_DIR, "i2psnark");
File f = new File(dir);
if (!f.isAbsolute())
f = new File(_context.getAppDir(), dir);
return f;
}
/** null to set initial defaults */
@@ -123,8 +128,10 @@ public class SnarkManager implements Snark.CompleteListener {
if (_config == null)
_config = new Properties();
if (filename != null) {
_configFile = filename;
File cfg = new File(filename);
if (!cfg.isAbsolute())
cfg = new File(_context.getConfigDir(), filename);
_configFile = cfg;
if (cfg.exists()) {
try {
DataHelper.loadProps(_config, cfg);
@@ -352,10 +359,10 @@ public class SnarkManager implements Snark.CompleteListener {
public void saveConfig() {
try {
synchronized (_configFile) {
DataHelper.storeProps(_config, new File(_configFile));
DataHelper.storeProps(_config, _configFile);
}
} catch (IOException ioe) {
addMessage("Unable to save the config to '" + _configFile + "'");
addMessage("Unable to save the config to '" + _configFile.getAbsolutePath() + "'");
}
}

View File

@@ -173,6 +173,7 @@ public class I2PSnarkServlet extends HttpServlet {
} else if ("Add torrent".equals(action)) {
String newFile = req.getParameter("newFile");
String newURL = req.getParameter("newURL");
// NOTE - newFile currently disabled in HTML form - see below
File f = null;
if ( (newFile != null) && (newFile.trim().length() > 0) )
f = new File(newFile.trim());

View File

@@ -372,6 +372,8 @@ public class I2PTunnel implements Logging, EventDispatcher {
}
privKeyFile = new File(args[2]);
if (!privKeyFile.isAbsolute())
privKeyFile = new File(_context.getAppDir(), args[2]);
if (!privKeyFile.canRead()) {
l.log("private key file does not exist");
_log.error(getPrefix() + "Private key file does not exist or is not readable: " + args[2]);
@@ -419,6 +421,8 @@ public class I2PTunnel implements Logging, EventDispatcher {
}
privKeyFile = new File(args[2]);
if (!privKeyFile.isAbsolute())
privKeyFile = new File(_context.getAppDir(), args[2]);
if (!privKeyFile.canRead()) {
l.log("private key file does not exist");
_log.error(getPrefix() + "Private key file does not exist or is not readable: " + args[2]);
@@ -476,6 +480,8 @@ public class I2PTunnel implements Logging, EventDispatcher {
String spoofedHost = args[2];
privKeyFile = new File(args[3]);
if (!privKeyFile.isAbsolute())
privKeyFile = new File(_context.getAppDir(), args[3]);
if (!privKeyFile.canRead()) {
l.log("private key file does not exist");
_log.error(getPrefix() + "Private key file does not exist or is not readable: " + args[3]);
@@ -870,6 +876,8 @@ public class I2PTunnel implements Logging, EventDispatcher {
}
File privKeyFile = new File(args[1]);
if (!privKeyFile.isAbsolute())
privKeyFile = new File(_context.getAppDir(), args[1]);
if (!privKeyFile.canRead()) {
l.log("private key file does not exist");
_log.error(getPrefix() + "Private key file does not exist or is not readable: " + args[3]);

View File

@@ -3,6 +3,7 @@
*/
package net.i2p.i2ptunnel;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@@ -106,6 +107,8 @@ public class I2PTunnelConnectClient extends I2PTunnelClientBase implements Runna
/** used to assign unique IDs to the threads / clients. no logic or functionality */
private static volatile long __clientId = 0;
private static final File _errorDir = new File(I2PAppContext.getGlobalContext().getBaseDir(), "docs");
/**
* @throws IllegalArgumentException if the I2PTunnel does not contain
* valid config to contact the router
@@ -261,9 +264,9 @@ public class I2PTunnelConnectClient extends I2PTunnelClientBase implements Runna
String str;
byte[] header;
if (usingWWWProxy)
str = FileUtil.readTextFile("docs/dnfp-header.ht", 100, true);
str = FileUtil.readTextFile((new File(_errorDir, "dnfp-header.ht")).getAbsolutePath(), 100, true);
else
str = FileUtil.readTextFile("docs/dnfh-header.ht", 100, true);
str = FileUtil.readTextFile((new File(_errorDir, "dnfh-header.ht")).getAbsolutePath(), 100, true);
if (str != null)
header = str.getBytes();
else
@@ -357,9 +360,9 @@ public class I2PTunnelConnectClient extends I2PTunnelClientBase implements Runna
String str;
byte[] header;
if (usingWWWProxy)
str = FileUtil.readTextFile("docs/dnfp-header.ht", 100, true);
str = FileUtil.readTextFile((new File(_errorDir, "dnfp-header.ht")).getAbsolutePath(), 100, true);
else
str = FileUtil.readTextFile("docs/dnf-header.ht", 100, true);
str = FileUtil.readTextFile((new File(_errorDir, "dnf-header.ht")).getAbsolutePath(), 100, true);
if (str != null)
header = str.getBytes();
else

View File

@@ -4,6 +4,7 @@
package net.i2p.i2ptunnel;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
@@ -136,6 +137,9 @@ public class I2PTunnelHTTPClient extends I2PTunnelClientBase implements Runnable
/** used to assign unique IDs to the threads / clients. no logic or functionality */
private static volatile long __clientId = 0;
private static final File _errorDir = new File(I2PAppContext.getGlobalContext().getBaseDir(), "docs");
/**
* @throws IllegalArgumentException if the I2PTunnel does not contain
* valid config to contact the router
@@ -372,7 +376,7 @@ public class I2PTunnelHTTPClient extends I2PTunnelClientBase implements Runnable
{
String str;
byte[] header;
str = FileUtil.readTextFile("docs/ahelper-conflict-header.ht", 100, true);
str = FileUtil.readTextFile((new File(_errorDir, "ahelper-conflict-header.ht")).getAbsolutePath(), 100, true);
if (str != null) header = str.getBytes();
else header = ERR_AHELPER_CONFLICT;
@@ -558,13 +562,13 @@ public class I2PTunnelHTTPClient extends I2PTunnelClientBase implements Runnable
byte[] header;
boolean showAddrHelper = false;
if (usingWWWProxy)
str = FileUtil.readTextFile("docs/dnfp-header.ht", 100, true);
str = FileUtil.readTextFile((new File(_errorDir, "dnfp-header.ht")).getAbsolutePath(), 100, true);
else if(ahelper != 0)
str = FileUtil.readTextFile("docs/dnfb-header.ht", 100, true);
str = FileUtil.readTextFile((new File(_errorDir, "dnfb-header.ht")).getAbsolutePath(), 100, true);
else if (destination.length() == 60 && destination.endsWith(".b32.i2p"))
str = FileUtil.readTextFile("docs/dnf-header.ht", 100, true);
str = FileUtil.readTextFile((new File(_errorDir, "dnf-header.ht")).getAbsolutePath(), 100, true);
else {
str = FileUtil.readTextFile("docs/dnfh-header.ht", 100, true);
str = FileUtil.readTextFile((new File(_errorDir, "dnfh-header.ht")).getAbsolutePath(), 100, true);
showAddrHelper = true;
}
if (str != null)
@@ -733,9 +737,9 @@ public class I2PTunnelHTTPClient extends I2PTunnelClientBase implements Runnable
String str;
byte[] header;
if (usingWWWProxy)
str = FileUtil.readTextFile("docs/dnfp-header.ht", 100, true);
str = FileUtil.readTextFile((new File(_errorDir, "dnfp-header.ht")).getAbsolutePath(), 100, true);
else
str = FileUtil.readTextFile("docs/dnf-header.ht", 100, true);
str = FileUtil.readTextFile((new File(_errorDir, "dnf-header.ht")).getAbsolutePath(), 100, true);
if (str != null)
header = str.getBytes();
else

View File

@@ -72,6 +72,8 @@ public class TunnelController implements Logging {
}
File keyFile = new File(getPrivKeyFile());
if (!keyFile.isAbsolute())
keyFile = new File(I2PAppContext.getGlobalContext().getAppDir(), getPrivKeyFile());
if (keyFile.exists()) {
//log("Not overwriting existing private keys in " + keyFile.getAbsolutePath());
return;

View File

@@ -270,9 +270,11 @@ public class TunnelControllerGroup {
*/
private Properties loadConfig(String configFile) {
File cfgFile = new File(configFile);
if (!cfgFile.isAbsolute())
cfgFile = new File(I2PAppContext.getGlobalContext().getConfigDir(), configFile);
if (!cfgFile.exists()) {
if (_log.shouldLog(Log.ERROR))
_log.error("Unable to load the controllers from " + configFile);
_log.error("Unable to load the controllers from " + cfgFile.getAbsolutePath());
return null;
}
@@ -282,7 +284,7 @@ public class TunnelControllerGroup {
return props;
} catch (IOException ioe) {
if (_log.shouldLog(Log.ERROR))
_log.error("Error reading the controllers from " + configFile, ioe);
_log.error("Error reading the controllers from " + cfgFile.getAbsolutePath(), ioe);
return null;
}
}

View File

@@ -41,7 +41,7 @@ public class ConfigServiceHandler extends FormHandler {
}
public void run() {
try {
Router.killKeys();
ContextHelper.getContext(null).router().killKeys();
WrapperManager.signalStopped(_exitCode);
} catch (Throwable t) {
t.printStackTrace();

View File

@@ -3,7 +3,6 @@ package net.i2p.router.web;
import java.io.File;
import java.util.Locale;
import net.i2p.router.RouterContext;
import net.i2p.util.FileUtil;
public class ContentHelper extends HelperBase {
@@ -14,6 +13,9 @@ public class ContentHelper extends HelperBase {
public ContentHelper() {}
/**
* Caution, use absolute paths only, do not assume files are in CWD
*/
public void setPage(String page) { _page = page; }
public void setStartAtBeginning(String moo) {
_startAtBeginning = Boolean.valueOf(""+moo).booleanValue();

View File

@@ -1,66 +1,70 @@
package net.i2p.router.web;
import java.io.File;
import java.util.List;
import net.i2p.router.RouterContext;
import net.i2p.util.FileUtil;
public class LogsHelper extends HelperBase {
public LogsHelper() {}
public String getLogs() {
List msgs = _context.logManager().getBuffer().getMostRecentMessages();
StringBuffer buf = new StringBuffer(16*1024);
buf.append("<ul>");
buf.append("<code>\n");
for (int i = msgs.size(); i > 0; i--) {
String msg = (String)msgs.get(i - 1);
msg = msg.replaceAll("<","&lt;");
buf.append("<li>");
buf.append(msg);
buf.append("</li>\n");
}
buf.append("</code></ul>\n");
return buf.toString();
return formatMessages(_context.logManager().getBuffer().getMostRecentMessages());
}
public String getCriticalLogs() {
List msgs = _context.logManager().getBuffer().getMostRecentCriticalMessages();
StringBuffer buf = new StringBuffer(16*1024);
buf.append("<ul>");
buf.append("<code>\n");
for (int i = msgs.size(); i > 0; i--) {
String msg = (String)msgs.get(i - 1);
msg = msg.replaceAll("<","&lt;");
buf.append("<li>");
buf.append(msg);
buf.append("</li>\n");
}
buf.append("</code></ul>\n");
return buf.toString();
return formatMessages(_context.logManager().getBuffer().getMostRecentCriticalMessages());
}
public String getServiceLogs() {
String str = FileUtil.readTextFile("wrapper.log", 250, false);
// look in new and old place
File f = new File(_context.getLogDir(), "wrapper.log");
if (!f.exists())
f = new File(_context.getBaseDir(), "wrapper.log");
String str = FileUtil.readTextFile(f.getAbsolutePath(), 250, false);
if (str == null)
return "";
else {
str = str.replaceAll("<","&lt;");
str = str.replaceAll("<", "&lt;").replaceAll(">", "&gt;");
return "<pre>" + str + "</pre>";
}
}
/***** unused
public String getConnectionLogs() {
List msgs = _context.commSystem().getMostRecentErrorMessages();
return formatMessages(_context.commSystem().getMostRecentErrorMessages());
}
******/
private String formatMessages(List msgs) {
boolean colorize = Boolean.valueOf(_context.getProperty("routerconsole.logs.color")).booleanValue();
StringBuffer buf = new StringBuffer(16*1024);
buf.append("<ul>");
buf.append("<code>\n");
for (int i = msgs.size(); i > 0; i--) {
String msg = (String)msgs.get(i - 1);
buf.append("<li>");
buf.append(msg);
if (colorize) {
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
if (msg.contains("CRIT"))
color = "#cc0000";
else if (msg.contains("ERROR"))
color = "#ff3300";
else if (msg.contains("WARN"))
color = "#ff00cc";
else if (msg.contains("INFO"))
color = "#000099";
else
color = "#006600";
buf.append("<font color=\"").append(color).append("\">");
buf.append(msg.replaceAll("<", "&lt;").replaceAll(">", "&gt;"));
buf.append("</font>");
} else {
buf.append(msg);
}
buf.append("</li>\n");
}
buf.append("</code></ul>\n");

View File

@@ -27,6 +27,8 @@ public class NewsFetcher implements Runnable, EepGet.StatusListener {
private long _lastUpdated;
private String _updateVersion;
private String _lastModified;
private File _newsFile;
private File _tempFile;
private static NewsFetcher _instance;
//public static final synchronized NewsFetcher getInstance() { return _instance; }
public static final synchronized NewsFetcher getInstance(I2PAppContext ctx) {
@@ -35,25 +37,26 @@ public class NewsFetcher implements Runnable, EepGet.StatusListener {
_instance = new NewsFetcher(ctx);
return _instance;
}
private static final String NEWS_FILE = "docs/news.xml";
private static final String TEMP_NEWS_FILE = "docs/news.xml.temp";
private static final String TEMP_NEWS_FILE = "news.xml.temp";
private NewsFetcher(I2PAppContext ctx) {
_context = ctx;
_log = ctx.logManager().getLog(NewsFetcher.class);
_instance = this;
_lastFetch = 0;
_newsFile = new File(_context.getBaseDir(), NEWS_FILE);
_tempFile = new File(_context.getTempDir(), TEMP_NEWS_FILE);
updateLastFetched();
_lastUpdated = _lastFetch;
_updateVersion = "";
}
private void updateLastFetched() {
File news = new File(NEWS_FILE);
if (news.exists()) {
if (_newsFile.exists()) {
if (_lastFetch == 0)
_lastFetch = news.lastModified();
_lastFetch = _newsFile.lastModified();
} else
_lastFetch = 0;
}
@@ -82,7 +85,7 @@ public class NewsFetcher implements Runnable, EepGet.StatusListener {
String policy = _context.getProperty(ConfigUpdateHandler.PROP_UPDATE_POLICY);
if ("notify".equals(policy))
return false;
File zip = new File(Router.UPDATE_FILE);
File zip = new File(_context.getRouterDir(), Router.UPDATE_FILE);
return !zip.exists();
}
@@ -114,18 +117,17 @@ public class NewsFetcher implements Runnable, EepGet.StatusListener {
boolean shouldProxy = Boolean.valueOf(_context.getProperty(ConfigUpdateHandler.PROP_SHOULD_PROXY, ConfigUpdateHandler.DEFAULT_SHOULD_PROXY)).booleanValue();
String proxyHost = _context.getProperty(ConfigUpdateHandler.PROP_PROXY_HOST, ConfigUpdateHandler.DEFAULT_PROXY_HOST);
String port = _context.getProperty(ConfigUpdateHandler.PROP_PROXY_PORT, ConfigUpdateHandler.DEFAULT_PROXY_PORT);
File tempFile = new File(TEMP_NEWS_FILE);
if (tempFile.exists())
tempFile.delete();
if (_tempFile.exists())
_tempFile.delete();
int proxyPort = -1;
try {
proxyPort = Integer.parseInt(port);
EepGet get = null;
if (shouldProxy)
get = new EepGet(_context, true, proxyHost, proxyPort, 2, TEMP_NEWS_FILE, newsURL, true, null, _lastModified);
get = new EepGet(_context, true, proxyHost, proxyPort, 2, _tempFile.getAbsolutePath(), newsURL, true, null, _lastModified);
else
get = new EepGet(_context, false, null, 0, 0, TEMP_NEWS_FILE, newsURL, true, null, _lastModified);
get = new EepGet(_context, false, null, 0, 0, _tempFile.getAbsolutePath(), newsURL, true, null, _lastModified);
get.addStatusListener(this);
if (get.fetch())
_lastModified = get.getLastModified();
@@ -138,11 +140,10 @@ public class NewsFetcher implements Runnable, EepGet.StatusListener {
private static final String VERSION_PREFIX = "version=\"";
private void checkForUpdates() {
_updateAvailable = false;
File news = new File(NEWS_FILE);
if ( (!news.exists()) || (news.length() <= 0) ) return;
if ( (!_newsFile.exists()) || (_newsFile.length() <= 0) ) return;
FileInputStream in = null;
try {
in = new FileInputStream(news);
in = new FileInputStream(_newsFile);
StringBuffer buf = new StringBuffer(128);
while (DataHelper.readLine(in, buf)) {
int index = buf.indexOf(VERSION_PREFIX);
@@ -220,13 +221,12 @@ public class NewsFetcher implements Runnable, EepGet.StatusListener {
if (_log.shouldLog(Log.INFO))
_log.info("News fetched from " + url + " with " + (alreadyTransferred+bytesTransferred));
File temp = new File(TEMP_NEWS_FILE);
long now = _context.clock().now();
if (temp.exists()) {
boolean copied = FileUtil.copy(TEMP_NEWS_FILE, NEWS_FILE, true);
if (_tempFile.exists()) {
boolean copied = FileUtil.copy(_tempFile.getAbsolutePath(), _newsFile.getAbsolutePath(), true);
if (copied) {
_lastUpdated = now;
temp.delete();
_tempFile.delete();
checkForUpdates();
} else {
if (_log.shouldLog(Log.ERROR))
@@ -242,8 +242,7 @@ public class NewsFetcher implements Runnable, EepGet.StatusListener {
public void transferFailed(String url, long bytesTransferred, long bytesRemaining, int currentAttempt) {
if (_log.shouldLog(Log.WARN))
_log.warn("Failed to fetch the news from " + url);
File temp = new File(TEMP_NEWS_FILE);
temp.delete();
_tempFile.delete();
}
public void headerReceived(String url, int attemptNum, String key, String val) {}
public void attempting(String url) {}

View File

@@ -256,7 +256,7 @@ public class ReseedHandler {
private void writeSeed(String name, byte data[]) throws Exception {
String dirName = "netDb"; // _context.getProperty("router.networkDatabase.dbDir", "netDb");
File netDbDir = new File(dirName);
File netDbDir = new File(_context.getRouterDir(), dirName);
if (!netDbDir.exists()) {
boolean ok = netDbDir.mkdirs();
}

View File

@@ -59,7 +59,7 @@ public class RouterConsoleRunner {
}
public void startConsole() {
File workDir = new File("work");
File workDir = new File(I2PAppContext.getGlobalContext().getTempDir(), "jetty-work");
boolean workDirRemoved = FileUtil.rmdir(workDir, false);
if (!workDirRemoved)
System.err.println("ERROR: Unable to remove Jetty temporary work directory");
@@ -95,8 +95,11 @@ public class RouterConsoleRunner {
}
_server.setRootWebApp(ROUTERCONSOLE);
WebApplicationContext wac = _server.addWebApplication("/", _webAppsDir + ROUTERCONSOLE + ".war");
File tmpdir = new File(workDir, ROUTERCONSOLE + "-" + _listenPort);
tmpdir.mkdir();
wac.setTempDirectory(tmpdir);
initialize(wac);
File dir = new File(_webAppsDir);
File dir = new File(I2PAppContext.getGlobalContext().getBaseDir(), _webAppsDir);
String fileNames[] = dir.list(WarFilenameFilter.instance());
if (fileNames != null) {
for (int i = 0; i < fileNames.length; i++) {
@@ -106,6 +109,9 @@ public class RouterConsoleRunner {
if (! "false".equals(enabled)) {
String path = new File(dir, fileNames[i]).getCanonicalPath();
wac = _server.addWebApplication("/"+ appName, path);
tmpdir = new File(workDir, appName + "-" + _listenPort);
tmpdir.mkdir();
wac.setTempDirectory(tmpdir);
initialize(wac);
if (enabled == null) {
// do this so configclients.jsp knows about all apps from reading the config
@@ -144,10 +150,10 @@ public class RouterConsoleRunner {
// don't have an installation directory that they can put the flag in yet.
File noReseedFile = new File(new File(System.getProperty("user.home")), ".i2pnoreseed");
File noReseedFileAlt1 = new File(new File(System.getProperty("user.home")), "noreseed.i2p");
File noReseedFileAlt2 = new File(".i2pnoreseed");
File noReseedFileAlt3 = new File("noreseed.i2p");
File noReseedFileAlt2 = new File(I2PAppContext.getGlobalContext().getConfigDir(), ".i2pnoreseed");
File noReseedFileAlt3 = new File(I2PAppContext.getGlobalContext().getConfigDir(), "noreseed.i2p");
if (!noReseedFile.exists() && !noReseedFileAlt1.exists() && !noReseedFileAlt2.exists() && !noReseedFileAlt3.exists()) {
File netDb = new File("netDb");
File netDb = new File(I2PAppContext.getGlobalContext().getRouterDir(), "netDb");
// 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)
@@ -216,7 +222,7 @@ public class RouterConsoleRunner {
Properties rv = new Properties();
// String webappConfigFile = ctx.getProperty(PROP_WEBAPP_CONFIG_FILENAME, DEFAULT_WEBAPP_CONFIG_FILENAME);
String webappConfigFile = DEFAULT_WEBAPP_CONFIG_FILENAME;
File cfgFile = new File(webappConfigFile);
File cfgFile = new File(I2PAppContext.getGlobalContext().getConfigDir(), webappConfigFile);
try {
DataHelper.loadProps(rv, cfgFile);
@@ -230,7 +236,7 @@ public class RouterConsoleRunner {
public static void storeWebAppProperties(Properties props) {
// String webappConfigFile = ctx.getProperty(PROP_WEBAPP_CONFIG_FILENAME, DEFAULT_WEBAPP_CONFIG_FILENAME);
String webappConfigFile = DEFAULT_WEBAPP_CONFIG_FILENAME;
File cfgFile = new File(webappConfigFile);
File cfgFile = new File(I2PAppContext.getGlobalContext().getConfigDir(), webappConfigFile);
try {
DataHelper.storeProps(props, cfgFile);

View File

@@ -31,6 +31,7 @@ public class UpdateHandler {
protected RouterContext _context;
protected Log _log;
protected DecimalFormat _pct = new DecimalFormat("00.0%");
protected String _updateFile;
protected static final String SIGNED_UPDATE_FILE = "i2pupdate.sud";
protected static final String PROP_UPDATE_IN_PROGRESS = "net.i2p.router.web.UpdateHandler.updateInProgress";
@@ -41,6 +42,7 @@ public class UpdateHandler {
public UpdateHandler(RouterContext ctx) {
_context = ctx;
_log = ctx.logManager().getLog(UpdateHandler.class);
_updateFile = (new File(ctx.getRouterDir(), SIGNED_UPDATE_FILE)).getAbsolutePath();
}
/**
@@ -137,9 +139,9 @@ public class UpdateHandler {
try {
EepGet get = null;
if (shouldProxy)
get = new EepGet(_context, proxyHost, proxyPort, 20, SIGNED_UPDATE_FILE, updateURL, false);
get = new EepGet(_context, proxyHost, proxyPort, 20, _updateFile, updateURL, false);
else
get = new EepGet(_context, 1, SIGNED_UPDATE_FILE, updateURL, false);
get = new EepGet(_context, 1, _updateFile, updateURL, false);
get.addStatusListener(UpdateRunner.this);
get.fetch();
} catch (Throwable t) {
@@ -167,8 +169,9 @@ public class UpdateHandler {
public void transferComplete(long alreadyTransferred, long bytesTransferred, long bytesRemaining, String url, String outputFile, boolean notModified) {
_status = "<b>Update downloaded</b>";
TrustedUpdate up = new TrustedUpdate(_context);
String err = up.migrateVerified(RouterVersion.VERSION, SIGNED_UPDATE_FILE, Router.UPDATE_FILE);
File f = new File(SIGNED_UPDATE_FILE);
File f = new File(_updateFile);
File to = new File(_context.getBaseDir(), Router.UPDATE_FILE);
String err = up.migrateVerified(RouterVersion.VERSION, f, to);
f.delete();
if (err == null) {
String policy = _context.getProperty(ConfigUpdateHandler.PROP_UPDATE_POLICY);

View File

@@ -15,8 +15,11 @@ if (c != null && c.length() > 0) {
java.io.OutputStream cout = response.getOutputStream();
response.setContentType("image/png");
response.setHeader("Cache-Control", "max-age=86400"); // cache for a day
String base = net.i2p.I2PAppContext.getGlobalContext().getBaseDir().getAbsolutePath();
String file = "docs" + java.io.File.separatorChar + "icons" + java.io.File.separatorChar +
"flags" + java.io.File.separatorChar + c + ".png";
try {
net.i2p.util.FileUtil.readFile(c + ".png", "docs/icons/flags", cout);
net.i2p.util.FileUtil.readFile(file, base, cout);
rendered = true;
} catch (java.io.IOException ioe) {}
if (rendered)

View File

@@ -1,4 +1,4 @@
<%
%
/*
* USE CAUTION WHEN EDITING
* Trailing whitespace OR NEWLINE on the last line will cause
@@ -16,5 +16,7 @@ if (uri.endsWith(".css")) {
response.setContentType("image/jpeg");
}
net.i2p.util.FileUtil.readFile(uri, "./docs", response.getOutputStream());
String base = net.i2p.I2PAppContext.getGlobalContext().getBaseDir().getAbsolutePath() +
java.io.File.separatorChar + "docs";
net.i2p.util.FileUtil.readFile(uri, base, response.getOutputStream());
%>

View File

@@ -33,12 +33,16 @@ import java.io.IOException;
import java.io.PrintWriter;
import java.io.Serializable;
import net.i2p.I2PAppContext;
public class ConfigBean implements Serializable {
/*
* as this is not provided as constant in addressbook, we define it here
*/
public static final String addressbookPrefix = "addressbook/";
public static final String addressbookPrefix =
(new File(I2PAppContext.getGlobalContext().getRouterDir(), "addressbook")).getAbsolutePath()
+ File.separatorChar;
public static final String configFileName = addressbookPrefix + "config.txt";
private String action, config;

View File

@@ -15,6 +15,7 @@
<classpath>
<pathelement location="../jetty/jettylib/javax.servlet.jar" />
<pathelement location="../jetty/jettylib/org.mortbay.jetty.jar" />
<pathelement location="../../core/java/build/i2p.jar" />
</classpath>
</javac>
</target>

View File

@@ -25,10 +25,13 @@ package i2p.susi.util;
import i2p.susi.debug.Debug;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;
import net.i2p.I2PAppContext;
/**
* @author susi
*/
@@ -81,7 +84,8 @@ public class Config {
}
FileInputStream fis = null;
try {
fis = new FileInputStream( "susimail.config" );
File cfg = new File(I2PAppContext.getGlobalContext().getConfigDir(), "susimail.config");
fis = new FileInputStream(cfg);
config.load( fis );
} catch (Exception e) {
Debug.debug( Debug.DEBUG, "Could not open susimail.config, reason: " + e.getMessage() );