Commit cd612961 authored by Axel Brand's avatar Axel Brand Committed by daeva

Gojara

- Changed adminmessages sent to contain id of specific command, changes in GojaraAdminProcessor to reflect this.
- Do a Config Check if a transport registers to see if it is configured for gojaraadmin, track this state so we can use it in jsp Overview of Spectrum2 Stats 

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@13698 b35dd754-fafc-0310-a699-88a17e54d16e
parent 1cb39be5
......@@ -8,6 +8,7 @@ import org.jivesoftware.openfire.XMPPServer;
import org.jivesoftware.openfire.interceptor.PacketInterceptor;
import org.jivesoftware.openfire.interceptor.PacketRejectedException;
import org.jivesoftware.openfire.plugin.gojara.messagefilter.processors.*;
import org.jivesoftware.openfire.plugin.gojara.sessions.GojaraAdminManager;
import org.jivesoftware.openfire.plugin.gojara.sessions.TransportSessionManager;
import org.jivesoftware.openfire.roster.RosterManager;
import org.jivesoftware.openfire.session.Session;
......@@ -35,6 +36,7 @@ public class MainInterceptor implements PacketInterceptor {
private Set<String> activeTransports = new ConcurrentHashSet<String>();
private Map<String, AbstractRemoteRosterProcessor> packetProcessors = new HashMap<String, AbstractRemoteRosterProcessor>();
private TransportSessionManager tSessionManager = TransportSessionManager.getInstance();
private GojaraAdminManager gojaraAdminmanager = GojaraAdminManager.getInstance();
private Boolean frozen;
public MainInterceptor() {
......@@ -65,8 +67,10 @@ public class MainInterceptor implements PacketInterceptor {
public boolean addTransport(String subDomain) {
Log.info("Trying to add " + subDomain + " to Set of watched Transports.");
boolean retval = this.activeTransports.add(subDomain);
if (retval)
if (retval) {
tSessionManager.addTransport(subDomain);
gojaraAdminmanager.testAdminConfiguration(subDomain);
}
return retval;
}
......@@ -74,6 +78,7 @@ public class MainInterceptor implements PacketInterceptor {
public boolean removeTransport(String subDomain) {
Log.info("Trying to remove " + subDomain + " from Set of watched Transports.");
tSessionManager.removeTransport(subDomain);
gojaraAdminmanager.gatewayUnregistered(subDomain);
return this.activeTransports.remove(subDomain);
}
......@@ -151,11 +156,19 @@ public class MainInterceptor implements PacketInterceptor {
if (to_s.length() > 0 && iqPacket.getType().equals(IQ.Type.get))
throw new PacketRejectedException();
}
}
// Gojara Admin Manager Feature - Intercept responses to ADHOC commands sent via AdminManager
else if (packet instanceof Message && activeTransports.contains(from) && to.contains("gojaraadmin")) {
packetProcessors.get("gojaraAdminProcessor").process(packet, from, to, from);
}
// NONPERSISTANT Feature
} else if (!JiveGlobals.getBooleanProperty("plugin.remoteroster.persistent", false)) {
else {
if (!JiveGlobals.getBooleanProperty("plugin.remoteroster.persistent", false)) {
if (packet instanceof Presence && activeTransports.contains(from))
packetProcessors.get("handleNonPersistant").process(packet, from, to, from);
}
}
} else if (incoming && processed) {
// We ignore Pings from S2 to S2 itself.
......@@ -188,10 +201,6 @@ public class MainInterceptor implements PacketInterceptor {
}
}
// Gojara Admin Manager Feature - Intercept responses to ADHOC commands sent via AdminManager
else if (packet instanceof Message && activeTransports.contains(from) && to.contains("gojaraadmin")) {
packetProcessors.get("gojaraAdminProcessor").process(packet, from, to, from);
}
} else if (!incoming && !processed) {
......
package org.jivesoftware.openfire.plugin.gojara.messagefilter.processors;
import org.jivesoftware.openfire.interceptor.PacketRejectedException;
import org.jivesoftware.openfire.plugin.gojara.sessions.GojaraAdminManager;
import org.jivesoftware.openfire.plugin.gojara.sessions.TransportSessionManager;
import org.xmpp.packet.JID;
import org.xmpp.packet.Message;
......@@ -8,6 +9,7 @@ import org.xmpp.packet.Packet;
public class GojaraAdminProcessor extends AbstractRemoteRosterProcessor {
private TransportSessionManager transportSessionManager = TransportSessionManager.getInstance();
private GojaraAdminManager gojaraAdminManager = GojaraAdminManager.getInstance();
public GojaraAdminProcessor() {
Log.info("Created GojaraAdminProcessor");
......@@ -22,19 +24,34 @@ public class GojaraAdminProcessor extends AbstractRemoteRosterProcessor {
@Override
public void process(Packet packet, String subdomain, String to, String from) throws PacketRejectedException {
Message message = (Message) packet;
String body = message.getBody();
// unregister <bare_jid>
if (body.endsWith("unregistered.") || body.endsWith("registered")) {
Log.info("Ignoring Message! " + message.toString());
// handle different commands
Log.info("Intercepted something: " + message.toString());
String command = packet.getID();
if (command.equals("online_users")){
handleOnlineUsers(message, subdomain);
} else if (command.equals("unregister")) {
handleUnregister(message);
} else if (command.equals("config_check")) {
handleConfigCheck(subdomain);
}
}
// online_users
else {
private void handleOnlineUsers(Message message, String subdomain) {
String[] content = message.getBody().split("\\r?\\n");
for (String user : content) {
JID userjid = new JID(user);
transportSessionManager.connectUserTo(subdomain, userjid.getNode());
}
Log.info("Found online Users!" + message.toString());
Log.info("Found online_users command!");
}
private void handleUnregister(Message message) {
Log.info("Found unregister command! ");
}
private void handleConfigCheck(String subdomain) {
gojaraAdminManager.confirmGatewayConfig(subdomain);
Log.info("Confirm config_check for " + subdomain);
}
}
\ No newline at end of file
package org.jivesoftware.openfire.plugin.gojara.sessions;
import java.util.HashSet;
import java.util.Set;
import org.jivesoftware.openfire.PacketRouter;
import org.jivesoftware.openfire.XMPPServer;
import org.jivesoftware.openfire.user.UserAlreadyExistsException;
......@@ -9,6 +12,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xmpp.packet.JID;
import org.xmpp.packet.Message;
import org.xmpp.packet.Message.Type;
/**
* This Class sends Ad-Hoc commands to given spectrum2 transports, which will then be intercepted by MainInterceptor,
......@@ -20,9 +24,11 @@ import org.xmpp.packet.Message;
public class GojaraAdminManager {
private static GojaraAdminManager myself;
private PacketRouter router;
private static final Logger Log = LoggerFactory.getLogger(TransportSessionManager.class);
private static final Logger Log = LoggerFactory.getLogger(GojaraAdminManager.class);
private JID adminUser;
private XMPPServer _server;
private Set<String> testGateways;
private boolean areGatewaysConfigured = true;
private GojaraAdminManager() {
_server = XMPPServer.getInstance();
......@@ -35,6 +41,7 @@ public class GojaraAdminManager {
Log.info("gojaraAdmin User already created.");
}
adminUser = _server.createJID("gojaraadmin", null);
testGateways = new HashSet<String>();
}
public static GojaraAdminManager getInstance() {
......@@ -54,29 +61,77 @@ public class GojaraAdminManager {
}
/**
* Sends the command online_users to specified Spectrum2 transport
* Sends a testmessage to specified gateway and schedules a task to check if there was a response.
*
*/
public void testAdminConfiguration(String gateway) {
areGatewaysConfigured = false;
testGateways.add(gateway);
Message message = new Message();
message.setFrom(adminUser);
message.setTo(gateway);
message.setID("config_check");
message.setBody("status");
message.setType(Type.chat);
router.route(message);
Log.info("Sent config_check Packet!" + message.toString());
}
/**
* Gets called from Interceptor to confirm that a Gateway responded to our config_check message.
* @param gateway
*/
public void confirmGatewayConfig(String gateway) {
testGateways.remove(gateway);
if (testGateways.isEmpty())
areGatewaysConfigured = true;
}
/**
* If a gateway disconnects we have to check if it was not configured as we may want to alter boolean areGatewaysConfigured.
*/
public void gatewayUnregistered(String gateway) {
if (testGateways.contains(gateway)) {
testGateways.remove(gateway);
if (testGateways.isEmpty())
areGatewaysConfigured = true;
}
}
public boolean areGatewaysConfigured() {
return areGatewaysConfigured;
}
/**
* Sends the command online_users to specified Spectrum2 transport. We set the ID specific to the command so we can
* identify the response.
*
* @param transport
*/
public void getOnlineUsersOf(String transport) {
Message message = new Message();
message.setFrom(adminUser);
message.setTo(transport);
message.setID("online_users");
message.setBody("online_users");
message.setType(Type.chat);
router.route(message);
Log.info("Sent following Packet!" + message.toString());
Log.info("Sent online_users Packet!" + message.toString());
}
/**
* Sends the unregister <bare_jid> command to specified Spectrum2 transport
* Sends the unregister <bare_jid> command to specified Spectrum2 transport. We set the ID specific to the command
* so we can identify the response.
*
* @param transport
*/
public void unregisterUserFrom(String transport, String user) {
Message message = new Message();
message.setFrom(adminUser);
message.setTo(transport);
message.setID("unregister");
message.setBody("unregister " + _server.createJID(user, null).toString());
message.setType(Type.chat);
router.route(message);
Log.info("Sent following Packet!" + message.toString());
Log.info("Sent Unregister Packet!" + message.toString());
}
}
......@@ -5,6 +5,7 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import org.jivesoftware.openfire.plugin.gojara.database.*;
......@@ -134,7 +135,7 @@ public class TransportSessionManager {
}
/**
* Initializes Sessions, ofc needs to be called at a point where there are Transports registered in
* Initializes Sessions through adminmanager, ofc needs to be called at a point where there are Transports registered in
* transportSessions
*/
public void initializeSessions() {
......@@ -144,6 +145,13 @@ public class TransportSessionManager {
}
}
/**
* @return Set of currently active Gateways
*/
public final Set<String>getActiveGateways() {
return transportSessions.keySet();
}
public final Map<String, Map<String, Long>> getSessions() {
return transportSessions;
}
......
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