SMTP frontend

Signed-off-by: Bernardus Jansen <bernardus@bajansen.nl>
master
Bernardus Jansen 9 years ago
parent 72cbac1a56
commit 69121a894a
  1. 6
      libresonic-main/pom.xml
  2. 20
      libresonic-main/src/main/java/org/libresonic/player/command/AdvancedSettingsCommand.java
  3. 20
      libresonic-main/src/main/java/org/libresonic/player/controller/AdvancedSettingsController.java
  4. 22
      libresonic-main/src/main/java/org/libresonic/player/controller/MultiController.java
  5. 34
      libresonic-main/src/main/java/org/libresonic/player/service/SettingsService.java
  6. 50
      libresonic-main/src/main/webapp/WEB-INF/jsp/advancedSettings.jsp

@ -259,6 +259,12 @@
<version>1.5.5</version> <version>1.5.5</version>
</dependency> </dependency>
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>javax.mail</artifactId>
<version>1.5.5</version>
</dependency>
<dependency> <dependency>
<groupId>taglibs</groupId> <groupId>taglibs</groupId>
<artifactId>standard</artifactId> <artifactId>standard</artifactId>

@ -134,43 +134,43 @@ public class AdvancedSettingsCommand {
this.toast = toast; this.toast = toast;
} }
public String getSMTPServer() { public String getSmtpServer() {
return smtpServer; return smtpServer;
} }
public void setSMTPServer(String smtpServer) { public void setSmtpServer(String smtpServer) {
this.smtpServer = smtpServer; this.smtpServer = smtpServer;
} }
public String getSMTPEncryption() { public String getSmtpEncryption() {
return smtpEncryption; return smtpEncryption;
} }
public void setSMTPEncryption(String smtpEncryption) { public void setSmtpEncryption(String smtpEncryption) {
this.smtpEncryption = smtpEncryption; this.smtpEncryption = smtpEncryption;
} }
public String getSMTPPort() { public String getSmtpPort() {
return smtpPort; return smtpPort;
} }
public void setSMTPPort(String smtpPort) { public void setSmtpPort(String smtpPort) {
this.smtpPort = smtpPort; this.smtpPort = smtpPort;
} }
public String getSMTPUser() { public String getSmtpUser() {
return smtpUser; return smtpUser;
} }
public void setSMTPUser(String smtpUser) { public void setSmtpUser(String smtpUser) {
this.smtpUser = smtpUser; this.smtpUser = smtpUser;
} }
public String getSMTPPassword() { public String getSmtpPassword() {
return smtpPassword; return smtpPassword;
} }
public void setSMTPPassword(String smtpPassword) { public void setSmtpPassword(String smtpPassword) {
this.smtpPassword = smtpPassword; this.smtpPassword = smtpPassword;
} }
} }

@ -47,10 +47,10 @@ public class AdvancedSettingsController extends SimpleFormController {
command.setLdapAutoShadowing(settingsService.isLdapAutoShadowing()); command.setLdapAutoShadowing(settingsService.isLdapAutoShadowing());
command.setBrand(settingsService.getBrand()); command.setBrand(settingsService.getBrand());
command.setSMTPServer(settingsService.getSMTPServer()); command.setSmtpServer(settingsService.getSmtpServer());
command.setSMTPEncryption(settingsService.getSMTPEncryption()); command.setSmtpEncryption(settingsService.getSmtpEncryption());
command.setSMTPPort(settingsService.getSMTPPort()); command.setSmtpPort(settingsService.getSmtpPort());
command.setSMTPUser(settingsService.getSMTPUser()); command.setSmtpUser(settingsService.getSmtpUser());
return command; return command;
} }
@ -79,13 +79,13 @@ public class AdvancedSettingsController extends SimpleFormController {
settingsService.setLdapManagerPassword(command.getLdapManagerPassword()); settingsService.setLdapManagerPassword(command.getLdapManagerPassword());
} }
settingsService.setSMTPServer(command.getSMTPServer()); settingsService.setSmtpServer(command.getSmtpServer());
settingsService.setSMTPEncryption(command.getSMTPEncryption()); settingsService.setSmtpEncryption(command.getSmtpEncryption());
settingsService.setSMTPPort(command.getSMTPPort()); settingsService.setSmtpPort(command.getSmtpPort());
settingsService.setSMTPUser(command.getSMTPUser()); settingsService.setSmtpUser(command.getSmtpUser());
if (StringUtils.isNotEmpty(command.getSMTPPassword())) { if (StringUtils.isNotEmpty(command.getSmtpPassword())) {
settingsService.setSMTPPassword(command.getSMTPPassword()); settingsService.setSmtpPassword(command.getSmtpPassword());
} }
settingsService.save(); settingsService.save();

@ -138,29 +138,29 @@ public class MultiController extends MultiActionController {
} }
/* /*
* e-mail user new password via configured SMTP server * e-mail user new password via configured Smtp server
*/ */
private boolean emailPassword(String password, String username, String email) { private boolean emailPassword(String password, String username, String email) {
/* Default to protocol smtp when SMTPEncryption is set to "None" */ /* Default to protocol smtp when SmtpEncryption is set to "None" */
String prot = "smtp"; String prot = "smtp";
if (settingsService.getSMTPServer() == null || settingsService.getSMTPServer().isEmpty()) { if (settingsService.getSmtpServer() == null || settingsService.getSmtpServer().isEmpty()) {
LOG.warn("Can not send email; no SMTP server configured."); LOG.warn("Can not send email; no Smtp server configured.");
return false; return false;
} }
Properties props = new Properties(); Properties props = new Properties();
if (settingsService.getSMTPEncryption().equals("SSL/TLS")) { if (settingsService.getSmtpEncryption().equals("SSL/TLS")) {
prot = "smtps"; prot = "smtps";
props.put("mail." + prot + ".ssl.enable", "true"); props.put("mail." + prot + ".ssl.enable", "true");
} else if (settingsService.getSMTPEncryption().equals("STARTTLS")) { } else if (settingsService.getSmtpEncryption().equals("STARTTLS")) {
prot = "smtp"; prot = "smtp";
props.put("mail." + prot + ".starttls.enable", "true"); props.put("mail." + prot + ".starttls.enable", "true");
} }
props.put("mail." + prot + ".host", settingsService.getSMTPServer()); props.put("mail." + prot + ".host", settingsService.getSmtpServer());
props.put("mail." + prot + ".port", settingsService.getSMTPPort()); props.put("mail." + prot + ".port", settingsService.getSmtpPort());
/* use authentication when SMTPUser is configured */ /* use authentication when SmtpUser is configured */
if (settingsService.getSMTPUser() != null && !settingsService.getSMTPUser().isEmpty()) { if (settingsService.getSmtpUser() != null && !settingsService.getSmtpUser().isEmpty()) {
props.put("mail." + prot + ".auth", "true"); props.put("mail." + prot + ".auth", "true");
} }
@ -183,7 +183,7 @@ public class MultiController extends MultiActionController {
Transport trans = session.getTransport(prot); Transport trans = session.getTransport(prot);
try { try {
if (props.get("mail." + prot + ".auth").equals("true")) { if (props.get("mail." + prot + ".auth").equals("true")) {
trans.connect(settingsService.getSMTPServer(), settingsService.getSMTPUser(), settingsService.getSMTPPassword()); trans.connect(settingsService.getSmtpServer(), settingsService.getSmtpUser(), settingsService.getSmtpPassword());
} else { } else {
trans.connect(); trans.connect();
} }

@ -144,11 +144,11 @@ public class SettingsService {
private static final String KEY_SONOS_SERVICE_NAME = "SonosServiceName"; private static final String KEY_SONOS_SERVICE_NAME = "SonosServiceName";
private static final String KEY_SONOS_SERVICE_ID = "SonosServiceId"; private static final String KEY_SONOS_SERVICE_ID = "SonosServiceId";
private static final String KEY_SMTP_SERVER = "SMTPServer"; private static final String KEY_SMTP_SERVER = "SmtpServer";
private static final String KEY_SMTP_ENCRYPTION = "SMTPEncryption"; private static final String KEY_SMTP_ENCRYPTION = "SmtpEncryption";
private static final String KEY_SMTP_PORT = "SMTPPort"; private static final String KEY_SMTP_PORT = "SmtpPort";
private static final String KEY_SMTP_USER = "SMTPUser"; private static final String KEY_SMTP_USER = "SmtpUser";
private static final String KEY_SMTP_PASSWORD = "SMTPPassword"; private static final String KEY_SMTP_PASSWORD = "SmtpPassword";
// Default values. // Default values.
private static final String DEFAULT_INDEX_STRING = "A B C D E F G H I J K L M N O P Q R S T U V W X-Z(XYZ)"; private static final String DEFAULT_INDEX_STRING = "A B C D E F G H I J K L M N O P Q R S T U V W X-Z(XYZ)";
@ -1459,52 +1459,52 @@ public class SettingsService {
this.versionService = versionService; this.versionService = versionService;
} }
public String getSMTPServer() { public String getSmtpServer() {
return properties.getProperty(KEY_SMTP_SERVER, DEFAULT_SMTP_SERVER); return properties.getProperty(KEY_SMTP_SERVER, DEFAULT_SMTP_SERVER);
} }
public void setSMTPServer(String smtpServer) { public void setSmtpServer(String smtpServer) {
setString(KEY_SMTP_SERVER, smtpServer); setString(KEY_SMTP_SERVER, smtpServer);
} }
public String getSMTPPort() { public String getSmtpPort() {
return getString(KEY_SMTP_PORT, DEFAULT_SMTP_PORT); return getString(KEY_SMTP_PORT, DEFAULT_SMTP_PORT);
} }
public void setSMTPPort(String smtpPort) { public void setSmtpPort(String smtpPort) {
setString(KEY_SMTP_PORT, smtpPort); setString(KEY_SMTP_PORT, smtpPort);
} }
public String getSMTPEncryption() { public String getSmtpEncryption() {
return properties.getProperty(KEY_SMTP_ENCRYPTION, DEFAULT_SMTP_ENCRYPTION); return properties.getProperty(KEY_SMTP_ENCRYPTION, DEFAULT_SMTP_ENCRYPTION);
} }
public void setSMTPEncryption(String encryptionMethod) { public void setSmtpEncryption(String encryptionMethod) {
setString(KEY_SMTP_ENCRYPTION, encryptionMethod); setString(KEY_SMTP_ENCRYPTION, encryptionMethod);
} }
public String getSMTPUser() { public String getSmtpUser() {
return properties.getProperty(KEY_SMTP_USER, DEFAULT_SMTP_USER); return properties.getProperty(KEY_SMTP_USER, DEFAULT_SMTP_USER);
} }
public void setSMTPUser(String smtpUser) { public void setSmtpUser(String smtpUser) {
setString(KEY_SMTP_USER, smtpUser); setString(KEY_SMTP_USER, smtpUser);
} }
public String getSMTPPassword() { public String getSmtpPassword() {
String s = properties.getProperty(KEY_SMTP_PASSWORD, DEFAULT_SMTP_PASSWORD); String s = properties.getProperty(KEY_SMTP_PASSWORD, DEFAULT_SMTP_PASSWORD);
try { try {
return StringUtil.utf8HexDecode(s); return StringUtil.utf8HexDecode(s);
} catch (Exception x) { } catch (Exception x) {
LOG.warn("Failed to decode SMTP password.", x); LOG.warn("Failed to decode Smtp password.", x);
return s; return s;
} }
} }
public void setSMTPPassword(String smtpPassword) { public void setSmtpPassword(String smtpPassword) {
try { try {
smtpPassword = StringUtil.utf8HexEncode(smtpPassword); smtpPassword = StringUtil.utf8HexEncode(smtpPassword);
} catch (Exception x) { } catch (Exception x) {
LOG.warn("Failed to encode SMTP password.", x); LOG.warn("Failed to encode Smtp password.", x);
} }
properties.setProperty(KEY_SMTP_PASSWORD, smtpPassword); properties.setProperty(KEY_SMTP_PASSWORD, smtpPassword);
} }

@ -41,6 +41,56 @@
</tr> </tr>
</table> </table>
<table style="white-space:nowrap" class="indent">
<tr>
<td><fmt:message key="advancedsettings.smtpServer"/></td>
<td>
<form:input path="smtpServer" size="50"/>
<c:import url="helpToolTip.jsp"><c:param name="topic" value="smtpServer"/></c:import>
</td>
</tr>
<tr>
<td><fmt:message key="advancedsettings.smtpPort"/></td>
<td>
<form:input path="smtpPort" size="5"/>
<c:import url="helpToolTip.jsp"><c:param name="topic" value="smtpPort"/></c:import>
</td>
</tr>
<tr>
<td><fmt:message key="advancedsettings.smtpEncryption"/></td>
<td>
<form:select path="smtpEncryption" cssStyle="width:20em">
<fmt:message key="advancedsettings.smtpEncryption.none" var="none"/>
<fmt:message key="advancedsettings.smtpEncryption.starttls" var="starttls"/>
<fmt:message key="advancedsettings.smtpEncryption.ssl" var="ssl"/>
<form:option value="None" label="None"/>
<form:option value="STARTTLS" label="STARTTLS"/>
<form:option value="SSL/TLS" label="SSL/TLS"/>
</form:select>
</td>
</tr>
<tr>
<td><fmt:message key="advancedsettings.smtpUser"/></td>
<td>
<form:input path="smtpUser" size="40"/>
<c:import url="helpToolTip.jsp"><c:param name="topic" value="smtpUser"/></c:import>
</td>
</tr>
<tr>
<td><fmt:message key="advancedsettings.smtpPassword"/></td>
<td>
<form:password path="smtpPassword" size="40"/>
<c:import url="helpToolTip.jsp"><c:param name="topic" value="smtpPassword"/></c:import>
</td>
</tr>
</table>
<table class="indent"><tr><td> <table class="indent"><tr><td>
<form:checkbox path="ldapEnabled" id="ldap" cssClass="checkbox" onclick="enableLdapFields()"/> <form:checkbox path="ldapEnabled" id="ldap" cssClass="checkbox" onclick="enableLdapFields()"/>
<label for="ldap"><fmt:message key="advancedsettings.ldapenabled"/></label> <label for="ldap"><fmt:message key="advancedsettings.ldapenabled"/></label>

Loading…
Cancel
Save