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; ...@@ -8,6 +8,7 @@ import org.jivesoftware.openfire.XMPPServer;
import org.jivesoftware.openfire.interceptor.PacketInterceptor; import org.jivesoftware.openfire.interceptor.PacketInterceptor;
import org.jivesoftware.openfire.interceptor.PacketRejectedException; import org.jivesoftware.openfire.interceptor.PacketRejectedException;
import org.jivesoftware.openfire.plugin.gojara.messagefilter.processors.*; 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.plugin.gojara.sessions.TransportSessionManager;
import org.jivesoftware.openfire.roster.RosterManager; import org.jivesoftware.openfire.roster.RosterManager;
import org.jivesoftware.openfire.session.Session; import org.jivesoftware.openfire.session.Session;
...@@ -35,6 +36,7 @@ public class MainInterceptor implements PacketInterceptor { ...@@ -35,6 +36,7 @@ public class MainInterceptor implements PacketInterceptor {
private Set<String> activeTransports = new ConcurrentHashSet<String>(); private Set<String> activeTransports = new ConcurrentHashSet<String>();
private Map<String, AbstractRemoteRosterProcessor> packetProcessors = new HashMap<String, AbstractRemoteRosterProcessor>(); private Map<String, AbstractRemoteRosterProcessor> packetProcessors = new HashMap<String, AbstractRemoteRosterProcessor>();
private TransportSessionManager tSessionManager = TransportSessionManager.getInstance(); private TransportSessionManager tSessionManager = TransportSessionManager.getInstance();
private GojaraAdminManager gojaraAdminmanager = GojaraAdminManager.getInstance();
private Boolean frozen; private Boolean frozen;
public MainInterceptor() { public MainInterceptor() {
...@@ -65,8 +67,10 @@ public class MainInterceptor implements PacketInterceptor { ...@@ -65,8 +67,10 @@ public class MainInterceptor implements PacketInterceptor {
public boolean addTransport(String subDomain) { public boolean addTransport(String subDomain) {
Log.info("Trying to add " + subDomain + " to Set of watched Transports."); Log.info("Trying to add " + subDomain + " to Set of watched Transports.");
boolean retval = this.activeTransports.add(subDomain); boolean retval = this.activeTransports.add(subDomain);
if (retval) if (retval) {
tSessionManager.addTransport(subDomain); tSessionManager.addTransport(subDomain);
gojaraAdminmanager.testAdminConfiguration(subDomain);
}
return retval; return retval;
} }
...@@ -74,6 +78,7 @@ public class MainInterceptor implements PacketInterceptor { ...@@ -74,6 +78,7 @@ public class MainInterceptor implements PacketInterceptor {
public boolean removeTransport(String subDomain) { public boolean removeTransport(String subDomain) {
Log.info("Trying to remove " + subDomain + " from Set of watched Transports."); Log.info("Trying to remove " + subDomain + " from Set of watched Transports.");
tSessionManager.removeTransport(subDomain); tSessionManager.removeTransport(subDomain);
gojaraAdminmanager.gatewayUnregistered(subDomain);
return this.activeTransports.remove(subDomain); return this.activeTransports.remove(subDomain);
} }
...@@ -151,10 +156,18 @@ public class MainInterceptor implements PacketInterceptor { ...@@ -151,10 +156,18 @@ public class MainInterceptor implements PacketInterceptor {
if (to_s.length() > 0 && iqPacket.getType().equals(IQ.Type.get)) if (to_s.length() > 0 && iqPacket.getType().equals(IQ.Type.get))
throw new PacketRejectedException(); throw new PacketRejectedException();
} }
// NONPERSISTANT Feature
} else if (!JiveGlobals.getBooleanProperty("plugin.remoteroster.persistent", false)) { }
if (packet instanceof Presence && activeTransports.contains(from)) // Gojara Admin Manager Feature - Intercept responses to ADHOC commands sent via AdminManager
packetProcessors.get("handleNonPersistant").process(packet, from, to, from); 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)) {
if (packet instanceof Presence && activeTransports.contains(from))
packetProcessors.get("handleNonPersistant").process(packet, from, to, from);
}
} }
} else if (incoming && processed) { } else if (incoming && processed) {
...@@ -188,10 +201,6 @@ public class MainInterceptor implements PacketInterceptor { ...@@ -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) { } else if (!incoming && !processed) {
......
package org.jivesoftware.openfire.plugin.gojara.messagefilter.processors; package org.jivesoftware.openfire.plugin.gojara.messagefilter.processors;
import org.jivesoftware.openfire.interceptor.PacketRejectedException; import org.jivesoftware.openfire.interceptor.PacketRejectedException;
import org.jivesoftware.openfire.plugin.gojara.sessions.GojaraAdminManager;
import org.jivesoftware.openfire.plugin.gojara.sessions.TransportSessionManager; import org.jivesoftware.openfire.plugin.gojara.sessions.TransportSessionManager;
import org.xmpp.packet.JID; import org.xmpp.packet.JID;
import org.xmpp.packet.Message; import org.xmpp.packet.Message;
...@@ -8,6 +9,7 @@ import org.xmpp.packet.Packet; ...@@ -8,6 +9,7 @@ import org.xmpp.packet.Packet;
public class GojaraAdminProcessor extends AbstractRemoteRosterProcessor { public class GojaraAdminProcessor extends AbstractRemoteRosterProcessor {
private TransportSessionManager transportSessionManager = TransportSessionManager.getInstance(); private TransportSessionManager transportSessionManager = TransportSessionManager.getInstance();
private GojaraAdminManager gojaraAdminManager = GojaraAdminManager.getInstance();
public GojaraAdminProcessor() { public GojaraAdminProcessor() {
Log.info("Created GojaraAdminProcessor"); Log.info("Created GojaraAdminProcessor");
...@@ -22,19 +24,34 @@ public class GojaraAdminProcessor extends AbstractRemoteRosterProcessor { ...@@ -22,19 +24,34 @@ public class GojaraAdminProcessor extends AbstractRemoteRosterProcessor {
@Override @Override
public void process(Packet packet, String subdomain, String to, String from) throws PacketRejectedException { public void process(Packet packet, String subdomain, String to, String from) throws PacketRejectedException {
Message message = (Message) packet; Message message = (Message) packet;
String body = message.getBody();
// unregister <bare_jid> // handle different commands
if (body.endsWith("unregistered.") || body.endsWith("registered")) { Log.info("Intercepted something: " + message.toString());
Log.info("Ignoring Message! " + 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 {
String[] content = message.getBody().split("\\r?\\n"); private void handleOnlineUsers(Message message, String subdomain) {
for (String user : content) { String[] content = message.getBody().split("\\r?\\n");
JID userjid = new JID(user); for (String user : content) {
transportSessionManager.connectUserTo(subdomain, userjid.getNode()); 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; package org.jivesoftware.openfire.plugin.gojara.sessions;
import java.util.HashSet;
import java.util.Set;
import org.jivesoftware.openfire.PacketRouter; import org.jivesoftware.openfire.PacketRouter;
import org.jivesoftware.openfire.XMPPServer; import org.jivesoftware.openfire.XMPPServer;
import org.jivesoftware.openfire.user.UserAlreadyExistsException; import org.jivesoftware.openfire.user.UserAlreadyExistsException;
...@@ -9,6 +12,7 @@ import org.slf4j.Logger; ...@@ -9,6 +12,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.xmpp.packet.JID; import org.xmpp.packet.JID;
import org.xmpp.packet.Message; 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, * 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; ...@@ -20,9 +24,11 @@ import org.xmpp.packet.Message;
public class GojaraAdminManager { public class GojaraAdminManager {
private static GojaraAdminManager myself; private static GojaraAdminManager myself;
private PacketRouter router; 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 JID adminUser;
private XMPPServer _server; private XMPPServer _server;
private Set<String> testGateways;
private boolean areGatewaysConfigured = true;
private GojaraAdminManager() { private GojaraAdminManager() {
_server = XMPPServer.getInstance(); _server = XMPPServer.getInstance();
...@@ -35,6 +41,7 @@ public class GojaraAdminManager { ...@@ -35,6 +41,7 @@ public class GojaraAdminManager {
Log.info("gojaraAdmin User already created."); Log.info("gojaraAdmin User already created.");
} }
adminUser = _server.createJID("gojaraadmin", null); adminUser = _server.createJID("gojaraadmin", null);
testGateways = new HashSet<String>();
} }
public static GojaraAdminManager getInstance() { public static GojaraAdminManager getInstance() {
...@@ -43,7 +50,7 @@ public class GojaraAdminManager { ...@@ -43,7 +50,7 @@ public class GojaraAdminManager {
} }
return myself; return myself;
} }
public void removeAdminUser() { public void removeAdminUser() {
UserManager userManager = UserManager.getInstance(); UserManager userManager = UserManager.getInstance();
try { try {
...@@ -52,31 +59,79 @@ public class GojaraAdminManager { ...@@ -52,31 +59,79 @@ public class GojaraAdminManager {
Log.info("Couldn't remove adminUser."); Log.info("Couldn't remove adminUser.");
} }
} }
/** /**
* 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 * @param transport
*/ */
public void getOnlineUsersOf(String transport) { public void getOnlineUsersOf(String transport) {
Message message = new Message(); Message message = new Message();
message.setFrom(adminUser); message.setFrom(adminUser);
message.setTo(transport); message.setTo(transport);
message.setID("online_users");
message.setBody("online_users"); message.setBody("online_users");
message.setType(Type.chat);
router.route(message); 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 * @param transport
*/ */
public void unregisterUserFrom(String transport, String user) { public void unregisterUserFrom(String transport, String user) {
Message message = new Message(); Message message = new Message();
message.setFrom(adminUser); message.setFrom(adminUser);
message.setTo(transport); message.setTo(transport);
message.setID("unregister");
message.setBody("unregister " + _server.createJID(user, null).toString()); message.setBody("unregister " + _server.createJID(user, null).toString());
message.setType(Type.chat);
router.route(message); 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; ...@@ -5,6 +5,7 @@ import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Date; import java.util.Date;
import java.util.Map; import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import org.jivesoftware.openfire.plugin.gojara.database.*; import org.jivesoftware.openfire.plugin.gojara.database.*;
...@@ -134,7 +135,7 @@ public class TransportSessionManager { ...@@ -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 * transportSessions
*/ */
public void initializeSessions() { public void initializeSessions() {
...@@ -143,7 +144,14 @@ public class TransportSessionManager { ...@@ -143,7 +144,14 @@ public class TransportSessionManager {
adminManager.getOnlineUsersOf(transport); adminManager.getOnlineUsersOf(transport);
} }
} }
/**
* @return Set of currently active Gateways
*/
public final Set<String>getActiveGateways() {
return transportSessions.keySet();
}
public final Map<String, Map<String, Long>> getSessions() { public final Map<String, Map<String, Long>> getSessions() {
return transportSessions; 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