forked from I2P_Developers/i2p.i2p
Console: Add ability to search netdb for a range of ports
Minor cleanup of dup strings
This commit is contained in:
@@ -26,7 +26,7 @@ public class NetDbHelper extends FormHandler {
|
||||
private String _version;
|
||||
private String _country;
|
||||
private String _family, _caps, _ip, _sybil, _mtu, _ssucaps, _ipv6, _transport, _hostname, _sort;
|
||||
private int _full, _port, _cost, _page, _mode;
|
||||
private int _full, _port, _cost, _page, _mode, _highPort;
|
||||
private long _date;
|
||||
private int _limit = DEFAULT_LIMIT;
|
||||
private boolean _lease;
|
||||
@@ -116,8 +116,16 @@ public class NetDbHelper extends FormHandler {
|
||||
|
||||
/** @since 0.9.28 */
|
||||
public void setPort(String f) {
|
||||
if (f == null)
|
||||
return;
|
||||
try {
|
||||
_port = Integer.parseInt(f);
|
||||
int dash = f.indexOf('-');
|
||||
if (dash > 0) {
|
||||
_port = Integer.parseInt(f.substring(0, dash).trim());
|
||||
_highPort = Integer.parseInt(f.substring(dash + 1).trim());
|
||||
} else {
|
||||
_port = Integer.parseInt(f.trim());
|
||||
}
|
||||
} catch (NumberFormatException nfe) {}
|
||||
}
|
||||
|
||||
@@ -300,7 +308,7 @@ public class NetDbHelper extends FormHandler {
|
||||
_ssucaps != null || _transport != null || _cost != 0 || _etype != null) {
|
||||
renderer.renderRouterInfoHTML(_out, _limit, _page,
|
||||
_routerPrefix, _version, _country,
|
||||
_family, _caps, _ip, _sybil, _port, _type, _etype,
|
||||
_family, _caps, _ip, _sybil, _port, _highPort, _type, _etype,
|
||||
_mtu, _ipv6, _ssucaps, _transport, _cost);
|
||||
} else if (_lease) {
|
||||
renderer.renderLeaseSetHTML(_out, _debug);
|
||||
@@ -423,7 +431,7 @@ public class NetDbHelper extends FormHandler {
|
||||
"<tr><td>IP:</td><td><input type=\"text\" name=\"ip\"></td><td>IPv4 or IPv6, /24,/16,/8 suffixes optional for IPv4, prefix ok for IPv6</td></tr>\n" +
|
||||
"<tr><td>IPv6 Prefix:</td><td><input type=\"text\" name=\"ipv6\"></td><td></td></tr>\n" +
|
||||
"<tr><td>" + _t("MTU") + ":</td><td><input type=\"text\" name=\"mtu\"></td><td></td></tr>\n" +
|
||||
"<tr><td>" + _t("Port") + ":</td><td><input type=\"text\" name=\"port\"></td><td></td></tr>\n" +
|
||||
"<tr><td>" + _t("Port") + " or Port Range:</td><td><input type=\"text\" name=\"port\"></td><td>e.g. 1024-1028</td></tr>\n" +
|
||||
"<tr><td>Signature Type:</td><td><select name=\"type\"><option value=\"\" selected=\"selected\"></option>");
|
||||
for (SigType type : EnumSet.allOf(SigType.class)) {
|
||||
_out.write("<option value=\"" + type + "\">" + type + "</option>\n");
|
||||
|
||||
@@ -103,11 +103,12 @@ class NetDbRenderer {
|
||||
* @param version may be null
|
||||
* @param country may be null
|
||||
* @param family may be null
|
||||
* @param highPort if nonzero, a range from port to highPort inclusive
|
||||
*/
|
||||
public void renderRouterInfoHTML(Writer out, int pageSize, int page,
|
||||
String routerPrefix, String version,
|
||||
String country, String family, String caps,
|
||||
String ip, String sybil, int port, SigType type, EncType etype,
|
||||
String ip, String sybil, int port, int highPort, SigType type, EncType etype,
|
||||
String mtu, String ipv6, String ssucaps,
|
||||
String tr, int cost) throws IOException {
|
||||
StringBuilder buf = new StringBuilder(4*1024);
|
||||
@@ -349,7 +350,9 @@ class NetDbRenderer {
|
||||
}
|
||||
} else if (port != 0) {
|
||||
for (RouterAddress ra : ri.getAddresses()) {
|
||||
if (port == ra.getPort()) {
|
||||
int raport = ra.getPort();
|
||||
if (port == raport ||
|
||||
(highPort > 0 && raport >= port && raport <= highPort)) {
|
||||
if (skipped < toSkip) {
|
||||
skipped++;
|
||||
break;
|
||||
@@ -461,8 +464,12 @@ class NetDbRenderer {
|
||||
buf.append("IP ").append(ipArg).append(' ');
|
||||
if (ipv6 != null)
|
||||
buf.append("IP ").append(ipv6).append(' ');
|
||||
if (port != 0)
|
||||
buf.append(_t("Port")).append(' ').append(port).append(' ');
|
||||
if (port != 0) {
|
||||
buf.append(_t("Port")).append(' ').append(port);
|
||||
if (highPort != 0)
|
||||
buf.append('-').append(highPort);
|
||||
buf.append(' ');
|
||||
}
|
||||
if (mtu != null)
|
||||
buf.append(_t("MTU")).append(' ').append(mtu).append(' ');
|
||||
if (cost != 0)
|
||||
@@ -821,7 +828,8 @@ class NetDbRenderer {
|
||||
buf.append("</td></tr>");
|
||||
|
||||
}
|
||||
buf.append("<tr><td colspan=\"2\"><ul class=\"netdb_leases\">");
|
||||
|
||||
buf.append("\n<tr><td colspan=\"2\"><ul class=\"netdb_leases\">");
|
||||
boolean isMeta = ls.getType() == DatabaseEntry.KEY_TYPE_META_LS2;
|
||||
for (int i = 0; i < ls.getLeaseCount(); i++) {
|
||||
Lease lease = ls.getLease(i);
|
||||
@@ -834,15 +842,17 @@ class NetDbRenderer {
|
||||
}
|
||||
if (debug) {
|
||||
long exl = lease.getEndTime() - now;
|
||||
buf.append("<b class=\"netdb_expiry\">");
|
||||
if (exl > 0)
|
||||
buf.append("<b class=\"netdb_expiry\">").append(_t("Expires in {0}", DataHelper.formatDuration2(exl))).append("</b>");
|
||||
buf.append(_t("Expires in {0}", DataHelper.formatDuration2(exl)));
|
||||
else
|
||||
buf.append("<b class=\"netdb_expiry\">").append(_t("Expired {0} ago", DataHelper.formatDuration2(0-exl))).append("</b>");
|
||||
buf.append(_t("Expired {0} ago", DataHelper.formatDuration2(0-exl)));
|
||||
buf.append("</b>");
|
||||
}
|
||||
buf.append("</li>");
|
||||
}
|
||||
buf.append("</ul></td></tr>\n");
|
||||
buf.append("</table>\n");
|
||||
buf.append("</ul></td></tr>\n" +
|
||||
"</table>\n");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user