|
|
|
@ -2,6 +2,7 @@ package de.srsoftware.widerhall.web;
@@ -2,6 +2,7 @@ package de.srsoftware.widerhall.web;
|
|
|
|
|
|
|
|
|
|
import de.srsoftware.widerhall.Configuration; |
|
|
|
|
import de.srsoftware.widerhall.Util; |
|
|
|
|
import de.srsoftware.widerhall.data.ListMember; |
|
|
|
|
import de.srsoftware.widerhall.data.MailingList; |
|
|
|
|
import de.srsoftware.widerhall.data.User; |
|
|
|
|
import org.slf4j.Logger; |
|
|
|
@ -49,72 +50,76 @@ public class Web extends HttpServlet {
@@ -49,72 +50,76 @@ public class Web extends HttpServlet {
|
|
|
|
|
|
|
|
|
|
private String addList(HttpServletRequest req, HttpServletResponse resp) { |
|
|
|
|
|
|
|
|
|
var user = req.getSession().getAttribute(USER); |
|
|
|
|
if (user == null) return redirectTo(LOGIN,resp); |
|
|
|
|
var data = new HashMap<String,Object>(); |
|
|
|
|
data.put(USER,user); |
|
|
|
|
|
|
|
|
|
var name = req.getParameter(NAME); |
|
|
|
|
data.put(NAME,name); |
|
|
|
|
|
|
|
|
|
var email = req.getParameter(EMAIL); |
|
|
|
|
data.put(EMAIL,email); |
|
|
|
|
|
|
|
|
|
var imapHost = req.getParameter(IMAP_HOST); |
|
|
|
|
data.put(IMAP_HOST,imapHost); |
|
|
|
|
var imapUser = req.getParameter(IMAP_USER); |
|
|
|
|
data.put(IMAP_USER,imapUser); |
|
|
|
|
var imapPass = req.getParameter(IMAP_PASS); |
|
|
|
|
var smtpHost = req.getParameter(SMTP_HOST); |
|
|
|
|
data.put(SMTP_HOST,smtpHost); |
|
|
|
|
var smtpUser = req.getParameter(SMTP_USER); |
|
|
|
|
data.put(SMTP_USER,smtpUser); |
|
|
|
|
var smtpPass = req.getParameter(SMTP_PASS); |
|
|
|
|
|
|
|
|
|
Integer imapPort = 993; |
|
|
|
|
data.put(IMAP_PORT,imapPort); |
|
|
|
|
|
|
|
|
|
Integer smtpPort = 465; |
|
|
|
|
data.put(SMTP_PORT,smtpPort); |
|
|
|
|
|
|
|
|
|
if (name == null || name.isBlank() || email == null || email.isBlank()) { |
|
|
|
|
data.put(ERROR,"List name and address are required!"); |
|
|
|
|
return loadTemplate(ADD_LIST,data,resp); |
|
|
|
|
} |
|
|
|
|
var o = req.getSession().getAttribute(USER); |
|
|
|
|
if (o instanceof User user){ |
|
|
|
|
var data = new HashMap<String,Object>(); |
|
|
|
|
data.put(USER,user); |
|
|
|
|
|
|
|
|
|
var name = req.getParameter(NAME); |
|
|
|
|
data.put(NAME,name); |
|
|
|
|
|
|
|
|
|
var email = req.getParameter(EMAIL); |
|
|
|
|
data.put(EMAIL,email); |
|
|
|
|
|
|
|
|
|
var imapHost = req.getParameter(IMAP_HOST); |
|
|
|
|
data.put(IMAP_HOST,imapHost); |
|
|
|
|
var imapUser = req.getParameter(IMAP_USER); |
|
|
|
|
data.put(IMAP_USER,imapUser); |
|
|
|
|
var imapPass = req.getParameter(IMAP_PASS); |
|
|
|
|
var smtpHost = req.getParameter(SMTP_HOST); |
|
|
|
|
data.put(SMTP_HOST,smtpHost); |
|
|
|
|
var smtpUser = req.getParameter(SMTP_USER); |
|
|
|
|
data.put(SMTP_USER,smtpUser); |
|
|
|
|
var smtpPass = req.getParameter(SMTP_PASS); |
|
|
|
|
|
|
|
|
|
Integer imapPort = 993; |
|
|
|
|
data.put(IMAP_PORT,imapPort); |
|
|
|
|
|
|
|
|
|
if (imapHost == null || imapHost.isBlank() || imapUser == null || imapUser.isBlank() || imapPass == null || imapPass.isBlank()) { |
|
|
|
|
data.put(ERROR,"IMAP credentials are required!"); |
|
|
|
|
return loadTemplate(ADD_LIST,data,resp); |
|
|
|
|
} |
|
|
|
|
Integer smtpPort = 465; |
|
|
|
|
data.put(SMTP_PORT,smtpPort); |
|
|
|
|
|
|
|
|
|
if (name == null || name.isBlank() || email == null || email.isBlank()) { |
|
|
|
|
data.put(ERROR,"List name and address are required!"); |
|
|
|
|
return loadTemplate(ADD_LIST,data,resp); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
imapPort = Integer.parseInt(req.getParameter(IMAP_PORT)); |
|
|
|
|
data.put(IMAP_PORT,imapPort); |
|
|
|
|
} catch (NumberFormatException nfe){ |
|
|
|
|
data.put(ERROR,t("'{}' is not a proper port number!",req.getParameter(IMAP_PORT))); |
|
|
|
|
return loadTemplate(ADD_LIST,data,resp); |
|
|
|
|
} |
|
|
|
|
if (imapHost == null || imapHost.isBlank() || imapUser == null || imapUser.isBlank() || imapPass == null || imapPass.isBlank()) { |
|
|
|
|
data.put(ERROR,"IMAP credentials are required!"); |
|
|
|
|
return loadTemplate(ADD_LIST,data,resp); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (smtpHost == null || smtpHost.isBlank() || smtpUser == null || smtpUser.isBlank() || smtpPass == null || smtpPass.isBlank()) { |
|
|
|
|
data.put(ERROR,"SMTP credentials are required!"); |
|
|
|
|
return loadTemplate(ADD_LIST,data,resp); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
smtpPort = Integer.parseInt(req.getParameter(SMTP_PORT)); |
|
|
|
|
data.put(SMTP_PORT,smtpPort); |
|
|
|
|
} catch (NumberFormatException nfe){ |
|
|
|
|
data.put(ERROR,t("'{}' is not a proper port number!",req.getParameter(SMTP_PORT))); |
|
|
|
|
return loadTemplate(ADD_LIST,data,resp); |
|
|
|
|
} |
|
|
|
|
try { |
|
|
|
|
imapPort = Integer.parseInt(req.getParameter(IMAP_PORT)); |
|
|
|
|
data.put(IMAP_PORT,imapPort); |
|
|
|
|
} catch (NumberFormatException nfe){ |
|
|
|
|
data.put(ERROR,t("'{}' is not a proper port number!",req.getParameter(IMAP_PORT))); |
|
|
|
|
return loadTemplate(ADD_LIST,data,resp); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
MailingList.create(email,name,imapHost,imapPort,imapUser,imapPass,smtpHost,smtpPort,smtpUser,smtpPass); |
|
|
|
|
return redirectTo(INDEX,resp); |
|
|
|
|
} catch (SQLException e) { |
|
|
|
|
return t("Failed to create list '{}': {}",name,e.getMessage()); |
|
|
|
|
if (smtpHost == null || smtpHost.isBlank() || smtpUser == null || smtpUser.isBlank() || smtpPass == null || smtpPass.isBlank()) { |
|
|
|
|
data.put(ERROR,"SMTP credentials are required!"); |
|
|
|
|
return loadTemplate(ADD_LIST,data,resp); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
smtpPort = Integer.parseInt(req.getParameter(SMTP_PORT)); |
|
|
|
|
data.put(SMTP_PORT,smtpPort); |
|
|
|
|
} catch (NumberFormatException nfe){ |
|
|
|
|
data.put(ERROR,t("'{}' is not a proper port number!",req.getParameter(SMTP_PORT))); |
|
|
|
|
return loadTemplate(ADD_LIST,data,resp); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
MailingList.create(email,name,imapHost,imapPort,imapUser,imapPass,smtpHost,smtpPort,smtpUser,smtpPass); |
|
|
|
|
ListMember.create(email,user.email(),ListMember.STATE_OWNER); |
|
|
|
|
return redirectTo(INDEX,resp); |
|
|
|
|
} catch (SQLException e) { |
|
|
|
|
return t("Failed to create list '{}': {}",name,e.getMessage()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return redirectTo(LOGIN,resp); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -132,7 +137,7 @@ public class Web extends HttpServlet {
@@ -132,7 +137,7 @@ public class Web extends HttpServlet {
|
|
|
|
|
|
|
|
|
|
private String handleGet(HttpServletRequest req, HttpServletResponse resp) { |
|
|
|
|
var path = req.getPathInfo(); |
|
|
|
|
path = path == null ? INDEX : path.substring(1); |
|
|
|
|
path = (path == null || path.equals("/")) ? INDEX : path.substring(1); |
|
|
|
|
String notes = null; |
|
|
|
|
switch (path){ |
|
|
|
|
case "reload": |
|
|
|
@ -141,7 +146,9 @@ public class Web extends HttpServlet {
@@ -141,7 +146,9 @@ public class Web extends HttpServlet {
|
|
|
|
|
notes = t("Templates have been reloaded"); |
|
|
|
|
break; |
|
|
|
|
case "css": |
|
|
|
|
return loadTemplate(path,null,resp); |
|
|
|
|
case "js": |
|
|
|
|
resp.setContentType("text/javascript"); |
|
|
|
|
return loadTemplate(path,null,resp); |
|
|
|
|
case LOGIN: |
|
|
|
|
try { |
|
|
|
@ -154,6 +161,7 @@ public class Web extends HttpServlet {
@@ -154,6 +161,7 @@ public class Web extends HttpServlet {
|
|
|
|
|
req.getSession().invalidate(); |
|
|
|
|
return redirectTo(INDEX,resp); |
|
|
|
|
case "jquery": |
|
|
|
|
resp.setContentType("text/javascript"); |
|
|
|
|
return loadFile("jquery-3.6.0.min.js",resp); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|