i2psnark: Don't fail to start if data directory not found (ticket #2166)

Try to create dir if doesn't exist
Hide add and create sections if dir not writable
Remove 403 handler, don't want it for standalone hostname check
This commit is contained in:
zzz
2018-03-15 15:50:33 +00:00
parent 1de82a6801
commit cfd84bdcdd
6 changed files with 53 additions and 29 deletions

View File

@ -1058,13 +1058,27 @@ public class SnarkManager implements CompleteListener, ClientApp {
} catch (NumberFormatException nfe) {}
}
// set this before we check the data dir
if (areFilesPublic() != filesPublic) {
_config.setProperty(PROP_FILES_PUBLIC, Boolean.toString(filesPublic));
_util.setFilesPublic(filesPublic);
if (filesPublic)
addMessage(_t("New files will be publicly readable"));
else
addMessage(_t("New files will not be publicly readable"));
changed = true;
}
if (dataDir != null && !dataDir.equals(getDataDir().getAbsolutePath())) {
dataDir = DataHelper.stripHTML(dataDir.trim());
File dd = new File(dataDir);
File dd = areFilesPublic() ? new File(dataDir) : new SecureDirectory(dataDir);
if (!dd.isAbsolute()) {
addMessage(_t("Data directory must be an absolute path") + ": " + dataDir);
} else if (!dd.exists()) {
addMessage(_t("Data directory does not exist") + ": " + dataDir);
} else if (!dd.exists() && !dd.mkdirs()) {
// save this tag for now, may need it again
if (false)
addMessage(_t("Data directory does not exist") + ": " + dataDir);
addMessage(_t("Data directory cannot be created") + ": " + dataDir);
} else if (!dd.isDirectory()) {
addMessage(_t("Not a directory") + ": " + dataDir);
} else if (!dd.canRead()) {
@ -1196,16 +1210,6 @@ public class SnarkManager implements CompleteListener, ClientApp {
changed = true;
} // reconnect || changed options
if (areFilesPublic() != filesPublic) {
_config.setProperty(PROP_FILES_PUBLIC, Boolean.toString(filesPublic));
_util.setFilesPublic(filesPublic);
if (filesPublic)
addMessage(_t("New files will be publicly readable"));
else
addMessage(_t("New files will not be publicly readable"));
changed = true;
}
if (shouldAutoStart() != autoStart) {
_config.setProperty(PROP_AUTO_START, Boolean.toString(autoStart));
if (autoStart)

View File

@ -39,6 +39,7 @@ import net.i2p.data.DataHelper;
import net.i2p.servlet.util.WriterOutputStream;
import net.i2p.util.ByteCache;
import net.i2p.util.Log;
import net.i2p.util.SecureFile;
import net.i2p.util.SystemVersion;
@ -113,7 +114,7 @@ class BasicServlet extends HttpServlet
String rb=getInitParameter("resourceBase");
if (rb!=null)
{
File f = new File(rb);
File f = new SecureFile(rb);
setResourceBase(f);
}
String wb = getInitParameter("warBase");
@ -124,10 +125,10 @@ class BasicServlet extends HttpServlet
/**
* Files are served from here
*/
protected void setResourceBase(File base) throws UnavailableException {
protected synchronized void setResourceBase(File base) throws UnavailableException {
if (!base.isDirectory()) {
_log.log(Log.CRIT, "Configured i2psnark directory " + base + " does not exist");
throw new UnavailableException("Resource base does not exist: " + base);
_log.error("Configured i2psnark directory " + base + " does not exist");
//throw new UnavailableException("Resource base does not exist: " + base);
}
_resourceBase = base;
if (_log.shouldLog(Log.INFO))

View File

@ -377,8 +377,14 @@ public class I2PSnarkServlet extends BasicServlet {
// end of mainsection div
if (pageOne) {
out.write("</div><div id=\"lowersection\">\n");
writeAddForm(out, req);
writeSeedForm(out, req, sortedTrackers);
boolean canWrite;
synchronized(this) {
canWrite = _resourceBase.canWrite();
}
if (canWrite) {
writeAddForm(out, req);
writeSeedForm(out, req, sortedTrackers);
}
writeConfigLink(out);
// end of lowersection div
}
@ -692,9 +698,22 @@ public class I2PSnarkServlet extends BasicServlet {
if (total == 0) {
out.write("<tr class=\"snarkTorrentNoneLoaded\">" +
"<td colspan=\"11\"><i>");
out.write(_t("No torrents loaded."));
out.write("</i></td></tr>\n");
"<td colspan=\"11\">");
synchronized(this) {
File dd = _resourceBase;
if (!dd.exists() && !dd.mkdirs()) {
out.write(_t("Data directory cannot be created") + ": " + DataHelper.escapeHTML(dd.toString()));
} else if (!dd.isDirectory()) {
out.write(_t("Not a directory") + ": " + DataHelper.escapeHTML(dd.toString()));
} else if (!dd.canRead()) {
out.write(_t("Unreadable") + ": " + DataHelper.escapeHTML(dd.toString()));
} else if (!dd.canWrite()) {
out.write(_t("No write permissions for data directory") + ": " + DataHelper.escapeHTML(dd.toString()));
} else {
out.write(_t("No torrents loaded."));
}
}
out.write("</td></tr>\n");
} else /** if (snarks.size() > 1) */ {
out.write("<tfoot><tr>\n" +
" <th id=\"snarkTorrentTotals\" align=\"left\" colspan=\"6\">");

View File

@ -50,10 +50,6 @@
</cookie-config>
</session-config>
<error-page>
<error-code>403</error-code>
<location>/.error</location>
</error-page>
<error-page>
<error-code>404</error-code>
<location>/.error</location>

View File

@ -1,13 +1,17 @@
2018-03-15 zzz
* i2psnark: Start even if data directory not found (ticket #2166)
2018-03-14 zzz
* Console:
- Hide links to webapps and eepsite if not running (ticket #2161)
- Hide link to /configplugins if disabled
- Add error handler to webapps (ticket #2155)
* i2ptunnel: Hide links to webapps that are not runnning (ticket #2161)
* SusDNS: Translate svg image text (ticket #1749)
* SusiDNS: Translate svg image text (ticket #1749)
* SusiMail: Shorten URLs
2018-03-12 zzz
* Susimail: Fix up compose.js (ticket #2176)
* SusiMail: Fix up compose.js (ticket #2176)
2018-03-11 zzz
* Crypto: Add utils for renewing a cert in a keystore

View File

@ -18,7 +18,7 @@ public class RouterVersion {
/** deprecated */
public final static String ID = "Monotone";
public final static String VERSION = CoreVersion.VERSION;
public final static long BUILD = 18;
public final static long BUILD = 19;
/** for example "-test" */
public final static String EXTRA = "";