Search in sources :

Example 1 with PluginManager

use of org.jivesoftware.openfire.container.PluginManager 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 2 with PluginManager

use of org.jivesoftware.openfire.container.PluginManager in project Openfire by igniterealtime.

the class LocaleUtils method getPluginResourceBundle.

/**
     * Retrieve the <code>ResourceBundle</code> that is used with this plugin.
     *
     * @param pluginName the name of the plugin.
     * @return the ResourceBundle used with this plugin.
     * @throws Exception thrown if an exception occurs.
     */
public static ResourceBundle getPluginResourceBundle(String pluginName) throws Exception {
    final Locale locale = JiveGlobals.getLocale();
    String i18nFile = getI18nFile(pluginName);
    // Retrieve classloader from pluginName.
    final XMPPServer xmppServer = XMPPServer.getInstance();
    PluginManager pluginManager = xmppServer.getPluginManager();
    Plugin plugin = pluginManager.getPlugin(pluginName);
    if (plugin == null) {
        throw new NullPointerException("Plugin could not be located.");
    }
    ClassLoader pluginClassLoader = pluginManager.getPluginClassloader(plugin);
    return ResourceBundle.getBundle(i18nFile, locale, pluginClassLoader);
}
Also used : Locale(java.util.Locale) PluginManager(org.jivesoftware.openfire.container.PluginManager) XMPPServer(org.jivesoftware.openfire.XMPPServer) Plugin(org.jivesoftware.openfire.container.Plugin)

Example 3 with PluginManager

use of org.jivesoftware.openfire.container.PluginManager in project Openfire by igniterealtime.

the class ClusterClassLoader method getResources.

public Enumeration<URL> getResources(String name) throws IOException {
    Enumeration<URL> answer = null;
    try {
        answer = enterpriseClassloader.getResources(name);
    } catch (IOException e) {
    // Ignore
    }
    if (answer == null || !answer.hasMoreElements()) {
        PluginManager pluginManager = XMPPServer.getInstance().getPluginManager();
        for (Plugin plugin : pluginManager.getPlugins()) {
            String pluginName = pluginManager.getPluginDirectory(plugin).getName();
            if ("clustering".equals(pluginName) || "admin".equals(pluginName)) {
                continue;
            }
            PluginClassLoader pluginClassloader = pluginManager.getPluginClassloader(plugin);
            try {
                answer = pluginClassloader.getResources(name);
            } catch (IOException e) {
            // Ignore
            }
            if (answer != null && answer.hasMoreElements()) {
                return answer;
            }
        }
    }
    return answer;
}
Also used : PluginManager(org.jivesoftware.openfire.container.PluginManager) IOException(java.io.IOException) URL(java.net.URL) Plugin(org.jivesoftware.openfire.container.Plugin) PluginClassLoader(org.jivesoftware.openfire.container.PluginClassLoader)

Example 4 with PluginManager

use of org.jivesoftware.openfire.container.PluginManager in project Openfire by igniterealtime.

the class ConfigManager method saveSettings.

/**
     * Saves settings from options screen.
     *
     * @param transportName Name of the transport to have it's options saved (type of transport)
     * @param options Options passed from options form.
     */
public void saveSettings(String transportName, HashMap<String, String> options) {
    PluginManager pluginManager = XMPPServer.getInstance().getPluginManager();
    KrakenPlugin plugin = (KrakenPlugin) pluginManager.getPlugin("kraken");
    Document optConfig = plugin.getOptionsConfig(TransportType.valueOf(transportName));
    Element leftPanel = optConfig.getRootElement().element("leftpanel");
    if (leftPanel != null && leftPanel.nodeCount() > 0) {
        for (Object nodeObj : leftPanel.elements("item")) {
            Element node = (Element) nodeObj;
            saveOptionSetting(node, options);
        }
    }
    Element rightPanel = optConfig.getRootElement().element("rightpanel");
    if (rightPanel != null && rightPanel.nodeCount() > 0) {
        for (Object nodeObj : rightPanel.elements("item")) {
            Element node = (Element) nodeObj;
            saveOptionSetting(node, options);
        }
    }
    Element bottomPanel = optConfig.getRootElement().element("bottompanel");
    if (bottomPanel != null && bottomPanel.nodeCount() > 0) {
        for (Object nodeObj : bottomPanel.elements("item")) {
            Element node = (Element) nodeObj;
            saveOptionSetting(node, options);
        }
    }
}
Also used : PluginManager(org.jivesoftware.openfire.container.PluginManager) Element(org.dom4j.Element) KrakenPlugin(net.sf.kraken.KrakenPlugin) Document(org.dom4j.Document)

Example 5 with PluginManager

use of org.jivesoftware.openfire.container.PluginManager in project Openfire by igniterealtime.

the class ConfigManager method logoutSession.

/**
     * Logs out session via the web interface.
     *
     *
     * @param registrationID ID number associated with registration to log off.
     * @return registration ID on success, -1 on failure (-1 so that js cb_logoutSession knows which Div to edit)
    */
public Integer logoutSession(Integer registrationID) {
    try {
        PluginManager pluginManager = XMPPServer.getInstance().getPluginManager();
        KrakenPlugin plugin = (KrakenPlugin) pluginManager.getPlugin("kraken");
        Registration registration = new Registration(registrationID);
        if (!plugin.getTransportInstance(registration.getTransportType().toString()).isEnabled()) {
            return -1;
        }
        JID jid = registration.getJID();
        TransportSession session = plugin.getTransportInstance(registration.getTransportType().toString()).getTransport().getSessionManager().getSession(jid);
        plugin.getTransportInstance(registration.getTransportType().toString()).getTransport().registrationLoggedOut(session);
        return registrationID;
    } catch (NotFoundException e) {
        return -1;
    }
}
Also used : PluginManager(org.jivesoftware.openfire.container.PluginManager) JID(org.xmpp.packet.JID) Registration(net.sf.kraken.registration.Registration) NotFoundException(org.jivesoftware.util.NotFoundException) GroupNotFoundException(org.jivesoftware.openfire.group.GroupNotFoundException) UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) TransportSession(net.sf.kraken.session.TransportSession) KrakenPlugin(net.sf.kraken.KrakenPlugin)

Aggregations

PluginManager (org.jivesoftware.openfire.container.PluginManager)20 Plugin (org.jivesoftware.openfire.container.Plugin)8 KrakenPlugin (net.sf.kraken.KrakenPlugin)7 IOException (java.io.IOException)5 URL (java.net.URL)5 PluginClassLoader (org.jivesoftware.openfire.container.PluginClassLoader)5 UserNotFoundException (org.jivesoftware.openfire.user.UserNotFoundException)4 Registration (net.sf.kraken.registration.Registration)3 GroupNotFoundException (org.jivesoftware.openfire.group.GroupNotFoundException)3 NotFoundException (org.jivesoftware.util.NotFoundException)3 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 FileNotFoundException (java.io.FileNotFoundException)2 Locale (java.util.Locale)2 BaseTransport (net.sf.kraken.BaseTransport)2 RegistrationHandler (net.sf.kraken.registration.RegistrationHandler)2 Element (org.dom4j.Element)2 XMPPServer (org.jivesoftware.openfire.XMPPServer)2 JID (org.xmpp.packet.JID)2 InputStream (java.io.InputStream)1