HttpBindStatus.java 3.78 KB
Newer Older
1
/**
2 3 4
 * $RCSfile$
 * $Revision: 3144 $
 * $Date: 2005-12-01 14:20:11 -0300 (Thu, 01 Dec 2005) $
5
 *
6 7
 * Copyright (C) 2004-2008 Jive Software. All rights reserved.
 *
8 9 10 11 12 13 14 15 16 17 18
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
19
 */
20
package org.jivesoftware.openfire.commands.admin;
21

22
import org.dom4j.Element;
23 24 25
import org.jivesoftware.openfire.commands.AdHocCommand;
import org.jivesoftware.openfire.commands.SessionData;
import org.jivesoftware.openfire.component.InternalComponentManager;
26
import org.jivesoftware.openfire.http.HttpBindManager;
27 28
import org.xmpp.forms.DataForm;
import org.xmpp.forms.FormField;
29
import org.xmpp.packet.JID;
30 31

import java.util.Collections;
32
import java.util.List;
33 34 35 36 37 38 39 40 41

/**
 * AdHoc command to return the current status of the HTTP-bind service. The command returns whether
 * or not the service is currently enabled, if it is enabled it will return the HTTP address on
 * which the service can be reached.
 *
 * @author Alexander Wenckus
 */
public class HttpBindStatus extends AdHocCommand {
42 43
    @Override
	public String getCode() {
44 45 46
        return "http://jabber.org/protocol/admin#status-http-bind";
    }

47 48
    @Override
	public String getDefaultLabel() {
49 50 51
        return "Current Http Bind Status";
    }

52 53
    @Override
	public int getMaxStages(SessionData data) {
54 55 56
        return 0;
    }

57 58
    @Override
	public void execute(SessionData data, Element command) {
59 60 61 62 63 64 65
        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");

66
        HttpBindManager manager = HttpBindManager.getInstance();
67 68 69 70
        boolean isEnabled = manager.isHttpBindEnabled();
        field = form.addField();
        field.setLabel("Http Bind Enabled");
        field.setVariable("httpbindenabled");
71
        field.addValue(String.valueOf(isEnabled));
72

73
        if (isEnabled) {
74 75 76 77 78 79 80 81 82
            field = form.addField();
            field.setLabel("Http Bind Address");
            field.setVariable("httpbindaddress");
            field.addValue(manager.getHttpBindUnsecureAddress());

            field = form.addField();
            field.setLabel("Http Bind Secure Address");
            field.setVariable("httpbindsecureaddress");
            field.addValue(manager.getHttpBindSecureAddress());
83 84 85 86 87 88 89 90

            String jsUrl = manager.getJavaScriptUrl();
            if (jsUrl != null) {
                field = form.addField();
                field.setLabel("Http Bind JavaScript Address");
                field.setVariable("javascriptaddress");
                field.addValue(jsUrl);
            }
91 92 93 94 95
        }

        command.add(form.getElement());
    }

96 97
    @Override
	protected void addStageInformation(SessionData data, Element command) {
98 99 100
        // no stages, do nothing.
    }

101 102
    @Override
	protected List<Action> getActions(SessionData data) {
103 104 105
        return Collections.emptyList();
    }

106 107
    @Override
	protected Action getExecuteAction(SessionData data) {
108 109
        return null;
    }
110 111 112 113


    @Override
    public boolean hasPermission(JID requester) {
114
        return super.hasPermission(requester) || InternalComponentManager.getInstance().hasComponent(requester);
115
    }
116
}