Commit f938414c authored by Thiago Camargo's avatar Thiago Camargo Committed by thiago

[OF-379] Updated Public IP Verification

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@11999 b35dd754-fafc-0310-a699-88a17e54d16e
parent d46b4e03
...@@ -63,5 +63,11 @@ ...@@ -63,5 +63,11 @@
<li>Public IP Verification</li> <li>Public IP Verification</li>
</ul> </ul>
<p><b>0.0.3</b> -- November 12, 2010</p>
<ul>
<li>Override Public IP COnfiguration</li>
</ul>
</body> </body>
</html> </html>
...@@ -5,4 +5,7 @@ admin.item.jn.settings.name=Jingle Nodes Status ...@@ -5,4 +5,7 @@ admin.item.jn.settings.name=Jingle Nodes Status
jn.verified.ip=Verified Public IP jn.verified.ip=Verified Public IP
jn.active.channels=Active Channels jn.active.channels=Active Channels
jn.settings.title=Jingle Nodes Status jn.settings.title=Jingle Nodes Status
jn.verified.ip.warning=Jingle Nodes Requires a Public IP for Internet Calling. Check your Network Settings. jn.verified.ip.warning=Jingle Nodes Requires a Public IP for Internet Calling. Public IP Found:
\ No newline at end of file jn.settings.update.settings =Update Settings
jn.settings.overrideip= Override Public IP
jn.settings.invalid.publicip =Invalid Public IP Address
\ No newline at end of file
...@@ -88,13 +88,6 @@ class JingleNodesComponent extends AbstractComponent { ...@@ -88,13 +88,6 @@ class JingleNodesComponent extends AbstractComponent {
childElement.addAttribute(LOCAL_PORT, Integer.toString(channel.getPortA())); childElement.addAttribute(LOCAL_PORT, Integer.toString(channel.getPortA()));
childElement.addAttribute(REMOTE_PORT, Integer.toString(channel.getPortB())); childElement.addAttribute(REMOTE_PORT, Integer.toString(channel.getPortB()));
// final RelayPublicMask rpm = new RelayPublicMask(channel);
// rpm.discover("stun.xten.com", 3478);
// childElement.addAttribute(HOST, rpm.getAddressA().getAddress().getHostAddress());
// childElement.addAttribute(LOCAL_PORT, Integer.toString(rpm.getAddressA().getPort()));
// childElement.addAttribute(REMOTE_PORT, Integer.toString(rpm.getAddressB().getPort()));
reply.setChildElement(childElement); reply.setChildElement(childElement);
Log.debug("Created relay channel {}:{}, {}:{}, {}:{}", new Object[]{HOST, Log.debug("Created relay channel {}:{}, {}:{}, {}:{}", new Object[]{HOST,
......
...@@ -29,6 +29,7 @@ import java.net.InetSocketAddress; ...@@ -29,6 +29,7 @@ import java.net.InetSocketAddress;
import org.jivesoftware.openfire.container.Plugin; import org.jivesoftware.openfire.container.Plugin;
import org.jivesoftware.openfire.container.PluginManager; import org.jivesoftware.openfire.container.PluginManager;
import org.jivesoftware.util.JiveGlobals;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.xmpp.component.ComponentException; import org.xmpp.component.ComponentException;
...@@ -41,17 +42,25 @@ import org.xmpp.jnodes.nio.PublicIPResolver; ...@@ -41,17 +42,25 @@ import org.xmpp.jnodes.nio.PublicIPResolver;
public class JingleNodesPlugin implements Plugin { public class JingleNodesPlugin implements Plugin {
private static final Logger Log = LoggerFactory.getLogger(JingleNodesPlugin.class); private static final Logger Log = LoggerFactory.getLogger(JingleNodesPlugin.class);
public static final String JN_PUB_IP_PROPERTY = "jinglenodes.publicip";
private ComponentManager componentManager; private ComponentManager componentManager;
private final ConcurrentHashMap<String, RelayChannel> channels = new ConcurrentHashMap<String, RelayChannel>(); private final ConcurrentHashMap<String, RelayChannel> channels = new ConcurrentHashMap<String, RelayChannel>();
private final long timeout = 60000; private final long timeout = 60000;
private final AtomicInteger ids = new AtomicInteger(0); private final AtomicInteger ids = new AtomicInteger(0);
private final ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(1); private final ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(1);
private final String serviceName = "relay"; private final String serviceName = "relay";
private final boolean bindAllInterfaces;
private boolean hasPublicIP = false; private boolean hasPublicIP = false;
public JingleNodesPlugin() {
final String os = System.getProperty("os.name");
bindAllInterfaces = !(os != null && os.toLowerCase().indexOf("win") > -1);
}
public void initializePlugin(PluginManager manager, File pluginDirectory) { public void initializePlugin(PluginManager manager, File pluginDirectory) {
componentManager = ComponentManagerFactory.getComponentManager(); componentManager = ComponentManagerFactory.getComponentManager();
JingleNodesComponent component = new JingleNodesComponent(this); JingleNodesComponent component = new JingleNodesComponent(this);
...@@ -82,13 +91,11 @@ public class JingleNodesPlugin implements Plugin { ...@@ -82,13 +91,11 @@ public class JingleNodesPlugin implements Plugin {
verifyNetwork(); verifyNetwork();
} }
private void verifyNetwork() { public void verifyNetwork() {
final String localAddress = JiveGlobals.getProperty(JN_PUB_IP_PROPERTY, LocalIPResolver.getLocalIP());
final String localAddress = LocalIPResolver.getLocalIP(); LocalIPResolver.setOverrideIp(localAddress);
final InetSocketAddress publicAddress = PublicIPResolver.getPublicAddress("stun.xten.com", 3478); final InetSocketAddress publicAddress = PublicIPResolver.getPublicAddress("stun.xten.com", 3478);
hasPublicIP = publicAddress != null && publicAddress.getAddress().getHostAddress().equals(localAddress); hasPublicIP = publicAddress != null && publicAddress.getAddress().getHostAddress().equals(localAddress);
} }
private void closeAllChannels() { private void closeAllChannels() {
...@@ -100,7 +107,8 @@ public class JingleNodesPlugin implements Plugin { ...@@ -100,7 +107,8 @@ public class JingleNodesPlugin implements Plugin {
public RelayChannel createRelayChannel() { public RelayChannel createRelayChannel() {
RelayChannel rc = null; RelayChannel rc = null;
try { try {
rc = RelayChannel.createLocalRelayChannel(LocalIPResolver.getLocalIP(), 30000, 50000);
rc = RelayChannel.createLocalRelayChannel(bindAllInterfaces ? "0.0.0.0" : LocalIPResolver.getLocalIP(), 30000, 50000);
final int id = ids.incrementAndGet(); final int id = ids.incrementAndGet();
final String sId = String.valueOf(id); final String sId = String.valueOf(id);
rc.setAttachment(sId); rc.setAttachment(sId);
......
<%@ page import="org.jinglenodes.JingleNodesPlugin" %> <%@ page import="org.jinglenodes.JingleNodesPlugin" %>
<%@ page import="org.jivesoftware.openfire.XMPPServer" %> <%@ page import="org.jivesoftware.openfire.XMPPServer" %>
<%@ page import="java.util.Collection" %> <%@ page import="org.jivesoftware.util.LocaleUtils" %>
<%@ page import="org.jivesoftware.openfire.container.Plugin" %> <%@ page import="org.xmpp.jnodes.nio.LocalIPResolver" %>
<%@ page import="java.net.InetAddress" %>
<%@ page import="org.jivesoftware.util.JiveGlobals" %>
<%@ page import="org.xmpp.jnodes.nio.PublicIPResolver" %>
<%@ page import="java.net.InetSocketAddress" %>
<%-- <%--
- $Revision: $ - $Revision: $
- $Date: $ - $Date: $
...@@ -27,9 +31,34 @@ ...@@ -27,9 +31,34 @@
<%@ taglib uri="http://java.sun.com/jstl/fmt_rt" prefix="fmt" %> <%@ taglib uri="http://java.sun.com/jstl/fmt_rt" prefix="fmt" %>
<% <%
boolean update = request.getParameter("update") != null;
String errorMessage = null;
// Get handle on the Monitoring plugin // Get handle on the Monitoring plugin
JingleNodesPlugin plugin = (JingleNodesPlugin) XMPPServer.getInstance().getPluginManager().getPlugin("jinglenodes"); JingleNodesPlugin plugin = (JingleNodesPlugin) XMPPServer.getInstance().getPluginManager().getPlugin("jinglenodes");
if (update) {
String overrideIP = request.getParameter("overrideip");
if (overrideIP != null) {
overrideIP = overrideIP.trim();
try {
InetAddress.getByName(overrideIP);
LocalIPResolver.setOverrideIp(overrideIP);
JiveGlobals.setProperty(JingleNodesPlugin.JN_PUB_IP_PROPERTY, overrideIP);
plugin.verifyNetwork();
} catch (Exception e) {
errorMessage = LocaleUtils.getLocalizedString("jn.settings.invalid.publicip", "jinglenodes");
}
}
}
String publicIP = "none";
if (!plugin.hasPublicIP()) {
final InetSocketAddress addr = PublicIPResolver.getPublicAddress("stun.xten.com", 3478);
if (addr != null) {
publicIP = addr.getAddress().getHostAddress();
}
}
%> %>
<html> <html>
<head> <head>
...@@ -37,32 +66,53 @@ ...@@ -37,32 +66,53 @@
<meta name="pageID" content="jingle-nodes"/> <meta name="pageID" content="jingle-nodes"/>
</head> </head>
<body> <body>
<% if (errorMessage != null) { %>
<div class="error">
<%= errorMessage%>
</div>
<br/>
<% } %>
<div class="jive-table"> <div class="jive-table">
<table class="jive-table" cellpadding="0" cellspacing="0" border="0" width="100%"> <form action="jingle-nodes.jsp" method="post">
<thead> <table class="jive-table" cellpadding="0" cellspacing="0" border="0" width="100%">
<tr> <thead>
<th colspan="2"><fmt:message key="jn.settings.title"/></th> <tr>
</tr> <th colspan="2"><fmt:message key="jn.settings.title"/></th>
</thead> </tr>
<tbody> </thead>
<tr> <tbody>
<td><label class="jive-label"><fmt:message key="jn.verified.ip"/>:</label><br></td> <tr>
<td align="left"><% if (plugin.hasPublicIP()) { %> <td><label class="jive-label"><fmt:message key="jn.verified.ip"/>:</label><br></td>
<img src="/images/check.gif" width="17" height="17" border="0"> <td align="left"><% if (plugin.hasPublicIP()) { %>
<% } else { %> <img src="/images/check.gif" width="17" height="17" border="0">
<img src="/images/x.gif" width="17" height="17" border="0"><i>&nbsp;<fmt:message key="jn.verified.ip.warning"/></i> <% } else { %>
<% } %> <img src="/images/x.gif" width="17" height="17" border="0"><i>&nbsp;<fmt:message
</td> key="jn.verified.ip.warning"/></i>&nbsp;<b><%=publicIP%></b>
</tr> <% } %>
<tr> </td>
<td><label class="jive-label"><fmt:message key="jn.active.channels"/>:</label><br> </tr>
</td> <tr>
<td align="left"><%=plugin.getActiveChannelCount()%> <td><label class="jive-label"><fmt:message key="jn.active.channels"/>:</label><br>
</td> </td>
</tr> <td align="left"><%=plugin.getActiveChannelCount()%>
</tbody> </td>
</table> </tr>
<tr>
<td><label class="jive-label"><fmt:message key="jn.settings.overrideip"/>:</label><br>
</td>
<td align="left">
<input name="overrideip" type="text" maxlength="15" size="15"
value="<%=LocalIPResolver.getLocalIP()%>"/>
</td>
</tr>
<tr>
<th colspan="2"><input type="submit" name="update"
value="<fmt:message key="jn.settings.update.settings" />"></th>
</tr>
</tbody>
</table>
</form>
</div> </div>
</body> </body>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment