more conversion to POST

This commit is contained in:
zzz
2010-11-22 01:03:35 +00:00
parent 3e52d6959b
commit ad96c8498d
2 changed files with 59 additions and 57 deletions

View File

@ -242,6 +242,13 @@ public class I2PSnarkServlet extends Default {
List snarks = getSortedSnarks(req); List snarks = getSortedSnarks(req);
String uri = req.getRequestURI(); String uri = req.getRequestURI();
boolean isForm = _manager.util().connected() || !snarks.isEmpty();
if (isForm) {
out.write("<form action=\"");
out.write(uri);
out.write("\" method=\"POST\">\n");
out.write("<input type=\"hidden\" name=\"nonce\" value=\"" + _nonce + "\" >\n");
}
out.write(TABLE_HEADER); out.write(TABLE_HEADER);
out.write("<img border=\"0\" src=\"/themes/snark/ubergine/images/status.png\""); out.write("<img border=\"0\" src=\"/themes/snark/ubergine/images/status.png\"");
out.write(" title=\""); out.write(" title=\"");
@ -301,25 +308,17 @@ public class I2PSnarkServlet extends Default {
out.write("</th>\n"); out.write("</th>\n");
out.write("<th align=\"center\">"); out.write("<th align=\"center\">");
if (_manager.util().connected()) { if (_manager.util().connected()) {
out.write("<a href=\"" + uri + "?action=StopAll&nonce=" + _nonce + out.write("<input type=\"image\" name=\"action\" value=\"StopAll\" title=\"");
"\" title=\"");
out.write(_("Stop all torrents and the I2P tunnel")); out.write(_("Stop all torrents and the I2P tunnel"));
out.write("\">"); out.write("\" src=\"/themes/snark/ubergine/images/stop_all.png\" alt=\"");
out.write("<img src=\"/themes/snark/ubergine/images/stop_all.png\" title=\"");
out.write(_("Stop all torrents and the I2P tunnel"));
out.write("\" alt=\"");
out.write(_("Stop All")); out.write(_("Stop All"));
out.write("\">"); out.write("\">");
out.write("</a>");
} else if (!snarks.isEmpty()) { } else if (!snarks.isEmpty()) {
out.write("<a href=\"" + uri + "?action=StartAll&nonce=" + _nonce + out.write("<input type=\"image\" name=\"action\" value=\"StartAll\" title=\"");
"\" title=\"");
out.write(_("Start all torrents and the I2P tunnel")); out.write(_("Start all torrents and the I2P tunnel"));
out.write("\" src=\"/themes/snark/ubergine/images/start_all.png\" alt=\"");
out.write(_("Start All"));
out.write("\">"); out.write("\">");
out.write("<img src=\"/themes/snark/ubergine/images/start_all.png\" title=\"");
out.write(_("Start all torrents and the I2P tunnel"));
out.write("\" alt=\"Start All\">");
out.write("</a>");
} else { } else {
out.write("&nbsp;"); out.write("&nbsp;");
} }
@ -357,6 +356,8 @@ public class I2PSnarkServlet extends Default {
} }
out.write("</table>"); out.write("</table>");
if (isForm)
out.write("</form>\n");
} }
/** /**
@ -368,11 +369,9 @@ public class I2PSnarkServlet extends Default {
// noop // noop
return; return;
} }
String method = req.getMethod(); if (!"POST".equals(req.getMethod()))
// check in each clause until all disallow GET return;
if ("Add".equals(action)) { if ("Add".equals(action)) {
if (!method.equals("POST"))
return;
String newFile = req.getParameter("newFile"); String newFile = req.getParameter("newFile");
String newURL = req.getParameter("newURL"); String newURL = req.getParameter("newURL");
// NOTE - newFile currently disabled in HTML form - see below // NOTE - newFile currently disabled in HTML form - see below
@ -416,8 +415,8 @@ public class I2PSnarkServlet extends Default {
} else { } else {
// no file or URL specified // no file or URL specified
} }
} else if ("Stop".equals(action)) { } else if (action.startsWith("Stop_")) {
String torrent = req.getParameter("torrent"); String torrent = action.substring(5);
if (torrent != null) { if (torrent != null) {
byte infoHash[] = Base64.decode(torrent); byte infoHash[] = Base64.decode(torrent);
if ( (infoHash != null) && (infoHash.length == 20) ) { // valid sha1 if ( (infoHash != null) && (infoHash.length == 20) ) { // valid sha1
@ -431,8 +430,8 @@ public class I2PSnarkServlet extends Default {
} }
} }
} }
} else if ("Start".equals(action)) { } else if (action.startsWith("Start_")) {
String torrent = req.getParameter("torrent"); String torrent = action.substring(6);
if (torrent != null) { if (torrent != null) {
byte infoHash[] = Base64.decode(torrent); byte infoHash[] = Base64.decode(torrent);
if ( (infoHash != null) && (infoHash.length == 20) ) { // valid sha1 if ( (infoHash != null) && (infoHash.length == 20) ) { // valid sha1
@ -447,8 +446,8 @@ public class I2PSnarkServlet extends Default {
} }
} }
} }
} else if ("Remove".equals(action)) { } else if (action.startsWith("Remove_")) {
String torrent = req.getParameter("torrent"); String torrent = action.substring(7);
if (torrent != null) { if (torrent != null) {
byte infoHash[] = Base64.decode(torrent); byte infoHash[] = Base64.decode(torrent);
if ( (infoHash != null) && (infoHash.length == 20) ) { // valid sha1 if ( (infoHash != null) && (infoHash.length == 20) ) { // valid sha1
@ -467,8 +466,8 @@ public class I2PSnarkServlet extends Default {
} }
} }
} }
} else if ("Delete".equals(action)) { } else if (action.startsWith("Delete_")) {
String torrent = req.getParameter("torrent"); String torrent = action.substring(7);
if (torrent != null) { if (torrent != null) {
byte infoHash[] = Base64.decode(torrent); byte infoHash[] = Base64.decode(torrent);
if ( (infoHash != null) && (infoHash.length == 20) ) { // valid sha1 if ( (infoHash != null) && (infoHash.length == 20) ) { // valid sha1
@ -514,8 +513,6 @@ public class I2PSnarkServlet extends Default {
} }
} }
} else if ("Save".equals(action)) { } else if ("Save".equals(action)) {
if (!method.equals("POST"))
return;
String dataDir = req.getParameter("dataDir"); String dataDir = req.getParameter("dataDir");
boolean autoStart = req.getParameter("autoStart") != null; boolean autoStart = req.getParameter("autoStart") != null;
String seedPct = req.getParameter("seedPct"); String seedPct = req.getParameter("seedPct");
@ -531,8 +528,6 @@ public class I2PSnarkServlet extends Default {
String openTrackers = req.getParameter("openTrackers"); String openTrackers = req.getParameter("openTrackers");
_manager.updateConfig(dataDir, autoStart, startupDel, seedPct, eepHost, eepPort, i2cpHost, i2cpPort, i2cpOpts, upLimit, upBW, useOpenTrackers, openTrackers); _manager.updateConfig(dataDir, autoStart, startupDel, seedPct, eepHost, eepPort, i2cpHost, i2cpPort, i2cpOpts, upLimit, upBW, useOpenTrackers, openTrackers);
} else if ("Create".equals(action)) { } else if ("Create".equals(action)) {
if (!method.equals("POST"))
return;
String baseData = req.getParameter("baseFile"); String baseData = req.getParameter("baseFile");
if (baseData != null && baseData.trim().length() > 0) { if (baseData != null && baseData.trim().length() > 0) {
File baseFile = new File(_manager.getDataDir(), baseData); File baseFile = new File(_manager.getDataDir(), baseData);
@ -838,62 +833,55 @@ public class I2PSnarkServlet extends Default {
out.write("</td>\n\t"); out.write("</td>\n\t");
out.write("<td align=\"center\" class=\"snarkTorrentAction " + rowClass + "\">"); out.write("<td align=\"center\" class=\"snarkTorrentAction " + rowClass + "\">");
String parameters = "&nonce=" + _nonce + "&torrent=" + Base64.encode(snark.meta.getInfoHash()); String parameters = "&nonce=" + _nonce + "&torrent=" + Base64.encode(snark.meta.getInfoHash());
String b64 = Base64.encode(snark.meta.getInfoHash());
if (showPeers) if (showPeers)
parameters = parameters + "&p=1"; parameters = parameters + "&p=1";
if (isRunning) { if (isRunning) {
out.write("<a href=\"" + uri + "?action=Stop" + parameters out.write("<input type=\"image\" name=\"action\" value=\"Stop_");
+ "\" title=\""); out.write(b64);
out.write("\" title=\"");
out.write(_("Stop the torrent")); out.write(_("Stop the torrent"));
out.write("\">"); out.write("\" src=\"/themes/snark/ubergine/images/stop.png\" alt=\"");
out.write("<img src=\"/themes/snark/ubergine/images/stop.png\" title=\"");
out.write(_("Stop the torrent"));
out.write("\" alt=\"");
out.write(_("Stop")); out.write(_("Stop"));
out.write("\">"); out.write("\">");
out.write("</a>");
} else { } else {
if (isValid) { if (isValid) {
out.write("<a href=\"" + uri + "?action=Start" + parameters out.write("<input type=\"image\" name=\"action\" value=\"Start_");
+ "\" title=\""); out.write(b64);
out.write("\" title=\"");
out.write(_("Start the torrent")); out.write(_("Start the torrent"));
out.write("\">"); out.write("\" src=\"/themes/snark/ubergine/images/start.png\" alt=\"");
out.write("<img src=\"/themes/snark/ubergine/images/start.png\" title=\"");
out.write(_("Start the torrent"));
out.write("\" alt=\"");
out.write(_("Start")); out.write(_("Start"));
out.write("\">"); out.write("\">");
out.write("</a>");
} }
out.write("<a href=\"" + uri + "?action=Remove" + parameters
+ "\" title=\""); out.write("<input type=\"image\" name=\"action\" value=\"Remove_");
out.write(b64);
out.write("\" 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("\" onclick=\"if (!confirm('"); out.write("\" onclick=\"if (!confirm('");
// Can't figure out how to escape double quotes inside the onclick string. // Can't figure out how to escape double quotes inside the onclick string.
// Single quotes in translate strings with parameters must be doubled. // Single quotes in translate strings with parameters must be doubled.
// Then the remaining single quite must be escaped // 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(_("Are you sure you want to delete the file \\''{0}.torrent\\'' (downloaded data will not be deleted) ?", fullFilename));
out.write("')) { return false; }\">"); out.write("')) { return false; }\"");
out.write("<img src=\"/themes/snark/ubergine/images/remove.png\" title=\""); out.write(" src=\"/themes/snark/ubergine/images/remove.png\" alt=\"");
out.write(_("Remove the torrent from the active list, deleting the .torrent file"));
out.write("\" alt=\"");
out.write(_("Remove")); out.write(_("Remove"));
out.write("\">"); out.write("\">");
out.write("</a>");
out.write("<a href=\"" + uri + "?action=Delete" + parameters out.write("<input type=\"image\" name=\"action\" value=\"Delete_");
+ "\" title=\""); out.write(b64);
out.write("\" 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("\" onclick=\"if (!confirm('"); out.write("\" onclick=\"if (!confirm('");
// Can't figure out how to escape double quotes inside the onclick string. // Can't figure out how to escape double quotes inside the onclick string.
// Single quotes in translate strings with parameters must be doubled. // Single quotes in translate strings with parameters must be doubled.
// Then the remaining single quite must be escaped // 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(_("Are you sure you want to delete the torrent \\''{0}\\'' and all downloaded data?", fullFilename));
out.write("')) { return false; }\">"); out.write("')) { return false; }\"");
out.write("<img src=\"/themes/snark/ubergine/images/delete.png\" title=\""); out.write(" src=\"/themes/snark/ubergine/images/delete.png\" alt=\"");
out.write(_("Delete the .torrent file and the associated data file(s)"));
out.write("\" alt=\"");
out.write(_("Delete")); out.write(_("Delete"));
out.write("\">"); out.write("\">");
out.write("</a>");
} }
out.write("</td>\n</tr>\n"); out.write("</td>\n</tr>\n");

View File

@ -474,6 +474,20 @@ input[type=submit]:active {
text-shadow: 0 !important; text-shadow: 0 !important;
} }
input[type=image] {
padding: 0 !important;
background: #000;
-moz-border-radius: 0px;
-khtml-border-radius: 0px;
border-radius: 0px;
border: medium none;
margin: 0 2px;
}
input[type=image]:hover {
border: 1px outset #bbb;
}
input[type=text]:active, input[type=text]:hover, input.r:hover { input[type=text]:active, input[type=text]:hover, input.r:hover {
background: #f60; background: #f60;
color: #fff; color: #fff;