Commit 9e4773b7 authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gaston

Parameterized the folder to save the audit files.


git-svn-id: http://svn.igniterealtime.org/svn/repos/messenger/trunk@1627 b35dd754-fafc-0310-a699-88a17e54d16e
parent 1f147968
......@@ -106,6 +106,20 @@ public interface AuditManager {
*/
void setLogTimeout(int logTimeout);
/**
* Returns the absolute path to the directory where the audit log files will be saved.
*
* @return the absolute path to the directory where the audit log files will be saved.
*/
String getLogDir();
/**
* Sets the absolute path to the directory where the audit log files will be saved.
*
* @param logDir the absolute path to the directory where the audit log files will be saved.
*/
void setLogDir(String logDir);
/**
* <p>Determines if the server will audit all message packets.</p>
* <p>This is a speed optimization and convenience for logging all message packets
......
......@@ -21,6 +21,7 @@ import org.jivesoftware.messenger.interceptor.PacketInterceptor;
import org.jivesoftware.util.JiveGlobals;
import org.xmpp.packet.Packet;
import java.io.File;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
......@@ -40,6 +41,7 @@ public class AuditManagerImpl extends BasicModule implements AuditManager {
private int maxSize;
private int maxCount;
private int logTimeout;
private String logDir;
private static final int MAX_FILE_SIZE = 10;
private static final int MAX_FILE_COUNT = 10;
private static final int DEFAULT_LOG_TIMEOUT = 120000;
......@@ -92,6 +94,16 @@ public class AuditManagerImpl extends BasicModule implements AuditManager {
JiveGlobals.setProperty("xmpp.audit.logtimeout", Integer.toString(logTimeout));
}
public String getLogDir() {
return logDir;
}
public void setLogDir(String logDir) {
this.logDir = logDir;
auditor.setLogDir(logDir);
JiveGlobals.setProperty("xmpp.audit.logdir", logDir);
}
public int getMaxFileCount() {
return maxCount;
}
......@@ -150,7 +162,7 @@ public class AuditManagerImpl extends BasicModule implements AuditManager {
private void saveXPath() {
String[] filters = new String[xpath.size()];
filters = (String[])xpath.toArray(filters);
filters = (String[]) xpath.toArray(filters);
// TODO: save XPath values!
}
......@@ -177,9 +189,12 @@ public class AuditManagerImpl extends BasicModule implements AuditManager {
maxSize = JiveGlobals.getIntProperty("xmpp.audit.maxsize", MAX_FILE_SIZE);
maxCount = JiveGlobals.getIntProperty("xmpp.audit.maxcount", MAX_FILE_COUNT);
logTimeout = JiveGlobals.getIntProperty("xmpp.audit.logtimeout", DEFAULT_LOG_TIMEOUT);
logDir = JiveGlobals.getProperty("xmpp.audit.logdir", JiveGlobals.getHomeDirectory() +
File.separator + "logs");
auditor = new AuditorImpl(this);
auditor.setMaxValues(maxSize, maxCount);
auditor.setLogTimeout(logTimeout);
auditor.setLogDir(logDir);
interceptor = new AuditorInterceptor();
if (enabled) {
......
......@@ -13,11 +13,9 @@ package org.jivesoftware.messenger.audit.spi;
import org.dom4j.DocumentFactory;
import org.dom4j.Element;
import org.jivesoftware.util.XMLWriter;
import org.jivesoftware.messenger.Session;
import org.jivesoftware.messenger.audit.AuditManager;
import org.jivesoftware.messenger.audit.Auditor;
import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.util.LocaleUtils;
import org.jivesoftware.util.Log;
import org.xmpp.packet.IQ;
......@@ -42,6 +40,10 @@ public class AuditorImpl implements Auditor {
private long maxCount;
private int logTimeout;
private boolean closed = false;
/**
* Directoty (absolute path) where the audit files will be saved.
*/
private String logDir;
/**
* Queue that holds the audited packets that will be later saved to an XML file.
......@@ -130,6 +132,10 @@ public class AuditorImpl implements Auditor {
}
public void setLogDir(String logDir) {
this.logDir = logDir;
}
public int getQueuedPacketsNumber() {
return logQueue.size();
}
......@@ -139,8 +145,7 @@ public class AuditorImpl implements Auditor {
int i;
// Find the next available log file name
for (i = 0; maxCount < 1 || i < maxCount; i++) {
currentAuditFile = new File(JiveGlobals.getHomeDirectory() + File.separator + "logs",
"jive.audit-" + i + ".log");
currentAuditFile = new File(logDir, "jive.audit-" + i + ".log");
if (!currentAuditFile.exists()) {
break;
}
......@@ -159,11 +164,9 @@ public class AuditorImpl implements Auditor {
// Rotate the files
for (i--; i >= 0; i--) {
String previousName = "jive.audit-" + i + ".log";
File previousFile = new File(JiveGlobals.getHomeDirectory() + File.separator + "logs",
previousName);
File previousFile = new File(logDir, previousName);
previousFile.renameTo(currentAuditFile);
currentAuditFile = new File(JiveGlobals.getHomeDirectory() + File.separator + "logs",
previousName);
currentAuditFile = new File(logDir, previousName);
}
}
......
......@@ -12,7 +12,8 @@
<%@ page import="org.jivesoftware.messenger.audit.AuditManager,
org.jivesoftware.admin.*,
org.jivesoftware.util.*,
java.util.*"
java.util.*,
java.io.File"
errorPage="error.jsp"
%>
......@@ -44,6 +45,7 @@
String maxCount = ParamUtils.getParameter(request,"maxCount");
String maxSize = ParamUtils.getParameter(request,"maxSize");
String logTimeout = ParamUtils.getParameter(request,"logTimeout");
String logDir = ParamUtils.getParameter(request,"logDir");
// Get an audit manager:
AuditManager auditManager = admin.getXMPPServer().getAuditManager();
......@@ -78,6 +80,17 @@
} catch (Exception e){
errors.put("logTimeout","logTimeout");
}
if (logDir == null || logDir.trim().length() == 0) {
errors.put("logDir","logDir");
}
else {
if (new File(logDir).isDirectory()) {
auditManager.setLogDir(logDir);
}
else {
errors.put("logDir","logDir");
}
}
// All done, redirect
if (errors.size() == 0){
%>
......@@ -107,6 +120,7 @@
maxCount = Integer.toString(auditManager.getMaxFileCount());
maxSize = Integer.toString(auditManager.getMaxFileSize());
logTimeout = Integer.toString(auditManager.getLogTimeout() / 1000);
logDir = auditManager.getLogDir();
}
%>
......@@ -150,6 +164,24 @@
</td>
<td width="99%">
<table cellpadding="3" cellspacing="0" border="0" width="100%">
<tr valign="top">
<td width="1%" nowrap class="c1">
<fmt:message key="audit.policy.log_directory" />
</td>
<td width="99%">
<input type="text" size="30" maxlength="150" name="logDir"
value="<%= ((logDir != null) ? logDir : "") %>">
<% if (errors.get("logDir") != null) { %>
<span class="jive-error-text">
<fmt:message key="audit.policy.valid_log_directory" />
</span>
<% } %>
</td>
</tr>
<tr valign="top">
<td width="1%" nowrap class="c1">
<fmt:message key="audit.policy.maxfile_size" />
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment