forked from I2P_Developers/i2p.i2p
Console: Move /configkeyring HTML to console,
don't truncate hashes, tag for translation, display as b32, trim form data, better form errors, fix removing entries, parameterize form messages (ticket #2108)
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
package net.i2p.router.web.helpers;
|
||||
|
||||
import net.i2p.data.Base32;
|
||||
import net.i2p.data.DataFormatException;
|
||||
import net.i2p.data.Hash;
|
||||
import net.i2p.data.SessionKey;
|
||||
@ -30,18 +31,23 @@ public class ConfigKeyringHandler extends FormHandler {
|
||||
try {
|
||||
sk.fromBase64(_key);
|
||||
} catch (DataFormatException dfe) {}
|
||||
if (h != null && h.getData() != null && sk.getData() != null) {
|
||||
_context.keyRing().put(h, sk);
|
||||
addFormNotice(_t("Key for") + " " + h.toBase64() + " " + _t("added to keyring"));
|
||||
if (h == null || h.getData() == null) {
|
||||
addFormError(_t("Invalid destination"));
|
||||
} else if (sk.getData() == null) {
|
||||
addFormError(_t("Invalid key"));
|
||||
} else {
|
||||
addFormError(_t("Invalid destination or key"));
|
||||
_context.keyRing().put(h, sk);
|
||||
addFormNotice(_t("Key for {0} added to keyring",
|
||||
Base32.encode(h.getData()) + ".b32.i2p"));
|
||||
}
|
||||
} else { // Delete
|
||||
if (h != null && h.getData() != null) {
|
||||
if (_context.keyRing().remove(h) != null)
|
||||
addFormNotice(_t("Key for") + " " + h.toBase64() + " " + _t("removed from keyring"));
|
||||
addFormNotice(_t("Key for {0} removed from keyring",
|
||||
Base32.encode(h.getData()) + ".b32.i2p"));
|
||||
else
|
||||
addFormNotice(_t("Key for") + " " + h.toBase64() + " " + _t("not found in keyring"));
|
||||
addFormNotice(_t("Key for {0} not found in keyring",
|
||||
Base32.encode(h.getData()) + ".b32.i2p"));
|
||||
} else {
|
||||
addFormError(_t("Invalid destination"));
|
||||
}
|
||||
@ -51,6 +57,6 @@ public class ConfigKeyringHandler extends FormHandler {
|
||||
}
|
||||
}
|
||||
|
||||
public void setPeer(String peer) { _peer = peer; }
|
||||
public void setKey(String peer) { _key = peer; }
|
||||
public void setPeer(String peer) { if (peer != null) _peer = peer.trim(); }
|
||||
public void setKey(String key) { if (key != null) _key = key.trim(); }
|
||||
}
|
||||
|
@ -2,7 +2,13 @@ package net.i2p.router.web.helpers;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import java.util.Map;
|
||||
|
||||
import net.i2p.data.Base32;
|
||||
import net.i2p.data.Destination;
|
||||
import net.i2p.data.Hash;
|
||||
import net.i2p.data.SessionKey;
|
||||
import net.i2p.router.TunnelPoolSettings;
|
||||
import net.i2p.router.web.HelperBase;
|
||||
|
||||
|
||||
@ -12,10 +18,44 @@ public class ConfigKeyringHelper extends HelperBase {
|
||||
public String getSummary() {
|
||||
StringWriter sw = new StringWriter(4*1024);
|
||||
try {
|
||||
_context.keyRing().renderStatusHTML(sw);
|
||||
renderStatusHTML(sw);
|
||||
} catch (IOException ioe) {
|
||||
ioe.printStackTrace();
|
||||
}
|
||||
return sw.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 0.9.33 moved from PersistentKeyRing
|
||||
*/
|
||||
private void renderStatusHTML(StringWriter out) throws IOException {
|
||||
StringBuilder buf = new StringBuilder(1024);
|
||||
buf.append("\n<table class=\"configtable\"><tr><th align=\"left\">").append(_t("Destination"))
|
||||
.append("<th align=\"left\">").append(_t("Name"))
|
||||
.append("<th align=\"left\">").append(_t("Encryption Key"))
|
||||
.append("</tr>");
|
||||
for (Map.Entry<Hash, SessionKey> e : _context.keyRing().entrySet()) {
|
||||
buf.append("\n<tr><td>");
|
||||
Hash h = e.getKey();
|
||||
buf.append(Base32.encode(h.getData())).append(".b32.i2p");
|
||||
buf.append("</td><td>");
|
||||
Destination dest = _context.netDb().lookupDestinationLocally(h);
|
||||
if (dest != null && _context.clientManager().isLocal(dest)) {
|
||||
TunnelPoolSettings in = _context.tunnelManager().getInboundSettings(h);
|
||||
if (in != null && in.getDestinationNickname() != null)
|
||||
buf.append(in.getDestinationNickname());
|
||||
} else {
|
||||
String host = _context.namingService().reverseLookup(h);
|
||||
if (host != null)
|
||||
buf.append(host);
|
||||
}
|
||||
buf.append("</td><td>");
|
||||
SessionKey sk = e.getValue();
|
||||
buf.append(sk.toBase64());
|
||||
buf.append("</td>\n");
|
||||
}
|
||||
buf.append("</table>\n");
|
||||
out.write(buf.toString());
|
||||
out.flush();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user