forked from I2P_Developers/i2p.i2p
* configkeyring.jsp: Add delete and cancel buttons
This commit is contained in:
@ -6,7 +6,7 @@ import net.i2p.data.SessionKey;
|
|||||||
import net.i2p.util.ConvertToHash;
|
import net.i2p.util.ConvertToHash;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Support additions via B64 Destkey, B64 Desthash, or blahblah.i2p
|
* Support additions via B64 Destkey, B64 Desthash, blahblah.i2p, and others supported by ConvertToHash
|
||||||
*/
|
*/
|
||||||
public class ConfigKeyringHandler extends FormHandler {
|
public class ConfigKeyringHandler extends FormHandler {
|
||||||
private String _peer;
|
private String _peer;
|
||||||
@ -14,21 +14,36 @@ public class ConfigKeyringHandler extends FormHandler {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void processForm() {
|
protected void processForm() {
|
||||||
if ("Add key".equals(_action)) {
|
if (_action == null) return;
|
||||||
if (_peer == null || _key == null) {
|
boolean adding = _action.startsWith("Add");
|
||||||
addFormError("You must enter a destination and a key");
|
if (adding || _action.startsWith("Delete")) {
|
||||||
|
if (_peer == null)
|
||||||
|
addFormError("You must enter a destination");
|
||||||
|
if (_key == null && adding)
|
||||||
|
addFormError("You must enter a key");
|
||||||
|
if (_peer == null || (_key == null && adding))
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
Hash h = ConvertToHash.getHash(_peer);
|
Hash h = ConvertToHash.getHash(_peer);
|
||||||
SessionKey sk = new SessionKey();
|
if (adding) {
|
||||||
try {
|
SessionKey sk = new SessionKey();
|
||||||
sk.fromBase64(_key);
|
try {
|
||||||
} catch (DataFormatException dfe) {}
|
sk.fromBase64(_key);
|
||||||
if (h != null && h.getData() != null && sk.getData() != null) {
|
} catch (DataFormatException dfe) {}
|
||||||
_context.keyRing().put(h, sk);
|
if (h != null && h.getData() != null && sk.getData() != null) {
|
||||||
addFormNotice("Key for " + h.toBase64() + " added to keyring");
|
_context.keyRing().put(h, sk);
|
||||||
} else {
|
addFormNotice("Key for " + h.toBase64() + " added to keyring");
|
||||||
addFormError("Invalid destination or key");
|
} else {
|
||||||
|
addFormError("Invalid destination or key");
|
||||||
|
}
|
||||||
|
} else { // Delete
|
||||||
|
if (h != null && h.getData() != null) {
|
||||||
|
if (_context.keyRing().remove(h) != null)
|
||||||
|
addFormNotice("Key for " + h.toBase64() + " removed from keyring");
|
||||||
|
else
|
||||||
|
addFormNotice("Key for " + h.toBase64() + " not found in keyring");
|
||||||
|
} else {
|
||||||
|
addFormError("Invalid destination");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
addFormError("Unsupported");
|
addFormError("Unsupported");
|
||||||
|
@ -40,9 +40,9 @@
|
|||||||
<td class="mediumtags" align="right">Dest. name, hash, or full key:</td>
|
<td class="mediumtags" align="right">Dest. name, hash, or full key:</td>
|
||||||
<td><textarea name="peer" cols="44" rows="1" style="height: 3em;" wrap="off"></textarea></td>
|
<td><textarea name="peer" cols="44" rows="1" style="height: 3em;" wrap="off"></textarea></td>
|
||||||
</tr><tr>
|
</tr><tr>
|
||||||
<td class="mediumtags" align="right">Session Key:</td>
|
<td class="mediumtags" align="right">Encryption Key:</td>
|
||||||
<td><input type="text" size="55" name="key" /></td>
|
<td><input type="text" size="55" name="key" /></td>
|
||||||
</tr><tr>
|
</tr><tr>
|
||||||
<td></td>
|
<td align="right" colspan="2"><input type="submit" name="action" value="Add key" />
|
||||||
<td align="right"><input type="submit" name="action" value="Add key" /></td>
|
<input type="submit" name="action" value="Delete key" /> <input type="reset" value="Cancel" /></td>
|
||||||
</tr></table></div></form></div></div></body></html>
|
</tr></table></div></form></div></div></body></html>
|
||||||
|
@ -67,7 +67,7 @@ public class PersistentKeyRing extends KeyRing {
|
|||||||
@Override
|
@Override
|
||||||
public void renderStatusHTML(Writer out) throws IOException {
|
public void renderStatusHTML(Writer out) throws IOException {
|
||||||
StringBuilder buf = new StringBuilder(1024);
|
StringBuilder buf = new StringBuilder(1024);
|
||||||
buf.append("\n<table><tr><th align=\"left\">Destination Hash<th align=\"left\">Name or Dest.<th align=\"left\">Session Key</tr>");
|
buf.append("\n<table><tr><th align=\"left\">Destination Hash<th align=\"left\">Name or Dest.<th align=\"left\">Encryption Key</tr>");
|
||||||
for (Entry<Hash, SessionKey> e : entrySet()) {
|
for (Entry<Hash, SessionKey> e : entrySet()) {
|
||||||
buf.append("\n<tr><td>");
|
buf.append("\n<tr><td>");
|
||||||
Hash h = e.getKey();
|
Hash h = e.getKey();
|
||||||
|
Reference in New Issue
Block a user