<%--
  -
  - Copyright (C) 2006-2008 Jive Software, 2017-2026 Ignite Realtime Foundation. All rights reserved.
  -
  - 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.
--%>
<%@ page contentType="text/html; charset=UTF-8" %>
<%@ page import="org.jivesoftware.openfire.XMPPServer"%>
<%@ page import="org.jivesoftware.util.JiveGlobals"%>
<%@ page import="java.util.Map" %>

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>

<%
    // Redirect if we've already run setup:
    if (!XMPPServer.getInstance().isSetupMode()) {
        response.sendRedirect("setup-completed.jsp");
        return;
    }
%>

<%
    // Get parameters
    boolean isLDAP = "org.jivesoftware.openfire.ldap.LdapAuthProvider".equals(
            JiveGlobals.getProperty("provider.auth.className"));
    boolean scramOnly = JiveGlobals.getBooleanProperty("user.scramHashedPasswordOnly");
    boolean requestedScramOnly = (request.getParameter("scramOnly") != null);
    boolean next = request.getParameter("continue") != null;
    boolean sessionFailure = false;
    if (next) {
        // Figure out where to send the user.
        String mode = request.getParameter("mode");

        if ("default".equals(mode)) {
            @SuppressWarnings("unchecked")
            Map<String,String> xmppSettings = (Map<String,String>)session.getAttribute("xmppSettings");
            if (xmppSettings == null){
                sessionFailure = true;
            } else {
                if (requestedScramOnly) {
                    JiveGlobals.setProperty("user.scramHashedPasswordOnly", "true");
                }

                // Redirect
                response.sendRedirect("setup-admin-settings.jsp");
                return;
            }
        }
        else if ("ldap".equals(mode)) {
            response.sendRedirect("setup-ldap-server.jsp");
            return;
        }
    }

    pageContext.setAttribute( "sessionFailure", sessionFailure );
    pageContext.setAttribute( "isLDAP", isLDAP );
    pageContext.setAttribute( "scramOnly", scramOnly );
%>
<html>
<head>
    <title><fmt:message key="setup.profile.title" /></title>
    <meta name="currentStep" content="3"/>
</head>
<body>

    <h1>
    <fmt:message key="setup.profile.title" />
    </h1>

    <p>
    <fmt:message key="setup.profile.description" />
    </p>

    <c:if test="${sessionFailure}">
        <span class="jive-error-text">
            <fmt:message key="setup.invalid_session" />
        </span>
    </c:if>

    <!-- BEGIN jive-contentBox -->
    <div class="jive-contentBox">
    <form action="setup-profile-settings.jsp" name="profileform" method="post">

<table cellpadding="3" cellspacing="2">
<tr>
    <td style="text-align: center; vertical-align: top">
        <input type="radio" name="mode" value="default" id="rb01" ${not isLDAP ? 'checked' : ''}>
    </td>
    <td>
        <label for="rb01"><b><fmt:message key="setup.profile.default" /></b></label><br>
        <fmt:message key="setup.profile.default_description" />
    </td>
</tr>
<tr>
    <td style="text-align: center; vertical-align: top">
        <input type="checkbox" name="scramOnly" value="scramOnly" id="rb01-0" ${scramOnly ? 'checked' : ''}>
    </td>
    <td>
        <label for="rb01-0"><b><fmt:message key="setup.profile.default.scramOnly" /></b></label><br>
        <fmt:message key="setup.profile.default.scramOnly_description" />
    </td>
</tr>
<tr>
    <td style="text-align: center; vertical-align: top">
        <input type="radio" name="mode" value="ldap" id="rb02" ${isLDAP ? 'checked' : ''}>
    </td>
    <td>
        <label for="rb02"><b><fmt:message key="setup.profile.ldap" /></b></label><br>
        <fmt:message key="setup.profile.ldap_description" />
    </td>
</tr>
</table>

<br>
        <div align="right">
            <input type="Submit" name="continue" value="<fmt:message key="global.continue" />" id="jive-setup-save">
        </div>

    </form>
    </div>
    <!-- END jive-contentBox -->

</body>
</html>
