i2psnark: Check for non-i2p URL

This commit is contained in:
zzz
2020-05-10 20:28:30 +00:00
parent 4f78040569
commit 4da58258f5
3 changed files with 65 additions and 4 deletions

View File

@ -1,6 +1,7 @@
package org.klomp.snark.web;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.Serializable;
@ -1087,10 +1088,63 @@ public class I2PSnarkServlet extends BasicServlet {
// b32
newURL = newURL.toUpperCase(Locale.US);
addMagnet(MagnetURI.MAGNET_FULL + newURL, dir);
} else {
// try as file path, hopefully we're on the same box
if (newURL.startsWith("file://"))
newURL = newURL.substring(7);
File file = new File(newURL);
if (file.isAbsolute() && file.exists()) {
if (!newURL.endsWith(".torrent")) {
_manager.addMessageNoEscape(_t("Torrent at {0} was not valid", DataHelper.escapeHTML(newURL)));
return;
}
FileInputStream in = null;
try {
// This is all copied from FetchAndAdd
// test that it's a valid torrent file, and get the hash to check for dups
in = new FileInputStream(file);
byte[] fileInfoHash = new byte[20];
String name = MetaInfo.getNameAndInfoHash(in, fileInfoHash);
try { in.close(); } catch (IOException ioe) {}
Snark snark = _manager.getTorrentByInfoHash(fileInfoHash);
if (snark != null) {
_manager.addMessage(_t("Torrent with this info hash is already running: {0}", snark.getBaseName()));
return;
}
// check for dup file name
String originalName = Storage.filterName(name);
name = originalName + ".torrent";
File torrentFile = new File(dd, name);
String canonical = torrentFile.getCanonicalPath();
if (torrentFile.exists()) {
if (_manager.getTorrent(canonical) != null)
_manager.addMessage(_t("Torrent already running: {0}", name));
else
_manager.addMessage(_t("Torrent already in the queue: {0}", name));
} else {
// This may take a LONG time to create the storage.
boolean ok = _manager.copyAndAddTorrent(file, canonical, dd);
if (!ok)
throw new IOException("Unknown error - check logs");
snark = _manager.getTorrentByBaseName(originalName);
if (snark != null)
snark.startTorrent();
else
throw new IOException("Unknown error - check logs");
}
} catch (IOException ioe) {
_manager.addMessageNoEscape(_t("Torrent at {0} was not valid", DataHelper.escapeHTML(newURL)) + ": " + DataHelper.stripHTML(ioe.getMessage()));
} catch (OutOfMemoryError oom) {
_manager.addMessageNoEscape(_t("ERROR - Out of memory, cannot create torrent from {0}", DataHelper.escapeHTML(newURL)) + ": " + DataHelper.stripHTML(oom.getMessage()));
} finally {
try { if (in != null) in.close(); } catch (IOException ioe) {}
}
} else {
_manager.addMessage(_t("Invalid URL: Must start with \"http://\", \"{0}\", or \"{1}\"",
MagnetURI.MAGNET, MagnetURI.MAGGOT));
}
}
} else {
// no file or URL specified
}

View File

@ -1,6 +1,13 @@
2020-05-10 zzz
* i2psnark: Support file paths in add form
2020-05-10 idk
* SusiDNS: Fix trac #2419
2020-05-08 zzz
* Build: Use git revisions when available
* Router: FloodfillPeerSelector cleanup (ticket #2694)
2020-05-07 zzz
* Router:
- Fix INMP NPE on non-default config (ticket #2688)

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 = 17;
public final static long BUILD = 18;
/** for example "-test" */
public final static String EXTRA = "";