audit-policy.jsp 13.9 KB
Newer Older
Bill Lynch's avatar
Bill Lynch committed
1
<%--
Matt Tucker's avatar
Matt Tucker committed
2 3 4
  -	$RCSfile$
  -	$Revision$
  -	$Date$
Bill Lynch's avatar
Bill Lynch committed
5 6 7 8 9
  -
  - Copyright (C) 2004 Jive Software. All rights reserved.
  -
  - This software is published under the terms of the GNU Public License (GPL),
  - a copy of which is included in this distribution.
Matt Tucker's avatar
Matt Tucker committed
10
--%>
Bill Lynch's avatar
Bill Lynch committed
11

12
<%@ page import="org.jivesoftware.wildfire.audit.AuditManager,
Derek DeMoro's avatar
Derek DeMoro committed
13
                   org.jivesoftware.util.*,
14
                   java.util.*,
15 16
                 java.io.File,
                 org.xmpp.packet.JID,
17
                 org.jivesoftware.wildfire.user.UserNotFoundException"
Bill Lynch's avatar
Bill Lynch committed
18 19
    errorPage="error.jsp"
%>
20 21
<%@ page import="org.jivesoftware.wildfire.XMPPServer"%>
<%@ page import="org.jivesoftware.wildfire.user.UserManager"%>
Bill Lynch's avatar
Bill Lynch committed
22

23
<%@ taglib uri="http://java.sun.com/jstl/fmt_rt" prefix="fmt" %>
Bill Lynch's avatar
Bill Lynch committed
24

25 26 27 28 29 30 31 32 33 34 35
<jsp:useBean id="webManager" class="org.jivesoftware.util.WebManager"  />
<% webManager.init(request, response, session, application, out ); %>

<html>
    <head>
        <title><fmt:message key="audit.policy.title"/></title>
        <meta name="pageID" content="server-audit-policy"/>
        <meta name="helpPage" content="set_server_traffic_auditing_policy.html"/>
    </head>
    <body>

Matt Tucker's avatar
Matt Tucker committed
36

Derek DeMoro's avatar
Derek DeMoro committed
37

Bill Lynch's avatar
Bill Lynch committed
38
<%   // Get parameters:
Matt Tucker's avatar
Matt Tucker committed
39 40 41 42 43 44 45 46 47 48
    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");
    boolean auditXPath = ParamUtils.getBooleanParameter(request,"auditXPath");
    String newXpathQuery = ParamUtils.getParameter(request,"newXpathQuery");
    String[] xpathQuery = ParamUtils.getParameters(request,"xpathQuery");
    String maxCount = ParamUtils.getParameter(request,"maxCount");
    String maxSize = ParamUtils.getParameter(request,"maxSize");
49
    String logTimeout = ParamUtils.getParameter(request,"logTimeout");
50
    String logDir = ParamUtils.getParameter(request,"logDir");
51 52
    String ignore = ParamUtils.getParameter(request,"ignore");

Matt Tucker's avatar
Matt Tucker committed
53 54

    // Get an audit manager:
55
    AuditManager auditManager = XMPPServer.getInstance().getAuditManager();
Matt Tucker's avatar
Matt Tucker committed
56

57
    Map<String,String> errors = new HashMap<String,String>();
Matt Tucker's avatar
Matt Tucker committed
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
    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<xpathQuery.length; i++) {
            auditManager.removeXPath(xpathQuery[i]);
        }
        */
        try {
            auditManager.setMaxFileCount(Integer.parseInt(maxCount));
        } catch (Exception e){
            errors.put("maxCount","maxCount");
        }
        try {
            auditManager.setMaxFileSize(Integer.parseInt(maxSize));
        } catch (Exception e){
            errors.put("maxSize","maxSize");
        }
82 83 84 85 86
        try {
            auditManager.setLogTimeout(Integer.parseInt(logTimeout) * 1000);
        } catch (Exception e){
            errors.put("logTimeout","logTimeout");
        }
87 88 89 90 91 92 93 94 95 96 97
        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");
            }
        }
Matt Tucker's avatar
Matt Tucker committed
98
        if (errors.size() == 0){
99 100 101 102 103 104 105 106 107 108 109 110
            if (ignore == null){
                // remove all ignored users
                auditManager.setIgnoreList(new ArrayList<String>());
            }
            else {
                // Set the new ignore list
                Collection<String> newIgnoreList = new HashSet<String>(ignore.length());
                StringTokenizer tokenizer = new StringTokenizer(ignore, ", \t\n\r\f");
                while (tokenizer.hasMoreTokens()) {
                    String tok = tokenizer.nextToken();
                    String username = tok;
                    if (tok.contains("@")) {
111
                        if (tok.contains("@" + webManager.getServerInfo().getName())) {
112 113 114 115 116 117 118 119
                           username = new JID(tok).getNode();
                        }
                        else {
                            // Skip this JID since it belongs to a remote server
                            continue;
                        }
                    }
                    try {
120
                        webManager.getUserManager().getUser(username);
121 122 123 124 125 126 127 128
                        newIgnoreList.add(username);
                    }
                    catch (UserNotFoundException e){
                    }
                }
                auditManager.setIgnoreList(newIgnoreList);
            }
        // All done, redirect
Matt Tucker's avatar
Matt Tucker committed
129
        %>
Bill Lynch's avatar
Bill Lynch committed
130 131 132 133

    <div class="jive-success">
    <table cellpadding="0" cellspacing="0" border="0">
    <tbody>
134
        <tr><td class="jive-icon"><img src="images/success-16x16.gif" width="16" height="16" border="0" alt=""></td>
Bill Lynch's avatar
Bill Lynch committed
135
        <td class="jive-icon-label">
136
        <fmt:message key="audit.policy.settings.saved_successfully" />
Bill Lynch's avatar
Bill Lynch committed
137 138 139 140 141
        </td></tr>
    </tbody>
    </table>
    </div><br>

Matt Tucker's avatar
Matt Tucker committed
142 143 144 145 146 147 148 149 150 151 152 153 154
        <%
        }
    }

    // Set page vars
    if (errors.size() == 0) {
        auditEnabled = auditManager.isEnabled();
        auditMessages = auditManager.isAuditMessage();
        auditPresence = auditManager.isAuditPresence();
        auditIQ = auditManager.isAuditIQ();
        auditXPath = auditManager.isAuditXPath();
        maxCount = Integer.toString(auditManager.getMaxFileCount());
        maxSize = Integer.toString(auditManager.getMaxFileSize());
155
        logTimeout = Integer.toString(auditManager.getLogTimeout() / 1000);
156
        logDir = auditManager.getLogDir();
157 158 159 160 161 162 163 164 165 166
        StringBuilder ignoreList = new StringBuilder();
        for (String username : auditManager.getIgnoreList()) {
            if (ignoreList.length() == 0) {
                ignoreList.append(username);
            }
            else {
                ignoreList.append(", ").append(username);
            }
        }
        ignore = ignoreList.toString();
Matt Tucker's avatar
Matt Tucker committed
167 168 169
    }
%>

Bill Lynch's avatar
Bill Lynch committed
170
<p>
171
<fmt:message key="title" />
172
<fmt:message key="audit.policy.title_info" />
Bill Lynch's avatar
Bill Lynch committed
173
</p>
Matt Tucker's avatar
Matt Tucker committed
174

175
<form action="audit-policy.jsp" name="f">
Matt Tucker's avatar
Matt Tucker committed
176

Bill Lynch's avatar
Bill Lynch committed
177
<fieldset>
178
    <legend><fmt:message key="audit.policy.policytitle" /></legend>
Bill Lynch's avatar
Bill Lynch committed
179 180 181
    <div>
    <table cellpadding="3" cellspacing="0" border="0" width="100%">
    <tbody>
Matt Tucker's avatar
Matt Tucker committed
182
        <tr valign="middle">
Matt Tucker's avatar
Matt Tucker committed
183
            <td width="1%" nowrap>
Bill Lynch's avatar
Bill Lynch committed
184 185
                <input type="radio" name="auditEnabled" value="false" id="rb01"
                 <%= (!auditEnabled ? "checked" : "") %>>
Matt Tucker's avatar
Matt Tucker committed
186 187
            </td>
            <td width="99%">
Bill Lynch's avatar
Bill Lynch committed
188
                <label for="rb01">
189
                <b><fmt:message key="audit.policy.label_disable_auditing" /></b> <fmt:message key="audit.policy.label_disable_auditing_info" />
Matt Tucker's avatar
Matt Tucker committed
190 191 192
                </label>
            </td>
        </tr>
Matt Tucker's avatar
Matt Tucker committed
193
        <tr valign="middle">
Matt Tucker's avatar
Matt Tucker committed
194
            <td width="1%" nowrap>
Bill Lynch's avatar
Bill Lynch committed
195 196
                <input type="radio" name="auditEnabled" value="true" id="rb02"
                 <%= (auditEnabled ? "checked" : "") %>>
Matt Tucker's avatar
Matt Tucker committed
197 198
            </td>
            <td width="99%">
Bill Lynch's avatar
Bill Lynch committed
199
                <label for="rb02">
200
                <b><fmt:message key="audit.policy.label_enable_auditing" /></b> <fmt:message key="audit.policy.label_enable_auditing_info" />
Matt Tucker's avatar
Matt Tucker committed
201 202 203 204 205 206 207 208
                </label>
            </td>
        </tr>
        <tr valign="top">
            <td width="1%" nowrap>
                &nbsp;
            </td>
            <td width="99%">
Bill Lynch's avatar
Bill Lynch committed
209
                <table cellpadding="3" cellspacing="0" border="0" width="100%">
210 211 212 213 214
                <tr valign="top">
                    <td width="1%" nowrap class="c1">
                        <fmt:message key="audit.policy.log_directory" />
                    </td>
                    <td width="99%">
Matt Tucker's avatar
Matt Tucker committed
215
                        <input type="text" size="50" maxlength="150" name="logDir"
216 217 218 219 220 221 222 223 224 225 226 227
                         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>
Bill Lynch's avatar
Bill Lynch committed
228 229
                <tr valign="top">
                    <td width="1%" nowrap class="c1">
230
                        <fmt:message key="audit.policy.maxfile_size" />
Matt Tucker's avatar
Matt Tucker committed
231
                    </td>
Bill Lynch's avatar
Bill Lynch committed
232 233 234
                    <td width="99%">
                        <input type="text" size="15" maxlength="50" name="maxSize"
                         value="<%= ((maxSize != null) ? maxSize : "") %>">
Matt Tucker's avatar
Matt Tucker committed
235

Bill Lynch's avatar
Bill Lynch committed
236
                    <%  if (errors.get("maxSize") != null) { %>
Matt Tucker's avatar
Matt Tucker committed
237

Bill Lynch's avatar
Bill Lynch committed
238
                        <span class="jive-error-text">
239
                        <fmt:message key="audit.policy.validnumber" />
Bill Lynch's avatar
Bill Lynch committed
240
                        </span>
Matt Tucker's avatar
Matt Tucker committed
241

Bill Lynch's avatar
Bill Lynch committed
242
                    <%  } %>
Matt Tucker's avatar
Matt Tucker committed
243

Bill Lynch's avatar
Bill Lynch committed
244 245 246 247
                    </td>
                </tr>
                <tr valign="top">
                    <td width="1%" nowrap class="c1">
248
                        <fmt:message key="audit.policy.maxfile_number" />
Bill Lynch's avatar
Bill Lynch committed
249 250 251 252
                    </td>
                    <td width="99%">
                        <input type="text" size="15" maxlength="50" name="maxCount"
                         value="<%= ((maxCount != null) ? maxCount : "") %>">
Matt Tucker's avatar
Matt Tucker committed
253

Bill Lynch's avatar
Bill Lynch committed
254
                        <%  if (errors.get("maxCount") != null) { %>
Matt Tucker's avatar
Matt Tucker committed
255

Bill Lynch's avatar
Bill Lynch committed
256
                            <span class="jive-error-text">
257
                            <fmt:message key="audit.policy.validnumber" />
Bill Lynch's avatar
Bill Lynch committed
258
                            </span>
Matt Tucker's avatar
Matt Tucker committed
259

Bill Lynch's avatar
Bill Lynch committed
260
                        <%  } %>
Matt Tucker's avatar
Matt Tucker committed
261

Bill Lynch's avatar
Bill Lynch committed
262 263
                    </td>
                </tr>
264 265
                <tr valign="top">
                    <td width="1%" nowrap class="c1">
266
                        <fmt:message key="audit.policy.flush_interval" />
267 268 269 270 271 272 273 274
                    </td>
                    <td width="99%">
                        <input type="text" size="15" maxlength="50" name="logTimeout"
                         value="<%= ((logTimeout != null) ? logTimeout : "") %>">

                    <%  if (errors.get("logTimeout") != null) { %>

                        <span class="jive-error-text">
275
                        <fmt:message key="audit.policy.validnumber" />
276 277 278 279 280 281
                        </span>

                    <%  } %>

                    </td>
                </tr>
Bill Lynch's avatar
Bill Lynch committed
282 283
                <tr valign="top">
                    <td width="1%" nowrap class="c1">
284
                        <fmt:message key="audit.policy.packet_audit" />
Bill Lynch's avatar
Bill Lynch committed
285 286 287 288 289 290 291 292 293 294 295 296
                    </td>
                    <td width="99%">

                        <table cellpadding="4" cellspacing="0" border="0" width="100%">
                        <tr valign="top">
                            <td width="1%" nowrap>
                                <input type="checkbox" name="auditMessages" id="cb01"
                                 onclick="this.form.auditEnabled[1].checked=true;"
                                 <%= (auditMessages ? "checked" : "") %>>
                            </td>
                            <td width="99%">
                                <label for="cb01">
297
                                <b><fmt:message key="audit.policy.label_audit_messenge_packets" /></b>
Bill Lynch's avatar
Bill Lynch committed
298 299 300 301 302 303 304 305 306 307 308
                                </label>
                            </td>
                        </tr>
                        <tr valign="top">
                            <td width="1%" nowrap>
                                <input type="checkbox" name="auditPresence" id="cb02"
                                 onclick="this.form.auditEnabled[1].checked=true;"
                                 <%= (auditPresence ? "checked" : "") %>>
                            </td>
                            <td width="99%">
                                <label for="cb02">
309
                                <b><fmt:message key="audit.policy.label_audit_presence_packets" /></b>
Bill Lynch's avatar
Bill Lynch committed
310 311 312 313 314 315 316 317 318 319 320
                                </label>
                            </td>
                        </tr>
                        <tr valign="top">
                            <td width="1%" nowrap>
                                <input type="checkbox" name="auditIQ" id="cb03"
                                 onclick="this.form.auditEnabled[1].checked=true;"
                                 <%= (auditIQ ? "checked" : "") %>>
                            </td>
                            <td width="99%">
                                <label for="cb03">
321
                                <b><fmt:message key="audit.policy.label_audit_iq_packets" /></b>
Bill Lynch's avatar
Bill Lynch committed
322 323 324 325 326 327
                                </label>
                            </td>
                        </tr>
                        </table>
                    </td>
                </tr>
328 329 330 331 332
                <tr valign="top">
                    <td width="1%" nowrap class="c1">
                        <fmt:message key="audit.policy.ignore" />
                    </td>
                    <td width="99%">
Matt Tucker's avatar
Matt Tucker committed
333 334
                        <textarea name="ignore" cols="40" rows="3" wrap="virtual"><%= ((ignore != null) ? ignore : "") %></textarea>
                        <%  if (errors.get("ignore") != null) { %>
335

Matt Tucker's avatar
Matt Tucker committed
336 337 338
                            <span class="jive-error-text">
                            <fmt:message key="audit.policy.validignore" />
                            </span>
339

Matt Tucker's avatar
Matt Tucker committed
340
                        <%  } %>
341 342
                    </td>
                </tr>
Matt Tucker's avatar
Matt Tucker committed
343 344 345
                </table>
            </td>
        </tr>
Bill Lynch's avatar
Bill Lynch committed
346 347
    </tbody>
    </table>
Matt Tucker's avatar
Matt Tucker committed
348 349 350
    <table border="0">
        <tr valign="top">
            <td width="1%" nowrap class="c1">
351
                <fmt:message key="audit.policy.queued_packets" />
Matt Tucker's avatar
Matt Tucker committed
352 353 354 355 356 357
            </td>
            <td width="99%">
                 <%= auditManager.getAuditor().getQueuedPacketsNumber() %>
            </td>
        </tr>
    </table>
Bill Lynch's avatar
Bill Lynch committed
358 359
    </div>
</fieldset>
Matt Tucker's avatar
Matt Tucker committed
360

Bill Lynch's avatar
Bill Lynch committed
361
<br><br>
Matt Tucker's avatar
Matt Tucker committed
362

363
<input type="submit" name="update" value="<fmt:message key="global.save_settings" />">
Matt Tucker's avatar
Matt Tucker committed
364 365 366

</form>

367 368
    </body>
</html>