|
|
@ -23,20 +23,21 @@ import java.util.ArrayList; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
import java.util.Properties; |
|
|
|
|
|
|
|
import java.util.Date; |
|
|
|
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import javax.mail.Message; |
|
|
|
|
|
|
|
import javax.mail.Session; |
|
|
|
|
|
|
|
import javax.mail.Transport; |
|
|
|
|
|
|
|
import javax.mail.internet.InternetAddress; |
|
|
|
|
|
|
|
import javax.mail.internet.MimeMessage; |
|
|
|
|
|
|
|
|
|
|
|
import org.apache.commons.lang.ObjectUtils; |
|
|
|
import org.apache.commons.lang.ObjectUtils; |
|
|
|
import org.apache.commons.lang.RandomStringUtils; |
|
|
|
import org.apache.commons.lang.RandomStringUtils; |
|
|
|
import org.apache.commons.lang.StringUtils; |
|
|
|
import org.apache.commons.lang.StringUtils; |
|
|
|
import org.apache.http.NameValuePair; |
|
|
|
|
|
|
|
import org.apache.http.client.HttpClient; |
|
|
|
|
|
|
|
import org.apache.http.client.entity.UrlEncodedFormEntity; |
|
|
|
|
|
|
|
import org.apache.http.client.methods.HttpPost; |
|
|
|
|
|
|
|
import org.apache.http.impl.client.DefaultHttpClient; |
|
|
|
|
|
|
|
import org.apache.http.message.BasicNameValuePair; |
|
|
|
|
|
|
|
import org.apache.http.params.HttpConnectionParams; |
|
|
|
|
|
|
|
import org.springframework.web.bind.ServletRequestUtils; |
|
|
|
import org.springframework.web.bind.ServletRequestUtils; |
|
|
|
import org.springframework.web.servlet.ModelAndView; |
|
|
|
import org.springframework.web.servlet.ModelAndView; |
|
|
|
import org.springframework.web.servlet.mvc.multiaction.MultiActionController; |
|
|
|
import org.springframework.web.servlet.mvc.multiaction.MultiActionController; |
|
|
@ -136,33 +137,65 @@ public class MultiController extends MultiActionController { |
|
|
|
return new ModelAndView("recover", "model", map); |
|
|
|
return new ModelAndView("recover", "model", map); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* |
|
|
|
|
|
|
|
* 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) { |
|
|
|
HttpClient client = new DefaultHttpClient(); |
|
|
|
/* Default to protocol smtp when SmtpEncryption is set to "None" */ |
|
|
|
|
|
|
|
String prot = "smtp"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (settingsService.getSmtpServer() == null || settingsService.getSmtpServer().isEmpty()) { |
|
|
|
|
|
|
|
LOG.warn("Can not send email; no Smtp server configured."); |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Properties props = new Properties(); |
|
|
|
|
|
|
|
if (settingsService.getSmtpEncryption().equals("SSL/TLS")) { |
|
|
|
|
|
|
|
prot = "smtps"; |
|
|
|
|
|
|
|
props.put("mail." + prot + ".ssl.enable", "true"); |
|
|
|
|
|
|
|
} else if (settingsService.getSmtpEncryption().equals("STARTTLS")) { |
|
|
|
|
|
|
|
prot = "smtp"; |
|
|
|
|
|
|
|
props.put("mail." + prot + ".starttls.enable", "true"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
props.put("mail." + prot + ".host", settingsService.getSmtpServer()); |
|
|
|
|
|
|
|
props.put("mail." + prot + ".port", settingsService.getSmtpPort()); |
|
|
|
|
|
|
|
/* use authentication when SmtpUser is configured */ |
|
|
|
|
|
|
|
if (settingsService.getSmtpUser() != null && !settingsService.getSmtpUser().isEmpty()) { |
|
|
|
|
|
|
|
props.put("mail." + prot + ".auth", "true"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Session session = Session.getInstance(props, null); |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
HttpConnectionParams.setConnectionTimeout(client.getParams(), 10000); |
|
|
|
Message message = new MimeMessage(session); |
|
|
|
HttpConnectionParams.setSoTimeout(client.getParams(), 10000); |
|
|
|
message.setFrom(new InternetAddress("libresonic@libresonic.org")); |
|
|
|
HttpPost method = new HttpPost("http://libresonic.org/backend/sendMail.view"); |
|
|
|
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(email)); |
|
|
|
|
|
|
|
message.setSubject("Libresonic Password"); |
|
|
|
List<NameValuePair> params = new ArrayList<NameValuePair>(); |
|
|
|
message.setText("Hi there!\n\n" + |
|
|
|
params.add(new BasicNameValuePair("from", "noreply@libresonic.org")); |
|
|
|
|
|
|
|
params.add(new BasicNameValuePair("to", email)); |
|
|
|
|
|
|
|
params.add(new BasicNameValuePair("subject", "Libresonic Password")); |
|
|
|
|
|
|
|
params.add(new BasicNameValuePair("text", |
|
|
|
|
|
|
|
"Hi there!\n\n" + |
|
|
|
|
|
|
|
"You have requested to reset your Libresonic password. Please find your new login details below.\n\n" + |
|
|
|
"You have requested to reset your Libresonic password. Please find your new login details below.\n\n" + |
|
|
|
"Username: " + username + "\n" + |
|
|
|
"Username: " + username + "\n" + |
|
|
|
"Password: " + password + "\n\n" + |
|
|
|
"Password: " + password + "\n\n" + |
|
|
|
"--\n" + |
|
|
|
"--\n" + |
|
|
|
"The Libresonic Team\n" + |
|
|
|
"Your Libresonic server\n" + |
|
|
|
"libresonic.org")); |
|
|
|
"libresonic.org"); |
|
|
|
method.setEntity(new UrlEncodedFormEntity(params, StringUtil.ENCODING_UTF8)); |
|
|
|
message.setSentDate(new Date()); |
|
|
|
client.execute(method); |
|
|
|
|
|
|
|
|
|
|
|
Transport trans = session.getTransport(prot); |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
if (props.get("mail." + prot + ".auth") != null && props.get("mail." + prot + ".auth").equals("true")) { |
|
|
|
|
|
|
|
trans.connect(settingsService.getSmtpServer(), settingsService.getSmtpUser(), settingsService.getSmtpPassword()); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
trans.connect(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
trans.sendMessage(message, message.getAllRecipients()); |
|
|
|
|
|
|
|
} finally { |
|
|
|
|
|
|
|
trans.close(); |
|
|
|
|
|
|
|
} |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
|
|
|
|
|
|
|
|
} catch (Exception x) { |
|
|
|
} catch (Exception x) { |
|
|
|
LOG.warn("Failed to send email.", x); |
|
|
|
LOG.warn("Failed to send email.", x); |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} finally { |
|
|
|
|
|
|
|
client.getConnectionManager().shutdown(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|