<!--
  ~ Copyright (C) 2018 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.
  -->
<jsp:root xmlns:c="http://java.sun.com/jsp/jstl/core"
          xmlns:jsp="http://java.sun.com/JSP/Page"
          xmlns:fmt="http://java.sun.com/jsp/jstl/fmt"
          xmlns:admin="admin"
          version="2.0">
    <jsp:useBean id="webManager" class="org.jivesoftware.util.WebManager" />

    <jsp:directive.attribute name="connectionType" required="true" type="org.jivesoftware.openfire.spi.ConnectionType"/>

    <c:choose>
        <c:when test="${connectionType eq 'SOCKET_C2S' or connectionType.fallback eq 'SOCKET_C2S'}">

            <h4><fmt:message key="ssl.certificates.trust-store.c2s"/></h4>

            <c:if test="${empty webManager.XMPPServer.certificateStoreManager.getTrustStore(connectionType)}">
                <admin:infobox type="warning"><fmt:message key="ssl.certificates.store-management.error.cannot-access"/></admin:infobox>
            </c:if>

            <c:set var="pwdTrustC2S" value=""/>
            <c:forEach items="${webManager.XMPPServer.certificateStoreManager.getTrustStoreConfiguration(connectionType).password}" var="c">
                <c:set var="pwdTrustC2S" value="${pwdTrustC2S}${c}"/>
            </c:forEach>

            <table>
                <tbody>
                <tr>
                    <td><label for="loc-trust-c2s"><fmt:message key="ssl.certificates.store-management.file_label"/>:</label></td>
                    <td><input id="loc-trust-c2s" name="loc-trust-c2s" type="text" size="80" value="${webManager.XMPPServer.certificateStoreManager.getTrustStoreConfiguration(connectionType).file}"/></td>
                </tr>
                <tr>
                    <td><label for="pwd-trust-c2s"><fmt:message key="ssl.certificates.store-management.password_label"/>:</label></td>
                    <td><input id="pwd-trust-c2s" name="pwd-trust-c2s" type="password" size="30" value="${pwdTrustC2S}"/></td>
                </tr>
                <tr>
                    <td>&#160;</td>
                    <td><a href="security-truststore.jsp?connectionType=${connectionType}"><fmt:message key="ssl.certificates.store-management.manage"/></a></td>
                </tr>
                </tbody>
            </table>
        </c:when>

        <c:otherwise>
            <h4><fmt:message key="ssl.certificates.trust-store.s2s"/></h4>

            <c:if test="${empty webManager.XMPPServer.certificateStoreManager.getTrustStore(connectionType)}">
                <admin:infobox type="warning"><fmt:message key="ssl.certificates.store-management.error.cannot-access"/></admin:infobox>
            </c:if>

            <c:set var="pwdTrustS2S" value=""/>
            <c:forEach items="${webManager.XMPPServer.certificateStoreManager.getTrustStoreConfiguration(connectionType).password}" var="c">
                <c:set var="pwdTrustS2S" value="${pwdTrustS2S}${c}"/>
            </c:forEach>

            <table>
                <tbody>
                <tr>
                    <td><label for="loc-trust-s2s"><fmt:message key="ssl.certificates.store-management.file_label"/>:</label></td>
                    <td><input id="loc-trust-s2s" name="loc-trust-s2s" type="text" size="80" value="${webManager.XMPPServer.certificateStoreManager.getTrustStoreConfiguration(connectionType).file}"/></td>
                </tr>
                <tr>
                    <td><label for="pwd-trust-s2s"><fmt:message key="ssl.certificates.store-management.password_label"/>:</label></td>
                    <td><input id="pwd-trust-s2s" name="pwd-trust-s2s" type="password" size="30" value="${pwdTrustS2S}"/></td>
                </tr>
                <tr>
                    <td>&#160;</td>
                    <td><a href="security-truststore.jsp?connectionType=${connectionType}"><fmt:message key="ssl.certificates.store-management.manage"/></a></td>
                </tr>
                </tbody>
            </table>
        </c:otherwise>

    </c:choose>
</jsp:root>
