%@ page contentType="text/html; charset=UTF-8" %>
<%--
~ Copyright (C) 2017-2023 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 import="java.util.*,
org.jivesoftware.util.*"
errorPage="error.jsp"
%>
<%@ page import="org.xmpp.packet.JID" %>
<%@ page import="org.jivesoftware.openfire.XMPPServer" %>
<%@ taglib uri="admin" prefix="admin" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<% webManager.init(request, response, session, application, out ); %>
<%
Map errors = new HashMap<>();
Cookie csrfCookie = CookieUtils.getCookie(request, "csrf");
String csrfParam = ParamUtils.getParameter(request, "csrf");
String s2sTestingDomain = ParamUtils.getParameter( request, "server2server-testing-domain" );
boolean s2sTest = request.getParameter("s2s-test") != null && s2sTestingDomain != null;
if (s2sTest) {
if (csrfCookie == null || csrfParam == null || !csrfCookie.getValue().equals(csrfParam)) {
s2sTest = false;
errors.put("csrf", "CSRF Failure!");
}
}
csrfParam = StringUtils.randomString(15);
CookieUtils.setCookie(request, response, "csrf", csrfParam, -1);
pageContext.setAttribute("csrf", csrfParam);
// Validate domain input;
JID domain = null;
if (s2sTest) {
try {
domain = new JID(s2sTestingDomain);
} catch (IllegalArgumentException e) {
// Be forgiving for some common copy/paste mistakes.
String parsedValue = s2sTestingDomain.trim();
if (parsedValue.startsWith("http://")) {
parsedValue = parsedValue.substring("http://".length());
}
if (parsedValue.startsWith("https://")) {
parsedValue = parsedValue.substring("https://".length());
}
if (parsedValue.endsWith("/")) {
parsedValue = parsedValue.substring(0, parsedValue.length() - 1);
}
try {
domain = new JID(parsedValue);
} catch (IllegalArgumentException e2) {
errors.put("s2sTestingDomain", "invalid");
}
}
}
if (XMPPServer.getInstance().isLocal(domain) || XMPPServer.getInstance().matchesComponent(domain)) {
errors.put("s2sTestingDomain", "ours");
}
if (errors.isEmpty() && s2sTest)
{
final Map results = new S2STestService(domain).run();
pageContext.setAttribute("s2sDomain", domain.getDomain());
pageContext.setAttribute("s2sTest", true);
pageContext.setAttribute("stanzas", results.get("stanzas"));
pageContext.setAttribute("logs", results.get("logs"));
pageContext.setAttribute("certs", results.get("certs"));
} else {
pageContext.setAttribute("s2sDomain", s2sTestingDomain);
pageContext.setAttribute("s2sTest", false);
}
pageContext.setAttribute("errors", errors);
%>