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 @@
<li>Public IP Verification</li>
</ul>
<p><b>0.0.3</b> -- November 12, 2010</p>
<ul>
<li>Override Public IP COnfiguration</li>
</ul>
</body>
</html>
......@@ -5,4 +5,7 @@ admin.item.jn.settings.name=Jingle Nodes Status
jn.verified.ip=Verified Public IP
jn.active.channels=Active Channels
jn.settings.title=Jingle Nodes Status
jn.verified.ip.warning=Jingle Nodes Requires a Public IP for Internet Calling. Check your Network Settings.
\ No newline at end of file
jn.verified.ip.warning=Jingle Nodes Requires a Public IP for Internet Calling. Public IP Found:
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 {
childElement.addAttribute(LOCAL_PORT, Integer.toString(channel.getPortA()));
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);
Log.debug("Created relay channel {}:{}, {}:{}, {}:{}", new Object[]{HOST,
......
......@@ -29,6 +29,7 @@ import java.net.InetSocketAddress;
import org.jivesoftware.openfire.container.Plugin;
import org.jivesoftware.openfire.container.PluginManager;
import org.jivesoftware.util.JiveGlobals;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xmpp.component.ComponentException;
......@@ -41,17 +42,25 @@ import org.xmpp.jnodes.nio.PublicIPResolver;
public class JingleNodesPlugin implements Plugin {
private static final Logger Log = LoggerFactory.getLogger(JingleNodesPlugin.class);
public static final String JN_PUB_IP_PROPERTY = "jinglenodes.publicip";
private ComponentManager componentManager;
private final ConcurrentHashMap<String, RelayChannel> channels = new ConcurrentHashMap<String, RelayChannel>();
private final long timeout = 60000;
private final AtomicInteger ids = new AtomicInteger(0);
private final ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(1);
private final String serviceName = "relay";
private final boolean bindAllInterfaces;
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) {
componentManager = ComponentManagerFactory.getComponentManager();
JingleNodesComponent component = new JingleNodesComponent(this);
......@@ -82,13 +91,11 @@ public class JingleNodesPlugin implements Plugin {
verifyNetwork();
}
private void verifyNetwork() {
final String localAddress = LocalIPResolver.getLocalIP();
public void verifyNetwork() {
final String localAddress = JiveGlobals.getProperty(JN_PUB_IP_PROPERTY, LocalIPResolver.getLocalIP());
LocalIPResolver.setOverrideIp(localAddress);
final InetSocketAddress publicAddress = PublicIPResolver.getPublicAddress("stun.xten.com", 3478);
hasPublicIP = publicAddress != null && publicAddress.getAddress().getHostAddress().equals(localAddress);
}
private void closeAllChannels() {
......@@ -100,7 +107,8 @@ public class JingleNodesPlugin implements Plugin {
public RelayChannel createRelayChannel() {
RelayChannel rc = null;
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 String sId = String.valueOf(id);
rc.setAttachment(sId);
......
<%@ page import="org.jinglenodes.JingleNodesPlugin" %>
<%@ page import="org.jivesoftware.openfire.XMPPServer" %>
<%@ page import="java.util.Collection" %>
<%@ page import="org.jivesoftware.openfire.container.Plugin" %>
<%@ page import="org.jivesoftware.util.LocaleUtils" %>
<%@ 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: $
- $Date: $
......@@ -27,9 +31,34 @@
<%@ 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
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>
<head>
......@@ -37,32 +66,53 @@
<meta name="pageID" content="jingle-nodes"/>
</head>
<body>
<% if (errorMessage != null) { %>
<div class="error">
<%= errorMessage%>
</div>
<br/>
<% } %>
<div class="jive-table">
<table class="jive-table" cellpadding="0" cellspacing="0" border="0" width="100%">
<thead>
<tr>
<th colspan="2"><fmt:message key="jn.settings.title"/></th>
</tr>
</thead>
<tbody>
<tr>
<td><label class="jive-label"><fmt:message key="jn.verified.ip"/>:</label><br></td>
<td align="left"><% if (plugin.hasPublicIP()) { %>
<img src="/images/check.gif" width="17" height="17" border="0">
<% } else { %>
<img src="/images/x.gif" width="17" height="17" border="0"><i>&nbsp;<fmt:message key="jn.verified.ip.warning"/></i>
<% } %>
</td>
</tr>
<tr>
<td><label class="jive-label"><fmt:message key="jn.active.channels"/>:</label><br>
</td>
<td align="left"><%=plugin.getActiveChannelCount()%>
</td>
</tr>
</tbody>
</table>
<form action="jingle-nodes.jsp" method="post">
<table class="jive-table" cellpadding="0" cellspacing="0" border="0" width="100%">
<thead>
<tr>
<th colspan="2"><fmt:message key="jn.settings.title"/></th>
</tr>
</thead>
<tbody>
<tr>
<td><label class="jive-label"><fmt:message key="jn.verified.ip"/>:</label><br></td>
<td align="left"><% if (plugin.hasPublicIP()) { %>
<img src="/images/check.gif" width="17" height="17" border="0">
<% } else { %>
<img src="/images/x.gif" width="17" height="17" border="0"><i>&nbsp;<fmt:message
key="jn.verified.ip.warning"/></i>&nbsp;<b><%=publicIP%></b>
<% } %>
</td>
</tr>
<tr>
<td><label class="jive-label"><fmt:message key="jn.active.channels"/>:</label><br>
</td>
<td align="left"><%=plugin.getActiveChannelCount()%>
</td>
</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>
</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