Search in sources :

Example 21 with DataForm

use of org.xmpp.forms.DataForm in project Openfire by igniterealtime.

the class GetAdminConsoleInfo method execute.

@Override
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");
    // Gets a valid bind interface
    PluginManager pluginManager = XMPPServer.getInstance().getPluginManager();
    AdminConsolePlugin adminConsolePlugin = ((AdminConsolePlugin) pluginManager.getPlugin("admin"));
    String bindInterface = adminConsolePlugin.getBindInterface();
    int adminPort = adminConsolePlugin.getAdminUnsecurePort();
    int adminSecurePort = adminConsolePlugin.getAdminSecurePort();
    if (bindInterface == null) {
        Enumeration<NetworkInterface> nets = null;
        try {
            nets = NetworkInterface.getNetworkInterfaces();
        } catch (SocketException e) {
            // We failed to discover a valid IP address where the admin console is running
            return;
        }
        for (NetworkInterface netInterface : Collections.list(nets)) {
            boolean found = false;
            Enumeration<InetAddress> addresses = netInterface.getInetAddresses();
            for (InetAddress address : Collections.list(addresses)) {
                if ("127.0.0.1".equals(address.getHostAddress()) || "0:0:0:0:0:0:0:1".equals(address.getHostAddress())) {
                    continue;
                }
                Socket socket = new Socket();
                InetSocketAddress remoteAddress = new InetSocketAddress(address, adminPort > 0 ? adminPort : adminSecurePort);
                try {
                    socket.connect(remoteAddress);
                    bindInterface = address.getHostAddress();
                    found = true;
                    break;
                } catch (IOException e) {
                // Ignore this address. Let's hope there is more addresses to validate
                }
            }
            if (found) {
                break;
            }
        }
    }
    // If there is no valid bind interface, return an error
    if (bindInterface == null) {
        Element note = command.addElement("note");
        note.addAttribute("type", "error");
        note.setText("Couldn't find a valid interface.");
        return;
    }
    // Add the bind interface
    field = form.addField();
    field.setLabel("Bind interface");
    field.setVariable("bindInterface");
    field.addValue(bindInterface);
    // Add the port
    field = form.addField();
    field.setLabel("Port");
    field.setVariable("adminPort");
    field.addValue(adminPort);
    // Add the secure port
    field = form.addField();
    field.setLabel("Secure port");
    field.setVariable("adminSecurePort");
    field.addValue(adminSecurePort);
    command.add(form.getElement());
}
Also used : Element(org.dom4j.Element) IOException(java.io.IOException) PluginManager(org.jivesoftware.openfire.container.PluginManager) AdminConsolePlugin(org.jivesoftware.openfire.container.AdminConsolePlugin) DataForm(org.xmpp.forms.DataForm) FormField(org.xmpp.forms.FormField)

Example 22 with DataForm

use of org.xmpp.forms.DataForm in project Openfire by igniterealtime.

the class GetListActiveUsers method execute.

@Override
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(max_items)) {
        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<>(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());
}
Also used : ClientSession(org.jivesoftware.openfire.session.ClientSession) DataForm(org.xmpp.forms.DataForm) FormField(org.xmpp.forms.FormField)

Example 23 with DataForm

use of org.xmpp.forms.DataForm in project Openfire by igniterealtime.

the class GetNumberActiveUsers method execute.

@Override
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<>(sessions.size());
    for (ClientSession session : sessions) {
        if (session.getPresence().isAvailable()) {
            users.add(session.getAddress().toBareJID());
        }
    }
    field.addValue(users.size());
    command.add(form.getElement());
}
Also used : ClientSession(org.jivesoftware.openfire.session.ClientSession) DataForm(org.xmpp.forms.DataForm) FormField(org.xmpp.forms.FormField) HashSet(java.util.HashSet)

Example 24 with DataForm

use of org.xmpp.forms.DataForm in project Openfire by igniterealtime.

the class GetNumberOnlineUsers method execute.

@Override
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<>(sessions.size());
    for (ClientSession session : sessions) {
        users.add(session.getAddress().toBareJID());
    }
    field.addValue(users.size());
    command.add(form.getElement());
}
Also used : ClientSession(org.jivesoftware.openfire.session.ClientSession) DataForm(org.xmpp.forms.DataForm) FormField(org.xmpp.forms.FormField) HashSet(java.util.HashSet)

Example 25 with DataForm

use of org.xmpp.forms.DataForm in project Openfire by igniterealtime.

the class GetUsersPresence method execute.

@Override
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(max_items)) {
        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());
}
Also used : ClientSession(org.jivesoftware.openfire.session.ClientSession) DataForm(org.xmpp.forms.DataForm) FormField(org.xmpp.forms.FormField)

Aggregations

DataForm (org.xmpp.forms.DataForm)81 FormField (org.xmpp.forms.FormField)67 Element (org.dom4j.Element)23 IQ (org.xmpp.packet.IQ)12 JID (org.xmpp.packet.JID)9 ArrayList (java.util.ArrayList)7 ClientSession (org.jivesoftware.openfire.session.ClientSession)6 HashMap (java.util.HashMap)4 List (java.util.List)4 Group (org.jivesoftware.openfire.group.Group)4 Date (java.util.Date)3 UnauthorizedException (org.jivesoftware.openfire.auth.UnauthorizedException)3 MUCRoom (org.jivesoftware.openfire.muc.MUCRoom)3 UserNotFoundException (org.jivesoftware.openfire.user.UserNotFoundException)3 XStream (com.thoughtworks.xstream.XStream)2 ParseException (java.text.ParseException)2 HashSet (java.util.HashSet)2 Iterator (java.util.Iterator)2 PacketException (org.jivesoftware.openfire.PacketException)2 GroupNotFoundException (org.jivesoftware.openfire.group.GroupNotFoundException)2