forked from I2P_Developers/i2p.i2p
Add upnp html output, fix up logging
This commit is contained in:
@@ -619,8 +619,8 @@ public class FIFOBandwidthLimiter {
|
||||
public void renderStatusHTML(Writer out) throws IOException {
|
||||
long now = now();
|
||||
StringBuffer buf = new StringBuffer(4096);
|
||||
buf.append("<br /><i id=\"bwlim\">Limiter status: ").append(getStatus().toString()).append("</i><br />\n");
|
||||
buf.append("<b>Pending bandwidth requests:</b><ul>");
|
||||
buf.append("<p><b id=\"bwlim\">Limiter Status:</b><br />").append(getStatus().toString()).append("</p>\n");
|
||||
buf.append("<p><b>Pending bandwidth requests:</b><ul>");
|
||||
buf.append("<li>Inbound requests: <ol>");
|
||||
synchronized (_pendingInboundRequests) {
|
||||
for (int i = 0; i < _pendingInboundRequests.size(); i++) {
|
||||
@@ -643,7 +643,7 @@ public class FIFOBandwidthLimiter {
|
||||
buf.append("ms ago</li>\n");
|
||||
}
|
||||
}
|
||||
buf.append("</ol></li></ul>\n");
|
||||
buf.append("</ol></li></ul></p>\n");
|
||||
out.write(buf.toString());
|
||||
out.flush();
|
||||
}
|
||||
|
@@ -369,7 +369,7 @@ public class TransportManager implements TransportEventListener {
|
||||
t.renderStatusHTML(out, urlBase, sortFlags);
|
||||
}
|
||||
StringBuffer buf = new StringBuffer(4*1024);
|
||||
buf.append("Listening on: <br /><pre>\n");
|
||||
buf.append("<p><b>Router Transport Addresses:</b><br /><pre>\n");
|
||||
for (int i = 0; i < _transports.size(); i++) {
|
||||
Transport t = (Transport)_transports.get(i);
|
||||
if (t.getCurrentAddress() != null)
|
||||
@@ -379,6 +379,8 @@ public class TransportManager implements TransportEventListener {
|
||||
}
|
||||
buf.append("</pre>\n");
|
||||
out.write(buf.toString());
|
||||
out.write(_upnpManager.renderStatusHTML());
|
||||
buf.append("</p>\n");
|
||||
out.flush();
|
||||
}
|
||||
}
|
||||
|
@@ -108,11 +108,17 @@ public class UPnP extends ControlPoint implements DeviceChangeListener {
|
||||
|
||||
DetectedIP result = null;
|
||||
final String natAddress = getNATAddress();
|
||||
if (natAddress == null || natAddress.length() <= 0) {
|
||||
_log.warn("No external address returned");
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
InetAddress detectedIP = InetAddress.getByName(natAddress);
|
||||
|
||||
short status = DetectedIP.NOT_SUPPORTED;
|
||||
thinksWeAreDoubleNatted = !TransportImpl.isPubliclyRoutable(detectedIP.getAddress());
|
||||
// If we have forwarded a port AND we don't have a private address
|
||||
_log.warn("NATAddress: \"" + natAddress + "\" detectedIP: " + detectedIP + " double? " + thinksWeAreDoubleNatted);
|
||||
if((portsForwarded.size() > 1) && (!thinksWeAreDoubleNatted))
|
||||
status = DetectedIP.FULL_INTERNET;
|
||||
|
||||
@@ -291,6 +297,7 @@ public class UPnP extends ControlPoint implements DeviceChangeListener {
|
||||
return Integer.valueOf(getIP.getOutputArgumentList().getArgument("NewDownstreamMaxBitRate").getValue());
|
||||
}
|
||||
|
||||
/***
|
||||
private void listStateTable(Service serv, StringBuilder sb) {
|
||||
ServiceStateTable table = serv.getServiceStateTable();
|
||||
sb.append("<div><small>");
|
||||
@@ -320,6 +327,7 @@ public class UPnP extends ControlPoint implements DeviceChangeListener {
|
||||
sb.append("</div>");
|
||||
}
|
||||
}
|
||||
***/
|
||||
|
||||
private String toString(String action, String Argument, Service serv) {
|
||||
Action getIP = serv.getAction(action);
|
||||
@@ -333,122 +341,103 @@ public class UPnP extends ControlPoint implements DeviceChangeListener {
|
||||
// TODO: extend it! RTFM
|
||||
private void listSubServices(Device dev, StringBuilder sb) {
|
||||
ServiceList sl = dev.getServiceList();
|
||||
if (sl.size() <= 0)
|
||||
return;
|
||||
sb.append("<ul>\n");
|
||||
for(int i=0; i<sl.size(); i++) {
|
||||
Service serv = sl.getService(i);
|
||||
if(serv == null) continue;
|
||||
sb.append("<div>service ("+i+") : "+serv.getServiceType()+"<br>");
|
||||
sb.append("<li>Service: ");
|
||||
if("urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1".equals(serv.getServiceType())){
|
||||
sb.append("WANCommonInterfaceConfig");
|
||||
sb.append(" status: " + toString("GetCommonLinkProperties", "NewPhysicalLinkStatus", serv));
|
||||
sb.append(" type: " + toString("GetCommonLinkProperties", "NewWANAccessType", serv));
|
||||
sb.append(" upstream: " + toString("GetCommonLinkProperties", "NewLayer1UpstreamMaxBitRate", serv));
|
||||
sb.append(" downstream: " + toString("GetCommonLinkProperties", "NewLayer1DownstreamMaxBitRate", serv) + "<br>");
|
||||
sb.append("WAN Common Interface Config<ul>");
|
||||
sb.append("<li>Status: " + toString("GetCommonLinkProperties", "NewPhysicalLinkStatus", serv));
|
||||
sb.append("<li>Type: " + toString("GetCommonLinkProperties", "NewWANAccessType", serv));
|
||||
sb.append("<li>Upstream: " + toString("GetCommonLinkProperties", "NewLayer1UpstreamMaxBitRate", serv));
|
||||
sb.append("<li>Downstream: " + toString("GetCommonLinkProperties", "NewLayer1DownstreamMaxBitRate", serv) + "<br>");
|
||||
}else if("urn:schemas-upnp-org:service:WANPPPConnection:1".equals(serv.getServiceType())){
|
||||
sb.append("WANPPPConnection");
|
||||
sb.append(" status: " + toString("GetStatusInfo", "NewConnectionStatus", serv));
|
||||
sb.append(" type: " + toString("GetConnectionTypeInfo", "NewConnectionType", serv));
|
||||
sb.append(" upstream: " + toString("GetLinkLayerMaxBitRates", "NewUpstreamMaxBitRate", serv));
|
||||
sb.append(" downstream: " + toString("GetLinkLayerMaxBitRates", "NewDownstreamMaxBitRate", serv) + "<br>");
|
||||
sb.append(" external IP: " + toString("GetExternalIPAddress", "NewExternalIPAddress", serv) + "<br>");
|
||||
sb.append("WAN PPP Connection<ul>");
|
||||
sb.append("<li>Status: " + toString("GetStatusInfo", "NewConnectionStatus", serv));
|
||||
sb.append("<li>Type: " + toString("GetConnectionTypeInfo", "NewConnectionType", serv));
|
||||
sb.append("<li>Upstream: " + toString("GetLinkLayerMaxBitRates", "NewUpstreamMaxBitRate", serv));
|
||||
sb.append("<li>Downstream: " + toString("GetLinkLayerMaxBitRates", "NewDownstreamMaxBitRate", serv) + "<br>");
|
||||
sb.append("<li>External IP: " + toString("GetExternalIPAddress", "NewExternalIPAddress", serv) + "<br>");
|
||||
}else if("urn:schemas-upnp-org:service:Layer3Forwarding:1".equals(serv.getServiceType())){
|
||||
sb.append("Layer3Forwarding");
|
||||
sb.append("DefaultConnectionService: " + toString("GetDefaultConnectionService", "NewDefaultConnectionService", serv));
|
||||
sb.append("Layer 3 Forwarding<ul>");
|
||||
sb.append("<li>Default Connection Service: " + toString("GetDefaultConnectionService", "NewDefaultConnectionService", serv));
|
||||
}else if(WAN_IP_CONNECTION.equals(serv.getServiceType())){
|
||||
sb.append("WANIPConnection");
|
||||
sb.append(" status: " + toString("GetStatusInfo", "NewConnectionStatus", serv));
|
||||
sb.append(" type: " + toString("GetConnectionTypeInfo", "NewConnectionType", serv));
|
||||
sb.append(" external IP: " + toString("GetExternalIPAddress", "NewExternalIPAddress", serv) + "<br>");
|
||||
sb.append("WAN IP Connection<ul>");
|
||||
sb.append("<li>Status: " + toString("GetStatusInfo", "NewConnectionStatus", serv));
|
||||
sb.append("<li>Type: " + toString("GetConnectionTypeInfo", "NewConnectionType", serv));
|
||||
sb.append("<li>External IP: " + toString("GetExternalIPAddress", "NewExternalIPAddress", serv) + "<br>");
|
||||
}else if("urn:schemas-upnp-org:service:WANEthernetLinkConfig:1".equals(serv.getServiceType())){
|
||||
sb.append("WANEthernetLinkConfig");
|
||||
sb.append(" status: " + toString("GetEthernetLinkStatus", "NewEthernetLinkStatus", serv) + "<br>");
|
||||
sb.append("WAN Ethernet Link Config<ol>");
|
||||
sb.append("<li>Status: " + toString("GetEthernetLinkStatus", "NewEthernetLinkStatus", serv) + "<br>");
|
||||
}else
|
||||
sb.append("~~~~~~~ "+serv.getServiceType());
|
||||
listActions(serv, sb);
|
||||
listStateTable(serv, sb);
|
||||
sb.append("</div>");
|
||||
sb.append("~~~~~~~ "+serv.getServiceType() + "<ul>");
|
||||
//listActions(serv, sb);
|
||||
//listStateTable(serv, sb);
|
||||
sb.append("</ul>\n");
|
||||
}
|
||||
sb.append("</ul>\n");
|
||||
}
|
||||
|
||||
private void listSubDev(String prefix, Device dev, StringBuilder sb){
|
||||
sb.append("<div><p>Device : "+dev.getFriendlyName()+" - "+ dev.getDeviceType()+"<br>");
|
||||
if (prefix == null)
|
||||
sb.append("Device: ");
|
||||
else
|
||||
sb.append("<li>Subdevice: ");
|
||||
sb.append(dev.getFriendlyName());
|
||||
listSubServices(dev, sb);
|
||||
|
||||
DeviceList dl = dev.getDeviceList();
|
||||
if (dl.size() <= 0)
|
||||
return;
|
||||
sb.append("<ul>\n");
|
||||
for(int j=0; j<dl.size(); j++) {
|
||||
Device subDev = dl.getDevice(j);
|
||||
if(subDev == null) continue;
|
||||
|
||||
sb.append("<div>");
|
||||
listSubDev(dev.getFriendlyName(), subDev, sb);
|
||||
sb.append("</div></div>");
|
||||
}
|
||||
sb.append("</p></div>");
|
||||
sb.append("</ul>\n");
|
||||
}
|
||||
|
||||
/*****
|
||||
public String handleHTTPGet(HTTPRequest request) throws PluginHTTPException {
|
||||
if(request.isParameterSet("getDeviceCapabilities")) {
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
sb.append("<html><head><title>UPnP report</title></head><body>");
|
||||
listSubDev("WANDevice", _router, sb);
|
||||
sb.append("</body></html>");
|
||||
public String renderStatusHTML() {
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
sb.append("<b>UPnP Status:</b><br />");
|
||||
|
||||
if(isDisabled) {
|
||||
sb.append("The plugin has been disabled; Do you have more than one UPnP Internet Gateway Device on your LAN ?");
|
||||
return sb.toString();
|
||||
} else if(!isNATPresent()) {
|
||||
sb.append("The plugin hasn't found any UPnP aware, compatible device on your LAN.");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
HTMLNode pageNode = pr.getPageMaker().getPageNode("UP&P plugin configuration page", false, null);
|
||||
HTMLNode contentNode = pr.getPageMaker().getContentNode(pageNode);
|
||||
|
||||
if(isDisabled) {
|
||||
HTMLNode disabledInfobox = contentNode.addChild("div", "class", "infobox infobox-error");
|
||||
HTMLNode disabledInfoboxHeader = disabledInfobox.addChild("div", "class", "infobox-header");
|
||||
HTMLNode disabledInfoboxContent = disabledInfobox.addChild("div", "class", "infobox-content");
|
||||
|
||||
disabledInfoboxHeader.addChild("#", "UP&P plugin report");
|
||||
disabledInfoboxContent.addChild("#", "The plugin has been disabled; Do you have more than one UP&P IGD on your LAN ?");
|
||||
return pageNode.generate();
|
||||
} else if(!isNATPresent()) {
|
||||
HTMLNode notFoundInfobox = contentNode.addChild("div", "class", "infobox infobox-warning");
|
||||
HTMLNode notFoundInfoboxHeader = notFoundInfobox.addChild("div", "class", "infobox-header");
|
||||
HTMLNode notFoundInfoboxContent = notFoundInfobox.addChild("div", "class", "infobox-content");
|
||||
|
||||
notFoundInfoboxHeader.addChild("#", "UP&P plugin report");
|
||||
notFoundInfoboxContent.addChild("#", "The plugin hasn't found any UP&P aware, compatible device on your LAN.");
|
||||
return pageNode.generate();
|
||||
}
|
||||
|
||||
HTMLNode foundInfobox = contentNode.addChild("div", "class", "infobox infobox-normal");
|
||||
HTMLNode foundInfoboxHeader = foundInfobox.addChild("div", "class", "infobox-header");
|
||||
HTMLNode foundInfoboxContent = foundInfobox.addChild("div", "class", "infobox-content");
|
||||
|
||||
// FIXME L10n!
|
||||
foundInfoboxHeader.addChild("#", "UP&P plugin report");
|
||||
foundInfoboxContent.addChild("p", "The following device has been found : ").addChild("a", "href", "?getDeviceCapabilities").addChild("#", _router.getFriendlyName());
|
||||
foundInfoboxContent.addChild("p", "Our current external ip address is : " + getNATAddress());
|
||||
sb.append("<p>Found ");
|
||||
listSubDev(null, _router, sb);
|
||||
sb.append("<br>The current external IP address reported by UPnP is " + getNATAddress());
|
||||
int downstreamMaxBitRate = getDownstreamMaxBitRate();
|
||||
int upstreamMaxBitRate = getUpstramMaxBitRate();
|
||||
if(downstreamMaxBitRate > 0)
|
||||
foundInfoboxContent.addChild("p", "Our reported max downstream bit rate is : " + getDownstreamMaxBitRate()+ " bits/sec");
|
||||
sb.append("<br>UPnP reports the max downstream bit rate is : " + getDownstreamMaxBitRate()+ " bits/sec\n");
|
||||
if(upstreamMaxBitRate > 0)
|
||||
foundInfoboxContent.addChild("p", "Our reported max upstream bit rate is : " + getUpstramMaxBitRate()+ " bits/sec");
|
||||
sb.append("<br>UPnP reports the max upstream bit rate is : " + getUpstramMaxBitRate()+ " bits/sec\n");
|
||||
synchronized(lock) {
|
||||
if(portsToForward != null) {
|
||||
for(ForwardPort port : portsToForward) {
|
||||
if(portsForwarded.contains(port)) {
|
||||
foundInfoboxContent.addChild("p", "The "+port.name+" port "+port.portNumber+" / "+port.protocol+" has been forwarded successfully.");
|
||||
} else {
|
||||
foundInfoboxContent.addChild("p", "The "+port.name+" port "+port.portNumber+" / "+port.protocol+" has not been forwarded.");
|
||||
}
|
||||
sb.append("<br>" + protoToString(port.protocol) + " port " + port.portNumber + " for " + port.name);
|
||||
if(portsForwarded.contains(port))
|
||||
sb.append(" has been forwarded successfully by UPnP.\n");
|
||||
else
|
||||
sb.append(" has not been forwarded UPnP.\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return pageNode.generate();
|
||||
sb.append("</p>");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public String handleHTTPPost(HTTPRequest request) throws PluginHTTPException {
|
||||
return null;
|
||||
}
|
||||
***/
|
||||
|
||||
private boolean addMapping(String protocol, int port, String description, ForwardPort fp) {
|
||||
if(isDisabled || !isNATPresent() || _router == null) {
|
||||
@@ -457,8 +446,8 @@ public class UPnP extends ControlPoint implements DeviceChangeListener {
|
||||
}
|
||||
|
||||
// Just in case...
|
||||
// this confuses my linksys - zzz
|
||||
// removeMapping(protocol, port, fp, true);
|
||||
// this confuses my linksys? - zzz
|
||||
removeMapping(protocol, port, fp, true);
|
||||
|
||||
Action add = _service.getAction("AddPortMapping");
|
||||
if(add == null) {
|
||||
@@ -557,14 +546,18 @@ public class UPnP extends ControlPoint implements DeviceChangeListener {
|
||||
registerPorts(portsToForwardNow);
|
||||
}
|
||||
|
||||
private static String protoToString(int p) {
|
||||
if(p == ForwardPort.PROTOCOL_UDP_IPV4)
|
||||
return "UDP";
|
||||
if(p == ForwardPort.PROTOCOL_TCP_IPV4)
|
||||
return "TCP";
|
||||
return "?";
|
||||
}
|
||||
|
||||
private void registerPorts(Set<ForwardPort> portsToForwardNow) {
|
||||
for(ForwardPort port : portsToForwardNow) {
|
||||
String proto;
|
||||
if(port.protocol == ForwardPort.PROTOCOL_UDP_IPV4)
|
||||
proto = "UDP";
|
||||
else if(port.protocol == ForwardPort.PROTOCOL_TCP_IPV4)
|
||||
proto = "TCP";
|
||||
else {
|
||||
String proto = protoToString(port.protocol);
|
||||
if (proto.length() <= 1) {
|
||||
HashMap<ForwardPort, ForwardPortStatus> map = new HashMap<ForwardPort, ForwardPortStatus>();
|
||||
map.put(port, new ForwardPortStatus(ForwardPortStatus.DEFINITE_FAILURE, "Protocol not supported", port.portNumber));
|
||||
forwardCallback.portForwardStatus(map);
|
||||
@@ -586,15 +579,10 @@ public class UPnP extends ControlPoint implements DeviceChangeListener {
|
||||
|
||||
private void unregisterPorts(Set<ForwardPort> portsToForwardNow) {
|
||||
for(ForwardPort port : portsToForwardNow) {
|
||||
String proto;
|
||||
if(port.protocol == ForwardPort.PROTOCOL_UDP_IPV4)
|
||||
proto = "UDP";
|
||||
else if(port.protocol == ForwardPort.PROTOCOL_TCP_IPV4)
|
||||
proto = "TCP";
|
||||
else {
|
||||
String proto = protoToString(port.protocol);
|
||||
if (proto.length() <= 1)
|
||||
// Ignore, we've already complained about it
|
||||
continue;
|
||||
}
|
||||
removeMapping(proto, port.portNumber, port, false);
|
||||
}
|
||||
}
|
||||
|
@@ -45,15 +45,18 @@ public class UPnPManager {
|
||||
}
|
||||
|
||||
public synchronized void start() {
|
||||
_log.error("UPnP Start");
|
||||
Debug.on(); // UPnP stuff -> wrapper log
|
||||
if (_log.shouldLog(Log.DEBUG)) {
|
||||
_log.debug("UPnP Start");
|
||||
Debug.on(); // UPnP stuff -> wrapper log
|
||||
}
|
||||
if (!_isRunning)
|
||||
_upnp.runPlugin();
|
||||
_isRunning = true;
|
||||
}
|
||||
|
||||
public synchronized void stop() {
|
||||
_log.error("UPnP Stop");
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("UPnP Stop");
|
||||
if (_isRunning)
|
||||
_upnp.terminate();
|
||||
_isRunning = false;
|
||||
@@ -61,7 +64,8 @@ public class UPnPManager {
|
||||
|
||||
/** call when the ports might have changed */
|
||||
public void update(Map<String, RouterAddress> addresses) {
|
||||
_log.error("UPnP Update:");
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("UPnP Update:");
|
||||
if (!_isRunning)
|
||||
return;
|
||||
Set<ForwardPort> forwards = new HashSet(addresses.size());
|
||||
@@ -86,7 +90,8 @@ public class UPnPManager {
|
||||
protocol = ForwardPort.PROTOCOL_TCP_IPV4;
|
||||
else
|
||||
continue;
|
||||
_log.error("Adding: " + style + " " + port);
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("Adding: " + style + " " + port);
|
||||
ForwardPort fp = new ForwardPort(style, false, protocol, port);
|
||||
forwards.add(fp);
|
||||
}
|
||||
@@ -98,18 +103,32 @@ public class UPnPManager {
|
||||
|
||||
/** Called to indicate status on one or more forwarded ports. */
|
||||
public void portForwardStatus(Map<ForwardPort,ForwardPortStatus> statuses) {
|
||||
_log.error("UPnP Callback:");
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("UPnP Callback:");
|
||||
|
||||
DetectedIP[] ips = _upnp.getAddress();
|
||||
for (DetectedIP ip : ips) {
|
||||
_log.error("External address: " + ip.publicAddress + " type: " + ip.natType);
|
||||
}
|
||||
DetectedIP[] ips = _upnp.getAddress();
|
||||
if (ips != null) {
|
||||
for (DetectedIP ip : ips) {
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("External address: " + ip.publicAddress + " type: " + ip.natType);
|
||||
}
|
||||
} else {
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("No external address returned");
|
||||
}
|
||||
|
||||
for (ForwardPort fp : statuses.keySet()) {
|
||||
ForwardPortStatus fps = statuses.get(fp);
|
||||
_log.error(fp.name + " " + fp.protocol + " " + fp.portNumber +
|
||||
" status: " + fps.status + " reason: " + fps.reasonString + " ext port: " + fps.externalPort);
|
||||
}
|
||||
}
|
||||
for (ForwardPort fp : statuses.keySet()) {
|
||||
ForwardPortStatus fps = statuses.get(fp);
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug(fp.name + " " + fp.protocol + " " + fp.portNumber +
|
||||
" status: " + fps.status + " reason: " + fps.reasonString + " ext port: " + fps.externalPort);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String renderStatusHTML() {
|
||||
if (!_isRunning)
|
||||
return "<b>UPnP is not enabled</b>\n";
|
||||
return _upnp.renderStatusHTML();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user