system-email.jsp 7.1 KB
Newer Older
1
<%--
2
  - Copyright (C) 2005-2008 Jive Software. All rights reserved.
3
  -
4 5 6 7 8 9 10 11 12 13 14
  - 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.
15 16 17
--%>

<%@ page import="java.util.*,
18
				 org.jivesoftware.util.*"
19 20 21 22 23 24
    errorPage="error.jsp"
%>

<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jstl/fmt_rt" prefix="fmt" %>

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

28
<%
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
    // get parameters
    String host = ParamUtils.getParameter(request,"host");
    int port = ParamUtils.getIntParameter(request,"port",0);
    String username = ParamUtils.getParameter(request,"server_username");
    String password = ParamUtils.getParameter(request,"server_password");
    boolean ssl = ParamUtils.getBooleanParameter(request,"ssl");
    boolean save = request.getParameter("save") != null;
    boolean test = request.getParameter("test") != null;
    boolean debug = ParamUtils.getBooleanParameter(request, "debug");

    // Handle a test request
    if (test) {
        response.sendRedirect("system-emailtest.jsp");
        return;
    }

    EmailService service = EmailService.getInstance();
    // Save the email settings if requested
47
    Map<String,String> errors = new HashMap<String,String>();
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
    if (save) {
        if (host != null) {
            service.setHost(host);
        }
        else {
            errors.put("host","");
        }
        if (port > 0) {
            service.setPort(port);
        }
        else {
            // Default to port 25.
            service.setPort(25);
        }
        service.setUsername(username);
63
        // Get hash value of existing password
64 65 66 67
        String existingHashPassword = "";
        if (service.getPassword() != null) {
            existingHashPassword = StringUtils.hash(service.getPassword());
        }
68 69 70 71 72 73 74 75 76 77 78 79 80

        // Check if the new password was changed. If it wasn't changed, then it is the original hashed password
        // NOTE: if the new PLAIN password equals the previous HASHED password this fails, but is unlikely.
        if (!existingHashPassword.equals(password)) {
            // Hash the new password since it was changed
            String newHashPassword = "";
            if (password != null) {
                    newHashPassword = StringUtils.hash(password);
            }
            // Change password if hash values are different
            if (!existingHashPassword.equals(newHashPassword)) {
                service.setPassword(password);
            }
81
        }
82
        
83 84 85 86
        service.setDebugEnabled(debug);
        service.setSSLEnabled(ssl);

        if (errors.size() == 0) {
87 88
            // Log the event
            webManager.logEvent("updated email service settings", "host = "+host+"\nport = "+port+"\nusername = "+username);
89 90
            // Set property to specify email is configured
            JiveGlobals.setProperty("mail.configured", "true");
91 92 93 94 95 96 97 98 99 100 101 102
            response.sendRedirect("system-email.jsp?success=true");
        }
    }

    host = service.getHost();
    port = service.getPort();
    username = service.getUsername();
    password = service.getPassword();
    ssl = service.isSSLEnabled();
    debug = service.isDebugEnabled();
%>

103 104 105 106 107 108
<html>
    <head>
        <title><fmt:message key="system.email.title"/></title>
        <meta name="pageID" content="system-email"/>
    </head>
    <body>
109 110 111 112 113 114 115 116 117 118 119

<p>
<fmt:message key="system.email.info" />
</p>

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

    <div class="jive-success">
    <table cellpadding="0" cellspacing="0" border="0">
    <tbody>
        <tr>
120
        	<td class="jive-icon"><img src="images/success-16x16.gif" width="16" height="16" border="0" alt=""></td>
121 122 123 124 125 126 127 128 129 130 131 132 133 134
        	<td class="jive-icon-label"><fmt:message key="system.email.update_success" /></td>
        </tr>
    </tbody>
    </table>
    </div>

<%  } %>

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

    <div class="jive-error">
    <table cellpadding="0" cellspacing="0" border="0">
    <tbody>
        <tr>
135
        	<td class="jive-icon"><img src="images/error-16x16.gif" width="16" height="16" border="0" alt=""></td>
136 137 138 139 140 141 142 143 144 145
        	<td class="jive-icon-label"><fmt:message key="system.email.update_failure" /></td>
        </tr>
    </tbody>
    </table>
    </div>

<%	} %>

<p>

146
<!-- BEGIN SMTP settings -->
147 148
<form action="system-email.jsp" name="f" method="post">

149 150 151 152 153 154 155 156 157 158
	<div class="jive-contentBoxHeader">
		<fmt:message key="system.email.name" />
	</div>
	<div class="jive-contentBox">
		<table width="80%" cellpadding="3" cellspacing="0" border="0">
		<tr>
			<td width="30%" nowrap>
				<fmt:message key="system.email.mail_host" />:
			</td>
			<td nowrap>
Sven Tantau's avatar
Sven Tantau committed
159
				<input type="text" name="host" value="<%= (host != null)? StringUtils.escapeForXML(host):"" %>" size="40" maxlength="150">
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203
			</td>
		</tr>

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

			<tr>
				<td nowrap>
					&nbsp;
				</td>
				<td nowrap class="jive-error-text">
					<fmt:message key="system.email.valid_host_name" />
				</td>
			</tr>

		<%  } %>

		<tr>
			<td nowrap>
				<fmt:message key="system.email.server_port" />:
			</td>
			<td nowrap>
				<input type="text" name="port" value="<%= (port > 0) ? String.valueOf(port) : "" %>" size="10" maxlength="15">
			</td>
		</tr>
		<tr>
			<td nowrap>
				<fmt:message key="system.email.mail_debugging" />:
			</td>
			<td nowrap>
				<input type="radio" name="debug" value="true"<%= (debug ? " checked" : "") %> id="rb01"> <label for="rb01">On</label>
				&nbsp;
				<input type="radio" name="debug" value="false"<%= (debug ? "" : " checked") %> id="rb02"> <label for="rb02">Off</label>
				&nbsp; (<fmt:message key="system.email.restart_possible" />)
			</td>
		</tr>

		<%-- spacer --%>
		<tr><td colspan="2">&nbsp;</td></tr>

		<tr>
			<td nowrap>
				<fmt:message key="system.email.server_username" />:
			</td>
			<td nowrap>
Sven Tantau's avatar
Sven Tantau committed
204
				<input type="text" name="server_username" value="<%= (username != null) ? StringUtils.escapeForXML(username) : "" %>" size="40" maxlength="150">
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225
			</td>
		</tr>
		<tr>
			<td nowrap>
				<fmt:message key="system.email.server_password" />:
			</td>
			<td nowrap>
				<input type="password" name="server_password" value="<%= (password != null) ? StringUtils.hash(password) : "" %>" size="40" maxlength="150">
			</td>
		</tr>

		<tr>
			<td nowrap>
				<fmt:message key="system.email.ssl" />:
			</td>
			<td nowrap>
				<input type="checkbox" name="ssl"<%= (ssl) ? " checked" : "" %>>
			</td>
		</tr>
		</table>
	</div>
226 227 228 229

<input type="submit" name="save" value="<fmt:message key="system.email.save" />">
<input type="submit" name="test" value="<fmt:message key="system.email.send_test" />">
</form>
230
<!-- END SMTP settings -->
231

232
</body>
Sven Tantau's avatar
Sven Tantau committed
233
</html>