implemented editing of list credentials for admin/owner, fixed bug:
if login fails due to wrong auth, it is no longer repeated. instead, the list is disabeld
This commit is contained in:
2
pom.xml
2
pom.xml
@@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>Widerhall</artifactId>
|
||||
<version>0.2.21</version>
|
||||
<version>0.2.22</version>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
|
||||
@@ -183,6 +183,11 @@ public class Database {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void run() throws SQLException {
|
||||
compile().run();
|
||||
}
|
||||
|
||||
/**
|
||||
* set single value for a certain key
|
||||
* @param key
|
||||
@@ -194,6 +199,11 @@ public class Database {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Request sort(String field) {
|
||||
sortFields.add(field);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* get the current (i.e. non-final) sql
|
||||
* @return
|
||||
@@ -251,11 +261,6 @@ public class Database {
|
||||
list.add(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Request sort(String field) {
|
||||
sortFields.add(field);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
public Database(Connection connection) {
|
||||
|
||||
@@ -406,6 +406,10 @@ public class ListMember {
|
||||
}
|
||||
}
|
||||
|
||||
public static void updateListEmail(String oldEmail, String newEmail) throws SQLException {
|
||||
Database.open().update(TABLE_NAME).set(LIST_EMAIL,newEmail).where(LIST_EMAIL,oldEmail).compile().run();
|
||||
}
|
||||
|
||||
public User user(){
|
||||
return user;
|
||||
}
|
||||
|
||||
@@ -3,14 +3,12 @@ package de.srsoftware.widerhall.data;
|
||||
import de.srsoftware.widerhall.Configuration;
|
||||
import de.srsoftware.widerhall.mail.ImapClient;
|
||||
import de.srsoftware.widerhall.mail.MessageHandler;
|
||||
import de.srsoftware.widerhall.mail.ProblemListener;
|
||||
import de.srsoftware.widerhall.mail.SmtpClient;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.mail.Address;
|
||||
import javax.mail.Flags;
|
||||
import javax.mail.Message;
|
||||
import javax.mail.MessagingException;
|
||||
import javax.mail.*;
|
||||
import javax.mail.internet.AddressException;
|
||||
import javax.mail.internet.InternetAddress;
|
||||
import java.io.*;
|
||||
@@ -27,7 +25,7 @@ import static de.srsoftware.widerhall.data.User.PERMISSION_ADMIN;
|
||||
/**
|
||||
* this class encapsulates a MailingList db object
|
||||
*/
|
||||
public class MailingList implements MessageHandler {
|
||||
public class MailingList implements MessageHandler, ProblemListener {
|
||||
public static final String KEY_FORWARD_FROM = "forward_from";
|
||||
public static final String KEY_FORWARD_ATTACHED = "forward_attached";
|
||||
public static final String KEY_HIDE_RECEIVERS = "hide_receivers";
|
||||
@@ -61,11 +59,11 @@ public class MailingList implements MessageHandler {
|
||||
private static final int HIDDEN = 0;
|
||||
private static final int DEFAULT_STATE = STATE_PENDING|STATE_HIDE_RECEIVERS|STATE_PUBLIC_ARCHIVE;
|
||||
private static final String RETAINED_FOLDER = "retained";
|
||||
private final String name;
|
||||
private final String email;
|
||||
private static final String LAST_ERROR = "last_error";
|
||||
private String email, name, lastError;
|
||||
private int state;
|
||||
private final SmtpClient smtp;
|
||||
private final ImapClient imap;
|
||||
private SmtpClient smtp;
|
||||
private ImapClient imap;
|
||||
|
||||
private static final HashMap<String,MailingList> cache = new HashMap<>();
|
||||
|
||||
@@ -88,7 +86,7 @@ public class MailingList implements MessageHandler {
|
||||
this.name = name;
|
||||
this.state = state;
|
||||
this.smtp = new SmtpClient(smtpHost,smtpPort,smtpUser,smtpPass);
|
||||
this.imap = new ImapClient(imapHost,imapPort,imapUser,imapPass,inbox);
|
||||
this.imap = new ImapClient(imapHost,imapPort,imapUser,imapPass,inbox,this);
|
||||
}
|
||||
|
||||
public MailingList archive(boolean enabled) throws SQLException {
|
||||
@@ -133,7 +131,8 @@ public class MailingList implements MessageHandler {
|
||||
.append(SMTP_PORT).append(" ").append(INT).append(", ")
|
||||
.append(SMTP_USER).append(" ").append(VARCHAR).append(", ")
|
||||
.append(SMTP_PASS).append(" ").append(VARCHAR).append(", ")
|
||||
.append(STATE).append(" ").append(INT)
|
||||
.append(STATE).append(" ").append(INT).append(", ")
|
||||
.append(LAST_ERROR).append(" ").append(TEXT)
|
||||
.append(");");
|
||||
Database.open().query(sql).compile().run();
|
||||
}
|
||||
@@ -146,7 +145,10 @@ public class MailingList implements MessageHandler {
|
||||
public MailingList enable(boolean enable) throws SQLException {
|
||||
if (!enable) imap.stop();
|
||||
setFlag(STATE_ENABLED,enable);
|
||||
if (enable) imap.start().addListener(this);
|
||||
if (enable) {
|
||||
setLastError(null);
|
||||
imap.start().addListener(this);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -273,12 +275,15 @@ public class MailingList implements MessageHandler {
|
||||
public static MailingList load(String listEmail) {
|
||||
if (listEmail == null) return null;
|
||||
var ml = cache.get(listEmail);
|
||||
if (ml == null) try {
|
||||
try {
|
||||
var rs = Database.open()
|
||||
.select(TABLE_NAME)
|
||||
.where(EMAIL,listEmail)
|
||||
.compile().exec();
|
||||
if (rs.next()) ml = MailingList.from(rs);
|
||||
if (rs.next()) {
|
||||
if (ml == null ) ml = MailingList.from(rs);
|
||||
ml.lastError = rs.getString(LAST_ERROR);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
LOG.debug("Failed to load MailingList: ",e);
|
||||
}
|
||||
@@ -352,6 +357,7 @@ public class MailingList implements MessageHandler {
|
||||
map.put(EMAIL,Map.of(PREFIX,parts[0],DOMAIN,parts[1]));
|
||||
map.put(NAME, name);
|
||||
map.put(STATE, stateMap());
|
||||
map.put(LAST_ERROR, lastError);
|
||||
return map;
|
||||
}
|
||||
|
||||
@@ -381,6 +387,16 @@ public class MailingList implements MessageHandler {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onImapException(MessagingException e) {
|
||||
try {
|
||||
if (e instanceof AuthenticationFailedException afe) this.enable(false);
|
||||
setLastError(e.getMessage());
|
||||
} catch (SQLException sqle) {
|
||||
LOG.warn("Database error during onImapException ({})",e.getMessage(),sqle);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMessageReceived(Message message) throws MessagingException {
|
||||
LOG.info("Message received: {}",message.getFrom());
|
||||
@@ -477,6 +493,7 @@ public class MailingList implements MessageHandler {
|
||||
if (smtp.port() != 0) map.put(SMTP_PORT, smtp.port());
|
||||
if (smtp.username() != null) map.put(SMTP_USER, smtp.username());
|
||||
map.put(STATE,stateMap());
|
||||
if (lastError != null) map.put(LAST_ERROR, lastError);
|
||||
return map;
|
||||
}
|
||||
|
||||
@@ -550,6 +567,10 @@ public class MailingList implements MessageHandler {
|
||||
return this;
|
||||
}
|
||||
|
||||
private void setLastError(String message) throws SQLException {
|
||||
Database.open().update(TABLE_NAME).set(LAST_ERROR,message).where(EMAIL,email()).run();
|
||||
}
|
||||
|
||||
public Map<String,Integer> stateMap(){
|
||||
var map = new HashMap<String,Integer>();
|
||||
if (hasState(STATE_ENABLED)) map.put("enabled",VISIBLE);
|
||||
@@ -664,4 +685,32 @@ public class MailingList implements MessageHandler {
|
||||
return new ArrayList<InternetAddress>().stream();
|
||||
}
|
||||
}
|
||||
|
||||
public void update(String name, String email, String imapHost, Integer imapPort, String imapUser, String imapPass, String inbox, String smtpHost, Integer smtpPort, String smtpUser, String smtpPass) throws SQLException {
|
||||
imap.stop();
|
||||
Database.open()
|
||||
.update(TABLE_NAME)
|
||||
.set(EMAIL, email)
|
||||
.set(NAME, name)
|
||||
.set(IMAP_HOST, imapHost)
|
||||
.set(IMAP_PORT, imapPort)
|
||||
.set(IMAP_USER, imapUser)
|
||||
.set(IMAP_PASS, imapPass)
|
||||
.set(INBOX,inbox)
|
||||
.set(SMTP_HOST, smtpHost)
|
||||
.set(SMTP_PORT, smtpPort)
|
||||
.set(SMTP_USER, smtpUser)
|
||||
.set(SMTP_PASS, smtpPass)
|
||||
.where(EMAIL,email())
|
||||
.compile()
|
||||
.run();
|
||||
if (!this.email.equals(email)){
|
||||
ListMember.updateListEmail(this.email,email);
|
||||
this.email = email;
|
||||
}
|
||||
this.name = name;
|
||||
smtp = new SmtpClient(smtpHost,smtpPort,smtpUser,smtpPass);
|
||||
imap = new ImapClient(imapHost,imapPort,imapUser,imapPass,inbox,this);
|
||||
if (this.hasState(STATE_ENABLED)) imap.start().addListener(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ public class ImapClient {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(ImapClient.class);
|
||||
private final int port;
|
||||
private final String host, username, password, folderName;
|
||||
private final ProblemListener problemListener;
|
||||
private IMAPFolder inbox;
|
||||
private ListeningThread listeningThread;
|
||||
private Heartbeat heartbeat;
|
||||
@@ -47,6 +48,7 @@ public class ImapClient {
|
||||
openInbox();
|
||||
} catch (MessagingException e){
|
||||
LOG.warn("Connection problem:",e);
|
||||
problemListener.onImapException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -127,12 +129,13 @@ public class ImapClient {
|
||||
}
|
||||
}
|
||||
|
||||
public ImapClient(String host, int port, String username, String password, String folderName) {
|
||||
public ImapClient(String host, int port, String username, String password, String folderName,ProblemListener listener) {
|
||||
this.host = host;
|
||||
this.port = port;
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
this.folderName = folderName;
|
||||
this.problemListener = listener;
|
||||
}
|
||||
|
||||
public ImapClient addListener(MessageHandler messageHandler) {
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package de.srsoftware.widerhall.mail;
|
||||
|
||||
import javax.mail.MessagingException;
|
||||
|
||||
public interface ProblemListener {
|
||||
public void onImapException(MessagingException e);
|
||||
}
|
||||
@@ -21,6 +21,7 @@ import java.util.Map;
|
||||
import static de.srsoftware.widerhall.Constants.*;
|
||||
import static de.srsoftware.widerhall.Util.t;
|
||||
import static de.srsoftware.widerhall.data.MailingList.*;
|
||||
import static de.srsoftware.widerhall.data.User.PERMISSION_ADMIN;
|
||||
|
||||
public class Web extends TemplateServlet {
|
||||
public static final String WEB_ROOT = "/web";
|
||||
@@ -29,6 +30,7 @@ public class Web extends TemplateServlet {
|
||||
private static final String CSS = "css";
|
||||
private static final Logger LOG = LoggerFactory.getLogger(Web.class);
|
||||
private static final String ADMIN = "admin";
|
||||
private static final String EDIT_LIST = "edit_list";
|
||||
private static final String INSPECT = "inspect";
|
||||
private static final String LOGIN = "login";
|
||||
private static final String LOGOUT = "logout";
|
||||
@@ -48,13 +50,10 @@ public class Web extends TemplateServlet {
|
||||
private static final int PRIMARY_KEY_CONSTRAINT = 19;
|
||||
|
||||
private String addList(HttpServletRequest req, HttpServletResponse resp) {
|
||||
|
||||
var o = req.getSession().getAttribute(USER);
|
||||
if (!(o instanceof User user)) {
|
||||
return redirectTo(LOGIN,resp);
|
||||
}
|
||||
var user = Util.getUser(req);
|
||||
if (user == null) return redirectTo(LOGIN,resp);
|
||||
var data = new HashMap<String, Object>();
|
||||
data.put(USER, user);
|
||||
data.put(USER, user.safeMap());
|
||||
|
||||
if (!user.hashPermission(User.PERMISSION_CREATE_LISTS)){
|
||||
data.put(ERROR,t("You are not allowed to create new mailing lists!"));
|
||||
@@ -128,7 +127,7 @@ public class Web extends TemplateServlet {
|
||||
try {
|
||||
var list = MailingList.create(email, name, imapHost, imapPort, imapUser, imapPass, inbox, smtpHost, smtpPort, smtpUser, smtpPass);
|
||||
ListMember.create(list, user, ListMember.STATE_OWNER);
|
||||
return redirectTo(INDEX, resp);
|
||||
return redirectTo(ADMIN, resp);
|
||||
} catch (SQLException e) {
|
||||
return t("Failed to create list '{}': {}", name, e.getMessage());
|
||||
}
|
||||
@@ -164,6 +163,91 @@ public class Web extends TemplateServlet {
|
||||
if (error != null) resp.sendError(400,error);
|
||||
}
|
||||
|
||||
public String editList(HttpServletRequest req, HttpServletResponse resp) {
|
||||
var user = Util.getUser(req);
|
||||
if (user == null) return redirectTo(LOGIN,resp);
|
||||
|
||||
var data = new HashMap<String, Object>();
|
||||
data.put(USER,user.safeMap());
|
||||
|
||||
var list = Util.getMailingList(req);
|
||||
data.put(LIST,list.safeMap());
|
||||
try {
|
||||
var allowed = user.hashPermission(PERMISSION_ADMIN) || ListMember.load(list,user).isOwner();
|
||||
if (!allowed) return loadTemplate(ADMIN,data,resp);
|
||||
|
||||
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 inbox = req.getParameter(INBOX);
|
||||
if (inbox == null || inbox.isBlank()) inbox = DEFAULT_INBOX;
|
||||
data.put(INBOX, inbox);
|
||||
|
||||
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(EDIT_LIST, data, resp);
|
||||
}
|
||||
|
||||
if (!Util.isEmail(email)) {
|
||||
data.put(ERROR, t("List email ({}) is not a valid email address!", email));
|
||||
return loadTemplate(EDIT_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(EDIT_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(EDIT_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(EDIT_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(EDIT_LIST, data, resp);
|
||||
}
|
||||
|
||||
list.update(name,email,imapHost,imapPort,imapUser,imapPass,inbox,smtpHost,smtpPort,smtpUser,smtpPass);
|
||||
return loadTemplate(ADMIN,data,resp);
|
||||
} catch (SQLException e) {
|
||||
LOG.warn("Editing list {} by {} failed",list.email(),user.email(),e);
|
||||
return t("Editing list {} by {} failed",list.email(),user.email());
|
||||
}
|
||||
}
|
||||
|
||||
private SQLException getCausingException(SQLException sqle) {
|
||||
Throwable cause = sqle.getCause();
|
||||
while (cause instanceof SQLException){
|
||||
@@ -230,7 +314,10 @@ public class Web extends TemplateServlet {
|
||||
|
||||
if (user != null){
|
||||
if (list != null) data.put(LIST,req.getParameter(LIST));
|
||||
//data.put(NOTES,notes);
|
||||
switch (path){
|
||||
case EDIT_LIST:
|
||||
return editList(req,resp);
|
||||
}
|
||||
return loadTemplate(path,data,resp);
|
||||
}
|
||||
return redirectTo(LOGIN,resp);
|
||||
@@ -263,6 +350,8 @@ public class Web extends TemplateServlet {
|
||||
switch (path){
|
||||
case ADD_LIST:
|
||||
return addList(req,resp);
|
||||
case EDIT_LIST:
|
||||
return editList(req,resp);
|
||||
case INSPECT:
|
||||
return inspect(req,resp);
|
||||
case LOGIN:
|
||||
@@ -367,7 +456,7 @@ public class Web extends TemplateServlet {
|
||||
|
||||
try {
|
||||
var user = User.create(email, name, pass);
|
||||
if (firstUser) user.addPermission(User.PERMISSION_ADMIN|User.PERMISSION_CREATE_LISTS);
|
||||
if (firstUser) user.addPermission(PERMISSION_ADMIN|User.PERMISSION_CREATE_LISTS);
|
||||
req.getSession().setAttribute("user",user);
|
||||
return redirectTo(INDEX,resp);
|
||||
} catch (SQLException e) {
|
||||
|
||||
@@ -9,66 +9,8 @@
|
||||
<body id="add_list">
|
||||
«navigation()»
|
||||
«userinfo()»
|
||||
<h1>Widerhall List Creation</h1>
|
||||
«messages()»
|
||||
<form method="POST" action="add_list">
|
||||
<fieldset>
|
||||
<legend>List configuration</legend>
|
||||
<fieldset>
|
||||
<legend>Basic data</legend>
|
||||
<label>
|
||||
<input type="text" name="name" value="«data.name»" id="name" />
|
||||
List name
|
||||
</label>
|
||||
<label>
|
||||
<input type="text" name="email" value="«data.email»" id="email" />
|
||||
List E-Mail Address
|
||||
</label>
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<legend>IMAP protocol</legend>
|
||||
<label>
|
||||
<input type="text" name="imap_host" value="«data.imap_host»" id="imap_host" />
|
||||
Hostname
|
||||
</label>
|
||||
<label>
|
||||
<input type="number" name="imap_port" value="«data.imap_port»" id="imap_port" />
|
||||
Port
|
||||
</label>
|
||||
<label>
|
||||
<input type="text" name="imap_user" value="«data.imap_user»" id="imap_user" />
|
||||
Username
|
||||
</label>
|
||||
<label>
|
||||
<input type="password" name="imap_pass" value="«data.imap_pass»" id="imap_pass" />
|
||||
Password
|
||||
</label>
|
||||
<label>
|
||||
<input type="text" name="inbox" value="«if(data.inbox)»«data.inbox»«else»INBOX«endif»" id="imap_inbox" />
|
||||
Inbox name
|
||||
</label>
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<legend>SMTP protocol</legend>
|
||||
<label>
|
||||
<input type="text" name="smtp_host" value="«data.smtp_host»" id="smtp_host" />
|
||||
Hostname
|
||||
</label>
|
||||
<label>
|
||||
<input type="number" name="smtp_port" value="«data.smtp_port»" id="smtp_port" />
|
||||
Port
|
||||
</label>
|
||||
<label>
|
||||
<input type="text" name="smtp_user" value="«data.smtp_user»" id="smtp_user" />
|
||||
Username
|
||||
</label>
|
||||
<label>
|
||||
<input type="password" name="smtp_pass" value="«data.smtp_pass»" id="smtp_pass" />
|
||||
Password
|
||||
</label>
|
||||
</fieldset>
|
||||
<button type="submit">Save new mailing list</button>
|
||||
</fieldset>
|
||||
</form>
|
||||
<h1>Widerhall List Creation</h1>
|
||||
«list_data_form()»
|
||||
</body>
|
||||
</html>
|
||||
@@ -3,7 +3,7 @@ label {
|
||||
margin: 5px 0;
|
||||
}
|
||||
|
||||
#add_list form,
|
||||
form#list_data,
|
||||
#login form,
|
||||
#register form,
|
||||
#subscribe form{
|
||||
|
||||
17
static/templates/edit_list.st
Normal file
17
static/templates/edit_list.st
Normal file
@@ -0,0 +1,17 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<script src="jquery"></script>
|
||||
<script src="js"></script>
|
||||
<link rel="stylesheet" href="css" />
|
||||
</head>
|
||||
<body>
|
||||
«navigation()»
|
||||
«userinfo()»
|
||||
«messages()»
|
||||
<h1>Widerhall List Setup</h1>
|
||||
«list_data_form()»
|
||||
«footer()»
|
||||
</body>
|
||||
</html>
|
||||
@@ -14,6 +14,7 @@
|
||||
<form method="POST">
|
||||
<fieldset>
|
||||
<legend>Settings</legend>
|
||||
This page shows configuration options for the mailing list. To edit login credentials, goto <a href="edit_list?list=«data.list»">edit list</a>
|
||||
<fieldset>
|
||||
<legend>Forward permissions</legend>
|
||||
<p>
|
||||
|
||||
@@ -110,7 +110,9 @@ function showListOfModeratedLists(data){
|
||||
if (list.state[state] > 0) states.push(state);
|
||||
}
|
||||
$('<td/>').text(states.toString()).appendTo(row);
|
||||
|
||||
if (list.last_error){
|
||||
$('<td/>').html('<span class="error">'+list.last_error+'</span>').appendTo(row);
|
||||
} else $('<td/>').text('-').appendTo(row);
|
||||
let select = $('<select/>',{name:addr}).change(function () {
|
||||
let action = $(this).children("option:selected").val();
|
||||
let list = $(this).attr('name');
|
||||
@@ -123,11 +125,9 @@ function showListOfModeratedLists(data){
|
||||
|
||||
$('<td/>').text(list.imap_host).appendTo(row);
|
||||
$('<td/>').text(list.imap_port).appendTo(row);
|
||||
$('<td/>').text(list.imap_user).appendTo(row);
|
||||
$('<td/>').text(list.inbox).appendTo(row);
|
||||
$('<td/>').text(list.smtp_host).appendTo(row);
|
||||
$('<td/>').text(list.smtp_port).appendTo(row);
|
||||
$('<td/>').text(list.smtp_user).appendTo(row);
|
||||
row.appendTo('#listlist');
|
||||
}
|
||||
if (data.user.permissions.includes('create lists')){
|
||||
|
||||
59
static/templates/list_data_form.st
Normal file
59
static/templates/list_data_form.st
Normal file
@@ -0,0 +1,59 @@
|
||||
<form id="list_data" method="POST">
|
||||
<fieldset>
|
||||
<legend>List configuration</legend>
|
||||
<fieldset>
|
||||
<legend>Basic data</legend>
|
||||
<label>
|
||||
<input type="text" name="name" value="«if(data.name)»«data.name»«else»«data.list.name»«endif»" id="name" />
|
||||
List name
|
||||
</label>
|
||||
<label>
|
||||
<input type="text" name="email" value="«if(data.email)»«data.email»«else»«data.list.email.prefix»@«data.list.email.domain»«endif»" id="email" />
|
||||
List E-Mail Address
|
||||
</label>
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<legend>IMAP protocol</legend>
|
||||
<label>
|
||||
<input type="text" name="imap_host" value="«if(data.imap_host)»«data.imap_host»«else»«data.list.imap_host»«endif»" id="imap_host" />
|
||||
Hostname
|
||||
</label>
|
||||
<label>
|
||||
<input type="number" name="imap_port" value="«if(data.imap_port)»«data.imap_port»«else»«data.list.imap_port»«endif»" id="imap_port" />
|
||||
Port
|
||||
</label>
|
||||
<label>
|
||||
<input type="text" name="imap_user" value="«if(data.imap_user)»«data.imap_user»«else»«data.list.imap_user»«endif»" id="imap_user" />
|
||||
Username
|
||||
</label>
|
||||
<label>
|
||||
<input type="password" name="imap_pass" value="«data.imap_pass»" id="imap_pass" />
|
||||
Password
|
||||
</label>
|
||||
<label>
|
||||
<input type="text" name="inbox" value="«if(data.inbox)»«data.inbox»«else»INBOX«endif»" id="imap_inbox" />
|
||||
Inbox name
|
||||
</label>
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<legend>SMTP protocol</legend>
|
||||
<label>
|
||||
<input type="text" name="smtp_host" value="«if(data.smtp_host)»«data.smtp_host»«else»«data.list.smtp_host»«endif»" id="smtp_host" />
|
||||
Hostname
|
||||
</label>
|
||||
<label>
|
||||
<input type="number" name="smtp_port" value="«if(data.smtp_port)»«data.smtp_port»«else»«data.list.smtp_port»«endif»" id="smtp_port" />
|
||||
Port
|
||||
</label>
|
||||
<label>
|
||||
<input type="text" name="smtp_user" value="«if(data.smtp_user)»«data.smtp_user»«else»«data.list.smtp_user»«endif»" id="smtp_user" />
|
||||
Username
|
||||
</label>
|
||||
<label>
|
||||
<input type="password" name="smtp_pass" value="«data.smtp_pass»" id="smtp_pass" />
|
||||
Password
|
||||
</label>
|
||||
</fieldset>
|
||||
<button type="submit">Save mailing list</button>
|
||||
</fieldset>
|
||||
</form>
|
||||
@@ -10,14 +10,13 @@
|
||||
<th>Name</th>
|
||||
<th>Address</th>
|
||||
<th>State</th>
|
||||
<th>Last error</th>
|
||||
<th>Actions</th>
|
||||
<th>Host</th>
|
||||
<th>Port</th>
|
||||
<th>User</th>
|
||||
<th>Inbox</th>
|
||||
<th>Host</th>
|
||||
<th>Port</th>
|
||||
<th>User</th>
|
||||
</tr>
|
||||
</table>
|
||||
<a href="add_list">Add new mailing list</a>
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
<nav>
|
||||
<a href="index">Home</a>
|
||||
<a href="admin">Administration</a>
|
||||
<!-- a class="button" href="reload" />Reload templates</a -->
|
||||
<script type="text/javascript">
|
||||
if ('«data.user.permissions»'.includes('admin')){
|
||||
$('<a/>',{class:'button',href:'reload'}).text('Reload templates').appendTo($('nav'));
|
||||
}
|
||||
</script>
|
||||
</nav>
|
||||
Reference in New Issue
Block a user