propagate from branch 'i2p.i2p.zzz.test' (head f4edeaaf6cd647f4a69847a09272b54cb51ef758)

to branch 'i2p.i2p' (head 0d7e18b693718b5924035d7a6f638ff0689af589)
This commit is contained in:
zzz
2009-01-25 01:15:45 +00:00
54 changed files with 1638 additions and 518 deletions

View File

@ -0,0 +1,55 @@
package net.i2p.router.web;
import net.i2p.I2PAppContext;
import net.i2p.data.DataFormatException;
import net.i2p.data.Destination;
import net.i2p.data.Hash;
import net.i2p.data.SessionKey;
/**
* Support additions via B64 Destkey, B64 Desthash, or blahblah.i2p
*/
public class ConfigKeyringHandler extends FormHandler {
private String _peer;
private String _key;
protected void processForm() {
if ("Add key".equals(_action)) {
if (_peer == null || _key == null) {
addFormError("You must enter a destination and a key");
return;
}
Hash h = new Hash();
try {
h.fromBase64(_peer);
} catch (DataFormatException dfe) {}
if (h.getData() == null) {
try {
Destination d = new Destination();
d.fromBase64(_peer);
h = d.calculateHash();
} catch (DataFormatException dfe) {}
}
if (h.getData() == null) {
Destination d = _context.namingService().lookup(_peer);
if (d != null)
h = d.calculateHash();
}
SessionKey sk = new SessionKey();
try {
sk.fromBase64(_key);
} catch (DataFormatException dfe) {}
if (h.getData() != null && sk.getData() != null) {
_context.keyRing().put(h, sk);
addFormNotice("Key for " + h.toBase64() + " added to keyring");
} else {
addFormError("Invalid destination or key");
}
} else {
addFormError("Unsupported");
}
}
public void setPeer(String peer) { _peer = peer; }
public void setKey(String peer) { _key = peer; }
}

View File

@ -0,0 +1,36 @@
package net.i2p.router.web;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import net.i2p.router.RouterContext;
public class ConfigKeyringHelper {
private RouterContext _context;
/**
* Configure this bean to query a particular router context
*
* @param contextId begging few characters of the routerHash, or null to pick
* the first one we come across.
*/
public void setContextId(String contextId) {
try {
_context = ContextHelper.getContext(contextId);
} catch (Throwable t) {
t.printStackTrace();
}
}
public ConfigKeyringHelper() {}
public String getSummary() {
ByteArrayOutputStream baos = new ByteArrayOutputStream(4*1024);
try {
_context.keyRing().renderStatusHTML(new OutputStreamWriter(baos));
} catch (IOException ioe) {
ioe.printStackTrace();
}
return new String(baos.toByteArray());
}
}

View File

@ -11,6 +11,7 @@ public class NetDbHelper {
private RouterContext _context;
private Writer _out;
private String _routerPrefix;
private boolean _full = false;
/**
* Configure this bean to query a particular router context
@ -30,6 +31,7 @@ public class NetDbHelper {
public void setWriter(Writer writer) { _out = writer; }
public void setRouter(String r) { _routerPrefix = r; }
public void setFull(String f) { _full = "1".equals(f); };
public String getNetDbSummary() {
try {
@ -37,14 +39,14 @@ public class NetDbHelper {
if (_routerPrefix != null)
_context.netDb().renderRouterInfoHTML(_out, _routerPrefix);
else
_context.netDb().renderStatusHTML(_out);
_context.netDb().renderStatusHTML(_out, _full);
return "";
} else {
ByteArrayOutputStream baos = new ByteArrayOutputStream(32*1024);
if (_routerPrefix != null)
_context.netDb().renderRouterInfoHTML(new OutputStreamWriter(baos), _routerPrefix);
else
_context.netDb().renderStatusHTML(new OutputStreamWriter(baos));
_context.netDb().renderStatusHTML(new OutputStreamWriter(baos), _full);
return new String(baos.toByteArray());
}
} catch (IOException ioe) {

View File

@ -244,7 +244,7 @@ public class SummaryHelper {
*/
public String getInboundSecondKBps() {
if (_context == null)
return "0.0";
return "0";
double kbps = _context.bandwidthLimiter().getReceiveBps()/1024d;
DecimalFormat fmt = new DecimalFormat("##0.00");
return fmt.format(kbps);
@ -256,7 +256,7 @@ public class SummaryHelper {
*/
public String getOutboundSecondKBps() {
if (_context == null)
return "0.0";
return "0";
double kbps = _context.bandwidthLimiter().getSendBps()/1024d;
DecimalFormat fmt = new DecimalFormat("##0.00");
return fmt.format(kbps);
@ -269,10 +269,10 @@ public class SummaryHelper {
*/
public String getInboundFiveMinuteKBps() {
if (_context == null)
return "0.0";
return "0";
RateStat receiveRate = _context.statManager().getRate("bw.recvRate");
if (receiveRate == null) return "0.0";
if (receiveRate == null) return "0";
Rate rate = receiveRate.getRate(5*60*1000);
double kbps = rate.getAverageValue()/1024;
DecimalFormat fmt = new DecimalFormat("##0.00");
@ -286,10 +286,10 @@ public class SummaryHelper {
*/
public String getOutboundFiveMinuteKBps() {
if (_context == null)
return "0.0";
return "0";
RateStat receiveRate = _context.statManager().getRate("bw.sendRate");
if (receiveRate == null) return "0.0";
if (receiveRate == null) return "0";
Rate rate = receiveRate.getRate(5*60*1000);
double kbps = rate.getAverageValue()/1024;
DecimalFormat fmt = new DecimalFormat("##0.00");
@ -303,10 +303,10 @@ public class SummaryHelper {
*/
public String getInboundLifetimeKBps() {
if (_context == null)
return "0.0";
return "0";
RateStat receiveRate = _context.statManager().getRate("bw.recvRate");
if (receiveRate == null) return "0.0";
if (receiveRate == null) return "0";
double kbps = receiveRate.getLifetimeAverageValue()/1024;
DecimalFormat fmt = new DecimalFormat("##0.00");
return fmt.format(kbps);
@ -319,10 +319,10 @@ public class SummaryHelper {
*/
public String getOutboundLifetimeKBps() {
if (_context == null)
return "0.0";
return "0";
RateStat sendRate = _context.statManager().getRate("bw.sendRate");
if (sendRate == null) return "0.0";
if (sendRate == null) return "0";
double kbps = sendRate.getLifetimeAverageValue()/1024;
DecimalFormat fmt = new DecimalFormat("##0.00");
return fmt.format(kbps);
@ -335,11 +335,11 @@ public class SummaryHelper {
*/
public String getInboundTransferred() {
if (_context == null)
return "0.0";
return "0";
long received = _context.bandwidthLimiter().getTotalAllocatedInboundBytes();
return getTransferred(received);
return DataHelper.formatSize(received) + 'B';
}
/**
@ -349,40 +349,10 @@ public class SummaryHelper {
*/
public String getOutboundTransferred() {
if (_context == null)
return "0.0";
return "0";
long sent = _context.bandwidthLimiter().getTotalAllocatedOutboundBytes();
return getTransferred(sent);
}
private static String getTransferred(long bytes) {
double val = bytes;
int scale = 0;
if (bytes > 1024*1024*1024) {
// gigs transferred
scale = 3;
val /= (double)(1024*1024*1024);
} else if (bytes > 1024*1024) {
// megs transferred
scale = 2;
val /= (double)(1024*1024);
} else if (bytes > 1024) {
// kbytes transferred
scale = 1;
val /= (double)1024;
} else {
scale = 0;
}
DecimalFormat fmt = new DecimalFormat("##0.00");
String str = fmt.format(val);
switch (scale) {
case 1: return str + "KB";
case 2: return str + "MB";
case 3: return str + "GB";
default: return bytes + "bytes";
}
return DataHelper.formatSize(sent) + 'B';
}
/**

View File

@ -0,0 +1,58 @@
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head>
<title>I2P Router Console - config keyring</title>
<link rel="stylesheet" href="default.css" type="text/css" />
</head><body>
<%@include file="nav.jsp" %>
<%@include file="summary.jsp" %>
<div class="main" id="main">
<%@include file="confignav.jsp" %>
<jsp:useBean class="net.i2p.router.web.ConfigKeyringHandler" id="formhandler" scope="request" />
<jsp:setProperty name="formhandler" property="*" />
<jsp:setProperty name="formhandler" property="contextId" value="<%=(String)session.getAttribute("i2p.contextId")%>" />
<font color="red"><jsp:getProperty name="formhandler" property="errors" /></font>
<i><jsp:getProperty name="formhandler" property="notices" /></i>
<jsp:useBean class="net.i2p.router.web.ConfigKeyringHelper" id="keyringhelper" scope="request" />
<jsp:setProperty name="keyringhelper" property="contextId" value="<%=(String)session.getAttribute("i2p.contextId")%>" />
<p>
<h2>Keyring</h2>
The router keyring is used to decrypt encrypted leaseSets.
The keyring may contain keys for local or remote encrypted destinations.
<p><jsp:getProperty name="keyringhelper" property="summary" />
</p>
<hr />
<form action="configkeyring.jsp" method="POST">
<% String prev = System.getProperty("net.i2p.router.web.ConfigKeyringHandler.nonce");
if (prev != null) System.setProperty("net.i2p.router.web.ConfigKeyringHandler.noncePrev", prev);
System.setProperty("net.i2p.router.web.ConfigKeyringHandler.nonce", new java.util.Random().nextLong()+""); %>
<input type="hidden" name="nonce" value="<%=System.getProperty("net.i2p.router.web.ConfigKeyringHandler.nonce")%>" />
<h2>Manual Keyring Addition</h2>
Enter keys for encrypted remote destinations here.
Keys for local destinations must be entered on the <a href="i2ptunnel/index.jsp">I2PTunnel page</a>.
<p>
<table>
<tr><td>Dest. name, hash, or full key:
<td><textarea name="peer" cols="44" rows="1" wrap="off"></textarea>
<tr><td align="right">Session Key:
<td><input type="text" size="55" name="key" />
<tr><td><td><input type="submit" name="action" value="Add key" />
</table>
</form>
</div>
</body>
</html>

View File

@ -10,6 +10,8 @@
%>Clients | <% } else { %><a href="configclients.jsp">Clients</a> | <% }
if (request.getRequestURI().indexOf("configpeer.jsp") != -1) {
%>Peers | <% } else { %><a href="configpeer.jsp">Peers</a> | <% }
if (request.getRequestURI().indexOf("configkeyring.jsp") != -1) {
%>Keyring | <% } else { %><a href="configkeyring.jsp">Keyring</a> | <% }
if (request.getRequestURI().indexOf("configlogging.jsp") != -1) {
%>Logging | <% } else { %><a href="configlogging.jsp">Logging</a> | <% }
if (request.getRequestURI().indexOf("configstats.jsp") != -1) {

View File

@ -34,9 +34,8 @@ licenses and dependencies. This webpage is being served as part of the I2P rout
client application, which is built off a trimmed down <a href="http://jetty.mortbay.com/jetty/index.html">Jetty</a>
instance (trimmed down, as in, we do not include the demo apps or other add-ons, and we simplify configuration),
allowing you to deploy standard JSP/Servlet web applications into your router. Jetty in turn makes use of
Apache's javax.servlet (javax.servlet.jar) implementation, as well as their xerces-j XML parser (xerces.jar).
Their XML parser requires the Sun XML APIs (JAXP) which is included in binary form (xml-apis.jar) as required
by their binary code license. This product includes software developed by the Apache Software Foundation
Apache's javax.servlet (javax.servlet.jar) implementation.
This product includes software developed by the Apache Software Foundation
(http://www.apache.org/). </p>
<p>Another application you can see on this webpage is <a href="http://www.i2p2.i2p/i2ptunnel">I2PTunnel</a>

View File

@ -14,6 +14,7 @@
<jsp:useBean class="net.i2p.router.web.NetDbHelper" id="netdbHelper" scope="request" />
<jsp:setProperty name="netdbHelper" property="contextId" value="<%=(String)session.getAttribute("i2p.contextId")%>" />
<jsp:setProperty name="netdbHelper" property="writer" value="<%=out%>" />
<jsp:setProperty name="netdbHelper" property="full" value="<%=request.getParameter("f")%>" />
<jsp:setProperty name="netdbHelper" property="router" value="<%=request.getParameter("r")%>" />
<jsp:getProperty name="netdbHelper" property="netDbSummary" />
</div>