Commit 6ede124a authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gato

Initial version. JM-637

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@3749 b35dd754-fafc-0310-a699-88a17e54d16e
parent c95b15f4
/**
* $Revision: $
* $Date: $
*
* Copyright (C) 2006 Jive Software. All rights reserved.
*
* This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution.
*/
package org.jivesoftware.wildfire.commands.admin;
import org.dom4j.Element;
import org.jivesoftware.wildfire.ClientSession;
import org.jivesoftware.wildfire.SessionManager;
import org.jivesoftware.wildfire.commands.AdHocCommand;
import org.jivesoftware.wildfire.commands.SessionData;
import org.xmpp.forms.DataForm;
import org.xmpp.forms.FormField;
import java.util.*;
/**
* Command that allows to retrieve a list of all active users.
*
* @author Gaston Dombiak
*
* TODO Use i18n
*/
public class GetListActiveUsers extends AdHocCommand {
protected void addStageInformation(SessionData data, Element command) {
DataForm form = new DataForm(DataForm.Type.form);
form.setTitle("Requesting List of Active Users");
form.addInstruction("Fill out this form to request the active users of this service.");
FormField field = form.addField();
field.setType(FormField.Type.hidden);
field.setVariable("FORM_TYPE");
field.addValue("http://jabber.org/protocol/admin");
field = form.addField();
field.setType(FormField.Type.list_single);
field.setLabel("Maximum number of items to show");
field.setVariable("max_items");
field.addOption("25", "25");
field.addOption("50", "50");
field.addOption("75", "75");
field.addOption("100", "100");
field.addOption("150", "150");
field.addOption("200", "200");
field.addOption("None", "none");
// Add the form to the command
command.add(form.getElement());
}
public void execute(SessionData data, Element command) {
String max_items = data.getData().get("max_items").get(0);
int maxItems = -1;
if (max_items != null && "none".equals(maxItems)) {
try {
maxItems = Integer.parseInt(max_items);
}
catch (NumberFormatException e) {
// Do nothing. Assume that all users are being requested
}
}
DataForm form = new DataForm(DataForm.Type.result);
FormField field = form.addField();
field.setType(FormField.Type.hidden);
field.setVariable("FORM_TYPE");
field.addValue("http://jabber.org/protocol/admin");
field = form.addField();
field.setLabel("The list of active users");
field.setVariable("activeuserjids");
// Get list of users (i.e. bareJIDs) that are connected to the server
Collection<ClientSession> sessions = SessionManager.getInstance().getSessions();
Set<String> users = new HashSet<String>(sessions.size());
for (ClientSession session : sessions) {
if (session.getPresence().isAvailable()) {
users.add(session.getAddress().toBareJID());
}
if (maxItems > 0 && users.size() >= maxItems) {
break;
}
}
// Add users to the result
for (String user : users) {
field.addValue(user);
}
command.add(form.getElement());
}
public String getCode() {
return "http://jabber.org/protocol/admin#get-active-users";
}
public String getDefaultLabel() {
return "Get List of Active Users";
}
protected List<Action> getActions(SessionData data) {
return Arrays.asList(Action.complete);
}
protected Action getExecuteAction(SessionData data) {
return Action.complete;
}
public int getMaxStages(SessionData data) {
return 1;
}
}
/**
* $Revision: $
* $Date: $
*
* Copyright (C) 2006 Jive Software. All rights reserved.
*
* This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution.
*/
package org.jivesoftware.wildfire.commands.admin;
import org.dom4j.Element;
import org.jivesoftware.wildfire.ClientSession;
import org.jivesoftware.wildfire.SessionManager;
import org.jivesoftware.wildfire.commands.AdHocCommand;
import org.jivesoftware.wildfire.commands.SessionData;
import org.xmpp.forms.DataForm;
import org.xmpp.forms.FormField;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
* Command that allows to retrieve the number of online users who are active at any one moment.
* Active users are those users that have sent an available presence.
*
* @author Gaston Dombiak
*/
public class GetNumberActiveUsers extends AdHocCommand {
protected void addStageInformation(SessionData data, Element command) {
//Do nothing since there are no stages
}
public void execute(SessionData data, Element command) {
DataForm form = new DataForm(DataForm.Type.result);
FormField field = form.addField();
field.setType(FormField.Type.hidden);
field.setVariable("FORM_TYPE");
field.addValue("http://jabber.org/protocol/admin");
field = form.addField();
field.setLabel(getLabel());
field.setVariable("activeusersnum");
// Make sure that we are only counting based on bareJIDs and not fullJIDs
Collection<ClientSession> sessions = SessionManager.getInstance().getSessions();
Set<String> users = new HashSet<String>(sessions.size());
for (ClientSession session : sessions) {
if (session.getPresence().isAvailable()) {
users.add(session.getAddress().toBareJID());
}
}
field.addValue(users.size());
command.add(form.getElement());
}
protected List<Action> getActions(SessionData data) {
//Do nothing since there are no stages
return null;
}
public String getCode() {
return "http://jabber.org/protocol/admin#get-active-users-num";
}
public String getDefaultLabel() {
// TODO Use i18n
return "Number of Active Users";
}
protected Action getExecuteAction(SessionData data) {
//Do nothing since there are no stages
return null;
}
public int getMaxStages(SessionData data) {
return 0;
}
}
/**
* $Revision: $
* $Date: $
*
* Copyright (C) 2006 Jive Software. All rights reserved.
*
* This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution.
*/
package org.jivesoftware.wildfire.commands.admin;
import org.dom4j.Element;
import org.jivesoftware.wildfire.ClientSession;
import org.jivesoftware.wildfire.SessionManager;
import org.jivesoftware.wildfire.commands.AdHocCommand;
import org.jivesoftware.wildfire.commands.SessionData;
import org.xmpp.forms.DataForm;
import org.xmpp.forms.FormField;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
* Command that allows to retrieve the number of registered users who are online at
* any one moment. By "online user" is meant any user or account that currently has
* an IM session that may or may no be available.
*
* @author Gaston Dombiak
*/
public class GetNumberOnlineUsers extends AdHocCommand {
protected void addStageInformation(SessionData data, Element command) {
//Do nothing since there are no stages
}
public void execute(SessionData data, Element command) {
DataForm form = new DataForm(DataForm.Type.result);
FormField field = form.addField();
field.setType(FormField.Type.hidden);
field.setVariable("FORM_TYPE");
field.addValue("http://jabber.org/protocol/admin");
field = form.addField();
field.setLabel(getLabel());
field.setVariable("onlineusersnum");
// Make sure that we are only counting based on bareJIDs and not fullJIDs
Collection<ClientSession> sessions = SessionManager.getInstance().getSessions();
Set<String> users = new HashSet<String>(sessions.size());
for (ClientSession session : sessions) {
users.add(session.getAddress().toBareJID());
}
field.addValue(users.size());
command.add(form.getElement());
}
protected List<Action> getActions(SessionData data) {
//Do nothing since there are no stages
return null;
}
public String getCode() {
return "http://jabber.org/protocol/admin#get-online-users-num";
}
public String getDefaultLabel() {
// TODO Use i18n
return "Number of Online Users";
}
protected Action getExecuteAction(SessionData data) {
//Do nothing since there are no stages
return null;
}
public int getMaxStages(SessionData data) {
return 0;
}
}
package org.jivesoftware.wildfire.commands.admin;
import org.dom4j.Element;
import org.jivesoftware.wildfire.SessionManager;
import org.jivesoftware.wildfire.commands.AdHocCommand;
import org.jivesoftware.wildfire.commands.SessionData;
import org.xmpp.forms.DataForm;
import org.xmpp.forms.FormField;
import java.util.List;
/**
* Command that allows to retrieve the number of user sessions at any one moment. That means
* that the result will include all connected resources of all users.
*
* @author Gaston Dombiak
*/
public class GetNumberUserSessions extends AdHocCommand {
protected void addStageInformation(SessionData data, Element command) {
//Do nothing since there are no stages
}
public void execute(SessionData data, Element command) {
DataForm form = new DataForm(DataForm.Type.result);
FormField field = form.addField();
field.setType(FormField.Type.hidden);
field.setVariable("FORM_TYPE");
field.addValue("http://jabber.org/protocol/admin");
field = form.addField();
field.setLabel(getLabel());
field.setVariable("onlineuserssessionsnum");
field.addValue(SessionManager.getInstance().getSessionCount());
command.add(form.getElement());
}
protected List<Action> getActions(SessionData data) {
//Do nothing since there are no stages
return null;
}
public String getCode() {
return "http://jabber.org/protocol/admin#get-sessions-num";
}
public String getDefaultLabel() {
// TODO Use i18n
return "Number of Connected User Sessions";
}
protected Action getExecuteAction(SessionData data) {
//Do nothing since there are no stages
return null;
}
public int getMaxStages(SessionData data) {
return 0;
}
}
/**
* $Revision: $
* $Date: $
*
* Copyright (C) 2006 Jive Software. All rights reserved.
*
* This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution.
*/
package org.jivesoftware.wildfire.commands.admin;
import org.dom4j.Element;
import org.jivesoftware.wildfire.ClientSession;
import org.jivesoftware.wildfire.SessionManager;
import org.jivesoftware.wildfire.commands.AdHocCommand;
import org.jivesoftware.wildfire.commands.SessionData;
import org.xmpp.forms.DataForm;
import org.xmpp.forms.FormField;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
/**
* Command that allows to retrieve the presence of all active users.
*
* @author Gaston Dombiak
*
* TODO Use i18n
*/
public class GetUsersPresence extends AdHocCommand {
protected void addStageInformation(SessionData data, Element command) {
DataForm form = new DataForm(DataForm.Type.form);
form.setTitle("Requesting Presence of Active Users");
form.addInstruction("Fill out this form to request the active users presence of this service.");
FormField field = form.addField();
field.setType(FormField.Type.hidden);
field.setVariable("FORM_TYPE");
field.addValue("http://jabber.org/protocol/admin");
field = form.addField();
field.setType(FormField.Type.list_single);
field.setLabel("Maximum number of items to return");
field.setVariable("max_items");
field.addOption("25", "25");
field.addOption("50", "50");
field.addOption("75", "75");
field.addOption("100", "100");
field.addOption("150", "150");
field.addOption("200", "200");
field.addOption("None", "none");
// Add the form to the command
command.add(form.getElement());
}
public void execute(SessionData data, Element command) {
String max_items = data.getData().get("max_items").get(0);
int maxItems = -1;
if (max_items != null && "none".equals(maxItems)) {
try {
maxItems = Integer.parseInt(max_items);
}
catch (NumberFormatException e) {
// Do nothing. Assume that all users are being requested
}
}
DataForm form = new DataForm(DataForm.Type.result);
FormField field = form.addField();
field.setType(FormField.Type.hidden);
field.setVariable("FORM_TYPE");
field.addValue("http://jabber.org/protocol/admin");
field = form.addField();
field.setLabel("The presences of active users");
field.setVariable("activeuserpresences");
// Get list of users (i.e. bareJIDs) that are connected to the server
Collection<ClientSession> sessions = SessionManager.getInstance().getSessions();
int index = 1;
for (ClientSession session : sessions) {
if (session.getPresence().isAvailable()) {
field.addValue(session.getPresence().toXML());
}
if (maxItems > 0 && index >= maxItems) {
break;
}
}
command.add(form.getElement());
}
public String getCode() {
return "http://jabber.org/protocol/admin#get-active-presences";
}
public String getDefaultLabel() {
return "Get Presence of Active Users";
}
protected List<Action> getActions(SessionData data) {
return Arrays.asList(Action.complete);
}
protected Action getExecuteAction(SessionData data) {
return Action.complete;
}
public int getMaxStages(SessionData data) {
return 1;
}
}
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