server-properties.jsp 11.6 KB
Newer Older
Bill Lynch's avatar
Bill Lynch committed
1 2 3 4
<%--
  -	$Revision$
  -	$Date$
  -
5
  - Copyright (C) 2004-2008 Jive Software. All rights reserved.
Bill Lynch's avatar
Bill Lynch committed
6
  -
7 8 9 10 11 12 13 14 15 16 17
  - 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.
Bill Lynch's avatar
Bill Lynch committed
18 19
--%>

20
<%@ page import="java.util.*,
Bill Lynch's avatar
Bill Lynch committed
21 22
                 org.jivesoftware.util.*,
                 org.jivesoftware.util.ParamUtils,
23
                 org.jivesoftware.util.JiveGlobals"
Bill Lynch's avatar
Bill Lynch committed
24 25
    errorPage="error.jsp"
%>
26
<%@ taglib uri="http://java.sun.com/jstl/fmt_rt" prefix="fmt" %>
Bill Lynch's avatar
Bill Lynch committed
27 28
<jsp:useBean id="pageinfo" scope="request" class="org.jivesoftware.admin.AdminPageBean" />

29 30 31
<jsp:useBean id="webManager" class="org.jivesoftware.util.WebManager"  />
<% webManager.init(request, response, session, application, out ); %>

Bill Lynch's avatar
Bill Lynch committed
32 33 34 35 36 37 38 39 40 41 42 43 44 45
<%!
    /**
     * Make sure the String can wrap at 80 chars.
     *
     * @param str the string.
     * @return a wrappable string.
     */
    String wrappableString(String str) {
        if (str.length() <= 60) {
            return str;
        }
        int count = 0;
        StringBuffer buf = new StringBuffer();
        char [] strChars = str.toCharArray();
46 47
        for (char strChar : strChars) {
            if (Character.isWhitespace(strChar)) {
Bill Lynch's avatar
Bill Lynch committed
48 49 50
                count = 0;
            }
            count++;
51
            buf.append(strChar);
Bill Lynch's avatar
Bill Lynch committed
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
            if (count >= 60) {
                buf.append(" ");
                count = 0;
            }
        }
        return buf.toString();
    }

 %>

<%
    String propName = ParamUtils.getParameter(request,"propName");
    String propValue = ParamUtils.getParameter(request,"propValue",true);
    boolean edit = ParamUtils.getBooleanParameter(request,"edit");
    boolean save = request.getParameter("save") != null;
    boolean delete = ParamUtils.getBooleanParameter(request,"del");

    if (request.getParameter("cancel") != null) {
        response.sendRedirect("server-properties.jsp");
        return;
    }

    if (delete) {
        if (propName != null) {
            JiveGlobals.deleteProperty(propName);
77 78
            // Log the event
            webManager.logEvent("deleted server property "+propName, null);
Bill Lynch's avatar
Bill Lynch committed
79 80 81 82 83
            response.sendRedirect("server-properties.jsp?deletesuccess=true");
            return;
        }
    }

84
    Map<String, String> errors = new HashMap<String, String>();
Bill Lynch's avatar
Bill Lynch committed
85
    if (save) {
86
        if (propName == null || "".equals(propName.trim()) || propName.startsWith("\"")) {
Bill Lynch's avatar
Bill Lynch committed
87 88 89 90 91 92 93 94 95 96
            errors.put("propName","");
        }
        if (propValue == null) {
            errors.put("propValue","");
        }
        else if (propValue.length() > 4000) {
            errors.put("propValueLength","");
        }
        if (errors.size() == 0) {
            JiveGlobals.setProperty(propName, propValue);
97 98
            // Log the event
            webManager.logEvent("set server property "+propName, propName+" = "+propValue);
Bill Lynch's avatar
Bill Lynch committed
99 100 101 102 103
            response.sendRedirect("server-properties.jsp?success=true");
            return;
        }
    }

104 105 106
    List<String> properties = JiveGlobals.getPropertyNames();
    Collections.sort(properties, new Comparator<String>() {
        public int compare(String s1, String s2) {
Bill Lynch's avatar
Bill Lynch committed
107 108 109 110 111 112 113 114 115
            return s1.toLowerCase().compareTo(s2.toLowerCase());
        }
    });

    if (edit) {
        propValue = JiveGlobals.getProperty(propName);
    }
%>

116 117 118 119 120 121 122
<html>
    <head>
        <title><fmt:message key="server.properties.title"/></title>
        <meta name="pageID" content="server-props"/>
        <meta name="helpPage" content="manage_system_properties.html"/>
    </head>
    <body>
Bill Lynch's avatar
Bill Lynch committed
123 124

<p>
125
<fmt:message key="server.properties.info" />
Bill Lynch's avatar
Bill Lynch committed
126 127
</p>

128
<p><b><fmt:message key="server.properties.system" /></b></p>
Bill Lynch's avatar
Bill Lynch committed
129 130 131 132 133 134

<%  if (errors.size() > 0) { %>

    <div class="jive-error">
    <table cellpadding="0" cellspacing="0" border="0">
    <tbody>
135
        <tr><td class="jive-icon"><img src="images/error-16x16.gif" width="16" height="16" border="0" alt=""></td>
Bill Lynch's avatar
Bill Lynch committed
136
        <td class="jive-icon-label">
137
        <fmt:message key="server.properties.error" />
Bill Lynch's avatar
Bill Lynch committed
138 139 140 141 142 143 144 145 146 147
        </td></tr>
    </tbody>
    </table>
    </div><br>

<%  } else if ("true".equals(request.getParameter("success"))) { %>

    <div class="jive-success">
    <table cellpadding="0" cellspacing="0" border="0">
    <tbody>
148
        <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
149
        <td class="jive-icon-label">
150
        <fmt:message key="server.properties.saved" />
Bill Lynch's avatar
Bill Lynch committed
151 152 153 154 155 156 157 158 159 160
        </td></tr>
    </tbody>
    </table>
    </div><br>

<%  } else if ("true".equals(request.getParameter("deletesuccess"))) { %>

    <div class="jive-success">
    <table cellpadding="0" cellspacing="0" border="0">
    <tbody>
161
        <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
162
        <td class="jive-icon-label">
163
        <fmt:message key="server.properties.deleted" />
Bill Lynch's avatar
Bill Lynch committed
164 165 166 167 168 169 170 171 172 173 174 175
        </td></tr>
    </tbody>
    </table>
    </div><br>

<%  } %>

<%  if (edit) { %>

    <div class="jive-info">
    <table cellpadding="0" cellspacing="0" border="0">
    <tbody>
176
        <tr><td class="jive-icon"><img src="images/info-16x16.gif" width="16" height="16" border="0" alt=""></td>
Bill Lynch's avatar
Bill Lynch committed
177
        <td class="jive-icon-label">
178
        <fmt:message key="server.properties.edit_property" />
Bill Lynch's avatar
Bill Lynch committed
179 180 181 182 183 184 185 186 187 188 189 190
        </td></tr>
    </tbody>
    </table>
    </div><br>

<%  } %>

<%  if (request.getParameter("delerror") != null) { %>

    <div class="jive-error">
    <table cellpadding="0" cellspacing="0" border="0">
    <tbody>
191
        <tr><td class="jive-icon"><img src="images/error-16x16.gif" width="16" height="16" border="0" alt=""></td>
Bill Lynch's avatar
Bill Lynch committed
192
        <td class="jive-icon-label">
193
        <fmt:message key="server.properties.error_deleting" />
Bill Lynch's avatar
Bill Lynch committed
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238
        </td></tr>
    </tbody>
    </table>
    </div><br>

<%  } %>

<script language="JavaScript" type="text/javascript">
function doedit(propName) {
    document.propform.propName.value = propName;
    document.propform.edit.value = 'true';
    document.propform.action = document.propform.action + '#edit';
    document.propform.submit();
}
function dodelete(propName) {
    var dodelete = confirm('Are you sure you want to delete this property?');
    if (dodelete) {
        document.propform.propName.value = propName;
        document.propform.del.value = 'true';
        document.propform.submit();
        return true;
    }
    else {
        return false;
    }
}
</script>

<form action="server-properties.jsp" method="post" name="propform">
<input type="hidden" name="edit" value="">
<input type="hidden" name="del" value="">
<input type="hidden" name="propName" value="">

<style type="text/css">
.hidebox {
    text-overflow : ellipsis;
    overflow : hidden;
    white-space : nowrap;
}
</style>

<div class="jive-table">
<table cellpadding="0" cellspacing="0" border="0" width="100%">
<thead>
    <tr>
239 240 241
        <th nowrap><fmt:message key="server.properties.name" /></th>
        <th nowrap><fmt:message key="server.properties.value" /></th>
        <th style="text-align:center;"><fmt:message key="server.properties.edit" /></th>
242
        <th style="text-align:center;"><fmt:message key="global.delete" /></th>
Bill Lynch's avatar
Bill Lynch committed
243 244 245 246 247 248 249 250
    </tr>
</thead>
<tbody>

    <%  if (properties.size() == 0) { %>

        <tr>
            <td colspan="4">
251
                <fmt:message key="server.properties.no_property" />
Bill Lynch's avatar
Bill Lynch committed
252 253 254 255 256
            </td>
        </tr>

    <%  } %>

257 258 259
    <% for (String n : properties) {
        String v = JiveGlobals.getProperty(n);
        v = StringUtils.replace(StringUtils.escapeHTMLTags(v), "\n", "<br>");
Bill Lynch's avatar
Bill Lynch committed
260
    %>
261
    <tr class="<%= (n.equals(propName) ? "hilite" : "") %>">
Bill Lynch's avatar
Bill Lynch committed
262

263 264
        <td>
            <div class="hidebox" style="width:200px;">
Bill Lynch's avatar
Bill Lynch committed
265 266 267
                <span title="<%= StringUtils.escapeHTMLTags(n) %>">
                <%= StringUtils.escapeHTMLTags(n) %>
                </span>
268 269 270 271
            </div>
        </td>
        <td>
            <div class="hidebox" style="width:300px;">
272
                <% if (n.toLowerCase().indexOf("passwd") > -1 || 
273 274
                       n.toLowerCase().indexOf("password") > -1 ||
                       n.toLowerCase().indexOf("cookiekey") > -1) { %>
275 276 277 278 279 280
                <span style="color:#999;"><i>hidden</i></span>
                <% } else { %>
                <span title="<%= ("".equals(v) ? "&nbsp;" : v) %>"><%= ("".equals(v) ? "&nbsp;" : v) %></span>
                <% } %>
            </div>
        </td>
281
        <td align="center"><a href="#" onclick="doedit('<%= StringUtils.replace(StringUtils.escapeHTMLTags(n),"'","''") %>');"
282 283
                ><img src="images/edit-16x16.gif" width="16" height="16"
                      alt="<fmt:message key="server.properties.alt_edit" />" border="0"></a
Bill Lynch's avatar
Bill Lynch committed
284
                >
285
        </td>
286
        <td align="center"><a href="#" onclick="return dodelete('<%= StringUtils.replace(StringUtils.escapeHTMLTags(n),"'","''") %>');"
287 288
                ><img src="images/delete-16x16.gif" width="16" height="16"
                      alt="<fmt:message key="server.properties.alt_delete" />" border="0"></a
Bill Lynch's avatar
Bill Lynch committed
289
                >
290 291
        </td>
    </tr>
Bill Lynch's avatar
Bill Lynch committed
292

293
    <% } %>
Bill Lynch's avatar
Bill Lynch committed
294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311

</tbody>
</table>
</div>

</form>

<br><br>

<a name="edit"></a>
<form action="server-properties.jsp" method="post" name="editform">

<div class="jive-table">
<table cellpadding="0" cellspacing="0" border="0" width="100%">
<thead>
    <tr>
        <th colspan="2">
            <%  if (edit) { %>
312
                <fmt:message key="server.properties.edit_property_title" />
Bill Lynch's avatar
Bill Lynch committed
313
            <%  } else { %>
314
                <fmt:message key="server.properties.new_property" />
Bill Lynch's avatar
Bill Lynch committed
315 316 317 318 319 320 321
            <%  } %>
        </th>
    </tr>
</thead>
<tbody>
    <tr valign="top">
        <td>
322
            <fmt:message key="server.properties.name" />:
Bill Lynch's avatar
Bill Lynch committed
323 324 325 326 327 328 329 330 331 332 333 334 335
        </td>
        <td>
            <%  if (edit) { %>

                <input type="hidden" name="propName" value="<%= StringUtils.escapeHTMLTags(propName) %>">
                <%= StringUtils.escapeHTMLTags(propName) %>

            <%  } else { %>

                <input type="text" name="propName" size="40" maxlength="100" value="<%= (propName != null ? StringUtils.escapeHTMLTags(propName) : "") %>">

                <%  if (errors.containsKey("propName")) { %>

336
                    <br><span class="jive-error-text"><fmt:message key="server.properties.enter_property_name" /></span>
Bill Lynch's avatar
Bill Lynch committed
337 338 339 340 341 342 343 344

                <%  } %>

            <%  } %>
        </td>
    </tr>
    <tr valign="top">
        <td>
345
            <fmt:message key="server.properties.value" />:
Bill Lynch's avatar
Bill Lynch committed
346 347 348 349 350 351
        </td>
        <td>
            <textarea cols="45" rows="5" name="propValue" wrap="virtual"><%= (propValue != null ? StringUtils.escapeHTMLTags(propValue) : "") %></textarea>

            <%  if (errors.containsKey("propValue")) { %>

352
                <br><span class="jive-error-text"><fmt:message key="server.properties.enter_property_value" /></span>
Bill Lynch's avatar
Bill Lynch committed
353 354 355

            <%  } else if (errors.containsKey("propValueLength")) { %>

356
                <br><span class="jive-error-text"><fmt:message key="server.properties.max_character" /></span>
Bill Lynch's avatar
Bill Lynch committed
357 358 359 360 361 362 363 364

            <%  } %>
        </td>
    </tr>
</tbody>
<tfoot>
    <tr>
        <td colspan="2">
365 366
            <input type="submit" name="save" value="<fmt:message key="global.save_property" />">
            <input type="submit" name="cancel" value="<fmt:message key="global.cancel" />">
Bill Lynch's avatar
Bill Lynch committed
367 368 369 370 371 372 373 374 375 376 377 378 379
        </td>
    </tr>
</tfoot>
</table>
</div>

</form>

<br><br><br><br><br><br>
<br><br><br><br><br><br>
<br><br><br><br><br><br>
<br><br><br><br><br><br>

380 381
    </body>
</html>