added fromtpage
This commit is contained in:
2
pom.xml
2
pom.xml
@@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>Widerhall</artifactId>
|
||||
<version>0.0.8</version>
|
||||
<version>0.0.9</version>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package de.srsoftware.widerhall;
|
||||
|
||||
import de.srsoftware.widerhall.web.Front;
|
||||
import de.srsoftware.widerhall.web.Rest;
|
||||
import de.srsoftware.widerhall.web.Web;
|
||||
import org.eclipse.jetty.server.Connector;
|
||||
@@ -34,6 +35,7 @@ public class Application {
|
||||
ServletContextHandler context = new ServletContextHandler(server, "/",sh,null,null,null);
|
||||
context.addServlet(Rest.class,"/api/*");
|
||||
context.addServlet(Web.class,"/web/*");
|
||||
context.addServlet(Front.class,"/*");
|
||||
|
||||
server.start();
|
||||
}
|
||||
|
||||
19
src/main/java/de/srsoftware/widerhall/web/Front.java
Normal file
19
src/main/java/de/srsoftware/widerhall/web/Front.java
Normal file
@@ -0,0 +1,19 @@
|
||||
package de.srsoftware.widerhall.web;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
public class Front extends TemplateServlet {
|
||||
|
||||
private static final String FRONT = "frontpage";
|
||||
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
|
||||
loadTemplates();
|
||||
String error = loadTemplate(FRONT, Map.of(),resp);
|
||||
if (error != null) resp.sendError(400,error);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package de.srsoftware.widerhall.web;
|
||||
|
||||
import de.srsoftware.widerhall.Configuration;
|
||||
import org.stringtemplate.v4.STGroup;
|
||||
import org.stringtemplate.v4.STRawGroupDir;
|
||||
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.util.Map;
|
||||
|
||||
import static de.srsoftware.widerhall.Util.t;
|
||||
|
||||
public abstract class TemplateServlet extends HttpServlet {
|
||||
private STGroup templates;
|
||||
private final String baseDir;
|
||||
|
||||
public TemplateServlet(){
|
||||
var config = Configuration.instance();
|
||||
baseDir = config.baseDir();
|
||||
loadTemplates();
|
||||
}
|
||||
|
||||
protected String loadFile(String filename, HttpServletResponse resp) {
|
||||
var path = String.join(File.separator,baseDir,"static",filename);
|
||||
var file = new File(path);
|
||||
if (!file.exists()) return t("File {} does not exist!",filename);
|
||||
try {
|
||||
var content = Files.readString(file.toPath());
|
||||
resp.getWriter().println(content);
|
||||
} catch (IOException e) {
|
||||
return t("Failed to load file '{}'!",filename);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected String loadTemplate(String path, Map<String, ? extends Object> data, HttpServletResponse resp) {
|
||||
var template = templates.getInstanceOf(path);
|
||||
if (template != null){
|
||||
try {
|
||||
template.add("data",data);
|
||||
resp.getWriter().println(template.render());
|
||||
return null;
|
||||
} catch (IOException e) {
|
||||
return t("Failed to load template '{}'",path);
|
||||
}
|
||||
}
|
||||
return t("No template for path '{}'!",path);
|
||||
}
|
||||
|
||||
protected void loadTemplates() {
|
||||
var templateDir = String.join(File.separator,baseDir,"static","templates");
|
||||
templates = new STRawGroupDir(templateDir,'«','»');
|
||||
}
|
||||
}
|
||||
@@ -28,7 +28,8 @@ import java.util.Map;
|
||||
import static de.srsoftware.widerhall.Constants.*;
|
||||
import static de.srsoftware.widerhall.Util.t;
|
||||
|
||||
public class Web extends HttpServlet {
|
||||
public class Web extends TemplateServlet {
|
||||
public static final String WEB_ROOT = "/web";
|
||||
private static final String ADD_LIST = "add_list";
|
||||
private static final String CONFIRM = "confirm";
|
||||
private static final Logger LOG = LoggerFactory.getLogger(Web.class);
|
||||
@@ -48,15 +49,6 @@ public class Web extends HttpServlet {
|
||||
private static final String SMTP_USER = "smtp_user";
|
||||
private static final String SMTP_PASS = "smtp_pass";
|
||||
private static final int PRIMARY_KEY_CONSTRAINT = 19;
|
||||
private final String baseDir;
|
||||
private STGroup templates;
|
||||
private static final String WEB_ROOT = "/web";
|
||||
|
||||
public Web(){
|
||||
var config = Configuration.instance();
|
||||
baseDir = config.baseDir();
|
||||
loadTemplates();
|
||||
}
|
||||
|
||||
private String addList(HttpServletRequest req, HttpServletResponse resp) {
|
||||
|
||||
@@ -154,7 +146,6 @@ public class Web extends HttpServlet {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
|
||||
String error = handleGet(req, resp);
|
||||
@@ -181,12 +172,13 @@ public class Web extends HttpServlet {
|
||||
}
|
||||
|
||||
private String handleGet(HttpServletRequest req, HttpServletResponse resp) {
|
||||
var path = req.getPathInfo();
|
||||
if (path == null) return redirectTo(INDEX,resp);
|
||||
var o = req.getSession().getAttribute("user");
|
||||
User user = o instanceof User ? (User) o : null;
|
||||
var data = new HashMap<String,Object>();
|
||||
if (user != null) data.put(USER,user.safeMap());
|
||||
var path = req.getPathInfo();
|
||||
path = (path == null || path.equals("/")) ? INDEX : path.substring(1);
|
||||
path = path.equals("/") ? INDEX : path.substring(1);
|
||||
String notes = null;
|
||||
var listEmail = req.getParameter(LIST);
|
||||
var list = MailingList.load(listEmail);
|
||||
@@ -276,37 +268,9 @@ public class Web extends HttpServlet {
|
||||
return t("No handler for path {}!",path);
|
||||
}
|
||||
|
||||
private String loadFile(String filename, HttpServletResponse resp) {
|
||||
var path = String.join(File.separator,baseDir,"static",filename);
|
||||
var file = new File(path);
|
||||
if (!file.exists()) return t("File {} does not exist!",filename);
|
||||
try {
|
||||
var content = Files.readString(file.toPath());
|
||||
resp.getWriter().println(content);
|
||||
} catch (IOException e) {
|
||||
return t("Failed to load file '{}'!",filename);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private String loadTemplate(String path, Map<String, ? extends Object> data, HttpServletResponse resp) {
|
||||
var template = templates.getInstanceOf(path);
|
||||
if (template != null){
|
||||
try {
|
||||
template.add("data",data);
|
||||
resp.getWriter().println(template.render());
|
||||
return null;
|
||||
} catch (IOException e) {
|
||||
return t("Failed to load template '{}'",path);
|
||||
}
|
||||
}
|
||||
return t("No template for path '{}'!",path);
|
||||
}
|
||||
|
||||
private void loadTemplates() {
|
||||
var templateDir = String.join(File.separator,baseDir,"static","templates");
|
||||
templates = new STRawGroupDir(templateDir,'«','»');
|
||||
}
|
||||
|
||||
|
||||
private String redirectTo(String page, HttpServletResponse resp) {
|
||||
try {
|
||||
|
||||
40
static/templates/frontpage.st
Normal file
40
static/templates/frontpage.st
Normal file
@@ -0,0 +1,40 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<link rel="stylesheet" href="css" />
|
||||
</head>
|
||||
<body id="login">
|
||||
<h1>Widerhall front page</h1>
|
||||
If you are looking for you mailing lists, <a href="web/index">Go to the /web page</a>...
|
||||
<fieldset>
|
||||
<legend>What is <em>Widerhall</em>?</legend>
|
||||
<p>
|
||||
Widerhall is a mailing list system written in Java.
|
||||
It allows to maintain a set of mailing lists with the option to make (some of) them publicy subscribable.
|
||||
</p>
|
||||
<p>
|
||||
<em>Widerhall</em> is very lightweight, as does not include a full email server stack.
|
||||
</p>
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<legend>Why should I use <em>Widerhall</em>?</legend>
|
||||
<p>
|
||||
Compared to other mailing list systems, widerhall is very lightweight:
|
||||
<p>
|
||||
It contains not mailserver stack. It does not even require you to set up a mailserver!
|
||||
</p>
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<legend>How does it work?</legend>
|
||||
<p>
|
||||
Widerhall works by just letting you set up any IMAP/SMTP enabled email address with a provider of your choice.
|
||||
It then connects to the inbox of you selected email address and watches for incoming messages.
|
||||
Upon message reception, it forwards the message to all subscribers of the mailing list.
|
||||
</p>
|
||||
<p>
|
||||
That's it.
|
||||
</p>
|
||||
</fieldset>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user