* configclients.jsp:

- Add js delete confirm
      - Remove delete button for webapps
    * i2psnark:
      - Ignore a non-i2p tracker in a torrent rather than deleting
        the torrent, thus "converting" a torrent to in-netowrk use
        via the open trackers
      - Add js delete confirm
This commit is contained in:
zzz
2010-02-22 18:17:11 +00:00
parent eae18e61b7
commit f6b9cf6f21
6 changed files with 90 additions and 21 deletions

View File

@ -198,6 +198,7 @@ public class SnarkManager implements Snark.CompleteListener {
String ot = _config.getProperty(I2PSnarkUtil.PROP_OPENTRACKERS); String ot = _config.getProperty(I2PSnarkUtil.PROP_OPENTRACKERS);
if (ot != null) if (ot != null)
_util.setOpenTrackerString(ot); _util.setOpenTrackerString(ot);
// FIXME set util use open trackers property somehow
getDataDir().mkdirs(); getDataDir().mkdirs();
} }
@ -428,6 +429,14 @@ public class SnarkManager implements Snark.CompleteListener {
fis.close(); fis.close();
fis = null; fis = null;
if (!TrackerClient.isValidAnnounce(info.getAnnounce())) {
if (_util.shouldUseOpenTrackers() && _util.getOpenTrackers() != null) {
addMessage(_("Warning - Ignoring non-i2p tracker in \"{0}\", will announce to i2p open trackers only", info.getName()));
} else {
addMessage(_("Warning - Ignoring non-i2p tracker in \"{0}\", and open trackers are disabled, you must enable open trackers before starting the torrent!", info.getName()));
dontAutoStart = true;
}
}
String rejectMessage = locked_validateTorrent(info); String rejectMessage = locked_validateTorrent(info);
if (rejectMessage != null) { if (rejectMessage != null) {
sfile.delete(); sfile.delete();
@ -551,12 +560,10 @@ public class SnarkManager implements Snark.CompleteListener {
saveConfig(); saveConfig();
} }
/**
* Warning - does not validate announce URL - use TrackerClient.isValidAnnounce()
*/
private String locked_validateTorrent(MetaInfo info) throws IOException { private String locked_validateTorrent(MetaInfo info) throws IOException {
String announce = info.getAnnounce();
// basic validation of url
if ((!announce.startsWith("http://")) ||
(announce.indexOf(".i2p/") < 0)) // need to do better than this
return _("Non-i2p tracker in \"{0}\", deleting it from our list of trackers!", info.getName());
List files = info.getFiles(); List files = info.getFiles();
if ( (files != null) && (files.size() > MAX_FILES_PER_TORRENT) ) { if ( (files != null) && (files.size() > MAX_FILES_PER_TORRENT) ) {
return _("Too many files in \"{0}\" ({1}), deleting it!", info.getName(), files.size()); return _("Too many files in \"{0}\" ({1}), deleting it!", info.getName(), files.size());

View File

@ -24,6 +24,8 @@ import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Iterator; import java.util.Iterator;
@ -123,13 +125,19 @@ public class TrackerClient extends I2PAppThread
// followed by the secondary open trackers // followed by the secondary open trackers
// It's painful, but try to make sure if an open tracker is also // It's painful, but try to make sure if an open tracker is also
// the primary tracker, that we don't add it twice. // the primary tracker, that we don't add it twice.
// todo: check for b32 matches as well
trackers = new ArrayList(2); trackers = new ArrayList(2);
trackers.add(new Tracker(meta.getAnnounce(), true)); String primary = meta.getAnnounce();
if (isValidAnnounce(primary)) {
trackers.add(new Tracker(meta.getAnnounce(), true));
} else {
_log.warn("Skipping invalid or non-i2p announce: " + primary);
}
List tlist = _util.getOpenTrackers(); List tlist = _util.getOpenTrackers();
if (tlist != null) { if (tlist != null) {
for (int i = 0; i < tlist.size(); i++) { for (int i = 0; i < tlist.size(); i++) {
String url = (String)tlist.get(i); String url = (String)tlist.get(i);
if (!url.startsWith("http://")) { if (!isValidAnnounce(url)) {
_log.error("Bad announce URL: [" + url + "]"); _log.error("Bad announce URL: [" + url + "]");
continue; continue;
} }
@ -138,22 +146,29 @@ public class TrackerClient extends I2PAppThread
_log.error("Bad announce URL: [" + url + "]"); _log.error("Bad announce URL: [" + url + "]");
continue; continue;
} }
if (meta.getAnnounce().startsWith(url.substring(0, slash))) if (primary.startsWith(url.substring(0, slash)))
continue; continue;
String dest = _util.lookup(url.substring(7, slash)); String dest = _util.lookup(url.substring(7, slash));
if (dest == null) { if (dest == null) {
_log.error("Announce host unknown: [" + url + "]"); _log.error("Announce host unknown: [" + url + "]");
continue; continue;
} }
if (meta.getAnnounce().startsWith("http://" + dest)) if (primary.startsWith("http://" + dest))
continue; continue;
if (meta.getAnnounce().startsWith("http://i2p/" + dest)) if (primary.startsWith("http://i2p/" + dest))
continue; continue;
trackers.add(new Tracker(url, false)); trackers.add(new Tracker(url, false));
_log.debug("Additional announce: [" + url + "] for infoHash: " + infoHash); _log.debug("Additional announce: [" + url + "] for infoHash: " + infoHash);
} }
} }
if (tlist.size() <= 0) {
// FIXME really need to get this message to the gui
stop = true;
_log.error("No valid trackers for infoHash: " + infoHash);
return;
}
long uploaded = coordinator.getUploaded(); long uploaded = coordinator.getUploaded();
long downloaded = coordinator.getDownloaded(); long downloaded = coordinator.getDownloaded();
long left = coordinator.getLeft(); long left = coordinator.getLeft();
@ -399,6 +414,22 @@ public class TrackerClient extends I2PAppThread
return sb.toString(); return sb.toString();
} }
/**
* @return true for i2p hosts only
* @since 0.7.12
*/
static boolean isValidAnnounce(String ann) {
URL url;
try {
url = new URL(ann);
} catch (MalformedURLException mue) {
return false;
}
return url.getProtocol().equals("http") &&
(url.getHost().endsWith(".i2p") || url.getHost().equals("i2p")) &&
url.getPort() < 0;
}
private class Tracker private class Tracker
{ {
String announce; String announce;

View File

@ -455,8 +455,11 @@ public class I2PSnarkServlet extends HttpServlet {
int i = filename.lastIndexOf(".torrent"); int i = filename.lastIndexOf(".torrent");
if (i > 0) if (i > 0)
filename = filename.substring(0, i); filename = filename.substring(0, i);
if (filename.length() > MAX_DISPLAYED_FILENAME_LENGTH) String fullFilename = filename;
if (filename.length() > MAX_DISPLAYED_FILENAME_LENGTH) {
fullFilename = new String(filename);
filename = filename.substring(0, MAX_DISPLAYED_FILENAME_LENGTH) + "&hellip;"; filename = filename.substring(0, MAX_DISPLAYED_FILENAME_LENGTH) + "&hellip;";
}
long total = snark.meta.getTotalLength(); long total = snark.meta.getTotalLength();
// Early typecast, avoid possibly overflowing a temp integer // Early typecast, avoid possibly overflowing a temp integer
long remaining = (long) snark.storage.needed() * (long) snark.meta.getPieceLength(0); long remaining = (long) snark.storage.needed() * (long) snark.meta.getPieceLength(0);
@ -627,13 +630,23 @@ public class I2PSnarkServlet extends HttpServlet {
out.write("<a href=\"" + uri + "?action=Remove" + parameters out.write("<a href=\"" + uri + "?action=Remove" + parameters
+ "\" title=\""); + "\" title=\"");
out.write(_("Remove the torrent from the active list, deleting the .torrent file")); out.write(_("Remove the torrent from the active list, deleting the .torrent file"));
out.write("\">"); out.write("\" onclick=\"if (!confirm('");
// Can't figure out how to escape double quotes inside the onclick string.
// Single quotes in translate strings with parameters must be doubled.
// Then the remaining single quite must be escaped
out.write(_("Are you sure you want to delete the file \\''{0}.torrent\\'' (downloaded data will not be deleted) ?", fullFilename));
out.write("')) { return false; }\">");
out.write(_("Remove")); out.write(_("Remove"));
out.write("</a><br>"); out.write("</a><br>");
out.write("<a href=\"" + uri + "?action=Delete" + parameters out.write("<a href=\"" + uri + "?action=Delete" + parameters
+ "\" title=\""); + "\" title=\"");
out.write(_("Delete the .torrent file and the associated data file(s)")); out.write(_("Delete the .torrent file and the associated data file(s)"));
out.write("\">"); out.write("\" onclick=\"if (!confirm('");
// Can't figure out how to escape double quotes inside the onclick string.
// Single quotes in translate strings with parameters must be doubled.
// Then the remaining single quite must be escaped
out.write(_("Are you sure you want to delete the torrent \\''{0}\\'' and all downloaded data?", fullFilename));
out.write("')) { return false; }\">");
out.write(_("Delete")); out.write(_("Delete"));
out.write("</a>"); out.write("</a>");
} }

View File

@ -42,11 +42,12 @@ public class ConfigClientsHelper extends HelperBase {
ClientAppConfig ca = clients.get(cur); ClientAppConfig ca = clients.get(cur);
renderForm(buf, ""+cur, ca.clientName, false, !ca.disabled, renderForm(buf, ""+cur, ca.clientName, false, !ca.disabled,
"webConsole".equals(ca.clientName) || "Web console".equals(ca.clientName), "webConsole".equals(ca.clientName) || "Web console".equals(ca.clientName),
ca.className + ((ca.args != null) ? " " + ca.args : ""), (""+cur).equals(_edit), true, false, false); ca.className + ((ca.args != null) ? " " + ca.args : ""), (""+cur).equals(_edit),
true, false, false, true);
} }
if ("new".equals(_edit)) if ("new".equals(_edit))
renderForm(buf, "" + clients.size(), "", false, false, false, "", true, false, false, false); renderForm(buf, "" + clients.size(), "", false, false, false, "", true, false, false, false, false);
buf.append("</table>\n"); buf.append("</table>\n");
return buf.toString(); return buf.toString();
} }
@ -63,7 +64,8 @@ public class ConfigClientsHelper extends HelperBase {
String app = name.substring(RouterConsoleRunner.PREFIX.length(), name.lastIndexOf(RouterConsoleRunner.ENABLED)); String app = name.substring(RouterConsoleRunner.PREFIX.length(), name.lastIndexOf(RouterConsoleRunner.ENABLED));
String val = props.getProperty(name); String val = props.getProperty(name);
renderForm(buf, app, app, !"addressbook".equals(app), renderForm(buf, app, app, !"addressbook".equals(app),
"true".equals(val), RouterConsoleRunner.ROUTERCONSOLE.equals(app), app + ".war", false, false, false, false); "true".equals(val), RouterConsoleRunner.ROUTERCONSOLE.equals(app), app + ".war",
false, false, false, false, false);
} }
} }
buf.append("</table>\n"); buf.append("</table>\n");
@ -146,7 +148,7 @@ public class ConfigClientsHelper extends HelperBase {
desc.append("</table>"); desc.append("</table>");
renderForm(buf, app, app, false, renderForm(buf, app, app, false,
"true".equals(val), false, desc.toString(), false, false, "true".equals(val), false, desc.toString(), false, false,
updateURL != null, true); updateURL != null, true, true);
} }
} }
buf.append("</table>\n"); buf.append("</table>\n");
@ -156,7 +158,8 @@ public class ConfigClientsHelper extends HelperBase {
/** ro trumps edit and showEditButton */ /** ro trumps edit and showEditButton */
private void renderForm(StringBuilder buf, String index, String name, boolean urlify, private void renderForm(StringBuilder buf, String index, String name, boolean urlify,
boolean enabled, boolean ro, String desc, boolean edit, boolean enabled, boolean ro, String desc, boolean edit,
boolean showEditButton, boolean showUpdateButton, boolean showStopButton) { boolean showEditButton, boolean showUpdateButton, boolean showStopButton,
boolean showDeleteButton) {
buf.append("<tr><td class=\"mediumtags\" align=\"right\" width=\"25%\">"); buf.append("<tr><td class=\"mediumtags\" align=\"right\" width=\"25%\">");
if (urlify && enabled) { if (urlify && enabled) {
String link = "/"; String link = "/";
@ -190,8 +193,13 @@ public class ConfigClientsHelper extends HelperBase {
buf.append("<button type=\"submit\" name=\"action\" value=\"Check ").append(index).append("\" >" + _("Check for updates") + "<span class=hide> ").append(index).append("</span></button>"); buf.append("<button type=\"submit\" name=\"action\" value=\"Check ").append(index).append("\" >" + _("Check for updates") + "<span class=hide> ").append(index).append("</span></button>");
buf.append("<button type=\"submit\" name=\"action\" value=\"Update ").append(index).append("\" >" + _("Update") + "<span class=hide> ").append(index).append("</span></button>"); buf.append("<button type=\"submit\" name=\"action\" value=\"Update ").append(index).append("\" >" + _("Update") + "<span class=hide> ").append(index).append("</span></button>");
} }
if ((!edit) && !ro) if (showDeleteButton && (!edit) && !ro) {
buf.append("<button type=\"submit\" name=\"action\" value=\"Delete ").append(index).append("\" >" + _("Delete") + "<span class=hide> ").append(index).append("</span></button>"); buf.append("<button type=\"submit\" name=\"action\" value=\"Delete ").append(index)
.append("\" onclick=\"if (!confirm('")
.append(_("Are you sure you want to delete {0}?", _(name)))
.append("')) { return false; }\">")
.append(_("Delete")).append("<span class=hide> ").append(index).append("</span></button>");
}
buf.append("</td><td align=\"left\" width=\"50%\">"); buf.append("</td><td align=\"left\" width=\"50%\">");
if (edit && !ro) { if (edit && !ro) {
buf.append("<input type=\"text\" size=\"80\" name=\"desc").append(index).append("\" value=\""); buf.append("<input type=\"text\" size=\"80\" name=\"desc").append(index).append("\" value=\"");

View File

@ -1,3 +1,13 @@
2010-02-22 zzz
* configclients.jsp:
- Add js delete confirm
- Remove delete button for webapps
* i2psnark:
- Ignore a non-i2p tracker in a torrent rather than deleting
the torrent, thus "converting" a torrent to in-netowrk use
via the open trackers
- Add js delete confirm
2010-02-19 zzz 2010-02-19 zzz
* i2psnark: Make file box bigger * i2psnark: Make file box bigger
* Plugins: * Plugins:

View File

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