0
|
1 <%
|
|
2 package nabble.view.web.more;
|
|
3
|
|
4 import fschmidt.db.DbDatabase;
|
|
5 import fschmidt.util.mail.MailAddress;
|
|
6 import fschmidt.util.servlet.CanonicalUrl;
|
|
7 import nabble.model.Db;
|
|
8 import nabble.model.ListServer;
|
|
9 import nabble.model.MailingList;
|
|
10 import nabble.model.Message;
|
|
11 import nabble.model.ModelException;
|
|
12 import nabble.model.ModelHome;
|
|
13 import nabble.model.Node;
|
|
14 import nabble.model.Site;
|
|
15 import nabble.model.User;
|
|
16 import nabble.view.lib.Jtp;
|
|
17 import nabble.view.lib.NewSiteMail;
|
|
18 import nabble.view.lib.Permissions;
|
|
19 import nabble.view.lib.Shared;
|
|
20 import nabble.view.lib.UrlMappable;
|
|
21 import nabble.view.lib.Recaptcha;
|
|
22
|
|
23 import javax.servlet.ServletException;
|
|
24 import javax.servlet.http.HttpServlet;
|
|
25 import javax.servlet.http.HttpServletRequest;
|
|
26 import javax.servlet.http.HttpServletResponse;
|
|
27 import java.io.IOException;
|
|
28 import java.io.PrintWriter;
|
|
29 import java.net.MalformedURLException;
|
|
30 import java.net.URL;
|
|
31 import java.util.Collections;
|
|
32 import java.util.HashMap;
|
|
33 import java.util.Map;
|
|
34 import java.util.regex.Matcher;
|
|
35 import java.util.regex.Pattern;
|
|
36
|
|
37
|
|
38 public final class MailingListRequest extends HttpServlet implements UrlMappable, CanonicalUrl {
|
|
39
|
|
40 private static final Pattern URL_PATTERN = Pattern.compile("/archive-your-mailing-list\\.html$");
|
|
41
|
|
42 public static String url() {
|
|
43 return Jtp.defaultContextUrl() + path();
|
|
44 }
|
|
45
|
|
46 public static String path() {
|
|
47 return "/archive-your-mailing-list.html";
|
|
48 }
|
|
49
|
|
50 public String getCanonicalUrl(HttpServletRequest request) {
|
|
51 return url();
|
|
52 }
|
|
53
|
|
54 public Map<String,String[]> getParameterMapFromUrl(HttpServletRequest request,String mappedUrl) {
|
|
55 Matcher m = URL_PATTERN.matcher(mappedUrl);
|
|
56 if( !m.find() )
|
|
57 throw new RuntimeException();
|
|
58 return new HashMap<String,String[]>();
|
|
59 }
|
|
60
|
|
61 public Pattern getUrlPattern() {
|
|
62 return URL_PATTERN;
|
|
63 }
|
|
64
|
|
65 protected void service(HttpServletRequest request,HttpServletResponse response)
|
|
66 throws ServletException, IOException
|
|
67 {
|
|
68 build(request, response, Collections.<String,String>emptyMap(), Collections.<String,String>emptyMap());
|
|
69 }
|
|
70
|
|
71 private static void build(HttpServletRequest request,HttpServletResponse response, Map<String,String> values, Map<String,String> errors)
|
|
72 throws ServletException, IOException
|
|
73 {
|
|
74 PrintWriter out = response.getWriter();
|
|
75 %>
|
|
76 <html>
|
|
77 <head>
|
|
78 <% Shared.title(request,response,"Archive Your Mailing List"); %>
|
|
79 <META NAME="description" CONTENT="Archiving a mailing list at Nabble is quick and easy. Fill in one simple form and you're done.">
|
|
80 <META NAME="keywords" CONTENT="free, mailing list archive, forum interface, gateway, customizable, easy, quick setup">
|
|
81 <style type="text/css">
|
|
82 div.field-title {
|
|
83 margin-top: 0;
|
|
84 }
|
|
85 td.column1 {
|
|
86 text-align:right;
|
|
87 width:7em;
|
|
88 white-space:nowrap;
|
|
89 }
|
|
90 div.field-box {
|
|
91 border:none;
|
|
92 margin:0;
|
|
93 }
|
|
94 input[type=text],input[type=password],select {
|
|
95 padding:.3em 0;
|
|
96 }
|
|
97 .important { font-weight:bold }
|
|
98 </style>
|
|
99 <script type="text/javascript">
|
|
100 $(document).ready(function() {
|
|
101 $('#username').focus();
|
|
102 });
|
|
103 </script>
|
|
104 <%= Recaptcha.JS %>
|
|
105 </head>
|
|
106 <body>
|
|
107 <% Shared.minHeaderGlobal(request,response); %>
|
|
108
|
|
109 <h1>Archive Your Mailing List</h1>
|
|
110 <p>
|
|
111 <img src="/images/homepage/archive.png" style="float:left;margin: 0 1em 1em 1em"/>
|
|
112 You can archive your mailing list to a fully functional forum at Nabble by filling out
|
|
113 the form below. This makes it easy for users to browse and search archived emails.
|
|
114 Users can even post to the Nabble forum and we will forward these posts to your mailing list.
|
|
115 </p>
|
|
116
|
|
117 <% if (errors.size() > 0) { %>
|
|
118 <div class="error-message important" style="margin:1em;padding:.5em 0 .5em 12em">
|
|
119 <% String generic = errors.get("generic"); %>
|
|
120 <%=generic != null? generic : errors.size() > 0? "Please check the errors below" : ""%>
|
|
121 </div>
|
|
122 <% } %>
|
|
123
|
|
124 <form method="post" action="/more/MailingListRequest$Save.jtp" accept-charset="UTF-8">
|
|
125 <input type="hidden" name="Action" value="save">
|
|
126
|
|
127 <div style="border-bottom:2px solid #eeeeee;padding:1em;width:50em">
|
|
128 <div class="weak-color" style="width:11.5em;text-align:center;float:left">
|
|
129 <div style="font-weight:bold">Account</div>
|
|
130 <img src="/images/account.png"/>
|
|
131 <div style="margin-top:1em;font-size:80%">
|
|
132 You will receive an email with a link to activate your account
|
|
133 </div>
|
|
134 </div>
|
|
135 <table>
|
|
136 <tr>
|
|
137 <td><div class="second-font field-title">User Name</div></td>
|
|
138 <td><input type="text" id="username" size="35" maxlength="30" name="username" value="<%=Jtp.hideNull(values.get("username"))%>" /></td>
|
|
139 <td class="important"><%=errors.containsKey("username")? errors.get("username"):""%></td>
|
|
140 </tr>
|
|
141 <tr>
|
|
142 <td><div class="second-font field-title">Email</div></td>
|
|
143 <td><input type="text" size="35" maxlength="60" name="email" value="<%=Jtp.hideNull(values.get("email"))%>"/></td>
|
|
144 <td class="important"><%=errors.containsKey("email")? errors.get("email"):""%></td>
|
|
145 </tr>
|
|
146 <tr>
|
|
147 <td><div class="second-font field-title">Password</div></td>
|
|
148 <td><input type="password" size="35" maxlength="15" name="password" value="<%=Jtp.hideNull(values.get("password"))%>"/></td>
|
|
149 <td class="important"><%=errors.containsKey("password")? errors.get("password"):""%></td>
|
|
150 </tr>
|
|
151 <tr>
|
|
152 <td class="column1"><input type="checkbox" id="terms" name="terms" value="y" <%="y".equals(values.get("terms"))?"checked":""%> /></td>
|
|
153 <td colspan=2><label for="terms">I have read and I agree to Nabble's <a href="<%=Jtp.termsUrl(true)%>">Terms of Use</a>.</label></td>
|
|
154 </tr>
|
|
155 </table>
|
|
156 </div>
|
|
157
|
|
158 <div style="padding:.5em;width:50em">
|
|
159 <div class="weak-color" style="width:12em;text-align:center;float:left;height:50em;padding-top:1em">
|
|
160 <div style="font-weight:bold">Mailing List</div>
|
|
161 <img src="/images/homepage/mailing-list.png" alt="Free Mailing List Archive">
|
|
162 </div>
|
|
163
|
|
164 <div class="field-box">
|
|
165 <div class="second-font field-title">Mailing List Address</div>
|
|
166 <div class="weak-color">
|
|
167 <input id="mailingList" type="text" name="ml-address" value="<%=Jtp.hideNull(values.get("ml-address"))%>" size="46" />
|
|
168 <span class="important"><%=errors.containsKey("ml-address")? errors.get("ml-address"):""%></span>
|
|
169 <div class="weak-color">e.g., mygroup@yahoogroups.com</div>
|
|
170 </div>
|
|
171 </div>
|
|
172
|
|
173 <div class="field-box light-border-color">
|
|
174 <div class="second-font field-title">Mailing List URL</div>
|
|
175 <div class="weak-color">
|
|
176 Enter the homepage of this mailing list, where other users can find more information.<br/>
|
|
177 <input type="text" name="ml-url" size="55" value="<%=Jtp.hideNull(values.get("ml-url"))%>" />
|
|
178 <span class="important"><%=errors.containsKey("ml-url")? errors.get("ml-url"):""%></span>
|
|
179 <div class="weak-color">e.g., http://www.mailinglist.com/list</div>
|
|
180 </div>
|
|
181 </div>
|
|
182
|
|
183 <div class="field-box light-border-color">
|
|
184 <div class="second-font field-title">Forum Name</div>
|
|
185 <div class="weak-color">
|
|
186 Enter the name of the forum for this mailing list.<br/>
|
|
187 <input type="text" name="subject" size="46" value="<%=Jtp.hideNull(values.get("subject"))%>" />
|
|
188 <span class="important"><%=errors.containsKey("subject")? errors.get("subject"):""%></span>
|
|
189 </div>
|
|
190 </div>
|
|
191
|
|
192 <div class="field-box light-border-color">
|
|
193 <div class="second-font field-title">Forum Description</div>
|
|
194 <div class="weak-color">
|
|
195 <textarea cols=46 rows=5 name="message" id="nabble.desc" wrap="SOFT"><%=Jtp.hideNull(values.get("message"))%></textarea>
|
|
196 </div>
|
|
197 </div>
|
|
198
|
|
199 <div class="field-box light-border-color">
|
|
200 <div class="second-font field-title">List Server and Version</div>
|
|
201 <div class="weak-color">
|
|
202 If you know, please select the mailing list server application.<br/>
|
|
203 <select name="server-type">
|
|
204 <%
|
|
205 String[] serverTypes = ListServer.getAllServerTypes();
|
|
206 ListServer selectedServer = ListServer.getServer(values.get("server-type"));
|
|
207 for (String s : serverTypes) {
|
|
208 ListServer currentServer = ListServer.getServer(s);
|
|
209 if(currentServer.showInInitialSetup()) {
|
|
210 %><option value="<%=currentServer.getType()%>" <%=currentServer == selectedServer?"selected":""%>><%=currentServer.getViewName()%></option><%
|
|
211 }
|
|
212 }
|
|
213 %>
|
|
214 </select>
|
|
215 <div class="weak-color">If you are not absolutely sure about the version of the list server, it is better if you leave it as Unknown</div>
|
|
216 </div>
|
|
217 </div>
|
|
218
|
|
219 <div class="field-box light-border-color">
|
|
220 <div class="second-font field-title">Other Settings</div>
|
|
221 <table>
|
|
222 <tr>
|
|
223 <td><input id="plain-text" name="plain-text" type="checkbox" value="y" <%="y".equals(values.get("plain-text"))?"checked":""%> /></td>
|
|
224 <td><label for="plain-text">This list accepts only plain-text emails</label>.</td>
|
|
225 </tr>
|
|
226 <tr>
|
|
227 <td><input id="ignore-x-noarchive" name="ignore-x-noarchive" type="checkbox" value="y" <%="y".equals(values.get("ignore-x-noarchive"))?"checked":""%> /></td>
|
|
228 <td><label for="ignore-x-noarchive">Ignore X-No-Archive Header</label>.</td>
|
|
229 </tr>
|
|
230 <tr>
|
|
231 <td colspan=2 style="padding-top:1em">
|
|
232 <%= Recaptcha.DIV %>
|
|
233 </td>
|
|
234 </tr>
|
|
235 </table>
|
|
236 </div>
|
|
237
|
|
238 <input type="submit" value="Create Mailing List Archive" style="padding:.5em .8em;font-size:110%;font-weight:bold"/>
|
|
239 </div>
|
|
240 </form>
|
|
241
|
|
242 <% Shared.footer(request,response); %>
|
|
243 <% Shared.analytics(request,response); %>
|
|
244 </body>
|
|
245 </html>
|
|
246 <%
|
|
247 }
|
|
248
|
|
249 public static class Save extends HttpServlet {
|
|
250
|
|
251 private static String get(String name, HttpServletRequest request) {
|
|
252 String s = request.getParameter(name);
|
|
253 return s == null? null : s.trim();
|
|
254 }
|
|
255
|
|
256 protected void service(HttpServletRequest request, HttpServletResponse response)
|
|
257 throws ServletException, IOException
|
|
258 {
|
|
259 String username = get("username", request);
|
|
260 String email = get("email", request);
|
|
261 String password = get("password", request);
|
|
262 boolean agreed = "y".equals(get("terms", request));
|
|
263
|
|
264 String mlAddress = get("ml-address", request);
|
|
265 String mlUrl = get("ml-url", request);
|
|
266 String subject = get("subject", request);
|
|
267 String message = get("message", request);
|
|
268 String serverType = get("server-type", request);
|
|
269 boolean isPlainText = "y".equals(get("plain-text", request));
|
|
270 boolean isIgnoreXNoArchive = "y".equals(get("ignore-x-noarchive", request));
|
|
271
|
|
272 Map<String,String> errors = new HashMap<String,String>();
|
|
273 if (username == null || username.trim().length() == 0)
|
|
274 errors.put("username", "required");
|
|
275 if (email == null || email.length() == 0)
|
|
276 errors.put("email", "required");
|
|
277 else if (!new MailAddress(email).isValid())
|
|
278 errors.put("email", "invalid email");
|
|
279 if (password == null || password.length() < 4)
|
|
280 errors.put("password", "too short");
|
|
281 if (!agreed)
|
|
282 errors.put("generic", "You must agree to the Terms and Conditions");
|
|
283 if (subject == null || subject.length() == 0)
|
|
284 errors.put("subject", "required");
|
|
285 if (mlAddress == null || mlAddress.length() == 0)
|
|
286 errors.put("ml-address", "required");
|
|
287 else if (!new MailAddress(mlAddress).isValid())
|
|
288 errors.put("ml-address", "invalid email");
|
|
289 if (mlUrl == null || mlUrl.length() == 0)
|
|
290 errors.put("ml-url", "required");
|
|
291 else {
|
|
292 try {
|
|
293 new URL(mlUrl);
|
|
294 } catch (MalformedURLException e) {
|
|
295 errors.put("ml-url", "invalid URL");
|
|
296 }
|
|
297 }
|
|
298
|
|
299 if (errors.isEmpty()) {
|
|
300 DbDatabase db = Db.dbGlobal();
|
|
301 db.beginTransaction();
|
|
302 try {
|
|
303 Recaptcha.check(request);
|
|
304 Site site = ModelHome.newSite(Node.Type.FORUM,subject, message, Message.Format.TEXT, email, username);
|
|
305 Permissions.addToGroup( (User)site.getRootNode().getOwner(), Permissions.ADMINISTRATORS_GROUP );
|
|
306 String key = site.newRegistration(email,password,username,"/mailing_list/SubscribeToMailingList.jtp?node="+site.getRootNode().getId());
|
|
307
|
|
308 MailingList ml = site.getRootNode().newMailingList(ListServer.getServer(serverType), mlAddress, mlUrl);
|
|
309 ml.setPlainTextOnly(isPlainText);
|
|
310 ml.setIgnoreNoArchive(isIgnoreXNoArchive);
|
|
311 ml.update();
|
|
312
|
|
313 db.commitTransaction();
|
|
314
|
|
315 site = site.getGoodCopy();
|
|
316 ForumStart.sendRegisterMail(site, email, key);
|
|
317 NewSiteMail.send(site, request, response);
|
|
318 response.sendRedirect(site.getBaseUrl()+"/more/MailingListRequest$FinalSteps.jtp");
|
|
319 return;
|
|
320 } catch(ModelException e) {
|
|
321 errors.put("generic", e.getMessage());
|
|
322 } finally {
|
|
323 db.endTransaction();
|
|
324 }
|
|
325 }
|
|
326
|
|
327 Map<String,String> values = new HashMap<String,String>();
|
|
328 values.put("username", username);
|
|
329 values.put("email", email);
|
|
330 values.put("password", password);
|
|
331 values.put("terms", agreed?"y":"");
|
|
332
|
|
333 values.put("ml-address", mlAddress);
|
|
334 values.put("ml-url", mlUrl);
|
|
335 values.put("subject", subject);
|
|
336 values.put("message", message);
|
|
337 values.put("server-type", serverType);
|
|
338 values.put("plain-text", isPlainText?"y":"");
|
|
339 values.put("ignore-x-noarchive", isIgnoreXNoArchive?"y":"");
|
|
340 build(request, response, values, errors);
|
|
341 }
|
|
342 }
|
|
343
|
|
344 public static class FinalSteps extends HttpServlet {
|
|
345
|
|
346 protected void service(HttpServletRequest request, HttpServletResponse response)
|
|
347 throws ServletException, IOException
|
|
348 {
|
|
349 PrintWriter out = response.getWriter();
|
|
350 %>
|
|
351 <html>
|
|
352 <head>
|
|
353 <% Shared.title(request,response,"Archive Created, But Subscription is Needed"); %>
|
|
354 </head>
|
|
355 <body>
|
|
356 <% Shared.minHeaderGlobal(request,response); %>
|
|
357 <h1>Success</h1>
|
|
358 <p>Your mailing list archive has been successfully created.</p>
|
|
359 <h2>What should I do now?</h2>
|
|
360 <p>
|
|
361 You should now check your email and click on the activation link sent to you.
|
|
362 That link will complete your account registration and take you to the page where you can subscribe the Nabble archive to the mailing list.
|
|
363 <b>If you don't subscribe the archive to the mailing list, it will NOT work properly!</b>
|
|
364 </p>
|
|
365 <p>You can contact <a href="<%=Jtp.supportUrl()%>">Nabble Support</a> if you have questions.</p>
|
|
366 <% Shared.footer(request,response); %>
|
|
367 <% Shared.analytics(request,response); %>
|
|
368 </body>
|
|
369 </html>
|
|
370 <%
|
|
371 }
|
|
372 }
|
|
373 }
|
|
374 %>
|