%@ page contentType="text/html; charset=UTF-8" %>
<%--
- Copyright (C) 2016-2025 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="org.jivesoftware.util.ParamUtils,
org.jivesoftware.util.CookieUtils,
org.jivesoftware.openfire.XMPPServer,
org.jivesoftware.openfire.audit.AuditManager,
org.jivesoftware.openfire.user.UserNotFoundException,
org.jivesoftware.util.StringUtils,
org.xmpp.packet.JID,
java.io.File"
errorPage="error.jsp"
%>
<%@ page import="java.util.*"%>
<%@ page import="java.time.Duration" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="admin" prefix="admin" %>
<% webManager.init(request, response, session, application, out ); %>
<% // Get parameters:
boolean update = request.getParameter("update") != null;
boolean auditEnabled = ParamUtils.getBooleanParameter(request,"auditEnabled");
boolean auditMessages = ParamUtils.getBooleanParameter(request,"auditMessages");
boolean auditPresence = ParamUtils.getBooleanParameter(request,"auditPresence");
boolean auditIQ = ParamUtils.getBooleanParameter(request,"auditIQ");
String maxTotalSize = ParamUtils.getParameter(request,"maxTotalSize");
String maxFileSize = ParamUtils.getParameter(request,"maxFileSize");
String maxDays = ParamUtils.getParameter(request,"maxDays");
String logTimeout = ParamUtils.getParameter(request,"logTimeout");
String logDir = ParamUtils.getParameter(request,"logDir");
String ignore = ParamUtils.getParameter(request,"ignore");
// Get an audit manager:
AuditManager auditManager = XMPPServer.getInstance().getAuditManager();
Map errors = new HashMap<>();
Cookie csrfCookie = CookieUtils.getCookie(request, "csrf");
String csrfParam = ParamUtils.getParameter(request, "csrf");
boolean csrfStatus = true;
if (update) {
if (csrfCookie == null || csrfParam == null || !csrfCookie.getValue().equals(csrfParam)) {
update = false;
errors.put("csrf", "csrf");
csrfStatus = false;
}
}
csrfParam = StringUtils.randomString(16);
CookieUtils.setCookie(request, response, "csrf", csrfParam, -1);
pageContext.setAttribute("csrf", csrfParam);
if (update) {
auditManager.setEnabled(auditEnabled);
auditManager.setAuditMessage(auditMessages);
auditManager.setAuditPresence(auditPresence);
auditManager.setAuditIQ(auditIQ);
/*
auditManager.setAuditXPath(auditXPath);
if (newXpathQuery != null) {
auditManager.addXPath(newXpathQuery);
}
for (int i=0; i());
}
else {
// Set the new ignore list
Collection newIgnoreList = new HashSet<>(ignore.length());
StringTokenizer tokenizer = new StringTokenizer(ignore, ", \t\n\r\f");
while (tokenizer.hasMoreTokens()) {
String tok = tokenizer.nextToken();
String username = tok;
if (tok.contains("@")) {
if (tok.contains("@" + webManager.getServerInfo().getXMPPDomain())) {
username = new JID(tok).getNode();
}
else {
// Skip this JID since it belongs to a remote server
continue;
}
}
try {
webManager.getUserManager().getUser(username);
newIgnoreList.add(username);
}
catch (UserNotFoundException e){
}
}
auditManager.setIgnoreList(newIgnoreList);
}
// Log the event
// TODO: Should probably log more here
webManager.logEvent("updated stanza audit policy", null);
// All done, redirect
%>
<%
}
else if (!csrfStatus) {
%>
<%
}
}
// Set page vars
if (errors.isEmpty()) {
auditEnabled = auditManager.isEnabled();
auditMessages = auditManager.isAuditMessage();
auditPresence = auditManager.isAuditPresence();
auditIQ = auditManager.isAuditIQ();
maxTotalSize = Integer.toString(auditManager.getMaxTotalSize());
maxFileSize = Integer.toString(auditManager.getMaxFileSize());
maxDays = Long.toString(auditManager.getRetention().toDays());
logTimeout = Long.toString(auditManager.getLogTimeout().toSeconds());
logDir = auditManager.getLogDir();
StringBuilder ignoreList = new StringBuilder();
for (String username : auditManager.getIgnoreList()) {
if (ignoreList.isEmpty()) {
ignoreList.append(username);
}
else {
ignoreList.append(", ").append(username);
}
}
ignore = ignoreList.toString();
}
%>